diff options
Diffstat (limited to 'lisp/emacs-lisp/easy-mmode.el')
-rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 9173d148c6a..abe7b1ea741 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -132,13 +132,14 @@ BODY contains code to execute each time the mode is enabled or disabled. :require SYM Same as in `defcustom'. :variable PLACE The location to use instead of the variable MODE to store the state of the mode. This can be simply a different - named variable, or more generally anything that can be used - with the CL macro `setf'. PLACE can also be of the form - \(GET . SET), where GET is an expression that returns the - current state, and SET is a function that takes one argument, - the new state, and sets it. If you specify a :variable, - this function does not define a MODE variable (nor any of - the terms used in :variable). + named variable, or a generalized variable. + PLACE can also be of the form \(GET . SET), where GET is + an expression that returns the current state, and SET is + a function that takes one argument, the new state, and + sets it. If you specify a :variable, this function does + not define a MODE variable (nor any of the terms used + in :variable). + :after-hook A single lisp form which is evaluated after the mode hooks have been run. It should not be quoted. @@ -340,9 +341,14 @@ If MODE's set-up depends on the major mode in effect when it was enabled, then disabling and reenabling MODE should make MODE work correctly with the current major mode. This is important to prevent problems with derived modes, that is, major modes that -call another major mode in their body." +call another major mode in their body. + +When a major mode is initialized, MODE is actually turned on just +after running the major mode's hook. However, MODE is not turned +on if the hook has explicitly disabled it." (declare (doc-string 2)) (let* ((global-mode-name (symbol-name global-mode)) + (mode-name (symbol-name mode)) (pretty-name (easy-mmode-pretty-mode-name mode)) (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) (group nil) @@ -353,6 +359,8 @@ call another major mode in their body." (MODE-check-buffers (intern (concat global-mode-name "-check-buffers"))) (MODE-cmhh (intern (concat global-mode-name "-cmhh"))) + (minor-MODE-hook (intern (concat mode-name "-hook"))) + (MODE-set-explicitly (intern (concat mode-name "-set-explicitly"))) (MODE-major-mode (intern (concat (symbol-name mode) "-major-mode"))) keyw) @@ -396,13 +404,9 @@ See `%s' for more information on %s." (progn (add-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers) - (add-hook 'change-major-mode-after-body-hook - ',MODE-enable-in-buffers) (add-hook 'find-file-hook ',MODE-check-buffers) (add-hook 'change-major-mode-hook ',MODE-cmhh)) (remove-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers) - (remove-hook 'change-major-mode-after-body-hook - ',MODE-enable-in-buffers) (remove-hook 'find-file-hook ',MODE-check-buffers) (remove-hook 'change-major-mode-hook ',MODE-cmhh)) @@ -415,6 +419,10 @@ See `%s' for more information on %s." ;; up-to-here. :autoload-end + ;; A function which checks whether MODE has been disabled in the major + ;; mode hook which has just been run. + (add-hook ',minor-MODE-hook ',MODE-set-explicitly) + ;; List of buffers left to process. (defvar ,MODE-buffers nil) @@ -423,14 +431,14 @@ See `%s' for more information on %s." (dolist (buf ,MODE-buffers) (when (buffer-live-p buf) (with-current-buffer buf - (unless (eq ,MODE-major-mode major-mode) - (if ,mode - (progn - (,mode -1) - (,turn-on) - (setq ,MODE-major-mode major-mode)) - (,turn-on) - (setq ,MODE-major-mode major-mode))))))) + (unless ,MODE-set-explicitly + (unless (eq ,MODE-major-mode major-mode) + (if ,mode + (progn + (,mode -1) + (,turn-on)) + (,turn-on)))) + (setq ,MODE-major-mode major-mode))))) (put ',MODE-enable-in-buffers 'definition-name ',global-mode) (defun ,MODE-check-buffers () @@ -443,24 +451,21 @@ See `%s' for more information on %s." (defun ,MODE-cmhh () (add-to-list ',MODE-buffers (current-buffer)) (add-hook 'post-command-hook ',MODE-check-buffers)) - (put ',MODE-cmhh 'definition-name ',global-mode)))) + (put ',MODE-cmhh 'definition-name ',global-mode) + ;; MODE-set-explicitly is set in MODE-set-explicitly and cleared by + ;; kill-all-local-variables. + (defvar-local ,MODE-set-explicitly nil) + (defun ,MODE-set-explicitly () + (setq ,MODE-set-explicitly t)) + (put ',MODE-set-explicitly 'definition-name ',global-mode)))) ;;; ;;; easy-mmode-defmap ;;; -(eval-and-compile - (if (fboundp 'set-keymap-parents) - (defalias 'easy-mmode-set-keymap-parents 'set-keymap-parents) - (defun easy-mmode-set-keymap-parents (m parents) - (set-keymap-parent - m - (cond - ((not (consp parents)) parents) - ((not (cdr parents)) (car parents)) - (t (let ((m (copy-keymap (pop parents)))) - (easy-mmode-set-keymap-parents m parents) - m))))))) +(defun easy-mmode-set-keymap-parents (m parents) + (set-keymap-parent + m (if (cdr parents) (make-composed-keymap parents) (car parents)))) ;;;###autoload (defun easy-mmode-define-keymap (bs &optional name m args) |