summaryrefslogtreecommitdiffstats
path: root/vanilla.el
blob: 3d82003532b34be7eec8b28835d0486e3447e9bc (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
(setq user-full-name "Yann Herklotz")
(setq user-mail-address "yann@yannherklotz.com")

(setq gc-cons-threshold (* 1024 1024 1024))

;; Set some global key rebindings, mainly trying to use `*-dwim' functions
;; whenever possible and making other common functions more convenient.  The
;; main keybinding that conflicts with other modes is `C-.' or `C-,'.
(global-set-key (kbd "M-u") #'upcase-dwim)
(global-set-key (kbd "M-l") #'downcase-dwim)
(global-set-key (kbd "M-c") #'capitalize-dwim)
(global-set-key (kbd "C-c z") #'quick-calc)
(global-set-key (kbd "<f5>") #'revert-buffer)
(global-set-key (kbd "C-.") #'other-window)
(global-set-key (kbd "C-,") #'ymh/prev-window)
(global-set-key (kbd "C-\\") #'undo-only)
(global-set-key (kbd "M-SPC") (lambda () (interactive) (insert " ")))
(global-set-key (kbd "C-<tab>") #'tab-bar-switch-to-recent-tab)

(global-set-key (kbd "C-c l") #'org-store-link)
(global-set-key (kbd "C-c c") #'org-capture)

(define-key global-map (kbd "M-Q") #'ymh/unfill-paragraph)

;; Create my own keymap for other, less important but still useful commands
;; which I want to have quick access to.  This can be quite flexible, and it
;; might change depending on what I need or how the configuration changes.
(define-prefix-command 'ymh-map)
(global-set-key (kbd "C-c y") 'ymh-map)
(define-key ymh-map (kbd "o") #'ymh/reset-coq-windows)
(define-key ymh-map (kbd "c") #'calendar)
(define-key ymh-map (kbd "C-l") #'org-agenda-open-link)
(define-key ymh-map (kbd "C-p") #'org-previous-link)
(define-key ymh-map (kbd "C-n") #'org-next-link)

;; Create variables which hold default locations for various things like my Org
;; directory or the directory containing the bibliography.  This makes it much
;; easier to migrate the configuration.
(defvar ymh/org-base-dir "~/Dropbox/org"
  "Contains the base directory for Org files.")

(defvar ymh/keyboard :default
  "Define which keyboard is being used.

Should be one of `:white-split', `:modified' or `:default'")

(defvar ymh/bib-base-dir "~/Dropbox/bibliography"
  "Contains the base directory for the bibliography related files.")

;; Define functions using the previous variables and `expand-file-name' to
;; calculate the full path for any file correctly.
(defun ymh/expand-org-file (file)
  "Expand FILE name relative to `ymh/org-base-dir'."
  (expand-file-name file ymh/org-base-dir))

(defun ymh/expand-bib-file (file)
  "Expand FILE name relative to `ymh/bib-base-dir'."
  (expand-file-name file ymh/bib-base-dir))

;; Set registers for commonly accessed files, especially org-mode files that
;; will be edited a lot.  In general, I use `org-capture' to edit the Org files
;; in particular though.
(set-register ?l (cons 'file (expand-file-name "init.el" user-emacs-directory)))
(set-register ?m (cons 'file (ymh/expand-org-file "meetings.org")))
(set-register ?i (cons 'file (ymh/expand-org-file "inbox.org")))
(set-register ?p (cons 'file (ymh/expand-org-file "projects.org")))
(set-register ?c (cons 'file (ymh/expand-org-file
                              (format-time-string "%Y-%m.org"))))

;; Emacs 29 contains some packages that otherwise need to be downloaded from
;; Melpa, and in addition to that it also allows for the installation of
;; packages using git.
(defvar ymh/emacs-29-p (version<= "29" emacs-version)
  "Checks if the current Emacs version is 29 or not.")

;; There are also some changes that are means for MacOS only, so it's useful to
;; have a flag for that as well.
(defvar ymh/macos-p (eq system-type 'darwin)
  "Checks if the current operating system is MacOS.")

;; Add linker arguments when compiling for macos.
(when ymh/macos-p (customize-set-variable 'native-comp-driver-options '("-Wl,-w")))

;; I currently use 80 as the default fill column width as it works on low-res
;; displays as well.
(setq-default fill-column 80)

(setq completion-cycle-threshold 3)
(setq tab-always-indent 'complete)

;; Some simple configurations which make using the interface a bit nicer.
(setq use-short-answers t)
(setq inhibit-startup-message t)
(setq confirm-nonexistent-file-or-buffer nil)
(setq ring-bell-function 'ignore)

;; I always end sentences in two spaces so that emacs can detect them easier.
(setq sentence-end-double-space t)

;; Follow symlinks when opening a file.
(setq find-file-visit-truename t)
(setq vc-follow-symlinks t)

;; When you have two dired buffers open, it will copy them from one to the
;; other automatically.
(setq dired-dwim-target t)
(setq wdired-allow-to-change-permissions t)

;; Some performance improvements because I do not use right-to-left text.
(setq truncate-partial-width-windows nil)
(setq-default bidi-paragraph-direction 'left-to-right)
(if (version<= "27.1" emacs-version)
    (setq bidi-inhibit-bpa t))

(setq read-extended-command-predicate
      #'command-completion-default-include-p)

(setq enable-recursive-minibuffers t)

;; Clean up backup directories.
(defvar --backup-directory)
(setq --backup-directory (expand-file-name "backups" user-emacs-directory))
(if (not (file-exists-p --backup-directory))
    (make-directory --backup-directory t))
(setq backup-directory-alist
      `(("^/dev/shm/" . nil)
        ("^/tmp/" . nil)
        ("." . ,--backup-directory)))
(setq make-backup-files t)
(setq backup-by-copying t)
(setq version-control t)
(setq delete-old-versions t)
(setq delete-by-moving-to-trash t)
(setq kept-old-versions 6)
(setq kept-new-versions 9)
(setq auto-save-default t)
(setq auto-save-timeout 20)
(setq auto-save-interval 200)

;; Setup some options to be able to use changelog mode.
(setq add-log-full-name user-full-name)
(setq add-log-mailing-address "git@yannherklotz.com")
(setq change-log-default-name "CHANGELOG")
(add-hook 'change-log-mode-hook
	      (lambda ()
	        (make-local-variable 'tab-width)
	        (make-local-variable 'left-margin)
	        (setq tab-width 2
		          left-margin 2)))

;; Set indentation settings for various languages.
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq-default python-indent-offset 4)
(setq-default c-basic-offset 4)

(setq line-number-display-limit 2000000)

;; Remove the emacs border when on Linux.
(unless ymh/macos-p
  (setq default-frame-alist '((undecorated . t)
                              (drag-internal-border . 1)
                              (internal-border-width . 5))))

(setq auth-sources '("~/.authinfo" "~/.authinfo.gpg" "~/.netrc"))

;; Set visual new line indicators when using `visual-line-mode'.
(setq visual-line-fringe-indicators '(left-curly-arrow nil))

(unless ymh/macos-p
  (menu-bar-mode -1))
(tool-bar-mode -1)
(scroll-bar-mode -1)
(column-number-mode 1)

(global-display-fill-column-indicator-mode)

(add-hook 'text-mode-hook #'visual-line-mode)
(add-hook 'text-mode-hook #'auto-fill-mode)

;; Enable those
(dolist (c '(overwrite-mode narrow-to-region narrow-to-page upcase-region
                            downcase-region))
  (put c 'disabled nil))

(set-frame-font "Iosevka YMHG Semibold-10" nil t)

(add-to-list 'mode-line-misc-info
             '(t ("[t:" (:eval (alist-get 'name (tab-bar--current-tab))) "] ")))

;; Mac configuration
(when ymh/macos-p
  (cl-case ymh/keyboard
    (:white-split (setq mac-right-option-modifier 'hyper
                        mac-command-modifier 'meta
                        mac-option-modifier 'super))
    (:modified (setq mac-right-option-modifier 'meta
                     mac-command-modifier 'super
                     mac-option-modifier 'hyper))
    (:default (setq mac-right-option-modifier 'hyper
                    mac-command-modifier 'meta
                    mac-option-modifier 'super)))
  (add-hook 'ns-system-appearance-change-functions #'ymh/apply-theme))

(provide 'vanilla)