3

I know that we can start emacs without opening last session's files and status, start it by:

emacs --no-desktop

But how do we do that in the init.el file?

3
  • You could remove the desktop load / read function attached to the after-init-hook and make sure that it is removed before the after-init-hook runs. Because it is a lambda function defined in desktop.el beginning at line 1513, you may need to remove it the same way. Your version of Emacs may be different than mine so, you should open desktop.el and copy it -- your code that will be added to your init.el will probably look something like (remove-hook 'after-init-hook (lambda () (let ((key "--no-desktop")) (when (member key command-line-args) . . .) I haven't actually tried it.
    – lawlist
    Mar 22, 2015 at 21:40
  • You could also try loading / requiring desktop.el after the after-init-hook has already run -- e.g., load / require desktop.el using the emacs-startup-hook, which runs after the after-init-hook. This will only work if nothing else loads / requires desktop.el beforehand. Again, I haven't actually tried it.
    – lawlist
    Mar 22, 2015 at 21:42
  • Thank you! Turns out it is caused by persp-mode, I disabled it and now emacs don't try to load everything.
    – godblessfq
    Mar 24, 2015 at 1:21

1 Answer 1

3

Just ensure that desktop-save-mode is turned off in your init file. If the mode is on when Emacs starts then your saved desktop file is loaded. If the mode is off then it is not loaded.

You can then turn the mode on anytime you like, to enable automatic saving. Or you can just use M-x desktop-save to manually save it anytime.

From the doc string of desktop-save-mode:

When Desktop Save mode is enabled, the state of Emacs is saved from one session to another. In particular, Emacs will save the desktop when it exits (this may prompt you; see the option `desktop-save'). The next time Emacs starts, if this mode is active it will restore the desktop.


Yes, this design of automatic loading being coupled with automatic saving is a bit bizarre, IMHO. But it's not the most bizarre thing in the design of desktop.el.

That distinction belongs instead to the assumption (built into the signatures of the functions) that there is at most one desktop file per directory.

That a user might find it convenient to have at most one such file per directory is one thing. But to make the functions depend on that assumption is nuts.

Take a look, for example, at function desktop-read. Then imagine that you want to use it to read a desktop file that might be located anywhere, passing the absolute file name. I had to roll my own function to do that (bmkp-desktop-read, which takes a file name as argument).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.