emacs.nix 43.9 KB
Newer Older
1
{ config, pkgs, sources, ... }:
Robert Helgesson's avatar
Robert Helgesson committed
2

3 4
let

5 6
  nurNoPkgs = import (import ../nix/sources.nix).nur { };
  # nurNoPkgs.repos.rycee = import ../../nur-expressions { pkgs = throw "nixpkgs eval"; };
7 8 9

in

Robert Helgesson's avatar
Robert Helgesson committed
10
{
11 12
  imports = [
    nurNoPkgs.repos.rycee.hmModules.emacs-init
Robert Helgesson's avatar
Robert Helgesson committed
13
    nurNoPkgs.repos.rycee.hmModules.emacs-notmuch
14 15
  ];

Robert Helgesson's avatar
Robert Helgesson committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29
  nixpkgs.overlays = [
    (import sources.emacs-overlay)
    (self: super: {
      emacs27 = super.emacs27.overrideAttrs (old: {
        patches = old.patches or [] ++ [
          # Fix "Attempt to shape unibyte text" error.
          (pkgs.fetchpatch {
            url = "https://github.com/emacs-mirror/emacs/commit/fe903c5ab7354b97f80ecf1b01ca3ff1027be446.patch";
            sha256 = "0zldjs8nx26x7r8pwjc995lvpg06iv52rq4cy1w38hxhy7vp8lp3";
          })
        ];
      });
    })
  ];
Robert Helgesson's avatar
Robert Helgesson committed
30 31 32 33 34

  programs.emacs.init = {
    enable = true;
    recommendedGcSettings = true;

35 36 37 38 39 40
    earlyInit = ''
      ;; Disable some GUI distractions. We set these manually to avoid starting
      ;; the corresponding minor modes.
      (push '(menu-bar-lines . 0) default-frame-alist)
      (push '(tool-bar-lines . nil) default-frame-alist)
      (push '(vertical-scroll-bars . nil) default-frame-alist)
Robert Helgesson's avatar
Robert Helgesson committed
41 42 43 44

      ;; Set up fonts early.
      (set-face-attribute 'default
                          nil
45 46
                          :height 80
                          :family "Fantasque Sans Mono")
Robert Helgesson's avatar
Robert Helgesson committed
47 48 49
      (set-face-attribute 'variable-pitch
                          nil
                          :family "DejaVu Sans")
50 51 52 53 54 55 56 57 58 59 60 61
    '';

    prelude = ''
      ;; Disable startup message.
      (setq inhibit-startup-screen t
            inhibit-startup-echo-area-message (user-login-name))

      (setq initial-major-mode 'fundamental-mode
            initial-scratch-message nil)

      ;; Don't blink the cursor.
      (setq blink-cursor-mode nil)
Robert Helgesson's avatar
Robert Helgesson committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

      ;; Set frame title.
      (setq frame-title-format
            '("" invocation-name ": "(:eval
                                      (if (buffer-file-name)
                                          (abbreviate-file-name (buffer-file-name))
                                        "%b"))))

      ;; Accept 'y' and 'n' rather than 'yes' and 'no'.
      (defalias 'yes-or-no-p 'y-or-n-p)

      ;; Don't want to move based on visual line.
      (setq line-move-visual nil)

      ;; Stop creating backup and autosave files.
      (setq make-backup-files nil
            auto-save-default nil)

80 81 82
      ;; Default is 4k, which is too low for LSP.
      (setq read-process-output-max (* 1024 1024))

83
      ;; Always show line and column number in the mode line.
Robert Helgesson's avatar
Robert Helgesson committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
      (line-number-mode)
      (column-number-mode)

      ;; Enable some features that are disabled by default.
      (put 'narrow-to-region 'disabled nil)

      ;; Typically, I only want spaces when pressing the TAB key. I also
      ;; want 4 of them.
      (setq-default indent-tabs-mode nil
                    tab-width 4
                    c-basic-offset 4)

      ;; Trailing white space are banned!
      (setq-default show-trailing-whitespace t)

      ;; Make a reasonable attempt at using one space sentence separation.
      (setq sentence-end "[.?!][]\"')}]*\\($\\|[ \t]\\)[ \t\n]*"
            sentence-end-double-space nil)

      ;; I typically want to use UTF-8.
      (prefer-coding-system 'utf-8)

      ;; Nicer handling of regions.
      (transient-mark-mode 1)

      ;; Make moving cursor past bottom only scroll a single line rather
      ;; than half a page.
      (setq scroll-step 1
            scroll-conservatively 5)

      ;; Enable highlighting of current line.
      (global-hl-line-mode 1)

      ;; Improved handling of clipboard in GNU/Linux and otherwise.
      (setq select-enable-clipboard t
            select-enable-primary t
            save-interprogram-paste-before-kill t)

      ;; Pasting with middle click should insert at point, not where the
      ;; click happened.
      (setq mouse-yank-at-point t)

      ;; Enable a few useful commands that are initially disabled.
      (put 'upcase-region 'disabled nil)
      (put 'downcase-region 'disabled nil)

      (setq custom-file (locate-user-emacs-file "custom.el"))
      (load custom-file)

      ;; When finding file in non-existing directory, offer to create the
      ;; parent directory.
      (defun with-buffer-name-prompt-and-make-subdirs ()
        (let ((parent-directory (file-name-directory buffer-file-name)))
          (when (and (not (file-exists-p parent-directory))
                     (y-or-n-p (format "Directory `%s' does not exist! Create it? " parent-directory)))
            (make-directory parent-directory t))))

      (add-to-list 'find-file-not-found-functions #'with-buffer-name-prompt-and-make-subdirs)

      ;; Don't want to complete .hi files.
      (add-to-list 'completion-ignored-extensions ".hi")

146 147 148
      (defun rah-disable-trailing-whitespace-mode ()
        (setq show-trailing-whitespace nil))

Robert Helgesson's avatar
Robert Helgesson committed
149
      ;; Shouldn't highlight trailing spaces in terminal mode.
150 151
      (add-hook 'term-mode #'rah-disable-trailing-whitespace-mode)
      (add-hook 'term-mode-hook #'rah-disable-trailing-whitespace-mode)
152 153 154 155 156 157 158 159 160 161 162 163

      (defun rah-prog-mode-setup ()
        ;; Use a bit wider fill column width in programming modes
        ;; since we often work with indentation to start with.
        (setq fill-column 80))

      (add-hook 'prog-mode-hook #'rah-prog-mode-setup)

      (defun rah-sort-lines-ignore-case ()
        (interactive)
        (let ((sort-fold-case t))
          (call-interactively 'sort-lines)))
Robert Helgesson's avatar
Robert Helgesson committed
164 165 166 167 168 169 170 171 172
    '';

    usePackage = {
      adoc-mode = {
        enable = true;
        mode = [
          ''"\\.txt\\'"''
          ''"\\.adoc\\'"''
        ];
173 174 175
        hook = [''
          (adoc-mode . (lambda ()
                         (visual-line-mode)
176
                         (buffer-face-mode)))
177 178 179 180
        ''];
        config = ''
          (set-face-background 'markup-verbatim-face nil)
        '';
Robert Helgesson's avatar
Robert Helgesson committed
181 182
      };

183 184 185 186 187
      ansi-color = {
        enable = true;
        command = [ "ansi-color-apply-on-region" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
188 189 190 191 192 193
      autorevert = {
        enable = true;
        diminish = [ "auto-revert-mode" ];
        command = [ "auto-revert-mode" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
194 195
      back-button = {
        enable = true;
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
        package = epkgs: epkgs.back-button.overrideAttrs (drv:
          let isNotUcsUtils = p: (builtins.parseDrvName p.name).name != "emacs-ucs-utils";
          in {
            patches = [
              # ucs-utils makes Emacs shutdown very slow, remove its use through this patch.
              (pkgs.fetchpatch {
                name = "remove-ucs-utils.patch";
                url = "https://github.com/rutger-eiq/back-button/commit/164cf6e2a536a8da6e45c0365922ea1887acde79.patch";
                sha256 = "0czii9hdk7l6j3palpb68377phms9jw9ldb51apjhbmscjyr55q3";
              })
            ];

            # Also need to remove ucs-utils from the various build inputs.
            buildInputs = builtins.filter isNotUcsUtils drv.buildInputs;
            propagatedBuildInputs = builtins.filter isNotUcsUtils drv.propagatedBuildInputs;
            propagatedUserEnvPkgs = builtins.filter isNotUcsUtils drv.propagatedUserEnvPkgs;
          });
213
        defer = 2;
Robert Helgesson's avatar
Robert Helgesson committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
        diminish = [ "back-button-mode" ];
        command = [ "back-button-mode" ];
        config = ''
          (back-button-mode 1)

          ;; Make mark ring larger.
          (setq global-mark-ring-max 50)
        '';
      };

      base16-theme = {
        enable = true;
        config = "(load-theme 'base16-tomorrow-night t)";
      };

Robert Helgesson's avatar
Robert Helgesson committed
229 230 231 232 233 234 235 236
      calc = {
        enable = true;
        command = [ "calc" ];
        config = ''
          (setq calc-date-format '(YYYY "-" MM "-" DD " " Www " " hh ":" mm ":" ss))
        '';
      };

237 238 239 240 241 242 243 244 245 246 247 248 249 250
      # From https://github.com/mlb-/emacs.d/blob/a818e80f7790dffa4f6a775987c88691c4113d11/init.el#L472-L482
      compile = {
        enable = true;
        defer = true;
        after = [ "ansi-color" ];
        hook = [
          ''
            (compilation-filter . (lambda ()
                                    (when (eq major-mode 'compilation-mode)
                                      (ansi-color-apply-on-region compilation-filter-start (point-max)))))
          ''
        ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
251
      beacon = {
Robert Helgesson's avatar
Robert Helgesson committed
252
        enable = false;
Robert Helgesson's avatar
Robert Helgesson committed
253 254 255 256 257 258
        command = [ "beacon-mode" ];
        diminish = [ "beacon-mode" ];
        defer = 1;
        config = "(beacon-mode 1)";
      };

259 260 261 262
      browse-at-remote = {
        command = [ "browse-at-remote" ];
      };

263 264 265 266 267 268
      cc-mode = {
        enable = true;
        defer = true;
        hook = [
          ''
            (c-mode-common . (lambda ()
269 270
                               (subword-mode)
                               (c-set-offset 'arglist-intro '++)))
271 272 273 274
          ''
        ];
      };

275 276 277 278
      csharp-mode = {
        mode = [ ''"\\.cs\\'"'' ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
279 280 281 282 283 284 285
      deadgrep = {
        enable = true;
        bind = {
          "C-x f" = "deadgrep";
        };
      };

286 287 288 289 290
      direnv = {
        enable = true;
        command = [ "direnv-mode" "direnv-update-environment" ];
      };

291
      dhall-mode.enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
292

293
      dockerfile-mode.enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
294

Robert Helgesson's avatar
Robert Helgesson committed
295 296 297
      doom-modeline = {
        enable = true;
        hook = [ "(after-init . doom-modeline-mode)" ];
298 299 300
        config = ''
          (setq doom-modeline-buffer-file-name-style 'truncate-except-project)
        '';
Robert Helgesson's avatar
Robert Helgesson committed
301 302
      };

Robert Helgesson's avatar
Robert Helgesson committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
      drag-stuff = {
        enable = true;
        bind = {
          "M-<up>" = "drag-stuff-up";
          "M-<down>" = "drag-stuff-down";
        };
      };

      ediff = {
        enable = true;
        defer = true;
        config = ''
          (setq ediff-window-setup-function 'ediff-setup-windows-plain)
        '';
      };

Robert Helgesson's avatar
Robert Helgesson committed
319 320 321 322 323 324
      eldoc = {
        enable = true;
        diminish = [ "eldoc-mode" ];
        command = [ "eldoc-mode" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
325 326 327 328 329 330 331 332 333 334 335
      # Enable Electric Indent mode to do automatic indentation on RET.
      electric = {
        enable = true;
        command = [ "electric-indent-local-mode" ];
        hook = [
          "(prog-mode . electric-indent-mode)"

          # Disable for some modes.
          "(nix-mode . (lambda () (electric-indent-local-mode -1)))"
        ];
      };
Robert Helgesson's avatar
Robert Helgesson committed
336

337
      elm-mode.enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
338 339 340 341 342 343 344 345

      etags = {
        enable = true;
        defer = true;
        # Avoid spamming reload requests of TAGS files.
        config = "(setq tags-revert-without-query t)";
      };

Robert Helgesson's avatar
Robert Helgesson committed
346 347 348 349 350 351 352 353 354 355
      gcmh = {
        enable = true;
        defer = 1;
        command = [ "gcmh-mode" ];
        config = ''
          (setq gcmh-verbose t)
          (gcmh-mode)
        '';
      };

Robert Helgesson's avatar
Robert Helgesson committed
356 357
      ggtags = {
        enable = true;
358
        defer = true;
Robert Helgesson's avatar
Robert Helgesson committed
359 360 361 362 363 364 365 366 367 368 369 370 371
        diminish = [ "ggtags-mode" ];
        command = [ "ggtags-mode" ];
      };

      groovy-mode = {
        enable = true;
        mode = [
          ''"\\.gradle\\'"''
          ''"\\.groovy\\'"''
          ''"Jenkinsfile\\'"''
        ];
      };

372 373 374 375 376
      idris-mode = {
        enable = true;
        mode = [ ''"\\.idr\\'"'' ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
377 378
      ispell = {
        enable = true;
379
        defer = 1;
Robert Helgesson's avatar
Robert Helgesson committed
380 381
      };

382 383 384 385 386 387 388 389 390 391 392
      js = {
        enable = true;
        mode = [
          ''("\\.js\\'" . js-mode)''
          ''("\\.json\\'" . js-mode)''
        ];
        config = ''
          (setq js-indent-level 2)
        '';
      };

Robert Helgesson's avatar
Robert Helgesson committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
      # See https://github.com/mickeynp/ligature.el
      ligature = {
        enable = true;
        package = epkgs: epkgs.trivialBuild {
          pname = "ligature.el";
          src = sources."ligature.el";
          preferLocalBuild = true;
          allowSubstitutes = false;
        };
        command = [ "ligature-set-ligatures" ];
        hook = [
          ''(nxml-mode . ligature-mode)''
          ''(prog-mode . ligature-mode)''
        ];
        config = ''
          ;; Prepare Fantasque Sans Mono ligatures in some modes.
          (ligature-set-ligatures 'nxml-mode '("<!--" "-->"))
          (ligature-set-ligatures 'prog-mode '("::" "!=" "!==" "-->" "->" "->>" "-<" "-<<" "//"
                                               "&&" "||" "|>" "==" "===" "==>" "=>" "=>>" "<="
                                               "=<<" "=/=" ">-" ">=" ">=>" ">>" ">>-" ">>="
                                               "<|" "<|>" "<-" "<--" "<->" "<=" "<==" "<=>"
                                               "<=<" "<>" "<<" "<<-" "<<=" "<~" "<~~" "~>"
                                               "~~" "~~>"))
        '';
      };

419 420 421 422 423
      notifications = {
        enable = true;
        command = [ "notifications-notify" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
      notmuch = {
        command = [ "notmuch" "notmuch-show-tag" "notmuch-search-tag" ];
        hook = [
          ''(notmuch-show . rah-disable-trailing-whitespace-mode)''
        ];
        bindLocal = {
          notmuch-show-mode-map = {
            "S" = "rah-notmuch-show-tag-spam";
            "d" = "rah-notmuch-show-tag-deleted";
          };
          notmuch-search-mode-map = {
            "S" = "rah-notmuch-search-tag-spam";
            "d" = "rah-notmuch-search-tag-deleted";
          };
        };
        config =
          let
            listTags = ts: "(list ${toString (map (t: ''"${t}"'') ts)})";
            spamTags = listTags ["+spam" "-inbox"];
            deletedTags = listTags ["+deleted" "-inbox"];
          in
            ''
              (defun rah-notmuch-show-tag-spam ()
                (interactive)
                (notmuch-show-tag ${spamTags}))

              (defun rah-notmuch-show-tag-deleted ()
                (interactive)
                (notmuch-show-tag ${deletedTags}))

              (defun rah-notmuch-search-tag-spam (&optional beg end)
                (interactive)
                (notmuch-search-tag ${spamTags} beg end))

              (defun rah-notmuch-search-tag-deleted (&optional beg end)
                (interactive)
                (notmuch-search-tag ${deletedTags} beg end))

              (setq notmuch-show-logo nil)
            '';
      };

Robert Helgesson's avatar
Robert Helgesson committed
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
      flyspell = {
        enable = true;
        diminish = [ "flyspell-mode" ];
        command = [ "flyspell-mode" "flyspell-prog-mode" ];
        hook = [
          # Spell check in text and programming mode.
          "(text-mode . flyspell-mode)"
          "(prog-mode . flyspell-prog-mode)"
        ];
        config = ''
          ;; In flyspell I typically do not want meta-tab expansion
          ;; since it often conflicts with the major mode. Also,
          ;; make it a bit less verbose.
          (setq flyspell-issue-message-flag nil
                flyspell-issue-welcome-flag nil
                flyspell-use-meta-tab nil)
        '';
      };

      # Remember where we where in a previously visited file. Built-in.
      saveplace = {
        enable = true;
488
        defer = 1;
Robert Helgesson's avatar
Robert Helgesson committed
489 490 491 492 493 494 495 496 497
        config = ''
          (setq-default save-place t)
          (setq save-place-file (locate-user-emacs-file "places"))
        '';
      };

      # More helpful buffer names. Built-in.
      uniquify = {
        enable = true;
498
        defer = 5;
Robert Helgesson's avatar
Robert Helgesson committed
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
        config = ''
          (setq uniquify-buffer-name-style 'post-forward)
        '';
      };

      # Hook up hippie expand.
      hippie-exp = {
        enable = true;
        bind = {
          "M-?" = "hippie-expand";
        };
      };

      which-key = {
        enable = true;
514
        command = [ "which-key-mode" "which-key-add-major-mode-key-based-replacements" ];
Robert Helgesson's avatar
Robert Helgesson committed
515
        diminish = [ "which-key-mode" ];
516
        defer = 3;
Robert Helgesson's avatar
Robert Helgesson committed
517 518 519 520 521 522 523 524
        config = "(which-key-mode)";
      };

      # Enable winner mode. This global minor mode allows you to
      # undo/redo changes to the window configuration. Uses the
      # commands C-c <left> and C-c <right>.
      winner = {
        enable = true;
525
        defer = 2;
Robert Helgesson's avatar
Robert Helgesson committed
526 527 528 529 530 531
        config = "(winner-mode 1)";
      };

      writeroom-mode = {
        enable = true;
        command = [ "writeroom-mode" ];
532 533 534 535 536 537
        bindLocal = {
          writeroom-mode-map = {
            "M-[" = "writeroom-decrease-width";
            "M-]" = "writeroom-increase-width";
            "M-'" = "writeroom-toggle-mode-line";
          };
Robert Helgesson's avatar
Robert Helgesson committed
538 539
        };
        hook = [ "(writeroom-mode . visual-line-mode)" ];
540 541 542
        config = ''
          (setq writeroom-bottom-divider-width 0)
        '';
Robert Helgesson's avatar
Robert Helgesson committed
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
      };

      buffer-move = {
        enable = true;
        bind = {
          "C-S-<up>"    = "buf-move-up";
          "C-S-<down>"  = "buf-move-down";
          "C-S-<left>"  = "buf-move-left";
          "C-S-<right>" = "buf-move-right";
        };
      };

      ivy = {
        enable = true;
        demand = true;
        diminish = [ "ivy-mode" ];
        command = [ "ivy-mode" ];
        config = ''
          (setq ivy-use-virtual-buffers t
                ivy-count-format "%d/%d "
563
                ivy-virtual-abbreviate 'full)
564

Robert Helgesson's avatar
Robert Helgesson committed
565 566 567 568
          (ivy-mode 1)
        '';
      };

Robert Helgesson's avatar
Robert Helgesson committed
569 570 571 572 573 574
      ivy-hydra = {
        enable = true;
        defer = true;
        after = [ "ivy" "hydra" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
575 576 577 578 579 580 581 582 583 584 585
      ivy-xref = {
        enable = true;
        after = [ "ivy" "xref" ];
        command = [ "ivy-xref-show-xrefs" ];
        config = ''
          (setq xref-show-xrefs-function #'ivy-xref-show-xrefs)
        '';
      };

      swiper = {
        enable = true;
586
        command = [ "swiper" "swiper-all" "swiper-isearch" ];
Robert Helgesson's avatar
Robert Helgesson committed
587
        bind = {
588
          "C-s" = "swiper-isearch";
Robert Helgesson's avatar
Robert Helgesson committed
589 590 591 592 593 594 595 596 597 598 599 600
        };
      };

      # Lets counsel do prioritization. A fork of smex.
      amx = {
        enable = true;
        command = [ "amx-initialize" ];
      };

      counsel = {
        enable = true;
        bind = {
601
          "C-x C-d" = "counsel-dired-jump";
Robert Helgesson's avatar
Robert Helgesson committed
602
          "C-x C-f" = "counsel-find-file";
603
          "C-x M-f" = "counsel-fzf";
Robert Helgesson's avatar
Robert Helgesson committed
604 605 606 607 608
          "C-x C-r" = "counsel-recentf";
          "C-x C-y" = "counsel-yank-pop";
          "M-x" = "counsel-M-x";
        };
        diminish = [ "counsel-mode" ];
609 610 611 612 613 614 615
        config =
          let
            fd = "${pkgs.fd}/bin/fd";
            fzf = "${pkgs.fzf}/bin/fzf";
          in ''
            (setq counsel-fzf-cmd "${fd} --type f | ${fzf} -f \"%s\"")
          '';
Robert Helgesson's avatar
Robert Helgesson committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
      };

      nyan-mode = {
        enable = true;
        command = [ "nyan-mode" ];
        config = ''
          (setq nyan-wavy-trail t)
        '';
      };

      string-inflection = {
        enable = true;
        bind = {
          "C-c C-u" = "string-inflection-all-cycle";
        };
      };

      # Configure magit, a nice mode for the git SCM.
      magit = {
        enable = true;
        bind = {
          "C-c g" = "magit-status";
        };
        config = ''
          (setq magit-completing-read-function 'ivy-completing-read)
          (add-to-list 'git-commit-style-convention-checks
                       'overlong-summary-line)
        '';
      };

      git-messenger = {
        enable = true;
        bind = {
          "C-x v p" = "git-messenger:popup-message";
        };
      };

      multiple-cursors = {
        enable = true;
        bind = {
          "C-S-c C-S-c" = "mc/edit-lines";
          "C-c m" = "mc/mark-all-like-this";
          "C->" = "mc/mark-next-like-this";
          "C-<" = "mc/mark-previous-like-this";
        };
      };

663 664 665 666 667
      nix-sandbox = {
        enable = true;
        command = [ "nix-current-sandbox" "nix-shell-command" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
668 669
      avy = {
        enable = true;
670 671 672 673 674
        bind = {
          "M-j" = "avy-goto-word-or-subword-1";
        };
        config = ''
          (setq avy-all-windows t)
Robert Helgesson's avatar
Robert Helgesson committed
675 676 677 678 679
        '';
      };

      undo-tree = {
        enable = true;
680
        defer = 1;
Robert Helgesson's avatar
Robert Helgesson committed
681 682 683 684
        diminish = [ "undo-tree-mode" ];
        command = [ "global-undo-tree-mode" ];
        config = ''
          (setq undo-tree-visualizer-relative-timestamps t
685 686
                undo-tree-visualizer-timestamps t
                undo-tree-enable-undo-in-region t)
Robert Helgesson's avatar
Robert Helgesson committed
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
          (global-undo-tree-mode)
        '';
      };

      # Configure AUCTeX.
      latex = {
        enable = true;
        package = epkgs: epkgs.auctex;
        mode = [ ''("\\.tex\\'" . latex-mode)'' ];
        hook = [
          ''
            (LaTeX-mode
             . (lambda ()
                 (turn-on-reftex)       ; Hook up AUCTeX with RefTeX.
                 (auto-fill-mode)
                 (define-key LaTeX-mode-map [adiaeresis] "\\\"a")))
          ''
        ];
        config = ''
          (setq TeX-PDF-mode t
                TeX-auto-save t
                TeX-parse-self t
                TeX-output-view-style '(("^pdf$" "." "evince %o")
                                        ( "^ps$" "." "evince %o")
                                        ("^dvi$" "." "evince %o")))

          ;; Add Glossaries command. See
          ;; http://tex.stackexchange.com/a/36914
          (eval-after-load "tex"
            '(add-to-list
              'TeX-command-list
              '("Glossaries"
                "makeglossaries %s"
                TeX-run-command
                nil
                t
                :help "Create glossaries file")))
        '';
      };

727 728 729 730 731 732 733 734 735 736 737 738 739
      lsp-elm = {
        enable = true;
        defer = true;
        hook = [ "(elm-mode . lsp)" ];
        config = ''
          (setq lsp-elm-elm-language-server-path
                  "${pkgs.elmPackages.elm-language-server}/bin/elm-language-server")
        '';
      };

      lsp-ivy = {
        enable = true;
        after = [ "lsp-mode" ];
740
        command = [ "lsp-ivy-workspace-symbol" ];
741 742
      };

Robert Helgesson's avatar
Robert Helgesson committed
743 744 745 746 747 748 749 750 751 752 753 754
      lsp-haskell = {
        enable = true;
        defer = true;
        hook = [
         ''
           (haskell-mode . (lambda ()
                             (direnv-update-environment)
                             (lsp)))
         ''
        ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
755 756
      lsp-ui = {
        enable = true;
757
        command = [ "lsp-ui-mode" ];
758 759 760 761 762
        bindLocal = {
          lsp-mode-map = {
            "C-c r d" = "lsp-ui-doc-glance";
            "C-c f s" = "lsp-ui-find-workspace-symbol";
          };
Robert Helgesson's avatar
Robert Helgesson committed
763
        };
Robert Helgesson's avatar
Robert Helgesson committed
764 765 766 767
        config = ''
          (setq lsp-ui-sideline-enable t
                lsp-ui-sideline-show-symbol nil
                lsp-ui-sideline-show-hover nil
768
                lsp-ui-sideline-show-code-actions nil
769 770 771 772 773
                lsp-ui-sideline-update-mode 'point)
          (setq lsp-ui-doc-enable nil
                lsp-ui-doc-position 'at-point
                lsp-ui-doc-max-width 120
                lsp-ui-doc-max-height 15)
Robert Helgesson's avatar
Robert Helgesson committed
774 775 776 777 778 779 780 781
        '';
      };

      lsp-ui-flycheck = {
        enable = true;
        after = [ "flycheck" "lsp-ui" ];
      };

782 783 784 785 786 787 788 789 790 791 792 793 794
      lsp-completion = {
        enable = true;
        after = [ "lsp-mode" ];
        config = ''
          (setq lsp-completion-enable-additional-text-edit nil)
        '';
      };

      lsp-diagnostics = {
        enable = true;
        after = [ "lsp-mode" ];
      };

795 796 797
      lsp-mode = {
        enable = true;
        command = [ "lsp" ];
798
        after = [ "company" "flycheck" ];
799
        hook = [ "(lsp-mode . lsp-enable-which-key-integration)" ];
800 801 802 803 804 805 806 807
        bindLocal = {
          lsp-mode-map = {
            "C-c r r" = "lsp-rename";
            "C-c r f" = "lsp-format-buffer";
            "C-c r g" = "lsp-format-region";
            "C-c r a" = "lsp-execute-code-action";
            "C-c f r" = "lsp-find-references";
          };
808
        };
809 810 811
        init = ''
          (setq lsp-keymap-prefix "C-c l")
        '';
812
        config = ''
813 814 815 816 817
          (setq lsp-diagnostics-provider :flycheck
                lsp-eldoc-render-all nil
                lsp-modeline-code-actions-enable nil
                lsp-modeline-diagnostics-enable nil
                lsp-modeline-workspace-status-enable nil)
818
          (define-key lsp-mode-map (kbd "C-c l") lsp-command-map)
819 820 821
        '';
      };

822 823 824 825 826
      lsp-modeline = {
        enable = true;
        after = [ "lsp-mode" ];
      };

827 828
      lsp-java = {
        enable = true;
829 830
        defer = true;
        hook = [ "(java-mode . lsp)" ];
831 832 833 834 835 836
        bindLocal = {
          java-mode-map = {
            "C-c r o" = "lsp-java-organize-imports";
          };
        };
        config = ''
837 838
          (setq lsp-java-save-actions-organize-imports nil
                lsp-java-completion-favorite-static-members
839 840 841 842 843 844 845 846 847 848
                    ["org.assertj.core.api.Assertions.*"
                     "org.assertj.core.api.Assumptions.*"
                     "org.hamcrest.Matchers.*"
                     "org.junit.Assert.*"
                     "org.junit.Assume.*"
                     "org.junit.jupiter.api.Assertions.*"
                     "org.junit.jupiter.api.Assumptions.*"
                     "org.junit.jupiter.api.DynamicContainer.*"
                     "org.junit.jupiter.api.DynamicTest.*"
                     "org.mockito.ArgumentMatchers.*"])
849 850
        '';
      };
851

852 853
      lsp-rust = {
        enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
854
        defer = true;
855 856
        hook = [
          ''
857 858 859
            (rust-mode . (lambda ()
                           (direnv-update-environment)
                           (lsp)))
860 861 862 863
          ''
        ];
      };

864 865
      lsp-treemacs = {
        enable = true;
866 867
        after = [ "lsp-mode" ];
        command = [ "lsp-treemacs-errors-list" ];
868 869 870
      };

      dap-mode = {
Robert Helgesson's avatar
Robert Helgesson committed
871
        enable = true;
872
        after = [ "lsp-mode" ];
873
        command = [ "dap-mode" "dap-auto-configure-mode" ];
874
        config = ''
875
          (dap-auto-configure-mode)
Robert Helgesson's avatar
Robert Helgesson committed
876 877 878
        '';
      };

Robert Helgesson's avatar
Robert Helgesson committed
879 880 881 882 883
      dap-mouse = {
        enable = true;
        command = [ "dap-tooltip-mode" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
884
      dap-ui = {
Robert Helgesson's avatar
Robert Helgesson committed
885
        enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
886 887 888
        after = [ "dap-mode" ];
        command = [ "dap-ui-mode" ];
        config = ''
889 890 891 892 893
          (dap-ui-mode t)
        '';
      };

      dap-java = {
Robert Helgesson's avatar
Robert Helgesson committed
894
        enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
895
        after = [ "dap-mode" "lsp-java" ];
896 897
      };

Robert Helgesson's avatar
Robert Helgesson committed
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
      #  Setup RefTeX.
      reftex = {
        enable = true;
        defer = true;
        config = ''
          (setq reftex-default-bibliography '("~/research/bibliographies/main.bib")
                reftex-cite-format 'natbib
                reftex-plug-into-AUCTeX t)
        '';
      };

      haskell-mode = {
        enable = true;
        mode = [
          ''("\\.hs\\'" . haskell-mode)''
          ''("\\.hsc\\'" . haskell-mode)''
          ''("\\.c2hs\\'" . haskell-mode)''
          ''("\\.cpphs\\'" . haskell-mode)''
Robert Helgesson's avatar
Robert Helgesson committed
916
          ''("\\.lhs\\'" . haskell-literate-mode)''
Robert Helgesson's avatar
Robert Helgesson committed
917 918
        ];
        hook = [
Robert Helgesson's avatar
Robert Helgesson committed
919
          ''(haskell-mode . subword-mode)''
Robert Helgesson's avatar
Robert Helgesson committed
920 921
        ];
        config = ''
Robert Helgesson's avatar
Robert Helgesson committed
922
          (setq tab-width 2)
Robert Helgesson's avatar
Robert Helgesson committed
923

Robert Helgesson's avatar
Robert Helgesson committed
924
          (setq haskell-process-log t
Robert Helgesson's avatar
Robert Helgesson committed
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
                haskell-notify-p t)

          (setq haskell-process-args-cabal-repl
                '("--ghc-options=+RTS -M500m -RTS -ferror-spans -fshow-loaded-modules"))
        '';
      };

      haskell-cabal = {
        enable = true;
        mode = [ ''("\\.cabal\\'" . haskell-cabal-mode)'' ];
        bindLocal = {
          haskell-cabal-mode-map = {
            "C-c C-c" = "haskell-process-cabal-build";
            "C-c c" = "haskell-process-cabal";
            "C-c C-b" = "haskell-interactive-bring";
          };
        };
      };

944 945 946 947 948
      haskell-doc = {
        enable = true;
        command = [ "haskell-doc-current-info" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
949 950
      markdown-mode = {
        enable = true;
951 952 953
        config = ''
          (setq markdown-command "${pkgs.pandoc}/bin/pandoc")
        '';
Robert Helgesson's avatar
Robert Helgesson committed
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
      };

      pandoc-mode = {
        enable = true;
        after = [ "markdown-mode" ];
        hook = [ "markdown-mode" ];
        bindLocal = {
          markdown-mode-map = {
            "C-c C-c" = "pandoc-run-pandoc";
          };
        };
      };

      nix-mode = {
        enable = true;
969
        hook = [ "(nix-mode . subword-mode)" ];
Robert Helgesson's avatar
Robert Helgesson committed
970 971
      };

972 973 974
      # Use ripgrep for fast text search in projects. I usually use
      # this through Projectile.
      ripgrep = {
Robert Helgesson's avatar
Robert Helgesson committed
975
        enable = true;
976
        command = [ "ripgrep-regexp" ];
Robert Helgesson's avatar
Robert Helgesson committed
977 978 979 980 981
      };

      org = {
        enable = true;
        bind = {
982 983 984 985
          "C-c o c" = "org-capture";
          "C-c o a" = "org-agenda";
          "C-c o l" = "org-store-link";
          "C-c o b" = "org-switchb";
Robert Helgesson's avatar
Robert Helgesson committed
986 987 988 989 990 991 992 993 994 995 996 997
        };
        hook = [
          ''
            (org-mode
             . (lambda ()
                 (add-hook 'completion-at-point-functions
                           'pcomplete-completions-at-point nil t)))
          ''
        ];
        config = ''
          ;; Some general stuff.
          (setq org-reverse-note-order t
998
                org-use-fast-todo-selection t
999
                org-adapt-indentation nil
1000
                org-hide-leading-stars t
1001
                org-hide-emphasis-markers t)
Robert Helgesson's avatar
Robert Helgesson committed
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019

          (setq org-tag-alist rah-org-tag-alist)

          ;; Add some todo keywords.
          (setq org-todo-keywords
                '((sequence "TODO(t)"
                            "STARTED(s!)"
                            "WAITING([email protected]/!)"
                            "DELEGATED(@!)"
                            "|"
                            "DONE(d!)"
                            "CANCELED([email protected]!)")))

          ;; Setup org capture.
          (setq org-default-notes-file (rah-org-file "capture"))

          ;; Active Org-babel languages
          (org-babel-do-load-languages 'org-babel-load-languages
1020 1021
                                       '((plantuml . t)
                                         (http . t)
1022 1023 1024
                                         (shell . t)
                                         (sql . t)
                                         (verb . t)))
Robert Helgesson's avatar
Robert Helgesson committed
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054

          ;; Unfortunately org-mode tends to take over keybindings that
          ;; start with C-c.
          (unbind-key "C-c SPC" org-mode-map)
          (unbind-key "C-c w" org-mode-map)
        '';
      };

      org-agenda = {
        enable = true;
        after = [ "org" ];
        defer = true;
        config = ''
          ;; Set up agenda view.
          (setq org-agenda-files (rah-all-org-files)
                org-agenda-span 5
                org-deadline-warning-days 14
                org-agenda-show-all-dates t
                org-agenda-skip-deadline-if-done t
                org-agenda-skip-scheduled-if-done t
                org-agenda-start-on-weekday nil)
        '';
      };

      org-mobile = {
        enable = true;
        after = [ "org" ];
        defer = true;
      };

1055 1056 1057 1058 1059 1060
      ob-http = {
        enable = true;
        after = [ "org" ];
        defer = true;
      };

Robert Helgesson's avatar
Robert Helgesson committed
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
      ob-plantuml = {
        enable = true;
        after = [ "org" ];
        defer = true;
      };

      org-table = {
        enable = true;
        after = [ "org" ];
        command = [ "orgtbl-to-generic" ];
        hook = [
          # For orgtbl mode, add a radio table translator function for
          # taking a table to a psql internal variable.
          ''
            (orgtbl-mode
             . (lambda ()
                 (defun rah-orgtbl-to-psqlvar (table params)
                   "Converts an org table to an SQL list inside a psql internal variable"
                   (let* ((params2
                           (list
                            :tstart (concat "\\set " (plist-get params :var-name) " '(")
                            :tend ")'"
                            :lstart "("
                            :lend "),"
                            :sep ","
                            :hline ""))
                          (res (orgtbl-to-generic table (org-combine-plists params2 params))))
                     (replace-regexp-in-string ",)'$"
                                               ")'"
                                               (replace-regexp-in-string "\n" "" res))))))
          ''
        ];
        config = ''
          (unbind-key "C-c SPC" orgtbl-mode-map)
          (unbind-key "C-c w" orgtbl-mode-map)
        '';
1097 1098 1099
        extraConfig = ''
          :functions org-combine-plists
        '';
Robert Helgesson's avatar
Robert Helgesson committed
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
      };

      org-capture = {
        enable = true;
        after = [ "org" ];
        config = ''
          (setq org-capture-templates rah-org-capture-templates)
        '';
      };

      org-clock = {
        enable = true;
        after = [ "org" ];
        config = ''
          (setq org-clock-rounding-minutes 5
                org-clock-out-remove-zero-time-clocks t)
        '';
      };

      org-duration = {
        enable = true;
        after = [ "org" ];
        config = ''
          ;; I always want clock tables and such to be in hours, not days.
          (setq org-duration-format (quote h:mm))
        '';
      };

1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
      org-refile = {
        enable = true;
        after = [ "org" ];
        config = ''
          ;; Refiling should include not only the current org buffer but
          ;; also the standard org files. Further, set up the refiling to
          ;; be convenient with IDO. Follows norang's setup quite closely.
          (setq org-refile-targets '((nil :maxlevel . 2)
                                     (org-agenda-files :maxlevel . 2))
                org-refile-use-outline-path t
                org-outline-path-complete-in-steps nil
                org-refile-allow-creating-parent-nodes 'confirm)
        '';
      };

1143
      org-superstar = {
Robert Helgesson's avatar
Robert Helgesson committed
1144
        enable = true;
1145
        hook = [ "(org-mode . org-superstar-mode)" ];
Robert Helgesson's avatar
Robert Helgesson committed
1146 1147 1148 1149 1150 1151 1152
      };

      org-tree-slide = {
        enable = true;
        command = [ "org-tree-slide-mode" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
1153
      org-variable-pitch = {
1154
        enable = false;
Robert Helgesson's avatar
Robert Helgesson committed
1155 1156 1157
        hook = [ "(org-mode . org-variable-pitch-minor-mode)" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
1158 1159 1160 1161
      # Set up yasnippet. Defer it for a while since I don't generally
      # need it immediately.
      yasnippet = {
        enable = true;
1162
        defer = 3;
Robert Helgesson's avatar
Robert Helgesson committed
1163
        diminish = [ "yas-minor-mode" ];
1164
        command = [ "yas-global-mode" "yas-minor-mode" "yas-expand-snippet" ];
Robert Helgesson's avatar
Robert Helgesson committed
1165 1166 1167 1168 1169 1170 1171 1172
        hook = [
          # Yasnippet interferes with tab completion in ansi-term.
          "(term-mode . (lambda () (yas-minor-mode -1)))"
        ];
        config = "(yas-global-mode 1)";
      };

      yasnippet-snippets = {
1173
        enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
        after = [ "yasnippet" ];
      };

      # Setup the cperl-mode, which I prefer over the default Perl
      # mode.
      cperl-mode = {
        enable = true;
        defer = true;
        hook = [ "ggtags-mode" ];
        command = [ "cperl-set-style" ];
        config = ''
          ;; Avoid deep indentation when putting function across several
          ;; lines.
1187
          (setq cperl-indent-parens-as-block t)
Robert Helgesson's avatar
Robert Helgesson committed
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200

          ;; Use cperl-mode instead of the default perl-mode
          (defalias 'perl-mode 'cperl-mode)
          (cperl-set-style "PerlStyle")
        '';
      };

      # Setup ebib, my chosen bibliography manager.
      ebib = {
        enable = true;
        command = [ "ebib" ];
        hook = [
          # Highlighting of trailing whitespace is a bit annoying in ebib.
1201 1202
          ''(ebib-index-mode-hook . rah-disable-trailing-whitespace-mode)''
          ''(ebib-entry-mode-hook . rah-disable-trailing-whitespace-mode)''
Robert Helgesson's avatar
Robert Helgesson committed
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
        ];
        config = ''
          (setq ebib-latex-preamble '("\\usepackage{a4}"
                                      "\\bibliographystyle{amsplain}")
                ebib-print-preamble '("\\usepackage{a4}")
                ebib-print-tempfile "/tmp/ebib.tex"
                ebib-extra-fields '(crossref
                                    url
                                    annote
                                    abstract
                                    keywords
                                    file
                                    timestamp
                                    doi))
        '';
      };

      smartparens = {
        enable = true;
1222
        defer = 3;
Robert Helgesson's avatar
Robert Helgesson committed
1223
        diminish = [ "smartparens-mode" ];
1224
        command = [ "smartparens-global-mode" "show-smartparens-global-mode" ];
Robert Helgesson's avatar
Robert Helgesson committed
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
        bindLocal = {
          smartparens-mode-map = {
            "C-M-f" = "sp-forward-sexp";
            "C-M-b" = "sp-backward-sexp";
          };
        };
        config = ''
          (require 'smartparens-config)
          (smartparens-global-mode t)
          (show-smartparens-global-mode t)
        '';
      };

      fill-column-indicator = {
        enable = true;
        command = [ "fci-mode" ];
      };

      flycheck = {
        enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
1245
        diminish = [ "flycheck-mode" ];
Robert Helgesson's avatar
Robert Helgesson committed
1246 1247
        command = [ "global-flycheck-mode" ];
        defer = 1;
Robert Helgesson's avatar
Robert Helgesson committed
1248 1249 1250 1251
        bind = {
          "M-n" = "flycheck-next-error";
          "M-p" = "flycheck-previous-error";
        };
Robert Helgesson's avatar
Robert Helgesson committed
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
        config = ''
          ;; Only check buffer when mode is enabled or buffer is saved.
          (setq flycheck-check-syntax-automatically '(mode-enabled save))

          ;; Enable flycheck in all eligible buffers.
          (global-flycheck-mode)
        '';
      };

      flycheck-plantuml = {
        enable = true;
        hook = [ "(flycheck-mode . flycheck-plantuml-setup)" ];
      };

      projectile = {
        enable = true;
        diminish = [ "projectile-mode" ];
1269
        command = [ "projectile-mode" "projectile-project-root" ];
Robert Helgesson's avatar
Robert Helgesson committed
1270
        bindKeyMap = {
1271
          "C-c p" = "projectile-command-map";
Robert Helgesson's avatar
Robert Helgesson committed
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
        };
        config = ''
          (setq projectile-enable-caching t
                projectile-completion-system 'ivy)
          (projectile-mode 1)
        '';
      };

      plantuml-mode = {
        enable = true;
        mode = [ ''"\\.puml\\'"'' ];
      };

      ace-window = {
        enable = true;
        extraConfig = ''
          :bind* (("C-c w" . ace-window)
                  ("M-o" . ace-window))
        '';
      };

      company = {
        enable = true;
        diminish = [ "company-mode" ];
1296 1297
        command = [ "company-mode" "company-doc-buffer" "global-company-mode" ];
        defer = 1;
Robert Helgesson's avatar
Robert Helgesson committed
1298 1299 1300 1301 1302 1303 1304
        extraConfig = ''
          :bind (:map company-mode-map
                      ([remap completion-at-point] . company-complete-common)
                      ([remap complete-symbol] . company-complete-common))
        '';
        config = ''
          (setq company-idle-delay 0.3
1305 1306 1307 1308 1309
                company-show-numbers t
                company-tooltip-maximum-width 100
                company-tooltip-minimum-width 20
                ; Allow me to keep typing even if company disapproves.
                company-require-match nil)
1310 1311

          (global-company-mode)
Robert Helgesson's avatar
Robert Helgesson committed
1312 1313
        '';
      };
Robert Helgesson's avatar
Robert Helgesson committed
1314 1315 1316 1317 1318 1319 1320 1321

      company-box = {
        enable = true;
        hook = [ "(company-mode . company-box-mode)" ];
        config = ''
          (setq company-box-icons-alist 'company-box-icons-all-the-icons)
        '';
      };
Robert Helgesson's avatar
Robert Helgesson committed
1322 1323 1324

      company-yasnippet = {
        enable = true;
1325
        after = [ "company" "yasnippet" ];
Robert Helgesson's avatar
Robert Helgesson committed
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
        bind = {
          "M-/" = "company-yasnippet";
        };
      };

      company-dabbrev = {
        enable = true;
        after = [ "company" ];
        command = [ "company-dabbrev" ];
        config = ''
          (setq company-dabbrev-downcase nil
                company-dabbrev-ignore-case t)
        '';
      };

      company-quickhelp = {
        enable = true;
        after = [ "company" ];
        command = [ "company-quickhelp-mode" ];
        config = ''
          (company-quickhelp-mode 1)
        '';
      };

      company-cabal = {
        enable = true;
        after = [ "company" ];
        command = [ "company-cabal" ];
        config = ''
          (add-to-list 'company-backends 'company-cabal)
        '';
      };

      php-mode = {
        mode = [ ''"\\.php\\'"'' ];
        hook = [ "ggtags-mode" ];
      };

1364 1365 1366 1367 1368 1369
      # Needed by Flycheck.
      pkg-info = {
        enable = true;
        command = [ "pkg-info-version-info" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382
      protobuf-mode = {
        mode = [ ''"'\\.proto\\'"'' ];
      };

      python = {
        enable = true;
        mode = [ ''("\\.py\\'" . python-mode)'' ];
        hook = [ "ggtags-mode" ];
      };

      transpose-frame = {
        enable = true;
        bind = {
1383
          "C-c f t" = "transpose-frame";
Robert Helgesson's avatar
Robert Helgesson committed
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
        };
      };

      tt-mode = {
        enable = true;
        mode = [ ''"\\.tt\\'"'' ];
      };

      smart-tabs-mode = {
        enable = false;
        config = ''
          (smart-tabs-insinuate 'c 'c++ 'cperl 'java)
        '';
      };

1399
      yaml-mode.enable = true;
Robert Helgesson's avatar
Robert Helgesson committed
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422

      wc-mode = {
        enable = true;
        command = [ "wc-mode" ];
      };

      web-mode = {
        enable = true;
        mode = [
          ''"\\.html\\'"''
          ''"\\.jsx?\\'"''
        ];
        config = ''
          (setq web-mode-attr-indent-offset 4
                web-mode-code-indent-offset 2
                web-mode-markup-indent-offset 2)

          (add-to-list 'web-mode-content-types '("jsx" . "\\.jsx?\\'"))
        '';
      };

      dired = {
        enable = true;
1423
        command = [ "dired" "dired-jump" ];
Robert Helgesson's avatar
Robert Helgesson committed
1424 1425 1426 1427
        config = ''
          (put 'dired-find-alternate-file 'disabled nil)
          ;; Use the system trash can.
          (setq delete-by-moving-to-trash t)
1428
          (setq dired-listing-switches "-alvh --group-directories-first")
Robert Helgesson's avatar
Robert Helgesson committed
1429 1430 1431
        '';
      };

1432 1433 1434 1435 1436
      all-the-icons-dired = {
        enable = true;
        hook = [ "(dired-mode . all-the-icons-dired-mode)" ];
      };

Robert Helgesson's avatar
Robert Helgesson committed
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
      wdired = {
        enable = true;
        bindLocal = {
          dired-mode-map = {
            "C-c C-w" = "wdired-change-to-wdired-mode";
          };
        };
        config = ''
          ;; I use wdired quite often and this setting allows editing file
          ;; permissions as well.
          (setq wdired-allow-to-change-permissions t)
        '';
      };

1451 1452
      # Hide hidden files when opening a dired buffer. But allow showing them by
      # pressing `.`.
Robert Helgesson's avatar
Robert Helgesson committed
1453 1454
      dired-x = {
        enable = true;
1455 1456 1457 1458 1459 1460 1461 1462
        hook = [ "(dired-mode . dired-omit-mode)" ];
        bindLocal.dired-mode-map = {
          "." = "dired-omit-mode";
        };
        config = ''
          (setq dired-omit-verbose nil
                dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
        '';
Robert Helgesson's avatar
Robert Helgesson committed
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479
      };

      recentf = {
        enable = true;
        command = [ "recentf-mode" ];
        config = ''
          (setq recentf-save-file (locate-user-emacs-file "recentf")
                recentf-max-menu-items 20
                recentf-max-saved-items 500
                recentf-exclude '("COMMIT_MSG" "COMMIT_EDITMSG"))
        '';
      };

      nxml-mode = {
        enable = true;
        mode = [ ''"\\.xml\\'"'' ];
        config = ''
1480
          (setq nxml-child-indent 2
Robert Helgesson's avatar
Robert Helgesson committed
1481 1482 1483 1484 1485 1486 1487
                nxml-attribute-indent 4
                nxml-slash-auto-complete-flag t)
          (add-to-list 'rng-schema-locating-files
                       "~/.emacs.d/nxml-schemas/schemas.xml")
        '';
      };

1488
      rust-mode.enable = true;
1489

Robert Helgesson's avatar
Robert Helgesson committed
1490
      sendmail = {
Robert Helgesson's avatar
Robert Helgesson committed
1491
        command = [ "mail-mode" "mail-text" ];
Robert Helgesson's avatar
Robert Helgesson committed
1492
        mode = [
Robert Helgesson's avatar
Robert Helgesson committed
1493 1494
          ''("^mutt-" . mail-mode)''
          ''("\\.article" . mail-mode)''
Robert Helgesson's avatar
Robert Helgesson committed
1495
        ];
Robert Helgesson's avatar
Robert Helgesson committed
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525
        bindLocal = {
          mail-mode-map = {
            # Make it easy to include references.
            "C-c [" = "rah-mail-reftex-citation";
          };
        };
        hook = [ "rah-mail-mode-hook" ];
        config = ''
          (defun rah-mail-reftex-citation ()
            (let ((reftex-cite-format 'locally))
              (reftex-citation)))

          (defun rah-mail-flyspell ()
            "Enable flyspell and set dictionary based on To: field."
            (save-excursion
              (goto-char (point-min))
              (when (re-search-forward "^To: .*\\.se\\($\\|,\\|>\\)" nil t)
                (ispell-change-dictionary "swedish"))))