Mercurial > emacs
comparison lisp/emacs-lisp/eldoc.el @ 82456:943f0b2ad6bb
(eldoc-get-fnsym-args-string): Convert
comment to basic doc string. Also apply eldoc-argument-case in
the help-split-fundoc case. Adapt for changed behavior of
eldoc-function-argstring, eldoc-function-argstring-format, and
eldoc-highlight-function-argument.
(eldoc-highlight-function-argument): Make INDEX argument
optional, just call eldoc-docstring-format-sym-doc if absent.
(eldoc-function-argstring): Change the behavior. Now it converts
an argument list to a string.
(eldoc-function-argstring-format): Change the behavior. Now it
applies `eldoc-argument-case' to a string.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 18 Aug 2007 23:43:44 +0000 |
parents | 694f889fbd90 |
children | 0b0688e8eda7 |
comparison
equal
deleted
inserted
replaced
82455:ce4b6c4001c1 | 82456:943f0b2ad6bb |
---|---|
262 (eldoc-message doc)))) | 262 (eldoc-message doc)))) |
263 ;; This is run from post-command-hook or some idle timer thing, | 263 ;; This is run from post-command-hook or some idle timer thing, |
264 ;; so we need to be careful that errors aren't ignored. | 264 ;; so we need to be careful that errors aren't ignored. |
265 (error (message "eldoc error: %s" err)))) | 265 (error (message "eldoc error: %s" err)))) |
266 | 266 |
267 ;; Return a string containing the function parameter list, or 1-line | 267 ;; FIXME improve doc-string. |
268 ;; docstring if function is a subr and no arglist is obtainable from the | |
269 ;; docstring or elsewhere. | |
270 (defun eldoc-get-fnsym-args-string (sym &optional argument-index) | 268 (defun eldoc-get-fnsym-args-string (sym &optional argument-index) |
271 (let ((args nil) | 269 "Return a string containing the parameter list of the function SYM. |
272 (doc nil)) | 270 If SYM is a subr and no arglist is obtainable from the docstring |
271 or elsewhere, return a 1-line docstring." | |
272 (let (args doc) | |
273 (cond ((not (and sym (symbolp sym) (fboundp sym)))) | 273 (cond ((not (and sym (symbolp sym) (fboundp sym)))) |
274 ((and (eq sym (aref eldoc-last-data 0)) | 274 ((and (eq sym (aref eldoc-last-data 0)) |
275 (eq 'function (aref eldoc-last-data 2))) | 275 (eq 'function (aref eldoc-last-data 2))) |
276 (setq doc (aref eldoc-last-data 1))) | 276 (setq doc (aref eldoc-last-data 1))) |
277 ((setq doc (help-split-fundoc (documentation sym t) sym)) | 277 ((setq doc (help-split-fundoc (documentation sym t) sym)) |
278 (setq args (car doc)) | 278 (setq args (car doc)) |
279 ;; Remove any enclosing (), since e-function-argstring adds them. | |
279 (string-match "\\`[^ )]* ?" args) | 280 (string-match "\\`[^ )]* ?" args) |
280 (setq args (concat "(" (substring args (match-end 0)))) | 281 (setq args (substring args (match-end 0))) |
281 (eldoc-last-data-store sym args 'function)) | 282 (if (string-match ")\\'" args) |
282 (t | 283 (setq args (substring args 0 -1)))) |
283 (setq args (eldoc-function-argstring sym)))) | 284 (t |
284 (and args | 285 (setq args (help-function-arglist sym)))) |
285 argument-index | 286 (if args |
286 (setq doc (eldoc-highlight-function-argument sym args argument-index))) | 287 ;; Stringify, and store before highlighting, downcasing, etc. |
287 doc)) | 288 ;; FIXME should truncate before storing. |
289 (eldoc-last-data-store sym (setq args (eldoc-function-argstring args)) | |
290 'function) | |
291 (setq args doc)) ; use stored value | |
292 ;; Change case, highlight, truncate. | |
293 (if args | |
294 (eldoc-highlight-function-argument | |
295 ;; FIXME apply word by word, ignore &optional, &rest. | |
296 sym (eldoc-function-argstring-format args) argument-index)))) | |
288 | 297 |
289 ;; Highlight argument INDEX in ARGS list for SYM. | 298 ;; Highlight argument INDEX in ARGS list for SYM. |
290 (defun eldoc-highlight-function-argument (sym args index) | 299 ;; In the absence of INDEX, just call eldoc-docstring-format-sym-doc. |
300 (defun eldoc-highlight-function-argument (sym args &optional index) | |
291 (let ((start nil) | 301 (let ((start nil) |
292 (end 0) | 302 (end 0) |
293 (argument-face 'bold)) | 303 (argument-face 'bold)) |
294 ;; Find the current argument in the argument string. We need to | 304 ;; Find the current argument in the argument string. We need to |
295 ;; handle `&rest' and informal `...' properly. | 305 ;; handle `&rest' and informal `...' properly. |
296 ;; | 306 ;; |
297 ;; FIXME: What to do with optional arguments, like in | 307 ;; FIXME: What to do with optional arguments, like in |
298 ;; (defun NAME ARGLIST [DOCSTRING] BODY...) case? | 308 ;; (defun NAME ARGLIST [DOCSTRING] BODY...) case? |
299 ;; The problem is there is no robust way to determine if | 309 ;; The problem is there is no robust way to determine if |
300 ;; the current argument is indeed a docstring. | 310 ;; the current argument is indeed a docstring. |
301 (while (>= index 1) | 311 (while (and index (>= index 1)) |
302 (if (string-match "[^ ()]+" args end) | 312 (if (string-match "[^ ()]+" args end) |
303 (progn | 313 (progn |
304 (setq start (match-beginning 0) | 314 (setq start (match-beginning 0) |
305 end (match-end 0)) | 315 end (match-end 0)) |
306 (let ((argument (match-string 0 args))) | 316 (let ((argument (match-string 0 args))) |
436 (condition-case err | 446 (condition-case err |
437 (setq defn (indirect-function fsym)) | 447 (setq defn (indirect-function fsym)) |
438 (error (setq defn nil)))) | 448 (error (setq defn nil)))) |
439 defn)) | 449 defn)) |
440 | 450 |
441 (defun eldoc-function-argstring (fn) | 451 (defun eldoc-function-argstring (arglist) |
442 (eldoc-function-argstring-format (help-function-arglist fn))) | 452 "Return ARGLIST as a string enclosed by (). |
443 | 453 ARGLIST is either a string, or a list of strings or symbols." |
444 (defun eldoc-function-argstring-format (arglist) | 454 (cond ((stringp arglist)) |
445 (cond ((not (listp arglist)) | 455 ((not (listp arglist)) |
446 (setq arglist nil)) | 456 (setq arglist nil)) |
447 ((symbolp (car arglist)) | 457 ((symbolp (car arglist)) |
448 (setq arglist | 458 (setq arglist |
449 (mapcar (function (lambda (s) | 459 (mapconcat (lambda (s) (symbol-name s)) |
450 (if (memq s '(&optional &rest)) | 460 arglist " "))) |
451 (symbol-name s) | 461 ((stringp (car arglist)) |
452 (funcall eldoc-argument-case | 462 (setq arglist |
453 (symbol-name s))))) | 463 (mapconcat (lambda (s) s) |
454 arglist))) | 464 arglist " ")))) |
455 ((stringp (car arglist)) | 465 (if arglist |
456 (setq arglist | 466 (format "(%s)" arglist))) |
457 (mapcar (function (lambda (s) | 467 |
458 (if (member s '("&optional" "&rest")) | 468 (defun eldoc-function-argstring-format (argstring) |
459 s | 469 "Apply `eldoc-argument-case' to each word in argstring. |
460 (funcall eldoc-argument-case s)))) | 470 The words \"&rest\", \"&optional\" are returned unchanged." |
461 arglist)))) | 471 (mapconcat (lambda (s) |
462 (concat "(" (mapconcat 'identity arglist " ") ")")) | 472 (if (member s '("&optional" "&rest")) |
463 | 473 s |
474 (funcall eldoc-argument-case s))) | |
475 (split-string argstring) " ")) | |
464 | 476 |
465 ;; When point is in a sexp, the function args are not reprinted in the echo | 477 ;; When point is in a sexp, the function args are not reprinted in the echo |
466 ;; area after every possible interactive command because some of them print | 478 ;; area after every possible interactive command because some of them print |
467 ;; their own messages in the echo area; the eldoc functions would instantly | 479 ;; their own messages in the echo area; the eldoc functions would instantly |
468 ;; overwrite them unless it is more restrained. | 480 ;; overwrite them unless it is more restrained. |