I want to restart Emacs at the same cursor position in the file (or buffer) I was just working on.
In my Emacs config I have the following code to try and do this:
(use-package desktop
:straight nil
;;:defer 1
:init
;; Automatically save and restore sessions
;; FIX: Replace hardcoded desktop-dirname with my-savefile-dir
(setq desktop-dirname "~/.emacs.d/desktop/"
desktop-base-file-name "emacs.desktop"
desktop-base-lock-name "lock"
desktop-path (list desktop-dirname)
desktop-save t
desktop-files-not-to-save "^$" ;reload tramp paths
desktop-load-locked-desktop nil
desktop-auto-save-timeout 30
desktop-restore-reuses-frames nil
desktop-buffers-not-to-save
(concat "\\("
"^nn\\.a[0-9]+\\|\\.log\\|(ftp)\\|^tags\\|^TAGS"
"\\|\\.emacs.*\\|\\.diary\\|\\.newsrc-dribble\\|\\.bbdb"
"\\)$"))
(setq desktop-restore-eager 1)
(desktop-save-mode 1)
(desktop-read)
:config
(add-to-list 'desktop-modes-not-to-save 'dired-mode)
;;(add-to-list 'desktop-modes-not-to-save 'Info-mode)
;;(add-to-list 'desktop-modes-not-to-save 'info-lookup-mode)
(add-to-list 'desktop-modes-not-to-save 'fundamental-mode))
Note: This is code updated slightly from the original post, but the issue still remains.
It seems to save the cursor in the given file if I exit.
However the problem is that when Emacs opens, it opens many buffers in separate windows. Each Emacs window appears to be a clone of the others . This is confusing and not the intended outcome. Not sure what is causing this issue.
For example, if I was working on file1.org
and left it at column 10, line 20, then
I want a single Emacs window to open in file1.org
at column 10, line 20. I don't want multiple windows to open with any previously visited Dired buffers etc.
I can confirm that if I comment out the above code, the problem goes away, but so does the required effect, i.e., I no longer start at file1.org
at the given location.
Here is a screenshot of the multiple windows that open when I startup Emacs.App (v28.1) on my macOS (Monterey v12.1):
I can clarify my settings further if needed.
(setq desktop-restore-eager 1)
to restore only the frontmost buffer immediately.file1.org
column 10, line 20, this is exactly where I would like emacs to have my cursor on startup. Right now it is opening up dired buffers etc, even though I tried to ignore them. Does that clarify better?emacs -Q
with your config like this. Would you mind delete your desktop file and check withemacs -Q
?emacs.d/desktop/emacs.desktop
andemacs.d/desktop/lock
files and restart. It did work as intended once. But since then I can't reproduce this even if I keep deleting these files and restarting. I've updated my config slightly in the original post. Is there some issue with the lock file setting?