]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/emacs/config.el
emacs: tweak config
[julm/julm-nix.git] / home-manager / profiles / emacs / config.el
1 ;;; config.el -*- lexical-binding: t; -*-
2
3 ;; DOC: https://git.v0.io/hlissner/doom-emacs/src/commit/a680a4c96d2b57fcb75635bd1a918e1235e72890/docs/api.org
4 ;; DOC: https://github.com/daviwil/emacs-from-scratch
5
6 ;; Line numbers are pretty slow all around. The performance boost of
7 ;; disabling them outweighs the utility of always keeping them on.
8 (setq display-line-numbers-type nil)
9
10 ;; Focus new window after splitting
11 (setq evil-split-window-below t
12 evil-vsplit-window-right t
13 )
14
15 ;; Undo
16 (setq undo-tree-auto-save-history t
17 undo-tree-history-directory-alist '(("." . "~/.cache/emacs/undo"))
18 )
19
20 ;; Fonts
21 (setq doom-font-increment 1
22 doom-font-size 9
23 ;doom-font-name "DejaVu Sans Mono"
24 doom-font-name "Hack"
25 ;doom-font-name "Unifont"
26 doom-font (font-spec :family doom-font-name :size doom-font-size :antialias t)
27 doom-unicode-font (font-spec :family "Symbola" :antialias t)
28 doom-variable-pitch-font (font-spec :family doom-font-name :antialias t)
29 ivy-posframe-font (font-spec :family doom-font-name :antialias t)
30 )
31 (setq x-underline-at-descent-line t)
32
33 ;; Dashboard
34 ;;(setq +doom-dashboard-banner-file (expand-file-name "banner.png" doom-private-dir))
35 (defun bury-messages-and-scratch ()
36 (mapcar #'bury-buffer '("*Messages*" "*scratch*")))
37 (add-hook 'emacs-startup-hook #'bury-messages-and-scratch)
38
39 ;; Formatting
40 (setq haskell-stylish-on-save nil)
41 (setq lsp-haskell-formatting-provider "fourmolu")
42 (setq +format-on-save-enabled-modes
43 '(not emacs-lisp-mode ; works well enough without it
44 sql-mode ; sqlformat is broken
45 tex-mode ; latexindent is broken
46 latex-mode ; latexindent is broken
47 bibtex-mode ; is broken
48 ess-r-mode ; styler takes forever
49 )
50 )
51
52 ;; Theming
53 (setq doom-theme 'doom-vibrant)
54 (custom-theme-set-faces! '(doom-vibrant)
55 '(default :background "black" :foreground "white")
56 '(hl-line :background "black")
57 '(cursor :background "DarkOrange" :foreground "black")
58 ;; Haskell colors
59 '(font-lock-string-face :foreground "magenta")
60 '(highlight-numbers-number :foreground "DeepSkyBlue" :bold t)
61 '(font-lock-comment-face :foreground "cyan3")
62 '(font-lock-doc-face :foreground "cyan1")
63 ;'(haskell-constructor-face :foreground "#c4451d")
64 ;'(haskell-keyword-face :foreground "#af005f")
65 ;'(haskell-keyword-face :foreground "RoyalBlue")
66 ;'(haskell-keyword-face :foreground "#44385f")
67 ;'(haskell-keyword-face :foreground "#906238" :bold t)
68 ;'(haskell-keyword-face :foreground "green4" :bold t)
69 '(haskell-keyword-face :foreground "LightGreen" :bold nil)
70 ;'(haskell-pragma-face :foreground "#2aa198")
71 '(haskell-pragma-face :foreground "#8f4e8b")
72 ;'(haskell-type-face :foreground "#9e358f")
73 '(haskell-operator-face :foreground "yellow" :bold nil)
74 ;'(haskell-type-face :foreground "SaddleBrown")
75 ;'(haskell-constructor-face :foreground "darkgoldenrod4")
76 '(haskell-definition-face :foreground "white" :bold nil)
77 '(swiper-line-face :background "grey15")
78 '(swiper-match-face-1 :foreground "grey50" :background "black") ; what is between matches
79 '(swiper-match-face-2 :foreground "black" :background "yellow2")
80 '(swiper-match-face-3 :foreground "black" :background "yellow3")
81 '(swiper-match-face-4 :foreground "black" :background "yellow4")
82 '(swiper-background-match-face-2 :foreground "black" :background "yellow2")
83 '(swiper-background-match-face-3 :foreground "black" :background "yellow3")
84 '(swiper-background-match-face-4 :foreground "black" :background "yellow4")
85 '(evil-ex-lazy-highlight :foreground "black" :background "yellow2")
86 '(region :foreground "black" :background "yellow") ; selected area
87 '(doom-modeline-buffer-modified :foreground "orange")
88 '(git-gutter-fr:added :foreground "green4" :background "black")
89 '(git-gutter-fr:deleted :foreground "red4" :background "black")
90 '(git-gutter-fr:modified :foreground "orange4" :background "black")
91 '(flycheck-fringe-error :foreground "red")
92 '(flycheck-fringe-warning :foreground "orange")
93 '(flycheck-fringe-info :foreground "purple")
94 '(flycheck-info :underline '(:color "SkyBlue4" :style wave))
95 '(flycheck-warning :underline '(:color "orange" :style wave))
96 '(flycheck-error :underline '(:color "red" :style wave))
97 '(warning :foreground "orange")
98 '(error :foreground "red")
99 '(ivy-minibuffer-match-face-1 :foreground "grey50" :background "black") ; what is between matches
100 '(ivy-minibuffer-match-face-2 :foreground "black" :background "yellow2")
101 '(ivy-minibuffer-match-face-3 :foreground "black" :background "yellow3")
102 '(ivy-minibuffer-match-face-4 :foreground "black" :background "yellow4")
103 ; Violet
104 ;'(haskell-operator-face :foreground "yellow3")
105 ;'(haskell-type-face :foreground "#5a4e82")
106 ;'(haskell-constructor-face :foreground "#8a4f88")
107 ;'(haskell-constructor-face :foreground "#8a4c87")
108 '(haskell-constructor-face :foreground "white" :bold t)
109 ; Almost the same as haskell-constructor-face
110 ; because that pattern does not match on type-contexts correctly
111 '(haskell-type-face :foreground "white" :bold t)
112 '(lsp-face-highlight-read :background "gray10")
113 '(lsp-face-highlight-write :background "gray10")
114 '(mode-line :background "gray20")
115 '(mode-line-inactive :background "gray5")
116 '(solaire-default-face :background "gray10")
117 '(solaire-mode-line-face :background "gray20")
118 '(solaire-mode-line-inactive-face :background "gray5")
119 '(doom-modeline-project-dir :foreground "DeepSkyBlue" :bold t)
120 ;'(magit-diff-context-highlight :foreground "white" :background "black")
121 '(magit-diff-added-highlight :foreground "green")
122 '(magit-diff-removed-highlight :foreground "red")
123 ;;'(font-lock-comment-face ((t (:foreground "cyan" :italic t :slant oblique))))
124 ;;'(font-lock-comment-delimiter-face ((t (:foreground "cyan"))))
125 ;;'(fringe ((t (:foreground "red" :background "black"))))
126 ;;'(whitespace-indentation ((t (:foreground "gray50" :bold t))))
127 ;;'(whitespace-space ((t (:foreground "black" :bold t))))
128 ;;'(whitespace-tab ((t (:foreground "gray50" :bold t))))
129 ;;'(whitespace-trailing ((t (:foreground "red" :bold t))))
130 ;;'(font-lock-builtin-face ((t (:foreground "yellow" :weight bold))))
131 ;;'(font-lock-keyword-face ((t (:foreground "yellow" :weight bold))))
132 ;;'(font-lock-string-face ((t (:foreground "magenta"))))
133 ;;'(font-lock-variable-name-face ((t (:foreground "SpringGreen3" :weight bold))))
134 ;;'(nix-antiquote-face ((t (:foreground "blue"))))
135 ;;'(mode-line ((t (:background "midnight blue" :box (:line-width 1 :color "blue") :height 1.0))))
136 ;;'(mode-line-inactive ((t (:background "grey30" :foreground "white" :box (:line-width 1 :color "grey30") :weight light :height 1.0))))
137 ;;'(mode-line ((t (:family "Noto Sans" :height 0.9))))
138 ;;'(mode-line-inactive ((t (:family "Noto Sans" :height 0.9))))
139 ;;'(solaire-mode-line-inactive-face ((t (:background "gray10"))))
140 )
141
142 ;; polymode
143 (use-package! polymode)
144 (define-hostmode poly-haskell-hostmode
145 :mode 'haskell-mode)
146 ;; Support org tables in Haskell files
147 (defun pm--org-table-tail-matcher (ahead)
148 (when (re-search-forward "^[^|]" nil t ahead)
149 (cons (match-beginning 0) (match-end 0))))
150 (define-innermode poly-haskell-org-table-innermode
151 :mode 'org-mode
152 :head-matcher "^|.*"
153 :tail-matcher #'pm--org-table-tail-matcher
154 :head-mode 'body
155 :tail-mode 'host)
156 (define-polymode poly-haskell-mode
157 :hostmode 'poly-haskell-hostmode
158 :innermodes '(poly-haskell-org-table-innermode))
159
160 ;; Language Server Protocol
161 (setq ;+lsp-prompt-to-install-server 'quiet
162 ;lsp-enable-file-watchers nil
163 ;lsp-enable-indentation nil
164 ;lsp-enable-on-type-formatting nil
165 ;lsp-enable-symbol-highlighting nil
166 lsp-enable-symbol-highlighting nil ; slow
167 lsp-ui-doc-enable nil ; slow
168 ;lsp-ui-sideline-enable nil ; not anymore useful than flycheck
169 ;lsp-ui-peek-enable t
170 ;lsp-ui-peek-always-show nil
171 ;lsp-ui-flycheck-enable t
172 ;lsp-ui-flycheck-live-reporting t
173 ;; Disable help mouse-overs for mode-line segments (i.e. :help-echo text).
174 ;; They're generally unhelpful and only add confusing visual clutter.
175 mode-line-default-help-echo nil
176 show-help-function nil
177 global-prettify-symbols-mode nil
178 prettify-symbols-mode -1
179 lsp-treemacs-errors-position-params `((side . right))
180 lsp-log-io nil ; Only for debugging
181 lsp-restart 'auto-restart
182 ; Only load lsp-clients to speed up loading
183 ; See https://github.com/emacs-lsp/lsp-mode/pull/1498
184 lsp-client-packages '(lsp-clients)
185 )
186
187 ;; The modeline is not useful to me in the popup window.
188 ;; It looks much nicer to hide it.
189 (remove-hook 'emacs-everywhere-init-hooks #'hide-mode-line-mode)
190
191 ;;(remove-hook 'window-setup-hook #'doom-init-theme-h)
192 ;;(add-hook 'after-init-hook #'doom-init-theme-h 'append)
193 ;;(delq! t custom-theme-load-path)
194
195 (setq auto-save-default t ; Nobody likes to loose work, I certainly don't
196 confirm-kill-emacs nil
197 make-backup-files nil
198 password-cache-expiry nil ; I can trust my computers ... can't I?
199 scroll-margin 10
200 ;; scroll-preserve-screen-position 'always ; Don't have `point' jump around
201 truncate-string-ellipsis "…" ; Unicode ellispis are nicer than "...", and also save /precious/ space
202 kill-whole-line t ; Make Ctrl-K remove the whole line, instead of just emptying it
203 undo-limit 80000000 ; Raise undo-limit to 80MB
204 x-stretch-cursor nil ; Disorienting
205 )
206
207 ;; Debugging
208 ;(setq debug-on-quit t)
209
210 ;; Haskell
211 (setq haskell-process-log nil
212 haskell-interactive-popup-errors nil
213 )
214 (add-hook 'haskell-mode-hook
215 (lambda ()
216 (set (make-local-variable 'company-backends)
217 (append '((company-capf company-dabbrev-code))
218 company-backends))))
219 (define-hostmode poly-haskell-hostmode
220 :mode 'haskell-mode)
221
222 ;; Layout
223 (setq split-height-threshold nil
224 split-width-threshold 160
225 )
226
227 (after! flycheck
228 ; flycheck-error-list-buffer
229 (set-popup-rule! (rx bos "*Flycheck errors*" eos) :side 'right :size 0.45)
230 ; M-x lsp-ui-flycheck-list
231 (setq lsp-ui-flycheck-list-position 'right)
232 (add-hook 'flycheck-error-list-mode-hook
233 (lambda () (setq tabulated-list-sort-key (list "Level"))))
234 )
235 ;(add-hook 'flycheck-error-list-after-refresh-hook
236 ; (lambda ()
237 ; (with-selected-window (flycheck-get-error-list-window t)
238 ; (fit-window-to-buffer (flycheck-get-error-list-window t) 30))))
239
240 ;; Completing
241 (add-hook 'after-init-hook 'global-company-mode)
242 ;(setq company-idle-delay nil)
243
244 ;(use-package! ivy
245 ; :defer t
246 ; :bind
247 ; (:map ivy-minibuffer-map
248 ; ("RET" . 'ivy-alt-done)
249 ; ("TAB" . 'ivy-alt-done))
250 ; :init
251 ; (setq ivy-extra-directories nil
252 ; )
253 ; )
254
255 ;(add-hook! 'org-mode-hook #'mixed-pitch-mode)
256 ;(add-hook! 'org-mode-hook #'solaire-mode)
257 ;(setq mixed-pitch-variable-pitch-cursor nil)
258
259 ;(add-hook! org-mode :append
260 ; #'visual-line-mode
261 ; #'variable-pitch-mode)
262
263 (setq doom-modeline-enable-word-count nil)
264
265 (map! "C-x b" #'counsel-buffer-or-recentf
266 "C-x C-b" #'counsel-switch-buffer)
267 (defun recentf-track-visited-file (_prev _curr)
268 (and buffer-file-name
269 (recentf-add-file buffer-file-name)))
270 (after! recentf
271 (add-hook 'switch-buffer-functions #'recentf-track-visited-file))
272
273 ;; Org
274 ; DOC: https://rgoswami.me/posts/org-note-workflow/
275 ; ToStudy: https://github.com/abo-abo/orca
276 ; ToStudy: https://github.com/weirdNox/org-noter
277 ; ToStudy: https://github.com/bastibe/org-journal
278 ; ToStudy: https://orgmode.org/manual/Org-Crypt.html
279 ; DOC: http://www.wouterspekkink.org/academia/writing/tool/doom-emacs/2021/02/27/writing-academic-papers-with-org-mode.html
280 ; DOC: https://jonathanabennett.github.io/blog/2019/05/29/writing-academic-papers-with-org-mode/
281 ; ToStudy: https://github.com/org-roam/org-roam-ui
282 ; ToStudy: https://blog.tecosaur.com/tmio/2021-07-31-citations.html
283 ; ToStudy: https://github.com/jkitchin/org-ref-cite
284 (setq org-directory "~/documents/notes")
285 (setq org-noter-notes-search-path '("~/notes/path/"))
286
287 (after! org
288 (setq org-log-done t
289 org-log-into-drawer t
290 org-special-ctrl-a/e t
291 org-special-ctrl-k t
292 ;org-hide-emphasis-markers t
293 )
294 (add-to-list 'org-capture-templates
295 '("e" "English" table-line ; key, name, type
296 (file "english/vocabulary.org") ; target
297 "|%^{English}|%^{Français}|%^{Registre|Courant|Soutenu|Familier}|"
298 :kill-buffer t))
299 (add-to-list 'org-capture-templates
300 '("x" "Expense" plain
301 (file "compta.org")
302 "\n%(org-read-date) * send %^{Send to} %^{For why}\nExpense:Gifts %^{Amount}\n %^{Currency|EUR|USD|JPY}\n Assets:%^{Account||Personal|Home}"))
303 ;; Firefox and Chrome
304 ;(add-to-list 'org-capture-templates
305 ; `("P" "Protocol" entry ; key, name, type
306 ; (file+headline +org-capture-notes-file "Inbox") ; target
307 ; "* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?"
308 ; :prepend t ; properties
309 ; :kill-buffer t))
310 ;(add-to-list 'org-capture-templates
311 ; `("L" "Protocol Link" entry
312 ; (file+headline +org-capture-notes-file "Inbox")
313 ; "* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n"
314 ; :prepend t
315 ; :kill-buffer t))
316 ; )
317 )
318
319 (map! :after counsel :map org-mode-map
320 "C-c l l h" #'counsel-org-link)
321 (after! counsel
322 (setq counsel-outline-display-style 'title))
323
324 ;(after! org-id
325 ; ;; Do not create ID if a CUSTOM_ID exists
326 ; (setq org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id)
327 ; )
328 ;
329 ;(after! org-agenda
330 ; ;; (setq org-agenda-prefix-format
331 ; ;; '((agenda . " %i %-12:c%?-12t% s")
332 ; ;; ;; Indent todo items by level to show nesting
333 ; ;; (todo . " %i %-12:c%l")
334 ; ;; (tags . " %i %-12:c")
335 ; ;; (search . " %i %-12:c")))
336 ; (setq org-agenda-include-diary t)
337 ; )
338 ;
339 ;(use-package! org-roam
340 ; :defer t
341 ; :hook ((after-init . org-roam-mode))
342 ; :custom
343 ; (setq org-roam-directory "~/documents/notes/org-roam")
344 ;
345 ; ;; Let's set up some org-roam capture templates
346 ; (setq org-roam-capture-templates
347 ; '(("d" "default" plain (function org-roam--capture-get-point)
348 ; "%?"
349 ; :file-name "%<%Y-%m-%d-%H%M%S>-${slug}"
350 ; :head "#+title: ${title}\n"
351 ; :unnarrowed t)))
352 ;
353 ; ;; And now we set necessary variables for org-roam-dailies
354 ; (setq org-roam-dailies-capture-templates
355 ; '(("d" "default" entry
356 ; #'org-roam-capture--get-point
357 ; "* %?"
358 ; :file-name "daily/%<%Y-%m-%d>"
359 ; :head "#+title: %<%Y-%m-%d>\n\n")))
360 ; )
361 ;
362 ;(use-package! org-ref
363 ; :after org-roam
364 ; :config
365 ; (setq reftex-default-bibliography bibliography-files
366 ; org-ref-default-bibliography bibliography-files
367 ; org-ref-bibliography-notes "~/documents/notes/org-roam/bibnotes.org" ;; Is this even needed?
368 ; org-ref-notes-directory "~/documents/notes/org-roam"
369 ; org-ref-notes-function 'orb-edit-notes
370 ; ;org-ref-get-pdf-filename-function 'org-ref-get-pdf-filename-helm-bibtex)
371 ; )
372 ;
373 ;(use-package! bibtex-completion
374 ; :defer t
375 ; :config
376 ; (setq bibtex-completion-notes-path "~/documents/notes/org-roam/"
377 ; bibtex-completion-pdf-field "file"
378 ; bibtex-completion-bibliography bibliography-files
379 ; )
380 ;)
381 ;
382 ;(defvar orb-title-format "${author-or-editor-abbrev} (${date}). ${title}."
383 ; "Format of the title to use for `orb-templates'.")
384 ;
385 ;(use-package! org-roam-bibtex
386 ; :after org-roam
387 ; :hook (org-roam-mode . org-roam-bibtex-mode)
388 ; :bind (:map org-mode-map
389 ; (("C-c n a" . orb-note-actions)))
390 ; :config
391 ; (setq orb-preformat-keywords
392 ; '(("citekey" . "=key=") "title" "date" "author-or-editor-abbrev")
393 ; orb-templates
394 ; `(("r" "ref" plain
395 ; (function org-roam-capture--get-point)
396 ; ""
397 ; :file-name "${citekey}"
398 ; :head ,(s-join "\n"
399 ; (list
400 ; (concat "#+TITLE: " orb-title-format)
401 ; "#+ROAM_KEY: ${ref}"
402 ; ""
403 ; "- tags :: "
404 ; ""
405 ; "* Notes"
406 ; ""))
407 ; :unnarrowed t)
408 ; ("n" "ref + noter" plain
409 ; (function org-roam-capture--get-point)
410 ; ""
411 ; :file-name "${citekey}"
412 ; :head ,(s-join "\n"
413 ; (list
414 ; (concat "#+TITLE: " orb-title-format)
415 ; "#+ROAM_KEY: ${ref}"
416 ; ""
417 ; "- tags :: "
418 ; ""
419 ; "* Annotations :noter:"
420 ; ":PROPERTIES:"
421 ; ":NOTER_DOCUMENT: %(orb-process-file-field \"${citekey}\")"
422 ; ":NOTER_PAGE:"
423 ; ":END:"
424 ; ""))))))
425 ;
426 ;(map! :after pdf-tools
427 ; :map pdf-view-mode-map
428 ; :gn "q" (lambda ()
429 ; (interactive)
430 ; (if (bound-and-true-p org-noter-doc-mode)
431 ; (org-noter-kill-session)
432 ; (kill-current-buffer)))
433 ; )
434 ;
435 ;(use-package! org-noter
436 ; :after (:any org pdf-view)
437 ; :config
438 ; (setq org-noter-notes-search-path '("~/documents/notes/org-roam")
439 ; org-noter-always-create-frame nil
440 ; )
441 ; )
442
443 ;(setq lsp-lens-mode t)
444 (setq doom-modeline-height 1)
445 (setq doom-modeline-lsp t)
446 ;(setq doom-modeline-minor-modes t)
447 ;(setq lsp-modeline-diagnostics-enable t)
448
449 ;; Indenting
450 (setq-default tab-width 2)
451 (setq indent-tabs-mode nil)
452
453 ;; Searching
454 (global-superword-mode t)
455 ; https://emacs.stackexchange.com/questions/9583/how-to-treat-underscore-as-part-of-the-word
456 (modify-syntax-entry ?_ "w")
457 (defun swiper-all/search-word-at-point ()
458 (interactive)
459 (swiper-all (format "%s" (thing-at-point 'word))))
460 ; Highlight without jumping to the next match
461 ; See: https://emacs.stackexchange.com/questions/52411/evil-star-visualstar-without-moving-the-cursor
462 (defun search-word-at-point ()
463 (interactive)
464 (evil-search (progn (evil-ex-search-word-forward)
465 (evil-ex-search-previous)
466 )))
467 (defun search-unbounded-word-at-point ()
468 (interactive)
469 (evil-search (progn (evil-ex-search-unbounded-word-forward)
470 (evil-ex-search-unbounded-word-previous)
471 )))
472 (setq ivy-case-fold-search-default nil ; case-sensitive search by default
473 )
474 (after! evil
475 ;(general-define-key "C-s" '(counsel-grep-or-swiper :which-key "search"))
476 ;(general-define-key :keymaps '(swiper-map) "C-u" '(lambda () (interactive) (kill-line 0)))
477 ;(general-nvmap "/" '(counsel-grep-or-swiper :which-key "search in buffer"))
478 (evil-define-key 'normal global-map
479 (kbd "/") 'swiper
480 (kbd "C-f") 'swiper-all
481 (kbd "C-/") 'swiper-all/search-word-at-point
482 (kbd "*") 'search-word-at-point
483 (kbd "g*") 'search-unbounded-word-at-point
484 )
485 )
486
487 ;; Edition
488 (after! evil
489 (setq evil-want-fine-undo t
490 )
491 (customize-set-variable 'evil-want-Y-yank-to-eol nil)
492 (evil-define-key 'normal global-map (kbd "K") 'evil-join)
493 (evil-define-key 'insert global-map (kbd "C-u") '(lambda () (interactive) (kill-line 0)))
494 (evil-define-key 'normal global-map (kbd "SPC g d") 'git-gutter:popup-hunk)
495 )
496 (setq +vc-gutter-default-style nil
497 )
498 (customize-set-variable 'git-gutter:update-interval 2)
499 ;(customize-set-variable 'git-gutter:window-width 2)
500 (after! git-gutter-fringe
501 (require 'fringe-helper)
502 ; Narrower vertical bar, matching the one in the "+" of git-gutter-fr:added
503 (fringe-helper-define 'git-gutter-fr:modified nil
504 "...XX..."
505 "...XX..."
506 ".XXXXXX."
507 ".XXXXXX."
508 "...XX..."
509 "...XX..."
510 ".XXXXXX."
511 ".XXXXXX.")
512 ; Narrower horizontql bar, matching the one in the "+" of git-gutter-fr:added
513 (fringe-helper-define 'git-gutter-fr:deleted nil
514 "........"
515 "........"
516 "........"
517 ".XXXXXX."
518 ".XXXXXX."
519 "........"
520 "........"
521 "........")
522 )
523
524
525 ;; Folding
526 (defun set-selective-display/at-point (&optional level)
527 "Fold text indented same of more than the cursor.
528 If level is set, set the indent level to LEVEL.
529 If 'selective-display' is already set to LEVEL,
530 calling it again will unset 'selective-display' by setting it to 0."
531 (interactive "P")
532 (if (eq selective-display (1+ (current-column)))
533 (set-selective-display 0)
534 (set-selective-display (or level (1+ (current-column))))))
535 (after! evil
536 (evil-define-key 'normal global-map
537 (kbd "C-d") 'set-selective-display/at-point)
538 )
539 ;; Navigation
540 ;; DOC: https://github.com/noctuid/evil-guide
541 (after! evil
542 (setq evil-cross-lines t
543 evil-move-cursor-back nil
544 evil-search-wrap nil
545 evil-want-C-i-jump nil
546 )
547
548 ;; Switching buffers
549 (evil-define-key 'motion 'global
550 (kbd "<C-i>") 'evil-prev-buffer ; Does not work without the angles ('<' and '>')
551 (kbd "C-k") 'evil-next-buffer
552 )
553 ;(define-key evil-normal-state-map [tab] 'evil-prev-buffer)
554
555 ;; Jumping
556 (evil-define-key 'motion 'global
557 (kbd "C-u") 'better-jumper-jump-backward
558 (kbd "C-o") 'better-jumper-jump-forward
559 )
560
561 ;; Moving with ijkl (instead of hjkl)
562 (evil-define-key '(motion normal visual) 'global
563 (kbd "i") 'evil-previous-visual-line
564 (kbd "j") 'evil-backward-char
565 (kbd "k") 'evil-next-visual-line
566 (kbd "h") 'evil-insert
567 )
568
569 ;; Switching windows with SPC-w + ijkl (instead of hjkl)
570 (define-key evil-window-map "i" 'evil-window-up)
571 (define-key evil-window-map "I" 'evil-window-move-very-top)
572 (define-key evil-window-map "j" 'evil-window-left)
573 (define-key evil-window-map "J" 'evil-window-move-far-left)
574 (define-key evil-window-map "k" 'evil-window-down)
575 (define-key evil-window-map "K" 'evil-window-move-very-bottom)
576 ;(define-key evil-emacs-state-map "\C-w" 'evil-window-map)
577 ;;(evil-define-key 'window global-map "l" 'evil-window-right)
578 ;;(evil-define-key 'window global-map "L" 'evil-window-move-far-right)
579
580 ;; ijkl in Dired
581 ;;(evil-define-key 'normal dired-mode-map "i" 'evil-previous-line)
582
583 ;; Errors
584 (evil-define-key 'motion 'global
585 (kbd "C-j") 'previous-error
586 (kbd "C-l") 'next-error
587 )
588 ;(bind-key "C-j" #'previous-error)
589 ;(bind-key "C-l" #'next-error)
590 )
591 (after! auto-yasnippet
592 (evil-define-key '(motion normal) 'global
593 (kbd "C-<tab>") 'evil-switch-to-windows-last-buffer
594 )
595 )
596 (after! (evil magit evil-collection-magit)
597 (evil-define-key '(motion normal) magit-mode-map
598 (kbd "C-i") 'evil-prev-buffer
599 (kbd "i") 'evil-previous-visual-line
600 (kbd "k") 'evil-next-visual-line
601 (kbd "C-k") 'evil-next-buffer
602 (kbd "j") 'magit-section-backward
603 (kbd "l") 'magit-section-forward
604 )
605 )
606 (after! (evil magit git-rebase)
607 (evil-define-key '(motion normal) git-rebase-mode-map
608 (kbd "C-i") 'evil-prev-buffer
609 (kbd "i") 'evil-previous-visual-line
610 (kbd "k") 'evil-next-visual-line
611 (kbd "C-k") 'evil-next-buffer
612 (kbd "j") 'evil-backward-char
613 )
614 )
615 ;;(eval-after-load 'evil ; to run after evil-integration.el
616 ;; '(progn
617 ;; (define-key Buffer-menu-mode-map "\C-i" 'evil-prev-buffer)
618 ;; (define-key Buffer-menu-mode-map "\C-k" 'evil-next-buffer)
619 ;; (define-key messages-buffer-mode-map "\C-i" 'evil-prev-buffer)
620 ;; (define-key messages-buffer-mode-map "\C-k" 'evil-next-buffer)
621 ;; (define-key completion-list-mode-map "\C-i" 'evil-prev-buffer)
622 ;; (define-key completion-list-mode-map "\C-k" 'evil-next-buffer)
623 ;; ;(define-key custom-theme-mode-map "\C-i" 'evil-prev-buffer)
624 ;; ;(define-key custom-theme-mode-map "\C-k" 'evil-next-buffer)
625 ;; )
626 ;; )
627
628 ;;(with-eval-after-load 'evil-maps
629 ;; (define-key evil-motion-state-map (kbd "TAB") nil))
630
631 ;; Feed reader
632 ; See also: Managing ArXiv RSS Feeds in Emacs https://cundy.me/post/elfeed/
633
634 (setq
635 elfeed-enable-web-interface t
636 url-queue-timeout 30
637 )
638 ;(global-set-key (kbd "C-x w") 'elfeed)
639
640 (defun elfeed-mark-all-as-read ()
641 (interactive)
642 (mark-whole-buffer)
643 (elfeed-search-untag-all-unread))
644
645 ; Functions to support syncing .elfeed between machines
646 ; makes sure elfeed reads index from disk before launching
647 (defun elfeed-load-db-and-open ()
648 "Wrapper to load the elfeed db from disk before opening"
649 (interactive)
650 (elfeed-db-load)
651 (elfeed)
652 (elfeed-search-update--force))
653
654 ; Write to disk when quiting
655 (defun elfeed-save-db-and-bury ()
656 "Wrapper to save the elfeed db to disk before burying buffer"
657 (interactive)
658 (elfeed-db-save)
659 (quit-window))
660
661 (defun elfeed-toggle-star ()
662 "Toggle star"
663 (interactive)
664 (elfeed-search-tag-all '*)
665 )
666 (after! (evil elfeed evil-collection-elfeed)
667 (evil-define-key 'motion elfeed-search-mode-map "m" #'elfeed-toggle-star)
668 )
669
670 (defun elfeed-org-update-incremental ()
671 "Automatically update the feeds from feeds.org when updated"
672 (setq my-elfeed-org-last (or (and (boundp 'elfeed-feeds) elfeed-feeds) nil))
673 (elfeed)
674 (setq my-elfeed-org-current elfeed-feeds)
675 (let ((elfeed-feeds (-difference my-elfeed-org-current my-elfeed-org-last)))
676 ;; You don't need the line below if you don't want to see a message about what feeds are being updated
677 (message "%s" elfeed-feeds)
678 (mapc #'elfeed-update-feed (elfeed--shuffle (elfeed-feed-list))))
679 (setq elfeed-feeds my-elfeed-org-current))
680