From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#27272: 25.2; [patch] Fix positional args among keyword args in eldoc. Date: Wed, 19 Jul 2017 22:22:04 -0400 Message-ID: <87shhralv7.fsf@users.sourceforge.net> References: <87poegnnyn.fsf@gmail.com> <87tw3ng6ov.fsf@gnu.org> <878tkzc5fm.fsf@gmail.com> <87wp8eru6z.fsf@users.sourceforge.net> <87lgound82.fsf@gmail.com> <87o9t6ktso.fsf@users.sourceforge.net> <87a84qx9q3.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1500517285 12051 195.159.176.226 (20 Jul 2017 02:21:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Jul 2017 02:21:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux) Cc: 27272@debbugs.gnu.org, Johan =?UTF-8?Q?Bockg=C3=A5rd?= To: Thierry Volpiatto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 20 04:21:19 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dY15U-0002SI-IT for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Jul 2017 04:21:12 +0200 Original-Received: from localhost ([::1]:35708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY15a-0006RX-02 for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Jul 2017 22:21:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY15P-0006R9-Rw for bug-gnu-emacs@gnu.org; Wed, 19 Jul 2017 22:21:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dY15K-0004Or-Sl for bug-gnu-emacs@gnu.org; Wed, 19 Jul 2017 22:21:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45702) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dY15K-0004On-Od for bug-gnu-emacs@gnu.org; Wed, 19 Jul 2017 22:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dY15K-0007Rh-A1 for bug-gnu-emacs@gnu.org; Wed, 19 Jul 2017 22:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 20 Jul 2017 02:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27272 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 27272-submit@debbugs.gnu.org id=B27272.150051724028579 (code B ref 27272); Thu, 20 Jul 2017 02:21:02 +0000 Original-Received: (at 27272) by debbugs.gnu.org; 20 Jul 2017 02:20:40 +0000 Original-Received: from localhost ([127.0.0.1]:48379 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dY14w-0007Qq-Mn for submit@debbugs.gnu.org; Wed, 19 Jul 2017 22:20:39 -0400 Original-Received: from mail-io0-f181.google.com ([209.85.223.181]:36315) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dY14u-0007Qd-60 for 27272@debbugs.gnu.org; Wed, 19 Jul 2017 22:20:36 -0400 Original-Received: by mail-io0-f181.google.com with SMTP id q2so6865003ioe.3 for <27272@debbugs.gnu.org>; Wed, 19 Jul 2017 19:20:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=zUAGHmnok4pmZNqTruuYO2OeOvM+iJ2xRQVKVOAiekA=; b=JmPg+FgKPvVpBBl538jCenPMe/ifY0ZNblnVds/rxZzwl9jy6ZEJcr8rdL6yfdhNgL SQeNHG+hmYaSeTX4O3U9kt6vFuQmhmHH9gWnzKDtUH6DKt0wZN/TxqWeJWPXf04ASN9Z yKOArStxixpElUhc7WvxjUol9dJ02/jRo7mSrKVVa7euaLcPUqG6rTphbICH6TOwcKqP Lik1m/oZbk9Oo1gW0IEHaMEo3ldoIQM6kz3TwhZqv7J4kkiR8Njd05WNVuFbSW4TIaHQ H+UfJJ94JAhwYYAlNcEcitl2KBJ/Ca/4oS7urxOzEGAB1UVCF1k04AXDCjnssqmiRTQj bGSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=zUAGHmnok4pmZNqTruuYO2OeOvM+iJ2xRQVKVOAiekA=; b=Lt3h7zyMaDd57yfTBAUjveY8gBZUlCNnF41h7XSnyilxs65/zghX/8JHa3bad3KoMr 8J8dvuiKmGOpeF9hyc3Jy+JjbT0NVAVq4fLgxquFhd8THpcsRigFYUzg1RP5qj/du/DY uE1FNZ1OT7IXuPVix3RRgOF077Vua7SiKRybpB0sfXW8PXWVa4yFMIXwvwV8SMon4d1i Un+qdDX8Zpx1tZJoc0x544oYIgl0YiLcM6XhnRSP80YacIA1twUKTI7DJKd6k2Zti+ob H/n7fEP3KjahLEstVu5CMdkqjPikTFyOiOS7piP/BtOBp7HQAkA6pPs8OMaWk+OxM5Ze YBpQ== X-Gm-Message-State: AIVw110VUk1ut+czpqJGWY+W5au/sgUE6h1Z5wKfUcOCeGTbic2pcoL3 e8sqbm9YdzflWg== X-Received: by 10.107.137.17 with SMTP id l17mr2068933iod.305.1500517230556; Wed, 19 Jul 2017 19:20:30 -0700 (PDT) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id g198sm711469itb.3.2017.07.19.19.20.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Jul 2017 19:20:29 -0700 (PDT) In-Reply-To: (Noam Postavsky's message of "Sat, 1 Jul 2017 17:00:19 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:134775 Archived-At: --=-=-= Content-Type: text/plain Noam Postavsky writes: > On Fri, Jun 30, 2017 at 2:36 AM, Thierry Volpiatto > wrote: >> >> This patch is an adaptation of what I use in my .emacs.el, originally >> the patch was correct, I have then deleted it (because the patch was >> refused) and then created it again on your request, forgetting to merge >> one line; Use let* instead of let. > > 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v3-0001-Fix-eldoc-highlighting-for-key-args-Bug-27272.patch Content-Description: patch >From 27ddcf55804d4e852b2572ec4b7cab7dacecc5d6 Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto Date: Thu, 15 Jun 2017 05:26:05 +0200 Subject: [PATCH v3 1/2] 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 is greater than the index of `&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 | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index b3f452ca5b..c70d5baffe 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))) + (start-key-pos (cl-position "&key" args-lst :test 'equal))) ;; Find the current argument in the argument string. We need to ;; handle `&rest' and informal `...' properly. ;; @@ -1412,11 +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 start-key-pos + (> index start-key-pos)) (let* (case-fold-search key-have-value (sym-name (symbol-name sym)) - (cur-w (current-word)) + (cur-w (current-word t)) (args-lst-ak (cdr (member "&key" args-lst))) (limit (save-excursion (when (re-search-backward sym-name nil t) @@ -1425,7 +1427,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 +1439,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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v3-0002-Add-tests-for-previous-commit.patch Content-Description: patch >From 2e15fa20c441d5ead95a416e7fd67c525bc5fbaf Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 19 Jul 2017 22:06:02 -0400 Subject: [PATCH v3 2/2] Add tests for previous commit * test/lisp/progmodes/elisp-mode-tests.el (elisp-mode-tests--face-propertized-string): New function. (elisp--highlight-function-argument-indexed) (elisp--highlight-function-argument-keyed-1) (elisp--highlight-function-argument-keyed-2): New tests. --- test/lisp/progmodes/elisp-mode-tests.el | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el index ee0837f2c4..675aa31a79 100644 --- a/test/lisp/progmodes/elisp-mode-tests.el +++ b/test/lisp/progmodes/elisp-mode-tests.el @@ -24,6 +24,7 @@ (require 'ert) (require 'xref) +(eval-when-compile (require 'cl-lib)) ;;; Completion @@ -180,6 +181,61 @@ (ert-deftest eval-last-sexp-print-format-large-int-echo () (call-interactively #'eval-last-sexp) (should (equal (current-message) "66 (#o102, #x42, ?B)")))))) +;;; eldoc + +(defun elisp-mode-tests--face-propertized-string (string) + "Return substring of STRING with a non-nil `face' property." + (let* ((start (next-single-property-change 0 'face string)) + (end (and start (next-single-property-change start 'face string)))) + (and end + (substring string start end)))) + +(ert-deftest elisp--highlight-function-argument-indexed () + (dotimes (i 3) + (should + (equal (elisp-mode-tests--face-propertized-string + (elisp--highlight-function-argument 'foo "(A B C)" (1+ i) "foo: ")) + (propertize (nth i '("A" "B" "C")) + 'face 'eldoc-highlight-function-argument))))) + +(ert-deftest elisp--highlight-function-argument-keyed-1 () + (with-temp-buffer + (emacs-lisp-mode) + (insert "(foo prompt bar :b 2)") + (goto-char (1+ (point-min))) + (cl-flet ((bold-arg (i) + (elisp-mode-tests--face-propertized-string + (elisp--highlight-function-argument + 'foo "(PROMPT LST &key A B C)" i "foo: ")))) + (should-not (bold-arg 0)) + (progn (forward-sexp) (forward-char)) + (should (equal (bold-arg 1) "PROMPT")) + (progn (forward-sexp) (forward-char)) + (should (equal (bold-arg 2) "LST")) + ;; Both `:b' and `2' should highlight the `B' arg. + (progn (forward-sexp) (forward-char)) + (should (equal (bold-arg 3) "B")) + (progn (forward-sexp) (forward-char)) + (should (equal (bold-arg 4) "B"))))) + +(ert-deftest elisp--highlight-function-argument-keyed-2 () + (with-temp-buffer + (emacs-lisp-mode) + (insert "(foo :b :a 1)") + (goto-char (1+ (point-min))) + (cl-flet ((bold-arg (i) + (elisp-mode-tests--face-propertized-string + (elisp--highlight-function-argument + 'foo "(X &key A B C)" i "foo: ")))) + (should-not (bold-arg 0)) + ;; The `:b' specifies positional arg `X'. + (progn (forward-sexp) (forward-char)) + (should (equal (bold-arg 1) "X")) + (progn (forward-sexp) (forward-char)) + (should (equal (bold-arg 2) "A")) + (progn (forward-sexp) (forward-char)) + (should (equal (bold-arg 3) "A"))))) + ;;; xref (defun xref-elisp-test-descr-to-target (xref) -- 2.11.1 --=-=-=--