[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A few questions about desktop.el
From: |
Lars Hansen |
Subject: |
Re: A few questions about desktop.el |
Date: |
Wed, 10 Aug 2005 11:50:34 +0200 |
User-agent: |
Debian Thunderbird 1.0.2 (X11/20050331) |
Juanma Barranquero wrote:
>Anyway, I'd prefer not to make many changes to desktop.el (even quite
>non-intrusive changes like these) until Lars returns from holidays, as
>he said he would take a look at some questions I posed. I'll post a
>patch as soon as I've got it ready, and wait for him.
>
>
Shall I install the attached patch?
*** /home/lh/cvsroot/emacs/lisp/desktop.el.~1.90.~ 2005-08-08
14:15:26.000000000 +0200
--- /home/lh/cvsroot/emacs/lisp/desktop.el 2005-08-10 11:38:08.519228192
+0200
***************
*** 51,63 ****
;; function is added to the `after-init-hook'. This function is
;; responsible for loading the desktop when Emacs is started.
! ;; Some words on minor modes: Most minor modes are controlled by
! ;; buffer-local variables, which have a standard save / restore
! ;; mechanism. To handle all minor modes, we take the following
! ;; approach: (1) check whether the variable name from
! ;; `minor-mode-alist' is also a function; and (2) use translation
! ;; table `desktop-minor-mode-table' in the case where the two names
! ;; are not the same.
;; By the way: don't use desktop.el to customize Emacs -- the file .emacs
;; in your home directory is used for that. Saving global default values
--- 51,116 ----
;; function is added to the `after-init-hook'. This function is
;; responsible for loading the desktop when Emacs is started.
! ;; Special handling.
! ;; -----------------
! ;; Variables `desktop-buffer-mode-handlers' and `desktop-minor-mode-handlers'
! ;; are supplied to handle special major and minor modes respectively.
! ;; `desktop-buffer-mode-handlers' is an alist of major mode specific functions
! ;; to restore a desktop buffer. Elements must have the form
! ;;
! ;; (MAJOR-MODE . RESTORE-BUFFER-FUNCTION).
! ;;
! ;; Functions listed are called by `desktop-create-buffer' when `desktop-read'
! ;; evaluates the desktop file. Buffers with a major mode not specified here,
! ;; are restored by the default handler `desktop-restore-file-buffer'.
! ;; `desktop-minor-mode-handlers' is an alist of functions to restore
! ;; non-standard minor modes. Elements must have the form
! ;;
! ;; (MINOR-MODE . RESTORE-FUNCTION).
! ;;
! ;; Functions are called by `desktop-create-buffer' to restore minor modes.
! ;; Minor modes not specified here, are restored by the standard minor mode
! ;; function. If you write a module that defines a major or minor mode that
! ;; needs a special handler, then place code like
!
! ;; (defun foo-restore-desktop-buffer
! ;; ...
! ;; (add-to-list 'desktop-buffer-mode-handlers
! ;; '(foo-mode . foo-restore-desktop-buffer))
!
! ;; or
!
! ;; (defun bar-desktop-restore
! ;; ...
! ;; (add-to-list 'desktop-minor-mode-handlers
! ;; '(bar-mode . bar-desktop-restore))
!
! ;; in the module itself, and make shure that the mode function is
! ;; autoloaded. See the docstrings of `desktop-buffer-mode-handlers' and
! ;; `desktop-minor-mode-handlers' for more info.
!
! ;; Minor modes.
! ;; ------------
! ;; Conventional minor modes (see node "Minor Mode Conventions" in the elisp
! ;; manual) are handled in the following way:
! ;; When `desktop-save' saves the state of a buffer to the desktop file, it
! ;; saves as `desktop-minor-modes' the list of names of those variables in
! ;; `minor-mode-alist' that have a non-nil value.
! ;; When `desktop-create' restores the buffer, each of the symbols in
! ;; `desktop-minor-modes' is called as function with parameter 1.
! ;; The variables `desktop-minor-mode-table' and `desktop-minor-mode-handlers'
! ;; are used to handle non-conventional minor modes. `desktop-save' uses
! ;; `desktop-minor-mode-table' to map minor mode variables to minor mode
! ;; functions before writing `desktop-minor-modes'. If a minor mode has a
! ;; variable name that is different form its function name, an entry
!
! ;; (NAME RESTORE-FUNCTION)
!
! ;; should be added to `desktop-minor-mode-table'. If a minor mode should not
! ;; be restored, RESTORE-FUNCTION should be set to nil. `desktop-create' uses
! ;; `desktop-minor-mode-handlers' to lookup minor modes that needs a restore
! ;; function different from the usual minor mode function.
! ;; ---------------------------------------------------------------------------
;; By the way: don't use desktop.el to customize Emacs -- the file .emacs
;; in your home directory is used for that. Saving global default values
***************
*** 207,226 ****
:group 'desktop
:version "22.1")
! (defcustom desktop-clear-preserve-buffers-regexp
! "^\\(\\*scratch\\*\\|\\*Messages\\*\\|\\*server\\*\\|\\*tramp/.+\\*\\)$"
! "Regexp identifying buffers that `desktop-clear' should not delete.
! See also `desktop-clear-preserve-buffers'."
! :type 'regexp
! :group 'desktop
! :version "22.1")
!
! (defcustom desktop-clear-preserve-buffers nil
! "*List of buffer names that `desktop-clear' should not delete.
! See also `desktop-clear-preserve-buffers-regexp'."
:type '(repeat string)
:group 'desktop)
(defcustom desktop-locals-to-save
'(desktop-locals-to-save ; Itself! Think it over.
truncate-lines
--- 260,274 ----
:group 'desktop
:version "22.1")
! (defcustom desktop-clear-preserve-buffers
! '("\\*scratch\\*" "\\*Messages\\*" "\\*server\\*" "\\*tramp/.+\\*")
! "*List of buffers that `desktop-clear' should not delete.
! Each element is a regular expression. Buffers with a name matched by any of
! these won't be deleted."
:type '(repeat string)
:group 'desktop)
+ ;;;###autoload
(defcustom desktop-locals-to-save
'(desktop-locals-to-save ; Itself! Think it over.
truncate-lines
***************
*** 230,241 ****
overwrite-mode
change-log-default-name
line-number-mode
! buffer-file-coding-system)
"List of local variables to save for each buffer.
! The variables are saved only when they really are local."
:type '(repeat symbol)
:group 'desktop)
- (make-variable-buffer-local 'desktop-locals-to-save)
;; We skip .log files because they are normally temporary.
;; (ftp) files because they require passwords and whatnot.
--- 278,295 ----
overwrite-mode
change-log-default-name
line-number-mode
! column-number-mode
! size-indication-mode
! buffer-file-coding-system
! indent-tabs-mode
! indicate-buffer-boundaries
! indicate-empty-lines
! show-trailing-whitespace)
"List of local variables to save for each buffer.
! The variables are saved only when they really are local. Conventional minor
! modes are restored automatically; they should not be listed here."
:type '(repeat symbol)
:group 'desktop)
;; We skip .log files because they are normally temporary.
;; (ftp) files because they require passwords and whatnot.
***************
*** 301,323 ****
When file names are returned, they should be formatted using the call
\"(desktop-file-name FILE-NAME DESKTOP-DIRNAME)\".
! Later, when `desktop-read' calls a function in `desktop-buffer-mode-handlers'
! to restore the buffer, the auxiliary information is passed as the argument
! DESKTOP-BUFFER-MISC.")
(make-variable-buffer-local 'desktop-save-buffer)
(make-obsolete-variable 'desktop-buffer-modes-to-save
'desktop-save-buffer "22.1")
(make-obsolete-variable 'desktop-buffer-misc-functions
'desktop-save-buffer "22.1")
! (defcustom desktop-buffer-mode-handlers
! '((dired-mode . dired-restore-desktop-buffer)
! (rmail-mode . rmail-restore-desktop-buffer)
! (mh-folder-mode . mh-restore-desktop-buffer)
! (Info-mode . Info-restore-desktop-buffer))
"Alist of major mode specific functions to restore a desktop buffer.
! Functions are called by `desktop-read'. List elements must have the form
! \(MAJOR-MODE . RESTORE-BUFFER-FUNCTION).
Buffers with a major mode not specified here, are restored by the default
handler `desktop-restore-file-buffer'.
--- 355,377 ----
When file names are returned, they should be formatted using the call
\"(desktop-file-name FILE-NAME DESKTOP-DIRNAME)\".
! Later, when `desktop-read' evaluates the desktop file, auxiliary information
! is passed as the argument DESKTOP-BUFFER-MISC to functions in
! `desktop-buffer-mode-handlers'.")
(make-variable-buffer-local 'desktop-save-buffer)
(make-obsolete-variable 'desktop-buffer-modes-to-save
'desktop-save-buffer "22.1")
(make-obsolete-variable 'desktop-buffer-misc-functions
'desktop-save-buffer "22.1")
! ;;;###autoload
! (defvar desktop-buffer-mode-handlers
! nil
"Alist of major mode specific functions to restore a desktop buffer.
! Functions listed are called by `desktop-create-buffer' when `desktop-read'
! evaluates the desktop file. List elements must have the form
!
! (MAJOR-MODE . RESTORE-BUFFER-FUNCTION).
Buffers with a major mode not specified here, are restored by the default
handler `desktop-restore-file-buffer'.
***************
*** 337,345 ****
desktop-buffer-locals
If a handler returns a buffer, then the saved mode settings
! and variable values for that buffer are copied into it."
! :type 'alist
! :group 'desktop)
(put 'desktop-buffer-mode-handlers 'risky-local-variable t)
(make-obsolete-variable 'desktop-buffer-handlers
--- 391,407 ----
desktop-buffer-locals
If a handler returns a buffer, then the saved mode settings
! and variable values for that buffer are copied into it.
!
! Modules that define a major mode that needs a special handler should contain
! code like
!
! (defun foo-restore-desktop-buffer
! ...
! (add-to-list 'desktop-buffer-mode-handlers
! '(foo-mode . foo-restore-desktop-buffer))
!
! Furthermore the major mode function must be autoloaded.")
(put 'desktop-buffer-mode-handlers 'risky-local-variable t)
(make-obsolete-variable 'desktop-buffer-handlers
***************
*** 355,364 ****
called. RESTORE-FUNCTION nil means don't try to restore the minor mode.
Only minor modes for which the name of the buffer-local variable
and the name of the minor mode function are different have to be added to
! this table."
:type 'sexp
:group 'desktop)
;;
----------------------------------------------------------------------------
(defvar desktop-dirname nil
"The directory in which the desktop file should be saved.")
--- 417,472 ----
called. RESTORE-FUNCTION nil means don't try to restore the minor mode.
Only minor modes for which the name of the buffer-local variable
and the name of the minor mode function are different have to be added to
! this table. See also `desktop-minor-mode-handlers'."
:type 'sexp
:group 'desktop)
+ ;;;###autoload
+ (defvar desktop-minor-mode-handlers
+ nil
+ "Alist of functions to restore non-standard minor modes.
+ Functions are called by `desktop-create-buffer' to restore minor modes.
+ List elements must have the form
+
+ (MINOR-MODE . RESTORE-FUNCTION).
+
+ Minor modes not specified here, are restored by the standard minor mode
+ function.
+
+ Handlers are called with argument list
+
+ (DESKTOP-BUFFER-LOCALS)
+
+ Furthermore, they may use the following variables:
+
+ desktop-file-version
+ desktop-buffer-file-name
+ desktop-buffer-name
+ desktop-buffer-major-mode
+ desktop-buffer-minor-modes
+ desktop-buffer-point
+ desktop-buffer-mark
+ desktop-buffer-read-only
+ desktop-buffer-misc
+
+ When a handler is called, the buffer has been created and the major mode has
+ been set, but local variables listed in desktop-buffer-locals has not yet been
+ created and set.
+
+ Modules that define a minor mode that needs a special handler should contain
+ code like
+
+ (defun foo-desktop-restore
+ ...
+ (add-to-list 'desktop-minor-mode-handlers
+ '(foo-mode . foo-desktop-restore))
+
+ Furthermore the minor mode function must be autoloaded.
+
+ See also `desktop-minor-mode-table'.")
+
+ (put 'desktop-minor-mode-handlers 'risky-local-variable t)
+
;;
----------------------------------------------------------------------------
(defvar desktop-dirname nil
"The directory in which the desktop file should be saved.")
***************
*** 382,404 ****
;;
----------------------------------------------------------------------------
(defun desktop-clear ()
"Empty the Desktop.
! This kills all buffers except for internal ones and those matching
! `desktop-clear-preserve-buffers-regexp' or listed in
! `desktop-clear-preserve-buffers'. Furthermore, it clears the
! variables listed in `desktop-globals-to-clear'."
(interactive)
(desktop-lazy-abort)
(dolist (var desktop-globals-to-clear)
(if (symbolp var)
(eval `(setq-default ,var nil))
(eval `(setq-default ,(car var) ,(cdr var)))))
! (let ((buffers (buffer-list)))
(while buffers
(let ((bufname (buffer-name (car buffers))))
(or
(null bufname)
! (string-match desktop-clear-preserve-buffers-regexp bufname)
! (member bufname desktop-clear-preserve-buffers)
;; Don't kill buffers made for internal purposes.
(and (not (equal bufname "")) (eq (aref bufname 0) ?\s))
(kill-buffer (car buffers))))
--- 490,516 ----
;;
----------------------------------------------------------------------------
(defun desktop-clear ()
"Empty the Desktop.
! This kills all buffers except for internal ones and those with names matched
by
! a regular expression in the list `desktop-clear-preserve-buffers'.
! Furthermore, it clears the variables listed in `desktop-globals-to-clear'."
(interactive)
(desktop-lazy-abort)
(dolist (var desktop-globals-to-clear)
(if (symbolp var)
(eval `(setq-default ,var nil))
(eval `(setq-default ,(car var) ,(cdr var)))))
! (let ((buffers (buffer-list))
! (preserve-regexp (concat "^\\("
! (mapconcat (lambda (regexp)
! (concat "\\(" regexp "\\)"))
! desktop-clear-preserve-buffers
! "\\|")
! "\\)$")))
(while buffers
(let ((bufname (buffer-name (car buffers))))
(or
(null bufname)
! (string-match preserve-regexp bufname)
;; Don't kill buffers made for internal purposes.
(and (not (equal bufname "")) (eq (aref bufname 0) ?\s))
(kill-buffer (car buffers))))
***************
*** 622,633 ****
(and
(boundp minor-mode)
(symbol-value minor-mode)
! (let ((special (assq minor-mode
desktop-minor-mode-table)))
! (when (or special (functionp minor-mode))
! (setq ret
! (cons
! (if special (cadr special) minor-mode)
! ret))))))
(mapcar #'car minor-mode-alist))
ret)
(point)
--- 734,743 ----
(and
(boundp minor-mode)
(symbol-value minor-mode)
! (let* ((special (assq minor-mode
desktop-minor-mode-table))
! (value (cond (special (cadr special))
! ((functionp minor-mode)
minor-mode))))
! (when value (add-to-list 'ret value)))))
(mapcar #'car minor-mode-alist))
ret)
(point)
***************
*** 685,691 ****
(insert ")\n\n")))
info)
(setq default-directory dirname)
- (when (file-exists-p filename) (delete-file filename))
(let ((coding-system-for-write 'emacs-mule))
(write-region (point-min) (point-max) filename nil 'nomessage))))
(setq desktop-dirname dirname))
--- 795,800 ----
***************
*** 850,862 ****
buf)
nil)))
;;
----------------------------------------------------------------------------
;; Create a buffer, load its file, set its mode, ...;
;; called from Desktop file only.
! (eval-when-compile ; Just to silence the byte compiler
! (defvar desktop-first-buffer) ;; Dynamically bound in `desktop-read'
! )
(defun desktop-create-buffer
(desktop-file-version
--- 959,978 ----
buf)
nil)))
+ (defun desktop-load-file (function)
+ "Load the file where auto loaded FUNCTION is defined."
+ (let ((fcell (symbol-function function)))
+ (when (and (listp fcell)
+ (eq 'autoload (car fcell)))
+ (load (cadr fcell)))))
+
;;
----------------------------------------------------------------------------
;; Create a buffer, load its file, set its mode, ...;
;; called from Desktop file only.
! ;; Just to silence the byte compiler.
! (eval-when-compile
! (defvar desktop-first-buffer)) ; Dynamically bound in `desktop-read'
(defun desktop-create-buffer
(desktop-file-version
***************
*** 877,882 ****
--- 993,1000 ----
;; To make desktop files with relative file names possible, we cannot
;; allow `default-directory' to change. Therefore we save current buffer.
(save-current-buffer
+ ;; Give major mode module a chance to add a handler.
+ (desktop-load-file desktop-buffer-major-mode)
(let ((buffer-list (buffer-list))
(result
(condition-case err
***************
*** 914,922 ****
(auto-fill-mode 0))
(t
(mapc #'(lambda (minor-mode)
! (when (functionp minor-mode) (funcall minor-mode 1)))
desktop-buffer-minor-modes)))
! ;; Even though point and mark are non-nil when written by
`desktop-save'
;; they may be modified by handlers wanting to set point or mark
themselves.
(when desktop-buffer-point
(goto-char
--- 1032,1046 ----
(auto-fill-mode 0))
(t
(mapc #'(lambda (minor-mode)
! ;; Give minor mode module a chance to add a handler.
! (desktop-load-file minor-mode)
! (let ((handler (cdr (assq minor-mode
desktop-minor-mode-handlers))))
! (if handler
! (funcall handler desktop-buffer-locals)
! (when (functionp minor-mode)
! (funcall minor-mode 1)))))
desktop-buffer-minor-modes)))
! ;; Even though point and mark are non-nil when written by
`desktop-save',
;; they may be modified by handlers wanting to set point or mark
themselves.
(when desktop-buffer-point
(goto-char
*** /home/lh/cvsroot/emacs/lisp/hilit-chg.el.~1.34.~ 2005-08-08
14:15:26.000000000 +0200
--- /home/lh/cvsroot/emacs/lisp/hilit-chg.el 2005-08-09 08:17:02.000000000
+0200
***************
*** 673,678 ****
--- 673,679 ----
(if new-highlight-changes-mode
;; mode is turned on -- but may be passive
(progn
+ (add-to-list 'desktop-locals-to-save 'highlight-changes-mode)
(hilit-chg-set new-highlight-changes-mode)
(or was-on
;; run highlight-changes-enable-hook once
***************
*** 1154,1159 ****
--- 1155,1170 ----
)))
(buffer-list)))
+ ;;;; Desktop support.
+
+ ;; Called by `desktop-create-buffer' to restore `highlight-changes-mode'.
+ (defun hilit-chg-desktop-restore (desktop-buffer-locals)
+ (highlight-changes-mode
+ (or (cdr (assq 'highlight-changes-mode desktop-buffer-locals)) 1)))
+
+ (add-to-list 'desktop-minor-mode-handlers
+ '(highlight-changes-mode . hilit-chg-desktop-restore))
+
;; ===================== debug ==================
;; For debug & test use:
;;
*** /home/lh/cvsroot/emacs/lisp/dired.el.~1.322.~ 2005-08-08
14:15:26.000000000 +0200
--- /home/lh/cvsroot/emacs/lisp/dired.el 2005-08-09 08:16:24.000000000
+0200
***************
*** 1469,1474 ****
--- 1469,1476 ----
;; Dired mode is suitable only for specially formatted data.
(put 'dired-mode 'mode-class 'special)
+ ;; Autoload cookie needed by desktop.el
+ ;;;###autoload
(defun dired-mode (&optional dirname switches)
"\
Mode for \"editing\" directory listings.
***************
*** 3270,3276 ****
(function (lambda (f) (desktop-file-name (car f) desktop-dirname)))
dired-subdir-alist)))))
- ;;;###autoload
(defun dired-restore-desktop-buffer (desktop-buffer-file-name
desktop-buffer-name
desktop-buffer-misc)
--- 3272,3277 ----
***************
*** 3291,3296 ****
--- 3292,3300 ----
(when desktop-missing-file-warning (sit-for 1))
nil)))
+ (add-to-list 'desktop-buffer-mode-handlers
+ '(dired-mode . dired-restore-desktop-buffer))
+
(if (eq system-type 'vax-vms)
(load "dired-vms"))
*** /home/lh/cvsroot/emacs/lisp/info.el.~1.440.~ 2005-08-09
08:01:44.000000000 +0200
--- /home/lh/cvsroot/emacs/lisp/info.el 2005-08-09 08:17:47.000000000 +0200
***************
*** 3199,3204 ****
--- 3199,3206 ----
(defvar tool-bar-map)
+ ;; Autoload cookie needed by desktop.el
+ ;;;###autoload
(defun Info-mode ()
"Info mode provides commands for browsing through the Info documentation
tree.
Documentation in Info is divided into \"nodes\", each of which discusses
***************
*** 4168,4174 ****
(if (not (member Info-current-file '("apropos" "history" "toc")))
(list Info-current-file Info-current-node)))
- ;;;###autoload
(defun Info-restore-desktop-buffer (desktop-buffer-file-name
desktop-buffer-name
desktop-buffer-misc)
--- 4170,4175 ----
***************
*** 4182,4187 ****
--- 4183,4191 ----
(Info-find-node first second)
(current-buffer))))
+ (add-to-list 'desktop-buffer-mode-handlers
+ '(Info-mode . Info-restore-desktop-buffer))
+
(provide 'info)
;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
*** /home/lh/cvsroot/emacs/lisp/mail/rmail.el.~1.407.~ 2005-08-08
14:15:19.000000000 +0200
--- /home/lh/cvsroot/emacs/lisp/mail/rmail.el 2005-08-09 08:19:09.000000000
+0200
***************
*** 4058,4064 ****
;;;; Desktop support
- ;;;###autoload
(defun rmail-restore-desktop-buffer (desktop-buffer-file-name
desktop-buffer-name
desktop-buffer-misc)
--- 4058,4063 ----
***************
*** 4073,4078 ****
--- 4072,4080 ----
(kill-buffer (current-buffer))
nil)))
+ (add-to-list 'desktop-buffer-mode-handlers
+ '(rmail-mode . rmail-restore-desktop-buffer))
+
(provide 'rmail)
;;; arch-tag: cff0a950-57fe-4f73-a86e-91ff75afd06c
*** /home/lh/cvsroot/emacs/lisp/mh-e/mh-e.el.~1.20.~ 2005-07-12
15:25:36.000000000 +0200
--- /home/lh/cvsroot/emacs/lisp/mh-e/mh-e.el 2005-08-09 08:18:27.000000000
+0200
***************
*** 1507,1512 ****
--- 1507,1514 ----
(not (member 'mh-folder-mode which-func-modes)))
(push 'mh-folder-mode which-func-modes))
+ ;; Autoload cookie needed by desktop.el
+ ;;;###autoload
(define-derived-mode mh-folder-mode fundamental-mode "MH-Folder"
"Major MH-E mode for \"editing\" an MH folder scan
listing.\\<mh-folder-mode-map>
***************
*** 1653,1659 ****
(set (make-local-variable (car pairs)) (car (cdr pairs)))
(setq pairs (cdr (cdr pairs)))))
- ;;;###autoload
(defun mh-restore-desktop-buffer (desktop-buffer-file-name
desktop-buffer-name
desktop-buffer-misc)
--- 1655,1660 ----
***************
*** 1666,1671 ****
--- 1667,1675 ----
(mh-visit-folder desktop-buffer-name)
(current-buffer))
+ (add-to-list 'desktop-buffer-mode-handlers
+ '(mh-folder-mode . mh-restore-desktop-buffer))
+
(defun mh-scan-folder (folder range &optional dont-exec-pending)
"Scan the FOLDER over the RANGE.
If the optional argument DONT-EXEC-PENDING is non-nil then pending deletes and
- Re: A few questions about desktop.el, Lars Hansen, 2005/08/08
- Re: A few questions about desktop.el, Lars Hansen, 2005/08/08
- Re: A few questions about desktop.el,
Lars Hansen <=
- Re: A few questions about desktop.el, Juanma Barranquero, 2005/08/10
- Re: A few questions about desktop.el, Luc Teirlinck, 2005/08/10
- Re: A few questions about desktop.el, Luc Teirlinck, 2005/08/10
- Re: A few questions about desktop.el, Luc Teirlinck, 2005/08/10
- Re: A few questions about desktop.el, Luc Teirlinck, 2005/08/10
- Re: A few questions about desktop.el, Luc Teirlinck, 2005/08/10
- Re: A few questions about desktop.el, Lars Hansen, 2005/08/11