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: Stefan Monnier
Subject: bug#57673: [PATCH] Parse --help messages for pcomplete
Date: Sat, 10 Sep 2022 10:32:38 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> 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






reply via email to

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