Skip to content

Commit

Permalink
doc/packages/emacs.section.md: reword
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonTorres committed Jan 21, 2025
1 parent bafce16 commit 82ead05
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions doc/packages/emacs.section.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# Emacs {#sec-emacs}

[Emacs](https://www.gnu.org/software/emacs/) is the advanced, extensible,
customizable, self-documenting editor.

At its core is an interpreter for Emacs Lisp (shortly, Elisp), a dialect
of the Lisp programming language with extensions to support text editing.

## Configuring Emacs {#sec-emacs-config}

The Emacs package comes with some extra helpers to make it easier to configure. `emacs.pkgs.withPackages` allows you to manage packages from ELPA. This means that you will not have to install that packages from within Emacs. For instance, if you wanted to use `company` `counsel`, `flycheck`, `ivy`, `magit`, `projectile`, and `use-package` you could use this as a `~/.config/nixpkgs/config.nix` override:
Nixpkgs provides a framework that leverages Emacs via Nix.

`emacs.pkgs.withPackages` allows managing packages from
various Elisp package repositories (ELPA, MELPA etc.) and
even third-party stand-alone packages from Nix, without relying on Emacs
to download and install them.

For instance, by writing the code below at
`~/.config/nixpkgs/config.nix`, the Elisp packages `company`,
`counsel`, `flycheck`, `ivy`,`magit`, `projectile`, and `use-package`
are installed:

```nix
{
Expand All @@ -20,7 +36,19 @@ The Emacs package comes with some extra helpers to make it easier to configure.
}
```

You can install it like any other packages via `nix-env -iA myEmacs`. However, this will only install those packages. It will not `configure` them for us. To do this, we need to provide a configuration file. Luckily, it is possible to do this from within Nix! By modifying the above example, we can make Emacs load a custom config file. The key is to create a package that provides a `default.el` file in `/share/emacs/site-start/`. Emacs knows to load this file automatically when it starts.
This custom package can be installed like any other one, via `nix-env -iA myEmacs`.

However, this expression merely installs the package, with no configuration.
Such a configuration requires an Elisp file crafted for this purpose.

Luckily, it is possible to do this from within Nix!

By modifying the above example, we can make Emacs load a custom config file.
The key is to create a package that provides a `default.el` file in
`/share/emacs/site-start/` -- since Emacs loads this file automatically
when it starts.

Let's modify the example above:

```nix
{
Expand Down Expand Up @@ -97,9 +125,24 @@ You can install it like any other packages via `nix-env -iA myEmacs`. However, t
}
```

This provides a fairly full Emacs start file. It will load in addition to the user's personal config. You can always disable it by passing `-q` to the Emacs command.
This provides a fairly full Emacs start file. It will be loaded in addition
to the user's personal config. Further, it can be disabled always when desired:
uiklEmacs accepts the command-line argument `--no-init-file` (short form `-q`)
to not load the init files.

Sometimes `emacs.pkgs.withPackages` is not enough, as this package set imposes
some priorities over their packages (with the lowest priority assigned to
GNU-devel ELPA, and the highest for packages manually defined in
`pkgs/applications/editors/emacs/elisp-packages/manual-packages`).

However it is not possible to control these priorities when some package
is installed as a dependency. The overrides can be done on a per-package-basis,
providing all the required dependencies manually.
However this procedure is tedious and error-prone, since there is the
possibility that an unwanted dependency sneaks in through some other package.

Sometimes `emacs.pkgs.withPackages` is not enough, as this package set has some priorities imposed on packages (with the lowest priority assigned to GNU-devel ELPA, and the highest for packages manually defined in `pkgs/applications/editors/emacs/elisp-packages/manual-packages`). But you can't control these priorities when some package is installed as a dependency. You can override it on a per-package-basis, providing all the required dependencies manually, but it's tedious and there is always a possibility that an unwanted dependency will sneak in through some other package. To completely override such a package, you can use `overrideScope`.
A complete and pervasive override for such a package can be done via
`overrideScope`.

```nix
let
Expand Down

0 comments on commit 82ead05

Please sign in to comment.