aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/emacs/programs.texi24
-rw-r--r--etc/NEWS12
-rw-r--r--lisp/emacs-lisp/eldoc.el77
-rw-r--r--lisp/hexl.el6
-rw-r--r--lisp/ielm.el4
-rw-r--r--lisp/progmodes/cfengine.el15
-rw-r--r--lisp/progmodes/elisp-mode.el4
-rw-r--r--lisp/progmodes/octave.el3
-rw-r--r--lisp/progmodes/python.el6
9 files changed, 115 insertions, 36 deletions
diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi
index 683374c6153..865a3a67d56 100644
--- a/doc/emacs/programs.texi
+++ b/doc/emacs/programs.texi
@@ -1269,9 +1269,27 @@ information whenever there is a Lisp function or variable at point;
1269for a function, it shows the argument list, and for a variable it 1269for a function, it shows the argument list, and for a variable it
1270shows the first line of the variable's documentation string. To 1270shows the first line of the variable's documentation string. To
1271toggle Eldoc mode, type @kbd{M-x eldoc-mode}. There's also a Global 1271toggle Eldoc mode, type @kbd{M-x eldoc-mode}. There's also a Global
1272Eldoc mode, which is turned on by default, and affects buffers, such 1272Eldoc mode, which is turned on by default, and affects buffers whose
1273as @samp{*scratch*}, whose major mode is Emacs Lisp or Lisp 1273major mode sets the variables described below. Use @w{@kbd{M-x
1274Interaction (@w{@kbd{M-x global-eldoc-mode}} to turn it off globally). 1274global-eldoc-mode}} to turn it off globally.
1275
1276@vindex eldoc-documentation-function
1277@vindex eldoc-documentation-functions
1278 These variables can be used to configure ElDoc mode:
1279
1280@table @code
1281@item eldoc-documentation-function
1282This variable holds the function which is used to retrieve
1283documentation for the item at point from the functions in the hook
1284@code{eldoc-documentation-functions}. By default,
1285@code{eldoc-documentation-function} returns the first documentation
1286string produced by the @code{eldoc-documentation-functions} hook.
1287
1288@item eldoc-documentation-functions
1289This abnormal hook holds documentation functions. It acts as a
1290collection of backends for ElDoc. This is what modes should use to
1291register their documentation functions with ElDoc.
1292@end table
1275 1293
1276@node Hideshow 1294@node Hideshow
1277@section Hideshow minor mode 1295@section Hideshow minor mode
diff --git a/etc/NEWS b/etc/NEWS
index 54aab1a5b60..ee3a3c19e7c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -125,6 +125,18 @@ To revert to the previous behaviour,
125unconditionally aborts the current edebug instrumentation with the 125unconditionally aborts the current edebug instrumentation with the
126supplied error message. 126supplied error message.
127 127
128+++
129** ElDoc
130
131*** New hook 'eldoc-documentation-functions' to be used for registering
132doc string functions. This makes the results of all doc string
133functions accessible to the user through the existing single function hook
134'eldoc-documentation-function'.
135
136*** 'eldoc-documentation-function' is now a custom variable.
137Modes should use the new hook instead of this variable to register
138their backends.
139
128** Tramp 140** Tramp
129 141
130+++ 142+++
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 7a7b8ec1647..456a650828c 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -40,9 +40,9 @@
40;; (add-hook 'ielm-mode-hook 'eldoc-mode) 40;; (add-hook 'ielm-mode-hook 'eldoc-mode)
41;; (add-hook 'eval-expression-minibuffer-setup-hook 'eldoc-mode) 41;; (add-hook 'eval-expression-minibuffer-setup-hook 'eldoc-mode)
42 42
43;; Major modes for other languages may use ElDoc by defining an 43;; Major modes for other languages may use ElDoc by adding an
44;; appropriate function as the buffer-local value of 44;; appropriate function to the buffer-local value of
45;; `eldoc-documentation-function'. 45;; `eldoc-documentation-functions'.
46 46
47;;; Code: 47;;; Code:
48 48
@@ -222,8 +222,8 @@ expression point is on."
222(defun eldoc--eval-expression-setup () 222(defun eldoc--eval-expression-setup ()
223 ;; Setup `eldoc', similar to `emacs-lisp-mode'. FIXME: Call 223 ;; Setup `eldoc', similar to `emacs-lisp-mode'. FIXME: Call
224 ;; `emacs-lisp-mode' itself? 224 ;; `emacs-lisp-mode' itself?
225 (add-function :before-until (local 'eldoc-documentation-function) 225 (add-hook 'eldoc-documentation-functions
226 #'elisp-eldoc-documentation-function) 226 #'elisp-eldoc-documentation-function nil t)
227 (eldoc-mode +1)) 227 (eldoc-mode +1))
228 228
229;;;###autoload 229;;;###autoload
@@ -235,7 +235,11 @@ See `eldoc-documentation-function' for more detail."
235 235
236(defun eldoc--supported-p () 236(defun eldoc--supported-p ()
237 "Non-nil if an ElDoc function is set for this buffer." 237 "Non-nil if an ElDoc function is set for this buffer."
238 (not (memq eldoc-documentation-function '(nil ignore)))) 238 (let ((hook 'eldoc-documentation-functions))
239 (and (not (memq eldoc-documentation-function '(nil ignore)))
240 (or (and (local-variable-p hook)
241 (buffer-local-value hook (current-buffer)))
242 (default-value hook)))))
239 243
240 244
241(defun eldoc-schedule-timer () 245(defun eldoc-schedule-timer ()
@@ -347,8 +351,46 @@ Also store it in `eldoc-last-message' and return that value."
347 (not (or executing-kbd-macro (bound-and-true-p edebug-active)))) 351 (not (or executing-kbd-macro (bound-and-true-p edebug-active))))
348 352
349 353
350;;;###autoload 354(defvar eldoc-documentation-functions nil
351(defvar eldoc-documentation-function #'ignore 355 "Hook for functions to call to return doc string.
356Each function should accept no arguments and return a one-line
357string for displaying doc about a function etc. appropriate to
358the context around point. It should return nil if there's no doc
359appropriate for the context. Typically doc is returned if point
360is on a function-like name or in its arg list.
361
362Major modes should modify this hook locally, for example:
363 (add-hook \\='eldoc-documentation-functions #\\='foo-mode-eldoc nil t)
364so that the global value (i.e. the default value of the hook) is
365taken into account if the major mode specific function does not
366return any documentation.")
367
368(defun eldoc-documentation-default ()
369 "Show first doc string for item at point.
370Default value for `eldoc-documentation-function'."
371 (let ((res (run-hook-with-args-until-success 'eldoc-documentation-functions)))
372 (when res
373 (if eldoc-echo-area-use-multiline-p res
374 (truncate-string-to-width
375 res (1- (window-width (minibuffer-window))))))))
376
377(defun eldoc-documentation-compose ()
378 "Show multiple doc string results at once.
379Meant as a value for `eldoc-documentation-function'."
380 (let (res)
381 (run-hook-wrapped
382 'eldoc-documentation-functions
383 (lambda (f)
384 (let ((str (funcall f)))
385 (when str (push str res))
386 nil)))
387 (when res
388 (setq res (mapconcat #'identity (nreverse res) ", "))
389 (if eldoc-echo-area-use-multiline-p res
390 (truncate-string-to-width
391 res (1- (window-width (minibuffer-window))))))))
392
393(defcustom eldoc-documentation-function #'eldoc-documentation-default
352 "Function to call to return doc string. 394 "Function to call to return doc string.
353The function of no args should return a one-line string for displaying 395The function of no args should return a one-line string for displaying
354doc about a function etc. appropriate to the context around point. 396doc about a function etc. appropriate to the context around point.
@@ -359,14 +401,14 @@ arg list.
359The result is used as is, so the function must explicitly handle 401The result is used as is, so the function must explicitly handle
360the variables `eldoc-argument-case' and `eldoc-echo-area-use-multiline-p', 402the variables `eldoc-argument-case' and `eldoc-echo-area-use-multiline-p',
361and the face `eldoc-highlight-function-argument', if they are to have any 403and the face `eldoc-highlight-function-argument', if they are to have any
362effect. 404effect."
363 405 :link '(info-link "(emacs) Lisp Doc")
364Major modes should modify this variable using `add-function', for example: 406 :type '(radio (function-item eldoc-documentation-default)
365 (add-function :before-until (local \\='eldoc-documentation-function) 407 (function-item eldoc-documentation-compose)
366 #\\='foo-mode-eldoc-function) 408 (function :tag "Other function")
367so that the global documentation function (i.e. the default value of the 409 (const :tag "None" nil))
368variable) is taken into account if the major mode specific function does not 410 :version "28.1"
369return any documentation.") 411 :group 'eldoc)
370 412
371(defun eldoc-print-current-symbol-info () 413(defun eldoc-print-current-symbol-info ()
372 "Print the text produced by `eldoc-documentation-function'." 414 "Print the text produced by `eldoc-documentation-function'."
@@ -381,7 +423,8 @@ return any documentation.")
381 ;; Only keep looking for the info as long as the user hasn't 423 ;; Only keep looking for the info as long as the user hasn't
382 ;; requested our attention. This also locally disables inhibit-quit. 424 ;; requested our attention. This also locally disables inhibit-quit.
383 (while-no-input 425 (while-no-input
384 (eldoc-message (funcall eldoc-documentation-function))))))) 426 (let ((fun eldoc-documentation-function))
427 (when fun (eldoc-message (funcall fun)))))))))
385 428
386;; If the entire line cannot fit in the echo area, the symbol name may be 429;; If the entire line cannot fit in the echo area, the symbol name may be
387;; truncated or eliminated entirely from the output to make room for the 430;; truncated or eliminated entirely from the output to make room for the
diff --git a/lisp/hexl.el b/lisp/hexl.el
index 58518e74169..cf7118f2089 100644
--- a/lisp/hexl.el
+++ b/lisp/hexl.el
@@ -367,8 +367,8 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode.
367 (add-hook 'change-major-mode-hook #'hexl-maybe-dehexlify-buffer nil t) 367 (add-hook 'change-major-mode-hook #'hexl-maybe-dehexlify-buffer nil t)
368 368
369 ;; Set a callback function for eldoc. 369 ;; Set a callback function for eldoc.
370 (add-function :before-until (local 'eldoc-documentation-function) 370 (add-hook 'eldoc-documentation-functions
371 #'hexl-print-current-point-info) 371 #'hexl-print-current-point-info nil t)
372 (eldoc-add-command-completions "hexl-") 372 (eldoc-add-command-completions "hexl-")
373 (eldoc-remove-command "hexl-save-buffer" 373 (eldoc-remove-command "hexl-save-buffer"
374 "hexl-current-address") 374 "hexl-current-address")
@@ -455,6 +455,8 @@ and edit the file in `hexl-mode'."
455 ;; 2. reset change-major-mode-hook in case that `hexl-mode' 455 ;; 2. reset change-major-mode-hook in case that `hexl-mode'
456 ;; previously added hexl-maybe-dehexlify-buffer to it. 456 ;; previously added hexl-maybe-dehexlify-buffer to it.
457 (remove-hook 'change-major-mode-hook #'hexl-maybe-dehexlify-buffer t) 457 (remove-hook 'change-major-mode-hook #'hexl-maybe-dehexlify-buffer t)
458 (remove-hook 'eldoc-documentation-functions
459 #'hexl-print-current-point-info t)
458 (setq major-mode 'fundamental-mode) 460 (setq major-mode 'fundamental-mode)
459 (hexl-mode))) 461 (hexl-mode)))
460 462
diff --git a/lisp/ielm.el b/lisp/ielm.el
index 41675c011d8..fc06ebfa2db 100644
--- a/lisp/ielm.el
+++ b/lisp/ielm.el
@@ -541,8 +541,8 @@ Customized bindings may be defined in `ielm-map', which currently contains:
541 (set (make-local-variable 'completion-at-point-functions) 541 (set (make-local-variable 'completion-at-point-functions)
542 '(comint-replace-by-expanded-history 542 '(comint-replace-by-expanded-history
543 ielm-complete-filename elisp-completion-at-point)) 543 ielm-complete-filename elisp-completion-at-point))
544 (add-function :before-until (local 'eldoc-documentation-function) 544 (add-hook 'eldoc-documentation-functions
545 #'elisp-eldoc-documentation-function) 545 #'elisp-eldoc-documentation-function nil t)
546 (set (make-local-variable 'ielm-prompt-internal) ielm-prompt) 546 (set (make-local-variable 'ielm-prompt-internal) ielm-prompt)
547 (set (make-local-variable 'comint-prompt-read-only) ielm-prompt-read-only) 547 (set (make-local-variable 'comint-prompt-read-only) ielm-prompt-read-only)
548 (setq comint-get-old-input 'ielm-get-old-input) 548 (setq comint-get-old-input 'ielm-get-old-input)
diff --git a/lisp/progmodes/cfengine.el b/lisp/progmodes/cfengine.el
index 18df372f2c6..f25b3cb9e2b 100644
--- a/lisp/progmodes/cfengine.el
+++ b/lisp/progmodes/cfengine.el
@@ -1390,12 +1390,15 @@ to the action header."
1390 (when buffer-file-name 1390 (when buffer-file-name
1391 (shell-quote-argument buffer-file-name))))) 1391 (shell-quote-argument buffer-file-name)))))
1392 1392
1393 ;; For emacs < 25.1 where `eldoc-documentation-function' defaults to 1393 (if (boundp 'eldoc-documentation-functions)
1394 ;; nil. 1394 (add-hook 'eldoc-documentation-functions
1395 (or eldoc-documentation-function 1395 #'cfengine3-documentation-function nil t)
1396 (setq-local eldoc-documentation-function #'ignore)) 1396 ;; For emacs < 25.1 where `eldoc-documentation-function' defaults
1397 (add-function :before-until (local 'eldoc-documentation-function) 1397 ;; to nil.
1398 #'cfengine3-documentation-function) 1398 (or eldoc-documentation-function
1399 (setq-local eldoc-documentation-function #'ignore))
1400 (add-function :before-until (local 'eldoc-documentation-function)
1401 #'cfengine3-documentation-function))
1399 1402
1400 (add-hook 'completion-at-point-functions 1403 (add-hook 'completion-at-point-functions
1401 #'cfengine3-completion-function nil t) 1404 #'cfengine3-completion-function nil t)
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 2617a6e4cce..813b628bc35 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -250,8 +250,8 @@ Blank lines separate paragraphs. Semicolons start comments.
250 (add-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs)) 250 (add-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs))
251 (setq-local electric-quote-string t) 251 (setq-local electric-quote-string t)
252 (setq imenu-case-fold-search nil) 252 (setq imenu-case-fold-search nil)
253 (add-function :before-until (local 'eldoc-documentation-function) 253 (add-hook 'eldoc-documentation-functions
254 #'elisp-eldoc-documentation-function) 254 #'elisp-eldoc-documentation-function nil t)
255 (add-hook 'xref-backend-functions #'elisp--xref-backend nil t) 255 (add-hook 'xref-backend-functions #'elisp--xref-backend nil t)
256 (setq-local project-vc-external-roots-function #'elisp-load-path-roots) 256 (setq-local project-vc-external-roots-function #'elisp-load-path-roots)
257 (add-hook 'completion-at-point-functions 257 (add-hook 'completion-at-point-functions
diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index 9e039562549..352c1810d1f 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -619,8 +619,7 @@ Key bindings:
619 (add-hook 'before-save-hook 'octave-sync-function-file-names nil t) 619 (add-hook 'before-save-hook 'octave-sync-function-file-names nil t)
620 (setq-local beginning-of-defun-function 'octave-beginning-of-defun) 620 (setq-local beginning-of-defun-function 'octave-beginning-of-defun)
621 (and octave-font-lock-texinfo-comment (octave-font-lock-texinfo-comment)) 621 (and octave-font-lock-texinfo-comment (octave-font-lock-texinfo-comment))
622 (add-function :before-until (local 'eldoc-documentation-function) 622 (add-hook 'eldoc-documentation-functions 'octave-eldoc-function nil t)
623 'octave-eldoc-function)
624 623
625 (easy-menu-add octave-mode-menu)) 624 (easy-menu-add octave-mode-menu))
626 625
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index a2d85d0bef8..67383b34154 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -5544,8 +5544,10 @@ REPORT-FN is Flymake's callback function."
5544 ;; Emacs<25 5544 ;; Emacs<25
5545 (set (make-local-variable 'eldoc-documentation-function) 5545 (set (make-local-variable 'eldoc-documentation-function)
5546 #'python-eldoc-function) 5546 #'python-eldoc-function)
5547 (add-function :before-until (local 'eldoc-documentation-function) 5547 (if (boundp 'eldoc-documentation-functions)
5548 #'python-eldoc-function)) 5548 (add-hook 'eldoc-documentation-functions #'python-eldoc-function nil t)
5549 (add-function :before-until (local 'eldoc-documentation-function)
5550 #'python-eldoc-function)))
5549 5551
5550 (add-to-list 5552 (add-to-list
5551 'hs-special-modes-alist 5553 'hs-special-modes-alist