summaryrefslogtreecommitdiff
path: root/lisp/programming.el
blob: 83bed87d94ff10616c9ef242daec44c5185183f6 (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
;;; 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)))

(use-package lsp-ui
  ;; The only reason I'm using `lsp-ui' is for integration with Flycheck. The
  ;; features like lenses don't interest me.
  :init
  (setq lsp-ui-sideline-enable nil
        lsp-ui-peek-enable nil
        lsp-ui-doc-enable nil))

;; Disable the default machinery in `lsp-mode'. The reason I'm using the package
;; in the first place is for its ability to integrate with the other
;; programming-related packages I use.

(use-package company-lsp
  :commands company-lsp
  :init
  (setq company-lsp-cache-candidates 'auto))

(use-package lsp-mode
  :init
  (setq lsp-enable-xref t)

  ;; Filesystem hygene.
  :init
  (setq lsp-session-file "~/.cache/emacs/.lsp-session-v1"
        lsp-auto-guess-root t)

  ;; Use `xref' keybindings instead of the default ones.
  :bind
  (:map lsp-mode-map
   ("M-." . lsp-find-definition)
   ("M-," . pop-tag-mark)))

© 2015 - 2026 Jakob L. Kreuze