2 @chapter Emacs Interface
5 GNU Guix comes with several useful modules (known as ``guix.el'') for
6 GNU@tie{}Emacs which are intended to make an Emacs user interaction with
7 Guix convenient and fun.
10 * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
11 * Package Management: Emacs Package Management. Managing packages and generations.
12 * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
13 * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
14 * Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
15 * Completions: Emacs Completions. Completing @command{guix} shell command.
16 * Development: Emacs Development. Tools for Guix developers.
20 @node Emacs Initial Setup
21 @section Initial Setup
23 On the Guix System Distribution (@pxref{GNU Distribution}), ``guix.el''
24 is ready to use, provided Guix is installed system-wide, which is the
25 case by default. So if that is what you're using, you can happily skip
26 this section and read about the fun stuff.
28 If you're not yet a happy user of GuixSD, a little bit of setup is needed.
29 To be able to use ``guix.el'', you need to install the following
34 @uref{http://www.gnu.org/software/emacs/, GNU Emacs}, version 24.3 or
38 @uref{http://nongnu.org/geiser/, Geiser}, version 0.3 or later: it is
39 used for interacting with the Guile process.
42 @uref{https://github.com/magit/magit/, magit-popup library}. You
43 already have this library if you use Magit 2.1.0 or later. This library
44 is an optional dependency---it is required only for @kbd{M-x@tie{}guix}
45 command (@pxref{Emacs Popup Interface}).
49 When it is done ``guix.el'' may be configured by requiring a special
50 @code{guix-init} file---i.e., by adding the following code into your
51 init file (@pxref{Init File,,, emacs, The GNU Emacs Manual}):
54 (add-to-list 'load-path "/path/to/directory-with-guix.el")
55 (require 'guix-init nil t)
58 So the only thing you need to figure out is where the directory with
59 elisp files for Guix is placed. It depends on how you installed Guix:
63 If it was installed by a package manager of your distribution or by a
64 usual @code{./configure && make && make install} command sequence, then
65 elisp files are placed in a standard directory with Emacs packages
66 (usually it is @file{/usr/share/emacs/site-lisp/}), which is already in
67 @code{load-path}, so there is no need to add that directory there.
70 If you used a binary installation method (@pxref{Binary Installation}),
71 then Guix is installed somewhere in the store, so the elisp files are
72 placed in @file{/gnu/store/@dots{}-guix-0.8.2/share/emacs/site-lisp/} or
73 alike. However it is not recommended to refer directly to a store
74 directory. Instead you can install Guix using Guix itself with
75 @command{guix package -i guix} command (@pxref{Invoking guix package})
76 and add @file{~/.guix-profile/share/emacs/site-lisp/} directory to
77 @code{load-path} variable.
80 If you did not install Guix at all and prefer a hacking way
81 (@pxref{Running Guix Before It Is Installed}), along with augmenting
82 @code{load-path} you need to set @code{guix-load-path} variable to the
83 same directory, so your final configuration will look like this:
86 (let ((dir "/path/to/your-guix-git-tree/emacs"))
87 (add-to-list 'load-path dir)
88 (setq guix-load-path dir))
89 (require 'guix-init nil t)
93 By default, along with autoloading (@pxref{Autoload,,, elisp, The GNU
94 Emacs Lisp Reference Manual}) the main interactive commands for
95 ``guix.el'' (@pxref{Emacs Commands}), requiring @code{guix-init} will
96 also autoload commands for the Emacs packages installed in your user
99 To disable automatic loading of installed Emacs packages, set
100 @code{guix-package-enable-at-startup} variable to @code{nil} before
101 requiring @code{guix-init}. This variable has the same meaning for
102 Emacs packages installed with Guix, as @code{package-enable-at-startup}
103 for the built-in Emacs package system (@pxref{Package Installation,,,
104 emacs, The GNU Emacs Manual}).
106 You can activate Emacs packages installed in your profile whenever you
107 want using @kbd{M-x@tie{}guix-emacs-load-autoloads}.
110 @node Emacs Package Management
111 @section Package Management
113 Once ``guix.el'' has been successfully configured, you should be able to
114 use a visual interface for routine package management tasks, pretty much
115 like the @command{guix package} command (@pxref{Invoking guix package}).
116 Specifically, it makes it easy to:
119 @item browse and display packages and generations;
120 @item search, install, upgrade and remove packages;
121 @item display packages from previous generations;
122 @item do some other useful things.
126 * Commands: Emacs Commands. @kbd{M-x guix-@dots{}}
127 * General information: Emacs General info. Common for both interfaces.
128 * ``List'' buffer: Emacs List buffer. List-like interface.
129 * ``Info'' buffer: Emacs Info buffer. Help-like interface.
130 * Configuration: Emacs Configuration. Configuring the interface.
136 All commands for displaying packages and generations use the current
137 profile, which can be changed with
138 @kbd{M-x@tie{}guix-set-current-profile}. Alternatively, if you call any
139 of these commands with prefix argument (@kbd{C-u}), you will be prompted
140 for a profile just for that command.
142 Commands for displaying packages:
146 @item M-x guix-all-available-packages
147 @itemx M-x guix-newest-available-packages
148 Display all/newest available packages.
150 @item M-x guix-installed-packages
151 Display all installed packages.
153 @item M-x guix-obsolete-packages
154 Display obsolete packages (the packages that are installed in a profile
155 but cannot be found among available packages).
157 @item M-x guix-search-by-name
158 Display package(s) with the specified name.
160 @item M-x guix-search-by-regexp
161 Search for packages by a specified regexp. By default ``name'',
162 ``synopsis'' and ``description'' of the packages will be searched. This
163 can be changed by modifying @code{guix-search-params} variable.
167 By default, these commands display each output on a separate line. If
168 you prefer to see a list of packages---i.e., a list with a package per
169 line, use the following setting:
172 (setq guix-package-list-type 'package)
175 Commands for displaying generations:
179 @item M-x guix-generations
180 List all the generations.
182 @item M-x guix-last-generations
183 List the @var{N} last generations. You will be prompted for the number
186 @item M-x guix-generations-by-time
187 List generations matching time period. You will be prompted for the
188 period using Org mode time prompt based on Emacs calendar (@pxref{The
189 date/time prompt,,, org, The Org Manual}).
193 You can also invoke the @command{guix pull} command (@pxref{Invoking
194 guix pull}) from Emacs using:
198 With @kbd{C-u}, make it verbose.
201 Once @command{guix pull} has succeeded, the Guix REPL is restared. This
202 allows you to keep using the Emacs interface with the updated Guix.
204 @node Emacs General info
205 @subsection General information
207 The following keys are available for both ``list'' and ``info'' types of
213 Go backward/forward by the history of the displayed results (this
214 history is similar to the history of the Emacs @code{help-mode} or
218 Revert current buffer: update information about the displayed
219 packages/generations and redisplay it.
222 Redisplay current buffer (without updating information).
225 Apply manifest to the current profile or to a specified profile, if
226 prefix argument is used. This has the same meaning as @code{--manifest}
227 option (@pxref{Invoking guix package}).
231 @cindex read-eval-print loop
232 Go to the Guix REPL (@pxref{The REPL,,, geiser, Geiser User Manual}).
236 Describe current mode to see all available bindings.
240 @emph{Hint:} If you need several ``list'' or ``info'' buffers, you can
241 simlpy @kbd{M-x clone-buffer} them, and each buffer will have its own
244 @emph{Warning:} Name/version pairs cannot be used to identify packages
245 (because a name is not necessarily unique), so ``guix.el'' uses special
246 identifiers that live only during a guile session, so if the Guix REPL
247 was restarted, you may want to revert ``list'' buffer (by pressing
250 @node Emacs List buffer
251 @subsection ``List'' buffer
253 An interface of a ``list'' buffer is similar to the interface provided
254 by ``package.el'' (@pxref{Package Menu,,, emacs, The GNU Emacs Manual}).
256 Default key bindings available for both ``package-list'' and
257 ``generation-list'' buffers:
261 Mark the current entry (with prefix, mark all entries).
263 Unmark the current entry (with prefix, unmark all entries).
267 Sort entries by a specified column.
270 A ``package-list'' buffer additionally provides the following bindings:
274 Describe marked packages (display available information in a
275 ``package-info'' buffer).
277 Mark the current package for installation.
279 Mark the current package for deletion.
281 Mark the current package for upgrading.
283 Mark all obsolete packages for upgrading.
285 Edit the definition of the curent package (go to its location). This is
286 similar to @command{guix edit} command (@pxref{Invoking guix edit}), but
287 for opening a package recipe in the current Emacs instance.
289 Execute actions on the marked packages.
292 A ``generation-list'' buffer additionally provides the following
297 List packages installed in the current generation.
299 Describe marked generations (display available information in a
300 ``generation-info'' buffer).
302 Switch profile to the current generation.
304 Mark the current generation for deletion (with prefix, mark all
307 Execute actions on the marked generations---i.e., delete generations.
309 Run Ediff (@pxref{Top,,, ediff, The Ediff Manual}) on package outputs
310 installed in the 2 marked generations. With prefix argument, run Ediff
311 on manifests of the marked generations.
314 Run Diff (@pxref{Diff Mode,,, emacs, The GNU Emacs Manual}) on package
315 outputs installed in the 2 marked generations. With prefix argument,
316 run Diff on manifests of the marked generations.
318 List package outputs added to the latest marked generation comparing
319 with another marked generation.
321 List package outputs removed from the latest marked generation comparing
322 with another marked generation.
325 @node Emacs Info buffer
326 @subsection ``Info'' buffer
328 The interface of an ``info'' buffer is similar to the interface of
329 @code{help-mode} (@pxref{Help Mode,,, emacs, The GNU Emacs Manual}).
331 ``Info'' buffer contains some buttons (as usual you may use @key{TAB} /
332 @kbd{S-@key{TAB}} to move between buttons---@pxref{Mouse References,,,
333 emacs, The GNU Emacs Manual}) which can be used to:
336 @item (in a ``package-info'' buffer)
339 @item install/remove a package;
340 @item jump to a package location;
341 @item browse home page of a package;
342 @item describe packages from ``Inputs'' fields.
345 @item (in a ``generation-info'' buffer)
348 @item remove a generation;
349 @item switch to a generation;
350 @item list packages installed in a generation;
351 @item jump to a generation directory.
356 It is also possible to copy a button label (a link to an URL or a file)
357 by pressing @kbd{c} on a button.
360 @node Emacs Configuration
361 @subsection Configuration
363 There are many variables you can modify to change the appearance or
364 behavior of Emacs user interface. Some of these variables are described
365 in this section. Also you can use Custom Interface (@pxref{Easy
366 Customization,,, emacs, The GNU Emacs Manual}) to explore/set variables
370 * Guile and Build Options: Emacs Build Options. Specifying how packages are built.
371 * Buffer Names: Emacs Buffer Names. Names of Guix buffers.
372 * Keymaps: Emacs Keymaps. Configuring key bindings.
373 * Appearance: Emacs Appearance. Settings for visual appearance.
376 @node Emacs Build Options
377 @subsubsection Guile and Build Options
380 @item guix-guile-program
381 If you have some special needs for starting a Guile process, you may set
382 this variable, for example:
385 (setq guix-guile-program '("/bin/guile" "--no-auto-compile"))
388 @item guix-use-substitutes
389 Has the same meaning as @code{--no-substitutes} option (@pxref{Invoking
393 Has the same meaning as @code{--dry-run} option (@pxref{Invoking guix
398 @node Emacs Buffer Names
399 @subsubsection Buffer Names
401 Default names of ``guix.el'' buffers (``*Guix@tie{}@dots{}*'') may be
402 changed with the following variables:
405 @item guix-package-list-buffer-name
406 @item guix-output-list-buffer-name
407 @item guix-generation-list-buffer-name
408 @item guix-package-info-buffer-name
409 @item guix-output-info-buffer-name
410 @item guix-generation-info-buffer-name
411 @item guix-repl-buffer-name
412 @item guix-internal-repl-buffer-name
415 By default, the name of a profile is also displayed in a ``list'' or
416 ``info'' buffer name. To change this behavior, use
417 @code{guix-buffer-name-function} variable.
419 For example, if you want to display all types of results in a single
420 buffer (in such case you will probably use a history (@kbd{l}/@kbd{r})
421 extensively), you may do it like this:
424 (let ((name "Guix Universal"))
426 guix-package-list-buffer-name name
427 guix-output-list-buffer-name name
428 guix-generation-list-buffer-name name
429 guix-package-info-buffer-name name
430 guix-output-info-buffer-name name
431 guix-generation-info-buffer-name name
432 guix-buffer-name-function #'guix-buffer-name-simple))
436 @subsubsection Keymaps
438 If you want to change default key bindings, use the following keymaps
439 (@pxref{Init Rebinding,,, emacs, The GNU Emacs Manual}):
443 Parent keymap with general keys for all guix modes.
445 @item guix-list-mode-map
446 Parent keymap with general keys for ``list'' buffers.
448 @item guix-package-list-mode-map
449 Keymap with specific keys for ``package-list'' buffers.
451 @item guix-output-list-mode-map
452 Keymap with specific keys for ``output-list'' buffers.
454 @item guix-generation-list-mode-map
455 Keymap with specific keys for ``generation-list'' buffers.
457 @item guix-info-mode-map
458 Parent keymap with general keys for ``info'' buffers.
460 @item guix-package-info-mode-map
461 Keymap with specific keys for ``package-info'' buffers.
463 @item guix-output-info-mode-map
464 Keymap with specific keys for ``output-info'' buffers.
466 @item guix-generation-info-mode-map
467 Keymap with specific keys for ``generation-info'' buffers.
469 @item guix-info-button-map
470 Keymap with keys available when a point is placed on a button.
474 @node Emacs Appearance
475 @subsubsection Appearance
477 You can change almost any aspect of ``list'' / ``info'' buffers using
478 the following variables:
481 @item guix-list-column-format
482 @itemx guix-list-column-titles
483 @itemx guix-list-column-value-methods
484 Specify the columns, their names, what and how is displayed in ``list''
487 @item guix-info-displayed-params
488 @itemx guix-info-insert-methods
489 @itemx guix-info-ignore-empty-vals
490 @itemx guix-info-param-title-format
491 @itemx guix-info-multiline-prefix
492 @itemx guix-info-indent
493 @itemx guix-info-fill-column
494 @itemx guix-info-delimiter
495 Various settings for ``info'' buffers.
500 @node Emacs Popup Interface
501 @section Popup Interface
503 If you ever used Magit, you know what ``popup interface'' is
504 (@pxref{Top,,, magit-popup, Magit-Popup User Manual}). Even if you are
505 not acquainted with Magit, there should be no worries as it is very
508 So @kbd{M-x@tie{}guix} command provides a top-level popup interface for
509 all available guix commands. When you select an option, you'll be
510 prompted for a value in the minibuffer. Many values have completions,
511 so don't hesitate to press @key{TAB} key. Multiple values (for example,
512 packages or lint checkers) should be separated by commas.
514 After specifying all options and switches for a command, you may choose
515 one of the available actions. The following default actions are
516 available for all commands:
521 Run the command in the Guix REPL. It is faster than running
522 @code{guix@tie{}@dots{}} command directly in shell, as there is no
523 need to run another guile process and to load required modules there.
526 Run the command in a shell buffer. You can set
527 @code{guix-run-in-shell-function} variable to fine tune the shell buffer
531 Add the command line to the kill ring (@pxref{Kill Ring,,, emacs, The
536 Several commands (@command{guix graph}, @command{guix system dmd-graph}
537 and @command{guix system extension-graph}) also have a ``View graph''
538 action, which allows you to view a generated graph using @command{dot}
539 command (specified by @code{guix-dot-program} variable). By default a
540 PNG file will be saved in @file{/tmp} directory and will be opened
541 directly in Emacs. This behavior may be changed with the following
546 @item guix-find-file-function
547 Function used to open a generated graph. If you want to open a graph in
548 an external program, you can do it by modifying this variable---for
549 example, you can use a functionality provided by the Org Mode
550 (@pxref{Top,,, org, The Org Manual}):
553 (setq guix-find-file-function 'org-open-file)
554 (add-to-list 'org-file-apps '("\\.png\\'" . "sxiv %s"))
557 @item guix-dot-default-arguments
558 Command line arguments to run @command{dot} command. If you change an
559 output format (for example, into @code{-Tpdf}), you also need to change
562 @item guix-dot-file-name-function
563 Function used to define a name of the generated graph file. Default
564 name is @file{/tmp/guix-emacs-graph-XXXXXX.png}.
568 So, for example, if you want to generate and open a PDF file in your
569 Emacs, you may change the settings like this:
572 (defun my-guix-pdf-graph ()
573 "/tmp/my-current-guix-graph.pdf")
575 (setq guix-dot-default-arguments '("-Tpdf")
576 guix-dot-file-name-function 'my-guix-pdf-graph)
581 @section Guix Prettify Mode
583 GNU@tie{}Guix also comes with ``guix-prettify.el''. It provides a minor
584 mode for abbreviating store file names by replacing hash sequences of
585 symbols with ``@dots{}'':
588 /gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1
589 @result{} /gnu/store/…-foo-0.1
592 Once you set up ``guix.el'' (@pxref{Emacs Initial Setup}), the following
593 commands become available:
597 @item M-x guix-prettify-mode
598 Enable/disable prettifying for the current buffer.
600 @item M-x global-guix-prettify-mode
601 Enable/disable prettifying globally.
605 To automatically enable @code{guix-prettify-mode} globally on Emacs
606 start, add the following line to your init file:
609 (global-guix-prettify-mode)
612 If you want to enable it only for specific major modes, add it to the
613 mode hooks (@pxref{Hooks,,, emacs, The GNU Emacs Manual}), for example:
616 (add-hook 'shell-mode-hook 'guix-prettify-mode)
617 (add-hook 'dired-mode-hook 'guix-prettify-mode)
621 @node Emacs Build Log
622 @section Build Log Mode
624 GNU@tie{}Guix provides major and minor modes for highlighting build
625 logs. So when you have a file with a package build output---for
626 example, a file returned by @command{guix build --log-file @dots{}}
627 command (@pxref{Invoking guix build}), you may call @kbd{M-x
628 guix-build-log-mode} command in the buffer with this file. This major
629 mode highlights some lines specific to build output and provides the
630 following key bindings:
635 Move to the next build phase.
638 Move to the previous build phase.
641 Toggle (show/hide) the body of the current build phase.
644 Toggle (show/hide) the bodies of all build phases.
648 There is also @kbd{M-x guix-build-log-minor-mode} which also provides
649 the same highlighting and the same key bindings as the major mode, but
650 prefixed with @kbd{C-c}. By default, this minor mode is enabled in
651 shell buffers (@pxref{Interactive Shell,,, emacs, The GNU Emacs
652 Manual}). If you don't like it, set
653 @code{guix-build-log-minor-mode-activate} to nil.
656 @node Emacs Completions
657 @section Shell Completions
659 Another feature that becomes available after configuring Emacs interface
660 (@pxref{Emacs Initial Setup}) is completing of @command{guix}
661 subcommands, options, packages and other things in @code{shell}
662 (@pxref{Interactive Shell,,, emacs, The GNU Emacs Manual}) and
663 @code{eshell} (@pxref{Top,,, eshell, Eshell: The Emacs Shell}).
665 It works the same way as other completions do. Just press @key{TAB}
666 when your intuition tells you.
668 And here are some examples, where pressing @key{TAB} may complete
673 @item @code{guix pa}@key{TAB}
674 @item @code{guix package -}@key{TAB}
675 @item @code{guix package --}@key{TAB}
676 @item @code{guix package -i gei}@key{TAB}
677 @item @code{guix build -L/tm}@key{TAB}
678 @item @code{guix build --sy}@key{TAB}
679 @item @code{guix build --system=i}@key{TAB}
680 @item @code{guix system rec}@key{TAB}
681 @item @code{guix lint --checkers=sy}@key{TAB}
682 @item @code{guix lint --checkers=synopsis,des}@key{TAB}
687 @node Emacs Development
690 By default, when you open a Scheme file, @code{guix-devel-mode} will be
691 activated (if you don't want it, set @code{guix-devel-activate-mode} to
692 nil). This minor mode provides the following key bindings:
697 Copy the name of the current Guile module into kill ring
698 (@code{guix-devel-copy-module-as-kill}).
701 Use the current Guile module. Often after opening a Scheme file, you
702 want to use a module it defines, so you switch to the Geiser REPL and
703 write @code{,use (some module)} there. You may just use this command
704 instead (@code{guix-devel-use-module}).
707 Build a package defined by the current variable definition. The
708 building process is run in the current Geiser REPL. If you modified the
709 current package definition, don't forget to reevaluate it before calling
710 this command---for example, with @kbd{C-M-x} (@pxref{To eval or not to
711 eval,,, geiser, Geiser User Manual})
712 (@code{guix-devel-build-package-definition}).
715 Build a source derivation of the package defined by the current variable
716 definition. This command has the same meaning as @code{guix build -S}
717 shell command (@pxref{Invoking guix build})
718 (@code{guix-devel-build-package-source}).
721 Lint (check) a package defined by the current variable definition
722 (@pxref{Invoking guix lint}) (@code{guix-devel-lint-package}).
726 Unluckily, there is a limitation related to long-running REPL commands.
727 When there is a running process in a Geiser REPL, you are not supposed
728 to evaluate anything in a scheme buffer, because this will ``freeze''
729 the REPL: it will stop producing any output (however, the evaluating
730 process will continue---you will just not see any progress anymore). Be
731 aware: even moving the point in a scheme buffer may ``break'' the REPL
732 if Autodoc (@pxref{Autodoc and friends,,, geiser, Geiser User Manual})
733 is enabled (which is the default).
735 So you have to postpone editing your scheme buffers until the running
736 evaluation will be finished in the REPL.
738 Alternatively, to avoid this limitation, you may just run another Geiser
739 REPL, and while something is being evaluated in the previous REPL, you
740 can continue editing a scheme file with the help of the current one.