summaryrefslogtreecommitdiff
path: root/emacs/init.el
blob: ffd53f6e8d921b9fe2eb60e39789ab5118c92738 (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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
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
419
420
421
422
423
424
425
426
;;; package --- init.el
;;; Comentary:

;; A new init.el

;;; Code:

(with-eval-after-load 'package
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t))

;; Automatic reread from disk if the underlying file changes
(setq auto-revert-interval 1)
(setq auto-revert-check-vc-info t)
(global-auto-revert-mode)

;; Move thourgh windows with Ctrl-<arrow keys>
(windmove-default-keybindings 'meta)

;; Fix archaic defaults
(setq sentence-end-double-space nil)

;; Make right click do something sensible
(when (display-graphic-p)
  (context-menu-mode))


;; Tramp - Faster than default scp
(setq tramp-default-method "ssh")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;   Interface enhancements/defaults
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Mode line information
(setq line-number-mode t)                        ; Show current line in modeline
(setq column-number-mode t)                      ; Show column as well

(setq x-underline-at-descent-line nil)           ; Prettier underlines
(setq switch-to-buffer-obey-display-actions t)   ; Make switching buffers more consistent

(setq-default show-trailing-whitespace nil)      ; By default, don't underline trailing spaces
(setq-default indicate-buffer-boundaries nil)    ; Show buffer top and bottom in the margin

;; Misc. UI tweaks
(blink-cursor-mode -1)                                ; Steady cursor
(pixel-scroll-precision-mode)                         ; Smooth scrolling

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;   Tab-bar configuration
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Show the tab-bar as soon as tab-bar functions are invoked
(setq tab-bar-show 0)

;; Add the time to the tab-bar, if visible
(add-to-list 'tab-bar-format 'tab-bar-format-align-right 'append)
(add-to-list 'tab-bar-format 'tab-bar-format-global 'append)
(setq display-time-format "%a %F %T")
(setq display-time-interval 1)
(display-time-mode)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;   Theme
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(use-package emacs
  :config
  (if (display-graphic-p)
      (progn
	(load-theme 'modus-operandi)
	(set-face-attribute 'default nil :font "Fantasque Sans Mono" :height 110)
	(set-face-attribute 'fixed-pitch nil :font "Input Mono" :height 100)
	(set-face-attribute 'variable-pitch nil :font "IBM Plex Sans" :height 110)
	(setq modus-themes-operandi-color-overrides
	      '((bg-main . "#fefcf4"))))
    (load-theme 'gruvbox-dark-hard)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;   Org
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq org-agenda-files (list "~/OrgRoam/agenda.org"
			     "/home/work/OrgRoam/20230808170239-code_reviews.org"
			     "/home/work/OrgRoam/20230808173230-tareas.org"))

(use-package org
  :hook ((org-mode . visual-line-mode)  ; wrap lines at word breaks
         (org-mode . flyspell-mode))    ; spell checking!

  :bind (:map global-map
              ("C-c l s" . org-store-link)          ; Mnemonic: link → store
              ("C-c l i" . org-insert-link-global)  ; Mnemonic: link → insert
	      ("C-c a" . org-agenda))
  :config
  (require 'org-tempo)			; Abbrv support for code blocks
  (add-to-list 'org-export-backends 'md)

  ;; Make org-open-at-point follow file links in the same window
  (setf (cdr (assoc 'file org-link-frame-setup)) 'find-file)

  ;; Make exporting quotes better
  (setq org-export-with-smart-quotes t)
  (setq org-confirm-babel-evaluate nil)	; Dont prompt for evaluation
  )
(add-hook 'org-mode-hook (lambda ()
			   (auto-fill-mode)
			   (variable-pitch-mode)
			   (bug-reference-mode)
			   (olivetti-mode)
			   (olivetti-set-width 100)))
(use-package org-roam
  :ensure t
  :defer t
  :init (setq org-roam-v2-ack t)
  :custom
  (org-roam-directory "~/OrgRoam")
  :bind (("C-c n l" . org-roam-buffer-toggle)
	 ("C-c n f" . org-roam-node-find)
	 ("C-c n i" . org-roam-node-insert))
  :config
  ;; (org-roam-setup) ;; One shot?
  (org-roam-db-autosync-mode)
  (setq org-roam-index-file "~/OrgRoam/index.org")
  (add-to-list 'display-buffer-alist
               '("\\*org-roam\\*"
                 (display-buffer-in-side-window)
                 (side . right)
                 (window-width . 0.4)
                 (window-height . fit-window-to-buffer))))

(use-package org-jira
  :config (setq jiralib-url "https://comprandoengrupo.atlassian.net"))

(use-package org-modern
  :ensure t
  :init (global-org-modern-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;   Minibuffer and completion
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Vertico: better vertical completion for minibuffer commands
(use-package vertico
  :ensure t
  :init
  ;; You'll want to make sure that e.g. fido-mode isn't enabled
  (vertico-mode))

;; Marginalia: annotations for minibuffer
(use-package marginalia
  :ensure t
  :config
  (marginalia-mode))

(use-package corfu
  :ensure t
  :custom
  (corfu-cycle t)
  :bind
  (:map corfu-map
	("SPC" . corfu-insert-separator))
  :hook ((prog-mode . corfu-mode)
	 (shell-mode . corfu-mode)
	 (eshell-mode . corfu-mode))
  :init (global-corfu-mode))

;; Part of corfu
(use-package corfu-popupinfo
  :after corfu
  :hook (corfu-mode . corfu-popupinfo-mode)
  :custom
  (corfu-popupinfo-delay '(0.25 . 0.1))
  (corfu-popupinfo-hide nil)
  :config
  (corfu-popupinfo-mode))

;; Make corfu popup come up in terminal overlay
(use-package corfu-terminal
  :if (not (display-graphic-p))
  :ensure t
  :config
  (corfu-terminal-mode))

;; Pretty icons for corfu
(use-package kind-icon
  :if (display-graphic-p)
  :ensure t
  :after corfu
  :config
  (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))

;; Orderless: powerful completion style
(use-package orderless
  :ensure t
  :config
  (setq completion-styles '(orderless)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;   Packages
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Treesiter config

(use-package emacs
  :config
  ;; Treesitter config

  ;; Tell Emacs to prefer the treesitter mode
  ;; You'll want to run the command `M-x treesit-install-language-grammar' before editing.
  (setq major-mode-remap-alist
        '(;(yaml-mode . yaml-ts-mode)
          (bash-mode . bash-ts-mode)
          (js2-mode . js-ts-mode)
          (typescript-mode . typescript-ts-mode)
          (json-mode . json-ts-mode)
          (css-mode . css-ts-mode)
          (python-mode . python-ts-mode)))
  :hook
  ;; Auto parenthesis matching
  ((prog-mode . electric-pair-mode)))

;; Eglot
(use-package eglot
  ;; no :ensure t here because it's built-in

  ;; Configure hooks to automatically turn-on eglot for selected modes
  ; :hook
  ; (((python-mode ruby-mode elixir-mode) . eglot))

  :custom
  (eglot-send-changes-idle-time 0.1)

  :config
  (fset #'jsonrpc--log-event #'ignore)  ; massive perf boost---don't log every event
  ;; Sometimes you need to tell Eglot where to find the language server
  ; (add-to-list 'eglot-server-programs
  ;              '(haskell-mode . ("haskell-language-server-wrapper" "--lsp")))
  (add-to-list 'eglot-server-programs
	       '(python-ts-mode . ("pylsp" "--tcp" "--port" :autoport)))
  )

;; YAML
(use-package yaml-mode :ensure t)

;; JSON
(use-package json-mode :ensure t)
(add-hook 'js-json-mode-hook
	  (lambda ()
	    (define-key js-json-mode-map (kbd "<f5>") 'json-pretty-print-buffer)))

;; Lisp
(use-package slime :defer t :ensure t)
(setq inferior-lisp-program "sbcl")

;; Rest client
(use-package restclient :defer t :ensure t)

;; Magit
(use-package magit
  :ensure t
  :bind (("s-g" . magit-status)
	 ("C-c g" . magit-status)))

;; python-mode configuration

(use-package pyvenv
  :ensure t
  :config
  ;; Set correct Python interpreter
  (setq pyvenv-post-activate-hooks
	(list (lambda ()
		(setq python-shell-interpreter (concat pyvenv-virtual-env "bin/python3")))))
  (setq pyvenv-post-deactivate-hooks
	(list (lambda ()
		(setq python-shell-interpreter "python3")))))

(use-package python-pytest
  :defer t
  :ensure t
  :config
  (transient-append-suffix
    'python-pytest-dispatch
    "-v"
    '("--db" "Create db" "--create-db")))

(add-hook 'python-ts-mode-hook
	  (lambda ()
	    (define-key python-ts-mode-map (kbd "C-c p") 'python-pytest-dispatch)
	    (define-key python-ts-mode-map (kbd "C-c m p") 'ceg/pre-commit-run-current-file)))

;; Load path from shell environment
(use-package exec-path-from-shell :ensure t :defer t)

;; sh-mode configuration
(use-package flymake-shellcheck
  :commands flymake-shellcheck-load
  :init
  (add-hook 'sh-mode-hook 'flymake-shellcheck-load))


;; Moodline
(use-package mood-line :ensure t)
(mood-line-mode)

;; Fix for flycheck with eglot
;; https://gitlab.com/jessieh/mood-line/-/merge_requests/11
(require 'cl-lib)

(defun mood-line--checker-flymake-count-errors ()
  "Return alist with count of all current flymake diagnostic reports.

Counts will be returned in an alist as the cdr of the following keys:
`'note-count'    | All notes reported by checker
`'error-count'   | All errors reported by checker
`'warning-count' | All warnings reported by checkero
`'issue-count'   | All errors and warnings reported by checker
`'all-count'     | Everything reported by checker"
  (let ((error-count 0)
        (warning-count 0)
        (note-count 0))
    (progn
      (cl-loop
       with warning-level = (warning-numeric-level :warning)
       with note-level = (warning-numeric-level :debug)
       for state being the hash-values of flymake--state
       do (cl-loop
           with diags = (flymake--state-diags state)
           for diag in diags do
           (let ((severity (flymake--lookup-type-property (flymake--diag-type diag) 'severity
                                                          (warning-numeric-level :error))))
             (cond ((> severity warning-level) (cl-incf error-count))
                   ((> severity note-level)    (cl-incf warning-count))
                   (t                          (cl-incf note-count)))))))
    `((note-count . ,note-count)
      (error-count . ,error-count)
      (warning-count . ,warning-count)
      (issue-count . ,(+ warning-count
                         error-count))
      (all-count . ,(+ note-count
                       warning-count
                       error-count)))))

;; IMenu everywhere
(use-package imenu-anywhere
  :ensure t
  :bind (("C-." . imenu-anywhere)))

;; Projectile
(use-package projectile
  :init
  (setq projectile-use-git-grep t))
(projectile-mode +1)
(define-key projectile-mode-map (kbd "M-p") 'projectile-command-map)


(use-package projectile-rails
  :defer t :ensure t
  :init (projectile-rails-global-mode))
(define-key projectile-rails-mode-map (kbd "C-c r")
	    'projectile-rails-command-map)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;   Custom functions
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun ceg/pre-commit-run-current-file ()
  "Run pre-commit with the current file name"
  (interactive)
  (let ((full-command (concat "pre-commit run --file " buffer-file-name " | sed 's;^ceg/;;g'")))
    (compile full-command)))

(defun ceg/pre-commit-run ()
  "Run pre-commit with the current file name"
  (interactive)
  (let ((full-command (concat "pre-commit run | sed 's;^ceg/;;g'")))
    (compile full-command)))

(add-hook 'python-mode (lambda ()
			 (local-set-key ("C-c o")
					'ceg/pre-commit-run)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;   Global keybindigns
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-key global-map (kbd "RET") 'newline-and-indent)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-;") 'completion-at-point)
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "M-z") 'zap-up-to-char)
(global-set-key (kbd "C-.") #'imenu-anywhere)
(global-set-key (kbd "M-o") 'other-window)
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-safe-themes
   '("919fabfc5cb6165ce07b9d8668f78fe75fe8bd08566006bc87513c29b4f34ade" "3770d0ae70172461ee0a02edcff71b7d480dc54066e8960d8de9367d12171efb" default))
 '(safe-local-variable-values
   '((python-pytest-executable . "pytest")
     (python-shell-interpreter-args . "/home/work/Workspace/ceg-intranet/ceg/manage.py shell_plus --plain"))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )