Mercurial > emacs
comparison lisp/emacs-lisp/eldoc.el @ 49697:eb34aebd1084
(eldoc-echo-area-multiline-supported-p, eldoc-use-idle-timer-p): Remove.
(timer): Never require. It only works in current Emacs anyway.
(eldoc-mode, eldoc-message, eldoc-display-message-p)
(eldoc-docstring-format-sym-doc, eldoc-remove-command): Simplify.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 11 Feb 2003 00:11:55 +0000 |
parents | cd1e53e61699 |
children | 3a65ede5c70c d7ddb3e565de |
comparison
equal
deleted
inserted
replaced
49696:b9ae76081fef | 49697:eb34aebd1084 |
---|---|
5 ;; Author: Noah Friedman <friedman@splode.com> | 5 ;; Author: Noah Friedman <friedman@splode.com> |
6 ;; Maintainer: friedman@splode.com | 6 ;; Maintainer: friedman@splode.com |
7 ;; Keywords: extensions | 7 ;; Keywords: extensions |
8 ;; Created: 1995-10-06 | 8 ;; Created: 1995-10-06 |
9 | 9 |
10 ;; $Id: eldoc.el,v 1.22 2003/01/03 11:46:20 jpw Exp $ | 10 ;; $Id: eldoc.el,v 1.23 2003/01/03 11:53:46 jpw Exp $ |
11 | 11 |
12 ;; This file is part of GNU Emacs. | 12 ;; This file is part of GNU Emacs. |
13 | 13 |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | 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 | 15 ;; it under the terms of the GNU General Public License as published by |
46 ;; (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode) | 46 ;; (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode) |
47 | 47 |
48 ;;; Code: | 48 ;;; Code: |
49 | 49 |
50 (require 'help-fns) ;For fundoc-usage handling functions. | 50 (require 'help-fns) ;For fundoc-usage handling functions. |
51 | |
52 ;; Use idle timers if available in the version of emacs running. | |
53 ;; Please don't change this to use `require'; this package works | |
54 ;; as-is in XEmacs 19.14 and later and I am striving to maintain | |
55 ;; compatibility between emacs variants. | |
56 (or (featurep 'timer) | |
57 (load "timer" t)) | |
58 | 51 |
59 (defgroup eldoc nil | 52 (defgroup eldoc nil |
60 "Show function arglist or variable docstring in echo area." | 53 "Show function arglist or variable docstring in echo area." |
61 :group 'lisp | 54 :group 'lisp |
62 :group 'extensions) | 55 :group 'extensions) |
97 single line without resizing window. Otherwise, behavior is just like | 90 single line without resizing window. Otherwise, behavior is just like |
98 former case. | 91 former case. |
99 | 92 |
100 If value is nil, messages are always truncated to fit in a single line of | 93 If value is nil, messages are always truncated to fit in a single line of |
101 display in the echo area. Function or variable symbol name may be | 94 display in the echo area. Function or variable symbol name may be |
102 truncated to make more of the arglist or documentation string visible. | 95 truncated to make more of the arglist or documentation string visible." |
103 | |
104 Non-nil values for this variable have no effect unless | |
105 `eldoc-echo-area-multiline-supported-p' is non-nil." | |
106 :type '(radio (const :tag "Always" t) | 96 :type '(radio (const :tag "Always" t) |
107 (const :tag "Never" nil) | 97 (const :tag "Never" nil) |
108 (const :tag "Yes, but truncate symbol names if it will\ | 98 (const :tag "Yes, but truncate symbol names if it will\ |
109 enable argument list to fit on one line" truncate-sym-name-if-fit)) | 99 enable argument list to fit on one line" truncate-sym-name-if-fit)) |
110 :group 'eldoc) | 100 :group 'eldoc) |
111 | 101 |
112 ;;; No user options below here. | 102 ;;; No user options below here. |
113 | |
114 ;; Non-nil if this version of emacs supports dynamically resizable echo areas. | |
115 (defvar eldoc-echo-area-multiline-supported-p | |
116 (and (string-lessp "21" emacs-version) | |
117 (save-match-data | |
118 (numberp (string-match "^GNU Emacs" (emacs-version)))))) | |
119 | 103 |
120 ;; Commands after which it is appropriate to print in the echo area. | 104 ;; Commands after which it is appropriate to print in the echo area. |
121 ;; Eldoc does not try to print function arglists, etc. after just any command, | 105 ;; Eldoc does not try to print function arglists, etc. after just any command, |
122 ;; because some commands print their own messages in the echo area and these | 106 ;; because some commands print their own messages in the echo area and these |
123 ;; functions would instantly overwrite them. But self-insert-command as well | 107 ;; functions would instantly overwrite them. But self-insert-command as well |
140 ;; symbol, so it can be printed again if necessary without reconsing. | 124 ;; symbol, so it can be printed again if necessary without reconsing. |
141 ;; 2 - 'function if function args, 'variable if variable documentation. | 125 ;; 2 - 'function if function args, 'variable if variable documentation. |
142 (defvar eldoc-last-data (make-vector 3 nil)) | 126 (defvar eldoc-last-data (make-vector 3 nil)) |
143 (defvar eldoc-last-message nil) | 127 (defvar eldoc-last-message nil) |
144 | 128 |
145 ;; Idle timers are supported in Emacs 19.31 and later. | 129 ;; eldoc's timer object. |
146 (defvar eldoc-use-idle-timer-p (fboundp 'run-with-idle-timer)) | |
147 | |
148 ;; eldoc's timer object, if using idle timers | |
149 (defvar eldoc-timer nil) | 130 (defvar eldoc-timer nil) |
150 | 131 |
151 ;; idle time delay currently in use by timer. | 132 ;; idle time delay currently in use by timer. |
152 ;; This is used to determine if eldoc-idle-delay is changed by the user. | 133 ;; This is used to determine if eldoc-idle-delay is changed by the user. |
153 (defvar eldoc-current-idle-delay eldoc-idle-delay) | 134 (defvar eldoc-current-idle-delay eldoc-idle-delay) |
168 instead. | 149 instead. |
169 | 150 |
170 With prefix ARG, turn ElDoc mode on if and only if ARG is positive." | 151 With prefix ARG, turn ElDoc mode on if and only if ARG is positive." |
171 nil eldoc-minor-mode-string nil | 152 nil eldoc-minor-mode-string nil |
172 (setq eldoc-last-message nil) | 153 (setq eldoc-last-message nil) |
173 (cond (eldoc-use-idle-timer-p | 154 (if eldoc-mode |
174 (add-hook 'post-command-hook 'eldoc-schedule-timer) | 155 (progn |
175 (add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area)) | 156 (add-hook 'post-command-hook 'eldoc-schedule-timer nil t) |
176 (t | 157 (add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t)) |
177 ;; Use post-command-idle-hook if defined, otherwise use | 158 (remove-hook 'post-command-hook 'eldoc-schedule-timer) |
178 ;; post-command-hook. The former is only proper to use in Emacs | 159 (remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area))) |
179 ;; 19.30; that is the first version in which it appeared, but it | |
180 ;; was obsolesced by idle timers in Emacs 19.31. | |
181 (add-hook (if (boundp 'post-command-idle-hook) | |
182 'post-command-idle-hook | |
183 'post-command-hook) | |
184 'eldoc-print-current-symbol-info t t) | |
185 ;; quick and dirty hack for seeing if this is XEmacs | |
186 (and (fboundp 'display-message) | |
187 (add-hook 'pre-command-hook | |
188 'eldoc-pre-command-refresh-echo-area t t))))) | |
189 | 160 |
190 ;;;###autoload | 161 ;;;###autoload |
191 (defun turn-on-eldoc-mode () | 162 (defun turn-on-eldoc-mode () |
192 "Unequivocally turn on eldoc-mode (see variable documentation)." | 163 "Unequivocally turn on eldoc-mode (see variable documentation)." |
193 (interactive) | 164 (interactive) |
207 (setq eldoc-current-idle-delay eldoc-idle-delay) | 178 (setq eldoc-current-idle-delay eldoc-idle-delay) |
208 (timer-set-idle-time eldoc-timer eldoc-idle-delay t)))) | 179 (timer-set-idle-time eldoc-timer eldoc-idle-delay t)))) |
209 | 180 |
210 (defun eldoc-message (&rest args) | 181 (defun eldoc-message (&rest args) |
211 (let ((omessage eldoc-last-message)) | 182 (let ((omessage eldoc-last-message)) |
212 (cond ((eq (car args) eldoc-last-message)) | 183 (setq eldoc-last-message |
213 ((or (null args) | 184 (cond ((eq (car args) eldoc-last-message) eldoc-last-message) |
214 (null (car args))) | 185 ((null (car args)) nil) |
215 (setq eldoc-last-message nil)) | 186 ;; If only one arg, no formatting to do, so put it in |
216 ;; If only one arg, no formatting to do so put it in | 187 ;; eldoc-last-message so eq test above might succeed on |
217 ;; eldoc-last-message so eq test above might succeed on | 188 ;; subsequent calls. |
218 ;; subsequent calls. | 189 ((null (cdr args)) (car args)) |
219 ((null (cdr args)) | 190 (t (apply 'format args)))) |
220 (setq eldoc-last-message (car args))) | |
221 (t | |
222 (setq eldoc-last-message (apply 'format args)))) | |
223 ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages | 191 ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages |
224 ;; are recorded in a log. Do not put eldoc messages in that log since | 192 ;; are recorded in a log. Do not put eldoc messages in that log since |
225 ;; they are Legion. | 193 ;; they are Legion. |
226 (cond ((fboundp 'display-message) | 194 ;; Emacs way of preventing log messages. |
227 ;; XEmacs 19.13 way of preventing log messages. | 195 (let ((message-log-max nil)) |
228 (cond (eldoc-last-message | 196 (cond (eldoc-last-message (message "%s" eldoc-last-message)) |
229 (display-message 'no-log eldoc-last-message)) | 197 (omessage (message nil))))) |
230 (omessage | |
231 (clear-message 'no-log)))) | |
232 (t | |
233 ;; Emacs way of preventing log messages. | |
234 (let ((message-log-max nil)) | |
235 (cond (eldoc-last-message | |
236 (message "%s" eldoc-last-message)) | |
237 (omessage | |
238 (message nil))))))) | |
239 eldoc-last-message) | 198 eldoc-last-message) |
240 | 199 |
241 ;; This function goes on pre-command-hook for XEmacs or when using idle | 200 ;; This function goes on pre-command-hook for XEmacs or when using idle |
242 ;; timers in Emacs. Motion commands clear the echo area for some reason, | 201 ;; timers in Emacs. Motion commands clear the echo area for some reason, |
243 ;; which make eldoc messages flicker or disappear just before motion | 202 ;; which make eldoc messages flicker or disappear just before motion |
251 (setq eldoc-last-message nil)))) | 210 (setq eldoc-last-message nil)))) |
252 | 211 |
253 ;; Decide whether now is a good time to display a message. | 212 ;; Decide whether now is a good time to display a message. |
254 (defun eldoc-display-message-p () | 213 (defun eldoc-display-message-p () |
255 (and (eldoc-display-message-no-interference-p) | 214 (and (eldoc-display-message-no-interference-p) |
256 (cond (eldoc-use-idle-timer-p | 215 ;; If this-command is non-nil while running via an idle |
257 ;; If this-command is non-nil while running via an idle | 216 ;; timer, we're still in the middle of executing a command, |
258 ;; timer, we're still in the middle of executing a command, | 217 ;; e.g. a query-replace where it would be annoying to |
259 ;; e.g. a query-replace where it would be annoying to | 218 ;; overwrite the echo area. |
260 ;; overwrite the echo area. | 219 (and (not this-command) |
261 (and (not this-command) | 220 (symbolp last-command) |
262 (symbolp last-command) | 221 (intern-soft (symbol-name last-command) |
263 (intern-soft (symbol-name last-command) | 222 eldoc-message-commands)))) |
264 eldoc-message-commands))) | |
265 (t | |
266 ;; If we don't have idle timers, this function is | |
267 ;; running on post-command-hook directly; that means the | |
268 ;; user's last command is still on `this-command', and we | |
269 ;; must wait briefly for input to see whether to do display. | |
270 (and (symbolp this-command) | |
271 (intern-soft (symbol-name this-command) | |
272 eldoc-message-commands) | |
273 (sit-for eldoc-idle-delay)))))) | |
274 | 223 |
275 ;; Check various conditions about the current environment that might make | 224 ;; Check various conditions about the current environment that might make |
276 ;; it undesirable to print eldoc messages right this instant. | 225 ;; it undesirable to print eldoc messages right this instant. |
277 (defun eldoc-display-message-no-interference-p () | 226 (defun eldoc-display-message-no-interference-p () |
278 (and eldoc-mode | 227 (and eldoc-mode |
305 ;; docstring if function is a subr and no arglist is obtainable from the | 254 ;; docstring if function is a subr and no arglist is obtainable from the |
306 ;; docstring or elsewhere. | 255 ;; docstring or elsewhere. |
307 (defun eldoc-get-fnsym-args-string (sym) | 256 (defun eldoc-get-fnsym-args-string (sym) |
308 (let ((args nil) | 257 (let ((args nil) |
309 (doc nil)) | 258 (doc nil)) |
310 (cond ((not (and sym | 259 (cond ((not (and sym (symbolp sym) (fboundp sym)))) |
311 (symbolp sym) | |
312 (fboundp sym)))) | |
313 ((and (eq sym (aref eldoc-last-data 0)) | 260 ((and (eq sym (aref eldoc-last-data 0)) |
314 (eq 'function (aref eldoc-last-data 2))) | 261 (eq 'function (aref eldoc-last-data 2))) |
315 (setq doc (aref eldoc-last-data 1))) | 262 (setq doc (aref eldoc-last-data 1))) |
316 ((setq doc (help-split-fundoc (documentation sym t) sym)) | 263 ((setq doc (help-split-fundoc (documentation sym t) sym)) |
317 (setq args (car doc)) | 264 (setq args (car doc)) |
360 ;; truncated or eliminated entirely from the output to make room for the | 307 ;; truncated or eliminated entirely from the output to make room for the |
361 ;; description. | 308 ;; description. |
362 (defun eldoc-docstring-format-sym-doc (sym doc) | 309 (defun eldoc-docstring-format-sym-doc (sym doc) |
363 (save-match-data | 310 (save-match-data |
364 (let* ((name (symbol-name sym)) | 311 (let* ((name (symbol-name sym)) |
365 (ea-multi (and eldoc-echo-area-multiline-supported-p | 312 (ea-multi eldoc-echo-area-use-multiline-p) |
366 eldoc-echo-area-use-multiline-p)) | |
367 ;; Subtract 1 from window width since emacs will not write | 313 ;; Subtract 1 from window width since emacs will not write |
368 ;; any chars to the last column, or in later versions, will | 314 ;; any chars to the last column, or in later versions, will |
369 ;; cause a wraparound and resize of the echo area. | 315 ;; cause a wraparound and resize of the echo area. |
370 (ea-width (1- (window-width (minibuffer-window)))) | 316 (ea-width (1- (window-width (minibuffer-window)))) |
371 (strip (- (+ (length name) (length ": ") (length doc)) ea-width))) | 317 (strip (- (+ (length name) (length ": ") (length doc)) ea-width))) |
471 (fboundp sym) | 417 (fboundp sym) |
472 (set (intern name eldoc-message-commands) t))))) | 418 (set (intern name eldoc-message-commands) t))))) |
473 | 419 |
474 (defun eldoc-add-command-completions (&rest names) | 420 (defun eldoc-add-command-completions (&rest names) |
475 (while names | 421 (while names |
476 (apply 'eldoc-add-command | 422 (apply 'eldoc-add-command |
477 (all-completions (car names) obarray 'fboundp)) | 423 (all-completions (car names) obarray 'fboundp)) |
478 (setq names (cdr names)))) | 424 (setq names (cdr names)))) |
479 | 425 |
480 (defun eldoc-remove-command (&rest cmds) | 426 (defun eldoc-remove-command (&rest cmds) |
481 (let (name) | 427 (let (name) |
482 (while cmds | 428 (while cmds |
483 (setq name (car cmds)) | 429 (setq name (car cmds)) |
484 (setq cmds (cdr cmds)) | 430 (setq cmds (cdr cmds)) |
485 | 431 |
486 (and (symbolp name) | 432 (and (symbolp name) |
487 (setq name (symbol-name name))) | 433 (setq name (symbol-name name))) |
488 | 434 |
489 (if (fboundp 'unintern) | 435 (unintern name eldoc-message-commands)))) |
490 (unintern name eldoc-message-commands) | |
491 (let ((s (intern-soft name eldoc-message-commands))) | |
492 (and s | |
493 (makunbound s))))))) | |
494 | 436 |
495 (defun eldoc-remove-command-completions (&rest names) | 437 (defun eldoc-remove-command-completions (&rest names) |
496 (while names | 438 (while names |
497 (apply 'eldoc-remove-command | 439 (apply 'eldoc-remove-command |
498 (all-completions (car names) eldoc-message-commands)) | 440 (all-completions (car names) eldoc-message-commands)) |