diff options
| author | Noah Friedman | 1997-02-19 10:24:26 +0000 |
|---|---|---|
| committer | Noah Friedman | 1997-02-19 10:24:26 +0000 |
| commit | 9d497c0123892d4756963be81fa29c04073ab94c (patch) | |
| tree | 25f225bbe95c5dc8d242a4b84945f3558eeeb918 | |
| parent | 2884cbf0e87b6581b626562afee7709f7d63213f (diff) | |
| download | emacs-9d497c0123892d4756963be81fa29c04073ab94c.tar.gz emacs-9d497c0123892d4756963be81fa29c04073ab94c.zip | |
(eldoc-message-commands): Doc fixes.
(eldoc-message): Make function, not macro.
(eldoc-last-message): New internal variable.
(eldoc-mode): Initialize it to nil.
(eldoc-message): Use it.
(eldoc-print-current-symbol-info): Use it.
(eldoc-pre-command-refresh-echo-area): New function.
(eldoc-mode): Put it on pre-command-hook if in XEmacs or using idle timers
in Emacs.
(eldoc-message-commands-table-size): New constant.
(eldoc-add-command): Use it to initialize eldoc-message-commands.
(eldoc-display-message-no-interference-p): New function.
(eldoc-display-message-p): Use it.
(eldoc-print-fnsym-args, eldoc-print-var-docstring): Arg sym no longer
optional.
Do not initialize arg if nil.
(eldoc-forward-sexp-safe): Function deleted.
(eldoc-beginning-of-sexp): New function.
(eldoc-fnsym-in-current-sexp): Use eldoc-beginning-of-sexp.
Use eldoc-current-symbol to get symbol at point.
(eldoc-function-argstring-from-docstring-method-table): Forge docstrings
for `and', `or', `list', `+', and `-'.
(eldoc-add-command-completions): New function.
(eldoc-add-command): Take list of args.
No longer interactive.
(eldoc-remove-command-completions): New function.
(eldoc-remove-command): Take list of args.
No longer interactive.
top level: Initialize eldoc-message-commands using
eldoc-add-command-completions.
| -rw-r--r-- | lisp/emacs-lisp/eldoc.el | 322 |
1 files changed, 184 insertions, 138 deletions
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index dfb983e771f..77b19422a57 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | ;; Keywords: extensions | 7 | ;; Keywords: extensions |
| 8 | ;; Created: 1995-10-06 | 8 | ;; Created: 1995-10-06 |
| 9 | 9 | ||
| 10 | ;; $Id: eldoc.el,v 1.8 1997/02/03 06:13:34 friedman Exp $ | 10 | ;; $Id: eldoc.el,v 1.9 1997/02/04 18:21:29 friedman Exp $ |
| 11 | 11 | ||
| 12 | ;; This file is part of GNU Emacs. | 12 | ;; This file is part of GNU Emacs. |
| 13 | 13 | ||
| @@ -92,41 +92,30 @@ This has two preferred values: `upcase' or `downcase'. | |||
| 92 | Actually, any name of a function which takes a string as an argument and | 92 | Actually, any name of a function which takes a string as an argument and |
| 93 | returns another string is acceptable.") | 93 | returns another string is acceptable.") |
| 94 | 94 | ||
| 95 | ;; No user options below here. | ||
| 96 | |||
| 95 | (defvar eldoc-message-commands nil | 97 | (defvar eldoc-message-commands nil |
| 96 | "*Commands after which it is appropriate to print in the echo area. | 98 | "Commands after which it is appropriate to print in the echo area. |
| 97 | 99 | ||
| 98 | Eldoc does not try to print function arglists, etc. after just any command, | 100 | Eldoc does not try to print function arglists, etc. after just any command, |
| 99 | because some commands print their own messages in the echo area and these | 101 | because some commands print their own messages in the echo area and these |
| 100 | functions would instantly overwrite them. But self-insert-command as well | 102 | functions would instantly overwrite them. But self-insert-command as well |
| 101 | as most motion commands are good candidates. | 103 | as most motion commands are good candidates. |
| 102 | 104 | ||
| 103 | This variable contains an obarray of symbols; it is probably best to | 105 | This variable contains an obarray of symbols; do not manipulate it |
| 104 | manipulate this data structure with the commands `eldoc-add-command' and | 106 | directly. Instead, use the functions `eldoc-add-command' and |
| 105 | `eldoc-remove-command'.") | 107 | `eldoc-remove-command'.") |
| 106 | 108 | ||
| 107 | (cond ((null eldoc-message-commands) | 109 | ;; This is used by eldoc-add-command to initialize eldoc-message-commands |
| 108 | ;; If you increase the number of buckets, keep it a prime number. | 110 | ;; as an obarray. |
| 109 | (setq eldoc-message-commands (make-vector 31 0)) | 111 | ;; If you increase the number of buckets, keep it a prime number. |
| 110 | (let ((list '("self-insert-command" | 112 | (defconst eldoc-message-commands-table-size 31) |
| 111 | "next-" "previous-" | ||
| 112 | "forward-" "backward-" | ||
| 113 | "beginning-of-" "end-of-" | ||
| 114 | "goto-" | ||
| 115 | "recenter" | ||
| 116 | "scroll-" | ||
| 117 | "mouse-set-point")) | ||
| 118 | (syms nil)) | ||
| 119 | (while list | ||
| 120 | (setq syms (all-completions (car list) obarray 'fboundp)) | ||
| 121 | (setq list (cdr list)) | ||
| 122 | (while syms | ||
| 123 | (set (intern (car syms) eldoc-message-commands) t) | ||
| 124 | (setq syms (cdr syms))))))) | ||
| 125 | 113 | ||
| 126 | ;; Bookkeeping; the car contains the last symbol read from the buffer. | 114 | ;; Bookkeeping; the car contains the last symbol read from the buffer. |
| 127 | ;; The cdr contains the string last displayed in the echo area, so it can | 115 | ;; The cdr contains the string last displayed in the echo area, so it can |
| 128 | ;; be printed again if necessary without reconsing. | 116 | ;; be printed again if necessary without reconsing. |
| 129 | (defvar eldoc-last-data '(nil . nil)) | 117 | (defvar eldoc-last-data '(nil . nil)) |
| 118 | (defvar eldoc-last-message nil) | ||
| 130 | 119 | ||
| 131 | ;; Idle timers are supported in Emacs 19.31 and later. | 120 | ;; Idle timers are supported in Emacs 19.31 and later. |
| 132 | (defconst eldoc-use-idle-timer-p (fboundp 'run-with-idle-timer)) | 121 | (defconst eldoc-use-idle-timer-p (fboundp 'run-with-idle-timer)) |
| @@ -138,16 +127,6 @@ manipulate this data structure with the commands `eldoc-add-command' and | |||
| 138 | ;; This is used to determine if eldoc-idle-delay is changed by the user. | 127 | ;; This is used to determine if eldoc-idle-delay is changed by the user. |
| 139 | (defvar eldoc-current-idle-delay eldoc-idle-delay) | 128 | (defvar eldoc-current-idle-delay eldoc-idle-delay) |
| 140 | 129 | ||
| 141 | ;; In emacs 19.29 and later, and XEmacs 19.13 and later, all messages are | ||
| 142 | ;; recorded in a log. Do not put eldoc messages in that log since | ||
| 143 | ;; they are Legion. | ||
| 144 | (defmacro eldoc-message (&rest args) | ||
| 145 | (if (fboundp 'display-message) | ||
| 146 | ;; XEmacs 19.13 way of preventing log messages. | ||
| 147 | (list 'display-message '(quote no-log) (apply 'list 'format args)) | ||
| 148 | (list 'let (list (list 'message-log-max 'nil)) | ||
| 149 | (apply 'list 'message args)))) | ||
| 150 | |||
| 151 | 130 | ||
| 152 | ;;;###autoload | 131 | ;;;###autoload |
| 153 | (defun eldoc-mode (&optional prefix) | 132 | (defun eldoc-mode (&optional prefix) |
| @@ -159,23 +138,26 @@ of the mode. | |||
| 159 | If called with a positive or negative prefix argument, enable or disable | 138 | If called with a positive or negative prefix argument, enable or disable |
| 160 | the mode, respectively." | 139 | the mode, respectively." |
| 161 | (interactive "P") | 140 | (interactive "P") |
| 162 | 141 | (setq eldoc-last-message nil) | |
| 163 | (cond (eldoc-use-idle-timer-p | 142 | (cond (eldoc-use-idle-timer-p |
| 164 | (add-hook 'post-command-hook 'eldoc-schedule-timer)) | 143 | (add-hook 'post-command-hook 'eldoc-schedule-timer) |
| 144 | (add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area)) | ||
| 165 | (t | 145 | (t |
| 166 | ;; Use post-command-idle-hook if defined, otherwise use | 146 | ;; Use post-command-idle-hook if defined, otherwise use |
| 167 | ;; post-command-hook. The former is only proper to use in Emacs | 147 | ;; post-command-hook. The former is only proper to use in Emacs |
| 168 | ;; 19.30; that is the first version in which it appeared, but it | 148 | ;; 19.30; that is the first version in which it appeared, but it |
| 169 | ;; was obsolesced by idle timers in Emacs 19.31. | 149 | ;; was obsolesced by idle timers in Emacs 19.31. |
| 170 | (add-hook (if (boundp 'post-command-idle-hook) | 150 | (add-hook (if (boundp 'post-command-idle-hook) |
| 171 | 'post-command-idle-hook | 151 | 'post-command-idle-hook |
| 172 | 'post-command-hook) | 152 | 'post-command-hook) |
| 173 | 'eldoc-print-current-symbol-info))) | 153 | 'eldoc-print-current-symbol-info) |
| 174 | 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)))) | ||
| 175 | (setq eldoc-mode (if prefix | 158 | (setq eldoc-mode (if prefix |
| 176 | (>= (prefix-numeric-value prefix) 0) | 159 | (>= (prefix-numeric-value prefix) 0) |
| 177 | (not eldoc-mode))) | 160 | (not eldoc-mode))) |
| 178 | |||
| 179 | (and (interactive-p) | 161 | (and (interactive-p) |
| 180 | (if eldoc-mode | 162 | (if eldoc-mode |
| 181 | (message "eldoc-mode is enabled") | 163 | (message "eldoc-mode is enabled") |
| @@ -188,38 +170,6 @@ the mode, respectively." | |||
| 188 | (interactive) | 170 | (interactive) |
| 189 | (eldoc-mode 1)) | 171 | (eldoc-mode 1)) |
| 190 | 172 | ||
| 191 | (defun eldoc-add-command (cmd) | ||
| 192 | "Add COMMAND to the list of commands which causes function arg display. | ||
| 193 | If called interactively, completion on defined commands is available. | ||
| 194 | |||
| 195 | When point is in a sexp, the function args are not reprinted in the echo | ||
| 196 | area after every possible interactive command because some of them print | ||
| 197 | their own messages in the echo area; the eldoc functions would instantly | ||
| 198 | overwrite them unless it is more restrained." | ||
| 199 | (interactive "CAdd function to eldoc message commands list: ") | ||
| 200 | (and (fboundp cmd) | ||
| 201 | (set (intern (symbol-name cmd) eldoc-message-commands) t))) | ||
| 202 | |||
| 203 | (defun eldoc-remove-command (cmd) | ||
| 204 | "Remove COMMAND from the list of commands which causes function arg display. | ||
| 205 | If called interactively, completion matches only those functions currently | ||
| 206 | in the list. | ||
| 207 | |||
| 208 | When point is in a sexp, the function args are not reprinted in the echo | ||
| 209 | area after every possible interactive command because some of them print | ||
| 210 | their own messages in the echo area; the eldoc functions would instantly | ||
| 211 | overwrite them unless it is more restrained." | ||
| 212 | (interactive (list (completing-read | ||
| 213 | "Remove function from eldoc message commands list: " | ||
| 214 | eldoc-message-commands 'boundp t))) | ||
| 215 | (and (symbolp cmd) | ||
| 216 | (setq cmd (symbol-name cmd))) | ||
| 217 | (if (fboundp 'unintern) | ||
| 218 | (unintern cmd eldoc-message-commands) | ||
| 219 | (let ((s (intern-soft cmd eldoc-message-commands))) | ||
| 220 | (and s | ||
| 221 | (makunbound s))))) | ||
| 222 | |||
| 223 | ;; Idle timers are part of Emacs 19.31 and later. | 173 | ;; Idle timers are part of Emacs 19.31 and later. |
| 224 | (defun eldoc-schedule-timer () | 174 | (defun eldoc-schedule-timer () |
| 225 | (or (and eldoc-timer | 175 | (or (and eldoc-timer |
| @@ -233,27 +183,58 @@ overwrite them unless it is more restrained." | |||
| 233 | (setq eldoc-current-idle-delay eldoc-idle-delay) | 183 | (setq eldoc-current-idle-delay eldoc-idle-delay) |
| 234 | (timer-set-idle-time eldoc-timer eldoc-idle-delay t)))) | 184 | (timer-set-idle-time eldoc-timer eldoc-idle-delay t)))) |
| 235 | 185 | ||
| 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 | |||
| 236 | 222 | ||
| 237 | (defun eldoc-print-current-symbol-info () | 223 | (defun eldoc-print-current-symbol-info () |
| 238 | (and (eldoc-display-message-p) | 224 | (and (eldoc-display-message-p) |
| 239 | (let ((current-symbol (eldoc-current-symbol)) | 225 | (let ((current-symbol (eldoc-current-symbol)) |
| 240 | (current-fnsym (eldoc-fnsym-in-current-sexp))) | 226 | (current-fnsym (eldoc-fnsym-in-current-sexp))) |
| 241 | (cond ((eq current-symbol current-fnsym) | 227 | (or (cond ((eq current-symbol current-fnsym) |
| 242 | (eldoc-print-fnsym-args current-fnsym)) | 228 | (or (eldoc-print-fnsym-args current-fnsym) |
| 243 | (t | 229 | (eldoc-print-var-docstring current-symbol))) |
| 244 | (or (eldoc-print-var-docstring current-symbol) | 230 | (t |
| 245 | (eldoc-print-fnsym-args current-fnsym))))))) | 231 | (or (eldoc-print-var-docstring current-symbol) |
| 232 | (eldoc-print-fnsym-args current-fnsym)))) | ||
| 233 | (eldoc-message nil))))) | ||
| 246 | 234 | ||
| 247 | ;; Decide whether now is a good time to display a message. | 235 | ;; Decide whether now is a good time to display a message. |
| 248 | (defun eldoc-display-message-p () | 236 | (defun eldoc-display-message-p () |
| 249 | (and eldoc-mode | 237 | (and (eldoc-display-message-no-interference-p) |
| 250 | (not executing-kbd-macro) | ||
| 251 | |||
| 252 | ;; Having this mode operate in an active minibuffer/echo area causes | ||
| 253 | ;; interference with what's going on there. | ||
| 254 | (not cursor-in-echo-area) | ||
| 255 | (not (eq (selected-window) (minibuffer-window))) | ||
| 256 | |||
| 257 | (cond (eldoc-use-idle-timer-p | 238 | (cond (eldoc-use-idle-timer-p |
| 258 | ;; If this-command is non-nil while running via an idle | 239 | ;; If this-command is non-nil while running via an idle |
| 259 | ;; timer, we're still in the middle of executing a command, | 240 | ;; timer, we're still in the middle of executing a command, |
| @@ -273,11 +254,19 @@ overwrite them unless it is more restrained." | |||
| 273 | eldoc-message-commands) | 254 | eldoc-message-commands) |
| 274 | (sit-for eldoc-idle-delay)))))) | 255 | (sit-for eldoc-idle-delay)))))) |
| 275 | 256 | ||
| 276 | (defun eldoc-print-fnsym-args (&optional symbol) | 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))))) | ||
| 264 | |||
| 265 | (defun eldoc-print-fnsym-args (sym) | ||
| 277 | (interactive) | 266 | (interactive) |
| 278 | (let ((sym (or symbol (eldoc-fnsym-in-current-sexp))) | 267 | (let ((args nil)) |
| 279 | (args nil)) | 268 | (cond ((not (and sym |
| 280 | (cond ((not (and (symbolp sym) | 269 | (symbolp sym) |
| 281 | (fboundp sym)))) | 270 | (fboundp sym)))) |
| 282 | ((eq sym (car eldoc-last-data)) | 271 | ((eq sym (car eldoc-last-data)) |
| 283 | (setq args (cdr eldoc-last-data))) | 272 | (setq args (cdr eldoc-last-data))) |
| @@ -294,24 +283,40 @@ overwrite them unless it is more restrained." | |||
| 294 | (eldoc-message "%s: %s" sym args)))) | 283 | (eldoc-message "%s: %s" sym args)))) |
| 295 | 284 | ||
| 296 | (defun eldoc-fnsym-in-current-sexp () | 285 | (defun eldoc-fnsym-in-current-sexp () |
| 297 | (let* ((p (point)) | 286 | (let ((p (point))) |
| 298 | (sym (progn | 287 | (eldoc-beginning-of-sexp) |
| 299 | (while (and (eldoc-forward-sexp-safe -1) | 288 | (prog1 |
| 300 | (> (point) (point-min)))) | 289 | ;; Don't do anything if current word is inside a string. |
| 301 | (cond ((or (= (point) (point-min)) | 290 | (if (= (or (char-after (1- (point))) 0) ?\") |
| 302 | (memq (or (char-after (point)) 0) | 291 | nil |
| 303 | '(?\( ?\")) | 292 | (eldoc-current-symbol)) |
| 304 | ;; If we hit a quotation mark before a paren, we | 293 | (goto-char p)))) |
| 305 | ;; are inside a specific string, not a list of | 294 | |
| 306 | ;; symbols. | 295 | (defun eldoc-beginning-of-sexp () |
| 307 | (eq (or (char-after (1- (point))) 0) ?\")) | 296 | (let ((parse-sexp-ignore-comments t)) |
| 308 | nil) | 297 | (condition-case err |
| 309 | (t (condition-case nil | 298 | (while (progn |
| 310 | (read (current-buffer)) | 299 | (forward-sexp -1) |
| 311 | (error nil))))))) | 300 | (or (= (or (char-after (1- (point)))) ?\") |
| 312 | (goto-char p) | 301 | (> (point) (point-min))))) |
| 313 | (and (symbolp sym) | 302 | (error nil)))) |
| 314 | sym))) | 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)) | ||
| 315 | 320 | ||
| 316 | (defun eldoc-function-argstring (fn) | 321 | (defun eldoc-function-argstring (fn) |
| 317 | (let* ((prelim-def (eldoc-symbol-function fn)) | 322 | (let* ((prelim-def (eldoc-symbol-function fn)) |
| @@ -349,8 +354,7 @@ overwrite them unless it is more restrained." | |||
| 349 | (concat "(" (mapconcat 'identity arglist " ") ")")) | 354 | (concat "(" (mapconcat 'identity arglist " ") ")")) |
| 350 | 355 | ||
| 351 | 356 | ||
| 352 | (defun eldoc-print-var-docstring (&optional sym) | 357 | (defun eldoc-print-var-docstring (sym) |
| 353 | (or sym (setq sym (eldoc-current-symbol))) | ||
| 354 | (eldoc-print-docstring sym (documentation-property | 358 | (eldoc-print-docstring sym (documentation-property |
| 355 | sym 'variable-documentation t))) | 359 | sym 'variable-documentation t))) |
| 356 | 360 | ||
| @@ -473,6 +477,20 @@ overwrite them unless it is more restrained." | |||
| 473 | (string-match "^Args are +\\([^\n]+\\)$" doc))) | 477 | (string-match "^Args are +\\([^\n]+\\)$" doc))) |
| 474 | (function (lambda (doc) | 478 | (function (lambda (doc) |
| 475 | (substring doc (match-beginning 1) (match-end 1))))) | 479 | (substring doc (match-beginning 1) (match-end 1))))) |
| 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"))) | ||
| 476 | )) | 494 | )) |
| 477 | 495 | ||
| 478 | (defun eldoc-function-argstring-from-docstring (fn) | 496 | (defun eldoc-function-argstring-from-docstring (fn) |
| @@ -507,36 +525,64 @@ overwrite them unless it is more restrained." | |||
| 507 | (concat "(" (funcall eldoc-argument-case doc) ")")))))) | 525 | (concat "(" (funcall eldoc-argument-case doc) ")")))))) |
| 508 | 526 | ||
| 509 | 527 | ||
| 510 | ;; forward-sexp calls scan-sexps, which returns an error if it hits the | 528 | ;; When point is in a sexp, the function args are not reprinted in the echo |
| 511 | ;; beginning or end of the sexp. This returns nil instead. | 529 | ;; area after every possible interactive command because some of them print |
| 512 | (defun eldoc-forward-sexp-safe (&optional count) | 530 | ;; their own messages in the echo area; the eldoc functions would instantly |
| 513 | "Move forward across one balanced expression (sexp). | 531 | ;; overwrite them unless it is more restrained. |
| 514 | With argument, do it that many times. Negative arg -COUNT means | 532 | ;; These functions do display-command table management. |
| 515 | move backward across COUNT balanced expressions. | 533 | |
| 516 | Return distance in buffer moved, or nil." | 534 | (defun eldoc-add-command (&rest cmds) |
| 517 | (or count (setq count 1)) | 535 | (or eldoc-message-commands |
| 518 | (condition-case err | 536 | (setq eldoc-message-commands |
| 519 | (- (- (point) (progn | 537 | (make-vector eldoc-message-commands-table-size 0))) |
| 520 | (let ((parse-sexp-ignore-comments t)) | 538 | |
| 521 | (forward-sexp count)) | 539 | (let (name sym) |
| 522 | (point)))) | 540 | (while cmds |
| 523 | (error nil))) | 541 | (setq name (car cmds)) |
| 524 | 542 | (setq cmds (cdr cmds)) | |
| 525 | ;; Do indirect function resolution if possible. | 543 | |
| 526 | (defun eldoc-symbol-function (fsym) | 544 | (cond ((symbolp name) |
| 527 | (let ((defn (and (fboundp fsym) | 545 | (setq sym name) |
| 528 | (symbol-function fsym)))) | 546 | (setq name (symbol-name sym))) |
| 529 | (and (symbolp defn) | 547 | ((stringp name) |
| 530 | (condition-case err | 548 | (setq sym (intern-soft name)))) |
| 531 | (setq defn (indirect-function fsym)) | 549 | |
| 532 | (error (setq defn nil)))) | 550 | (and (symbolp sym) |
| 533 | defn)) | 551 | (fboundp sym) |
| 534 | 552 | (set (intern name eldoc-message-commands) t))))) | |
| 535 | (defun eldoc-current-symbol () | 553 | |
| 536 | (let ((c (char-after (point)))) | 554 | (defun eldoc-add-command-completions (&rest names) |
| 537 | (and c | 555 | (while names |
| 538 | (memq (char-syntax c) '(?w ?_)) | 556 | (apply 'eldoc-add-command |
| 539 | (intern-soft (current-word))))) | 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))) | ||
| 568 | |||
| 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-") | ||
| 540 | 586 | ||
| 541 | (provide 'eldoc) | 587 | (provide 'eldoc) |
| 542 | 588 | ||