GNU bug report logs - #27272
25.2; [patch] Fix positional args among keyword args in eldoc.

Previous Next

Package: emacs;

Reported by: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>

Date: Wed, 7 Jun 2017 09:32:01 UTC

Severity: normal

Tags: fixed, patch

Found in version 25.2

Fixed in version 26.1

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

Full log


Message #50 received at 27272 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>
Cc: 27272 <at> debbugs.gnu.org, Johan Bockgård <bojohan <at> gnu.org>
Subject: Re: bug#27272: 25.2;
 [patch] Fix positional args among keyword args in eldoc.
Date: Fri, 04 Aug 2017 21:35:18 -0400
[Message part 1 (text/plain, inline)]
npostavs <at> users.sourceforge.net writes:

> Noam Postavsky <npostavs <at> users.sourceforge.net> writes:

>> Thanks, we will have to test the patch to make sure it works since it
>> hasn't been tested in isolation then.
>
> I've added a commit message and tests, I will push in a few days if there
> are no objections.

Actually, I found another little problem: it uses `cl-position' without
requiring `cl-lib', so it triggers void-function errors in the *scratch*
buffer from 'emacs -Q'.  Here's a new version that uses `member' instead
of `cl-position'.

[v4-0001-Fix-eldoc-highlighting-for-key-args-Bug-27272.patch (text/x-diff, inline)]
From b6861be04246d29ea46cf4130700df4d923fac58 Mon Sep 17 00:00:00 2001
From: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>
Date: Thu, 15 Jun 2017 05:26:05 +0200
Subject: [PATCH v4] Fix eldoc highlighting for &key args (Bug#27272)

* lisp/progmodes/elisp-mode.el (elisp--highlight-function-argument):
Only switch to keyword-based searching if INDEX point beyond `&key' in
the argument list.  All arguments prior to the `&key' are position
based.  Additionally, be more strict about what is a keyword when
searching for the current keyword.
---
 lisp/progmodes/elisp-mode.el | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index b3f452ca5b..47739f5957 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -1394,13 +1394,14 @@ (defun elisp--highlight-function-argument (sym args index prefix)
   ;; FIXME: This should probably work on the list representation of `args'
   ;; rather than its string representation.
   ;; FIXME: This function is much too long, we need to split it up!
-  (let ((start          nil)
-	(end            0)
-	(argument-face  'eldoc-highlight-function-argument)
-        (args-lst (mapcar (lambda (x)
-                            (replace-regexp-in-string
-                             "\\`[(]\\|[)]\\'" "" x))
-                          (split-string args))))
+  (let* ((start          nil)
+         (end            0)
+         (argument-face  'eldoc-highlight-function-argument)
+         (args-lst (mapcar (lambda (x)
+                             (replace-regexp-in-string
+                              "\\`[(]\\|[)]\\'" "" x))
+                           (split-string args)))
+         (args-lst-ak (cdr (member "&key" args-lst))))
     ;; Find the current argument in the argument string.  We need to
     ;; handle `&rest' and informal `...' properly.
     ;;
@@ -1412,12 +1413,12 @@ (defun elisp--highlight-function-argument (sym args index prefix)
     ;; 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)
+    (when (and args-lst-ak
+               (>= index (- (length args-lst) (length args-lst-ak))))
       (let* (case-fold-search
              key-have-value
              (sym-name (symbol-name sym))
-             (cur-w (current-word))
-             (args-lst-ak (cdr (member "&key" args-lst)))
+             (cur-w (current-word t))
              (limit (save-excursion
                       (when (re-search-backward sym-name nil t)
                         (match-end 0))))
@@ -1425,7 +1426,7 @@ (defun elisp--highlight-function-argument (sym args index prefix)
                         (substring cur-w 1)
                       (save-excursion
                         (let (split)
-                          (when (re-search-backward ":\\([^()\n]*\\)" limit t)
+                          (when (re-search-backward ":\\([^ ()\n]*\\)" limit t)
                             (setq split (split-string (match-string 1) " " t))
                             (prog1 (car split)
                               (when (cdr split)
@@ -1437,7 +1438,7 @@ (defun elisp--highlight-function-argument (sym args index prefix)
                                  args-lst-ak
                                  (not (member (upcase cur-a) args-lst-ak))
                                  (upcase (car (last args-lst-ak))))))
-        (unless (string= cur-w sym-name)
+        (unless (or (null cur-w) (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'
-- 
2.11.1


This bug report was last modified 8 years and 1 day ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.