aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles A. Roelli2017-07-22 11:09:36 +0300
committerEli Zaretskii2017-07-22 11:09:36 +0300
commitd37a82b4a35bdffa0462ba9954bd432cf7d54659 (patch)
tree08b927c81b857f200389c97fcfa4113ae3ec8c5a
parent842ac11c0d3f4fe24a30c35e3ae8d810cf56c549 (diff)
downloademacs-d37a82b4a35bdffa0462ba9954bd432cf7d54659.tar.gz
emacs-d37a82b4a35bdffa0462ba9954bd432cf7d54659.zip
ElDoc: add docstrings and minor refactoring
* lisp/emacs-lisp/eldoc.el (eldoc-edit-message-commands): Add docstring. (turn-on-eldoc-mode): Fix capitalization. (eldoc--supported-p): Add docstring. (eldoc-schedule-timer): Add docstring and use 'eldoc--supported-p'. (eldoc-message): Add docstring and make calling convention clearer. (eldoc--message-command-p): (eldoc-pre-command-refresh-echo-area): (eldoc-display-message-p): (eldoc-display-message-no-interference-p): (eldoc-print-current-symbol-info): (eldoc-docstring-format-sym-doc): (eldoc-add-command, eldoc-add-command-completions): (eldoc-remove-command, eldoc-remove-command-completions): Add docstring. (Bug#27230)
-rw-r--r--lisp/emacs-lisp/eldoc.el49
1 files changed, 38 insertions, 11 deletions
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index a05bd7cc4d4..bca40ab87da 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -160,6 +160,10 @@ This is used to determine if `eldoc-idle-delay' is changed by the user.")
160It should receive the same arguments as `message'.") 160It should receive the same arguments as `message'.")
161 161
162(defun eldoc-edit-message-commands () 162(defun eldoc-edit-message-commands ()
163 "Return an obarray containing common editing commands.
164
165When `eldoc-print-after-edit' is non-nil, ElDoc messages are only
166printed after commands contained in this obarray."
163 (let ((cmds (make-vector 31 0)) 167 (let ((cmds (make-vector 31 0))
164 (re (regexp-opt '("delete" "insert" "edit" "electric" "newline")))) 168 (re (regexp-opt '("delete" "insert" "edit" "electric" "newline"))))
165 (mapatoms (lambda (s) 169 (mapatoms (lambda (s)
@@ -211,16 +215,21 @@ expression point is on."
211 215
212;;;###autoload 216;;;###autoload
213(defun turn-on-eldoc-mode () 217(defun turn-on-eldoc-mode ()
214 "Turn on `eldoc-mode' if the buffer has eldoc support enabled. 218 "Turn on `eldoc-mode' if the buffer has ElDoc support enabled.
215See `eldoc-documentation-function' for more detail." 219See `eldoc-documentation-function' for more detail."
216 (when (eldoc--supported-p) 220 (when (eldoc--supported-p)
217 (eldoc-mode 1))) 221 (eldoc-mode 1)))
218 222
219(defun eldoc--supported-p () 223(defun eldoc--supported-p ()
224 "Non-nil if an ElDoc function is set for this buffer."
220 (not (memq eldoc-documentation-function '(nil ignore)))) 225 (not (memq eldoc-documentation-function '(nil ignore))))
221 226
222 227
223(defun eldoc-schedule-timer () 228(defun eldoc-schedule-timer ()
229 "Ensure `eldoc-timer' is running.
230
231If the user has changed `eldoc-idle-delay', update the timer to
232reflect the change."
224 (or (and eldoc-timer 233 (or (and eldoc-timer
225 (memq eldoc-timer timer-idle-list)) ;FIXME: Why? 234 (memq eldoc-timer timer-idle-list)) ;FIXME: Why?
226 (setq eldoc-timer 235 (setq eldoc-timer
@@ -229,8 +238,7 @@ See `eldoc-documentation-function' for more detail."
229 (lambda () 238 (lambda ()
230 (when (or eldoc-mode 239 (when (or eldoc-mode
231 (and global-eldoc-mode 240 (and global-eldoc-mode
232 (not (memq eldoc-documentation-function 241 (eldoc--supported-p)))
233 '(nil ignore)))))
234 (eldoc-print-current-symbol-info)))))) 242 (eldoc-print-current-symbol-info))))))
235 243
236 ;; If user has changed the idle delay, update the timer. 244 ;; If user has changed the idle delay, update the timer.
@@ -268,16 +276,19 @@ Otherwise work like `message'."
268 (force-mode-line-update))) 276 (force-mode-line-update)))
269 (apply 'message format-string args))) 277 (apply 'message format-string args)))
270 278
271(defun eldoc-message (&rest args) 279(defun eldoc-message (&optional format-string &rest args)
280 "Display FORMAT-STRING formatted with ARGS as an ElDoc message.
281
282Store the message (if any) in `eldoc-last-message', and return it."
272 (let ((omessage eldoc-last-message)) 283 (let ((omessage eldoc-last-message))
273 (setq eldoc-last-message 284 (setq eldoc-last-message
274 (cond ((eq (car args) eldoc-last-message) eldoc-last-message) 285 (cond ((eq format-string eldoc-last-message) eldoc-last-message)
275 ((null (car args)) nil) 286 ((null format-string) nil)
276 ;; If only one arg, no formatting to do, so put it in 287 ;; If only one arg, no formatting to do, so put it in
277 ;; eldoc-last-message so eq test above might succeed on 288 ;; eldoc-last-message so eq test above might succeed on
278 ;; subsequent calls. 289 ;; subsequent calls.
279 ((null (cdr args)) (car args)) 290 ((null args) format-string)
280 (t (apply #'format-message args)))) 291 (t (apply #'format-message format-string args))))
281 ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages 292 ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages
282 ;; are recorded in a log. Do not put eldoc messages in that log since 293 ;; are recorded in a log. Do not put eldoc messages in that log since
283 ;; they are Legion. 294 ;; they are Legion.
@@ -289,6 +300,7 @@ Otherwise work like `message'."
289 eldoc-last-message) 300 eldoc-last-message)
290 301
291(defun eldoc--message-command-p (command) 302(defun eldoc--message-command-p (command)
303 "Return non-nil if COMMAND is in `eldoc-message-commands'."
292 (and (symbolp command) 304 (and (symbolp command)
293 (intern-soft (symbol-name command) eldoc-message-commands))) 305 (intern-soft (symbol-name command) eldoc-message-commands)))
294 306
@@ -299,6 +311,7 @@ Otherwise work like `message'."
299;; before the next command executes, which does away with the flicker. 311;; before the next command executes, which does away with the flicker.
300;; This doesn't seem to be required for Emacs 19.28 and earlier. 312;; This doesn't seem to be required for Emacs 19.28 and earlier.
301(defun eldoc-pre-command-refresh-echo-area () 313(defun eldoc-pre-command-refresh-echo-area ()
314 "Reprint `eldoc-last-message' in the echo area."
302 (and eldoc-last-message 315 (and eldoc-last-message
303 (not (minibufferp)) ;We don't use the echo area when in minibuffer. 316 (not (minibufferp)) ;We don't use the echo area when in minibuffer.
304 (if (and (eldoc-display-message-no-interference-p) 317 (if (and (eldoc-display-message-no-interference-p)
@@ -310,6 +323,7 @@ Otherwise work like `message'."
310 323
311;; Decide whether now is a good time to display a message. 324;; Decide whether now is a good time to display a message.
312(defun eldoc-display-message-p () 325(defun eldoc-display-message-p ()
326 "Return non-nil when it is appropriate to display an ElDoc message."
313 (and (eldoc-display-message-no-interference-p) 327 (and (eldoc-display-message-no-interference-p)
314 ;; If this-command is non-nil while running via an idle 328 ;; If this-command is non-nil while running via an idle
315 ;; timer, we're still in the middle of executing a command, 329 ;; timer, we're still in the middle of executing a command,
@@ -322,6 +336,7 @@ Otherwise work like `message'."
322;; Check various conditions about the current environment that might make 336;; Check various conditions about the current environment that might make
323;; it undesirable to print eldoc messages right this instant. 337;; it undesirable to print eldoc messages right this instant.
324(defun eldoc-display-message-no-interference-p () 338(defun eldoc-display-message-no-interference-p ()
339 "Return nil if displaying a message would cause interference."
325 (not (or executing-kbd-macro (bound-and-true-p edebug-active)))) 340 (not (or executing-kbd-macro (bound-and-true-p edebug-active))))
326 341
327 342
@@ -347,6 +362,7 @@ variable) is taken into account if the major mode specific function does not
347return any documentation.") 362return any documentation.")
348 363
349(defun eldoc-print-current-symbol-info () 364(defun eldoc-print-current-symbol-info ()
365 "Print the text produced by `eldoc-documentation-function'."
350 ;; This is run from post-command-hook or some idle timer thing, 366 ;; This is run from post-command-hook or some idle timer thing,
351 ;; so we need to be careful that errors aren't ignored. 367 ;; so we need to be careful that errors aren't ignored.
352 (with-demoted-errors "eldoc error: %s" 368 (with-demoted-errors "eldoc error: %s"
@@ -361,6 +377,13 @@ return any documentation.")
361;; truncated or eliminated entirely from the output to make room for the 377;; truncated or eliminated entirely from the output to make room for the
362;; description. 378;; description.
363(defun eldoc-docstring-format-sym-doc (prefix doc &optional face) 379(defun eldoc-docstring-format-sym-doc (prefix doc &optional face)
380 "Combine PREFIX and DOC, and shorten the result to fit in the echo area.
381
382When PREFIX is a symbol, propertize its symbol name with FACE
383before combining it with DOC. If FACE is not provided, just
384apply the nil face.
385
386See also: `eldoc-echo-area-use-multiline-p'."
364 (when (symbolp prefix) 387 (when (symbolp prefix)
365 (setq prefix (concat (propertize (symbol-name prefix) 'face face) ": "))) 388 (setq prefix (concat (propertize (symbol-name prefix) 'face face) ": ")))
366 (let* ((ea-multi eldoc-echo-area-use-multiline-p) 389 (let* ((ea-multi eldoc-echo-area-use-multiline-p)
@@ -390,22 +413,26 @@ return any documentation.")
390;; These functions do display-command table management. 413;; These functions do display-command table management.
391 414
392(defun eldoc-add-command (&rest cmds) 415(defun eldoc-add-command (&rest cmds)
416 "Add each of CMDS to the obarray `eldoc-message-commands'."
393 (dolist (name cmds) 417 (dolist (name cmds)
394 (and (symbolp name) 418 (and (symbolp name)
395 (setq name (symbol-name name))) 419 (setq name (symbol-name name)))
396 (set (intern name eldoc-message-commands) t))) 420 (set (intern name eldoc-message-commands) t)))
397 421
398(defun eldoc-add-command-completions (&rest names) 422(defun eldoc-add-command-completions (&rest names)
423 "Pass every prefix completion of NAMES to `eldoc-add-command'."
399 (dolist (name names) 424 (dolist (name names)
400 (apply #'eldoc-add-command (all-completions name obarray 'commandp)))) 425 (apply #'eldoc-add-command (all-completions name obarray 'commandp))))
401 426
402(defun eldoc-remove-command (&rest cmds) 427(defun eldoc-remove-command (&rest cmds)
428 "Remove each of CMDS from the obarray `eldoc-message-commands'."
403 (dolist (name cmds) 429 (dolist (name cmds)
404 (and (symbolp name) 430 (and (symbolp name)
405 (setq name (symbol-name name))) 431 (setq name (symbol-name name)))
406 (unintern name eldoc-message-commands))) 432 (unintern name eldoc-message-commands)))
407 433
408(defun eldoc-remove-command-completions (&rest names) 434(defun eldoc-remove-command-completions (&rest names)
435 "Pass every prefix completion of NAMES to `eldoc-remove-command'."
409 (dolist (name names) 436 (dolist (name names)
410 (apply #'eldoc-remove-command 437 (apply #'eldoc-remove-command
411 (all-completions name eldoc-message-commands)))) 438 (all-completions name eldoc-message-commands))))
@@ -418,9 +445,9 @@ return any documentation.")
418 "down-list" "end-of-" "exchange-point-and-mark" "forward-" "goto-" 445 "down-list" "end-of-" "exchange-point-and-mark" "forward-" "goto-"
419 "handle-select-window" "indent-for-tab-command" "left-" "mark-page" 446 "handle-select-window" "indent-for-tab-command" "left-" "mark-page"
420 "mark-paragraph" "mouse-set-point" "move-" "move-beginning-of-" 447 "mark-paragraph" "mouse-set-point" "move-" "move-beginning-of-"
421 "move-end-of-" "newline" "next-" "other-window" "pop-global-mark" "previous-" 448 "move-end-of-" "newline" "next-" "other-window" "pop-global-mark"
422 "recenter" "right-" "scroll-" "self-insert-command" "split-window-" 449 "previous-" "recenter" "right-" "scroll-" "self-insert-command"
423 "up-list") 450 "split-window-" "up-list")
424 451
425(provide 'eldoc) 452(provide 'eldoc)
426 453