;;; desktop.el --- save partial status of Emacs when killed -*- lexical-binding: t -*-
-;; Copyright (C) 1993-1995, 1997, 2000-2014 Free Software Foundation, Inc.
+;; Copyright (C) 1993-1995, 1997, 2000-2015 Free Software Foundation,
+;; Inc.
;; Author: Morten Welinder <terra@diku.dk>
;; Keywords: convenience
(defcustom desktop-minor-mode-table
'((auto-fill-function auto-fill-mode)
+ (defining-kbd-macro nil)
+ (isearch-mode nil)
(vc-mode nil)
(vc-dired-mode nil)
(erc-track-minor-mode nil)
(and desktop-restore-frames
(frameset-save nil
:app desktop--app-id
- :name (concat user-login-name "@" system-name)
+ :name (concat user-login-name "@" (system-name))
:predicate #'desktop--check-dont-save))))
;;;###autoload
-(defun desktop-save (dirname &optional release auto-save)
+(defun desktop-save (dirname &optional release only-if-changed)
"Save the desktop in a desktop file.
Parameter DIRNAME specifies where to save the desktop file.
Optional parameter RELEASE says whether we're done with this desktop.
-If AUTO-SAVE is non-nil, compare the saved contents to the one last saved,
-and don't save the buffer if they are the same."
+If ONLY-IF-CHANGED is non-nil, compare the current desktop information
+to that in the desktop file, and if the desktop information has not
+changed since it was last saved then do not rewrite the file."
(interactive (list
;; Or should we just use (car desktop-path)?
(let ((default (if (member "." desktop-path)
(setq default-directory desktop-dirname)
;; When auto-saving, avoid writing if nothing has changed since the last write.
- (let* ((beg (and auto-save
+ (let* ((beg (and only-if-changed
(save-excursion
(goto-char (point-min))
;; Don't check the header with changing timestamp
;; Restore buffer list order with new buffer at end. Don't change
;; the order for old desktop files (old desktop module behavior).
(unless (< desktop-file-version 206)
- (mapc 'bury-buffer buffer-list)
+ (dolist (buf buffer-list)
+ (and (buffer-live-p buf)
+ (bury-buffer buf)))
(when result (bury-buffer result)))
(when result
(unless (or desktop-first-buffer (< desktop-file-version 206))
(if (consp desktop-buffer-mark)
(progn
(move-marker (mark-marker) (car desktop-buffer-mark))
- ;; FIXME: Should we call (de)activate-mark instead?
- (setq mark-active (car (cdr desktop-buffer-mark))))
+ (if (car (cdr desktop-buffer-mark))
+ (activate-mark 'dont-touch-tmm)))
(move-marker (mark-marker) desktop-buffer-mark)))
;; Never override file system if the file really is read-only marked.
(when desktop-buffer-read-only (setq buffer-read-only desktop-buffer-read-only))
(setq command-line-args (delete key command-line-args))
(desktop-save-mode 0)))
(when desktop-save-mode
- (desktop-read)
- (setq inhibit-startup-screen t))))
+ ;; People don't expect emacs -nw, or --daemon,
+ ;; to create graphical frames (bug#17693).
+ ;; TODO perhaps there should be a separate value
+ ;; for desktop-restore-frames to control this startup behavior?
+ (let ((desktop-restore-frames (and desktop-restore-frames
+ initial-window-system
+ (not (daemonp)))))
+ (desktop-read)
+ (setq inhibit-startup-screen t)))))
;; So we can restore vc-dir buffers.
(autoload 'vc-dir-mode "vc-dir" nil t)