summaryrefslogtreecommitdiff
path: root/init.el
blob: e82f7134e181f6614355a905ed52f2c041283799 (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
;; Start maximized
(add-to-list 'default-frame-alist '(fullscreen . maximized))

;; Font
(add-to-list 'default-frame-alist `(font . "IBM Plex Mono 12"))

;; Add line numbers
(setq display-line-numbers t)
(add-hook 'prog-mode-hook 'display-line-numbers-mode)

;; Visualize whitespace for programming modes
;; Yoinked from Rexim (Tsoding)
;; https://github.com/rexim/dotfiles/blob/a96479ac248e8d1b3ad307fdd667eb4593eec56d/.emacs.custom.el#L31
(setq whitespace-style
      '(face
        tabs
        spaces
        trailing
        space-before-tab
        newline
        indentation
        empty
        space-after-tab
        space-mark
        tab-mark))
(add-hook 'prog-mode-hook 'whitespace-mode)

;; support for use-package on imenu
(setopt use-package-enable-imenu-support t)

;; Melpa
(require 'package)
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/") t)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

;; Ensure packages by default
(require 'use-package-ensure)
(setq use-package-always-ensure t)

;; Better defaults
(use-package vertico
  :init (vertico-mode))

(use-package better-defaults                   ; It is important to run after vertico
                                               ; or it will run completion with ido
  :after vertico)
(setq help-window-select t)                    ; Automatically move cursor into help window
(setq kill-do-not-save-duplicates t)           ; No duplicates in the kill ring

;; Here’s a scenario: you copy a URL from your browser, switch to Emacs, kill a line with C-k,
;; and then try to yank the URL you copied earlier with C-y. Gone. The kill replaced it on the
;; clipboard.  This setting makes Emacs save the existing clipboard content into the kill ring
;; before overwriting it:
(setq save-interprogram-paste-before-kill t)

(setq read-process-output-max (* 1024 1024 4)) ; Increase garbage collection threshold

(setq-default bidi-display-reordering 'left-to-right   ; Disables bidirectional scanning
              bidi-paragraph-direction 'left-to-right) ; aka. RTL language support
(setq bidi-inhibit-bpa t)

(use-package no-littering)                     ; Move litter to separate dirs

(global-auto-revert-mode 1)                    ; Update files changed externally
(setq global-auto-revert-non-file-buffers t)   ; Update dired when directory changes

(setq calendar-week-start-day 1)               ; Start calendar on Monday

(which-key-mode)                               ; Enable which-key (didn't know this is built-in now!)

(delete-selection-mode 1)
(setq-default fill-column 94)                  ; Fill columns to half of my laptop's screen

;; Spellcheck
(unless (eq system-type 'windows-nt)
  (setq ispell-program-name "aspell")
  (add-hook 'text-mode-hook 'flyspell-mode)
  (add-hook 'prog-mode-hook 'flyspell-prog-mode))

;; Multiple-cursors
(use-package multiple-cursors
  :bind
  ("C-S-c C-S-c" . mc/edit-lines)
  ("C->" . mc/mark-next-like-this)
  ("C-<" . mc/mark-previous-like-this)
  ("C-c C-<" . mc/mark-all-like-this))

;; Org & Agenda
(global-set-key (kbd "C-c l") #'org-store-link)
(global-set-key (kbd "C-c a") #'org-agenda)
(global-set-key (kbd "C-c c") #'org-capture)

(setq org-directory "~/Documents/Org"
      org-agenda-directory (file-name-concat org-directory "Agenda")
      org-agenda-files (list org-agenda-directory))

(setq org-html-head ""
      org-html-head-extra ""
      org-html-head-include-default-style nil
      org-html-head-include-scripts nil
      org-html-preamble nil
      org-html-postamble nil
      org-html-use-infojs nil)

(setq org-capture-templates
      `(("t" "Todo" entry (file ,(file-name-concat org-agenda-directory "Todo.org"))
         "* TODO %?\n %i\n")))

;; Roam
(use-package org-roam
  :custom
  (org-roam-directory (file-truename (if (eq system-type 'windows-nt)
                                         "D:/Documents/Org/Roam"
                                       "~/Documents/Org/Roam/")))
  :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)
         ("C-c n c" . org-roam-capture))
  :config
  (org-roam-db-autosync-mode))

;; Emacs theme
(use-package tokyonight-themes
  :vc (:url "https://github.com/xuchengpeng/tokyonight-themes")
  :config (load-theme 'tokyonight-moon :no-confirm))

(use-package company
  :hook (after-init . company-mode))

;; Retro-active completion
(use-package orderless
  :custom
  (completion-styles '(orderless basic))
  (completion-category-overrides '((file (styles basic partial-completion)))))

;; Annotations in minibuffer
(use-package marginalia
  :bind
  (:map minibuffer-local-map ("M-A" . marginalia-cycle))
  :commands marginalia-mode
  :init (add-hook 'after-init-hook #'marginalia-mode))

;; pdf-tools
(use-package pdf-tools
  :config
  ;; Let's face it, I'll be more likely reading PDFs than editing 😉
  (add-to-list 'auto-mode-alist '("\\.pdf\\'" . pdf-view-mode)))

;; Magit
(use-package magit)

;; Markdown
(use-package markdown-mode)

;; Treesitter grammars
(setq treesit-language-source-alist
      '((css "https://github.com/tree-sitter/tree-sitter-css" "v0.23.2")
        (go "https://github.com/tree-sitter/tree-sitter-go")
        (html "https://github.com/tree-sitter/tree-sitter-html" "v0.23.2")
        (java "https://github.com/tree-sitter/tree-sitter-java" "v0.23.5")
        (javascript "https://github.com/tree-sitter/tree-sitter-javascript" "v0.25.0")
        (jsdoc "https://github.com/tree-sitter/tree-sitter-jsdoc" "v0.25.0")
        (nix "https://github.com/nix-community/tree-sitter-nix" "tree-sitter-0.25")
        (php "https://github.com/tree-sitter/tree-sitter-php" "v0.23.12" "php/src")
        (phpdoc "https://github.com/claytonrcarter/tree-sitter-phpdoc" "v0.1.6")
        (python "https://github.com/tree-sitter/tree-sitter-python" "v0.25.0")))

;; Treesitter languages
(add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode))
(add-to-list 'auto-mode-alist '("\\.java\\'" . java-ts-mode))

;; Nix
(use-package nix-ts-mode
  :mode "\\.nix\\'")

;; Web development
(use-package web-mode
  :config
  ;; PHP & Laravel
  (add-to-list 'auto-mode-alist '("\\.php\\'" . php-ts-mode))
  (add-to-list 'auto-mode-alist '("^artisan$" . php-ts-mode))
  (add-to-list 'auto-mode-alist '("\\.blade\\.php\\'" . web-mode)))