]> git.eshelyaron.com Git - emacs.git/commitdiff
(delayed-after-hook-functions): Tighten the code a bit
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 27 Dec 2017 22:49:39 +0000 (17:49 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 27 Dec 2017 22:49:39 +0000 (17:49 -0500)
* lisp/subr.el (delayed-mode-hooks, delayed-after-hook-functions):
Use defvar-local.
(run-mode-hooks): Reset delayed-after-hook-functions before running
those functions, in case an error is signaled.

* lisp/emacs-lisp/derived.el (define-derived-mode): Don't duplicate code.

lisp/emacs-lisp/derived.el
lisp/subr.el

index c0ef199424b2199563b3b3ee65057e6933199c1e..3bb8eb4f2f25d7249486703a30b470952f5aef6c 100644 (file)
@@ -281,12 +281,10 @@ No problems result if this variable is not bound.
                                        ; Splice in the body (if any).
          ,@body
          )
-        ;; Run the hooks, if any.
-         (run-mode-hooks ',hook)
-         ,@(when after-hook
-             `((if delay-mode-hooks
-                   (push (lambda () ,after-hook) delayed-after-hook-functions)
-                 ,after-hook)))))))
+        ,@(when after-hook
+            `((push (lambda () ,after-hook) delayed-after-hook-functions)))
+        ;; Run the hooks (and delayed-after-hook-functions), if any.
+        (run-mode-hooks ',hook)))))
 
 ;; PUBLIC: find the ultimate class of a derived mode.
 
index 67209b4d4f6c009c2bc4f9b8c221c1750d8c7639..76d7a1a556db5613afcc1990cd60046c4b5c9047 100644 (file)
@@ -1839,15 +1839,13 @@ if it is empty or a duplicate."
 
 (defvar delay-mode-hooks nil
   "If non-nil, `run-mode-hooks' should delay running the hooks.")
-(defvar delayed-mode-hooks nil
+(defvar-local delayed-mode-hooks nil
   "List of delayed mode hooks waiting to be run.")
-(make-variable-buffer-local 'delayed-mode-hooks)
 (put 'delay-mode-hooks 'permanent-local t)
 
-(defvar delayed-after-hook-functions nil
+(defvar-local delayed-after-hook-functions nil
   "List of delayed :after-hook forms waiting to be run.
 These forms come from `define-derived-mode'.")
-(make-variable-buffer-local 'delayed-after-hook-functions)
 
 (defvar change-major-mode-after-body-hook nil
   "Normal hook run in major mode functions, before the mode hooks.")
@@ -1889,9 +1887,9 @@ running their FOO-mode-hook."
         (with-demoted-errors "File local-variables error: %s"
           (hack-local-variables 'no-mode)))
     (run-hooks 'after-change-major-mode-hook)
-    (dolist (fun (nreverse delayed-after-hook-functions))
-      (funcall fun))
-    (setq delayed-after-hook-functions nil)))
+    (dolist (fun (prog1 (nreverse delayed-after-hook-functions)
+                    (setq delayed-after-hook-functions nil)))
+      (funcall fun))))
 
 (defmacro delay-mode-hooks (&rest body)
   "Execute BODY, but delay any `run-mode-hooks'.