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#26270: help-function-arglist doesn't respect "(fn ARGS...)" in docstring Date: Fri, 02 Jun 2017 23:03:14 -0400 Message-ID: <87r2z122od.fsf@users.sourceforge.net> References: <8737dz4bj8.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1496458933 20684 195.159.176.226 (3 Jun 2017 03:02:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 3 Jun 2017 03:02:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux) Cc: Philipp Stephani To: 26270@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 03 05:02:09 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 1dGzKJ-0004zH-VV for geb-bug-gnu-emacs@m.gmane.org; Sat, 03 Jun 2017 05:02:08 +0200 Original-Received: from localhost ([::1]:52240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGzKN-0001wT-HY for geb-bug-gnu-emacs@m.gmane.org; Fri, 02 Jun 2017 23:02:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGzKH-0001wN-IP for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2017 23:02:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGzKE-00055Q-Go for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2017 23:02:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49564) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGzKE-00054Z-B7 for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2017 23:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dGzKD-0003l8-K2 for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2017 23:02:01 -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: Sat, 03 Jun 2017 03:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26270 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26270-submit@debbugs.gnu.org id=B26270.149645890614432 (code B ref 26270); Sat, 03 Jun 2017 03:02:01 +0000 Original-Received: (at 26270) by debbugs.gnu.org; 3 Jun 2017 03:01:46 +0000 Original-Received: from localhost ([127.0.0.1]:52241 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dGzJw-0003kg-Iy for submit@debbugs.gnu.org; Fri, 02 Jun 2017 23:01:44 -0400 Original-Received: from mail-it0-f49.google.com ([209.85.214.49]:37810) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dGzJu-0003kS-Lm for 26270@debbugs.gnu.org; Fri, 02 Jun 2017 23:01:43 -0400 Original-Received: by mail-it0-f49.google.com with SMTP id m47so35130176iti.0 for <26270@debbugs.gnu.org>; Fri, 02 Jun 2017 20:01:42 -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=ljd13YqkKuZxLdwoYx6c4VtQ+kQFy6Lm9zcJfEg+/K0=; b=Hv9M6HHW1NtC7aXmWBTT2AptyuwCOCS5eGZfzgk9qxHLfaj3CW9K9p+CJUcD8qgAwL mMpC6Em4ZpHXGHYiA8whfupKWwchPrBQSCQA8vjZ7YHrgaC5pLKI7QH4jotyFsyniGQs 90QuPjfHPUjjCIBo4csBJ4lmC3rWJpu6MGsazHqbPWIPMz9nDrVheo/TVOqc4xZYgd3o HX1oRXBqOOgm4lrZzIZ/6EoGcFfuWAtP/MyZHA7jbQflonaBDbxYjEz1xFUh8EiZNw4k BEMwpeNO83350jix3lYmRVYGfhJ8alRb8tg3CvuJRSe/Pfw/RtivgSTR2y4MsEDeI7jF LK6Q== 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=ljd13YqkKuZxLdwoYx6c4VtQ+kQFy6Lm9zcJfEg+/K0=; b=iCA6wkPZpdlpUF0n34aH2EA8Ncvd063p4YHjDpF12okCeAPIh1WatmERo4t6AsBF0i Pxa+jQPQxQcSQvxEGOC9j/2GTlGru13iok+7sxnYp9cQ3EPxRWtq1ZEvumBnPXB0TSKN JkozTWicHSKENBa9ZLbfAFYXxKk+ENaqgRZVKH5D4Mk+xs4BVvshQ3dFJOBH4Rwev/hd QwRCpP6f658oNA837FLuQ07Ypc82GuRrRlZBMrqgM90R4dw7H7Ocf7om0kVBf1iNmx/y oiRU93126GXgPyau/w2PCpU4iKi7CBgIqXF9IuSusXpH8uJg7FMXaW161GSwV0gtOheP 8ixQ== X-Gm-Message-State: AODbwcDi5ubnr3V0OUEcGX6+41Wrqgh7efy5E8Ta1jXn9HSCn3b6rbEc IepsY4ZoAD0Wgg== X-Received: by 10.107.178.215 with SMTP id b206mr7335298iof.50.1496458896963; Fri, 02 Jun 2017 20:01:36 -0700 (PDT) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id m89sm10876535ioi.32.2017.06.02.20.01.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 02 Jun 2017 20:01:36 -0700 (PDT) In-Reply-To: <8737dz4bj8.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net's message of "Sun, 26 Mar 2017 23:57:15 -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:133203 Archived-At: --=-=-= Content-Type: text/plain npostavs@users.sourceforge.net writes: > (defun foo (&rest args) > "Do foo. > > \(fn ARG1 ARG2)") > > (help-function-arglist 'foo) ;=> (&rest args) Here's a patch which puts the check of the docstring before the lambda list. I'm not sure what to do with the PRESERVE-NAMES argument of `help-function-arglist' though. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-Prefer-docstring-as-source-of-arglist-with-names-.patch Content-Description: patch >From 0a84e9441d94485ba20c2e44cb9062a7e4259968 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Fri, 2 Jun 2017 22:34:32 -0400 Subject: [PATCH v1] Prefer docstring as source of arglist with names (Bug#26270) * lisp/help.el (help-arglist-from-docstring): New function, extracted from `help-function-arglist'. (help-function-arglist): Use it before looking for a function's lambda list. --- lisp/help.el | 61 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/lisp/help.el b/lisp/help.el index 361ab2a01e..4d98c1dc81 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -1417,6 +1417,23 @@ (defun help-add-fundoc-usage (docstring arglist) (error "Unrecognized usage format")) (help--make-usage-docstring 'fn arglist))))) +(defun help-arglist-from-docstring (doc) + "Return argument list parsed from the docstring, DOC. +DOC should end with \"(fn ARGLIST)\", see Info node `(elisp) +Function Documentation'." + (let* ((docargs (if doc (car (help-split-fundoc doc nil)))) + (arglist (if docargs (cdr (read (downcase docargs))))) + (valid t)) + ;; Check validity. + (dolist (arg arglist) + (unless (and (symbolp arg) + (let ((name (symbol-name arg))) + (if (eq (aref name 0) ?&) + (memq arg '(&rest &optional)) + (not (string-match "\\." name))))) + (setq valid nil))) + (when valid arglist))) + (defun help-function-arglist (def &optional preserve-names) "Return a formal argument list for the function DEF. If PRESERVE-NAMES is non-nil, return a formal arglist that uses @@ -1425,40 +1442,28 @@ (defun help-function-arglist (def &optional preserve-names) (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def))) ;; If definition is a macro, find the function inside it. (if (eq (car-safe def) 'macro) (setq def (cdr def))) + ;; FIXME: What does PRESERVE-NAMES really mean?? (cond + ((help-arglist-from-docstring + (ignore-errors (documentation def)))) ((and (byte-code-function-p def) (listp (aref def 0))) (aref def 0)) ((eq (car-safe def) 'lambda) (nth 1 def)) ((eq (car-safe def) 'closure) (nth 2 def)) ((or (and (byte-code-function-p def) (integerp (aref def 0))) (subrp def) (module-function-p def)) - (or (when preserve-names - (let* ((doc (condition-case nil (documentation def) (error nil))) - (docargs (if doc (car (help-split-fundoc doc nil)))) - (arglist (if docargs - (cdar (read-from-string (downcase docargs))))) - (valid t)) - ;; Check validity. - (dolist (arg arglist) - (unless (and (symbolp arg) - (let ((name (symbol-name arg))) - (if (eq (aref name 0) ?&) - (memq arg '(&rest &optional)) - (not (string-match "\\." name))))) - (setq valid nil))) - (when valid arglist))) - (let* ((arity (func-arity def)) - (max (cdr arity)) - (min (car arity)) - (arglist ())) - (dotimes (i min) - (push (intern (concat "arg" (number-to-string (1+ i)))) arglist)) - (when (and (integerp max) (> max min)) - (push '&optional arglist) - (dotimes (i (- max min)) - (push (intern (concat "arg" (number-to-string (+ 1 i min)))) - arglist))) - (unless (integerp max) (push '&rest arglist) (push 'rest arglist)) - (nreverse arglist)))) + (let* ((arity (func-arity def)) + (max (cdr arity)) + (min (car arity)) + (arglist ())) + (dotimes (i min) + (push (intern (concat "arg" (number-to-string (1+ i)))) arglist)) + (when (and (integerp max) (> max min)) + (push '&optional arglist) + (dotimes (i (- max min)) + (push (intern (concat "arg" (number-to-string (+ 1 i min)))) + arglist))) + (unless (integerp max) (push '&rest arglist) (push 'rest arglist)) + (nreverse arglist))) ((and (autoloadp def) (not (eq (nth 4 def) 'keymap))) "[Arg list not available until function definition is loaded.]") (t t))) -- 2.11.1 --=-=-=--