emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master db87b14: * lisp/desktop.el: If modes aren't autoloa


From: Glenn Morris
Subject: [Emacs-diffs] master db87b14: * lisp/desktop.el: If modes aren't autoloaded, try simple guesswork.
Date: Tue, 26 May 2015 06:28:19 +0000

branch: master
commit db87b14e7c9368e231fb0396bc4fd1aad56cf849
Author: Glenn Morris <address@hidden>
Commit: Glenn Morris <address@hidden>

    * lisp/desktop.el: If modes aren't autoloaded, try simple guesswork.
    
    (desktop-load-file): Guess that "foobar" defines "foobar-mode".
    (desktop-buffer-mode-handlers, desktop-minor-mode-handlers):
    Doc updates.
    (vc-dir-mode): Remove unnecessary autoload.
    
    ; Ref: http://debbugs.gnu.org/19226#14
---
 lisp/desktop.el |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/lisp/desktop.el b/lisp/desktop.el
index fb803b4..c168f9c 100644
--- a/lisp/desktop.el
+++ b/lisp/desktop.el
@@ -83,8 +83,10 @@
 ;;    (add-to-list 'desktop-minor-mode-handlers
 ;;                 '(bar-mode . bar-desktop-restore))
 
-;; in the module itself, and make sure that the mode function is
-;; autoloaded.  See the docstrings of `desktop-buffer-mode-handlers' and
+;; in the module itself.  The mode function must either be autoloaded,
+;; or of the form "foobar-mode" and defined in library "foobar", so that
+;; desktop can guess how to load its definition.
+;; See the docstrings of `desktop-buffer-mode-handlers' and
 ;; `desktop-minor-mode-handlers' for more info.
 
 ;; Minor modes.
@@ -520,7 +522,9 @@ code like
    (add-to-list 'desktop-buffer-mode-handlers
                 '(foo-mode . foo-restore-desktop-buffer))
 
-Furthermore the major mode function must be autoloaded.")
+The major mode function must either be autoloaded, or of the form
+\"foobar-mode\" and defined in library \"foobar\", so that desktop
+can guess how to load the mode's definition.")
 
 ;;;###autoload
 (put 'desktop-buffer-mode-handlers 'risky-local-variable t)
@@ -585,7 +589,9 @@ code like
    (add-to-list 'desktop-minor-mode-handlers
                 '(foo-mode . foo-desktop-restore))
 
-Furthermore the minor mode function must be autoloaded.
+The minor mode function must either be autoloaded, or of the form
+\"foobar-mode\" and defined in library \"foobar\", so that desktop
+can guess how to load the mode's definition.
 
 See also `desktop-minor-mode-table'.")
 
@@ -1352,9 +1358,18 @@ after that many seconds of idle time."
       nil)))
 
 (defun desktop-load-file (function)
-  "Load the file where auto loaded FUNCTION is defined."
-  (when (fboundp function)
-    (autoload-do-load (symbol-function function) function)))
+  "Load the file where auto loaded FUNCTION is defined.
+If FUNCTION is not currently defined, guess the library that defines it
+and try to load that."
+  (if (fboundp function)
+      (autoload-do-load (symbol-function function) function)
+    ;; Guess that foobar-mode is defined in foobar.
+    ;; TODO rather than guessing or requiring an autoload, the desktop
+    ;; file should record the name of the library.
+    (let ((name (symbol-name function)))
+      (if (string-match "\\`\\(.*\\)-mode\\'" name)
+          (with-demoted-errors "Require error in desktop-load-file: %S"
+              (require (intern (match-string 1 name)) nil t))))))
 
 ;; ----------------------------------------------------------------------------
 ;; Create a buffer, load its file, set its mode, ...;
@@ -1572,9 +1587,6 @@ If there are no buffers left to create, kill the timer."
         (desktop-read)
         (setq inhibit-startup-screen t)))))
 
-;; So we can restore vc-dir buffers.
-(autoload 'vc-dir-mode "vc-dir" nil t)
-
 (provide 'desktop)
 
 ;;; desktop.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]