Mercurial > emacs
annotate lisp/emacs-lisp/eldoc.el @ 15833:aa7b0c77a89a
(rmail-reply-regexp): Match Re[2].
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 06 Aug 1996 18:41:06 +0000 |
parents | 27e6b6f4f1b6 |
children | 2b768a1e4f5f |
rev | line source |
---|---|
13530 | 1 ;;; eldoc.el --- show function arglist or variable docstring in echo area |
2 | |
3 ;; Copyright (C) 1995 Noah S. Friedman | |
4 | |
5 ;; Author: Noah Friedman <friedman@prep.ai.mit.edu> | |
6 ;; Maintainer: friedman@prep.ai.mit.edu | |
7 ;; Keywords: extensions | |
8 ;; Status: Works in Emacs 19 and XEmacs. | |
9 ;; Created: 1995-10-06 | |
10 | |
11 ;; LCD Archive Entry: | |
12 ;; eldoc|Noah Friedman|friedman@prep.ai.mit.edu| | |
13 ;; show function arglist or variable docstring in echo area| | |
15671
27e6b6f4f1b6
(eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents:
13647
diff
changeset
|
14 ;; $Date: 1995/11/25 03:45:25 $|$Revision: 1.5 $|~/misc/eldoc.el.gz| |
13530 | 15 |
15671
27e6b6f4f1b6
(eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents:
13647
diff
changeset
|
16 ;; $Id: eldoc.el,v 1.5 1995/11/25 03:45:25 friedman Exp friedman $ |
13530 | 17 |
18 ;; This program is free software; you can redistribute it and/or modify | |
19 ;; it under the terms of the GNU General Public License as published by | |
20 ;; the Free Software Foundation; either version 2, or (at your option) | |
21 ;; any later version. | |
22 ;; | |
23 ;; This program is distributed in the hope that it will be useful, | |
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 ;; GNU General Public License for more details. | |
27 ;; | |
28 ;; You should have received a copy of the GNU General Public License | |
29 ;; along with this program; if not, you can either send email to this | |
30 ;; program's maintainer or write to: The Free Software Foundation, | |
31 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA. | |
32 | |
33 ;;; Commentary: | |
34 | |
35 ;; This program was inspired by the behavior of the Lisp Machine "mouse | |
36 ;; documentation window"; as you type a function's symbol name as part of a | |
37 ;; sexp, it will print the argument list for that function. However, this | |
38 ;; program's behavior is different in a couple of significant ways. For | |
39 ;; one, you need not actually type the function name; you need only move | |
40 ;; point around in a sexp that calls it. However, if point is over a | |
41 ;; documented variable, it will print the one-line documentation for that | |
42 ;; variable instead, to remind you of that variable's purpose. | |
43 | |
44 ;; One useful way to enable this minor mode is to put the following in your | |
45 ;; .emacs: | |
46 ;; | |
47 ;; (autoload 'turn-on-eldoc-mode "eldoc" nil t) | |
48 ;; (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode) | |
49 ;; (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode) | |
50 | |
51 ;;; Code: | |
52 | |
53 ;;;###autoload | |
54 (defvar eldoc-mode nil | |
55 "*If non-nil, show the defined parameters for the elisp function near point. | |
56 | |
57 For the emacs lisp function at the beginning of the sexp which point is | |
58 within, show the defined parameters for the function in the echo area. | |
59 This information is extracted directly from the function or macro if it is | |
60 in pure lisp. | |
61 | |
62 If the emacs function is a subr, the parameters are obtained from the | |
63 documentation string if possible. | |
64 | |
65 If point is over a documented variable, print that variable's docstring | |
66 instead; see function `eldoc-print-var-docstring'. | |
67 | |
68 This variable is buffer-local.") | |
69 (make-variable-buffer-local 'eldoc-mode) | |
70 | |
71 (defvar eldoc-idle-delay 0.50 | |
72 "*Number of seconds of idle time to wait before printing. | |
73 If user input arrives before this interval of time has elapsed after the | |
74 last input, no documentation will be printed. | |
75 | |
76 If this variable is set to 0, no idle time is required.") | |
77 | |
78 (defvar eldoc-argument-case 'upcase | |
79 "Case to display argument names of functions, as a symbol. | |
80 This has two preferred values: `upcase' or `downcase'. | |
81 Actually, any name of a function which takes a string as an argument and | |
82 returns another string is acceptable.") | |
83 | |
84 (defvar eldoc-mode-message-commands nil | |
85 "*Obarray of command names where it is appropriate to print in the echo area. | |
86 | |
87 This is not done for all commands since some print their own | |
88 messages in the echo area, and these functions would instantly overwrite | |
89 them. But self-insert-command as well as most motion commands are good | |
90 candidates. | |
91 | |
92 It is probably best to manipulate this data structure with the commands | |
93 `eldoc-add-command' and `eldoc-remove-command'.") | |
94 | |
95 (cond ((null eldoc-mode-message-commands) | |
96 ;; If you increase the number of buckets, keep it a prime number. | |
97 (setq eldoc-mode-message-commands (make-vector 31 0)) | |
98 (let ((list '("self-insert-command" | |
99 "next-" "previous-" | |
100 "forward-" "backward-" | |
101 "beginning-of-" "end-of-" | |
102 "goto-" | |
103 "recenter" | |
104 "scroll-")) | |
105 (syms nil)) | |
106 (while list | |
107 (setq syms (all-completions (car list) obarray 'fboundp)) | |
108 (setq list (cdr list)) | |
109 (while syms | |
110 (set (intern (car syms) eldoc-mode-message-commands) t) | |
111 (setq syms (cdr syms))))))) | |
112 | |
113 ;; Bookkeeping; the car contains the last symbol read from the buffer. | |
114 ;; The cdr contains the string last displayed in the echo area, so it can | |
115 ;; be printed again if necessary without reconsing. | |
116 (defvar eldoc-last-data '(nil . nil)) | |
117 | |
13591
b2fb0109006d
(eldoc-minor-mode-string): New variable.
Noah Friedman <friedman@splode.com>
parents:
13532
diff
changeset
|
118 (defvar eldoc-minor-mode-string " ElDoc" |
b2fb0109006d
(eldoc-minor-mode-string): New variable.
Noah Friedman <friedman@splode.com>
parents:
13532
diff
changeset
|
119 "*String to display in mode line when Eldoc Mode is enabled.") |
b2fb0109006d
(eldoc-minor-mode-string): New variable.
Noah Friedman <friedman@splode.com>
parents:
13532
diff
changeset
|
120 |
13532
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
121 ;; Put this minor mode on the global minor-mode-alist. |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
122 (or (assq 'eldoc-mode (default-value 'minor-mode-alist)) |
13530 | 123 (setq-default minor-mode-alist |
13532
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
124 (append (default-value 'minor-mode-alist) |
13591
b2fb0109006d
(eldoc-minor-mode-string): New variable.
Noah Friedman <friedman@splode.com>
parents:
13532
diff
changeset
|
125 '((eldoc-mode eldoc-minor-mode-string))))) |
13530 | 126 |
13647
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
127 ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages are |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
128 ;; recorded in a log. Do not put eldoc messages in that log since |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
129 ;; they are Legion. |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
130 (defmacro eldoc-message (&rest args) |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
131 (if (fboundp 'display-message) |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
132 ;; XEmacs 19.13 way of preventing log messages. |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
133 (list 'display-message '(quote no-log) (apply 'list 'format args)) |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
134 (list 'let (list (list 'message-log-max 'nil)) |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
135 (apply 'list 'message args)))) |
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
136 |
13530 | 137 |
138 ;;;###autoload | |
139 (defun eldoc-mode (&optional prefix) | |
140 "*If non-nil, then enable eldoc-mode (see variable docstring)." | |
141 (interactive "P") | |
142 | |
143 ;; Make sure it's on the post-command-idle-hook if defined, otherwise put | |
144 ;; it on post-command-hook. The former first appeared in Emacs 19.30. | |
145 (add-hook (if (boundp 'post-command-idle-hook) | |
146 'post-command-idle-hook | |
147 'post-command-hook) | |
148 'eldoc-mode-print-current-symbol-info) | |
149 | |
15671
27e6b6f4f1b6
(eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents:
13647
diff
changeset
|
150 (setq eldoc-mode (if prefix |
27e6b6f4f1b6
(eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents:
13647
diff
changeset
|
151 (>= (prefix-numeric-value prefix) 0) |
27e6b6f4f1b6
(eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents:
13647
diff
changeset
|
152 (not eldoc-mode))) |
27e6b6f4f1b6
(eldoc-mode): Toggle eldoc-mode if no prefix given.
Noah Friedman <friedman@splode.com>
parents:
13647
diff
changeset
|
153 |
13530 | 154 (and (interactive-p) |
155 (if eldoc-mode | |
156 (message "eldoc-mode is enabled") | |
157 (message "eldoc-mode is disabled"))) | |
158 eldoc-mode) | |
159 | |
160 ;;;###autoload | |
161 (defun turn-on-eldoc-mode () | |
162 "Unequivocally turn on eldoc-mode (see variable documentation)." | |
163 (interactive) | |
164 (eldoc-mode 1)) | |
165 | |
166 (defun eldoc-add-command (cmd) | |
167 "Add COMMAND to the list of commands which causes function arg display. | |
168 If called interactively, completion matches any bound function. | |
169 | |
170 When point is in a sexp, the function args are not reprinted in the echo | |
171 area after every possible interactive command because some of them print | |
172 their own messages in the echo area; the eldoc functions would instantly | |
173 overwrite them unless it is more restrained." | |
174 (interactive "aAdd function to eldoc message commands list: ") | |
175 (and (fboundp cmd) | |
176 (set (intern (symbol-name cmd) eldoc-mode-message-commands) t))) | |
177 | |
178 (defun eldoc-remove-command (cmd) | |
179 "Remove COMMAND from the list of commands which causes function arg display. | |
180 If called interactively, completion matches only those functions currently | |
181 in the list. | |
182 | |
183 When point is in a sexp, the function args are not reprinted in the echo | |
184 area after every possible interactive command because some of them print | |
185 their own messages in the echo area; the eldoc functions would instantly | |
186 overwrite them unless it is more restrained." | |
187 (interactive (list (completing-read | |
188 "Remove function from eldoc message commands list: " | |
189 eldoc-mode-message-commands 'boundp t))) | |
190 (and (symbolp cmd) | |
191 (setq cmd (symbol-name cmd))) | |
192 (if (fboundp 'unintern) | |
193 (unintern cmd eldoc-mode-message-commands) | |
194 (let ((s (intern-soft cmd eldoc-mode-message-commands))) | |
195 (and s | |
196 (makunbound s))))) | |
197 | |
198 (defun eldoc-mode-print-current-symbol-info () | |
199 (and eldoc-mode | |
13614
de978cbb25d2
(eldoc-mode-print-current-symbol-info): Do nothing if executing-macro.
Noah Friedman <friedman@splode.com>
parents:
13591
diff
changeset
|
200 (not executing-macro) |
13530 | 201 ;; Having this mode operate in the minibuffer makes it impossible to |
202 ;; see what you're doing. | |
203 (not (eq (selected-window) (minibuffer-window))) | |
204 (sit-for eldoc-idle-delay) | |
13532
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
205 (symbolp this-command) |
13530 | 206 (intern-soft (symbol-name this-command) eldoc-mode-message-commands) |
207 (let ((current-symbol (eldoc-current-symbol)) | |
208 (current-fnsym (eldoc-fnsym-in-current-sexp))) | |
209 (cond ((eq current-symbol current-fnsym) | |
210 (eldoc-print-fnsym-args current-fnsym)) | |
211 (t | |
212 (or (eldoc-print-var-docstring current-symbol) | |
213 (eldoc-print-fnsym-args current-fnsym))))))) | |
214 | |
215 | |
216 (defun eldoc-print-var-docstring (&optional sym) | |
217 "Print the brief (one-line) documentation string for the variable at point. | |
218 If called with no argument, print the first line of the variable | |
219 documentation string for the symbol at point in the echo area. | |
220 If called with a symbol, print the line for that symbol. | |
221 | |
222 If the entire line cannot fit in the echo area, the variable name may be | |
223 truncated or eliminated entirely from the output to make room. | |
224 Any leading `*' in the docstring (which indicates the variable is a user | |
225 option) is not printed." | |
226 (interactive) | |
227 (let* ((s (or sym (eldoc-current-symbol))) | |
228 (name (symbol-name s)) | |
229 (doc (and s (documentation-property s 'variable-documentation t)))) | |
230 (and doc | |
231 (save-match-data | |
232 (and (string-match "\n" doc) | |
233 (setq doc (substring doc 0 (match-beginning 0)))) | |
234 (and (string-match "^\\*" doc) | |
235 (setq doc (substring doc 1))) | |
236 (let* ((doclen (+ (length name) (length ": ") (length doc))) | |
237 ;; Subtract 1 from window width since emacs seems not to | |
238 ;; write any chars to the last column, at least for some | |
239 ;; terminal types. | |
240 (strip (- doclen (1- (window-width (minibuffer-window)))))) | |
241 (cond ((> strip 0) | |
242 (let* ((len (length name))) | |
243 (cond ((>= strip len) | |
13647
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
244 (eldoc-message "%s" doc)) |
13530 | 245 (t |
246 (setq name (substring name 0 (- len strip))) | |
13647
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
247 (eldoc-message "%s: %s" name doc))))) |
13530 | 248 (t |
13647
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
249 (eldoc-message "%s: %s" s doc)))) |
13530 | 250 t)))) |
251 | |
252 | |
253 ;;;###autoload | |
254 (defun eldoc-print-fnsym-args (&optional symbol) | |
255 "*Show the defined parameters for the function near point. | |
256 For the function at the beginning of the sexp which point is within, show | |
257 the defined parameters for the function in the echo area. | |
258 This information is extracted directly from the function or macro if it is | |
259 in pure lisp. | |
260 If the emacs function is a subr, the parameters are obtained from the | |
261 documentation string if possible." | |
262 (interactive) | |
263 (let ((sym (or symbol (eldoc-fnsym-in-current-sexp))) | |
264 (printit t) | |
265 (args nil)) | |
266 (cond ((not (and (symbolp sym) | |
267 (fboundp sym)))) | |
268 ((eq sym (car eldoc-last-data)) | |
269 (setq printit nil) | |
270 (setq args (cdr eldoc-last-data))) | |
271 ((subrp (eldoc-symbol-function sym)) | |
272 (setq args (eldoc-function-argstring-from-docstring sym)) | |
273 (setcdr eldoc-last-data args)) | |
274 (t | |
275 (setq args (eldoc-function-argstring sym)) | |
276 (setcdr eldoc-last-data args))) | |
277 (and args | |
278 printit | |
13647
40e469e13255
(eldoc-message): New macro.
Noah Friedman <friedman@splode.com>
parents:
13614
diff
changeset
|
279 (eldoc-message "%s: %s" sym args)))) |
13530 | 280 |
281 (defun eldoc-fnsym-in-current-sexp () | |
282 (let* ((p (point)) | |
283 (sym (progn | |
284 (while (and (eldoc-forward-sexp-safe -1) | |
285 (> (point) (point-min)))) | |
286 (cond ((or (= (point) (point-min)) | |
287 (memq (or (char-after (point)) 0) | |
288 '(?\( ?\")) | |
289 ;; If we hit a quotation mark before a paren, we | |
290 ;; are inside a specific string, not a list of | |
291 ;; symbols. | |
292 (eq (or (char-after (1- (point))) 0) ?\")) | |
293 nil) | |
294 (t (condition-case nil | |
295 (read (current-buffer)) | |
296 (error nil))))))) | |
297 (goto-char p) | |
298 (and (symbolp sym) | |
299 sym))) | |
300 | |
301 (defun eldoc-function-argstring (fn) | |
13532
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
302 (let* ((prelim-def (eldoc-symbol-function fn)) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
303 (def (if (eq (car-safe prelim-def) 'macro) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
304 (cdr prelim-def) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
305 prelim-def)) |
13530 | 306 (arglist (cond ((null def) nil) |
13532
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
307 ((byte-code-function-p def) |
13530 | 308 (if (fboundp 'compiled-function-arglist) |
309 (funcall 'compiled-function-arglist def) | |
13532
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
310 (aref def 0))) |
13530 | 311 ((eq (car-safe def) 'lambda) |
312 (nth 1 def)) | |
313 (t t)))) | |
314 (eldoc-function-argstring-format arglist))) | |
315 | |
316 (defun eldoc-function-argstring-from-docstring (fn) | |
317 (let ((docstring (documentation fn 'raw)) | |
318 (doc nil) | |
319 (doclist nil) | |
320 (end nil)) | |
321 (save-match-data | |
322 (cond | |
323 ;; Try first searching for args starting with symbol name. | |
324 ;; This is to avoid matching parenthetical remarks in e.g. sit-for. | |
325 ((string-match (format "^(%s[^\n)]*)$" fn) docstring) | |
326 ;; end does not include trailing ")" sequence. | |
327 (setq end (- (match-end 0) 1)) | |
328 (if (string-match " +" docstring (match-beginning 0)) | |
329 (setq doc (substring docstring (match-end 0) end)) | |
330 (setq doc ""))) | |
331 | |
332 ;; Try again not requiring this symbol name in the docstring. | |
333 ;; This will be the case when looking up aliases. | |
334 ((string-match (format "^([^\n)]+)$" fn) docstring) | |
335 ;; end does not include trailing ")" sequence. | |
336 (setq end (- (match-end 0) 1)) | |
337 (if (string-match " +" docstring (match-beginning 0)) | |
338 (setq doc (substring docstring (match-end 0) end)) | |
339 (setq doc ""))) | |
340 | |
341 ;; Emacs subr docstring style: | |
342 ;; (fn arg1 arg2 ...): description... | |
343 ((string-match "^([^\n)]+):" docstring) | |
344 ;; end does not include trailing "):" sequence. | |
345 (setq end (- (match-end 0) 2)) | |
346 (if (string-match " +" docstring (match-beginning 0)) | |
347 (setq doc (substring docstring (match-end 0) end)) | |
348 (setq doc ""))) | |
349 | |
350 ;; XEmacs subr docstring style: | |
351 ;; "arguments: (arg1 arg2 ...) | |
352 ((string-match "^arguments: (\\([^\n)]+\\))" docstring) | |
353 ;; Also, skip leading paren, but the first word is actually an | |
354 ;; argument, not the function name. | |
355 (setq doc (substring docstring | |
356 (match-beginning 1) | |
357 (match-end 1)))) | |
358 | |
13532
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
359 ;; This finds the argstring for `condition-case'. |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
360 ;; I don't know if there are any others with the same pattern. |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
361 ((string-match (format "^Usage looks like \\((%s[^\n)]*)\\)\\.$" fn) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
362 docstring) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
363 ;; end does not include trailing ")" sequence. |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
364 (setq end (- (match-end 1) 1)) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
365 (if (string-match " +" docstring (match-beginning 1)) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
366 (setq doc (substring docstring (match-end 0) end)) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
367 (setq doc ""))) |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
368 |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
369 ;; This finds the argstring for `setq-default'. |
37fdd3664658
(top level): Make sure to set global minor-mode-alist, not local one.
Noah Friedman <friedman@splode.com>
parents:
13530
diff
changeset
|
370 ;; I don't know if there are any others with the same pattern. |
13530 | 371 ((string-match (format "^[ \t]+\\((%s[^\n)]*)\\)$" fn) docstring) |
372 ;; end does not include trailing ")" sequence. | |
373 (setq end (- (match-end 1) 1)) | |
374 (if (string-match " +" docstring (match-beginning 1)) | |
375 (setq doc (substring docstring (match-end 0) end)) | |
376 (setq doc "")))) | |
377 | |
378 (cond ((not (stringp doc)) | |
379 nil) | |
380 ((string-match "&" doc) | |
381 (let ((p 0) | |
382 (l (length doc))) | |
383 (while (< p l) | |
384 (cond ((string-match "[ \t\n]+" doc p) | |
385 (setq doclist | |
386 (cons (substring doc p (match-beginning 0)) | |
387 doclist)) | |
388 (setq p (match-end 0))) | |
389 (t | |
390 (setq doclist (cons (substring doc p) doclist)) | |
391 (setq p l)))) | |
392 (eldoc-function-argstring-format (nreverse doclist)))) | |
393 (t | |
394 (concat "(" (funcall eldoc-argument-case doc) ")")))))) | |
395 | |
396 (defun eldoc-function-argstring-format (arglist) | |
397 (cond ((not (listp arglist)) | |
398 (setq arglist nil)) | |
399 ((symbolp (car arglist)) | |
400 (setq arglist | |
401 (mapcar (function (lambda (s) | |
402 (if (memq s '(&optional &rest)) | |
403 (symbol-name s) | |
404 (funcall eldoc-argument-case | |
405 (symbol-name s))))) | |
406 arglist))) | |
407 ((stringp (car arglist)) | |
408 (setq arglist | |
409 (mapcar (function (lambda (s) | |
410 (if (member s '("&optional" "&rest")) | |
411 s | |
412 (funcall eldoc-argument-case s)))) | |
413 arglist)))) | |
414 (concat "(" (mapconcat 'identity arglist " ") ")")) | |
415 | |
416 | |
417 ;; forward-sexp calls scan-sexps, which returns an error if it hits the | |
418 ;; beginning or end of the sexp. This returns nil instead. | |
419 (defun eldoc-forward-sexp-safe (&optional count) | |
420 "Move forward across one balanced expression (sexp). | |
421 With argument, do it that many times. Negative arg -COUNT means | |
422 move backward across COUNT balanced expressions. | |
423 Return distance in buffer moved, or nil." | |
424 (or count (setq count 1)) | |
425 (condition-case err | |
426 (- (- (point) (progn | |
427 (let ((parse-sexp-ignore-comments t)) | |
428 (forward-sexp count)) | |
429 (point)))) | |
430 (error nil))) | |
431 | |
432 ;; Do indirect function resolution if possible. | |
433 (defun eldoc-symbol-function (fsym) | |
434 (let ((defn (and (fboundp fsym) | |
435 (symbol-function fsym)))) | |
436 (and (symbolp defn) | |
437 (condition-case err | |
438 (setq defn (indirect-function fsym)) | |
439 (error (setq defn nil)))) | |
440 defn)) | |
441 | |
442 (defun eldoc-current-symbol () | |
443 (let ((c (char-after (point)))) | |
444 (and c | |
445 (memq (char-syntax c) '(?w ?_)) | |
446 (intern-soft (current-word))))) | |
447 | |
448 (provide 'eldoc) | |
449 | |
450 ;;; eldoc.el ends here |