News for hackers. Stuff that matters.
Re:A vision of a multi-threaded Emacs by dotancohen on Monday May 30, 2022 @02:22PM (#31561951)
I just got into emacs last year, for Org mode. Startup times drive me crazy.

What would be the correct way to configure my .emacs file to e.g. check for package updates in a background process?

Re:A vision of a multi-threaded Emacs by complex1314 on Monday May 30, 2022 @03:16PM (#31562567)
Use emacsclient and have a emacs server running at all times. Super fast startup times, you can even use emacsclient -nw (or make an alias 'e' for that) in the terminal for fast edits with instantaneous startup.

You could also make a script that starts emacs as a client only if a server already is running

  #!/bin/sh
  if [ "$#" -eq 0 ]
  then
    echo "Starting new Emacs process ..." >&2
    nohup emacs > /dev/null 2>&1 &
  elif emacsclient -n "$@" 2> /dev/null
  then
    echo "Opened $@ in Emacs server" >&2
  else
    echo "Opening $@ in a new Emacs process ..." >&2
    nohup emacs "$@" > /dev/null 2>&1 &
  fi
(Copied from an emacs starter kit but don't remember which...)
Re:A vision of a multi-threaded Emacs by alex_smart on Tuesday May 31, 2022 @04:25PM (#31574476)
You don't need to do all that. Just run emacsclient with `emacsclient -a ""`.

From the man page:

    -a, --alternate-editor=COMMAND
           If  the  Emacs  server  is  not  running, run the specified shell command instead.  This can also be specified via the ALTERNATE_EDITOR environment variable.  If the value of ALTERNATE_EDITOR is the empty string, run
           "emacs --daemon" to start Emacs in daemon mode, and try to connect to it.
Re:A vision of a multi-threaded Emacs by complex1314 on Wednesday June 01, 2022 @04:46PM (#31587855)
Didn't know that, thanks!
Re:A vision of a multi-threaded Emacs by massysett on Monday May 30, 2022 @05:41PM (#31563932)
This is really “just leave Emacs running all the time,” which is more of a workaround or an acceptance of “fit your workflow around Emacs” than it is truly a solution, which would be to reduce startup times.
Re:A vision of a multi-threaded Emacs by joseph8th on Monday May 30, 2022 @06:10PM (#31564174)
Once it starts it does almost nothing unless you're using it, and then it's still a lightweight document editor, not an Electron app
Re:A vision of a multi-threaded Emacs by tom_ on Monday May 30, 2022 @06:00PM (#31564091)
Why do you quit though? I don’t quit other programs... why is Emacs different?
Re:A vision of a multi-threaded Emacs by massysett on Monday May 30, 2022 @07:00PM (#31564536)
I quit and restart Vim dozens of times daily.

I’m not saying there’s something wrong with leaving Emacs running. But it’s a workaround. When I used Emacs, startup time was not a problem. But I didn’t use a bunch of packages.

Re:A vision of a multi-threaded Emacs by ghosty141 on Tuesday May 31, 2022 @11:43AM (#31570858)
Emacs is not supposed to be used like vim. The stereotype of living inside emacs doesnt exist for no reason.

Apart from that, without too many paclages stsrtup time is not an issue imo

Re:A vision of a multi-threaded Emacs by tom_ on Tuesday May 31, 2022 @03:07AM (#31566860)
I never used to quit vim either!
Re:A vision of a multi-threaded Emacs by BeetleB on Tuesday May 31, 2022 @12:25AM (#31566091)
A no-config Emacs has a rapid startup time - it's instant on my PC.

> or an acceptance of “fit your workflow around Emacs” than it is truly a solution, which would be to reduce startup times.

I don't see a problem with this. Emacs is a general purpose platform, and it's silly to expect really fast startup times if you're using it as a general purpose platform. People aren't expecting Linux to have an instant startup time if you have a large number of services running - why expect it from Emacs?

Re:A vision of a multi-threaded Emacs by dotancohen on Tuesday May 31, 2022 @01:49AM (#31566479)
Actually, reducing OS startup time used to be a goal. I think that stock Ubuntu on run-of-the-mill hardware (spinning rust) was down to 14 seconds bios-to-login at some point when they made an effort on that front.
Re:A vision of a multi-threaded Emacs by BeetleB on Tuesday May 31, 2022 @03:13AM (#31566890)
And stock Emacs load time is virtually instant.
Re:A vision of a multi-threaded Emacs by dotancohen on Tuesday May 31, 2022 @03:02AM (#31566822)
Acceptable workaround, though. I don't mind when people XY analyze my problems, often those with experience in a field will be mindful of details that I did not know.

For what its worth, I've got at least 23 (service --status-all) daemons already running on this desktop. So leaving things running in the background until they are needed has precedent.

Re:A vision of a multi-threaded Emacs by nurbl on Tuesday May 31, 2022 @04:30AM (#31567248)
My fresh emacs startup time is a couple of seconds, not super snappy but then it has a reasonably large config to load. Reducing startup time is nice but I think vanilla emacs actually already starts quickly. How would you even be able to prevent people from adding heavy stuff to their config? It's possible to defer loading of packages until you need them but I think it would be hard to enforce by default, given that Emacs is really just a lisp machine and the config file is a lisp program.

I normally never exit Emacs. This is not because of startup time. To me it's like the web browser; I use it all the time, have a workspace dedicated to it and it's natural to keep lots of buffers open. My muscle memory takes care of jumping between open buffers.

Re:A vision of a multi-threaded Emacs by oh_sigh on Tuesday May 31, 2022 @12:37AM (#31566152)
If a process isn't using any resources, is it really running at all?

(Of course it doesn't really use no resources - it consumes a finite PID among other things)

Re:A vision of a multi-threaded Emacs by dotancohen on Tuesday May 31, 2022 @01:47AM (#31566463)
Terrific, thank you.
Re:A vision of a multi-threaded Emacs by alex_smart on Monday May 30, 2022 @02:32PM (#31562055)
Don't check for package updates during startup? Setup a cron job to upgrade the packages while you are asleep?
Re:A vision of a multi-threaded Emacs by dotancohen on Tuesday May 31, 2022 @01:55AM (#31566512)
It seems that Emacs does the check automatically, no? I have looked briefly on how to disable that but I didn't have the prerequisite knowledge at the time to understand what was happening. I'll look at that again, thank you.
Re:A vision of a multi-threaded Emacs by unhammer on Tuesday May 31, 2022 @03:51AM (#31567055)
Maybe you're using (use-package foo :ensure t) or something similar? I did that before, and if there was some package that simply wasn't available it would of course check and not find anything every time I started emacs. I don't use :ensure t any more (I check the elpa folder into git along with my init file for keeping it in sync across machines)
Re:A vision of a multi-threaded Emacs by alex_smart on Tuesday May 31, 2022 @02:18AM (#31566613)
>It seems that Emacs does the check automatically, no?

Nope, it for sure does not.

Re:A vision of a multi-threaded Emacs by contravariant on Monday May 30, 2022 @03:09PM (#31562485)
Using Doom emacs was the easiest way for me to get fast loading times. It provides some sane defaults that should be pretty fast in most cases. It might be worth checking out.
Re:A vision of a multi-threaded Emacs by dotancohen on Tuesday May 31, 2022 @01:54AM (#31566508)
Thanks. I just left Spacemacs for vanilla. A distro was a great way into the Emacs ecosystem, but now I'd like to configure the thing to my use cases specifically.

I might look at the doom config and try to divine how they're getting such fast loading times. Thank you for the suggestion.

Re:A vision of a multi-threaded Emacs by BeetleB on Monday May 30, 2022 @04:49PM (#31563492)
Don't do automatic package updates. It's a sure way to continually break things.
Re:A vision of a multi-threaded Emacs by kwhitefoot on Monday May 30, 2022 @06:15PM (#31564203)
Why does Emacs startup time bother people so much? It's pretty quick for me and only happens once every few months anyway.
Re:A vision of a multi-threaded Emacs by NeutralForest on Monday May 30, 2022 @02:54PM (#31562323)
You should use `use-package` to manage your packages and defer their loading to when you use them. I have over 100 packages in my init.el and my Emacs loads in less than a second.
Re:A vision of a multi-threaded Emacs by dotancohen on Tuesday May 31, 2022 @01:59AM (#31566537)
Thank you. I'm not using many packages, so I'm not sure what to change. Using csv for example:

  $ grep csv ~/.emacs
   '(package-selected-packages '(csv-mode org-evil dash)))
If I want evil all the time but csv only when needed, I should change that to the following?

   '(package-selected-packages '(org-evil dash)))
   '(use-package '(csv-mode)))
Re:A vision of a multi-threaded Emacs by unhammer on Tuesday May 31, 2022 @05:35AM (#31567563)
The package-selected-packages is just the list of installed packages, doesn't load anything.

You can set

    (setq use-package-always-defer t)
so anything you load with use-package will only be loaded on-demand. Or you can do it per package with e.g. `(use-package csv-mode :defer t)`.

Also make sure you don't set use-package-always-ensure and don't `:ensure t` or it'll try to install anything that's not installed on startup. If you want fast startup, it's better to explicitly install with M-x package-install

Re:A vision of a multi-threaded Emacs by NeutralForest on Tuesday May 31, 2022 @07:09AM (#31568183)
Always defer is a bad idea because some packages are required at startup or look for variables defined at startup (which is why `:init`) is a thing. Also, `:ensure t` only installs what is not installed at startup, but it does so only once and the following updates are to be made by hand. Once this is done, it does not try to install the packages anymore unless you remove them. This is how you get both fast startup and feature availability. Agreed on not using `always-ensure`, there are builtin packages that do not need it and will error out, this is why you should `:defer` and `:ensure` yourself.
Re:A vision of a multi-threaded Emacs by NeutralForest on Tuesday May 31, 2022 @04:28AM (#31567238)
You should have everything managed by use-package for coherence, even when you don't defer. For example,

(use-package org-evil :ensure t ;; download if not present :defer t ;; defer loading hook (org-mode . org-evil-mode)) ;; start this mode in org buffers

(use-package csv :ensure t :defer t) ;; modes are usually smart enough to know in which buffer they start

and so on for all your packages. If you NEED something to start when Emacs open, you can remove the `:defer t` macro. There are also other useful things like `:init` `:config` `custom`, you should check out the docs!

Re:A vision of a multi-threaded Emacs by bitwize on Monday May 30, 2022 @07:02PM (#31564558)
Emacs starts up in half a second or less for me. I use a vanilla configuration and don't update packages every time.
Re:A vision of a multi-threaded Emacs by KSteffensen on Tuesday May 31, 2022 @03:48AM (#31567040)
Re:A vision of a multi-threaded Emacs by hierandthere on Monday May 30, 2022 @06:59PM (#31564526)
How often do you start Emacs? I do that maybe once a week.
Re:A vision of a multi-threaded Emacs by dotancohen on Tuesday May 31, 2022 @02:00AM (#31566539)
I start Emacs every few minutes, for Org mode notes.
Re:A vision of a multi-threaded Emacs by alex_smart on Tuesday May 31, 2022 @02:22AM (#31566636)
You do not have to start a new instance of Emacs every time. You can tell emacs to start a server and then use emacsclient to connect to your already running instance of emacs.
Re:A vision of a multi-threaded Emacs by dotancohen on Tuesday May 31, 2022 @03:03AM (#31566828)
Thank you Alex. I'm configuring that now.