; 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.
(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.")
(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'.