@@ -516,4 +516,140 @@ to your configuration, rebuild, and run the game with
516516
517517</section>
518518
519+<section xml:id="sec-emacs">
520+
521+<title>Emacs</title>
522+
523+<section xml:id="sec-emacs-config">
524+
525+<title>Configuring Emacs</title>
526+
527+<para>
528+ The Emacs package comes with some extra helpers to make it easier to
529+ configure. <varname>emacsWithPackages</varname> allows you to manage
530+ packages from ELPA. This means that you will not have to install
531+ that packages from within Emacs. For instance, if you wanted to use
532+ <literal>company</literal>, <literal>counsel</literal>,
533+ <literal>flycheck</literal>, <literal>ivy</literal>,
534+ <literal>magit</literal>, <literal>projectile</literal>, and
535+ <literal>use-package</literal> you could use this as a
536+ <filename>~/.config/nixpkgs/config.nix</filename> override:
537+</para>
538+
539+<screen>
540+{
541+ packageOverrides = pkgs: with pkgs; {
542+ myEmacs = emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
543+ company
544+ counsel
545+ flycheck
546+ ivy
547+ magit
548+ projectile
549+ use-package
550+ ]));
551+ }
552+}
553+</screen>
554+
555+<para>
556+ You can install it like any other packages via <command>nix-env -iA
557+ myEmacs</command>. However, this will only install those packages.
558+ It will not <literal>configure</literal> them for us. To do this, we
559+ need to provide a configuration file. Luckily, it is possible to do
560+ this from within Nix! By modifying the above example, we can make
561+ Emacs load a custom config file. The key is to create a package that
562+ provide a <filename>default.el</filename> file in
563+ <filename>/share/emacs/site-start/</filename>. Emacs knows to load
564+ this file automatically when it starts.
565+</para>
566+
567+<screen>
568+{
569+ packageOverrides = pkgs: with pkgs; rec {
570+ myEmacsConfig = writeText "default.el" ''
571+;; initialize package
572+
573+(require 'package)
574+(package-initialize 'noactivate)
575+(eval-when-compile
576+ (require 'use-package))
577+
578+;; load some packages
579+
580+(use-package company
581+ :bind ("<C-tab>" . company-complete)
582+ :diminish company-mode
583+ :commands (company-mode global-company-mode)
584+ :defer 1
585+ :config
586+ (global-company-mode))
587+
588+(use-package counsel
589+ :commands (counsel-descbinds)
590+ :bind (([remap execute-extended-command] . counsel-M-x)
591+ ("C-x C-f" . counsel-find-file)
592+ ("C-c g" . counsel-git)
593+ ("C-c j" . counsel-git-grep)
594+ ("C-c k" . counsel-ag)
595+ ("C-x l" . counsel-locate)
596+ ("M-y" . counsel-yank-pop)))
597+
598+(use-package flycheck
599+ :defer 2
600+ :config (global-flycheck-mode))
601+
602+(use-package ivy
603+ :defer 1
604+ :bind (("C-c C-r" . ivy-resume)
605+ ("C-x C-b" . ivy-switch-buffer)
606+ :map ivy-minibuffer-map
607+ ("C-j" . ivy-call))
608+ :diminish ivy-mode
609+ :commands ivy-mode
610+ :config
611+ (ivy-mode 1))
612+
613+(use-package magit
614+ :defer
615+ :if (executable-find "git")
616+ :bind (("C-x g" . magit-status)
617+ ("C-x G" . magit-dispatch-popup))
618+ :init
619+ (setq magit-completing-read-function 'ivy-completing-read))
620+
621+(use-package projectile
622+ :commands projectile-mode
623+ :bind-keymap ("C-c p" . projectile-command-map)
624+ :defer 5
625+ :config
626+ (projectile-global-mode))
627+ '';
628+ myEmacs = emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
629+ (runCommand "default.el" {} ''
630+mkdir -p $out/share/emacs/site-lisp
631+cp ${myEmacsConfig} $out/share/emacs/site-lisp/default.el
632+'')
633+ company
634+ counsel
635+ flycheck
636+ ivy
637+ magit
638+ projectile
639+ use-package
640+ ]));
641+ };
642+}
643+</screen>
644+
645+<para>
646+ This provides a fairly full Emacs start file. It will load in
647+ addition to the user's presonal config. You can always disable it by
648+ passing <command>-q</command> to the Emacs command.
649+</para>
650+
651+</section>
652+
653+</section>
654+
519655</chapter>