guix-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 2/2] emacs: Add shell completions for "guix" command.


From: Ludovic Courtès
Subject: Re: [PATCH 2/2] emacs: Add shell completions for "guix" command.
Date: Sun, 07 Jun 2015 17:36:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Alex Kost <address@hidden> skribis:

> Oof!  There is a plenty of guix commands, actions, options, …
> So after this patch, it would be more convenient to use ‘guix’ in
> "M-x shell".

Woohoo!  Wonderful!  :-)

> It should complete almost everything except suboptions of subcommands, I
> mean those ‘import’ modules (e.g., it will not complete
> ‘--no-test-dependencies’ option for ‘guix import hackage’ command).

I think that’s fine.  We wouldn’t want to maintain relatively custom
completion code for all these things anyway.

However it’s important to fall back to file name completions for things
that are not handled, so that at least it is not worse than without the
pcomplete code.

> Completing may lag a bit from time to time.  It happens because shell
> commands (like ‘guix ... --help’) are called when necessary to find
> options, packages, etc.  But the found entries are "memoized" so next
> time the same entries will be completed much faster.

I wonder if ‘guix-pcomplete-run-guix’ couldn’t run the command in a REPL
instead of spawning a process.  That is, when completing ‘guix build’,
it would evaluate something like:

  (with-output-to-string
    (lambda ()
      (catch 'quit
        (lambda ()
          ((@ (guix scripts build) guix-build) "--help"))
        (const #t))))

How does that sound?

> Many thanks to Ludovic for the great idea of this package!

Well I’m always impressed by your productivity!

> From 9ed30b97519afad84c58f1a7166f11a5e22ecda1 Mon Sep 17 00:00:00 2001
> From: Alex Kost <address@hidden>
> Date: Sat, 6 Jun 2015 22:19:51 +0300
> Subject: [PATCH 2/2] emacs: Add shell completions for "guix" command.
>
> * emacs/guix-pcomplete.el: New file.
> * emacs.am (ELFILES): Add it.
> * doc/emacs.texi (Emacs Completions): New node.

LGTM!  OK to push.

> +     ((option? "-L" "--load-path")
> +      (complete* (pcomplete-dirs)))
> +     ((string= "--key-download" option)
> +      (complete* guix-pcomplete-key-policies))
> +
> +     ((command? "package")
> +      (cond
> +       ;; For '--install[=]' and '--remove[=]', try to complete a package
> +       ;; name (INPUT) after the "=" sign, and then the rest packages
> +       ;; separated with spaces.
> +       ((option? "-i" "--install")
> +        (complete (guix-pcomplete-all-packages))
> +        (while (not (guix-pcomplete-match-option))
> +          (pcomplete-here (guix-pcomplete-all-packages))))
> +       ((option? "-r" "--remove")
> +        (let* ((profile (or (guix-pcomplete-short-option-arg
> +                             "-p" pcomplete-args)
> +                            (guix-pcomplete-long-option-arg
> +                             "--profile" pcomplete-args)))
> +               (profile (and profile (expand-file-name profile))))
> +          (complete (guix-pcomplete-installed-packages profile))
> +          (while (not (guix-pcomplete-match-option))
> +            (pcomplete-here (guix-pcomplete-installed-packages profile)))))
> +       ((string= "--show" option)
> +        (complete (guix-pcomplete-all-packages)))
> +       ((option? "-p" "--profile")
> +        (complete* (pcomplete-dirs)))
> +       ((option? "-m" "--manifest")
> +        (complete* (pcomplete-entries)))))
> +
> +     ((and (command? "archive" "build")
> +           (option? "-s" "--system"))
> +      (complete* guix-pcomplete-systems))
> +
> +     ((and (command? "build")
> +           (option? "-r" "--root"))
> +      (complete* (pcomplete-entries)))
> +
> +     ((and (command? "environment")
> +           (option? "-l" "--load"))
> +      (complete* (pcomplete-entries)))
> +
> +     ((and (command? "hash" "download")
> +           (option? "-f" "--format"))
> +      (complete* guix-pcomplete-hash-formats))
> +
> +     ((and (command? "lint")
> +           (option? "-c" "--checkers"))
> +      (guix-pcomplete-complete-comma-args
> +       (guix-pcomplete-lint-checkers)))
> +
> +     ((and (command? "publish")
> +           (option? "-u" "--user"))
> +      (complete* (pcmpl-unix-user-names)))
> +
> +     ((and (command? "refresh")
> +           (option? "-s" "--select"))
> +      (complete* guix-pcomplete-refresh-subsets)))))

I like that this is very accurate.  I was first slightly concerned about
the risk of this becoming out of sync, but I think we’d quickly notice
and it seems easy to update anyway.

Thank you!

Ludo’.



reply via email to

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