summaryrefslogtreecommitdiff
path: root/lisp/programming.el
blob: 088319902083ef920d59da9c2c8eb65f8b0944f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
;;; programming.el -*- lexical-binding: t; -*-
;;;
;;; Author:  Jakob L. Kreuze <zerodaysfordays@sdf.org>
;;; URL:     https://git.sr.ht/~jakob/.emacs.d/
;;;
;;; Configuration for "meta" packages which apply to all programming language
;;; development environments I have configured.
;;;

(use-package dumb-jump
  ;; Replace `xref' keybindings instead of using the default ones, since these
  ;; will get overwritten if I'm using a proper tag indexer anyway.
  :config
  (define-key dumb-jump-mode-map (kbd "C-M-g") nil)
  (define-key dumb-jump-mode-map (kbd "C-M-p") nil)
  (define-key dumb-jump-mode-map (kbd "C-M-q") nil)
  (define-key dumb-jump-mode-map (kbd "M-.") #'dumb-jump-go)
  (define-key dumb-jump-mode-map (kbd "M-,") #'dumb-jump-back)
  (dumb-jump-mode))

(use-package company
  ;; Start suggesting completions (almost) as soon as possible.
  :config
  (setq company-idle-delay 0.1
        company-minimum-prefix-length 3)

  ;; Use standard movement keys for selecting entries from the completion popup
  ;; instead of those used for minibuffer next/previous.
  :bind
  (:map company-active-map
   ("M-n" . nil)
   ("M-p" . nil)
   ("C-n" . company-select-next)
   ("C-p" . company-select-previous))

  ;; And have <tab> responsible for completion rather than <ret>, so that
  ;; company isn't quite as in-the-way.
  :bind
  (:map company-active-map
   ("TAB" . company-complete-selection)
   ("<tab>" . company-complete-selection)
   ("RET" . nil)
   ("<return>" . nil)))

(use-package compile
  :straight nil
  :bind
  ("<f12>" . compile)

  ;; Taken from EmacsWiki [1]. The compilation command can be changed by invoking
  ;; compile with a prefix argument, so I don't see the advantage of popping a
  ;; prompt every time.
  ;;
  ;; [1]: https://www.emacswiki.org/emacs/CompileCommand
  :init
  (setq compilation-read-command nil)

  ;; Hide the compilation buffer upon successful compilation. I typically don't
  ;; care about the output unless there were errors.
  :config
  (add-hook 'compilation-finish-functions
            (lambda (buf strg)
              (ignore strg)
              (let ((win (get-buffer-window buf 'visible)))
                (when win (delete-window win))))))

(use-package flycheck)

(use-package magit
  :bind
  ("C-c g" . magit-status))

;; After several failed attempts at getting into Smartparens, I've finally
;; developed a taste for it. Rommel was not lying when he said that "[i]t's like
;; having cybernetic limbs—it makes you jump higher and punch harder."

(use-package smartparens
  ;; Use the default Smartparens configuration as a base.
  :config
  (require 'smartparens-config)

  ;; Enable the Smartparens-flavored replacement for `show-paren-mode'.
  :config
  (show-smartparens-global-mode t)

  ;; Enable Smartparens in all modes derived from `prog-mode' or `comint-mode',
  ;; the latter hopefully covering all REPL cases.
  :hook
  (prog-mode . turn-on-smartparens-mode)
  (comint-mode . turn-on-smartparens-mode)

  ;; Rebind the default keys for manipulating sexps to the alternatives
  ;; suggested in Emacs and Pairs [1].
  ;;
  ;; [1]: https://ebzzry.io/en/emacs-pairs/
  :bind
  (:map smartparens-mode-map
    ("C-M-a" . sp-beginning-of-sexp)
    ("C-M-e" . sp-end-of-sexp)
    ("C-M-d" . sp-down-sexp)
    ("C-M-u" . sp-backward-up-sexp)
    ("C-M-f" . sp-forward-sexp)
    ("C-M-b" . sp-backward-sexp)
    ("C-M-n" . sp-next-sexp)
    ("C-M-p" . sp-previous-sexp)

    ("M-[" . sp-backward-unwrap-sexp)
    ("M-]" . sp-unwrap-sexp)
    ("C-<right>" . sp-forward-slurp-sexp)
    ("C-<left>" . sp-backward-slurp-sexp)
    ("M-<right>" . sp-foward-barf-sexp)
    ("M-<right>" . sp-forward-barf-sexp)

    ("C-M-t" . sp-transpose-sexp)
    ("C-M-k" . sp-kill-sexp)
    ("M-k" . sp-backward-kill-sexp))

  ;; The following mask `split-line' and `completion-at-point', respectively,
  ;; but I have yet to use either of these, so I don't mind using the keys for
  ;; Smartparens. I use "o" as a mnemonic for "out", and "i" is a mnemonic for
  ;; "in".
  :bind
  (:map smartparens-mode-map
    ("C-M-o" . sp-up-sexp)
    ("C-M-i" . sp-backward-down-sexp)))

;; Dash [1] is an alright system for managing documentation offline. We're in
;; Emacs, though, so why not make full use of it and use EWW to browse docs?
;;
;; [1]: https://kapeli.com/dash

(defun maybe-install-docset (name)
  "Install NAME if it is not already installed."
  (let ((file-name (concat name ".docset")))
    (unless (file-exists-p (expand-file-name file-name dash-docs-docsets-path))
      (dash-docs-install-docset name))))

(use-package dash-docs
  :init
  (setq dash-docs-browser-func 'eww)
  :config
  (maybe-install-docset "Rust")
  :hook
  (rust-mode . (lambda () (setq-local dash-docs-docsets '("Rust"))))
  :bind
  (("C-c C-M-d" . counsel-dash)))

(use-package counsel-dash)

;; I configure EWW here because I mostly use it for Dash. Thanks to the
;; Javascript curse, Firefox is my daily driver for recreational browsing.

(use-package eww
  :straight nil
  :init
  (setq shr-max-width 80)
  (setq shr-use-colors nil)
  (setq shr-use-fonts nil)
  (setq eww-header-line-format nil))

;; The last time I tried `lsp-mode', I was unhappy with the sheer amount of
;; stuff that was included. So I use `eglot' instead. Thus far, it's been a
;; pleasant experience.

(use-package eglot)

© 2015 - 2026 Jakob L. Kreuze