From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.bugs Subject: bug#18048: 24.3.92; [patch] eldoc improvements Date: Tue, 19 Aug 2014 07:39:39 +0200 Message-ID: <87y4ulghjk.fsf@gmail.com> References: <87egxjxkxh.fsf@gmail.com> <8738dx6a0g.fsf@gmail.com> <87y4vn2mu6.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1408427127 13289 80.91.229.3 (19 Aug 2014 05:45:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Aug 2014 05:45:27 +0000 (UTC) Cc: 18048-done@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 19 07:45:19 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XJcEQ-0002W2-Il for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Aug 2014 07:45:18 +0200 Original-Received: from localhost ([::1]:48294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJcEQ-0001SJ-4n for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Aug 2014 01:45:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJcEI-0001RK-2n for bug-gnu-emacs@gnu.org; Tue, 19 Aug 2014 01:45:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJcEB-0004n6-Ph for bug-gnu-emacs@gnu.org; Tue, 19 Aug 2014 01:45:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:39961) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJcEB-0004kr-Ls for bug-gnu-emacs@gnu.org; Tue, 19 Aug 2014 01:45:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XJcEA-0003MS-JK for bug-gnu-emacs@gnu.org; Tue, 19 Aug 2014 01:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Thierry Volpiatto Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Aug 2014 05:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18048 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 18048-done@debbugs.gnu.org id=D18048.140842707012856 (code D ref 18048); Tue, 19 Aug 2014 05:45:02 +0000 Original-Received: (at 18048-done) by debbugs.gnu.org; 19 Aug 2014 05:44:30 +0000 Original-Received: from localhost ([127.0.0.1]:46904 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XJcDe-0003LH-2B for submit@debbugs.gnu.org; Tue, 19 Aug 2014 01:44:30 -0400 Original-Received: from mail-we0-f173.google.com ([74.125.82.173]:65113) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XJcDc-0003L0-2I for 18048-done@debbugs.gnu.org; Tue, 19 Aug 2014 01:44:28 -0400 Original-Received: by mail-we0-f173.google.com with SMTP id q58so5980188wes.32 for <18048-done@debbugs.gnu.org>; Mon, 18 Aug 2014 22:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:from:to:cc:subject:date:in-reply-to:message-id :mime-version:content-type; bh=EgHLIMpwW1c1TBw4/naLVxKqhtKHWvXtFXxF/VN93WU=; b=PBTKhWnqDx9ukudH1DTQy1uw4mLoQyBNc6JnKY8AwVIcLu+1QqZ3mLnwWf7L3jWmEV pM1OhlFi48tgrqIQldGgsq325GgqoCytTb8HUaxiGoXD/9t9cazfNOkV4KOXuF2rUiTH yTzswQuVLCuhD9vZEChN6dpGx21V0EZ205zxMBnA4qHKzRZucBpGkVkJjn7zK66qdSKS U1jv8siXgWcFxae7RwyAfch3UstKXkkBrm/Sjj5JpANuKjhTCb08FzBQ0lcbuCB1Klfu nnXHU/yR3XDYu5FeM6lF+2DevTxO0r42OG6Ec3RBdfZPuc0HqQp7Lgfd1/7YYZxCmzAu jAnw== X-Received: by 10.180.210.231 with SMTP id mx7mr3971897wic.42.1408427061832; Mon, 18 Aug 2014 22:44:21 -0700 (PDT) Original-Received: from dell-14z ([37.162.228.28]) by mx.google.com with ESMTPSA id ch5sm47668421wjb.18.2014.08.18.22.44.18 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 18 Aug 2014 22:44:21 -0700 (PDT) In-reply-to: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:92527 Archived-At: Stefan Monnier 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