emacs: Add "memoization" code.
[jackhill/guix/guix.git] / doc / emacs.texi
CommitLineData
457f60fa
AK
1@node Emacs Interface
2@section Emacs Interface
3
bd53d327 4@cindex Emacs
457f60fa
AK
5GNU Guix comes with a visual user interface for GNU@tie{}Emacs, known
6as ``guix.el''. It can be used for routine package management tasks,
7pretty much like the @command{guix package} command (@pxref{Invoking
8guix package}). Specifically, ``guix.el'' makes it easy to:
9
10@itemize
11@item browse and display packages and generations;
12@item search, install, upgrade and remove packages;
13@item display packages from previous generations;
14@item do some other useful things.
15@end itemize
16
17@menu
bd53d327
AK
18* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
19* Usage: Emacs Usage. Using the interface.
20* Configuration: Emacs Configuration. Configuring the interface.
9a130e19 21* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
457f60fa
AK
22@end menu
23
bd53d327 24@node Emacs Initial Setup
457f60fa
AK
25@subsection Initial Setup
26
80ae897f
LC
27On the Guix System Distribution (@pxref{GNU Distribution}), ``guix.el''
28is ready to use, provided Guix is installed system-wide, which is the
29case by default. So if that is what you're using, you can happily skip
30this section and read about the fun stuff.
31
ba3bcec9 32If you're not yet a happy user of GuixSD, a little bit of setup is needed.
457f60fa
AK
33To be able to use ``guix.el'', you need to install the following
34packages:
35
36@itemize
37@item
38@uref{http://www.gnu.org/software/emacs/, GNU Emacs}, version 24.3 or
39later;
40
41@item
42@uref{http://nongnu.org/geiser/, Geiser}, version 0.3 or later: it is
43used for interacting with the Guile process.
44
45@end itemize
46
47When it is done, add the following into your init file (@pxref{Init
773bab64 48File,,, emacs, The GNU Emacs Manual}):
457f60fa
AK
49
50@example
51(require 'guix-init nil t)
52@end example
53
54However there is a chance that @code{load-path} of your Emacs does not
55contain a directory with ``guix.el'' (usually it is
56@file{/usr/share/emacs/site-lisp/}). In that case you need to add it
773bab64
AK
57before requiring (@pxref{Lisp Libraries,,, emacs, The GNU Emacs
58Manual}):
457f60fa
AK
59
60@example
61(add-to-list 'load-path "/path/to/directory-with-guix.el")
62(require 'guix-init)
63@end example
64
a7f862e4
AK
65By default, along with autoloading (@pxref{Autoload,,, elisp, The GNU
66Emacs Lisp Reference Manual}) the main interactive commands for
67``guix.el'' (@pxref{Emacs Commands}), requiring @code{guix-init} will
68also autoload commands for the Emacs packages installed in your user
69profile.
70
71To disable automatic loading of installed Emacs packages, set
72@code{guix-package-enable-at-startup} variable to @code{nil} before
73requiring @code{guix-init}. This variable has the same meaning for
74Emacs packages installed with Guix, as @code{package-enable-at-startup}
5ec98c3d 75for the built-in Emacs package system (@pxref{Package Installation,,,
a7f862e4
AK
76emacs, The GNU Emacs Manual}).
77
78You can activate Emacs packages installed in your profile whenever you
79want using @kbd{M-x@tie{}guix-emacs-load-autoloads}.
457f60fa 80
bd53d327 81@node Emacs Usage
457f60fa
AK
82@subsection Usage
83
84Once ``guix.el'' has been successfully configured, you should be able to
85use commands for displaying packages and generations. This information
86can be displayed in a ``list'' or ``info'' buffer.
87
88@menu
bd53d327
AK
89* Commands: Emacs Commands. @kbd{M-x guix-@dots{}}
90* General information: Emacs General info. Common for both interfaces.
91* ``List'' buffer: Emacs List buffer. List-like interface.
92* ``Info'' buffer: Emacs Info buffer. Help-like interface.
457f60fa
AK
93@end menu
94
bd53d327 95@node Emacs Commands
457f60fa
AK
96@subsubsection Commands
97
23459fa5
AK
98All commands for displaying packages and generations use the current
99profile, which can be changed with
100@kbd{M-x@tie{}guix-set-current-profile}. Alternatively, if you call any
101of these commands with prefix argument (@kbd{C-u}), you will be prompted
102for a profile just for that command.
103
104Commands for displaying packages:
457f60fa
AK
105
106@table @kbd
23459fa5 107
457f60fa
AK
108@item M-x guix-all-available-packages
109@itemx M-x guix-newest-available-packages
110Display all/newest available packages.
111
112@item M-x guix-installed-packages
23459fa5 113Display all installed packages.
457f60fa
AK
114
115@item M-x guix-obsolete-packages
23459fa5
AK
116Display obsolete packages (the packages that are installed in a profile
117but cannot be found among available packages).
457f60fa
AK
118
119@item M-x guix-search-by-name
120Display package(s) with the specified name.
121
122@item M-x guix-search-by-regexp
123Search for packages by a specified regexp. By default ``name'',
124``synopsis'' and ``description'' of the packages will be searched. This
125can be changed by modifying @code{guix-search-params} variable.
126
457f60fa
AK
127@end table
128
23459fa5
AK
129By default, these commands display each output on a separate line. If
130you prefer to see a list of packages---i.e., a list with a package per
131line, use the following setting:
a54a237b
AK
132
133@example
134(setq guix-package-list-type 'package)
135@end example
136
23459fa5
AK
137Commands for displaying generations:
138
139@table @kbd
140
141@item M-x guix-generations
142List all the generations.
143
144@item M-x guix-last-generations
145List the @var{N} last generations. You will be prompted for the number
146of generations.
147
148@item M-x guix-generations-by-time
149List generations matching time period. You will be prompted for the
150period using Org mode time prompt based on Emacs calendar (@pxref{The
773bab64 151date/time prompt,,, org, The Org Manual}).
23459fa5
AK
152
153@end table
457f60fa 154
2d7bf949
AK
155You can also invoke the @command{guix pull} command (@pxref{Invoking
156guix pull}) from Emacs using:
157
158@table @kbd
159@item M-x guix-pull
160With @kbd{C-u}, make it verbose.
161@end table
162
163Once @command{guix pull} has succeeded, the Guix REPL is restared. This
164allows you to keep using the Emacs interface with the updated Guix.
165
bd53d327 166@node Emacs General info
457f60fa
AK
167@subsubsection General information
168
169The following keys are available for both ``list'' and ``info'' types of
170buffers:
171
172@table @kbd
173@item l
174@itemx r
175Go backward/forward by the history of the displayed results (this
176history is similar to the history of the Emacs @code{help-mode} or
177@code{Info-mode}).
178
179@item g
180Revert current buffer: update information about the displayed
181packages/generations and redisplay it.
182
183@item R
184Redisplay current buffer (without updating information).
185
5a727cdf
AK
186@item M
187Apply manifest to the current profile or to a specified profile, if
188prefix argument is used. This has the same meaning as @code{--manifest}
189option (@pxref{Invoking guix package}).
190
457f60fa
AK
191@item C-c C-z
192Go to the Guix REPL (@pxref{The REPL,,, geiser, Geiser User Manual}).
193
194@item h
195@itemx ?
196Describe current mode to see all available bindings.
197
198@end table
199
200@emph{Hint:} If you need several ``list'' or ``info'' buffers, you can
201simlpy @kbd{M-x clone-buffer} them, and each buffer will have its own
202history.
203
204@emph{Warning:} Name/version pairs cannot be used to identify packages
205(because a name is not necessarily unique), so ``guix.el'' uses special
206identifiers that live only during a guile session, so if the Guix REPL
207was restarted, you may want to revert ``list'' buffer (by pressing
208@kbd{g}).
209
bd53d327 210@node Emacs List buffer
457f60fa
AK
211@subsubsection ``List'' buffer
212
213An interface of a ``list'' buffer is similar to the interface provided
773bab64 214by ``package.el'' (@pxref{Package Menu,,, emacs, The GNU Emacs Manual}).
457f60fa
AK
215
216Default key bindings available for both ``package-list'' and
217``generation-list'' buffers:
218
219@table @kbd
220@item m
578b98da 221Mark the current entry (with prefix, mark all entries).
457f60fa 222@item u
91cc37a1 223Unmark the current entry (with prefix, unmark all entries).
457f60fa
AK
224@item @key{DEL}
225Unmark backward.
457f60fa
AK
226@item S
227Sort entries by a specified column.
228@end table
229
230A ``package-list'' buffer additionally provides the following bindings:
231
232@table @kbd
233@item @key{RET}
234Describe marked packages (display available information in a
235``package-info'' buffer).
236@item i
a54a237b 237Mark the current package for installation.
457f60fa 238@item d
a54a237b 239Mark the current package for deletion.
91cc37a1 240@item U
a54a237b 241Mark the current package for upgrading.
457f60fa 242@item ^
91cc37a1 243Mark all obsolete packages for upgrading.
457f60fa 244@item x
a54a237b 245Execute actions on the marked packages.
457f60fa
AK
246@end table
247
248A ``generation-list'' buffer additionally provides the following
249bindings:
250
251@table @kbd
252@item @key{RET}
253List packages installed in the current generation.
254@item i
255Describe marked generations (display available information in a
256``generation-info'' buffer).
af874238
AK
257@item s
258Switch profile to the current generation.
cb6a5c71
AK
259@item d
260Mark the current generation for deletion (with prefix, mark all
261generations).
262@item x
263Execute actions on the marked generations---i.e., delete generations.
d38bd08c
AK
264@item e
265Run Ediff (@pxref{Top,,, ediff, The Ediff Manual}) on package outputs
266installed in the 2 marked generations. With prefix argument, run Ediff
267on manifests of the marked generations.
268@item D
269@itemx =
270Run Diff (@pxref{Diff Mode,,, emacs, The GNU Emacs Manual}) on package
271outputs installed in the 2 marked generations. With prefix argument,
272run Diff on manifests of the marked generations.
273@item +
274List package outputs added to the latest marked generation comparing
275with another marked generation.
276@item -
277List package outputs removed from the latest marked generation comparing
278with another marked generation.
457f60fa
AK
279@end table
280
bd53d327 281@node Emacs Info buffer
457f60fa
AK
282@subsubsection ``Info'' buffer
283
284The interface of an ``info'' buffer is similar to the interface of
773bab64 285@code{help-mode} (@pxref{Help Mode,,, emacs, The GNU Emacs Manual}).
457f60fa
AK
286
287``Info'' buffer contains some buttons (as usual you may use @key{TAB} /
288@kbd{S-@key{TAB}} to move between buttons---@pxref{Mouse References,,,
773bab64 289emacs, The GNU Emacs Manual}) which can be used to:
457f60fa
AK
290
291@itemize @bullet
292@item (in a ``package-info'' buffer)
293
294@itemize @minus
295@item install/remove a package;
296@item jump to a package location;
297@item browse home page of a package;
298@item describe packages from ``Inputs'' fields.
299@end itemize
300
301@item (in a ``generation-info'' buffer)
302
303@itemize @minus
304@item remove a generation;
af874238 305@item switch to a generation;
457f60fa
AK
306@item list packages installed in a generation;
307@item jump to a generation directory.
308@end itemize
309
310@end itemize
311
56149217
AK
312It is also possible to copy a button label (a link to an URL or a file)
313by pressing @kbd{c} on a button.
314
457f60fa 315
bd53d327 316@node Emacs Configuration
457f60fa
AK
317@subsection Configuration
318
319There are many variables you can modify to change the appearance or
320behavior of Emacs user interface. Some of these variables are described
321in this section. Also you can use Custom Interface (@pxref{Easy
773bab64
AK
322Customization,,, emacs, The GNU Emacs Manual}) to explore/set variables
323(not all) and faces.
457f60fa
AK
324
325@menu
bd53d327
AK
326* Guile and Build Options: Emacs Build Options. Specifying how packages are built.
327* Buffer Names: Emacs Buffer Names. Names of Guix buffers.
328* Keymaps: Emacs Keymaps. Configuring key bindings.
329* Appearance: Emacs Appearance. Settings for visual appearance.
457f60fa
AK
330@end menu
331
bd53d327 332@node Emacs Build Options
457f60fa
AK
333@subsubsection Guile and Build Options
334
335@table @code
336@item guix-guile-program
337If you have some special needs for starting a Guile process, you may set
338this variable, for example:
339
340@example
341(setq guix-guile-program '("/bin/guile" "--no-auto-compile"))
342@end example
343
344@item guix-use-substitutes
345Has the same meaning as @code{--no-substitutes} option (@pxref{Invoking
346guix build}).
347
348@item guix-dry-run
349Has the same meaning as @code{--dry-run} option (@pxref{Invoking guix
350build}).
351
352@end table
353
bd53d327 354@node Emacs Buffer Names
a54a237b
AK
355@subsubsection Buffer Names
356
357Default names of ``guix.el'' buffers (``*Guix@tie{}@dots{}*'') may be
358changed with the following variables:
359
360@table @code
361@item guix-package-list-buffer-name
362@item guix-output-list-buffer-name
363@item guix-generation-list-buffer-name
364@item guix-package-info-buffer-name
365@item guix-output-info-buffer-name
366@item guix-generation-info-buffer-name
367@item guix-repl-buffer-name
368@item guix-internal-repl-buffer-name
a54a237b
AK
369@end table
370
23459fa5
AK
371By default, the name of a profile is also displayed in a ``list'' or
372``info'' buffer name. To change this behavior, use
373@code{guix-buffer-name-function} variable.
374
375For example, if you want to display all types of results in a single
a54a237b
AK
376buffer (in such case you will probably use a history (@kbd{l}/@kbd{r})
377extensively), you may do it like this:
378
379@example
380(let ((name "Guix Universal"))
381 (setq
382 guix-package-list-buffer-name name
383 guix-output-list-buffer-name name
384 guix-generation-list-buffer-name name
385 guix-package-info-buffer-name name
386 guix-output-info-buffer-name name
23459fa5
AK
387 guix-generation-info-buffer-name name
388 guix-buffer-name-function #'guix-buffer-name-simple))
a54a237b
AK
389@end example
390
bd53d327 391@node Emacs Keymaps
457f60fa
AK
392@subsubsection Keymaps
393
394If you want to change default key bindings, use the following keymaps
773bab64 395(@pxref{Init Rebinding,,, emacs, The GNU Emacs Manual}):
457f60fa
AK
396
397@table @code
398@item guix-list-mode-map
399Parent keymap with general keys for ``list'' buffers.
400
401@item guix-package-list-mode-map
402Keymap with specific keys for ``package-list'' buffers.
403
a54a237b
AK
404@item guix-output-list-mode-map
405Keymap with specific keys for ``output-list'' buffers.
406
457f60fa
AK
407@item guix-generation-list-mode-map
408Keymap with specific keys for ``generation-list'' buffers.
409
410@item guix-info-mode-map
411Parent keymap with general keys for ``info'' buffers.
412
413@item guix-package-info-mode-map
414Keymap with specific keys for ``package-info'' buffers.
415
a54a237b
AK
416@item guix-output-info-mode-map
417Keymap with specific keys for ``output-info'' buffers.
418
457f60fa
AK
419@item guix-generation-info-mode-map
420Keymap with specific keys for ``generation-info'' buffers.
421
56149217
AK
422@item guix-info-button-map
423Keymap with keys available when a point is placed on a button.
424
457f60fa
AK
425@end table
426
bd53d327 427@node Emacs Appearance
457f60fa
AK
428@subsubsection Appearance
429
430You can change almost any aspect of ``list'' / ``info'' buffers using
431the following variables:
432
433@table @code
434@item guix-list-column-format
435@itemx guix-list-column-titles
436@itemx guix-list-column-value-methods
437Specify the columns, their names, what and how is displayed in ``list''
438buffers.
439
440@item guix-info-displayed-params
441@itemx guix-info-insert-methods
442@itemx guix-info-ignore-empty-vals
443@itemx guix-info-param-title-format
444@itemx guix-info-multiline-prefix
445@itemx guix-info-indent
446@itemx guix-info-fill-column
447@itemx guix-info-delimiter
448Various settings for ``info'' buffers.
449
450@end table
9a130e19
AK
451
452
453@node Emacs Prettify
454@subsection Guix Prettify Mode
455
456Along with ``guix.el'', GNU@tie{}Guix comes with ``guix-prettify.el''.
457It provides a minor mode for abbreviating store file names by replacing
458hash sequences of symbols with ``@dots{}'':
459
460@example
461/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1
462@result{} /gnu/store/…-foo-0.1
463@end example
464
465Once you set up ``guix.el'' (@pxref{Emacs Initial Setup}), the following
466commands become available:
467
468@table @kbd
469
470@item M-x guix-prettify-mode
471Enable/disable prettifying for the current buffer.
472
473@item M-x global-guix-prettify-mode
474Enable/disable prettifying globally.
475
476@end table
477
478To automatically enable @code{guix-prettify-mode} globally on Emacs
479start, add the following line to your init file:
480
481@example
482(global-guix-prettify-mode)
483@end example
484
485If you want to enable it only for specific major modes, add it to the
486mode hooks (@pxref{Hooks,,, emacs, The GNU Emacs Manual}), for example:
487
488@example
489(add-hook 'shell-mode-hook 'guix-prettify-mode)
490(add-hook 'dired-mode-hook 'guix-prettify-mode)
491@end example