98
|
1 ;;; eldoc.el --- show function arglist or variable docstring in echo area
|
|
2
|
|
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Noah Friedman <friedman@prep.ai.mit.edu>
|
|
6 ;; Maintainer: friedman@prep.ai.mit.edu
|
|
7 ;; Keywords: extensions
|
|
8 ;; Created: 1995-10-06
|
|
9
|
110
|
10 ;; $Id: eldoc.el,v 1.3 1997/03/16 03:05:48 steve Exp $
|
98
|
11
|
|
12 ;; This file is part of GNU Emacs.
|
|
13
|
|
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.
|
|
18
|
|
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.
|
|
23
|
|
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.
|
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
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.
|
|
39
|
|
40 ;; One useful way to enable this minor mode is to put the following in your
|
|
41 ;; .emacs:
|
|
42 ;;
|
|
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)
|
100
|
46 ;; (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
|
98
|
47
|
|
48 ;;; Code:
|
|
49
|
|
50 ;; Use idle timers if available in the version of emacs running.
|
|
51 ;; Please don't change this to use `require'; this package works as-is in
|
|
52 ;; XEmacs (which doesn't have timer.el as of 19.14), and I would like to
|
|
53 ;; maintain compatibility with that since I must use it sometimes. --Noah
|
|
54 (or (featurep 'timer)
|
|
55 (load "timer" t))
|
|
56
|
|
57 ;;;###autoload
|
|
58 (defvar eldoc-mode nil
|
|
59 "*If non-nil, show the defined parameters for the elisp function near point.
|
|
60
|
|
61 For the emacs lisp function at the beginning of the sexp which point is
|
|
62 within, show the defined parameters for the function in the echo area.
|
|
63 This information is extracted directly from the function or macro if it is
|
|
64 in pure lisp. If the emacs function is a subr, the parameters are obtained
|
|
65 from the documentation string if possible.
|
|
66
|
|
67 If point is over a documented variable, print that variable's docstring
|
|
68 instead.
|
|
69
|
|
70 This variable is buffer-local.")
|
|
71 (make-variable-buffer-local 'eldoc-mode)
|
|
72
|
|
73 (defconst eldoc-idle-delay 0.50
|
|
74 "*Number of seconds of idle time to wait before printing.
|
|
75 If user input arrives before this interval of time has elapsed after the
|
|
76 last input, no documentation will be printed.
|
|
77
|
|
78 If this variable is set to 0, no idle time is required.")
|
|
79
|
|
80 (defconst eldoc-minor-mode-string " ElDoc"
|
|
81 "*String to display in mode line when Eldoc Mode is enabled.")
|
|
82
|
|
83 ;; Put this minor mode on the global minor-mode-alist.
|
|
84 (or (assq 'eldoc-mode (default-value 'minor-mode-alist))
|
|
85 (setq-default minor-mode-alist
|
|
86 (append (default-value 'minor-mode-alist)
|
|
87 '((eldoc-mode eldoc-minor-mode-string)))))
|
|
88
|
|
89 (defconst eldoc-argument-case 'upcase
|
|
90 "Case to display argument names of functions, as a symbol.
|
|
91 This has two preferred values: `upcase' or `downcase'.
|
|
92 Actually, any name of a function which takes a string as an argument and
|
|
93 returns another string is acceptable.")
|
|
94
|
100
|
95 ;; No user options below here.
|
|
96
|
98
|
97 (defvar eldoc-message-commands nil
|
100
|
98 "Commands after which it is appropriate to print in the echo area.
|
98
|
99
|
|
100 Eldoc does not try to print function arglists, etc. after just any command,
|
|
101 because some commands print their own messages in the echo area and these
|
|
102 functions would instantly overwrite them. But self-insert-command as well
|
|
103 as most motion commands are good candidates.
|
|
104
|
100
|
105 This variable contains an obarray of symbols; do not manipulate it
|
|
106 directly. Instead, use the functions `eldoc-add-command' and
|
98
|
107 `eldoc-remove-command'.")
|
|
108
|
100
|
109 ;; This is used by eldoc-add-command to initialize eldoc-message-commands
|
|
110 ;; as an obarray.
|
|
111 ;; If you increase the number of buckets, keep it a prime number.
|
|
112 (defconst eldoc-message-commands-table-size 31)
|
98
|
113
|
|
114 ;; Bookkeeping; the car contains the last symbol read from the buffer.
|
|
115 ;; The cdr contains the string last displayed in the echo area, so it can
|
|
116 ;; be printed again if necessary without reconsing.
|
|
117 (defvar eldoc-last-data '(nil . nil))
|
100
|
118 (defvar eldoc-last-message nil)
|
98
|
119
|
|
120 ;; Idle timers are supported in Emacs 19.31 and later.
|
|
121 (defconst eldoc-use-idle-timer-p (fboundp 'run-with-idle-timer))
|
|
122
|
|
123 ;; eldoc's timer object, if using idle timers
|
|
124 (defvar eldoc-timer nil)
|
|
125
|
|
126 ;; idle time delay currently in use by timer.
|
|
127 ;; This is used to determine if eldoc-idle-delay is changed by the user.
|
|
128 (defvar eldoc-current-idle-delay eldoc-idle-delay)
|
|
129
|
|
130
|
|
131 ;;;###autoload
|
|
132 (defun eldoc-mode (&optional prefix)
|
|
133 "*Enable or disable eldoc mode.
|
|
134 See documentation for the variable of the same name for more details.
|
|
135
|
|
136 If called interactively with no prefix argument, toggle current condition
|
|
137 of the mode.
|
|
138 If called with a positive or negative prefix argument, enable or disable
|
|
139 the mode, respectively."
|
|
140 (interactive "P")
|
100
|
141 (setq eldoc-last-message nil)
|
98
|
142 (cond (eldoc-use-idle-timer-p
|
100
|
143 (add-hook 'post-command-hook 'eldoc-schedule-timer)
|
|
144 (add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area))
|
98
|
145 (t
|
|
146 ;; Use post-command-idle-hook if defined, otherwise use
|
|
147 ;; post-command-hook. The former is only proper to use in Emacs
|
|
148 ;; 19.30; that is the first version in which it appeared, but it
|
|
149 ;; was obsolesced by idle timers in Emacs 19.31.
|
|
150 (add-hook (if (boundp 'post-command-idle-hook)
|
100
|
151 'post-command-idle-hook
|
|
152 'post-command-hook)
|
|
153 'eldoc-print-current-symbol-info)
|
|
154 ;; quick and dirty hack for seeing if this is XEmacs
|
|
155 (and (fboundp 'display-message)
|
|
156 (add-hook 'pre-command-hook
|
|
157 'eldoc-pre-command-refresh-echo-area))))
|
98
|
158 (setq eldoc-mode (if prefix
|
|
159 (>= (prefix-numeric-value prefix) 0)
|
|
160 (not eldoc-mode)))
|
|
161 (and (interactive-p)
|
|
162 (if eldoc-mode
|
|
163 (message "eldoc-mode is enabled")
|
|
164 (message "eldoc-mode is disabled")))
|
|
165 eldoc-mode)
|
|
166
|
|
167 ;;;###autoload
|
|
168 (defun turn-on-eldoc-mode ()
|
|
169 "Unequivocally turn on eldoc-mode (see variable documentation)."
|
|
170 (interactive)
|
|
171 (eldoc-mode 1))
|
|
172
|
|
173 ;; Idle timers are part of Emacs 19.31 and later.
|
|
174 (defun eldoc-schedule-timer ()
|
|
175 (or (and eldoc-timer
|
|
176 (memq eldoc-timer timer-idle-list))
|
|
177 (setq eldoc-timer
|
|
178 (run-with-idle-timer eldoc-idle-delay t
|
|
179 'eldoc-print-current-symbol-info)))
|
|
180
|
|
181 ;; If user has changed the idle delay, update the timer.
|
|
182 (cond ((not (= eldoc-idle-delay eldoc-current-idle-delay))
|
|
183 (setq eldoc-current-idle-delay eldoc-idle-delay)
|
|
184 (timer-set-idle-time eldoc-timer eldoc-idle-delay t))))
|
|
185
|
100
|
186 ;; This function goes on pre-command-hook for XEmacs or when using idle
|
|
187 ;; timers in Emacs. Motion commands clear the echo area for some reason,
|
|
188 ;; which make eldoc messages flicker or disappear just before motion
|
|
189 ;; begins. This function reprints the last eldoc message immediately
|
|
190 ;; before the next command executes, which does away with the flicker.
|
|
191 ;; This doesn't seem to be required for Emacs 19.28 and earlier.
|
|
192 (defun eldoc-pre-command-refresh-echo-area ()
|
|
193 (and eldoc-last-message
|
|
194 (if (eldoc-display-message-no-interference-p)
|
|
195 (eldoc-message eldoc-last-message)
|
|
196 (setq eldoc-last-message nil))))
|
|
197
|
|
198 (defun eldoc-message (&rest args)
|
|
199 (let ((omessage eldoc-last-message))
|
|
200 (cond ((eq (car args) eldoc-last-message))
|
|
201 ((or (null args)
|
|
202 (null (car args)))
|
|
203 (setq eldoc-last-message nil))
|
|
204 (t
|
|
205 (setq eldoc-last-message (apply 'format args))))
|
|
206 ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages
|
|
207 ;; are recorded in a log. Do not put eldoc messages in that log since
|
|
208 ;; they are Legion.
|
|
209 (if (fboundp 'display-message)
|
|
210 ;; XEmacs 19.13 way of preventing log messages.
|
|
211 (if eldoc-last-message
|
|
212 (display-message 'no-log eldoc-last-message)
|
|
213 (and omessage
|
|
214 (clear-message 'no-log)))
|
|
215 (let ((message-log-max nil))
|
|
216 (if eldoc-last-message
|
|
217 (message "%s" eldoc-last-message)
|
|
218 (and omessage
|
|
219 (message nil))))))
|
|
220 eldoc-last-message)
|
|
221
|
98
|
222
|
|
223 (defun eldoc-print-current-symbol-info ()
|
100
|
224 (and (eldoc-display-message-p)
|
|
225 (let ((current-symbol (eldoc-current-symbol))
|
|
226 (current-fnsym (eldoc-fnsym-in-current-sexp)))
|
|
227 (or (cond ((eq current-symbol current-fnsym)
|
|
228 (or (eldoc-print-fnsym-args current-fnsym)
|
|
229 (eldoc-print-var-docstring current-symbol)))
|
|
230 (t
|
|
231 (or (eldoc-print-var-docstring current-symbol)
|
|
232 (eldoc-print-fnsym-args current-fnsym))))
|
|
233 (eldoc-message nil)))))
|
98
|
234
|
100
|
235 ;; Decide whether now is a good time to display a message.
|
|
236 (defun eldoc-display-message-p ()
|
|
237 (and (eldoc-display-message-no-interference-p)
|
98
|
238 (cond (eldoc-use-idle-timer-p
|
100
|
239 ;; If this-command is non-nil while running via an idle
|
|
240 ;; timer, we're still in the middle of executing a command,
|
|
241 ;; e.g. a query-replace where it would be annoying to
|
|
242 ;; overwrite the echo area.
|
110
|
243 (and ;(not this-command)
|
100
|
244 (symbolp last-command)
|
98
|
245 (intern-soft (symbol-name last-command)
|
|
246 eldoc-message-commands)))
|
|
247 (t
|
|
248 ;; If we don't have idle timers, this function is
|
|
249 ;; running on post-command-hook directly; that means the
|
|
250 ;; user's last command is still on `this-command', and we
|
|
251 ;; must wait briefly for input to see whether to do display.
|
|
252 (and (symbolp this-command)
|
|
253 (intern-soft (symbol-name this-command)
|
|
254 eldoc-message-commands)
|
100
|
255 (sit-for eldoc-idle-delay))))))
|
98
|
256
|
100
|
257 (defun eldoc-display-message-no-interference-p ()
|
|
258 (and eldoc-mode
|
|
259 (not executing-kbd-macro)
|
|
260 ;; Having this mode operate in an active minibuffer/echo area causes
|
|
261 ;; interference with what's going on there.
|
|
262 (not cursor-in-echo-area)
|
|
263 (not (eq (selected-window) (minibuffer-window)))))
|
98
|
264
|
100
|
265 (defun eldoc-print-fnsym-args (sym)
|
98
|
266 (interactive)
|
100
|
267 (let ((args nil))
|
|
268 (cond ((not (and sym
|
|
269 (symbolp sym)
|
98
|
270 (fboundp sym))))
|
|
271 ((eq sym (car eldoc-last-data))
|
|
272 (setq args (cdr eldoc-last-data)))
|
|
273 ((subrp (eldoc-symbol-function sym))
|
|
274 (setq args (or (eldoc-function-argstring-from-docstring sym)
|
|
275 (eldoc-docstring-first-line (documentation sym t))))
|
|
276 (setcar eldoc-last-data sym)
|
|
277 (setcdr eldoc-last-data args))
|
|
278 (t
|
|
279 (setq args (eldoc-function-argstring sym))
|
|
280 (setcar eldoc-last-data sym)
|
|
281 (setcdr eldoc-last-data args)))
|
|
282 (and args
|
|
283 (eldoc-message "%s: %s" sym args))))
|
|
284
|
|
285 (defun eldoc-fnsym-in-current-sexp ()
|
100
|
286 (let ((p (point)))
|
|
287 (eldoc-beginning-of-sexp)
|
|
288 (prog1
|
|
289 ;; Don't do anything if current word is inside a string.
|
|
290 (if (= (or (char-after (1- (point))) 0) ?\")
|
|
291 nil
|
|
292 (eldoc-current-symbol))
|
|
293 (goto-char p))))
|
|
294
|
|
295 (defun eldoc-beginning-of-sexp ()
|
|
296 (let ((parse-sexp-ignore-comments t))
|
|
297 (condition-case err
|
|
298 (while (progn
|
|
299 (forward-sexp -1)
|
|
300 (or (= (or (char-after (1- (point)))) ?\")
|
|
301 (> (point) (point-min)))))
|
|
302 (error nil))))
|
|
303
|
|
304 ;; returns nil unless current word is an interned symbol.
|
|
305 (defun eldoc-current-symbol ()
|
|
306 (let ((c (char-after (point))))
|
|
307 (and c
|
|
308 (memq (char-syntax c) '(?w ?_))
|
|
309 (intern-soft (current-word)))))
|
|
310
|
|
311 ;; Do indirect function resolution if possible.
|
|
312 (defun eldoc-symbol-function (fsym)
|
|
313 (let ((defn (and (fboundp fsym)
|
|
314 (symbol-function fsym))))
|
|
315 (and (symbolp defn)
|
|
316 (condition-case err
|
|
317 (setq defn (indirect-function fsym))
|
|
318 (error (setq defn nil))))
|
|
319 defn))
|
98
|
320
|
|
321 (defun eldoc-function-argstring (fn)
|
|
322 (let* ((prelim-def (eldoc-symbol-function fn))
|
|
323 (def (if (eq (car-safe prelim-def) 'macro)
|
|
324 (cdr prelim-def)
|
|
325 prelim-def))
|
|
326 (arglist (cond ((null def) nil)
|
|
327 ((byte-code-function-p def)
|
|
328 (if (fboundp 'compiled-function-arglist)
|
|
329 (funcall 'compiled-function-arglist def)
|
|
330 (aref def 0)))
|
|
331 ((eq (car-safe def) 'lambda)
|
|
332 (nth 1 def))
|
|
333 (t t))))
|
|
334 (eldoc-function-argstring-format arglist)))
|
|
335
|
|
336 (defun eldoc-function-argstring-format (arglist)
|
|
337 (cond ((not (listp arglist))
|
|
338 (setq arglist nil))
|
|
339 ((symbolp (car arglist))
|
|
340 (setq arglist
|
|
341 (mapcar (function (lambda (s)
|
|
342 (if (memq s '(&optional &rest))
|
|
343 (symbol-name s)
|
|
344 (funcall eldoc-argument-case
|
|
345 (symbol-name s)))))
|
|
346 arglist)))
|
|
347 ((stringp (car arglist))
|
|
348 (setq arglist
|
|
349 (mapcar (function (lambda (s)
|
|
350 (if (member s '("&optional" "&rest"))
|
|
351 s
|
|
352 (funcall eldoc-argument-case s))))
|
|
353 arglist))))
|
|
354 (concat "(" (mapconcat 'identity arglist " ") ")"))
|
|
355
|
|
356
|
100
|
357 (defun eldoc-print-var-docstring (sym)
|
98
|
358 (eldoc-print-docstring sym (documentation-property
|
|
359 sym 'variable-documentation t)))
|
|
360
|
|
361 ;; Print the brief (one-line) documentation string for the symbol.
|
|
362 (defun eldoc-print-docstring (symbol doc)
|
|
363 (and doc
|
|
364 (eldoc-message "%s" (eldoc-docstring-message symbol doc))))
|
|
365
|
|
366 ;; If the entire line cannot fit in the echo area, the variable name may be
|
|
367 ;; truncated or eliminated entirely from the output to make room.
|
|
368 ;; Any leading `*' in the docstring (which indicates the variable is a user
|
|
369 ;; option) is not printed."
|
|
370 (defun eldoc-docstring-message (symbol doc)
|
|
371 (and doc
|
|
372 (let ((name (symbol-name symbol)))
|
|
373 (setq doc (eldoc-docstring-first-line doc))
|
|
374 (save-match-data
|
|
375 (let* ((doclen (+ (length name) (length ": ") (length doc)))
|
|
376 ;; Subtract 1 from window width since emacs seems not to
|
|
377 ;; write any chars to the last column, at least for some
|
|
378 ;; terminal types.
|
|
379 (strip (- doclen (1- (window-width (minibuffer-window))))))
|
|
380 (cond ((> strip 0)
|
|
381 (let* ((len (length name)))
|
|
382 (cond ((>= strip len)
|
|
383 (format "%s" doc))
|
|
384 (t
|
|
385 (setq name (substring name 0 (- len strip)))
|
|
386 (format "%s: %s" name doc)))))
|
|
387 (t
|
|
388 (format "%s: %s" symbol doc))))))))
|
|
389
|
|
390 (defun eldoc-docstring-first-line (doc)
|
|
391 (save-match-data
|
|
392 (and (string-match "\n" doc)
|
|
393 (setq doc (substring doc 0 (match-beginning 0))))
|
|
394 (and (string-match "^\\*" doc)
|
|
395 (setq doc (substring doc 1))))
|
|
396 doc)
|
|
397
|
|
398
|
|
399 ;; Alist of predicate/action pairs.
|
|
400 ;; Each member of the list is a sublist consisting of a predicate function
|
|
401 ;; used to determine if the arglist for a function can be found using a
|
|
402 ;; certain pattern, and a function which returns the actual arglist from
|
|
403 ;; that docstring.
|
|
404 ;;
|
|
405 ;; The order in this table is significant, since later predicates may be
|
|
406 ;; more general than earlier ones.
|
|
407 ;;
|
|
408 ;; Compiler note for Emacs 19.29 and later: these functions will be
|
|
409 ;; compiled to bytecode, but can't be lazy-loaded even if you set
|
|
410 ;; byte-compile-dynamic; to do that would require making them named
|
|
411 ;; top-level defuns, and that's not particularly desirable either.
|
|
412 (defconst eldoc-function-argstring-from-docstring-method-table
|
|
413 (list
|
|
414 ;; Try first searching for args starting with symbol name.
|
|
415 ;; This is to avoid matching parenthetical remarks in e.g. sit-for.
|
|
416 (list (function (lambda (doc fn)
|
|
417 (string-match (format "^(%s[^\n)]*)$" fn) doc)))
|
|
418 (function (lambda (doc)
|
|
419 ;; end does not include trailing ")" sequence.
|
|
420 (let ((end (- (match-end 0) 1)))
|
|
421 (if (string-match " +" doc (match-beginning 0))
|
|
422 (substring doc (match-end 0) end)
|
|
423 "")))))
|
|
424
|
|
425 ;; Try again not requiring this symbol name in the docstring.
|
|
426 ;; This will be the case when looking up aliases.
|
|
427 (list (function (lambda (doc fn)
|
|
428 (string-match "^([^\n)]+)$" doc)))
|
|
429 (function (lambda (doc)
|
|
430 ;; end does not include trailing ")" sequence.
|
|
431 (let ((end (- (match-end 0) 1)))
|
|
432 (and (string-match " +" doc (match-beginning 0))
|
|
433 (substring doc (match-end 0) end))))))
|
|
434
|
|
435 ;; Emacs subr docstring style:
|
|
436 ;; (fn arg1 arg2 ...): description...
|
|
437 (list (function (lambda (doc fn)
|
|
438 (string-match "^([^\n)]+):" doc)))
|
|
439 (function (lambda (doc)
|
|
440 ;; end does not include trailing "):" sequence.
|
|
441 (let ((end (- (match-end 0) 2)))
|
|
442 (and (string-match " +" doc (match-beginning 0))
|
|
443 (substring doc (match-end 0) end))))))
|
|
444
|
|
445 ;; XEmacs subr docstring style:
|
|
446 ;; "arguments: (arg1 arg2 ...)
|
|
447 (list (function (lambda (doc fn)
|
|
448 (string-match "^arguments: (\\([^\n)]+\\))" doc)))
|
|
449 (function (lambda (doc)
|
|
450 ;; also skip leading paren, but the first word is
|
|
451 ;; actually an argument, not the function name.
|
|
452 (substring doc (match-beginning 1) (match-end 1)))))
|
|
453
|
|
454 ;; This finds the argstring for `condition-case'. Any others?
|
|
455 (list (function (lambda (doc fn)
|
|
456 (string-match
|
|
457 (format "^Usage looks like \\((%s[^\n)]*)\\)\\.$" fn)
|
|
458 doc)))
|
|
459 (function (lambda (doc)
|
|
460 ;; end does not include trailing ")" sequence.
|
|
461 (let ((end (- (match-end 1) 1)))
|
|
462 (and (string-match " +" doc (match-beginning 1))
|
|
463 (substring doc (match-end 0) end))))))
|
|
464
|
|
465 ;; This finds the argstring for `setq-default'. Any others?
|
|
466 (list (function (lambda (doc fn)
|
|
467 (string-match (format "^[ \t]+\\((%s[^\n)]*)\\)$" fn)
|
|
468 doc)))
|
|
469 (function (lambda (doc)
|
|
470 ;; end does not include trailing ")" sequence.
|
|
471 (let ((end (- (match-end 1) 1)))
|
|
472 (and (string-match " +" doc (match-beginning 1))
|
|
473 (substring doc (match-end 0) end))))))
|
|
474
|
|
475 ;; This finds the argstring for `start-process'. Any others?
|
|
476 (list (function (lambda (doc fn)
|
|
477 (string-match "^Args are +\\([^\n]+\\)$" doc)))
|
|
478 (function (lambda (doc)
|
|
479 (substring doc (match-beginning 1) (match-end 1)))))
|
100
|
480
|
|
481 ;; These subrs don't have arglists in their docstrings.
|
|
482 ;; This is cheating.
|
|
483 (list (function (lambda (doc fn)
|
|
484 (memq fn '(and or list + -))))
|
|
485 (function (lambda (doc)
|
|
486 ;; The value nil is a placeholder; otherwise, the
|
|
487 ;; following string may be compiled as a docstring,
|
|
488 ;; and not a return value for the function.
|
|
489 ;; In interpreted lisp form they are
|
|
490 ;; indistinguishable; it only matters for compiled
|
|
491 ;; forms.
|
|
492 nil
|
|
493 "&rest args")))
|
98
|
494 ))
|
|
495
|
|
496 (defun eldoc-function-argstring-from-docstring (fn)
|
|
497 (let ((docstring (documentation fn 'raw))
|
|
498 (table eldoc-function-argstring-from-docstring-method-table)
|
|
499 (doc nil)
|
|
500 (doclist nil))
|
|
501 (save-match-data
|
|
502 (while table
|
|
503 (cond ((funcall (car (car table)) docstring fn)
|
|
504 (setq doc (funcall (car (cdr (car table))) docstring))
|
|
505 (setq table nil))
|
|
506 (t
|
|
507 (setq table (cdr table)))))
|
|
508
|
|
509 (cond ((not (stringp doc))
|
|
510 nil)
|
|
511 ((string-match "&" doc)
|
|
512 (let ((p 0)
|
|
513 (l (length doc)))
|
|
514 (while (< p l)
|
|
515 (cond ((string-match "[ \t\n]+" doc p)
|
|
516 (setq doclist
|
|
517 (cons (substring doc p (match-beginning 0))
|
|
518 doclist))
|
|
519 (setq p (match-end 0)))
|
|
520 (t
|
|
521 (setq doclist (cons (substring doc p) doclist))
|
|
522 (setq p l))))
|
|
523 (eldoc-function-argstring-format (nreverse doclist))))
|
|
524 (t
|
|
525 (concat "(" (funcall eldoc-argument-case doc) ")"))))))
|
|
526
|
|
527
|
100
|
528 ;; When point is in a sexp, the function args are not reprinted in the echo
|
|
529 ;; area after every possible interactive command because some of them print
|
|
530 ;; their own messages in the echo area; the eldoc functions would instantly
|
|
531 ;; overwrite them unless it is more restrained.
|
|
532 ;; These functions do display-command table management.
|
|
533
|
|
534 (defun eldoc-add-command (&rest cmds)
|
|
535 (or eldoc-message-commands
|
|
536 (setq eldoc-message-commands
|
|
537 (make-vector eldoc-message-commands-table-size 0)))
|
|
538
|
|
539 (let (name sym)
|
|
540 (while cmds
|
|
541 (setq name (car cmds))
|
|
542 (setq cmds (cdr cmds))
|
|
543
|
|
544 (cond ((symbolp name)
|
|
545 (setq sym name)
|
|
546 (setq name (symbol-name sym)))
|
|
547 ((stringp name)
|
|
548 (setq sym (intern-soft name))))
|
|
549
|
|
550 (and (symbolp sym)
|
|
551 (fboundp sym)
|
|
552 (set (intern name eldoc-message-commands) t)))))
|
98
|
553
|
100
|
554 (defun eldoc-add-command-completions (&rest names)
|
|
555 (while names
|
|
556 (apply 'eldoc-add-command
|
|
557 (all-completions (car names) obarray 'fboundp))
|
|
558 (setq names (cdr names))))
|
|
559
|
|
560 (defun eldoc-remove-command (&rest cmds)
|
|
561 (let (name)
|
|
562 (while cmds
|
|
563 (setq name (car cmds))
|
|
564 (setq cmds (cdr cmds))
|
|
565
|
|
566 (and (symbolp name)
|
|
567 (setq name (symbol-name name)))
|
98
|
568
|
100
|
569 (if (fboundp 'unintern)
|
|
570 (unintern name eldoc-message-commands)
|
|
571 (let ((s (intern-soft name eldoc-message-commands)))
|
|
572 (and s
|
|
573 (makunbound s)))))))
|
|
574
|
|
575 (defun eldoc-remove-command-completions (&rest names)
|
|
576 (while names
|
|
577 (apply 'eldoc-remove-command
|
|
578 (all-completions (car names) eldoc-message-commands))
|
|
579 (setq names (cdr names))))
|
|
580
|
|
581 ;; Prime the command list.
|
|
582 (eldoc-add-command-completions
|
|
583 "backward-" "beginning-of-" "delete-other-windows" "delete-window"
|
|
584 "end-of-" "forward-" "goto-" "mouse-set-point" "next-" "other-window"
|
|
585 "previous-" "recenter" "scroll-" "self-insert-command" "split-window-")
|
98
|
586
|
|
587 (provide 'eldoc)
|
|
588
|
|
589 ;;; eldoc.el ends here
|