From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.bugs Subject: bug#57673: [PATCH] Parse --help messages for pcomplete Date: Sat, 10 Sep 2022 18:12:31 +0200 Message-ID: <87sfkzgqds.fsf@gmail.com> References: <87zgfagqfs.fsf@gmail.com> <87sfl1leip.fsf@gmail.com> <87pmg3ef6j.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9812"; 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: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 10 18:13:16 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 1oX36a-0002MU-Du for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Sep 2022 18:13:16 +0200 Original-Received: from localhost ([::1]:34546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oX36Y-0004Mc-QN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Sep 2022 12:13:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oX36N-0004MR-4F for bug-gnu-emacs@gnu.org; Sat, 10 Sep 2022 12:13:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51553) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oX36M-0004QP-Rf for bug-gnu-emacs@gnu.org; Sat, 10 Sep 2022 12:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oX36M-00041u-H4 for bug-gnu-emacs@gnu.org; Sat, 10 Sep 2022 12:13:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Sep 2022 16:13: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.166282636415466 (code B ref 57673); Sat, 10 Sep 2022 16:13:02 +0000 Original-Received: (at 57673) by debbugs.gnu.org; 10 Sep 2022 16:12:44 +0000 Original-Received: from localhost ([127.0.0.1]:40252 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oX364-00041O-Bd for submit@debbugs.gnu.org; Sat, 10 Sep 2022 12:12:44 -0400 Original-Received: from mail-ej1-f54.google.com ([209.85.218.54]:42943) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oX35z-000417-Bp for 57673@debbugs.gnu.org; Sat, 10 Sep 2022 12:12:43 -0400 Original-Received: by mail-ej1-f54.google.com with SMTP id r17so10786927ejy.9 for <57673@debbugs.gnu.org>; Sat, 10 Sep 2022 09:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date; bh=SHths6xUSc/x8OuqXNJTpQa8Duaj2Fm0+ln5WZj2wmU=; b=GZRCpLGvCv0g78zmkTs9ctmheQrNu1MQ7DSwLQUamT2w6XyqR3hOxs4fATn48oexNd TYk/SnGATwTZ/rnItJfcEjcPeucRVKzoYb36lt8+p9a0/X4rj8A7RoR5LZPjgk22B4er LzCGxME6JrfKWoVhWsQV+qVv9LQt/JBYOI0GrtPmdamcg77FUzjknRNhkW76xMD0uh/h bJlmBrJL5YoTaN05+nIB0d5nffnaAIXp/1MgSV7DAerj5j/gGqYc4X5H9SI9cBDr8FFb e4Qacv5lpov2FakYZyPCYP0MsfjmkwGYrycJdev4Jhx/NjnSNDhE/aoxBLTqlAgkoQnH glyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date; bh=SHths6xUSc/x8OuqXNJTpQa8Duaj2Fm0+ln5WZj2wmU=; b=7+tdONHMlkN/keuPE9F+c24RvJmRitkiMsRqxkj6sy1cGINU+IJXEJT0Jqx2ymipva +2b4rFEQx3k2iEYhuDjcvvoVDs+D+4Z6n9RPQpIuMK9KJuNL/fmnD2KH+pAW8+N1MQ6p Lynp5u+gpcjW/HFAhdW65L0xQx2K51xtgk0pEDNFv0ERFszjYupwWLyLxF14cIzHnBIj Rxfgc57LAizySQO3S+0Q40A0+tNoOTCeetRzQybX/qYakie3EL0YcdtFLWTSmI+HJVv6 6x6R7shcM+c1CHI3W7709CtY8heK0+Cz7D/JCv+T4v5C0i+S8nSxrIeXw+vegufmRAH4 bGrw== X-Gm-Message-State: ACgBeo0KNO7LzyhiAWwGXCNX2oVavRkCr5X67WDX+wD8u199FmrFN/3h h7yMhV4pQyVO5dHXRivssWSKx8O4ehw= X-Google-Smtp-Source: AA6agR4FKs81rsqX9b9M5/YoMo39WlhzM4ihwnk4WO7j0H5OPi2WKTBhBh1dBB/xEAhjuxOfkNsflQ== X-Received: by 2002:a17:907:2ced:b0:773:6f77:f10f with SMTP id hz13-20020a1709072ced00b007736f77f10fmr10267838ejc.34.1662826352966; Sat, 10 Sep 2022 09:12:32 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::157b]) by smtp.gmail.com with ESMTPSA id 1-20020a170906218100b00730b61d8a5esm1880025eju.61.2022.09.10.09.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Sep 2022 09:12:32 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Sat, 10 Sep 2022 10:32:38 -0400") 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:242110 Archived-At: On Sat, 10 Sep 2022 at 10:32, Stefan Monnier wrote: >> 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`. Sounds good, I'll send a mergeable patch in due time. >> 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: Yes, the function is wholly sufficient, except that I don't know how to make the definitions autoloadable. I guess there's no performance reasons to autoload these little definitions, but we would need autoloading to keep the grouping of commands into the different pcmpl-*.el libraries. So how to I teach the autoload mechanism to do whatever it needs to do every time it sees a (define-simple-pcomplete ...) form? >> +;; 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