summary refs log tree commit diff
path: root/emacs/custom/my-prog.el
blob: 2a0f29a1a9f4909e5722b71cbb48900443065081 (plain) (blame)
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
;;; my-prog.el --- Configures emacs for various programming languages -*- lexical-binding: t -*-

;;; Commentary:

;;; Code:

(customize-set-variable 'Man-notify-method 'aggressive)
(customize-set-variable 'Man-fontify-manpage-flag t)

;; turn on `electric-pair-mode' on `prog-mode' and `conf-mode-hook'
(dolist (hook '(prog-mode-hook conf-mode-hook))
  (add-hook hook 'electric-pair-mode))

;; Skip over warnings and info messages in compilation
(customize-set-variable 'compilation-skip-threshold 2)
;; Don't freeze when process reads from stdin
(customize-set-variable 'compilation-disable-input t)
;; Show three lines of context around the current message
(customize-set-variable 'compilation-context-lines 3)
;; Jump to first error
(customize-set-variable 'compilation-scroll-output 'first-error)

(customize-set-variable 'flymake-start-on-flymake-mode t)
(customize-set-variable 'flymake-start-on-save-buffer t)
(customize-set-variable 'flymake-no-changes-timeout nil)
(customize-set-variable 'flymake-proc-compilation-prevents-syntax-check t)
(customize-set-variable 'flymake-wrap-around nil)
(customize-set-variable 'elisp-flymake-byte-compile-load-path load-path)

(with-eval-after-load 'flymake
  (define-key flymake-mode-map (kbd "C-c ! n") 'flymake-goto-next-error)
  (define-key flymake-mode-map (kbd "C-c ! p") 'flymake-goto-prev-error)
  (define-key flymake-mode-map (kbd "C-c ! d") 'flymake-show-diagnostics-buffer))

(dolist (hook '(prog-mode-hook conf-mode-hook))
  (add-hook hook 'flymake-mode))

;; yasnippet is required to support place holders with eglot
(dolist (hook '(prog-mode-hook conf-mode-hook org-mode-hook))
  (add-hook hook 'yas-minor-mode))

;; I want comments to be wrapped at column 80
(customize-set-variable 'comment-fill-column 80)
(customize-set-variable 'comment-auto-fill-only-comments t)

(dolist (hook '(prog-mode-hook conf-mode-hook))
  (add-hook hook 'auto-fill-mode))

(defun my/sh-mode-hook ()
  "Hooks for `sh-mode'."
  ;; shell scripts are made executable
  (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
  (customize-set-variable 'sh-indentation 2)
  (customize-set-variable 'sh-basic-offset 2))

(add-hook 'sh-mode-hook 'my/sh-mode-hook)

;; set the indent level for python
(customize-set-variable 'python-indent-offset 2)

(defun my/makefile-mode-hook ()
  "Hooks for `makefile-mode'."
  ;; I want small tabs when working in a Makefile
  (setq tab-width 2))

(add-hook 'makefile-mode-hook 'my/makefile-mode-hook)

(defun my/go-mode-hook ()
  "Hooks for `go-mode'."
  (add-hook 'before-save-hook 'gofmt-before-save)
  (setq tab-width 4)

  (set (make-local-variable 'compile-command)
       "go build -v && go test -v -cover")
  (define-key go-mode-map (kbd "C-c C-r") 'compile)
  (define-key go-mode-map (kbd "C-c C-R") 'recompile)

  (customize-set-variable 'go-test-verbose t)
  (define-key go-mode-map (kbd "C-c C-n") 'go-run)
  (define-key go-mode-map (kbd "C-c C-c") 'go-coverage)
  (define-key go-mode-map (kbd "C-c .") 'go-test-current-test)
  (define-key go-mode-map (kbd "C-c C-f") 'go-test-current-file)
  (define-key go-mode-map (kbd "C-c C-p") 'go-test-current-project))

(add-hook 'go-mode-hook 'my/go-mode-hook)

(defun my/elisp-mode-hook ()
  "Hooks for `elisp-mode'."
  (define-key emacs-lisp-mode-map (kbd "C-c C-e") 'eval-buffer)
  (define-key emacs-lisp-mode-map (kbd "C-c C-r") 'eval-region))

(add-hook 'emacs-lisp-mode-hook 'my/elisp-mode-hook)

(define-key prog-mode-map (kbd "C-c C-h") 'eldoc)
(dolist (hook '(prog-mode-hook conf-mode-hook))
  (add-hook hook 'turn-on-eldoc-mode))

;; format nix buffers on save
(add-hook 'before-save-hook 'nix-format-before-save)

;; List of settings for gopls:
;; https://github.com/golang/tools/blob/master/gopls/doc/settings.md
(customize-set-variable 'eglot-workspace-configuration
                        '((:gopls .
                                  ((staticcheck     . t)
                                   (matcher         . "CaseSensitive")
                                   (usePlaceholders . t)))))

;; ensure we load eglot for some specific modes
(dolist (hook '(go-mode-hook nix-mode-hook))
  (add-hook hook 'eglot-ensure))

(provide 'my-prog)

;;; my-prog.el ends here