all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: 18048@debbugs.gnu.org
Subject: bug#18048: 24.3.92; [patch] eldoc improvements
Date: Tue, 22 Jul 2014 08:16:45 +0200	[thread overview]
Message-ID: <87fvhtsysy.fsf@gmail.com> (raw)
In-Reply-To: <87egxjxkxh.fsf@gmail.com>


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) " "))
 
 \f
 ;; 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	other threads:[~2014-07-22  6:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-18  5:46 bug#18048: 24.3.92; [patch] eldoc improvements Thierry Volpiatto
2014-07-19  3:07 ` Stefan Monnier
2014-07-19  5:25   ` Thierry Volpiatto
2014-07-19  5:46   ` Thierry Volpiatto
2014-07-19  8:11   ` Thierry Volpiatto
2014-07-19 17:01     ` Stefan Monnier
2014-07-21  7:24       ` Thierry Volpiatto
2014-08-18 19:32         ` Stefan Monnier
2014-08-19  5:39           ` Thierry Volpiatto
2014-09-04 14:50             ` Stefan Monnier
2014-07-21 12:27       ` Thierry Volpiatto
2014-07-21 15:13         ` Thierry Volpiatto
2014-07-22  6:16           ` Thierry Volpiatto [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fvhtsysy.fsf@gmail.com \
    --to=thierry.volpiatto@gmail.com \
    --cc=18048@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.