emacs: Add "View map" action to 'size' popup.
[jackhill/guix/guix.git] / doc / emacs.texi
CommitLineData
457f60fa 1@node Emacs Interface
c554de89 2@chapter Emacs Interface
457f60fa 3
bd53d327 4@cindex Emacs
c554de89
AK
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.
457f60fa
AK
8
9@menu
bd53d327 10* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
c554de89 11* Package Management: Emacs Package Management. Managing packages and generations.
9b0afb0d 12* Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
9a130e19 13* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
34850cd5 14* Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
00a8dae2 15* Completions: Emacs Completions. Completing @command{guix} shell command.
457f60fa
AK
16@end menu
17
c554de89 18
bd53d327 19@node Emacs Initial Setup
c554de89 20@section Initial Setup
457f60fa 21
80ae897f
LC
22On the Guix System Distribution (@pxref{GNU Distribution}), ``guix.el''
23is ready to use, provided Guix is installed system-wide, which is the
24case by default. So if that is what you're using, you can happily skip
25this section and read about the fun stuff.
26
ba3bcec9 27If you're not yet a happy user of GuixSD, a little bit of setup is needed.
457f60fa
AK
28To be able to use ``guix.el'', you need to install the following
29packages:
30
31@itemize
32@item
33@uref{http://www.gnu.org/software/emacs/, GNU Emacs}, version 24.3 or
34later;
35
36@item
37@uref{http://nongnu.org/geiser/, Geiser}, version 0.3 or later: it is
38used for interacting with the Guile process.
39
9b0afb0d
AK
40@item
41@uref{https://github.com/magit/magit/, magit-popup library}. You
42already have this library if you use Magit 2.1.0 or later. This library
43is an optional dependency---it is required only for @kbd{M-x@tie{}guix}
44command (@pxref{Emacs Popup Interface}).
45
457f60fa
AK
46@end itemize
47
a72f18a5
AK
48When it is done ``guix.el'' may be configured by requiring a special
49@code{guix-init} file---i.e., by adding the following code into your
50init file (@pxref{Init File,,, emacs, The GNU Emacs Manual}):
457f60fa
AK
51
52@example
a72f18a5 53(add-to-list 'load-path "/path/to/directory-with-guix.el")
457f60fa
AK
54(require 'guix-init nil t)
55@end example
56
a72f18a5
AK
57So the only thing you need to figure out is where the directory with
58elisp files for Guix is placed. It depends on how you installed Guix:
59
60@itemize
61@item
62If it was installed by a package manager of your distribution or by a
63usual @code{./configure && make && make install} command sequence, then
64elisp files are placed in a standard directory with Emacs packages
65(usually it is @file{/usr/share/emacs/site-lisp/}), which is already in
66@code{load-path}, so there is no need to add that directory there.
67
68@item
69If you used a binary installation method (@pxref{Binary Installation}),
70then Guix is installed somewhere in the store, so the elisp files are
71placed in @file{/gnu/store/@dots{}-guix-0.8.2/share/emacs/site-lisp/} or
72alike. However it is not recommended to refer directly to a store
73directory. Instead you can install Guix using Guix itself with
74@command{guix package -i guix} command (@pxref{Invoking guix package})
75and add @file{~/.guix-profile/share/emacs/site-lisp/} directory to
76@code{load-path} variable.
77
78@item
79If you did not install Guix at all and prefer a hacking way
80(@pxref{Running Guix Before It Is Installed}), along with augmenting
81@code{load-path} you need to set @code{guix-load-path} variable to the
82same directory, so your final configuration will look like this:
457f60fa
AK
83
84@example
a72f18a5
AK
85(let ((dir "/path/to/your-guix-git-tree/emacs"))
86 (add-to-list 'load-path dir)
87 (setq guix-load-path dir))
88(require 'guix-init nil t)
457f60fa 89@end example
a72f18a5 90@end itemize
457f60fa 91
a7f862e4
AK
92By default, along with autoloading (@pxref{Autoload,,, elisp, The GNU
93Emacs Lisp Reference Manual}) the main interactive commands for
94``guix.el'' (@pxref{Emacs Commands}), requiring @code{guix-init} will
95also autoload commands for the Emacs packages installed in your user
96profile.
97
98To disable automatic loading of installed Emacs packages, set
99@code{guix-package-enable-at-startup} variable to @code{nil} before
100requiring @code{guix-init}. This variable has the same meaning for
101Emacs packages installed with Guix, as @code{package-enable-at-startup}
5ec98c3d 102for the built-in Emacs package system (@pxref{Package Installation,,,
a7f862e4
AK
103emacs, The GNU Emacs Manual}).
104
105You can activate Emacs packages installed in your profile whenever you
106want using @kbd{M-x@tie{}guix-emacs-load-autoloads}.
457f60fa 107
c554de89
AK
108
109@node Emacs Package Management
110@section Package Management
457f60fa
AK
111
112Once ``guix.el'' has been successfully configured, you should be able to
c554de89
AK
113use a visual interface for routine package management tasks, pretty much
114like the @command{guix package} command (@pxref{Invoking guix package}).
115Specifically, it makes it easy to:
116
117@itemize
118@item browse and display packages and generations;
119@item search, install, upgrade and remove packages;
120@item display packages from previous generations;
121@item do some other useful things.
122@end itemize
457f60fa
AK
123
124@menu
bd53d327
AK
125* Commands: Emacs Commands. @kbd{M-x guix-@dots{}}
126* General information: Emacs General info. Common for both interfaces.
127* ``List'' buffer: Emacs List buffer. List-like interface.
128* ``Info'' buffer: Emacs Info buffer. Help-like interface.
c554de89 129* Configuration: Emacs Configuration. Configuring the interface.
457f60fa
AK
130@end menu
131
bd53d327 132@node Emacs Commands
c554de89 133@subsection Commands
457f60fa 134
23459fa5
AK
135All commands for displaying packages and generations use the current
136profile, which can be changed with
137@kbd{M-x@tie{}guix-set-current-profile}. Alternatively, if you call any
138of these commands with prefix argument (@kbd{C-u}), you will be prompted
139for a profile just for that command.
140
141Commands for displaying packages:
457f60fa
AK
142
143@table @kbd
23459fa5 144
457f60fa
AK
145@item M-x guix-all-available-packages
146@itemx M-x guix-newest-available-packages
147Display all/newest available packages.
148
149@item M-x guix-installed-packages
23459fa5 150Display all installed packages.
457f60fa
AK
151
152@item M-x guix-obsolete-packages
23459fa5
AK
153Display obsolete packages (the packages that are installed in a profile
154but cannot be found among available packages).
457f60fa
AK
155
156@item M-x guix-search-by-name
157Display package(s) with the specified name.
158
159@item M-x guix-search-by-regexp
160Search for packages by a specified regexp. By default ``name'',
161``synopsis'' and ``description'' of the packages will be searched. This
162can be changed by modifying @code{guix-search-params} variable.
163
457f60fa
AK
164@end table
165
23459fa5
AK
166By default, these commands display each output on a separate line. If
167you prefer to see a list of packages---i.e., a list with a package per
168line, use the following setting:
a54a237b
AK
169
170@example
171(setq guix-package-list-type 'package)
172@end example
173
23459fa5
AK
174Commands for displaying generations:
175
176@table @kbd
177
178@item M-x guix-generations
179List all the generations.
180
181@item M-x guix-last-generations
182List the @var{N} last generations. You will be prompted for the number
183of generations.
184
185@item M-x guix-generations-by-time
186List generations matching time period. You will be prompted for the
187period using Org mode time prompt based on Emacs calendar (@pxref{The
773bab64 188date/time prompt,,, org, The Org Manual}).
23459fa5
AK
189
190@end table
457f60fa 191
2d7bf949
AK
192You can also invoke the @command{guix pull} command (@pxref{Invoking
193guix pull}) from Emacs using:
194
195@table @kbd
196@item M-x guix-pull
197With @kbd{C-u}, make it verbose.
198@end table
199
200Once @command{guix pull} has succeeded, the Guix REPL is restared. This
201allows you to keep using the Emacs interface with the updated Guix.
202
bd53d327 203@node Emacs General info
c554de89 204@subsection General information
457f60fa
AK
205
206The following keys are available for both ``list'' and ``info'' types of
207buffers:
208
209@table @kbd
210@item l
211@itemx r
212Go backward/forward by the history of the displayed results (this
213history is similar to the history of the Emacs @code{help-mode} or
214@code{Info-mode}).
215
216@item g
217Revert current buffer: update information about the displayed
218packages/generations and redisplay it.
219
220@item R
221Redisplay current buffer (without updating information).
222
5a727cdf
AK
223@item M
224Apply manifest to the current profile or to a specified profile, if
225prefix argument is used. This has the same meaning as @code{--manifest}
226option (@pxref{Invoking guix package}).
227
457f60fa
AK
228@item C-c C-z
229Go to the Guix REPL (@pxref{The REPL,,, geiser, Geiser User Manual}).
230
231@item h
232@itemx ?
233Describe current mode to see all available bindings.
234
235@end table
236
237@emph{Hint:} If you need several ``list'' or ``info'' buffers, you can
238simlpy @kbd{M-x clone-buffer} them, and each buffer will have its own
239history.
240
241@emph{Warning:} Name/version pairs cannot be used to identify packages
242(because a name is not necessarily unique), so ``guix.el'' uses special
243identifiers that live only during a guile session, so if the Guix REPL
244was restarted, you may want to revert ``list'' buffer (by pressing
245@kbd{g}).
246
bd53d327 247@node Emacs List buffer
c554de89 248@subsection ``List'' buffer
457f60fa
AK
249
250An interface of a ``list'' buffer is similar to the interface provided
773bab64 251by ``package.el'' (@pxref{Package Menu,,, emacs, The GNU Emacs Manual}).
457f60fa
AK
252
253Default key bindings available for both ``package-list'' and
254``generation-list'' buffers:
255
256@table @kbd
257@item m
578b98da 258Mark the current entry (with prefix, mark all entries).
457f60fa 259@item u
91cc37a1 260Unmark the current entry (with prefix, unmark all entries).
457f60fa
AK
261@item @key{DEL}
262Unmark backward.
457f60fa
AK
263@item S
264Sort entries by a specified column.
265@end table
266
267A ``package-list'' buffer additionally provides the following bindings:
268
269@table @kbd
270@item @key{RET}
271Describe marked packages (display available information in a
272``package-info'' buffer).
273@item i
a54a237b 274Mark the current package for installation.
457f60fa 275@item d
a54a237b 276Mark the current package for deletion.
91cc37a1 277@item U
a54a237b 278Mark the current package for upgrading.
457f60fa 279@item ^
91cc37a1 280Mark all obsolete packages for upgrading.
6248e326
AK
281@item e
282Edit the definition of the curent package (go to its location). This is
283similar to @command{guix edit} command (@pxref{Invoking guix edit}), but
284for opening a package recipe in the current Emacs instance.
457f60fa 285@item x
a54a237b 286Execute actions on the marked packages.
457f60fa
AK
287@end table
288
289A ``generation-list'' buffer additionally provides the following
290bindings:
291
292@table @kbd
293@item @key{RET}
294List packages installed in the current generation.
295@item i
296Describe marked generations (display available information in a
297``generation-info'' buffer).
af874238
AK
298@item s
299Switch profile to the current generation.
cb6a5c71
AK
300@item d
301Mark the current generation for deletion (with prefix, mark all
302generations).
303@item x
304Execute actions on the marked generations---i.e., delete generations.
d38bd08c
AK
305@item e
306Run Ediff (@pxref{Top,,, ediff, The Ediff Manual}) on package outputs
307installed in the 2 marked generations. With prefix argument, run Ediff
308on manifests of the marked generations.
309@item D
310@itemx =
311Run Diff (@pxref{Diff Mode,,, emacs, The GNU Emacs Manual}) on package
312outputs installed in the 2 marked generations. With prefix argument,
313run Diff on manifests of the marked generations.
314@item +
315List package outputs added to the latest marked generation comparing
316with another marked generation.
317@item -
318List package outputs removed from the latest marked generation comparing
319with another marked generation.
457f60fa
AK
320@end table
321
bd53d327 322@node Emacs Info buffer
c554de89 323@subsection ``Info'' buffer
457f60fa
AK
324
325The interface of an ``info'' buffer is similar to the interface of
773bab64 326@code{help-mode} (@pxref{Help Mode,,, emacs, The GNU Emacs Manual}).
457f60fa
AK
327
328``Info'' buffer contains some buttons (as usual you may use @key{TAB} /
329@kbd{S-@key{TAB}} to move between buttons---@pxref{Mouse References,,,
773bab64 330emacs, The GNU Emacs Manual}) which can be used to:
457f60fa
AK
331
332@itemize @bullet
333@item (in a ``package-info'' buffer)
334
335@itemize @minus
336@item install/remove a package;
337@item jump to a package location;
338@item browse home page of a package;
339@item describe packages from ``Inputs'' fields.
340@end itemize
341
342@item (in a ``generation-info'' buffer)
343
344@itemize @minus
345@item remove a generation;
af874238 346@item switch to a generation;
457f60fa
AK
347@item list packages installed in a generation;
348@item jump to a generation directory.
349@end itemize
350
351@end itemize
352
56149217
AK
353It is also possible to copy a button label (a link to an URL or a file)
354by pressing @kbd{c} on a button.
355
457f60fa 356
bd53d327 357@node Emacs Configuration
457f60fa
AK
358@subsection Configuration
359
360There are many variables you can modify to change the appearance or
361behavior of Emacs user interface. Some of these variables are described
362in this section. Also you can use Custom Interface (@pxref{Easy
773bab64
AK
363Customization,,, emacs, The GNU Emacs Manual}) to explore/set variables
364(not all) and faces.
457f60fa
AK
365
366@menu
bd53d327
AK
367* Guile and Build Options: Emacs Build Options. Specifying how packages are built.
368* Buffer Names: Emacs Buffer Names. Names of Guix buffers.
369* Keymaps: Emacs Keymaps. Configuring key bindings.
370* Appearance: Emacs Appearance. Settings for visual appearance.
457f60fa
AK
371@end menu
372
bd53d327 373@node Emacs Build Options
457f60fa
AK
374@subsubsection Guile and Build Options
375
376@table @code
377@item guix-guile-program
378If you have some special needs for starting a Guile process, you may set
379this variable, for example:
380
381@example
382(setq guix-guile-program '("/bin/guile" "--no-auto-compile"))
383@end example
384
385@item guix-use-substitutes
386Has the same meaning as @code{--no-substitutes} option (@pxref{Invoking
387guix build}).
388
389@item guix-dry-run
390Has the same meaning as @code{--dry-run} option (@pxref{Invoking guix
391build}).
392
393@end table
394
bd53d327 395@node Emacs Buffer Names
a54a237b
AK
396@subsubsection Buffer Names
397
398Default names of ``guix.el'' buffers (``*Guix@tie{}@dots{}*'') may be
399changed with the following variables:
400
401@table @code
402@item guix-package-list-buffer-name
403@item guix-output-list-buffer-name
404@item guix-generation-list-buffer-name
405@item guix-package-info-buffer-name
406@item guix-output-info-buffer-name
407@item guix-generation-info-buffer-name
408@item guix-repl-buffer-name
409@item guix-internal-repl-buffer-name
a54a237b
AK
410@end table
411
23459fa5
AK
412By default, the name of a profile is also displayed in a ``list'' or
413``info'' buffer name. To change this behavior, use
414@code{guix-buffer-name-function} variable.
415
416For example, if you want to display all types of results in a single
a54a237b
AK
417buffer (in such case you will probably use a history (@kbd{l}/@kbd{r})
418extensively), you may do it like this:
419
420@example
421(let ((name "Guix Universal"))
422 (setq
423 guix-package-list-buffer-name name
424 guix-output-list-buffer-name name
425 guix-generation-list-buffer-name name
426 guix-package-info-buffer-name name
427 guix-output-info-buffer-name name
23459fa5
AK
428 guix-generation-info-buffer-name name
429 guix-buffer-name-function #'guix-buffer-name-simple))
a54a237b
AK
430@end example
431
bd53d327 432@node Emacs Keymaps
457f60fa
AK
433@subsubsection Keymaps
434
435If you want to change default key bindings, use the following keymaps
773bab64 436(@pxref{Init Rebinding,,, emacs, The GNU Emacs Manual}):
457f60fa
AK
437
438@table @code
74cc6737
AK
439@item guix-root-map
440Parent keymap with general keys for all guix modes.
441
457f60fa
AK
442@item guix-list-mode-map
443Parent keymap with general keys for ``list'' buffers.
444
445@item guix-package-list-mode-map
446Keymap with specific keys for ``package-list'' buffers.
447
a54a237b
AK
448@item guix-output-list-mode-map
449Keymap with specific keys for ``output-list'' buffers.
450
457f60fa
AK
451@item guix-generation-list-mode-map
452Keymap with specific keys for ``generation-list'' buffers.
453
454@item guix-info-mode-map
455Parent keymap with general keys for ``info'' buffers.
456
457@item guix-package-info-mode-map
458Keymap with specific keys for ``package-info'' buffers.
459
a54a237b
AK
460@item guix-output-info-mode-map
461Keymap with specific keys for ``output-info'' buffers.
462
457f60fa
AK
463@item guix-generation-info-mode-map
464Keymap with specific keys for ``generation-info'' buffers.
465
56149217
AK
466@item guix-info-button-map
467Keymap with keys available when a point is placed on a button.
468
457f60fa
AK
469@end table
470
bd53d327 471@node Emacs Appearance
457f60fa
AK
472@subsubsection Appearance
473
474You can change almost any aspect of ``list'' / ``info'' buffers using
475the following variables:
476
477@table @code
478@item guix-list-column-format
479@itemx guix-list-column-titles
480@itemx guix-list-column-value-methods
481Specify the columns, their names, what and how is displayed in ``list''
482buffers.
483
484@item guix-info-displayed-params
485@itemx guix-info-insert-methods
486@itemx guix-info-ignore-empty-vals
487@itemx guix-info-param-title-format
488@itemx guix-info-multiline-prefix
489@itemx guix-info-indent
490@itemx guix-info-fill-column
491@itemx guix-info-delimiter
492Various settings for ``info'' buffers.
493
494@end table
9a130e19
AK
495
496
9b0afb0d
AK
497@node Emacs Popup Interface
498@section Popup Interface
499
500If you ever used Magit, you know what ``popup interface'' is
501(@pxref{Top,,, magit-popup, Magit-Popup User Manual}). Even if you are
502not acquainted with Magit, there should be no worries as it is very
503intuitive.
504
505So @kbd{M-x@tie{}guix} command provides a top-level popup interface for
506all available guix commands. When you select an option, you'll be
507prompted for a value in the minibuffer. Many values have completions,
508so don't hesitate to press @key{TAB} key. Multiple values (for example,
509packages or lint checkers) should be separated by commas.
510
511After specifying all options and switches for a command, you may choose
512one of the available actions. The following default actions are
513available for all commands:
514
515@itemize
516
517@item
518Run the command in the Guix REPL. It is faster than running
519@code{guix@tie{}@dots{}} command directly in shell, as there is no
520need to run another guile process and to load required modules there.
521
522@item
523Run the command in a shell buffer. You can set
524@code{guix-run-in-shell-function} variable to fine tune the shell buffer
525you want to use.
526
527@item
528Add the command line to the kill ring (@pxref{Kill Ring,,, emacs, The
529GNU Emacs Manual}).
530
531@end itemize
532
533
9a130e19 534@node Emacs Prettify
c554de89 535@section Guix Prettify Mode
9a130e19 536
c554de89
AK
537GNU@tie{}Guix also comes with ``guix-prettify.el''. It provides a minor
538mode for abbreviating store file names by replacing hash sequences of
539symbols with ``@dots{}'':
9a130e19
AK
540
541@example
542/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1
543@result{} /gnu/store/…-foo-0.1
544@end example
545
546Once you set up ``guix.el'' (@pxref{Emacs Initial Setup}), the following
547commands become available:
548
549@table @kbd
550
551@item M-x guix-prettify-mode
552Enable/disable prettifying for the current buffer.
553
554@item M-x global-guix-prettify-mode
555Enable/disable prettifying globally.
556
557@end table
558
559To automatically enable @code{guix-prettify-mode} globally on Emacs
560start, add the following line to your init file:
561
562@example
563(global-guix-prettify-mode)
564@end example
565
566If you want to enable it only for specific major modes, add it to the
567mode hooks (@pxref{Hooks,,, emacs, The GNU Emacs Manual}), for example:
568
569@example
570(add-hook 'shell-mode-hook 'guix-prettify-mode)
571(add-hook 'dired-mode-hook 'guix-prettify-mode)
572@end example
00a8dae2
AK
573
574
34850cd5
AK
575@node Emacs Build Log
576@section Build Log Mode
577
578GNU@tie{}Guix provides major and minor modes for highlighting build
579logs. So when you have a file with a package build output---for
580example, a file returned by @command{guix build --log-file @dots{}}
581command (@pxref{Invoking guix build}), you may call @kbd{M-x
582guix-build-log-mode} command in the buffer with this file. This major
583mode highlights some lines specific to build output and provides the
584following key bindings:
585
586@table @kbd
587
588@item M-n
589Move to the next build phase.
590
591@item M-p
592Move to the previous build phase.
593
eda1cc8b
AK
594@item @key{TAB}
595Toggle (show/hide) the body of the current build phase.
596
597@item S-@key{TAB}
598Toggle (show/hide) the bodies of all build phases.
599
34850cd5
AK
600@end table
601
602There is also @kbd{M-x guix-build-log-minor-mode} which also provides
603the same highlighting (but not key bindings). And as it is a minor
604mode, it can be enabled in any buffer. For example, if you are building
605some package in a shell buffer (@pxref{Interactive Shell,,, emacs, The
606GNU Emacs Manual}), you may enable @command{guix-build-log-minor-mode}
607to make it more colorful. Guix build output is rather specific, so this
608new highlighting shouldn't conflict with the existing one.
609
610
00a8dae2 611@node Emacs Completions
c554de89 612@section Shell Completions
00a8dae2
AK
613
614Another feature that becomes available after configuring Emacs interface
615(@pxref{Emacs Initial Setup}) is completing of @command{guix}
616subcommands, options, packages and other things in @code{shell}
617(@pxref{Interactive Shell,,, emacs, The GNU Emacs Manual}) and
618@code{eshell} (@pxref{Top,,, eshell, Eshell: The Emacs Shell}).
619
620It works the same way as other completions do. Just press @key{TAB}
621when your intuition tells you.
622
623And here are some examples, where pressing @key{TAB} may complete
624something:
625
626@itemize @w{}
627
628@item @code{guix pa}@key{TAB}
629@item @code{guix package -}@key{TAB}
630@item @code{guix package --}@key{TAB}
631@item @code{guix package -i gei}@key{TAB}
632@item @code{guix build -L/tm}@key{TAB}
633@item @code{guix build --sy}@key{TAB}
634@item @code{guix build --system=i}@key{TAB}
635@item @code{guix system rec}@key{TAB}
636@item @code{guix lint --checkers=sy}@key{TAB}
637@item @code{guix lint --checkers=synopsis,des}@key{TAB}
638
639@end itemize