From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: 18048-done@debbugs.gnu.org
Subject: bug#18048: 24.3.92; [patch] eldoc improvements
Date: Tue, 19 Aug 2014 07:39:39 +0200 [thread overview]
Message-ID: <87y4ulghjk.fsf@gmail.com> (raw)
In-Reply-To: <jwvlhqlocma.fsf-monnier+emacsbugs@gnu.org>
Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
> I also installed your &key handling patch, thanks.
Thanks, however this patch doesn't handle things like:
--8<---------------cut here---------------start------------->8---
(define-ibuffer-op 1 2 "" :interactive t :mark 'foo :dangerous t :modifier-p t (foo))
^^^^^
or
(cl-multiple-value-bind (a b c) '(1 2 3) (+ a b c))
--8<---------------cut here---------------end--------------->8---
This patch is fixing it:
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el
index 0b8304a..c2d3c98 100644
--- a/lisp/emacs-lisp/eldoc.el
+++ b/lisp/emacs-lisp/eldoc.el
@@ -371,7 +371,11 @@ or elsewhere, return a 1-line docstring."
In the absence of INDEX, just call `eldoc-docstring-format-sym-doc'."
(let ((start nil)
(end 0)
- (argument-face 'eldoc-highlight-function-argument))
+ (argument-face 'eldoc-highlight-function-argument)
+ (args-lst (mapcar (lambda (x)
+ (replace-regexp-in-string
+ "\\`[(]\\|[)]\\'" "" x))
+ (split-string args))))
;; Find the current argument in the argument string. We need to
;; handle `&rest' and informal `...' properly.
;;
@@ -385,23 +389,53 @@ In the absence of INDEX, just call `eldoc-docstring-format-sym-doc'."
;; position in ARGS based on this current arg.
(when (string-match "&key" args)
(let* (case-fold-search
+ key-have-value
+ (sym-name (symbol-name sym))
(cur-w (current-word))
+ (args-lst-ak (cdr (member "&key" args-lst)))
(limit (save-excursion
- (when (re-search-backward (symbol-name sym) nil t)
+ (when (re-search-backward sym-name nil t)
(match-end 0))))
- (cur-a (if (string-match ":\\([^ ()]*\\)" cur-w)
+ (cur-a (if (and cur-w (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)))))
+ (let (split)
+ (when (re-search-backward ":\\([^()\n]*\\)" limit t)
+ (setq split (split-string (match-string 1) " " t))
+ (prog1 (car split)
+ (when (cdr split)
+ (setq key-have-value t))))))))
+ ;; If `cur-a' is not one of `args-lst-ak'
+ ;; assume user is entering an unknow key
+ ;; referenced in last position in signature.
+ (other-key-arg (and (stringp cur-a)
+ args-lst-ak
+ (not (member (upcase cur-a) args-lst-ak))
+ (upcase (car (last args-lst-ak))))))
+ (unless (string= cur-w sym-name)
+ ;; The last keyword have already a value
+ ;; i.e :foo a b and cursor is at b.
+ ;; If signature have also `&rest'
+ ;; (assume it is after the `&key' section)
+ ;; go to the arg after `&rest'.
+ (if (and key-have-value
+ (save-excursion
+ (not (re-search-forward ":.*" (point-at-eol) t)))
+ (string-match "&rest \\([^ ()]*\\)" args))
+ (setq index nil ; Skip next block based on positional args.
+ start (match-beginning 1)
+ end (match-end 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 ; A keyword arg (dot removed) or nil.
+ (or (string-match
+ (concat "\\_<" (upcase cur-a) "\\_>") args)
+ (string-match
+ (concat "\\_<" other-key-arg "\\_>") 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)
@@ -412,13 +446,16 @@ 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")) ; Skip.
+ ((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) (cl-oddp index)))
+ ((or (and (string-match-p "\\.\\.\\.$" argument)
+ (string= argument (car (last args-lst))))
+ (and (string-match-p "\\.\\.\\.$"
+ (substring args 1 (1- (length args))))
+ (= (length (remove "..." args-lst)) 2)
+ (> index 1) (oddp index)))
(setq index 0))
(t
(setq index (1- index))))))
--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
next prev parent reply other threads:[~2014-08-19 5:39 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 [this message]
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
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=87y4ulghjk.fsf@gmail.com \
--to=thierry.volpiatto@gmail.com \
--cc=18048-done@debbugs.gnu.org \
--cc=monnier@IRO.UMontreal.CA \
/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.