bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#18048: 24.3.92; [patch] eldoc improvements


From: Thierry Volpiatto
Subject: bug#18048: 24.3.92; [patch] eldoc improvements
Date: Tue, 22 Jul 2014 08:16:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.92 (gnu/linux)

Here the last version of previous patch simplified and with some
comments.


Changes from master to working directory
1 file changed, 42 insertions(+), 10 deletions(-)
 lisp/emacs-lisp/eldoc.el | 52 ++++++++++++++++++++++++++++++++++++++----------

        Modified   lisp/emacs-lisp/eldoc.el
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 7102b55..744dea7 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -388,6 +388,30 @@ In the absence of INDEX, just call 
`eldoc-docstring-format-sym-doc'."
     ;;        (defun NAME ARGLIST [DOCSTRING] BODY...) case?
     ;;        The problem is there is no robust way to determine if
     ;;        the current argument is indeed a docstring.
+
+    ;; When `&key' is used finding position based on `index'
+    ;; would be wrong, so find the arg at point and determine
+    ;; position in ARGS based on this current arg.
+    (when (string-match "&key" args)
+      (let* (case-fold-search
+             (cur-w (current-word))
+             (limit (save-excursion
+                      (when (re-search-backward (symbol-name sym) nil t)
+                        (match-end 0))))
+             (cur-a (if (string-match ":\\([^ ()]*\\)" cur-w)
+                        (substring cur-w 1)
+                      (save-excursion
+                        (when (re-search-backward ":\\([^ ()\n]*\\)" limit t)
+                            (match-string 1))))))
+        ;; If `cur-a' is nil probably cursor is on a positional arg
+        ;; before `&key', in this case, exit this block and determine
+        ;; position with `index'.
+        (when (and cur-a
+                   (string-match (concat "\\_<" (upcase cur-a) "\\_>") args))
+          (setq index nil ; Skip next block based on positional args.
+                start (match-beginning 0)
+                end   (match-end 0)))))
+    ;; Handle now positional arguments.
     (while (and index (>= index 1))
       (if (string-match "[^ ()]+" args end)
          (progn
@@ -397,9 +421,14 @@ In the absence of INDEX, just call 
`eldoc-docstring-format-sym-doc'."
              (cond ((string= argument "&rest")
                     ;; All the rest arguments are the same.
                     (setq index 1))
-                   ((string= argument "&optional"))
-                   ((string-match-p "\\.\\.\\.$" argument)
-                    (setq index 0))
+                   ((string= argument "&optional")) ; Skip.
+                    ((string= argument "&allow-other-keys")) ; Skip.
+                    ;; Back to index 0 in ARG1 ARG2 ARG2 ARG3 etc...
+                    ;; like in `setq'.
+                   ((or (string-match-p "\\.\\.\\.$" argument)
+                         (and (string-match-p "\\.\\.\\.)?$" args)
+                              (> index 1) (oddp index)))
+                     (setq index 0))
                    (t
                     (setq index (1- index))))))
        (setq end           (length args)
@@ -548,13 +577,16 @@ ARGLIST is either a string, or a list of strings or 
symbols."
       (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 (string-match-p "\\`(?&\\(?:optional\\|rest\\))?\\'" s)
-                  s
-                (funcall eldoc-argument-case s)))
-            (split-string argstring) " "))
+    "Apply `eldoc-argument-case' to each word in ARGSTRING.
+The words \"&rest\", \"&optional\", \"&key\" and \"&allow-other-keys\"
+are returned unchanged."
+    (mapconcat
+     (lambda (s)
+       (if (string-match-p
+            "\\`(?&\\(?:optional\\|rest\\|key\\|allow-other-keys\\))?\\'" s)
+           s
+         (funcall eldoc-argument-case s)))
+     (split-string argstring) " "))
 
 
 ;; When point is in a sexp, the function args are not reprinted in the echo


-- 
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 






reply via email to

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