aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoam Postavsky2019-08-03 20:19:31 -0400
committerNoam Postavsky2019-08-20 20:20:52 -0400
commit7e2090ee80c9099ee953392444e1d73d10e973d4 (patch)
tree5fc7f91f27dd90b1b8e1a52ec8fb444de043c2ea
parent5a9552128296478ec74594b45d0728d87450197e (diff)
downloademacs-7e2090ee80c9099ee953392444e1d73d10e973d4.tar.gz
emacs-7e2090ee80c9099ee953392444e1d73d10e973d4.zip
Respect global-eldoc-mode in minibuffers (Bug#36886)
* 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.
-rw-r--r--doc/lispref/modes.texi8
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/emacs-lisp/easy-mmode.el38
-rw-r--r--lisp/emacs-lisp/eldoc.el19
-rw-r--r--lisp/simple.el6
5 files changed, 49 insertions, 25 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 764a67e3627..7185c243e24 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1783,12 +1783,12 @@ don't need any.
1783 (hungry-electric-delete t))))) 1783 (hungry-electric-delete t)))))
1784@end smallexample 1784@end smallexample
1785 1785
1786@defmac define-globalized-minor-mode global-mode mode turn-on keyword-args@dots{} 1786@defmac define-globalized-minor-mode global-mode mode turn-on keyword-args@dots{} body@dots{}
1787This defines a global toggle named @var{global-mode} whose meaning is 1787This defines a global toggle named @var{global-mode} whose meaning is
1788to enable or disable the buffer-local minor mode @var{mode} in all 1788to enable or disable the buffer-local minor mode @var{mode} in all
1789buffers. To turn on the minor mode in a buffer, it uses the function 1789buffers. It also executes the @var{body} forms. To turn on the minor
1790@var{turn-on}; to turn off the minor mode, it calls @var{mode} with 1790mode in a buffer, it uses the function @var{turn-on}; to turn off the
1791@minus{}1 as argument. 1791minor mode, it calls @var{mode} with @minus{}1 as argument.
1792 1792
1793Globally enabling the mode also affects buffers subsequently created 1793Globally enabling the mode also affects buffers subsequently created
1794by visiting files, and buffers that use a major mode other than 1794by visiting files, and buffers that use a major mode other than
diff --git a/etc/NEWS b/etc/NEWS
index 7c329f0044a..9f25cf4af51 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2569,6 +2569,9 @@ subr.el so that it is available by default. It now always returns the
2569non-nil argument when the other is nil. Several duplicates of 'xor' 2569non-nil argument when the other is nil. Several duplicates of 'xor'
2570in other packages are now obsolete aliases of 'xor'. 2570in other packages are now obsolete aliases of 'xor'.
2571 2571
2572+++
2573** 'define-globalized-minor-mode' now takes BODY forms.
2574
2572 2575
2573* Changes in Emacs 27.1 on Non-Free Operating Systems 2576* Changes in Emacs 27.1 on Non-Free Operating Systems
2574 2577
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index be531aab849..bbc3a27504c 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -363,18 +363,21 @@ No problems result if this variable is not bound.
363;;;###autoload 363;;;###autoload
364(defalias 'define-global-minor-mode 'define-globalized-minor-mode) 364(defalias 'define-global-minor-mode 'define-globalized-minor-mode)
365;;;###autoload 365;;;###autoload
366(defmacro define-globalized-minor-mode (global-mode mode turn-on &rest keys) 366(defmacro define-globalized-minor-mode (global-mode mode turn-on &rest body)
367 "Make a global mode GLOBAL-MODE corresponding to buffer-local minor MODE. 367 "Make a global mode GLOBAL-MODE corresponding to buffer-local minor MODE.
368TURN-ON is a function that will be called with no args in every buffer 368TURN-ON is a function that will be called with no args in every buffer
369 and that should try to turn MODE on if applicable for that buffer. 369 and that should try to turn MODE on if applicable for that buffer.
370KEYS is a list of CL-style keyword arguments. As the minor mode 370Each of KEY VALUE is a pair of CL-style keyword arguments. As
371 defined by this function is always global, any :global keyword is 371 the minor mode defined by this function is always global, any
372 ignored. Other keywords have the same meaning as in `define-minor-mode', 372 :global keyword is ignored. Other keywords have the same
373 which see. In particular, :group specifies the custom group. 373 meaning as in `define-minor-mode', which see. In particular,
374 The most useful keywords are those that are passed on to the 374 :group specifies the custom group. The most useful keywords
375 `defcustom'. It normally makes no sense to pass the :lighter 375 are those that are passed on to the `defcustom'. It normally
376 or :keymap keywords to `define-globalized-minor-mode', since these 376 makes no sense to pass the :lighter or :keymap keywords to
377 are usually passed to the buffer-local version of the minor mode. 377 `define-globalized-minor-mode', since these are usually passed
378 to the buffer-local version of the minor mode.
379BODY contains code to execute each time the mode is enabled or disabled.
380 It is executed after toggling the mode, and before running GLOBAL-MODE-hook.
378 381
379If MODE's set-up depends on the major mode in effect when it was 382If MODE's set-up depends on the major mode in effect when it was
380enabled, then disabling and reenabling MODE should make MODE work 383enabled, then disabling and reenabling MODE should make MODE work
@@ -384,7 +387,9 @@ call another major mode in their body.
384 387
385When a major mode is initialized, MODE is actually turned on just 388When a major mode is initialized, MODE is actually turned on just
386after running the major mode's hook. However, MODE is not turned 389after running the major mode's hook. However, MODE is not turned
387on if the hook has explicitly disabled it." 390on if the hook has explicitly disabled it.
391
392\(fn GLOBAL-MODE MODE TURN-ON [KEY VALUE]... BODY...)"
388 (declare (doc-string 2)) 393 (declare (doc-string 2))
389 (let* ((global-mode-name (symbol-name global-mode)) 394 (let* ((global-mode-name (symbol-name global-mode))
390 (mode-name (symbol-name mode)) 395 (mode-name (symbol-name mode))
@@ -404,12 +409,12 @@ on if the hook has explicitly disabled it."
404 keyw) 409 keyw)
405 410
406 ;; Check keys. 411 ;; Check keys.
407 (while (keywordp (setq keyw (car keys))) 412 (while (keywordp (setq keyw (car body)))
408 (setq keys (cdr keys)) 413 (pop body)
409 (pcase keyw 414 (pcase keyw
410 (:group (setq group (nconc group (list :group (pop keys))))) 415 (:group (setq group (nconc group (list :group (pop body)))))
411 (:global (setq keys (cdr keys))) 416 (:global (pop body))
412 (_ (push keyw extra-keywords) (push (pop keys) extra-keywords)))) 417 (_ (push keyw extra-keywords) (push (pop body) extra-keywords))))
413 418
414 `(progn 419 `(progn
415 (progn 420 (progn
@@ -446,7 +451,8 @@ See `%s' for more information on %s."
446 ;; Go through existing buffers. 451 ;; Go through existing buffers.
447 (dolist (buf (buffer-list)) 452 (dolist (buf (buffer-list))
448 (with-current-buffer buf 453 (with-current-buffer buf
449 (if ,global-mode (funcall #',turn-on) (when ,mode (,mode -1)))))) 454 (if ,global-mode (funcall #',turn-on) (when ,mode (,mode -1)))))
455 ,@body)
450 456
451 ;; Autoloading define-globalized-minor-mode autoloads everything 457 ;; Autoloading define-globalized-minor-mode autoloads everything
452 ;; up-to-here. 458 ;; up-to-here.
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 16b58632099..2892faae21d 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -207,7 +207,24 @@ expression point is on."
207(define-globalized-minor-mode global-eldoc-mode eldoc-mode turn-on-eldoc-mode 207(define-globalized-minor-mode global-eldoc-mode eldoc-mode turn-on-eldoc-mode
208 :group 'eldoc 208 :group 'eldoc
209 :initialize 'custom-initialize-delay 209 :initialize 'custom-initialize-delay
210 :init-value t) 210 :init-value t
211 ;; For `read--expression', the usual global mode mechanism of
212 ;; `change-major-mode-hook' runs in the minibuffer before
213 ;; `eldoc-documentation-function' is set, so `turn-on-eldoc-mode'
214 ;; does nothing. Configure and enable eldoc from
215 ;; `eval-expression-minibuffer-setup-hook' instead.
216 (if global-eldoc-mode
217 (add-hook 'eval-expression-minibuffer-setup-hook
218 #'eldoc--eval-expression-setup)
219 (remove-hook 'eval-expression-minibuffer-setup-hook
220 #'eldoc--eval-expression-setup)))
221
222(defun eldoc--eval-expression-setup ()
223 ;; Setup `eldoc', similar to `emacs-lisp-mode'. FIXME: Call
224 ;; `emacs-lisp-mode' itself?
225 (add-function :before-until (local 'eldoc-documentation-function)
226 #'elisp-eldoc-documentation-function)
227 (eldoc-mode +1))
211 228
212;;;###autoload 229;;;###autoload
213(defun turn-on-eldoc-mode () 230(defun turn-on-eldoc-mode ()
diff --git a/lisp/simple.el b/lisp/simple.el
index 84497c31b25..9f86d70f847 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1587,10 +1587,8 @@ display the result of expression evaluation."
1587 (let ((minibuffer-completing-symbol t)) 1587 (let ((minibuffer-completing-symbol t))
1588 (minibuffer-with-setup-hook 1588 (minibuffer-with-setup-hook
1589 (lambda () 1589 (lambda ()
1590 ;; FIXME: call emacs-lisp-mode? 1590 ;; FIXME: call emacs-lisp-mode (see also
1591 (add-function :before-until (local 'eldoc-documentation-function) 1591 ;; `eldoc--eval-expression-setup')?
1592 #'elisp-eldoc-documentation-function)
1593 (eldoc-mode 1)
1594 (add-hook 'completion-at-point-functions 1592 (add-hook 'completion-at-point-functions
1595 #'elisp-completion-at-point nil t) 1593 #'elisp-completion-at-point nil t)
1596 (run-hooks 'eval-expression-minibuffer-setup-hook)) 1594 (run-hooks 'eval-expression-minibuffer-setup-hook))