emacs: Factorize macros for defining interfaces.
[jackhill/guix/guix.git] / doc / emacs.texi
... / ...
CommitLineData
1@node Emacs Interface
2@chapter Emacs Interface
3
4@cindex Emacs
5GNU Guix comes with several useful modules (known as ``guix.el'') for
6GNU@tie{}Emacs which are intended to make an Emacs user interaction with
7Guix convenient and fun.
8
9@menu
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.
17@end menu
18
19
20@node Emacs Initial Setup
21@section Initial Setup
22
23On the Guix System Distribution (@pxref{GNU Distribution}), ``guix.el''
24is ready to use, provided Guix is installed system-wide, which is the
25case by default. So if that is what you're using, you can happily skip
26this section and read about the fun stuff.
27
28If you're not yet a happy user of GuixSD, a little bit of setup is needed.
29To be able to use ``guix.el'', you need to install the following
30packages:
31
32@itemize
33@item
34@uref{http://www.gnu.org/software/emacs/, GNU Emacs}, version 24.3 or
35later;
36
37@item
38@uref{http://nongnu.org/geiser/, Geiser}, version 0.3 or later: it is
39used for interacting with the Guile process.
40
41@item
42@uref{https://github.com/magit/magit/, magit-popup library}. You
43already have this library if you use Magit 2.1.0 or later. This library
44is an optional dependency---it is required only for @kbd{M-x@tie{}guix}
45command (@pxref{Emacs Popup Interface}).
46
47@end itemize
48
49When 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
51init file (@pxref{Init File,,, emacs, The GNU Emacs Manual}):
52
53@example
54(add-to-list 'load-path "/path/to/directory-with-guix.el")
55(require 'guix-init nil t)
56@end example
57
58So the only thing you need to figure out is where the directory with
59elisp files for Guix is placed. It depends on how you installed Guix:
60
61@itemize
62@item
63If it was installed by a package manager of your distribution or by a
64usual @code{./configure && make && make install} command sequence, then
65elisp 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.
68
69@item
70If you used a binary installation method (@pxref{Binary Installation}),
71then Guix is installed somewhere in the store, so the elisp files are
72placed in @file{/gnu/store/@dots{}-guix-0.8.2/share/emacs/site-lisp/} or
73alike. However it is not recommended to refer directly to a store
74directory. Instead you can install Guix using Guix itself with
75@command{guix package -i guix} command (@pxref{Invoking guix package})
76and add @file{~/.guix-profile/share/emacs/site-lisp/} directory to
77@code{load-path} variable.
78
79@item
80If 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
83same directory, so your final configuration will look like this:
84
85@example
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)
90@end example
91@end itemize
92
93By default, along with autoloading (@pxref{Autoload,,, elisp, The GNU
94Emacs Lisp Reference Manual}) the main interactive commands for
95``guix.el'' (@pxref{Emacs Commands}), requiring @code{guix-init} will
96also autoload commands for the Emacs packages installed in your user
97profile.
98
99To disable automatic loading of installed Emacs packages, set
100@code{guix-package-enable-at-startup} variable to @code{nil} before
101requiring @code{guix-init}. This variable has the same meaning for
102Emacs packages installed with Guix, as @code{package-enable-at-startup}
103for the built-in Emacs package system (@pxref{Package Installation,,,
104emacs, The GNU Emacs Manual}).
105
106You can activate Emacs packages installed in your profile whenever you
107want using @kbd{M-x@tie{}guix-emacs-load-autoloads}.
108
109
110@node Emacs Package Management
111@section Package Management
112
113Once ``guix.el'' has been successfully configured, you should be able to
114use a visual interface for routine package management tasks, pretty much
115like the @command{guix package} command (@pxref{Invoking guix package}).
116Specifically, it makes it easy to:
117
118@itemize
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.
123@end itemize
124
125@menu
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.
131@end menu
132
133@node Emacs Commands
134@subsection Commands
135
136All commands for displaying packages and generations use the current
137profile, which can be changed with
138@kbd{M-x@tie{}guix-set-current-profile}. Alternatively, if you call any
139of these commands with prefix argument (@kbd{C-u}), you will be prompted
140for a profile just for that command.
141
142Commands for displaying packages:
143
144@table @kbd
145
146@item M-x guix-all-available-packages
147@itemx M-x guix-newest-available-packages
148Display all/newest available packages.
149
150@item M-x guix-installed-packages
151Display all installed packages.
152
153@item M-x guix-obsolete-packages
154Display obsolete packages (the packages that are installed in a profile
155but cannot be found among available packages).
156
157@item M-x guix-search-by-name
158Display package(s) with the specified name.
159
160@item M-x guix-search-by-regexp
161Search for packages by a specified regexp. By default ``name'',
162``synopsis'' and ``description'' of the packages will be searched. This
163can be changed by modifying @code{guix-search-params} variable.
164
165@end table
166
167By default, these commands display each output on a separate line. If
168you prefer to see a list of packages---i.e., a list with a package per
169line, use the following setting:
170
171@example
172(setq guix-package-list-type 'package)
173@end example
174
175Commands for displaying generations:
176
177@table @kbd
178
179@item M-x guix-generations
180List all the generations.
181
182@item M-x guix-last-generations
183List the @var{N} last generations. You will be prompted for the number
184of generations.
185
186@item M-x guix-generations-by-time
187List generations matching time period. You will be prompted for the
188period using Org mode time prompt based on Emacs calendar (@pxref{The
189date/time prompt,,, org, The Org Manual}).
190
191@end table
192
193You can also invoke the @command{guix pull} command (@pxref{Invoking
194guix pull}) from Emacs using:
195
196@table @kbd
197@item M-x guix-pull
198With @kbd{C-u}, make it verbose.
199@end table
200
201Once @command{guix pull} has succeeded, the Guix REPL is restared. This
202allows you to keep using the Emacs interface with the updated Guix.
203
204@node Emacs General info
205@subsection General information
206
207The following keys are available for both ``list'' and ``info'' types of
208buffers:
209
210@table @kbd
211@item l
212@itemx r
213Go backward/forward by the history of the displayed results (this
214history is similar to the history of the Emacs @code{help-mode} or
215@code{Info-mode}).
216
217@item g
218Revert current buffer: update information about the displayed
219packages/generations and redisplay it.
220
221@item R
222Redisplay current buffer (without updating information).
223
224@item M
225Apply manifest to the current profile or to a specified profile, if
226prefix argument is used. This has the same meaning as @code{--manifest}
227option (@pxref{Invoking guix package}).
228
229@item C-c C-z
230@cindex REPL
231@cindex read-eval-print loop
232Go to the Guix REPL (@pxref{The REPL,,, geiser, Geiser User Manual}).
233
234@item h
235@itemx ?
236Describe current mode to see all available bindings.
237
238@end table
239
240@emph{Hint:} If you need several ``list'' or ``info'' buffers, you can
241simlpy @kbd{M-x clone-buffer} them, and each buffer will have its own
242history.
243
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
246identifiers that live only during a guile session, so if the Guix REPL
247was restarted, you may want to revert ``list'' buffer (by pressing
248@kbd{g}).
249
250@node Emacs List buffer
251@subsection ``List'' buffer
252
253An interface of a ``list'' buffer is similar to the interface provided
254by ``package.el'' (@pxref{Package Menu,,, emacs, The GNU Emacs Manual}).
255
256Default key bindings available for both ``package-list'' and
257``generation-list'' buffers:
258
259@table @kbd
260@item m
261Mark the current entry (with prefix, mark all entries).
262@item u
263Unmark the current entry (with prefix, unmark all entries).
264@item @key{DEL}
265Unmark backward.
266@item S
267Sort entries by a specified column.
268@end table
269
270A ``package-list'' buffer additionally provides the following bindings:
271
272@table @kbd
273@item @key{RET}
274Describe marked packages (display available information in a
275``package-info'' buffer).
276@item i
277Mark the current package for installation.
278@item d
279Mark the current package for deletion.
280@item U
281Mark the current package for upgrading.
282@item ^
283Mark all obsolete packages for upgrading.
284@item e
285Edit the definition of the curent package (go to its location). This is
286similar to @command{guix edit} command (@pxref{Invoking guix edit}), but
287for opening a package recipe in the current Emacs instance.
288@item x
289Execute actions on the marked packages.
290@end table
291
292A ``generation-list'' buffer additionally provides the following
293bindings:
294
295@table @kbd
296@item @key{RET}
297List packages installed in the current generation.
298@item i
299Describe marked generations (display available information in a
300``generation-info'' buffer).
301@item s
302Switch profile to the current generation.
303@item d
304Mark the current generation for deletion (with prefix, mark all
305generations).
306@item x
307Execute actions on the marked generations---i.e., delete generations.
308@item e
309Run Ediff (@pxref{Top,,, ediff, The Ediff Manual}) on package outputs
310installed in the 2 marked generations. With prefix argument, run Ediff
311on manifests of the marked generations.
312@item D
313@itemx =
314Run Diff (@pxref{Diff Mode,,, emacs, The GNU Emacs Manual}) on package
315outputs installed in the 2 marked generations. With prefix argument,
316run Diff on manifests of the marked generations.
317@item +
318List package outputs added to the latest marked generation comparing
319with another marked generation.
320@item -
321List package outputs removed from the latest marked generation comparing
322with another marked generation.
323@end table
324
325@node Emacs Info buffer
326@subsection ``Info'' buffer
327
328The interface of an ``info'' buffer is similar to the interface of
329@code{help-mode} (@pxref{Help Mode,,, emacs, The GNU Emacs Manual}).
330
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,,,
333emacs, The GNU Emacs Manual}) which can be used to:
334
335@itemize @bullet
336@item (in a ``package-info'' buffer)
337
338@itemize @minus
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.
343@end itemize
344
345@item (in a ``generation-info'' buffer)
346
347@itemize @minus
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.
352@end itemize
353
354@end itemize
355
356It is also possible to copy a button label (a link to an URL or a file)
357by pressing @kbd{c} on a button.
358
359
360@node Emacs Configuration
361@subsection Configuration
362
363There are many variables you can modify to change the appearance or
364behavior of Emacs user interface. Some of these variables are described
365in this section. Also you can use Custom Interface (@pxref{Easy
366Customization,,, emacs, The GNU Emacs Manual}) to explore/set variables
367(not all) and faces.
368
369@menu
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.
374@end menu
375
376@node Emacs Build Options
377@subsubsection Guile and Build Options
378
379@table @code
380@item guix-guile-program
381If you have some special needs for starting a Guile process, you may set
382this variable, for example:
383
384@example
385(setq guix-guile-program '("/bin/guile" "--no-auto-compile"))
386@end example
387
388@item guix-use-substitutes
389Has the same meaning as @code{--no-substitutes} option (@pxref{Invoking
390guix build}).
391
392@item guix-dry-run
393Has the same meaning as @code{--dry-run} option (@pxref{Invoking guix
394build}).
395
396@end table
397
398@node Emacs Buffer Names
399@subsubsection Buffer Names
400
401Default names of ``guix.el'' buffers (``*Guix@tie{}@dots{}*'') may be
402changed with the following variables:
403
404@table @code
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
413@end table
414
415By 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.
418
419For example, if you want to display all types of results in a single
420buffer (in such case you will probably use a history (@kbd{l}/@kbd{r})
421extensively), you may do it like this:
422
423@example
424(let ((name "Guix Universal"))
425 (setq
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))
433@end example
434
435@node Emacs Keymaps
436@subsubsection Keymaps
437
438If you want to change default key bindings, use the following keymaps
439(@pxref{Init Rebinding,,, emacs, The GNU Emacs Manual}):
440
441@table @code
442@item guix-root-map
443Parent keymap with general keys for all guix modes.
444
445@item guix-list-mode-map
446Parent keymap with general keys for ``list'' buffers.
447
448@item guix-package-list-mode-map
449Keymap with specific keys for ``package-list'' buffers.
450
451@item guix-output-list-mode-map
452Keymap with specific keys for ``output-list'' buffers.
453
454@item guix-generation-list-mode-map
455Keymap with specific keys for ``generation-list'' buffers.
456
457@item guix-info-mode-map
458Parent keymap with general keys for ``info'' buffers.
459
460@item guix-package-info-mode-map
461Keymap with specific keys for ``package-info'' buffers.
462
463@item guix-output-info-mode-map
464Keymap with specific keys for ``output-info'' buffers.
465
466@item guix-generation-info-mode-map
467Keymap with specific keys for ``generation-info'' buffers.
468
469@item guix-info-button-map
470Keymap with keys available when a point is placed on a button.
471
472@end table
473
474@node Emacs Appearance
475@subsubsection Appearance
476
477You can change almost any aspect of ``list'' / ``info'' buffers using
478the following variables (@dfn{ENTRY-TYPE} means @code{package},
479@code{output} or @code{generation}):
480
481@table @code
482@item guix-ENTRY-TYPE-list-format
483@itemx guix-list-column-titles
484Specify the columns, their names, what and how is displayed in ``list''
485buffers.
486
487@item guix-info-format
488@itemx guix-info-ignore-empty-values
489@itemx guix-info-param-title-format
490@itemx guix-info-multiline-prefix
491@itemx guix-info-indent
492@itemx guix-info-fill
493@itemx guix-info-delimiter
494Various settings for ``info'' buffers.
495
496@end table
497
498
499@node Emacs Popup Interface
500@section Popup Interface
501
502If you ever used Magit, you know what ``popup interface'' is
503(@pxref{Top,,, magit-popup, Magit-Popup User Manual}). Even if you are
504not acquainted with Magit, there should be no worries as it is very
505intuitive.
506
507So @kbd{M-x@tie{}guix} command provides a top-level popup interface for
508all available guix commands. When you select an option, you'll be
509prompted for a value in the minibuffer. Many values have completions,
510so don't hesitate to press @key{TAB} key. Multiple values (for example,
511packages or lint checkers) should be separated by commas.
512
513After specifying all options and switches for a command, you may choose
514one of the available actions. The following default actions are
515available for all commands:
516
517@itemize
518
519@item
520Run the command in the Guix REPL. It is faster than running
521@code{guix@tie{}@dots{}} command directly in shell, as there is no
522need to run another guile process and to load required modules there.
523
524@item
525Run the command in a shell buffer. You can set
526@code{guix-run-in-shell-function} variable to fine tune the shell buffer
527you want to use.
528
529@item
530Add the command line to the kill ring (@pxref{Kill Ring,,, emacs, The
531GNU Emacs Manual}).
532
533@end itemize
534
535Several commands (@command{guix graph}, @command{guix system dmd-graph}
536and @command{guix system extension-graph}) also have a ``View graph''
537action, which allows you to view a generated graph using @command{dot}
538command (specified by @code{guix-dot-program} variable). By default a
539PNG file will be saved in @file{/tmp} directory and will be opened
540directly in Emacs. This behavior may be changed with the following
541variables:
542
543@table @code
544
545@item guix-find-file-function
546Function used to open a generated graph. If you want to open a graph in
547an external program, you can do it by modifying this variable---for
548example, you can use a functionality provided by the Org Mode
549(@pxref{Top,,, org, The Org Manual}):
550
551@example
552(setq guix-find-file-function 'org-open-file)
553(add-to-list 'org-file-apps '("\\.png\\'" . "sxiv %s"))
554@end example
555
556@item guix-dot-default-arguments
557Command line arguments to run @command{dot} command. If you change an
558output format (for example, into @code{-Tpdf}), you also need to change
559the next variable.
560
561@item guix-dot-file-name-function
562Function used to define a name of the generated graph file. Default
563name is @file{/tmp/guix-emacs-graph-XXXXXX.png}.
564
565@end table
566
567So, for example, if you want to generate and open a PDF file in your
568Emacs, you may change the settings like this:
569
570@example
571(defun my-guix-pdf-graph ()
572 "/tmp/my-current-guix-graph.pdf")
573
574(setq guix-dot-default-arguments '("-Tpdf")
575 guix-dot-file-name-function 'my-guix-pdf-graph)
576@end example
577
578
579@node Emacs Prettify
580@section Guix Prettify Mode
581
582GNU@tie{}Guix also comes with ``guix-prettify.el''. It provides a minor
583mode for abbreviating store file names by replacing hash sequences of
584symbols with ``@dots{}'':
585
586@example
587/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1
588@result{} /gnu/store/…-foo-0.1
589@end example
590
591Once you set up ``guix.el'' (@pxref{Emacs Initial Setup}), the following
592commands become available:
593
594@table @kbd
595
596@item M-x guix-prettify-mode
597Enable/disable prettifying for the current buffer.
598
599@item M-x global-guix-prettify-mode
600Enable/disable prettifying globally.
601
602@end table
603
604To automatically enable @code{guix-prettify-mode} globally on Emacs
605start, add the following line to your init file:
606
607@example
608(global-guix-prettify-mode)
609@end example
610
611If you want to enable it only for specific major modes, add it to the
612mode hooks (@pxref{Hooks,,, emacs, The GNU Emacs Manual}), for example:
613
614@example
615(add-hook 'shell-mode-hook 'guix-prettify-mode)
616(add-hook 'dired-mode-hook 'guix-prettify-mode)
617@end example
618
619
620@node Emacs Build Log
621@section Build Log Mode
622
623GNU@tie{}Guix provides major and minor modes for highlighting build
624logs. So when you have a file with a package build output---for
625example, a file returned by @command{guix build --log-file @dots{}}
626command (@pxref{Invoking guix build}), you may call @kbd{M-x
627guix-build-log-mode} command in the buffer with this file. This major
628mode highlights some lines specific to build output and provides the
629following key bindings:
630
631@table @kbd
632
633@item M-n
634Move to the next build phase.
635
636@item M-p
637Move to the previous build phase.
638
639@item @key{TAB}
640Toggle (show/hide) the body of the current build phase.
641
642@item S-@key{TAB}
643Toggle (show/hide) the bodies of all build phases.
644
645@end table
646
647There is also @kbd{M-x guix-build-log-minor-mode} which also provides
648the same highlighting and the same key bindings as the major mode, but
649prefixed with @kbd{C-c}. By default, this minor mode is enabled in
650shell buffers (@pxref{Interactive Shell,,, emacs, The GNU Emacs
651Manual}). If you don't like it, set
652@code{guix-build-log-minor-mode-activate} to nil.
653
654
655@node Emacs Completions
656@section Shell Completions
657
658Another feature that becomes available after configuring Emacs interface
659(@pxref{Emacs Initial Setup}) is completing of @command{guix}
660subcommands, options, packages and other things in @code{shell}
661(@pxref{Interactive Shell,,, emacs, The GNU Emacs Manual}) and
662@code{eshell} (@pxref{Top,,, eshell, Eshell: The Emacs Shell}).
663
664It works the same way as other completions do. Just press @key{TAB}
665when your intuition tells you.
666
667And here are some examples, where pressing @key{TAB} may complete
668something:
669
670@itemize @w{}
671
672@item @code{guix pa}@key{TAB}
673@item @code{guix package -}@key{TAB}
674@item @code{guix package --}@key{TAB}
675@item @code{guix package -i gei}@key{TAB}
676@item @code{guix build -L/tm}@key{TAB}
677@item @code{guix build --sy}@key{TAB}
678@item @code{guix build --system=i}@key{TAB}
679@item @code{guix system rec}@key{TAB}
680@item @code{guix lint --checkers=sy}@key{TAB}
681@item @code{guix lint --checkers=synopsis,des}@key{TAB}
682
683@end itemize
684
685
686@node Emacs Development
687@section Development
688
689By default, when you open a Scheme file, @code{guix-devel-mode} will be
690activated (if you don't want it, set @code{guix-devel-activate-mode} to
691nil). This minor mode provides the following key bindings:
692
693@table @kbd
694
695@item C-c . k
696Copy the name of the current Guile module into kill ring
697(@code{guix-devel-copy-module-as-kill}).
698
699@item C-c . u
700Use the current Guile module. Often after opening a Scheme file, you
701want to use a module it defines, so you switch to the Geiser REPL and
702write @code{,use (some module)} there. You may just use this command
703instead (@code{guix-devel-use-module}).
704
705@item C-c . b
706Build a package defined by the current variable definition. The
707building process is run in the current Geiser REPL. If you modified the
708current package definition, don't forget to reevaluate it before calling
709this command---for example, with @kbd{C-M-x} (@pxref{To eval or not to
710eval,,, geiser, Geiser User Manual})
711(@code{guix-devel-build-package-definition}).
712
713@item C-c . s
714Build a source derivation of the package defined by the current variable
715definition. This command has the same meaning as @code{guix build -S}
716shell command (@pxref{Invoking guix build})
717(@code{guix-devel-build-package-source}).
718
719@item C-c . l
720Lint (check) a package defined by the current variable definition
721(@pxref{Invoking guix lint}) (@code{guix-devel-lint-package}).
722
723@end table
724
725Unluckily, there is a limitation related to long-running REPL commands.
726When there is a running process in a Geiser REPL, you are not supposed
727to evaluate anything in a scheme buffer, because this will ``freeze''
728the REPL: it will stop producing any output (however, the evaluating
729process will continue---you will just not see any progress anymore). Be
730aware: even moving the point in a scheme buffer may ``break'' the REPL
731if Autodoc (@pxref{Autodoc and friends,,, geiser, Geiser User Manual})
732is enabled (which is the default).
733
734So you have to postpone editing your scheme buffers until the running
735evaluation will be finished in the REPL.
736
737Alternatively, to avoid this limitation, you may just run another Geiser
738REPL, and while something is being evaluated in the previous REPL, you
739can continue editing a scheme file with the help of the current one.