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, 22 Jul 2014 08:16:45 +0200 Organization: Emacs Helm Message-ID: <87fvhtsysy.fsf@gmail.com> References: <87egxjxkxh.fsf@gmail.com> <8738dx6a0g.fsf@gmail.com> <87d2cy99fl.fsf@gmail.com> <87k376spqi.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1406009924 27262 80.91.229.3 (22 Jul 2014 06:18:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Jul 2014 06:18:44 +0000 (UTC) To: 18048@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 22 08:18:36 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 1X9TPE-0004ZO-Ny for geb-bug-gnu-emacs@m.gmane.org; Tue, 22 Jul 2014 08:18:32 +0200 Original-Received: from localhost ([::1]:37697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9TPE-0000LT-5P for geb-bug-gnu-emacs@m.gmane.org; Tue, 22 Jul 2014 02:18:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9TOu-0008TC-Tg for bug-gnu-emacs@gnu.org; Tue, 22 Jul 2014 02:18:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X9TOk-0007mW-Tz for bug-gnu-emacs@gnu.org; Tue, 22 Jul 2014 02:18:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:38827) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9TOk-0007mQ-R9 for bug-gnu-emacs@gnu.org; Tue, 22 Jul 2014 02:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1X9TOk-0008WF-GR for bug-gnu-emacs@gnu.org; Tue, 22 Jul 2014 02:18:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87egxjxkxh.fsf@gmail.com> Resent-From: Thierry Volpiatto Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 22 Jul 2014 06:18: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 X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.140600985632693 (code B ref -1); Tue, 22 Jul 2014 06:18:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Jul 2014 06:17:36 +0000 Original-Received: from localhost ([127.0.0.1]:34093 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X9TOJ-0008VE-79 for submit@debbugs.gnu.org; Tue, 22 Jul 2014 02:17:35 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53184) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X9TOG-0008Uv-L0 for submit@debbugs.gnu.org; Tue, 22 Jul 2014 02:17:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X9TO1-0007eW-BA for submit@debbugs.gnu.org; Tue, 22 Jul 2014 02:17:27 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:45522) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9TO1-0007eQ-7z for submit@debbugs.gnu.org; Tue, 22 Jul 2014 02:17:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9TNt-0008QW-Li for bug-gnu-emacs@gnu.org; Tue, 22 Jul 2014 02:17:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X9TNm-0007bH-5S for bug-gnu-emacs@gnu.org; Tue, 22 Jul 2014 02:17:09 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:37059) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9TNl-0007b8-Uk for bug-gnu-emacs@gnu.org; Tue, 22 Jul 2014 02:17:02 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1X9TNl-0003S0-1E for bug-gnu-emacs@gnu.org; Tue, 22 Jul 2014 08:17:01 +0200 Original-Received: from 37.162.56.247 ([37.162.56.247]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 22 Jul 2014 08:17:01 +0200 Original-Received: from thierry.volpiatto by 37.162.56.247 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 22 Jul 2014 08:17:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 93 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 37.162.56.247 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.92 (gnu/linux) Cancel-Lock: sha1:LpAIpmUUbGNtAJaOChqSVfL9nlg= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). 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:91741 Archived-At: 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) " ")) ;; 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