| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
(require 'help-fns) |
|---|
| 53 |
|
|---|
| 54 |
(defgroup eldoc nil |
|---|
| 55 |
"Show function arglist or variable docstring in echo area." |
|---|
| 56 |
:group 'lisp |
|---|
| 57 |
:group 'extensions) |
|---|
| 58 |
|
|---|
| 59 |
(defcustom eldoc-idle-delay 0.50 |
|---|
| 60 |
"*Number of seconds of idle time to wait before printing. |
|---|
| 61 |
If user input arrives before this interval of time has elapsed after the |
|---|
| 62 |
last input, no documentation will be printed. |
|---|
| 63 |
|
|---|
| 64 |
If this variable is set to 0, no idle time is required." |
|---|
| 65 |
:type 'number |
|---|
| 66 |
:group 'eldoc) |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
(defcustom eldoc-minor-mode-string " ElDoc" |
|---|
| 70 |
"*String to display in mode line when Eldoc Mode is enabled; nil for none." |
|---|
| 71 |
:type '(choice string (const :tag "None" nil)) |
|---|
| 72 |
:group 'eldoc) |
|---|
| 73 |
|
|---|
| 74 |
(defcustom eldoc-argument-case 'upcase |
|---|
| 75 |
"Case to display argument names of functions, as a symbol. |
|---|
| 76 |
This has two preferred values: `upcase' or `downcase'. |
|---|
| 77 |
Actually, any name of a function which takes a string as an argument and |
|---|
| 78 |
returns another string is acceptable." |
|---|
| 79 |
:type '(radio (function-item upcase) |
|---|
| 80 |
(function-item downcase) |
|---|
| 81 |
function) |
|---|
| 82 |
:group 'eldoc) |
|---|
| 83 |
|
|---|
| 84 |
(defcustom eldoc-echo-area-use-multiline-p 'truncate-sym-name-if-fit |
|---|
| 85 |
"*Allow long eldoc messages to resize echo area display. |
|---|
| 86 |
If value is t, never attempt to truncate messages; complete symbol name |
|---|
| 87 |
and function arglist or 1-line variable documentation will be displayed |
|---|
| 88 |
even if echo area must be resized to fit. |
|---|
| 89 |
|
|---|
| 90 |
If value is any non-nil value other than t, symbol name may be truncated |
|---|
| 91 |
if it will enable the function arglist or documentation string to fit on a |
|---|
| 92 |
single line without resizing window. Otherwise, behavior is just like |
|---|
| 93 |
former case. |
|---|
| 94 |
|
|---|
| 95 |
If value is nil, messages are always truncated to fit in a single line of |
|---|
| 96 |
display in the echo area. Function or variable symbol name may be |
|---|
| 97 |
truncated to make more of the arglist or documentation string visible." |
|---|
| 98 |
:type '(radio (const :tag "Always" t) |
|---|
| 99 |
(const :tag "Never" nil) |
|---|
| 100 |
(const :tag "Yes, but truncate symbol names if it will\ |
|---|
| 101 |
enable argument list to fit on one line" truncate-sym-name-if-fit)) |
|---|
| 102 |
:group 'eldoc) |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
(defvar eldoc-message-commands-table-size 31 |
|---|
| 107 |
"This is used by `eldoc-add-command' to initialize `eldoc-message-commands' |
|---|
| 108 |
as an obarray. |
|---|
| 109 |
It should probably never be necessary to do so, but if you |
|---|
| 110 |
choose to increase the number of buckets, you must do so before loading |
|---|
| 111 |
this file since the obarray is initialized at load time. |
|---|
| 112 |
Remember to keep it a prime number to improve hash performance.") |
|---|
| 113 |
|
|---|
| 114 |
(defconst eldoc-message-commands |
|---|
| 115 |
(make-vector eldoc-message-commands-table-size 0) |
|---|
| 116 |
"Commands after which it is appropriate to print in the echo area. |
|---|
| 117 |
Eldoc does not try to print function arglists, etc. after just any command, |
|---|
| 118 |
because some commands print their own messages in the echo area and these |
|---|
| 119 |
functions would instantly overwrite them. But `self-insert-command' as well |
|---|
| 120 |
as most motion commands are good candidates. |
|---|
| 121 |
This variable contains an obarray of symbols; do not manipulate it |
|---|
| 122 |
directly. Instead, use `eldoc-add-command' and `eldoc-remove-command'.") |
|---|
| 123 |
|
|---|
| 124 |
(defconst eldoc-last-data (make-vector 3 nil) |
|---|
| 125 |
"Bookkeeping; elements are as follows: |
|---|
| 126 |
0 - contains the last symbol read from the buffer. |
|---|
| 127 |
1 - contains the string last displayed in the echo area for that |
|---|
| 128 |
symbol, so it can be printed again if necessary without reconsing. |
|---|
| 129 |
2 - 'function if function args, 'variable if variable documentation.") |
|---|
| 130 |
(defvar eldoc-last-message nil) |
|---|
| 131 |
|
|---|
| 132 |
(defvar eldoc-timer nil "eldoc's timer object.") |
|---|
| 133 |
|
|---|
| 134 |
(defvar eldoc-current-idle-delay eldoc-idle-delay |
|---|
| 135 |
"Idle time delay currently in use by timer. |
|---|
| 136 |
This is used to determine if `eldoc-idle-delay' is changed by the user.") |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
(define-minor-mode eldoc-mode |
|---|
| 141 |
"Toggle ElDoc mode on or off. |
|---|
| 142 |
In ElDoc mode, the echo area displays information about a |
|---|
| 143 |
function or variable in the text where point is. If point is |
|---|
| 144 |
on a documented variable, it displays the first line of that |
|---|
| 145 |
variable's doc string. Otherwise it displays the argument list |
|---|
| 146 |
of the function called in the expression point is on. |
|---|
| 147 |
|
|---|
| 148 |
With prefix ARG, turn ElDoc mode on if and only if ARG is positive." |
|---|
| 149 |
:group 'eldoc :lighter eldoc-minor-mode-string |
|---|
| 150 |
(setq eldoc-last-message nil) |
|---|
| 151 |
(if eldoc-mode |
|---|
| 152 |
(progn |
|---|
| 153 |
(add-hook 'post-command-hook 'eldoc-schedule-timer nil t) |
|---|
| 154 |
(add-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area t)) |
|---|
| 155 |
(remove-hook 'post-command-hook 'eldoc-schedule-timer) |
|---|
| 156 |
(remove-hook 'pre-command-hook 'eldoc-pre-command-refresh-echo-area))) |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
(defun turn-on-eldoc-mode () |
|---|
| 160 |
"Unequivocally turn on ElDoc mode (see command `eldoc-mode')." |
|---|
| 161 |
(interactive) |
|---|
| 162 |
(eldoc-mode 1)) |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
(defun eldoc-schedule-timer () |
|---|
| 166 |
(or (and eldoc-timer |
|---|
| 167 |
(memq eldoc-timer timer-idle-list)) |
|---|
| 168 |
(setq eldoc-timer |
|---|
| 169 |
(run-with-idle-timer eldoc-idle-delay t |
|---|
| 170 |
'eldoc-print-current-symbol-info))) |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
(cond ((not (= eldoc-idle-delay eldoc-current-idle-delay)) |
|---|
| 174 |
(setq eldoc-current-idle-delay eldoc-idle-delay) |
|---|
| 175 |
(timer-set-idle-time eldoc-timer eldoc-idle-delay t)))) |
|---|
| 176 |
|
|---|
| 177 |
(defun eldoc-message (&rest args) |
|---|
| 178 |
(let ((omessage eldoc-last-message)) |
|---|
| 179 |
(setq eldoc-last-message |
|---|
| 180 |
(cond ((eq (car args) eldoc-last-message) eldoc-last-message) |
|---|
| 181 |
((null (car args)) nil) |
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
((null (cdr args)) (car args)) |
|---|
| 186 |
(t (apply 'format args)))) |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
(let ((message-log-max nil)) |
|---|
| 192 |
(cond (eldoc-last-message (message "%s" eldoc-last-message)) |
|---|
| 193 |
(omessage (message nil))))) |
|---|
| 194 |
eldoc-last-message) |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
(defun eldoc-pre-command-refresh-echo-area () |
|---|
| 203 |
(and eldoc-last-message |
|---|
| 204 |
(if (eldoc-display-message-no-interference-p) |
|---|
| 205 |
(eldoc-message eldoc-last-message) |
|---|
| 206 |
(setq eldoc-last-message nil)))) |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
(defun eldoc-display-message-p () |
|---|
| 210 |
(and (eldoc-display-message-no-interference-p) |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
(and (not this-command) |
|---|
| 216 |
(symbolp last-command) |
|---|
| 217 |
(intern-soft (symbol-name last-command) |
|---|
| 218 |
eldoc-message-commands)))) |
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
(defun eldoc-display-message-no-interference-p () |
|---|
| 223 |
(and eldoc-mode |
|---|
| 224 |
(not executing-kbd-macro) |
|---|
| 225 |
(not (and (boundp 'edebug-active) edebug-active)) |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
(not cursor-in-echo-area) |
|---|
| 229 |
(not (eq (selected-window) (minibuffer-window))))) |
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
(defvar eldoc-documentation-function nil |
|---|
| 234 |
"If non-nil, function to call to return doc string. |
|---|
| 235 |
The function of no args should return a one-line string for displaying |
|---|
| 236 |
doc about a function etc. appropriate to the context around point. |
|---|
| 237 |
It should return nil if there's no doc appropriate for the context. |
|---|
| 238 |
Typically doc is returned if point is on a function-like name or in its |
|---|
| 239 |
arg list. |
|---|
| 240 |
|
|---|
| 241 |
This variable is expected to be made buffer-local by modes (other than |
|---|
| 242 |
Emacs Lisp mode) that support Eldoc.") |
|---|
| 243 |
|
|---|
| 244 |
(defun eldoc-print-current-symbol-info () |
|---|
| 245 |
(condition-case err |
|---|
| 246 |
(and (eldoc-display-message-p) |
|---|
| 247 |
(if eldoc-documentation-function |
|---|
| 248 |
(eldoc-message (funcall eldoc-documentation-function)) |
|---|
| 249 |
(let* ((current-symbol (eldoc-current-symbol)) |
|---|
| 250 |
(current-fnsym (eldoc-fnsym-in-current-sexp)) |
|---|
| 251 |
(doc (cond |
|---|
| 252 |
((eq current-symbol current-fnsym) |
|---|
| 253 |
(or (eldoc-get-fnsym-args-string current-fnsym) |
|---|
| 254 |
(eldoc-get-var-docstring current-symbol))) |
|---|
| 255 |
(t |
|---|
| 256 |
(or (eldoc-get-var-docstring current-symbol) |
|---|
| 257 |
(eldoc-get-fnsym-args-string current-fnsym)))))) |
|---|
| 258 |
(eldoc-message doc)))) |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
(error (message "eldoc error: %s" err)))) |
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
(defun eldoc-get-fnsym-args-string (sym) |
|---|
| 267 |
(let ((args nil) |
|---|
| 268 |
(doc nil)) |
|---|
| 269 |
(cond ((not (and sym (symbolp sym) (fboundp sym)))) |
|---|
| 270 |
((and (eq sym (aref eldoc-last-data 0)) |
|---|
| 271 |
(eq 'function (aref eldoc-last-data 2))) |
|---|
| 272 |
(setq doc (aref eldoc-last-data 1))) |
|---|
| 273 |
((setq doc (help-split-fundoc (documentation sym t) sym)) |
|---|
| 274 |
(setq args (car doc)) |
|---|
| 275 |
(string-match "\\`[^ )]* ?" args) |
|---|
| 276 |
(setq args (concat "(" (substring args (match-end 0))))) |
|---|
| 277 |
(t |
|---|
| 278 |
(setq args (eldoc-function-argstring sym)))) |
|---|
| 279 |
(cond (args |
|---|
| 280 |
(setq doc (eldoc-docstring-format-sym-doc sym args)) |
|---|
| 281 |
(eldoc-last-data-store sym doc 'function))) |
|---|
| 282 |
doc)) |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
(defun eldoc-get-var-docstring (sym) |
|---|
| 287 |
(when sym |
|---|
| 288 |
(cond ((and (eq sym (aref eldoc-last-data 0)) |
|---|
| 289 |
(eq 'variable (aref eldoc-last-data 2))) |
|---|
| 290 |
(aref eldoc-last-data 1)) |
|---|
| 291 |
(t |
|---|
| 292 |
(let ((doc (documentation-property sym 'variable-documentation t))) |
|---|
| 293 |
(cond (doc |
|---|
| 294 |
(setq doc (eldoc-docstring-format-sym-doc |
|---|
| 295 |
sym (eldoc-docstring-first-line doc))) |
|---|
| 296 |
(eldoc-last-data-store sym doc 'variable))) |
|---|
| 297 |
doc))))) |
|---|
| 298 |
|
|---|
| 299 |
(defun eldoc-last-data-store (symbol doc type) |
|---|
| 300 |
(aset eldoc-last-data 0 symbol) |
|---|
| 301 |
(aset eldoc-last-data 1 doc) |
|---|
| 302 |
(aset eldoc-last-data 2 type)) |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
(defun eldoc-docstring-first-line (doc) |
|---|
| 307 |
(and (stringp doc) |
|---|
| 308 |
(substitute-command-keys |
|---|
| 309 |
(save-match-data |
|---|
| 310 |
(let ((start (if (string-match "^\\*" doc) (match-end 0) 0))) |
|---|
| 311 |
(cond ((string-match "\n" doc) |
|---|
| 312 |
(substring doc start (match-beginning 0))) |
|---|
| 313 |
((zerop start) doc) |
|---|
| 314 |
(t (substring doc start)))))))) |
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
(defun eldoc-docstring-format-sym-doc (sym doc) |
|---|
| 320 |
(save-match-data |
|---|
| 321 |
(let* ((name (symbol-name sym)) |
|---|
| 322 |
(ea-multi eldoc-echo-area-use-multiline-p) |
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
(ea-width (1- (window-width (minibuffer-window)))) |
|---|
| 327 |
(strip (- (+ (length name) (length ": ") (length doc)) ea-width))) |
|---|
| 328 |
(cond ((or (<= strip 0) |
|---|
| 329 |
(eq ea-multi t) |
|---|
| 330 |
(and ea-multi (> (length doc) ea-width))) |
|---|
| 331 |
(format "%s: %s" sym doc)) |
|---|
| 332 |
((> (length doc) ea-width) |
|---|
| 333 |
(substring (format "%s" doc) 0 ea-width)) |
|---|
| 334 |
((>= strip (length name)) |
|---|
| 335 |
(format "%s" doc)) |
|---|
| 336 |
(t |
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
(setq name (substring name strip)) |
|---|
| 341 |
(format "%s: %s" name doc)))))) |
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
(defun eldoc-fnsym-in-current-sexp () |
|---|
| 345 |
(let ((p (point))) |
|---|
| 346 |
(eldoc-beginning-of-sexp) |
|---|
| 347 |
(prog1 |
|---|
| 348 |
|
|---|
| 349 |
(if (= (or (char-after (1- (point))) 0) ?\") |
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
&optional" "&rest")) |
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
(" (mapconcat 'identity arglist " ") ")")) |
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows" |
|---|
| 435 |
delete-window" "handle-select-window" |
|---|
| 436 |
end-of-" "move-end-of-" "exchange-point-and-mark" "forward-" |
|---|
| 437 |
indent-for-tab-command" "goto-" "mark-page" "mark-paragraph" |
|---|
| 438 |
mouse-set-point" "move-" "pop-global-mark" "next-" "other-window" |
|---|
| 439 |
previous-" "recenter" "scroll-" "self-insert-command" |
|---|
| 440 |
split-window-" "up-list" "down-list") |
|---|
| 441 |
|
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|