]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/eldoc.el
ert-x trivia
[gnu-emacs] / lisp / emacs-lisp / eldoc.el
index 38318826c22e000b0405d44346c860061307098b..6e5b8e92fb8e41f4278fe601edc5c82fabc7756a 100644 (file)
@@ -1,7 +1,6 @@
 ;;; eldoc.el --- show function arglist or variable docstring in echo area
 
-;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
 
 ;; Author: Noah Friedman <friedman@splode.com>
 ;; Maintainer: friedman@splode.com
@@ -41,7 +40,7 @@
 ;;      (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
 ;;      (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
 
-;; Major modes for other languages may use Eldoc by defining an
+;; Major modes for other languages may use ElDoc by defining an
 ;; appropriate function as the buffer-local value of
 ;; `eldoc-documentation-function'.
 
@@ -64,8 +63,8 @@ If this variable is set to 0, no idle time is required."
   :group 'eldoc)
 
 ;;;###autoload
-(defcustom eldoc-minor-mode-string " ElDoc"
-  "String to display in mode line when Eldoc Mode is enabled; nil for none."
+(defcustom eldoc-minor-mode-string (purecopy " ElDoc")
+  "String to display in mode line when ElDoc Mode is enabled; nil for none."
   :type '(choice string (const :tag "None" nil))
   :group 'eldoc)
 
@@ -124,19 +123,21 @@ Remember to keep it a prime number to improve hash performance.")
 (defconst eldoc-message-commands
   (make-vector eldoc-message-commands-table-size 0)
   "Commands after which it is appropriate to print in the echo area.
-Eldoc does not try to print function arglists, etc., after just any command,
+ElDoc does not try to print function arglists, etc., after just any command,
 because some commands print their own messages in the echo area and these
 functions would instantly overwrite them.  But `self-insert-command' as well
 as most motion commands are good candidates.
 This variable contains an obarray of symbols; do not manipulate it
 directly.  Instead, use `eldoc-add-command' and `eldoc-remove-command'.")
 
+;; Not a constant.
 (defconst eldoc-last-data (make-vector 3 nil)
   "Bookkeeping; elements are as follows:
   0 - contains the last symbol read from the buffer.
   1 - contains the string last displayed in the echo area for variables,
       or argument string for functions.
   2 - 'function if function args, 'variable if variable documentation.")
+
 (defvar eldoc-last-message nil)
 
 (defvar eldoc-timer nil "ElDoc's timer object.")
@@ -148,14 +149,17 @@ This is used to determine if `eldoc-idle-delay' is changed by the user.")
 \f
 ;;;###autoload
 (define-minor-mode eldoc-mode
-  "Toggle ElDoc mode on or off.
-In ElDoc mode, the echo area displays information about a
-function or variable in the text where point is.  If point is
-on a documented variable, it displays the first line of that
-variable's doc string.  Otherwise it displays the argument list
-of the function called in the expression point is on.
-
-With prefix ARG, turn ElDoc mode on if and only if ARG is positive."
+  "Toggle echo area display of Lisp objects at point (ElDoc mode).
+With a prefix argument ARG, enable ElDoc mode if ARG is positive,
+and disable it otherwise.  If called from Lisp, enable ElDoc mode
+if ARG is omitted or nil.
+
+ElDoc mode is a buffer-local minor mode.  When enabled, the echo
+area displays information about a function or variable in the
+text where point is.  If point is on a documented variable, it
+displays the first line of that variable's doc string.  Otherwise
+it displays the argument list of the function called in the
+expression point is on."
   :group 'eldoc :lighter eldoc-minor-mode-string
   (setq eldoc-last-message nil)
   (if eldoc-mode
@@ -254,7 +258,7 @@ and the face `eldoc-highlight-function-argument', if they are to have any
 effect.
 
 This variable is expected to be made buffer-local by modes (other than
-Emacs Lisp mode) that support Eldoc.")
+Emacs Lisp mode) that support ElDoc.")
 
 (defun eldoc-print-current-symbol-info ()
   (condition-case err
@@ -288,17 +292,20 @@ or elsewhere, return a 1-line docstring.  Calls the functions
 former calls `eldoc-argument-case'; the latter gives the
 function name `font-lock-function-name-face', and optionally
 highlights argument number INDEX."
-  (let (args doc)
+  (let (args doc advertised)
     (cond ((not (and sym (symbolp sym) (fboundp sym))))
          ((and (eq sym (aref eldoc-last-data 0))
                (eq 'function (aref eldoc-last-data 2)))
           (setq doc (aref eldoc-last-data 1)))
+         ((listp (setq advertised (gethash (indirect-function sym)
+                                           advertised-signature-table t)))
+          (setq args advertised))
          ((setq doc (help-split-fundoc (documentation sym t) sym))
           (setq args (car doc))
           ;; Remove any enclosing (), since e-function-argstring adds them.
           (string-match "\\`[^ )]* ?" args)
           (setq args (substring args (match-end 0)))
-          (if (string-match ")\\'" args)
+          (if (string-match-p ")\\'" args)
               (setq args (substring args 0 -1))))
          (t
           (setq args (help-function-arglist sym))))
@@ -336,7 +343,7 @@ In the absence of INDEX, just call `eldoc-docstring-format-sym-doc'."
                     ;; All the rest arguments are the same.
                     (setq index 1))
                    ((string= argument "&optional"))
-                   ((string-match "\\.\\.\\.$" argument)
+                   ((string-match-p "\\.\\.\\.$" argument)
                     (setq index 0))
                    (t
                     (setq index (1- index))))))
@@ -427,7 +434,7 @@ In the absence of INDEX, just call `eldoc-docstring-format-sym-doc'."
          nil
        (list (eldoc-current-symbol) argument-index)))))
 
-;; Move to the beginnig of current sexp.  Return the number of nested
+;; Move to the beginning of current sexp.  Return the number of nested
 ;; sexp the point was over or after.
 (defun eldoc-beginning-of-sexp ()
   (let ((parse-sexp-ignore-comments t)
@@ -489,10 +496,10 @@ ARGLIST is either a string, or a list of strings or symbols."
   "Apply `eldoc-argument-case' to each word in ARGSTRING.
 The words \"&rest\", \"&optional\" are returned unchanged."
   (mapconcat (lambda (s)
-              (if (member s '("&optional" "&rest"))
+              (if (string-match-p "\\`(?&\\(?:optional\\|rest\\))?\\'" s)
                   s
                 (funcall eldoc-argument-case s)))
-            (split-string argstring "[][ ()]+" t) " "))
+            (split-string argstring) " "))
 
 \f
 ;; When point is in a sexp, the function args are not reprinted in the echo
@@ -525,15 +532,14 @@ The words \"&rest\", \"&optional\" are returned unchanged."
 \f
 ;; Prime the command list.
 (eldoc-add-command-completions
- "backward-" "beginning-of-" "move-beginning-of-" "delete-other-windows"
- "delete-window" "handle-select-window"
- "end-of-" "move-end-of-" "exchange-point-and-mark" "forward-"
- "indent-for-tab-command" "goto-" "mark-page" "mark-paragraph"
- "mouse-set-point" "move-" "pop-global-mark" "next-" "other-window"
- "previous-" "recenter" "scroll-" "self-insert-command"
- "split-window-" "up-list" "down-list")
+ "backward-" "beginning-of-" "delete-other-windows" "delete-window"
+ "down-list" "end-of-" "exchange-point-and-mark" "forward-" "goto-"
+ "handle-select-window" "indent-for-tab-command" "left-" "mark-page"
+ "mark-paragraph" "mouse-set-point" "move-" "move-beginning-of-"
+ "move-end-of-" "next-" "other-window" "pop-global-mark" "previous-"
+ "recenter" "right-" "scroll-" "self-insert-command" "split-window-"
+ "up-list")
 
 (provide 'eldoc)
 
-;; arch-tag: c9a58f9d-2055-46c1-9b82-7248b71a8375
 ;;; eldoc.el ends here