summaryrefslogtreecommitdiff
path: root/emacs/inits/20-programming.el
blob: f48d419da70ad7776fda463dd2985dfc45976ad2 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
;; Time-stamp: <2020-01-12 11:46:11 (tslil@bison)>

;; -----------------------------------------------------------------------------
;; General setup

;; Always split horizontally when compiling
(defadvice compile (around split-horizontally activate)
  (let ((split-width-threshold 0)
        (split-height-threshold nil))
    ad-do-it))

;; Resize to fill column (and a little bit)
(defadvice compile (after resize-window-properly activate)
  (let ((ww (window-width)))
    (when (< ww (+ 5 fill-column))
      (enlarge-window-horizontally (- (+ 5 fill-column) ww)))))

(defun programming-setup ()
  (subword-mode 1)
  (electric-pair-local-mode)
  ;; Emacs25 compat
  (if (fboundp 'display-line-numbers-mode)
      (display-line-numbers-mode)
    (linum-mode))
  (setq auto-hscroll-mode t))

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

;; -----------------------------------------------------------------------------
;; Specific packages

(use-package shift-number
  :ensure t
  :bind (("C-c S-i" . shift-number-up)
         ("C-c S-d" . shift-number-down)))

(use-package comment-dwim-2
  :ensure t
  :bind (("M-;" . comment-dwim-2))
  :config (setq comment-multi-line t))

(use-package aggressive-indent
  :ensure t
  :defer t)

(use-package yasnippet
  :ensure t
  :defer t)

(use-package elec-pair
  :defer t
  :config
  (setq electric-pair-delete-adjacent-pairs t
        electric-pair-skip-self 'electric-pair-default-skip-self
        electric-pair-preserve-balance t
        electric-pair-skip-whitespace t
        electric-pair-pairs '((?\" . ?\")
                              (?' . ?')
                              (?\( . ?\))
                              (?< . ?>)
                              (?\[ . ?\]))))

(use-package js-comint
  :ensure t
  :defer t
  :config
  (setq js-comint-program-command "node"
        js-comint-program-arguments nil))

(use-package js2-mode
  :ensure t
  :defer t
  :after js-comint
  :mode "\\.js$"
  :bind (:map js2-mode-map
              ("TAB" . js2-indent-line)
              ("C-x C-e" . js-send-last-sexp)
              ("C-c C-b" . js-send-buffer)
              ("C-c C-l" . js-load-file))
  :hook (js2-mode . (lambda ()
                      (auto-revert-mode -1)
                      (yas-minor-mode-on))))

(use-package nodemcu-mode
  :ensure t
  :defer t
  :config
  (setq nodemcu-default-keybindings t
        nodemcu-port "/dev/ttyUSB0"
        nodemcu-backend "nodemcu-uploader")

  (defun nodemcu-better-upload-current-file (&optional noreset)
    (interactive "P")
    (let ((proc (get-process "nodemcu-terminal")))
      (when proc
        (delete-process proc))
      (shell-command
       (nodemcu--get-command "upload" (file-name-nondirectory (buffer-file-name))))
      (unless noreset
        (shell-command
         (nodemcu--get-command "node restart"))
        (when proc
          (nodemcu-terminal))))))

(use-package lua-mode
  :after nodemcu-mode
  :ensure t
  :defer t
  :bind (:map lua-mode-map
              ("C-x C-e" . lua-send-current-line)
              ("C-c C-d" . lua-send-defun)
              ("C-c C-e" . lua-send-region)
              ("C-c C-u" . nodemcu-better-upload-current-file)
              ("C-c C-t" . nodemcu-terminal)
              ("M-n" . lua-forward-sexp)
              ("M-p" . lua-backwards-to-block-begin-or-end))
  :hook (lua-mode . (lambda ()
                      (require 'nodemcu-mode)
                      (use-package company-lua :ensure t :demand)
                      (nodemcu-mode 1)
                      (add-to-list 'company-backends 'company-lua))))

;; What are these?
;; (setq gdb-show-threads-by-default nil
;;       gdb-many-windows nil
;;       gdb-show-main nil)


(use-package flycheck
  :defer t
  :ensure t)

(use-package irony
  :ensure t
  :defer t
  :hook (lambda ()
          (irony-cdb-autosetup-compile-options)
          (company-irony-setup-begin-commands)))

(use-package cc-mode
  :defer t
  :config
  (c-set-offset 'case-label '+)
  (setq-default c-basic-offset 2))

(add-hook 'c-mode-hook
          (lambda ()
            (irony-mode)
            (abbrev-mode 0)
            (flycheck-mode)
            (flycheck-irony-setup)
            (c-toggle-hungry-state 1)
            (c-toggle-electric-state 1)
            (c-toggle-syntactic-indentation 1)))

(use-package flycheck-rust
  :after flycheck
  :ensure t
  :defer t)

(use-package rust-mode
  :ensure t
  :defer t
  :bind (:map rust-mode-map
              ("C-c C-c" . rust-compile)
              ("C-c C-r" . rust-run))
  :hook (rust-mode . (lambda ()
                       (flycheck-mode)
                       (flycheck-rust-setup)))
  :config
  (setq rust-indent-offset 4
        rust-indent-method-chain t
        rust-indent-where-clause t
        rust-format-on-save t))

(use-package verilog-mode
  :ensure t
  :defer t)