desktop: Load after make frame and comment about attempt to fix owner

master
Pierre Neidhardt 2018-02-11 10:33:33 +01:00
parent 11efa3f742
commit 26038620e5
2 changed files with 36 additions and 8 deletions

View File

@ -245,9 +245,6 @@
(setq comint-prompt-read-only t)
;;; Desktop-mode
;;; REVIEW: Desktop does not get saved when Emacs quits.
;;; See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=28945.
(load "patch-desktop")
;;; REVIEW: `desktop-kill' should not query the user in `kill-emacs-hook'.
;;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28943
;;; TODO: Desktop mode does not save window registers properly.
@ -257,19 +254,27 @@
;;; and https://stackoverflow.com/questions/5830494/windows-configuration-to-registers#5830928
;;; and https://www.reddit.com/r/emacs/comments/7au3hj/how_do_you_manage_your_emacs_windows_and_stay_sane/dpfbg3a/?context=3.
(when (daemonp)
;; Let Emacs auto-load/save sessions only when running the daemon.
;; Auto-load/save sessions only when running the daemon.
;; `server-running-p' is only useful once the daemon is started and cannot be
;; used for initialization. We use `daemonp' instead.
;; used for initialization. Use `daemonp' instead.
(require 'desktop)
(load "patch-desktop")
(setq history-length 250
;; REVIEW: Default timer (30) is way to high: for somebody too frenzy, the
;; timer might never be saved. See
;; Default timer (30) is way too high: for somebody too frenzy, the timer
;; might never be saved. See
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28943.
desktop-auto-save-timeout 5
desktop-dirname (expand-file-name "desktop" emacs-cache-folder)
desktop-path (list desktop-dirname)
;; desktop-restore-eager 4 ; Can be annoying as you don't have your last-loaded buffers immediately.
desktop-load-locked-desktop 'ask
desktop-restore-frames nil
desktop-save t)
(desktop-save-mode)
(defun desktop-init (_frame)
(desktop-save-mode)
(desktop-read)
(remove-hook 'after-make-frame-functions 'desktop-init))
(add-hook 'after-make-frame-functions 'desktop-init) ; This does not fix the window register restoration.
(add-to-list 'desktop-modes-not-to-save 'pdf-view-mode)
(add-to-list 'desktop-modes-not-to-save 'image-mode)
(unless (file-directory-p desktop-dirname)

View File

@ -121,3 +121,26 @@ Using it may cause conflicts. Use it anyway? " owner)))))
(run-hooks 'desktop-no-desktop-file-hook))
(message "No desktop file.")
nil)))
;;; Fix 30421
;;; Return nil if the PID found is not owned by a process named Emacs.
;;; This assumes that no other name would be using the desktop file.
;;; Upstream decided not to do this because of possible clashes when emacs
;;; process is running remotely. Start desktop-mode in
;;; `after-make-frame-functions' instead.
;; (defun desktop-owner (&optional dirname)
;; "Return the PID of the Emacs process that owns the desktop file in DIRNAME.
;; Return nil if no desktop file found or no Emacs process is using it.
;; DIRNAME omitted or nil means use `desktop-dirname'."
;; (let (owner
;; (file (desktop-full-lock-name dirname)))
;; (and (file-exists-p file)
;; (ignore-errors
;; (with-temp-buffer
;; (insert-file-contents-literally file)
;; (goto-char (point-min))
;; (setq owner (read (current-buffer)))
;; (integerp owner)
;; (process-attributes owner)
;; (string= "emacs" (alist-get 'comm (process-attributes owner)))))
;; owner)))