bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#57673: [PATCH] Parse --help messages for pcomplete


From: Augusto Stoffel
Subject: bug#57673: [PATCH] Parse --help messages for pcomplete
Date: Sat, 10 Sep 2022 18:12:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

On Sat, 10 Sep 2022 at 10:32, Stefan Monnier <monnier@iro.umontreal.ca> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]