emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/emacs-lisp/eldoc.el,v


From: Glenn Morris
Subject: [Emacs-diffs] Changes to emacs/lisp/emacs-lisp/eldoc.el,v
Date: Sat, 18 Aug 2007 23:43:44 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Glenn Morris <gm>       07/08/18 23:43:44

Index: eldoc.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/eldoc.el,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -b -r1.45 -r1.46
--- eldoc.el    8 Aug 2007 08:14:03 -0000       1.45
+++ eldoc.el    18 Aug 2007 23:43:44 -0000      1.46
@@ -264,30 +264,40 @@
     ;; so we need to be careful that errors aren't ignored.
     (error (message "eldoc error: %s" err))))
 
-;; Return a string containing the function parameter list, or 1-line
-;; docstring if function is a subr and no arglist is obtainable from the
-;; docstring or elsewhere.
+;; FIXME improve doc-string.
 (defun eldoc-get-fnsym-args-string (sym &optional argument-index)
-  (let ((args nil)
-        (doc nil))
+  "Return a string containing the parameter list of the function SYM.
+If SYM is a subr and no arglist is obtainable from the docstring
+or elsewhere, return a 1-line docstring."
+  (let (args doc)
     (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)))
          ((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 (concat "(" (substring args (match-end 0))))
-          (eldoc-last-data-store sym args 'function))
+          (setq args (substring args (match-end 0)))
+          (if (string-match ")\\'" args)
+              (setq args (substring args 0 -1))))
           (t
-           (setq args (eldoc-function-argstring sym))))
-    (and args
-         argument-index
-         (setq doc (eldoc-highlight-function-argument sym args 
argument-index)))
-    doc))
+          (setq args (help-function-arglist sym))))
+    (if args
+       ;; Stringify, and store before highlighting, downcasing, etc.
+       ;; FIXME should truncate before storing.
+       (eldoc-last-data-store sym (setq args (eldoc-function-argstring args))
+                              'function)
+      (setq args doc))           ; use stored value
+    ;; Change case, highlight, truncate.
+    (if args
+       (eldoc-highlight-function-argument
+        ;; FIXME apply word by word, ignore &optional, &rest.
+        sym (eldoc-function-argstring-format args) argument-index))))
 
 ;; Highlight argument INDEX in ARGS list for SYM.
-(defun eldoc-highlight-function-argument (sym args index)
+;; In the absence of INDEX, just call eldoc-docstring-format-sym-doc.
+(defun eldoc-highlight-function-argument (sym args &optional index)
   (let ((start          nil)
        (end            0)
        (argument-face  'bold))
@@ -298,7 +308,7 @@
     ;;        (defun NAME ARGLIST [DOCSTRING] BODY...) case?
     ;;        The problem is there is no robust way to determine if
     ;;        the current argument is indeed a docstring.
-    (while (>= index 1)
+    (while (and index (>= index 1))
       (if (string-match "[^ ()]+" args end)
          (progn
            (setq start (match-beginning 0)
@@ -438,29 +448,31 @@
            (error (setq defn nil))))
     defn))
 
-(defun eldoc-function-argstring (fn)
-  (eldoc-function-argstring-format (help-function-arglist fn)))
-
-(defun eldoc-function-argstring-format (arglist)
-  (cond ((not (listp arglist))
+(defun eldoc-function-argstring (arglist)
+  "Return ARGLIST as a string enclosed by ().
+ARGLIST is either a string, or a list of strings or symbols."
+  (cond ((stringp arglist))
+       ((not (listp arglist))
          (setq arglist nil))
         ((symbolp (car arglist))
          (setq arglist
-               (mapcar (function (lambda (s)
-                                   (if (memq s '(&optional &rest))
-                                       (symbol-name s)
-                                     (funcall eldoc-argument-case
-                                              (symbol-name s)))))
-                       arglist)))
+              (mapconcat (lambda (s) (symbol-name s))
+                         arglist " ")))
         ((stringp (car arglist))
          (setq arglist
-               (mapcar (function (lambda (s)
+              (mapconcat (lambda (s) s)
+                         arglist " "))))
+  (if arglist
+      (format "(%s)" arglist)))
+
+(defun eldoc-function-argstring-format (argstring)
+  "Apply `eldoc-argument-case' to each word in argstring.
+The words \"&rest\", \"&optional\" are returned unchanged."
+  (mapconcat (lambda (s)
                                    (if (member s '("&optional" "&rest"))
                                        s
-                                     (funcall eldoc-argument-case s))))
-                       arglist))))
-  (concat "(" (mapconcat 'identity arglist " ") ")"))
-
+                (funcall eldoc-argument-case s)))
+            (split-string argstring) " "))
 
 ;; When point is in a sexp, the function args are not reprinted in the echo
 ;; area after every possible interactive command because some of them print




reply via email to

[Prev in Thread] Current Thread [Next in Thread]