Some fixes to follow coding conventions in files maintained by FSF.
[emacs.git] / lisp / emacs-lisp / eldoc.el
blob54fbb896b51f6a2a1bc26311d6cd80a43447eb1b
1 ;;; eldoc.el --- show function arglist or variable docstring in echo area
3 ;; Copyright (C) 1996, 97, 98, 99, 2000 Free Software Foundation, Inc.
5 ;; Author: Noah Friedman <friedman@splode.com>
6 ;; Maintainer: friedman@splode.com
7 ;; Keywords: extensions
8 ;; Created: 1995-10-06
10 ;; $Id: eldoc.el,v 1.17 2000/07/24 00:37:03 friedman Exp $
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
29 ;;; Commentary:
31 ;; This program was inspired by the behavior of the "mouse documentation
32 ;; window" on many Lisp Machine systems; as you type a function's symbol
33 ;; name as part of a sexp, it will print the argument list for that
34 ;; function. Behavior is not identical; for example, you need not actually
35 ;; type the function name, you need only move point around in a sexp that
36 ;; calls it. Also, if point is over a documented variable, it will print
37 ;; the one-line documentation for that variable instead, to remind you of
38 ;; that variable's meaning.
40 ;; One useful way to enable this minor mode is to put the following in your
41 ;; .emacs:
43 ;; (autoload 'turn-on-eldoc-mode "eldoc" nil t)
44 ;; (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
45 ;; (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
46 ;; (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
48 ;;; Code:
50 ;; Use idle timers if available in the version of emacs running.
51 ;; Please don't change this to use `require'; this package works
52 ;; as-is in XEmacs 19.14 and later and I am striving to maintain
53 ;; compatibility between emacs variants.
54 (or (featurep 'timer)
55 (load "timer" t))
57 (defgroup eldoc nil
58 "Show function arglist or variable docstring in echo area."
59 :group 'lisp
60 :group 'extensions)
62 ;;;###autoload
63 (defcustom eldoc-mode nil
64 "*If non-nil, show the defined parameters for the elisp function near point.
66 For the emacs lisp function at the beginning of the sexp which point is
67 within, show the defined parameters for the function in the echo area.
68 This information is extracted directly from the function or macro if it is
69 in pure lisp. If the emacs function is a subr, the parameters are obtained
70 from the documentation string if possible.
72 If point is over a documented variable, print that variable's docstring
73 instead.
75 This variable is buffer-local."
76 :type 'boolean
77 :group 'eldoc)
78 (make-variable-buffer-local 'eldoc-mode)
80 (defcustom eldoc-idle-delay 0.50
81 "*Number of seconds of idle time to wait before printing.
82 If user input arrives before this interval of time has elapsed after the
83 last input, no documentation will be printed.
85 If this variable is set to 0, no idle time is required."
86 :type 'number
87 :group 'eldoc)
89 ;;;###autoload
90 (defcustom eldoc-minor-mode-string " ElDoc"
91 "*String to display in mode line when Eldoc Mode is enabled."
92 :type 'string
93 :group 'eldoc)
95 (defcustom eldoc-argument-case 'upcase
96 "Case to display argument names of functions, as a symbol.
97 This has two preferred values: `upcase' or `downcase'.
98 Actually, any name of a function which takes a string as an argument and
99 returns another string is acceptable."
100 :type '(radio (function-item upcase)
101 (function-item downcase)
102 function)
103 :group 'eldoc)
105 (defcustom eldoc-echo-area-use-multiline-p 'truncate-sym-name-if-fit
106 "*Allow long eldoc messages to resize echo area display.
107 If value is `t', never attempt to truncate messages; complete symbol name
108 and function arglist or 1-line variable documentation will be displayed
109 even if echo area must be resized to fit.
111 If value is any non-nil value other than `t', symbol name may be truncated
112 if it will enable the function arglist or documentation string to fit on a
113 single line without resizing window. Otherwise, behavior is just like
114 former case.
116 If value is nil, messages are always truncated to fit in a single line of
117 display in the echo area. Function or variable symbol name may be
118 truncated to make more of the arglist or documentation string visible.
120 Non-nil values for this variable have no effect unless
121 `eldoc-echo-area-multiline-supported-p' is non-nil."
122 :type '(radio (const :tag "Always" t)
123 (const :tag "Never" nil)
124 (const :tag "Yes, but truncate symbol names if it will\
125 enable argument list to fit on one line" truncate-sym-name-if-fit))
126 :group 'eldoc)
128 ;;; No user options below here.
130 ;; Non-nil if this version of emacs supports dynamically resizable echo areas.
131 (defvar eldoc-echo-area-multiline-supported-p
132 (and (string-lessp "21" emacs-version)
133 (save-match-data
134 (numberp (string-match "^GNU Emacs" (emacs-version))))))
136 ;; Commands after which it is appropriate to print in the echo area.
137 ;; Eldoc does not try to print function arglists, etc. after just any command,
138 ;; because some commands print their own messages in the echo area and these
139 ;; functions would instantly overwrite them. But self-insert-command as well
140 ;; as most motion commands are good candidates.
141 ;; This variable contains an obarray of symbols; do not manipulate it
142 ;; directly. Instead, use `eldoc-add-command' and `eldoc-remove-command'.
143 (defvar eldoc-message-commands nil)
145 ;; This is used by eldoc-add-command to initialize eldoc-message-commands
146 ;; as an obarray.
147 ;; It should probably never be necessary to do so, but if you
148 ;; choose to increase the number of buckets, you must do so before loading
149 ;; this file since the obarray is initialized at load time.
150 ;; Remember to keep it a prime number to improve hash performance.
151 (defvar eldoc-message-commands-table-size 31)
153 ;; Bookkeeping; elements are as follows:
154 ;; 0 - contains the last symbol read from the buffer.
155 ;; 1 - contains the string last displayed in the echo area for that
156 ;; symbol, so it can be printed again if necessary without reconsing.
157 ;; 2 - 'function if function args, 'variable if variable documentation.
158 (defvar eldoc-last-data (make-vector 3 nil))
159 (defvar eldoc-last-message nil)
161 ;; Idle timers are supported in Emacs 19.31 and later.
162 (defvar eldoc-use-idle-timer-p (fboundp 'run-with-idle-timer))
164 ;; eldoc's timer object, if using idle timers
165 (defvar eldoc-timer nil)
167 ;; idle time delay currently in use by timer.
168 ;; This is used to determine if eldoc-idle-delay is changed by the user.
169 (defvar eldoc-current-idle-delay eldoc-idle-delay)
171 ;; Put minor mode string on the global minor-mode-alist.
172 ;;;###autoload
173 (cond ((fboundp 'add-minor-mode)
174 (add-minor-mode 'eldoc-mode 'eldoc-minor-mode-string))
175 ((assq 'eldoc-mode (default-value 'minor-mode-alist)))
177 (setq-default minor-mode-alist
178 (append (default-value 'minor-mode-alist)
179 '((eldoc-mode eldoc-minor-mode-string))))))
182 ;;;###autoload
183 (defun eldoc-mode (&optional prefix)
184 "*Enable or disable eldoc mode.
185 See documentation for the variable of the same name for more details.
187 If called interactively with no prefix argument, toggle current condition
188 of the mode.
189 If called with a positive or negative prefix argument, enable or disable
190 the mode, respectively."
191 (interactive "P")
192 (setq eldoc-last-message nil)
193 (cond (eldoc-use-idle-timer-p
194 (add-hook 'post-command-hook 'eldoc-schedule-timer)
195 (add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area))
197 ;; Use post-command-idle-hook if defined, otherwise use
198 ;; post-command-hook. The former is only proper to use in Emacs
199 ;; 19.30; that is the first version in which it appeared, but it
200 ;; was obsolesced by idle timers in Emacs 19.31.
201 (add-hook (if (boundp 'post-command-idle-hook)
202 'post-command-idle-hook
203 'post-command-hook)
204 'eldoc-print-current-symbol-info t t)
205 ;; quick and dirty hack for seeing if this is XEmacs
206 (and (fboundp 'display-message)
207 (add-hook 'pre-command-hook
208 'eldoc-pre-command-refresh-echo-area t t))))
209 (setq eldoc-mode (if prefix
210 (>= (prefix-numeric-value prefix) 0)
211 (not eldoc-mode)))
212 (and (interactive-p)
213 (if eldoc-mode
214 (message "eldoc-mode is enabled")
215 (message "eldoc-mode is disabled")))
216 eldoc-mode)
218 ;;;###autoload
219 (defun turn-on-eldoc-mode ()
220 "Unequivocally turn on eldoc-mode (see variable documentation)."
221 (interactive)
222 (eldoc-mode 1))
225 ;; Idle timers are part of Emacs 19.31 and later.
226 (defun eldoc-schedule-timer ()
227 (or (and eldoc-timer
228 (memq eldoc-timer timer-idle-list))
229 (setq eldoc-timer
230 (run-with-idle-timer eldoc-idle-delay t
231 'eldoc-print-current-symbol-info)))
233 ;; If user has changed the idle delay, update the timer.
234 (cond ((not (= eldoc-idle-delay eldoc-current-idle-delay))
235 (setq eldoc-current-idle-delay eldoc-idle-delay)
236 (timer-set-idle-time eldoc-timer eldoc-idle-delay t))))
238 (defun eldoc-message (&rest args)
239 (let ((omessage eldoc-last-message))
240 (cond ((eq (car args) eldoc-last-message))
241 ((or (null args)
242 (null (car args)))
243 (setq eldoc-last-message nil))
244 ;; If only one arg, no formatting to do so put it in
245 ;; eldoc-last-message so eq test above might succeed on
246 ;; subsequent calls.
247 ((null (cdr args))
248 (setq eldoc-last-message (car args)))
250 (setq eldoc-last-message (apply 'format args))))
251 ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages
252 ;; are recorded in a log. Do not put eldoc messages in that log since
253 ;; they are Legion.
254 (cond ((fboundp 'display-message)
255 ;; XEmacs 19.13 way of preventing log messages.
256 (cond (eldoc-last-message
257 (display-message 'no-log eldoc-last-message))
258 (omessage
259 (clear-message 'no-log))))
261 ;; Emacs way of preventing log messages.
262 (let ((message-log-max nil))
263 (cond (eldoc-last-message
264 (message "%s" eldoc-last-message))
265 (omessage
266 (message nil)))))))
267 eldoc-last-message)
269 ;; This function goes on pre-command-hook for XEmacs or when using idle
270 ;; timers in Emacs. Motion commands clear the echo area for some reason,
271 ;; which make eldoc messages flicker or disappear just before motion
272 ;; begins. This function reprints the last eldoc message immediately
273 ;; before the next command executes, which does away with the flicker.
274 ;; This doesn't seem to be required for Emacs 19.28 and earlier.
275 (defun eldoc-pre-command-refresh-echo-area ()
276 (and eldoc-last-message
277 (if (eldoc-display-message-no-interference-p)
278 (eldoc-message eldoc-last-message)
279 (setq eldoc-last-message nil))))
281 ;; Decide whether now is a good time to display a message.
282 (defun eldoc-display-message-p ()
283 (and (eldoc-display-message-no-interference-p)
284 (cond (eldoc-use-idle-timer-p
285 ;; If this-command is non-nil while running via an idle
286 ;; timer, we're still in the middle of executing a command,
287 ;; e.g. a query-replace where it would be annoying to
288 ;; overwrite the echo area.
289 (and (not this-command)
290 (symbolp last-command)
291 (intern-soft (symbol-name last-command)
292 eldoc-message-commands)))
294 ;; If we don't have idle timers, this function is
295 ;; running on post-command-hook directly; that means the
296 ;; user's last command is still on `this-command', and we
297 ;; must wait briefly for input to see whether to do display.
298 (and (symbolp this-command)
299 (intern-soft (symbol-name this-command)
300 eldoc-message-commands)
301 (sit-for eldoc-idle-delay))))))
303 ;; Check various conditions about the current environment that might make
304 ;; it undesirable to print eldoc messages right this instant.
305 (defun eldoc-display-message-no-interference-p ()
306 (and eldoc-mode
307 (not executing-kbd-macro)
308 (not (and (boundp 'edebug-active) edebug-active))
309 ;; Having this mode operate in an active minibuffer/echo area causes
310 ;; interference with what's going on there.
311 (not cursor-in-echo-area)
312 (not (eq (selected-window) (minibuffer-window)))))
315 (defun eldoc-print-current-symbol-info ()
316 (and (eldoc-display-message-p)
317 (let* ((current-symbol (eldoc-current-symbol))
318 (current-fnsym (eldoc-fnsym-in-current-sexp))
319 (doc (cond ((eq current-symbol current-fnsym)
320 (or (eldoc-get-fnsym-args-string current-fnsym)
321 (eldoc-get-var-docstring current-symbol)))
323 (or (eldoc-get-var-docstring current-symbol)
324 (eldoc-get-fnsym-args-string current-fnsym))))))
325 (eldoc-message doc))))
327 ;; Return a string containing the function parameter list, or 1-line
328 ;; docstring if function is a subr and no arglist is obtainable from the
329 ;; docstring or elsewhere.
330 (defun eldoc-get-fnsym-args-string (sym)
331 (let ((args nil)
332 (doc nil))
333 (cond ((not (and sym
334 (symbolp sym)
335 (fboundp sym))))
336 ((and (eq sym (aref eldoc-last-data 0))
337 (eq 'function (aref eldoc-last-data 2)))
338 (setq doc (aref eldoc-last-data 1)))
339 ((subrp (eldoc-symbol-function sym))
340 (setq args (or (eldoc-function-argstring-from-docstring sym)
341 (eldoc-docstring-first-line (documentation sym t)))))
343 (setq args (eldoc-function-argstring sym))))
344 (cond (args
345 (setq doc (eldoc-docstring-format-sym-doc sym args))
346 (eldoc-last-data-store sym doc 'function)))
347 doc))
349 ;; Return a string containing a brief (one-line) documentation string for
350 ;; the variable.
351 (defun eldoc-get-var-docstring (sym)
352 (cond ((and (eq sym (aref eldoc-last-data 0))
353 (eq 'variable (aref eldoc-last-data 2)))
354 (aref eldoc-last-data 1))
356 (let ((doc (documentation-property sym 'variable-documentation t)))
357 (cond (doc
358 (setq doc (eldoc-docstring-format-sym-doc
359 sym (eldoc-docstring-first-line doc)))
360 (eldoc-last-data-store sym doc 'variable)))
361 doc))))
363 (defun eldoc-last-data-store (symbol doc type)
364 (aset eldoc-last-data 0 symbol)
365 (aset eldoc-last-data 1 doc)
366 (aset eldoc-last-data 2 type))
368 ;; Note that any leading `*' in the docstring (which indicates the variable
369 ;; is a user option) is removed.
370 (defun eldoc-docstring-first-line (doc)
371 (and (stringp doc)
372 (substitute-command-keys
373 (save-match-data
374 (let ((start (if (string-match "^\\*" doc) (match-end 0) 0)))
375 (cond ((string-match "\n" doc)
376 (substring doc start (match-beginning 0)))
377 ((zerop start) doc)
378 (t (substring doc start))))))))
380 ;; If the entire line cannot fit in the echo area, the symbol name may be
381 ;; truncated or eliminated entirely from the output to make room for the
382 ;; description.
383 (defun eldoc-docstring-format-sym-doc (sym doc)
384 (save-match-data
385 (let* ((name (symbol-name sym))
386 (ea-multi (and eldoc-echo-area-multiline-supported-p
387 eldoc-echo-area-use-multiline-p))
388 ;; Subtract 1 from window width since emacs will not write
389 ;; any chars to the last column, or in later versions, will
390 ;; cause a wraparound and resize of the echo area.
391 (ea-width (1- (window-width (minibuffer-window))))
392 (strip (- (+ (length name) (length ": ") (length doc)) ea-width)))
393 (cond ((or (<= strip 0)
394 (eq ea-multi t)
395 (and ea-multi (> (length doc) ea-width)))
396 (format "%s: %s" sym doc))
397 ((> (length doc) ea-width)
398 (substring (format "%s" doc) 0 ea-width))
399 ((>= strip (length name))
400 (format "%s" doc))
402 ;; Show the end of the partial symbol name, rather
403 ;; than the beginning, since the former is more likely
404 ;; to be unique given package namespace conventions.
405 (setq name (substring name strip))
406 (format "%s: %s" name doc))))))
409 (defun eldoc-fnsym-in-current-sexp ()
410 (let ((p (point)))
411 (eldoc-beginning-of-sexp)
412 (prog1
413 ;; Don't do anything if current word is inside a string.
414 (if (= (or (char-after (1- (point))) 0) ?\")
416 (eldoc-current-symbol))
417 (goto-char p))))
419 (defun eldoc-beginning-of-sexp ()
420 (let ((parse-sexp-ignore-comments t))
421 (condition-case err
422 (while (progn
423 (forward-sexp -1)
424 (or (= (or (char-after (1- (point)))) ?\")
425 (> (point) (point-min)))))
426 (error nil))))
428 ;; returns nil unless current word is an interned symbol.
429 (defun eldoc-current-symbol ()
430 (let ((c (char-after (point))))
431 (and c
432 (memq (char-syntax c) '(?w ?_))
433 (intern-soft (current-word)))))
435 ;; Do indirect function resolution if possible.
436 (defun eldoc-symbol-function (fsym)
437 (let ((defn (and (fboundp fsym)
438 (symbol-function fsym))))
439 (and (symbolp defn)
440 (condition-case err
441 (setq defn (indirect-function fsym))
442 (error (setq defn nil))))
443 defn))
445 (defun eldoc-function-arglist (fn)
446 (let* ((prelim-def (eldoc-symbol-function fn))
447 (def (if (eq (car-safe prelim-def) 'macro)
448 (cdr prelim-def)
449 prelim-def))
450 (arglist (cond ((null def) nil)
451 ((byte-code-function-p def)
452 (cond ((fboundp 'compiled-function-arglist)
453 (funcall 'compiled-function-arglist def))
455 (aref def 0))))
456 ((eq (car-safe def) 'lambda)
457 (nth 1 def))
458 (t t))))
459 arglist))
461 (defun eldoc-function-argstring (fn)
462 (eldoc-function-argstring-format (eldoc-function-arglist fn)))
464 (defun eldoc-function-argstring-format (arglist)
465 (cond ((not (listp arglist))
466 (setq arglist nil))
467 ((symbolp (car arglist))
468 (setq arglist
469 (mapcar (function (lambda (s)
470 (if (memq s '(&optional &rest))
471 (symbol-name s)
472 (funcall eldoc-argument-case
473 (symbol-name s)))))
474 arglist)))
475 ((stringp (car arglist))
476 (setq arglist
477 (mapcar (function (lambda (s)
478 (if (member s '("&optional" "&rest"))
480 (funcall eldoc-argument-case s))))
481 arglist))))
482 (concat "(" (mapconcat 'identity arglist " ") ")"))
485 ;; Alist of predicate/action pairs.
486 ;; Each member of the list is a sublist consisting of a predicate function
487 ;; used to determine if the arglist for a function can be found using a
488 ;; certain pattern, and a function which returns the actual arglist from
489 ;; that docstring.
491 ;; The order in this table is significant, since later predicates may be
492 ;; more general than earlier ones.
494 ;; Compiler note for Emacs/XEmacs versions which support dynamic loading:
495 ;; these functions will be compiled to bytecode, but can't be lazy-loaded
496 ;; even if you set byte-compile-dynamic; to do that would require making
497 ;; them named top-level defuns, which is not particularly desirable either.
498 (defvar eldoc-function-argstring-from-docstring-method-table
499 (list
500 ;; Try first searching for args starting with symbol name.
501 ;; This is to avoid matching parenthetical remarks in e.g. sit-for.
502 (list (function (lambda (doc fn)
503 (string-match (format "^(%s[^\n)]*)$" fn) doc)))
504 (function (lambda (doc)
505 ;; end does not include trailing ")" sequence.
506 (let ((end (- (match-end 0) 1)))
507 (if (string-match " +" doc (match-beginning 0))
508 (substring doc (match-end 0) end)
509 "")))))
511 ;; Try again not requiring this symbol name in the docstring.
512 ;; This will be the case when looking up aliases.
513 (list (function (lambda (doc fn)
514 ;; save-restriction has a pathological docstring in
515 ;; Emacs/XEmacs 19.
516 (and (not (eq fn 'save-restriction))
517 (string-match "^([^\n)]+)$" doc))))
518 (function (lambda (doc)
519 ;; end does not include trailing ")" sequence.
520 (let ((end (- (match-end 0) 1)))
521 (and (string-match " +" doc (match-beginning 0))
522 (substring doc (match-end 0) end))))))
524 ;; Emacs subr docstring style:
525 ;; (fn arg1 arg2 ...): description...
526 (list (function (lambda (doc fn)
527 (string-match "^([^\n)]+):" doc)))
528 (function (lambda (doc)
529 ;; end does not include trailing "):" sequence.
530 (let ((end (- (match-end 0) 2)))
531 (and (string-match " +" doc (match-beginning 0))
532 (substring doc (match-end 0) end))))))
534 ;; XEmacs subr docstring style:
535 ;; "arguments: (arg1 arg2 ...)
536 (list (function (lambda (doc fn)
537 (string-match "^arguments: (\\([^\n)]+\\))" doc)))
538 (function (lambda (doc)
539 ;; also skip leading paren, but the first word is
540 ;; actually an argument, not the function name.
541 (substring doc (match-beginning 1) (match-end 1)))))
543 ;; This finds the argstring for `condition-case'. Any others?
544 (list (function (lambda (doc fn)
545 (string-match
546 (format "^Usage looks like \\((%s[^\n)]*)\\)\\.$" fn)
547 doc)))
548 (function (lambda (doc)
549 ;; end does not include trailing ")" sequence.
550 (let ((end (- (match-end 1) 1)))
551 (and (string-match " +" doc (match-beginning 1))
552 (substring doc (match-end 0) end))))))
554 ;; This finds the argstring for `setq-default'. Any others?
555 (list (function (lambda (doc fn)
556 (string-match (format "^[ \t]+\\((%s[^\n)]*)\\)$" fn)
557 doc)))
558 (function (lambda (doc)
559 ;; end does not include trailing ")" sequence.
560 (let ((end (- (match-end 1) 1)))
561 (and (string-match " +" doc (match-beginning 1))
562 (substring doc (match-end 0) end))))))
564 ;; This finds the argstring for `start-process'. Any others?
565 (list (function (lambda (doc fn)
566 (string-match "^Args are +\\([^\n]+\\)$" doc)))
567 (function (lambda (doc)
568 (substring doc (match-beginning 1) (match-end 1)))))
570 ;; These common subrs don't have arglists in their docstrings. So cheat.
571 (list (function (lambda (doc fn)
572 (memq fn '(and or list + -))))
573 (function (lambda (doc)
574 ;; The value nil is a placeholder; otherwise, the
575 ;; following string may be compiled as a docstring,
576 ;; and not a return value for the function.
577 ;; In interpreted lisp form they are
578 ;; indistinguishable; it only matters for compiled
579 ;; forms.
581 "&rest args")))
584 (defun eldoc-function-argstring-from-docstring (fn)
585 (let ((docstring (documentation fn 'raw))
586 (table eldoc-function-argstring-from-docstring-method-table)
587 (doc nil)
588 (doclist nil))
589 (save-match-data
590 (while table
591 (cond ((funcall (car (car table)) docstring fn)
592 (setq doc (funcall (car (cdr (car table))) docstring))
593 (setq table nil))
595 (setq table (cdr table)))))
597 (cond ((not (stringp doc))
598 nil)
599 ((string-match "&" doc)
600 (let ((p 0)
601 (l (length doc)))
602 (while (< p l)
603 (cond ((string-match "[ \t\n]+" doc p)
604 (setq doclist
605 (cons (substring doc p (match-beginning 0))
606 doclist))
607 (setq p (match-end 0)))
609 (setq doclist (cons (substring doc p) doclist))
610 (setq p l))))
611 (eldoc-function-argstring-format (nreverse doclist))))
613 (concat "(" (funcall eldoc-argument-case doc) ")"))))))
616 ;; When point is in a sexp, the function args are not reprinted in the echo
617 ;; area after every possible interactive command because some of them print
618 ;; their own messages in the echo area; the eldoc functions would instantly
619 ;; overwrite them unless it is more restrained.
620 ;; These functions do display-command table management.
622 (defun eldoc-add-command (&rest cmds)
623 (or eldoc-message-commands
624 (setq eldoc-message-commands
625 (make-vector eldoc-message-commands-table-size 0)))
627 (let (name sym)
628 (while cmds
629 (setq name (car cmds))
630 (setq cmds (cdr cmds))
632 (cond ((symbolp name)
633 (setq sym name)
634 (setq name (symbol-name sym)))
635 ((stringp name)
636 (setq sym (intern-soft name))))
638 (and (symbolp sym)
639 (fboundp sym)
640 (set (intern name eldoc-message-commands) t)))))
642 (defun eldoc-add-command-completions (&rest names)
643 (while names
644 (apply 'eldoc-add-command
645 (all-completions (car names) obarray 'fboundp))
646 (setq names (cdr names))))
648 (defun eldoc-remove-command (&rest cmds)
649 (let (name)
650 (while cmds
651 (setq name (car cmds))
652 (setq cmds (cdr cmds))
654 (and (symbolp name)
655 (setq name (symbol-name name)))
657 (if (fboundp 'unintern)
658 (unintern name eldoc-message-commands)
659 (let ((s (intern-soft name eldoc-message-commands)))
660 (and s
661 (makunbound s)))))))
663 (defun eldoc-remove-command-completions (&rest names)
664 (while names
665 (apply 'eldoc-remove-command
666 (all-completions (car names) eldoc-message-commands))
667 (setq names (cdr names))))
670 ;; Prime the command list.
671 (eldoc-add-command-completions
672 "backward-" "beginning-of-" "delete-other-windows" "delete-window"
673 "end-of-" "forward-" "indent-for-tab-command" "goto-" "mouse-set-point"
674 "next-" "other-window" "previous-" "recenter" "scroll-"
675 "self-insert-command" "split-window-"
676 "up-list" "down-list")
678 (provide 'eldoc)
680 ;;; eldoc.el ends here