From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#57673: [PATCH] Parse --help messages for pcomplete Date: Sat, 10 Sep 2022 10:32:38 -0400 Message-ID: References: <87zgfagqfs.fsf@gmail.com> <87sfl1leip.fsf@gmail.com> <87pmg3ef6j.fsf@gmail.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9510"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Lars Ingebrigtsen , 57673@debbugs.gnu.org To: Augusto Stoffel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 10 16:33:18 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oX1Xo-0002FU-N6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Sep 2022 16:33:17 +0200 Original-Received: from localhost ([::1]:48606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oX1Xn-0000Tw-KZ for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Sep 2022 10:33:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oX1Xa-0000Tn-RL for bug-gnu-emacs@gnu.org; Sat, 10 Sep 2022 10:33:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51419) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oX1Xa-00075e-Hf for bug-gnu-emacs@gnu.org; Sat, 10 Sep 2022 10:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oX1Xa-0001X0-4e for bug-gnu-emacs@gnu.org; Sat, 10 Sep 2022 10:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Sep 2022 14:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57673 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 57673-submit@debbugs.gnu.org id=B57673.16628203695867 (code B ref 57673); Sat, 10 Sep 2022 14:33:02 +0000 Original-Received: (at 57673) by debbugs.gnu.org; 10 Sep 2022 14:32:49 +0000 Original-Received: from localhost ([127.0.0.1]:40118 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oX1XM-0001WZ-RU for submit@debbugs.gnu.org; Sat, 10 Sep 2022 10:32:49 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:11807) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oX1XL-0001WL-1D for 57673@debbugs.gnu.org; Sat, 10 Sep 2022 10:32:47 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 5E3A380390; Sat, 10 Sep 2022 10:32:41 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id C628C8043C; Sat, 10 Sep 2022 10:32:39 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1662820359; bh=1j2aKHHwQpI01d4d08Y657mQjKOrwR5h0PtDG1QZ1s8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=nHUgP5vO/+KaOaslWzqCKg7ImAM3tq2W9HTQz9N8fUuf4FWBDHLtqlCNJ4iGVUCYf oPRo2dvYvlY8K8IPnIj+9AqwFG6nRSrRpKw0jr72ObFJG9H4aqI3poU8sQE5h8fwq9 yBQGUMZs8/Z2s0LHH0jYzYQeMqy1as7lxJmofIGQsmLLgZMObK78RRSQBTSYWTPfLO 7ra4czEWQXBL1uHa07sxh3JWrnarC8kpdN1hP5ieUZIztpqwujGb6R2EgWZ9AGWXCO Rx8m0Tto0EO5i54zZF1TtNBvv1SahrUrYemiIATkWbjVfj4IRfylLguDW0lNR1u9gn Ix3Ntv3qgmyfg== Original-Received: from pastel (unknown [157.52.9.190]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 98AF71207FF; Sat, 10 Sep 2022 10:32:39 -0400 (EDT) In-Reply-To: <87pmg3ef6j.fsf@gmail.com> (Augusto Stoffel's message of "Sat, 10 Sep 2022 11:45:08 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:242106 Archived-At: > I've attached a new iteration of the patch. I think the git completion > should be pretty usable (but certainly can be refined in the future). > I'm also satisfied with the parser, please have a look if you are > interested. LGTM, feel free to push it to `master`. > Next I'd like to think now of a good way to add batches of simpler > commands, say all GNU coreutils. This would entail repeating variations > of > > (defun pcomplete/gpg () > "Completion for the GNU Privacy Guard." > (while (if (pcomplete-match "\\`-" 0) > (pcomplete-here (pcomplete-from-help "gpg --help" > :narrow-end "^ -se")) > (pcomplete-here (pcomplete-entries))))) > > over and over, so I was wondering if it makes sense to add a macro to > help here. See a suggestion at the end of pcomplete.el. I do think it makes sense, but I think it doesn't need to be a macro: > +;; What do you think of a macro like this? > +(defmacro define-simple-pcomplete (name command &rest args) > + "Create `pcomplete' completions for a simple command. > +COMMAND and ARGS are as in `pcomplete-from-help'. Completion > +candidates for this command will include the parsed arguments as > +well as files." > + (let* ((namestr (symbol-name name)) > + (docstring (if-let ((i (string-search "/" namestr))) > + (format "Completions for the `%s' command in `%s'." > + (substring namestr 0 i) > + (substring namestr i)) > + (format "Completions for the `%s' command." namestr)))) > + `(defun ,(intern (concat "pcomplete/" namestr)) () > + ,docstring > + (pcomplete--simple-command ,command ',args)))) (defun define-simple-pcomplete (name command &rest args) "Create `pcomplete' completions for a simple command. COMMAND and ARGS are as in `pcomplete-from-help'. Completion candidates for this command will include the parsed arguments as well as files." (let* ((namestr (symbol-name name)) (docstring (if-let ((i (string-search "/" namestr))) (format "Completions for the `%s' command in `%s'." (substring namestr 0 i) (substring namestr i)) (format "Completions for the `%s' command." namestr)))) (defalias (intern (concat "pcomplete/" namestr)) (lambda () (:documentation docstring) (pcomplete--simple-command command args))))) Also, we may end up with various "simple" solutions, so I'd use a name that is more explicit about how it works. E.g. `pcomplete-via-help`? Stefan