Emacs: Difference between revisions
Phanirithvij (talk | contribs) m link to search.nixos.org  | 
				 Change formatting and wording to match the manual of style guidelines  | 
				||
| Line 8: | Line 8: | ||
==== Using nix-shell ====  | ==== Using nix-shell ====  | ||
<syntaxhighlight lang="  | <syntaxhighlight lang="console" start="3">  | ||
nix-shell -p emacs  | $ nix-shell -p emacs  | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
| Line 17: | Line 17: | ||
  pkgs.emacs  |   pkgs.emacs  | ||
];  | ];  | ||
</syntaxhighlight>  | </syntaxhighlight>Apply these changes by running:<syntaxhighlight lang="console">  | ||
# nixos-rebuild switch  | |||
</syntaxhighlight>  | </syntaxhighlight>  | ||
| Line 26: | Line 26: | ||
   pkgs.emacs    |    pkgs.emacs    | ||
];  | ];  | ||
</syntaxhighlight>  | </syntaxhighlight>Apply the changes by running:<syntaxhighlight lang="console">  | ||
home-manager switch  | $ home-manager switch  | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
| Line 111: | Line 111: | ||
<b>Bonus Tip:</b>  | <b>Bonus Tip:</b>  | ||
<code>emacs.pkgs.pretty-sha-path</code> is quality of life improvement for   | <code>emacs.pkgs.pretty-sha-path</code> is quality of life improvement for Nix, Guix users.  | ||
Allows toggling Guix / Nix store paths by replacing SHA-sequences with ellipsis, i.e.:  | Allows toggling Guix/Nix store paths by replacing SHA-sequences with ellipsis, i.e.:  | ||
<syntaxhighlight lang="bash">  | <syntaxhighlight lang="bash">/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1  →  /gnu/store/…-foo-0.1  | ||
/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1  →  /gnu/store/…-foo-0.1  | /nix/store/nh4n4yzb1bx7nss2rg342dz44g14m06x-bar-0.2  →  /nix/store/…-bar-0.2</syntaxhighlight>  | ||
/nix/store/nh4n4yzb1bx7nss2rg342dz44g14m06x-bar-0.2  →  /nix/store/…-bar-0.2  | |||
</syntaxhighlight>  | |||
located at https://github.com/alezost/pretty-sha-path.el  | located at https://github.com/alezost/pretty-sha-path.el  | ||
| Line 150: | Line 148: | ||
See the [https://github.com/nix-community/emacs-overlay#extra-library-functionality overlay README] for a full list of options.  | See the [https://github.com/nix-community/emacs-overlay#extra-library-functionality overlay README] for a full list of options.  | ||
==== Adding packages from outside ELPA / MELPA ====  | ==== Adding packages from outside ELPA/MELPA ====  | ||
Some packages may require more sophisticated derivation, but the following is a good starting point for adding external packages:  | Some packages may require more sophisticated derivation, but the following is a good starting point for adding external packages:  | ||
| Line 210: | Line 208: | ||
}</nowiki>}}  | }</nowiki>}}  | ||
==== Packaging and testing   | ==== Packaging and testing Emacs nixpkgs ====  | ||
Emacs packages can be defined and tested like other nixpkgs.  | Emacs packages can be defined and tested like other nixpkgs.  | ||
They can be obtained from melpa, elpa or other sources such as github.  | They can be obtained from melpa, elpa or other sources such as github.  | ||
| Line 243: | Line 241: | ||
</nowiki>}}  | </nowiki>}}  | ||
They are located at pkgs/applications/editors/emacs/elisp-packages/manual-packages/ and a new pkg must be added under pkgs/applications/editors/elisp-packages/manual-packages.nix.  | They are located at <code>pkgs/applications/editors/emacs/elisp-packages/manual-packages/</code> [https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/editors/emacs/elisp-packages/manual-packages] and a new pkg must be added under <code>pkgs/applications/editors/elisp-packages/manual-packages.nix</code> [https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/emacs/elisp-packages/manual-packages.nix]. Once the nixpkg is ready, it can be tested using the following command. This inserts the nixpkg into the load-path of Emacs.<syntaxhighlight lang="console">  | ||
Once the nixpkg is ready, it can be tested using the following command. This inserts the nixpkg into the load-path of   | $ nix-shell -I nixpkgs=<path_to_nixpkgs_copy> -p "(emacsPackagesFor pkgs.emacs28).emacsWithPackages (epkgs: [ epkgs.<package> ])"  | ||
</syntaxhighlight>  | |||
==== Window Manager Integration ====  | ==== Window Manager Integration ====  | ||
| Line 262: | Line 260: | ||
===== 1. Stable (nixpkgs) =====  | ===== 1. Stable (nixpkgs) =====  | ||
Emacs is available in nixpkgs under the names <code>emacs</code> and <code>emacs-gtk</code>.  | Emacs is available in nixpkgs under the names <code>emacs</code> and <code>emacs-gtk</code>.  | ||
[https://github.com/NixOS/nixpkgs/pull/189543 Since 2022-09], the package called <code>emacs</code> now installs the lucid toolkit instead of gtk. The reason is that   | |||
[https://github.com/NixOS/nixpkgs/pull/189543 Since 2022-09], the package called <code>emacs</code> now installs the lucid toolkit instead of gtk. The reason is that Emacs is less stable with gtk especially in daemon mode. However, the lucid flavor of Emacs will not take into account the GTK theme (since it is not even GTK) and looks quite… ugly (see comparisons [https://emacs.stackexchange.com/questions/33065/on-linux-why-should-one-choose-lucid-over-gtk-gui-for-emacs here]). If you still prefer the GTK version of Emacs, you can instead install <code>emacs-gtk</code> (before 2022-09 this package does not exist and Emacs defaults to the gtk version).  | |||
===== 2. Unstable (community overlay) =====  | ===== 2. Unstable (community overlay) =====  | ||
The [https://github.com/nix-community/emacs-overlay community overlay] provides nightly versions of the Emacs unstable branches, ELPA / MELPA packages, and [https://github.com/ch11ng/exwm EXWM] + its dependencies. '''To use these, first apply the overlay (instructions below), which will make the packages available in nixpkgs.''' Then you can follow the normal nixpkgs installation instructions (above), but use your package of choice from the overlay (e.g. <code>pkgs.emacsGit</code>) in place of <code>pkgs.emacs</code>. See the [https://github.com/nix-community/emacs-overlay#emacs-overlay README] for a complete list of packages provided, and their differences.  | The [https://github.com/nix-community/emacs-overlay community overlay] provides nightly versions of the Emacs unstable branches, ELPA/MELPA packages, and [https://github.com/ch11ng/exwm EXWM] + its dependencies. '''To use these, first apply the overlay (instructions below), which will make the packages available in nixpkgs.''' Then you can follow the normal nixpkgs installation instructions (above), but use your package of choice from the overlay (e.g. <code>pkgs.emacsGit</code>) in place of <code>pkgs.emacs</code>. See the [https://github.com/nix-community/emacs-overlay#emacs-overlay README] for a complete list of packages provided, and their differences.  | ||
===== With flakes =====  | ===== With flakes =====  | ||
Using a system flake, one can specify the specific revision of the overlay as a flake input, for example:  | Using a system flake, one can specify the specific revision of the overlay as a flake input, for example:<syntaxhighlight lang="nix">  | ||
inputs.emacs-overlay.url = "github:nix-community/emacs-overlay/da2f552d133497abd434006e0cae996c0a282394";  | |||
</syntaxhighlight>This can then be used in the system configuration by using the {{ic|self}} argument:<syntaxhighlight lang="nix">  | |||
nixpkgs.overlays = [ (import self.inputs.emacs-overlay) ];  | |||
This can then be used in the system configuration by using the {{ic|self}} argument:  | </syntaxhighlight>  | ||
=====  Without flakes =====  | =====  Without flakes =====  | ||
For installing one of the unstable branches of   | For installing one of the unstable branches of Emacs, add the following lines to {{ic|/etc/nixos/configuration.nix}}:  | ||
{{file|configuration.nix|nix|<nowiki>  | {{file|configuration.nix|nix|<nowiki>  | ||
{  | {  | ||
| Line 323: | Line 321: | ||
==== Plasma taskbar grouping ====  | ==== Plasma taskbar grouping ====  | ||
To fix/workaround [[Plasma]] grouping   | To fix/workaround [[Plasma]] grouping Emacs incorrectly (confusing emacs.desktop with emacsclient.desktop), perform the following:  | ||
* Open Emacs  | |||
* Right click title bar  | |||
* More Actions > Configure Special Window Settings  | |||
* Add Property > Desktop File Name  | |||
* Set desktop file name to "/home/<USERNAME>/.nix-profile/share/applications/emacs.desktop"  | |||
* Apply the changes  | |||
* Restart Emacs if need  | |||
All Emacs instances should now be grouped together, allowing you to pin it and reliably switch to it with Super+<number>  | |||
==== Spell checking ====  | ==== Spell checking ====  | ||
Because   | Because Emacs expects the dictionaries to be on the same directory as aspell, they won't be picked up. To fix it install the <code>aspellWithDicts</code> package, specifying the dictionaries you want to use:    | ||
{{file|configuration.nix|nix|<nowiki>  | {{file|configuration.nix|nix|<nowiki>  | ||