Emacs: Difference between revisions

Layer-09 (talk | contribs)
Changed the structure into a more readable one. Added tree-sitter in the tips and tricks section.
m link to search.nixos.org
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
[https://www.gnu.org/software/emacs/ Emacs] is a versatile and powerful software application, valued for its exceptional extensibility, allowing users to tailor the editor to their specific needs. It boasts an automatic self-documenting behavior, providing users with readily accessible information about functions, variables, and keybindings. The flexibility of Emacs enables it to adapt to various workflows and programming styles, while its syntax awareness enhances coding efficiency across multiple languages. Its extensive package repository surpasses many of its competitors, including [[Vim]] and its fork [[Neovim]], making it one of the most customizable and feature-rich editors available.  
[https://www.gnu.org/software/emacs/ Emacs] is a versatile and powerful software application, valued for its exceptional extensibility, allowing users to tailor the editor to their specific needs. It boasts an automatic self-documenting behavior, providing users with readily accessible information about functions, variables, and keybindings. The flexibility of Emacs enables it to adapt to various workflows and programming styles, while its syntax awareness enhances coding efficiency across multiple languages. Its extensive package repository surpasses many of its competitors, including [[Vim]] and its fork [[Neovim]], making it one of the most customizable and feature-rich editors available.  


For those seeking a more approachable entry point to the Emacs ecosystem, the [https://github.com/hlissner/doom-emacs Doom Emacs] project offers a framework with a beginner-friendly default configuration. Doom Emacs comes pre-configured with popular modules for features such as IDE-like functionality, note-taking, and time management.
For those seeking a more approachable entry point to the Emacs ecosystem, the [https://doomemacs.org Doom Emacs] project offers a framework with a beginner-friendly default configuration. Doom Emacs comes pre-configured with popular modules for features such as IDE-like functionality, note-taking, and time management.
 
There is an official Matrix room for Nix/Emacs: [https://matrix.to/#/#emacs:nixos.org #emacs:nixos.org].


== Installation ==
== Installation ==
Line 64: Line 66:
The home manager options are defined in the following [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.emacs.enable Home Manager Options Manual].
The home manager options are defined in the following [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.emacs.enable Home Manager Options Manual].


The global options are listed on [https://mynixos.com/search?q=nixpkgs%2Foption%2Fservices.emacs MyNixOS].
The global options are listed here [https://search.nixos.org/options?channel=unstable&query=services.emacs services.emacs.*].


==== Installing Packages ====
==== Installing Packages ====
Line 93: Line 95:




</syntaxhighlight>[[Emacs]] 29 [[emacswiki:Tree-sitter|supports Tree-sitter parsers]] when built with the <code>--with-tree-sitter</code> option. The <code>emacsPackages.treesit-grammars</code> fake package makes them accessible to Emacs when using <code>emacs29.pkgs.withPackages</code>:<ref>https://github.com/NixOS/nixpkgs/pull/230751</ref><syntaxhighlight lang="nix">
</syntaxhighlight>
 
==== Tree-sitter ====
[[Emacs]] 29 [[emacswiki:Tree-sitter|supports Tree-sitter parsers]] when built with the <code>--with-tree-sitter</code> option. The <code>emacsPackages.treesit-grammars</code> fake package makes them accessible to Emacs when using <code>emacs29.pkgs.withPackages</code>:<ref>https://github.com/NixOS/nixpkgs/pull/230751</ref><syntaxhighlight lang="nix">
{
{
   pkgs ? import <nixpkgs> { },
   pkgs ? import <nixpkgs> { },
Line 101: Line 106:
])
])
</syntaxhighlight>
</syntaxhighlight>
When using Emacs with tree-sitter support, it's recommended to install both <code>epkgs.tree-sitter-langs</code> and <code>epkgs.treesit-grammars</code>. While <code>treesit-grammars</code> handles the registration of grammars with Emacs's native tree-sitter interface, the actual grammar files will come from <code>tree-sitter-langs</code>. <code>tree-sitter-langs</code> being a MELPA package means it receives regular updates when new grammar versions are released, whereas the grammars in the tree-sitter-grammars package may lag behind in nixpkgs. The combination ensures you get both up-to-date grammars and proper integration with Emacs's built-in tree-sitter support.
<b>Bonus Tip:</b>
<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.:
<syntaxhighlight lang="bash">
/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1  →  /gnu/store/…-foo-0.1
/nix/store/nh4n4yzb1bx7nss2rg342dz44g14m06x-bar-0.2  →  /nix/store/…-bar-0.2
</syntaxhighlight>
located at https://github.com/alezost/pretty-sha-path.el


==== Automatic Package Management ====
==== Automatic Package Management ====
Line 114: Line 134:
       # Optionally provide extra packages not in the configuration file.
       # Optionally provide extra packages not in the configuration file.
       extraEmacsPackages = epkgs: [
       extraEmacsPackages = epkgs: [
         epkgs.use-package;
         epkgs.use-package
       ];
       ];


Line 135: Line 155:
{{file|lambda-line.nix|nix|<nowiki>
{{file|lambda-line.nix|nix|<nowiki>
{
{
   trivialBuild,
   melpaBuild,
   fetchFromGitHub,
   fetchFromGitHub,
   all-the-icons,
   all-the-icons,
}:
}:
trivialBuild rec {
melpaBuild {
   pname = "lambda-line";
   pname = "lambda-line";
   version = "main-23-11-2022";
   version = "0-unstable-2022-11-23";
   src = fetchFromGitHub {
   src = fetchFromGitHub {
     owner = "Lambda-Emacs";
     owner = "Lambda-Emacs";
Line 149: Line 169:
   };
   };
   # elisp dependencies
   # elisp dependencies
   propagatedUserEnvPkgs = [
   packageRequires = [
     all-the-icons
     all-the-icons
   ];
   ];
  buildInputs = propagatedUserEnvPkgs;
}
}
</nowiki>}}
</nowiki>}}
Line 166: Line 185:
         lambda-line = callPackage ./lambda-line.nix {
         lambda-line = callPackage ./lambda-line.nix {
           inherit (pkgs) fetchFromGitHub;
           inherit (pkgs) fetchFromGitHub;
           inherit (epkgs) trivialBuild all-the-icons;
           inherit (epkgs) melpaBuild all-the-icons;
         };
         };
       };
       };
Line 184: Line 203:
           (callPackage ./lambda-line.nix {
           (callPackage ./lambda-line.nix {
             inherit (pkgs) fetchFromGitHub;
             inherit (pkgs) fetchFromGitHub;
             inherit (epkgs) trivialBuild all-the-icons;
             inherit (epkgs) melpaBuild all-the-icons;
           };)  
           };)  
       ]))
       ]))
Line 196: Line 215:


{{file|default.nix|nix|<nowiki>
{{file|default.nix|nix|<nowiki>
{ trivialBuild
{ melpaBuild
, lib
, lib
, fetchFromGitHub
, fetchFromGitHub
Line 202: Line 221:
}:
}:


trivialBuild {
melpaBuild {
   pname = "...";
   pname = "...";
   version = "...";
   version = "...";
Line 210: Line 229:
     repo = "...";
     repo = "...";
     rev = "...";
     rev = "...";
     sha256 = "...";
     hash = "...";
   };
   };


Line 219: Line 238:
   meta = {
   meta = {
     description = "...";
     description = "...";
     license = lib.licenses.gpl3;
     license = lib.licenses.gpl3Plus;
    platforms = lib.platforms.all;
   };
   };
}
}
Line 285: Line 303:
             url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/fix-window-role.patch";
             url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/fix-window-role.patch";
             sha256 = "0c41rgpi19vr9ai740g09lka3nkjk48ppqyqdnncjrkfgvm2710z";
             sha256 = "0c41rgpi19vr9ai740g09lka3nkjk48ppqyqdnncjrkfgvm2710z";
          })
          # Use poll instead of select to get file descriptors
          (fetchpatch {
            url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-29/poll.patch";
            sha256 = "0j26n6yma4n5wh4klikza6bjnzrmz6zihgcsdx36pn3vbfnaqbh5";
           })
           })
           # Enable rounded window with no decoration
           # Enable rounded window with no decoration
Line 336: Line 349:
== References ==
== References ==
[[Category:Applications]]
[[Category:Applications]]
[[Category:CLI Applications]]
[[Category:NixOS Manual]]
[[Category:NixOS Manual]]
[[Category:Text Editor]]