2016-06-25 22:19:27 +00:00
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
xmlns:xi="http://www.w3.org/2001/XInclude"
|
|
|
|
version="5.0"
|
|
|
|
xml:id="module-services-emacs">
|
2018-09-30 00:51:11 +00:00
|
|
|
<title>Emacs</title>
|
|
|
|
<!--
|
2016-06-25 22:19:27 +00:00
|
|
|
Documentation contributors:
|
|
|
|
Damien Cassou @DamienCassou
|
|
|
|
Thomas Tuegel @ttuegel
|
|
|
|
Rodney Lorrimar @rvl
|
2019-08-07 22:52:22 +00:00
|
|
|
Adam Hoese @adisbladis
|
2016-06-25 22:19:27 +00:00
|
|
|
-->
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
<link xlink:href="https://www.gnu.org/software/emacs/">Emacs</link> is an
|
|
|
|
extensible, customizable, self-documenting real-time display editor — and
|
|
|
|
more. At its core is an interpreter for Emacs Lisp, a dialect of the Lisp
|
|
|
|
programming language with extensions to support text editing.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Emacs runs within a graphical desktop environment using the X Window System,
|
|
|
|
but works equally well on a text terminal. Under
|
|
|
|
<productname>macOS</productname>, a "Mac port" edition is available, which
|
|
|
|
uses Apple's native GUI frameworks.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
<productname>Nixpkgs</productname> provides a superior environment for
|
|
|
|
running <application>Emacs</application>. It's simple to create custom builds
|
|
|
|
by overriding the default packages. Chaotic collections of Emacs Lisp code
|
|
|
|
and extensions can be brought under control using declarative package
|
|
|
|
management. <productname>NixOS</productname> even provides a
|
|
|
|
<command>systemd</command> user service for automatically starting the Emacs
|
|
|
|
daemon.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
<section xml:id="module-services-emacs-installing">
|
|
|
|
<title>Installing <application>Emacs</application></title>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Emacs can be installed in the normal way for Nix (see
|
|
|
|
<xref linkend="sec-package-management" />). In addition, a NixOS
|
|
|
|
<emphasis>service</emphasis> can be enabled.
|
2016-06-25 22:19:27 +00:00
|
|
|
</para>
|
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<section xml:id="module-services-emacs-releases">
|
|
|
|
<title>The Different Releases of Emacs</title>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
<productname>Nixpkgs</productname> defines several basic Emacs packages.
|
|
|
|
The following are attributes belonging to the <varname>pkgs</varname> set:
|
2018-09-30 00:51:11 +00:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<varname>emacs</varname>
|
|
|
|
</term>
|
|
|
|
<term>
|
2020-08-20 22:34:15 +00:00
|
|
|
<varname>emacs</varname>
|
2018-09-30 00:51:11 +00:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-20 22:34:15 +00:00
|
|
|
The latest stable version of Emacs using the
|
2019-09-19 17:17:30 +00:00
|
|
|
<link
|
|
|
|
xlink:href="http://www.gtk.org">GTK 2</link>
|
|
|
|
widget toolkit.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
2020-08-20 22:34:15 +00:00
|
|
|
<varname>emacs-nox</varname>
|
2018-09-30 00:51:11 +00:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-20 22:34:15 +00:00
|
|
|
Emacs built without any dependency on X11 libraries.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term>
|
|
|
|
<varname>emacsMacport</varname>
|
|
|
|
</term>
|
|
|
|
<term>
|
2020-08-20 22:34:15 +00:00
|
|
|
<varname>emacsMacport</varname>
|
2018-09-30 00:51:11 +00:00
|
|
|
</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-20 22:34:15 +00:00
|
|
|
Emacs with the "Mac port" patches, providing a more native look and
|
2019-09-19 17:17:30 +00:00
|
|
|
feel under macOS.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
If those aren't suitable, then the following imitation Emacs editors are
|
|
|
|
also available in Nixpkgs:
|
|
|
|
<link xlink:href="https://www.gnu.org/software/zile/">Zile</link>,
|
|
|
|
<link xlink:href="http://homepage.boetes.org/software/mg/">mg</link>,
|
|
|
|
<link xlink:href="http://yi-editor.github.io/">Yi</link>,
|
|
|
|
<link xlink:href="https://joe-editor.sourceforge.io/">jmacs</link>.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</section>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<section xml:id="module-services-emacs-adding-packages">
|
|
|
|
<title>Adding Packages to Emacs</title>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Emacs includes an entire ecosystem of functionality beyond text editing,
|
|
|
|
including a project planner, mail and news reader, debugger interface,
|
|
|
|
calendar, and more.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Most extensions are gotten with the Emacs packaging system
|
|
|
|
(<filename>package.el</filename>) from
|
|
|
|
<link
|
|
|
|
xlink:href="https://elpa.gnu.org/">Emacs Lisp Package Archive
|
|
|
|
(<acronym>ELPA</acronym>)</link>,
|
|
|
|
<link xlink:href="https://melpa.org/"><acronym>MELPA</acronym></link>,
|
|
|
|
<link xlink:href="https://stable.melpa.org/">MELPA Stable</link>, and
|
|
|
|
<link xlink:href="http://orgmode.org/elpa.html">Org ELPA</link>. Nixpkgs is
|
|
|
|
regularly updated to mirror all these archives.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Under NixOS, you can continue to use
|
|
|
|
<function>package-list-packages</function> and
|
|
|
|
<function>package-install</function> to install packages. You can also
|
|
|
|
declare the set of Emacs packages you need using the derivations from
|
|
|
|
Nixpkgs. The rest of this section discusses declarative installation of
|
|
|
|
Emacs packages through nixpkgs.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
The first step to declare the list of packages you want in your Emacs
|
|
|
|
installation is to create a dedicated derivation. This can be done in a
|
|
|
|
dedicated <filename>emacs.nix</filename> file such as:
|
2018-09-30 00:51:11 +00:00
|
|
|
<example xml:id="ex-emacsNix">
|
|
|
|
<title>Nix expression to build Emacs with packages (<filename>emacs.nix</filename>)</title>
|
|
|
|
<programlisting language="nix">
|
2016-06-25 22:19:27 +00:00
|
|
|
/*
|
|
|
|
This is a nix expression to build Emacs and some Emacs packages I like
|
|
|
|
from source on any distribution where Nix is installed. This will install
|
|
|
|
all the dependencies from the nixpkgs repository and build the binary files
|
|
|
|
without interfering with the host distribution.
|
|
|
|
|
|
|
|
To build the project, type the following from the current directory:
|
|
|
|
|
|
|
|
$ nix-build emacs.nix
|
|
|
|
|
|
|
|
To run the newly compiled executable:
|
|
|
|
|
|
|
|
$ ./result/bin/emacs
|
|
|
|
*/
|
|
|
|
{ pkgs ? import <nixpkgs> {} }: <co xml:id="ex-emacsNix-1" />
|
|
|
|
|
|
|
|
let
|
|
|
|
myEmacs = pkgs.emacs; <co xml:id="ex-emacsNix-2" />
|
2020-12-18 03:46:05 +00:00
|
|
|
emacsWithPackages = (pkgs.emacsPackagesFor myEmacs).emacsWithPackages; <co xml:id="ex-emacsNix-3" />
|
2016-06-25 22:19:27 +00:00
|
|
|
in
|
|
|
|
emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [ <co xml:id="ex-emacsNix-4" />
|
|
|
|
magit # ; Integrate git <C-x g>
|
|
|
|
zerodark-theme # ; Nicolas' theme
|
|
|
|
]) ++ (with epkgs.melpaPackages; [ <co xml:id="ex-emacsNix-5" />
|
|
|
|
undo-tree # ; <C-x u> to show the undo tree
|
|
|
|
zoom-frm # ; increase/decrease font size for all buffers %lt;C-x C-+>
|
|
|
|
]) ++ (with epkgs.elpaPackages; [ <co xml:id="ex-emacsNix-6" />
|
|
|
|
auctex # ; LaTeX mode
|
|
|
|
beacon # ; highlight my cursor when scrolling
|
|
|
|
nameless # ; hide current package name everywhere in elisp code
|
|
|
|
]) ++ [
|
|
|
|
pkgs.notmuch # From main packages set <co xml:id="ex-emacsNix-7" />
|
|
|
|
])
|
|
|
|
</programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</example>
|
|
|
|
<calloutlist>
|
|
|
|
<callout arearefs="ex-emacsNix-1">
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
The first non-comment line in this file (<literal>{ pkgs ? ...
|
|
|
|
}</literal>) indicates that the whole file represents a function.
|
2016-06-25 22:19:27 +00:00
|
|
|
</para>
|
2018-09-30 00:51:11 +00:00
|
|
|
</callout>
|
|
|
|
<callout arearefs="ex-emacsNix-2">
|
2016-06-25 22:19:27 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
The <varname>let</varname> expression below defines a
|
|
|
|
<varname>myEmacs</varname> binding pointing to the current stable
|
|
|
|
version of Emacs. This binding is here to separate the choice of the
|
|
|
|
Emacs binary from the specification of the required packages.
|
2016-06-25 22:19:27 +00:00
|
|
|
</para>
|
2018-09-30 00:51:11 +00:00
|
|
|
</callout>
|
|
|
|
<callout arearefs="ex-emacsNix-3">
|
2016-06-25 22:19:27 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
This generates an <varname>emacsWithPackages</varname> function. It
|
|
|
|
takes a single argument: a function from a package set to a list of
|
|
|
|
packages (the packages that will be available in Emacs).
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</callout>
|
|
|
|
<callout arearefs="ex-emacsNix-4">
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
The rest of the file specifies the list of packages to install. In the
|
|
|
|
example, two packages (<varname>magit</varname> and
|
|
|
|
<varname>zerodark-theme</varname>) are taken from MELPA stable.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</callout>
|
|
|
|
<callout arearefs="ex-emacsNix-5">
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Two packages (<varname>undo-tree</varname> and
|
|
|
|
<varname>zoom-frm</varname>) are taken from MELPA.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</callout>
|
|
|
|
<callout arearefs="ex-emacsNix-6">
|
|
|
|
<para>
|
|
|
|
Three packages are taken from GNU ELPA.
|
|
|
|
</para>
|
|
|
|
</callout>
|
|
|
|
<callout arearefs="ex-emacsNix-7">
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
<varname>notmuch</varname> is taken from a nixpkgs derivation which
|
|
|
|
contains an Emacs mode.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</callout>
|
|
|
|
</calloutlist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
The result of this configuration will be an <command>emacs</command>
|
|
|
|
command which launches Emacs with all of your chosen packages in the
|
|
|
|
<varname>load-path</varname>.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
You can check that it works by executing this in a terminal:
|
2016-06-25 22:19:27 +00:00
|
|
|
<screen>
|
2019-06-17 11:25:50 +00:00
|
|
|
<prompt>$ </prompt>nix-build emacs.nix
|
|
|
|
<prompt>$ </prompt>./result/bin/emacs -q
|
2016-06-25 22:19:27 +00:00
|
|
|
</screen>
|
2019-09-19 17:17:30 +00:00
|
|
|
and then typing <literal>M-x package-initialize</literal>. Check that you
|
|
|
|
can use all the packages you want in this Emacs instance. For example, try
|
|
|
|
switching to the zerodark theme through <literal>M-x load-theme <RET>
|
|
|
|
zerodark <RET> y</literal>.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<tip>
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
A few popular extensions worth checking out are: auctex, company,
|
|
|
|
edit-server, flycheck, helm, iedit, magit, multiple-cursors, projectile,
|
|
|
|
and yasnippet.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</tip>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
The list of available packages in the various ELPA repositories can be seen
|
|
|
|
with the following commands:
|
2018-09-30 00:51:11 +00:00
|
|
|
<example xml:id="module-services-emacs-querying-packages">
|
|
|
|
<title>Querying Emacs packages</title>
|
|
|
|
<programlisting><![CDATA[
|
2020-12-18 03:46:05 +00:00
|
|
|
nix-env -f "<nixpkgs>" -qaP -A emacs.pkgs.elpaPackages
|
|
|
|
nix-env -f "<nixpkgs>" -qaP -A emacs.pkgs.melpaPackages
|
|
|
|
nix-env -f "<nixpkgs>" -qaP -A emacs.pkgs.melpaStablePackages
|
|
|
|
nix-env -f "<nixpkgs>" -qaP -A emacs.pkgs.orgPackages
|
2016-06-25 22:19:27 +00:00
|
|
|
]]></programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
If you are on NixOS, you can install this particular Emacs for all users by
|
|
|
|
adding it to the list of system packages (see
|
|
|
|
<xref linkend="sec-declarative-package-mgmt" />). Simply modify your file
|
|
|
|
<filename>configuration.nix</filename> to make it contain:
|
2018-09-30 00:51:11 +00:00
|
|
|
<example xml:id="module-services-emacs-configuration-nix">
|
|
|
|
<title>Custom Emacs in <filename>configuration.nix</filename></title>
|
|
|
|
<programlisting><![CDATA[
|
2016-06-25 22:19:27 +00:00
|
|
|
{
|
|
|
|
environment.systemPackages = [
|
|
|
|
# [...]
|
|
|
|
(import /path/to/emacs.nix { inherit pkgs; })
|
|
|
|
];
|
|
|
|
}
|
|
|
|
]]></programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</example>
|
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
In this case, the next <command>nixos-rebuild switch</command> will take
|
|
|
|
care of adding your <command>emacs</command> to the <varname>PATH</varname>
|
|
|
|
environment variable (see <xref linkend="sec-changing-config" />).
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
|
|
|
<!-- fixme: i think the following is better done with config.nix
|
|
|
|
https://nixos.org/nixpkgs/manual/#sec-modify-via-packageOverrides
|
|
|
|
-->
|
2018-09-30 00:51:11 +00:00
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
If you are not on NixOS or want to install this particular Emacs only for
|
|
|
|
yourself, you can do so by adding it to your
|
|
|
|
<filename>~/.config/nixpkgs/config.nix</filename> (see
|
2020-04-18 20:51:19 +00:00
|
|
|
<link xlink:href="https://nixos.org/nixpkgs/manual/#sec-modify-via-packageOverrides">Nixpkgs
|
2019-09-19 17:17:30 +00:00
|
|
|
manual</link>):
|
2018-09-30 00:51:11 +00:00
|
|
|
<example xml:id="module-services-emacs-config-nix">
|
|
|
|
<title>Custom Emacs in <filename>~/.config/nixpkgs/config.nix</filename></title>
|
|
|
|
<programlisting><![CDATA[
|
2016-06-25 22:19:27 +00:00
|
|
|
{
|
|
|
|
packageOverrides = super: let self = super.pkgs; in {
|
|
|
|
myemacs = import /path/to/emacs.nix { pkgs = self; };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]]></programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</example>
|
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
In this case, the next <literal>nix-env -f '<nixpkgs>' -iA
|
|
|
|
myemacs</literal> will take care of adding your emacs to the
|
|
|
|
<varname>PATH</varname> environment variable.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
</section>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<section xml:id="module-services-emacs-advanced">
|
|
|
|
<title>Advanced Emacs Configuration</title>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
If you want, you can tweak the Emacs package itself from your
|
|
|
|
<filename>emacs.nix</filename>. For example, if you want to have a
|
|
|
|
GTK 3-based Emacs instead of the default GTK 2-based binary and remove the
|
2020-08-27 20:54:23 +00:00
|
|
|
automatically generated <filename>emacs.desktop</filename> (useful if you
|
2019-09-19 17:17:30 +00:00
|
|
|
only use <command>emacsclient</command>), you can change your file
|
|
|
|
<filename>emacs.nix</filename> in this way:
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<example xml:id="ex-emacsGtk3Nix">
|
|
|
|
<title>Custom Emacs build</title>
|
|
|
|
<programlisting><![CDATA[
|
2016-06-25 22:19:27 +00:00
|
|
|
{ pkgs ? import <nixpkgs> {} }:
|
|
|
|
let
|
2016-10-30 16:35:57 +00:00
|
|
|
myEmacs = (pkgs.emacs.override {
|
2016-06-25 22:19:27 +00:00
|
|
|
# Use gtk3 instead of the default gtk2
|
|
|
|
withGTK3 = true;
|
|
|
|
withGTK2 = false;
|
2016-10-30 16:35:57 +00:00
|
|
|
}).overrideAttrs (attrs: {
|
2016-06-25 22:19:27 +00:00
|
|
|
# I don't want emacs.desktop file because I only use
|
|
|
|
# emacsclient.
|
2016-10-30 16:35:57 +00:00
|
|
|
postInstall = (attrs.postInstall or "") + ''
|
2016-06-25 22:19:27 +00:00
|
|
|
rm $out/share/applications/emacs.desktop
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
in [...]
|
|
|
|
]]></programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</example>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
After building this file as shown in <xref linkend="ex-emacsNix" />, you
|
|
|
|
will get an GTK 3-based Emacs binary pre-loaded with your favorite packages.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
</section>
|
2018-09-30 00:51:11 +00:00
|
|
|
</section>
|
|
|
|
<section xml:id="module-services-emacs-running">
|
2016-06-25 22:19:27 +00:00
|
|
|
<title>Running Emacs as a Service</title>
|
2018-09-30 00:51:11 +00:00
|
|
|
|
2016-06-25 22:19:27 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
<productname>NixOS</productname> provides an optional
|
|
|
|
<command>systemd</command> service which launches
|
|
|
|
<link xlink:href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html">
|
|
|
|
Emacs daemon </link> with the user's login session.
|
2016-06-25 22:19:27 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
<emphasis>Source:</emphasis>
|
|
|
|
<filename>modules/services/editors/emacs.nix</filename>
|
2016-06-25 22:19:27 +00:00
|
|
|
</para>
|
|
|
|
|
2018-09-01 20:15:29 +00:00
|
|
|
<section xml:id="module-services-emacs-enabling">
|
2018-09-30 00:51:11 +00:00
|
|
|
<title>Enabling the Service</title>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
To install and enable the <command>systemd</command> user service for Emacs
|
|
|
|
daemon, add the following to your <filename>configuration.nix</filename>:
|
2018-04-05 08:43:56 +00:00
|
|
|
<programlisting>
|
|
|
|
<xref linkend="opt-services.emacs.enable"/> = true;
|
|
|
|
<xref linkend="opt-services.emacs.package"/> = import /home/cassou/.emacs.d { pkgs = pkgs; };
|
|
|
|
</programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
The <varname>services.emacs.package</varname> option allows a custom
|
|
|
|
derivation to be used, for example, one created by
|
|
|
|
<function>emacsWithPackages</function>.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Ensure that the Emacs server is enabled for your user's Emacs
|
|
|
|
configuration, either by customizing the <varname>server-mode</varname>
|
|
|
|
variable, or by adding <literal>(server-start)</literal> to
|
|
|
|
<filename>~/.emacs.d/init.el</filename>.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To start the daemon, execute the following:
|
2016-06-25 22:19:27 +00:00
|
|
|
<screen>
|
2019-06-17 11:25:50 +00:00
|
|
|
<prompt>$ </prompt>nixos-rebuild switch # to activate the new configuration.nix
|
|
|
|
<prompt>$ </prompt>systemctl --user daemon-reload # to force systemd reload
|
|
|
|
<prompt>$ </prompt>systemctl --user start emacs.service # to start the Emacs daemon
|
2016-06-25 22:19:27 +00:00
|
|
|
</screen>
|
2018-09-30 00:51:11 +00:00
|
|
|
The server should now be ready to serve Emacs clients.
|
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
</section>
|
|
|
|
|
2018-09-01 20:15:29 +00:00
|
|
|
<section xml:id="module-services-emacs-starting-client">
|
2018-09-30 00:51:11 +00:00
|
|
|
<title>Starting the client</title>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Ensure that the emacs server is enabled, either by customizing the
|
|
|
|
<varname>server-mode</varname> variable, or by adding
|
|
|
|
<literal>(server-start)</literal> to <filename>~/.emacs</filename>.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To connect to the emacs daemon, run one of the following:
|
|
|
|
<programlisting><![CDATA[
|
2016-06-25 22:19:27 +00:00
|
|
|
emacsclient FILENAME
|
|
|
|
emacsclient --create-frame # opens a new frame (window)
|
|
|
|
emacsclient --create-frame --tty # opens a new frame on the current terminal
|
|
|
|
]]></programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
</section>
|
|
|
|
|
2018-09-01 20:15:29 +00:00
|
|
|
<section xml:id="module-services-emacs-editor-variable">
|
2018-09-30 00:51:11 +00:00
|
|
|
<title>Configuring the <varname>EDITOR</varname> variable</title>
|
|
|
|
|
|
|
|
<!--<title><command>emacsclient</command> as the Default Editor</title>-->
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
If <xref linkend="opt-services.emacs.defaultEditor"/> is
|
|
|
|
<literal>true</literal>, the <varname>EDITOR</varname> variable will be set
|
|
|
|
to a wrapper script which launches <command>emacsclient</command>.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Any setting of <varname>EDITOR</varname> in the shell config files will
|
|
|
|
override <varname>services.emacs.defaultEditor</varname>. To make sure
|
|
|
|
<varname>EDITOR</varname> refers to the Emacs wrapper script, remove any
|
|
|
|
existing <varname>EDITOR</varname> assignment from
|
|
|
|
<filename>.profile</filename>, <filename>.bashrc</filename>,
|
|
|
|
<filename>.zshenv</filename> or any other shell config file.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
If you have formed certain bad habits when editing files, these can be
|
|
|
|
corrected with a shell alias to the wrapper script:
|
2018-09-30 00:51:11 +00:00
|
|
|
<programlisting>alias vi=$EDITOR</programlisting>
|
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
</section>
|
|
|
|
|
2018-09-01 20:15:29 +00:00
|
|
|
<section xml:id="module-services-emacs-per-user">
|
2018-09-30 00:51:11 +00:00
|
|
|
<title>Per-User Enabling of the Service</title>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
In general, <command>systemd</command> user services are globally enabled
|
|
|
|
by symlinks in <filename>/etc/systemd/user</filename>. In the case where
|
|
|
|
Emacs daemon is not wanted for all users, it is possible to install the
|
|
|
|
service but not globally enable it:
|
2018-04-05 08:43:56 +00:00
|
|
|
<programlisting>
|
|
|
|
<xref linkend="opt-services.emacs.enable"/> = false;
|
|
|
|
<xref linkend="opt-services.emacs.install"/> = true;
|
|
|
|
</programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
To enable the <command>systemd</command> user service for just the
|
|
|
|
currently logged in user, run:
|
2018-09-30 00:51:11 +00:00
|
|
|
<programlisting>systemctl --user enable emacs</programlisting>
|
2019-09-19 17:17:30 +00:00
|
|
|
This will add the symlink
|
|
|
|
<filename>~/.config/systemd/user/emacs.service</filename>.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
</section>
|
2018-09-30 00:51:11 +00:00
|
|
|
</section>
|
|
|
|
<section xml:id="module-services-emacs-configuring">
|
2016-06-25 22:19:27 +00:00
|
|
|
<title>Configuring Emacs</title>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
The Emacs init file should be changed to load the extension packages at
|
|
|
|
startup:
|
2018-09-30 00:51:11 +00:00
|
|
|
<example xml:id="module-services-emacs-package-initialisation">
|
|
|
|
<title>Package initialization in <filename>.emacs</filename></title>
|
|
|
|
<programlisting><![CDATA[
|
2016-06-25 22:19:27 +00:00
|
|
|
(require 'package)
|
|
|
|
|
|
|
|
;; optional. makes unpure packages archives unavailable
|
|
|
|
(setq package-archives nil)
|
|
|
|
|
|
|
|
(setq package-enable-at-startup nil)
|
|
|
|
(package-initialize)
|
|
|
|
]]></programlisting>
|
2018-09-30 00:51:11 +00:00
|
|
|
</example>
|
2016-06-25 22:19:27 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
After the declarative emacs package configuration has been tested,
|
|
|
|
previously downloaded packages can be cleaned up by removing
|
|
|
|
<filename>~/.emacs.d/elpa</filename> (do make a backup first, in case you
|
|
|
|
forgot a package).
|
2016-06-25 22:19:27 +00:00
|
|
|
</para>
|
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<!--
|
2016-06-25 22:19:27 +00:00
|
|
|
todo: is it worth documenting customizations for
|
|
|
|
server-switch-hook, server-done-hook?
|
|
|
|
-->
|
|
|
|
|
2018-09-01 20:15:29 +00:00
|
|
|
<section xml:id="module-services-emacs-major-mode">
|
2018-09-30 00:51:11 +00:00
|
|
|
<title>A Major Mode for Nix Expressions</title>
|
2016-06-25 22:19:27 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Of interest may be <varname>melpaPackages.nix-mode</varname>, which
|
|
|
|
provides syntax highlighting for the Nix language. This is particularly
|
|
|
|
convenient if you regularly edit Nix files.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
</section>
|
|
|
|
|
2018-09-01 20:15:29 +00:00
|
|
|
<section xml:id="module-services-emacs-man-pages">
|
2018-09-30 00:51:11 +00:00
|
|
|
<title>Accessing man pages</title>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
You can use <function>woman</function> to get completion of all available
|
|
|
|
man pages. For example, type <literal>M-x woman <RET> nixos-rebuild
|
|
|
|
<RET>.</literal>
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-06-25 22:19:27 +00:00
|
|
|
</section>
|
2016-08-09 20:23:59 +00:00
|
|
|
|
|
|
|
<section xml:id="sec-emacs-docbook-xml">
|
2018-09-30 00:51:11 +00:00
|
|
|
<title>Editing DocBook 5 XML Documents</title>
|
2016-08-09 20:23:59 +00:00
|
|
|
|
2018-09-30 00:51:11 +00:00
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Emacs includes
|
|
|
|
<link
|
|
|
|
xlink:href="https://www.gnu.org/software/emacs/manual/html_node/nxml-mode/Introduction.html">nXML</link>,
|
|
|
|
a major-mode for validating and editing XML documents. When editing DocBook
|
|
|
|
5.0 documents, such as <link linkend="book-nixos-manual">this one</link>,
|
|
|
|
nXML needs to be configured with the relevant schema, which is not
|
|
|
|
included.
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
To install the DocBook 5.0 schemas, either add
|
|
|
|
<varname>pkgs.docbook5</varname> to
|
|
|
|
<xref linkend="opt-environment.systemPackages"/>
|
|
|
|
(<link
|
|
|
|
linkend="sec-declarative-package-mgmt">NixOS</link>), or run
|
|
|
|
<literal>nix-env -f '<nixpkgs>' -iA docbook5</literal>
|
|
|
|
(<link linkend="sec-ad-hoc-packages">Nix</link>).
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2019-09-19 17:17:30 +00:00
|
|
|
Then customize the variable <varname>rng-schema-locating-files</varname> to
|
|
|
|
include <filename>~/.emacs.d/schemas.xml</filename> and put the following
|
|
|
|
text into that file:
|
2018-09-30 00:51:11 +00:00
|
|
|
<example xml:id="ex-emacs-docbook-xml">
|
|
|
|
<title>nXML Schema Configuration (<filename>~/.emacs.d/schemas.xml</filename>)</title>
|
|
|
|
<programlisting language="xml"><![CDATA[
|
2016-08-09 20:23:59 +00:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<!--
|
|
|
|
To let emacs find this file, evaluate:
|
|
|
|
(add-to-list 'rng-schema-locating-files "~/.emacs.d/schemas.xml")
|
|
|
|
-->
|
|
|
|
<locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
|
|
|
|
<!--
|
|
|
|
Use this variation if pkgs.docbook5 is added to environment.systemPackages
|
|
|
|
-->
|
|
|
|
<namespace ns="http://docbook.org/ns/docbook"
|
|
|
|
uri="/run/current-system/sw/share/xml/docbook-5.0/rng/docbookxi.rnc"/>
|
|
|
|
<!--
|
|
|
|
Use this variation if installing schema with "nix-env -iA pkgs.docbook5".
|
|
|
|
<namespace ns="http://docbook.org/ns/docbook"
|
|
|
|
uri="../.nix-profile/share/xml/docbook-5.0/rng/docbookxi.rnc"/>
|
|
|
|
-->
|
|
|
|
</locatingRules>
|
|
|
|
]]></programlisting>
|
|
|
|
</example>
|
2018-09-30 00:51:11 +00:00
|
|
|
</para>
|
2016-08-09 20:23:59 +00:00
|
|
|
</section>
|
2018-09-30 00:51:11 +00:00
|
|
|
</section>
|
2016-06-25 22:19:27 +00:00
|
|
|
</chapter>
|