]> git.eshelyaron.com Git - emacs.git/commitdiff
Respect global-eldoc-mode in minibuffers (Bug#36886)
authorNoam Postavsky <npostavs@gmail.com>
Sun, 4 Aug 2019 00:19:31 +0000 (20:19 -0400)
committerNoam Postavsky <npostavs@gmail.com>
Wed, 21 Aug 2019 00:20:52 +0000 (20:20 -0400)
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Accept
a BODY parameter.
* doc/lispref/modes.texi (Defining Minor Modes): Document new
parameter.
* etc/NEWS: Announce it.

* lisp/simple.el (read--expression): Move eldoc-mode setup to...
* lisp/emacs-lisp/eldoc.el (eldoc--eval-expression-setup): ... here,
new function.
(global-eldoc-mode): Add or remove it to
eval-expression-minibuffer-setup-hook when enabling or disabling
global-eldoc-mode.  This enables eldoc in the minibuffer (solving
Bug#27202), only when global-eldoc-mode is enabled.

doc/lispref/modes.texi
etc/NEWS
lisp/emacs-lisp/easy-mmode.el
lisp/emacs-lisp/eldoc.el
lisp/simple.el

index 764a67e3627414d7e70692d3d14f647113eb2f5a..7185c243e24f584b01d0d921aa55375bace59ace 100644 (file)
@@ -1783,12 +1783,12 @@ don't need any.
         (hungry-electric-delete t)))))
 @end smallexample
 
-@defmac define-globalized-minor-mode global-mode mode turn-on keyword-args@dots{}
+@defmac define-globalized-minor-mode global-mode mode turn-on keyword-args@dots{} body@dots{}
 This defines a global toggle named @var{global-mode} whose meaning is
 to enable or disable the buffer-local minor mode @var{mode} in all
-buffers.  To turn on the minor mode in a buffer, it uses the function
-@var{turn-on}; to turn off the minor mode, it calls @var{mode} with
-@minus{}1 as argument.
+buffers.  It also executes the @var{body} forms.  To turn on the minor
+mode in a buffer, it uses the function @var{turn-on}; to turn off the
+minor mode, it calls @var{mode} with @minus{}1 as argument.
 
 Globally enabling the mode also affects buffers subsequently created
 by visiting files, and buffers that use a major mode other than
index 7c329f0044a23c27b9fabe3520064b3fcfa22588..9f25cf4af51aa938aaa9d7c699cf8deafb396349 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2569,6 +2569,9 @@ subr.el so that it is available by default.  It now always returns the
 non-nil argument when the other is nil.  Several duplicates of 'xor'
 in other packages are now obsolete aliases of 'xor'.
 
++++
+** 'define-globalized-minor-mode' now takes BODY forms.
+
 \f
 * Changes in Emacs 27.1 on Non-Free Operating Systems
 
index be531aab849dda40b410d54641d65c73b0e64a65..bbc3a27504c5a9ed4cade0931d37fa7664ed2836 100644 (file)
@@ -363,18 +363,21 @@ No problems result if this variable is not bound.
 ;;;###autoload
 (defalias 'define-global-minor-mode 'define-globalized-minor-mode)
 ;;;###autoload
-(defmacro define-globalized-minor-mode (global-mode mode turn-on &rest keys)
+(defmacro define-globalized-minor-mode (global-mode mode turn-on &rest body)
   "Make a global mode GLOBAL-MODE corresponding to buffer-local minor MODE.
 TURN-ON is a function that will be called with no args in every buffer
   and that should try to turn MODE on if applicable for that buffer.
-KEYS is a list of CL-style keyword arguments.  As the minor mode
-  defined by this function is always global, any :global keyword is
-  ignored.  Other keywords have the same meaning as in `define-minor-mode',
-  which see.  In particular, :group specifies the custom group.
-  The most useful keywords are those that are passed on to the
-  `defcustom'.  It normally makes no sense to pass the :lighter
-  or :keymap keywords to `define-globalized-minor-mode', since these
-  are usually passed to the buffer-local version of the minor mode.
+Each of KEY VALUE is a pair of CL-style keyword arguments.  As
+  the minor mode defined by this function is always global, any
+  :global keyword is ignored.  Other keywords have the same
+  meaning as in `define-minor-mode', which see.  In particular,
+  :group specifies the custom group.  The most useful keywords
+  are those that are passed on to the `defcustom'.  It normally
+  makes no sense to pass the :lighter or :keymap keywords to
+  `define-globalized-minor-mode', since these are usually passed
+  to the buffer-local version of the minor mode.
+BODY contains code to execute each time the mode is enabled or disabled.
+  It is executed after toggling the mode, and before running GLOBAL-MODE-hook.
 
 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
@@ -384,7 +387,9 @@ 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."
+on if the hook has explicitly disabled it.
+
+\(fn GLOBAL-MODE MODE TURN-ON [KEY VALUE]... BODY...)"
   (declare (doc-string 2))
   (let* ((global-mode-name (symbol-name global-mode))
         (mode-name (symbol-name mode))
@@ -404,12 +409,12 @@ on if the hook has explicitly disabled it."
         keyw)
 
     ;; Check keys.
-    (while (keywordp (setq keyw (car keys)))
-      (setq keys (cdr keys))
+    (while (keywordp (setq keyw (car body)))
+      (pop body)
       (pcase keyw
-       (:group (setq group (nconc group (list :group (pop keys)))))
-       (:global (setq keys (cdr keys)))
-       (_ (push keyw extra-keywords) (push (pop keys) extra-keywords))))
+        (:group (setq group (nconc group (list :group (pop body)))))
+        (:global (pop body))
+        (_ (push keyw extra-keywords) (push (pop body) extra-keywords))))
 
     `(progn
        (progn
@@ -446,7 +451,8 @@ See `%s' for more information on %s."
         ;; Go through existing buffers.
         (dolist (buf (buffer-list))
           (with-current-buffer buf
-            (if ,global-mode (funcall #',turn-on) (when ,mode (,mode -1))))))
+             (if ,global-mode (funcall #',turn-on) (when ,mode (,mode -1)))))
+         ,@body)
 
        ;; Autoloading define-globalized-minor-mode autoloads everything
        ;; up-to-here.
index 16b58632099049c18f2a0c987ec51bd02324fa59..2892faae21d4c39c7b166ac821732ff95f48de77 100644 (file)
@@ -207,7 +207,24 @@ expression point is on."
 (define-globalized-minor-mode global-eldoc-mode eldoc-mode turn-on-eldoc-mode
   :group 'eldoc
   :initialize 'custom-initialize-delay
-  :init-value t)
+  :init-value t
+  ;; For `read--expression', the usual global mode mechanism of
+  ;; `change-major-mode-hook' runs in the minibuffer before
+  ;; `eldoc-documentation-function' is set, so `turn-on-eldoc-mode'
+  ;; does nothing.  Configure and enable eldoc from
+  ;; `eval-expression-minibuffer-setup-hook' instead.
+  (if global-eldoc-mode
+      (add-hook 'eval-expression-minibuffer-setup-hook
+                #'eldoc--eval-expression-setup)
+    (remove-hook 'eval-expression-minibuffer-setup-hook
+                 #'eldoc--eval-expression-setup)))
+
+(defun eldoc--eval-expression-setup ()
+  ;; Setup `eldoc', similar to `emacs-lisp-mode'.  FIXME: Call
+  ;; `emacs-lisp-mode' itself?
+  (add-function :before-until (local 'eldoc-documentation-function)
+                #'elisp-eldoc-documentation-function)
+  (eldoc-mode +1))
 
 ;;;###autoload
 (defun turn-on-eldoc-mode ()
index 84497c31b254863ef5176f07daf52c86a78b11bb..9f86d70f8471349757c89ad2ba42198111deb5af 100644 (file)
@@ -1587,10 +1587,8 @@ display the result of expression evaluation."
   (let ((minibuffer-completing-symbol t))
     (minibuffer-with-setup-hook
         (lambda ()
-          ;; FIXME: call emacs-lisp-mode?
-          (add-function :before-until (local 'eldoc-documentation-function)
-                        #'elisp-eldoc-documentation-function)
-          (eldoc-mode 1)
+          ;; FIXME: call emacs-lisp-mode (see also
+          ;; `eldoc--eval-expression-setup')?
           (add-hook 'completion-at-point-functions
                     #'elisp-completion-at-point nil t)
           (run-hooks 'eval-expression-minibuffer-setup-hook))