From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH 2/2] emacs: Add shell completions for "guix" command. Date: Sun, 07 Jun 2015 17:36:12 +0200 Message-ID: <87pp57zg2b.fsf@gnu.org> References: <87mw0czhvi.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1cca-00063p-M1 for guix-devel@gnu.org; Sun, 07 Jun 2015 11:36:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z1ccQ-0000RU-LE for guix-devel@gnu.org; Sun, 07 Jun 2015 11:36:24 -0400 In-Reply-To: <87mw0czhvi.fsf@gmail.com> (Alex Kost's message of "Sat, 06 Jun 2015 23:44:49 +0300") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Alex Kost Cc: guix-devel@gnu.org Alex Kost skribis: > Oof! There is a plenty of guix commands, actions, options, =E2=80=A6 > So after this patch, it would be more convenient to use =E2=80=98guix=E2= =80=99 in > "M-x shell". Woohoo! Wonderful! :-) > It should complete almost everything except suboptions of subcommands, I > mean those =E2=80=98import=E2=80=99 modules (e.g., it will not complete > =E2=80=98--no-test-dependencies=E2=80=99 option for =E2=80=98guix import = hackage=E2=80=99 command). I think that=E2=80=99s fine. We wouldn=E2=80=99t want to maintain relative= ly custom completion code for all these things anyway. However it=E2=80=99s important to fall back to file name completions for th= ings 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 =E2=80=98guix ... --help=E2=80=99) are called when necessa= ry 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 =E2=80=98guix-pcomplete-run-guix=E2=80=99 couldn=E2=80=99t run = the command in a REPL instead of spawning a process. That is, when completing =E2=80=98guix buil= d=E2=80=99, 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=E2=80=99m always impressed by your productivity! > From 9ed30b97519afad84c58f1a7166f11a5e22ecda1 Mon Sep 17 00:00:00 2001 > From: Alex Kost > 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=3D "--key-download" option) > + (complete* guix-pcomplete-key-policies)) > + > + ((command? "package") > + (cond > + ;; For '--install[=3D]' and '--remove[=3D]', try to complete a pa= ckage > + ;; name (INPUT) after the "=3D" 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=3D "--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=E2=80=99d quickly not= ice and it seems easy to update anyway. Thank you! Ludo=E2=80=99.