-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.el
384 lines (321 loc) · 14 KB
/
init.el
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
;;==========================================================
;; GENERAL SETUP
;;==========================================================
;; speed up start
(setq gc-cons-threshold 100000000) ; provide more memory
;; don't show startup message
(setq inhibit-startup-message t)
;; character encodings default to utf-8.
(prefer-coding-system 'utf-8)
(set-language-environment 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
;; treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;; MS Windows clipboard is UTF-16LE
(when (eq system-type 'windows-nt)
(set-clipboard-coding-system 'utf-16le-dos))
;; start emacs server
;; (server-start) ; uncomment this, if you want the server to start on every start-up
;; Emacs 28: Use the older, more tolerant version of seq-empty-p.
(when (= emacs-major-version 28)
(require 'seq-24))
;;==========================================================
;; DIRECTORIES SETUP
;;==========================================================
;; set home directory
;; 1: check HOME variable
(when (or
(not (getenv "HOME"))
(string-equal (getenv "HOME") "")
)
(if (y-or-n-p "Environment variable HOME not set! Do this now?")
(progn
(call-interactively 'tl-ask-home)
)
(progn )
)
)
;; 2: ask for HOME path
(defun tl-ask-home (path)
(interactive "sHOME: ")
(setenv "HOME" path)
(message "HOME variable was set to: %s (only for this session)" path)
)
;; 3: set default-directory
(setq default-directory (expand-file-name (concat (getenv "HOME") "/")))
(defvar home-directory default-directory)
(when (getenv "EMACS_USER_DIRECTORY")
(setq user-emacs-directory
(expand-file-name (concat (getenv "EMACS_USER_DIRECTORY") "/"))))
;; set path to local lisp libaries
(defvar lisp-dir)
(setq lisp-dir
(expand-file-name "lisp" user-emacs-directory))
(add-to-list 'load-path lisp-dir)
;; save point position between sessions
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file (expand-file-name ".places" user-emacs-directory))
;;================================================================
;; PRIVATE SETTINGS: DIRECTORIES & FILES (outside .emacs.d)
;;================================================================
(defvar org-directory
(expand-file-name "org/" home-directory) ; default value; may be overwritten by private directory settings
"Path to private org notes.
This variable should be changed in private-emacs-settings-before.el.")
(defvar my-deft-dir org-directory ; default value; may be overwritten by private directory settings
"Path to the directory that deft observes.
This variable should be changed in private-emacs-settings-before.el.")
(defvar my-org-roam-directory org-directory ; default value; may be overwritten by private directory settings
"Path to the directory that org-roam uses.
This variable should be changed in private-emacs-settings-before.el.")
(defvar authinfo-directory home-directory ; default value; may be overwritten by private directory settings
"Path to authinfo.
This variable should be changed in private-emacs-settings-before.el.")
(defvar private-emacs-settings-dir
(expand-file-name "private-emacs-settings/" user-emacs-directory) ; default value; may be overwritten by system variable PRIVATE_EMACS_SETTINGS
"Path to private Emacs settings directory.
This variable can be changed with the system variable PRIVATE_EMACS_SETTINGS.")
(if (getenv "PRIVATE_EMACS_SETTINGS")
(message "Info: PRIVATE_EMACS_SETTINGS=%s" (expand-file-name (getenv "PRIVATE_EMACS_SETTINGS")))
(message "Warning: system variabel PRIVATE_EMACS_SETTINGS"))
(defvar my-bbdb-file
(expand-file-name "bbdb" user-emacs-directory)
"Path to bbdb file.
This variable should be changed in private-emacs-settings-before.el.")
(require 'bookmark)
(defvar my-bookmarks-file
(concat bookmark-default-file)
"Path to bookmarks file.
This variable should be changed in private-emacs-settings-before.el.")
;; if system variable exists, use it
(when (getenv "PRIVATE_EMACS_SETTINGS")
(setq private-emacs-settings-dir
(expand-file-name (concat (getenv "PRIVATE_EMACS_SETTINGS") "/"))))
(require 'subr-x) ; string-remove-prefix needs this
(defvar trimmed-private-emacs-settings-dir
(concat "~/" (string-remove-prefix home-directory private-emacs-settings-dir))
"This variable contains the trimmed version of the path in private-emacs-settings-dir starting with ~/.
Using trimmed paths is necessary with some packages, e.g. calfw.
")
(defvar docsets-dir
(expand-file-name "docsets/" home-directory)
"Path to docsets directory.
This variable should be changed in private-emacs-settings-before.el.")
(defvar music-dir
(expand-file-name "Music/" home-directory)
"Path to music directory.
This variable should be changed in private-emacs-settings-before.el.")
(defvar backup-dir
(expand-file-name "backup/" user-emacs-directory)
"Path to backup directory.
This variable should be changed in private-emacs-settings-before.el.")
(defvar mail-dir
(expand-file-name "Maildir/" home-directory)
"Path to mail directory.
This variable should be changed in private-emacs-settings-before.el.")
(defvar personal-dictionary-file
nil
"Path to personal dictionary file that is used by ispell.
This variable should be changed in private-emacs-settings-before.el.")
(defvar personal-dictionary-dir
nil
"Path to directory with personal dictionaries that is used by ispell.
This variable should be changed in private-emacs-settings-before.el.")
(defvar langtool-dir
nil
"Path to directory with langtool resources.
This variable should be changed in private-emacs-settings-before.el.")
(defvar share-dir
(expand-file-name "share/" user-emacs-directory)
"Path to directory with shared resources.
This variable should be changed in private-emacs-settings-before.el.")
;;==========================================================
;; PRIVATE SETTINGS: USER INFO (outside .emacs.d)
;;==========================================================
;; GENERAL USER INFO
(defvar user-acronym "user-acronym"
"Contains the acronym of the user name, which is used, e.g., in cm-mode.
This variable should be changed in private-emacs-settings.el.")
;; MISCELLANEOUS USER SETTINGS
(defvar user-bibliography-file
"/path/to/bibliography.bib"
"Path to the user bibliography file.
This variable should be changed in private-emacs-settings.el.")
(defvar user-bibliography-pdf-dir
"/path/to/pdfs/"
"Path to the user directory of PDFs belonging to the bibliography.
This variable should be changed in private-emacs-settings.el.")
(defvar user-bibliography-notes-dir
"/path/to/pdfs/"
"Path to the user directory of notes belonging to the bibliography.
This variable should be changed in private-emacs-settings.el.")
(defvar user-deepl-key
"key"
"Authentication Key for DeepL API
This variable should be changed in private-emacs-settings.el.")
;; load file with private settings before generic settings
(let ((private-settings-file (expand-file-name "private-emacs-settings-before.el" private-emacs-settings-dir)))
(when (file-exists-p private-settings-file)
(load-file private-settings-file)))
;;==========================================================
;; WEMACS
;;=========================================================
(when (eq system-type 'windows-nt)
(defvar wemacs-dir "")
(when (getenv "WEMACS_HOME")
;; set path to wemacs folder with additional third-party software
(setq wemacs-dir
(expand-file-name (getenv "WEMACS_HOME"))))
(when (getenv "WEMACS_PATH")
;; using setenv makes available the PATH variable to the emacs shells
(setenv "PATH" (expand-file-name (concat (getenv "WEMACS_PATH") ";" (getenv "PATH"))))
;; using exec-path makes available the PATH variable to the rest of emacs
(setq exec-path
(append (split-string (expand-file-name (getenv "WEMACS_PATH")) ";") exec-path))
;; (setq exec-path (concat (getenv "PATH") ";" exec-path))
)
;; the following can be left implicit
;; ;; use ported gnu find command under windows
;; ;; findutils seems to be faster than gnuwin32
;; (setq find-program
;; (expand-file-name
;; (concat wemacs-dir "/findutils/bin/find")))
;; ;; use external ls instead of ls-lisp
;; ;; (caveat: grouping of directories might not work out of the box any more.)
;; (setq ls-lisp-use-insert-directory-program t)
;; make PC keyboard's Win key to type Super or Hyper, for emacs running on Windows.
(progn
(setq w32-pass-lwindow-to-system nil)
(setq w32-lwindow-modifier 'super) ; Left Windows key
)
)
;;==========================================================
;; CUSTOM.EL
;;=========================================================
;; Font
(defvar custom-default-font "DejaVu Sans Mono" nil)
(defvar custom-fixed-pitch-font "DejaVu Sans Mono" nil)
(defvar custom-variable-pitch-font "Segoe UI" nil)
;; ;; The following was supposed to check the availability of Segoe UI with a fall-back option.
;; ;; Unfortunately, `find-font` only works as expected when a frame
;; ;; is already present, which is not the case when loading the emacs daemon.
;; ;; A solution is described here: https://emacs.stackexchange.com/questions/12351/when-to-call-find-font-if-launching-emacs-in-daemon-mode
;; (when (not (find-font (font-spec :name "Segoe UI"))) ; Segoe UI might be unavailable on Linux
;; (setq custom-variable-pitch-font "Arial"))
;; stolen from custom.el (can be overridden by custom.el)
(custom-set-faces
`(default ((t (:family ,custom-default-font :foundry "outline" :slant normal :weight normal :height 113 :width normal))))
`(fixed-pitch ((t (:family ,custom-fixed-pitch-font :foundry "outline" :slant normal :weight normal :height 113 :width normal))))
`(variable-pitch ((t (:family ,custom-variable-pitch-font :foundry "outline" :slant normal :weight normal :height 125 :width normal))))
)
;; load custom file
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(if (file-exists-p custom-file)
(load custom-file)
(message "Warning: custom.el not found.")
)
;;==========================================================
;; PACKAGE MANAGEMENT
;;==========================================================
(when (>= emacs-major-version 24)
(require 'package)
(setq package-archives
'(("GNU ELPA" . "http://elpa.gnu.org/packages/")
("MELPA Stable" . "https://stable.melpa.org/packages/")
("MELPA" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/"))
package-archive-priorities
'(("MELPA Stable" . 10)
("GNU ELPA" . 5)
("MELPA" . 0)
("org" . 0)))
;; (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
;; (add-to-list 'package-archives ; repository of the sunrise commander
;; '("SC" . "http://joseito.republika.pl/sunrise-commander/") t)
(package-initialize))
;; list the packages you want
(setq package-list '(async ; paradox needs async
paradox
use-package ; built-in as of v29
org ; built-in
))
;; ;; fetch the list of packages available
;; (unless package-archive-contents
;; (package-refresh-contents))
;; install the missing packages (and refresh the package list if necessary)
(setq package-list-refreshed nil)
(dolist (package package-list)
(unless (package-installed-p package)
(if package-list-refreshed ; package list already refreshed?
(package-install package) ; package list already refreshed!
(progn (package-refresh-contents) ; package list not yet refreshed!
(setq package-list-refreshed t)
(package-install package))
)
)
)
;; upgrade packages (this slows down start-up somewhat)
;; (paradox-upgrade-packages)
;; upgrade org-mode if necessary
;; (require 'org)
;; (when (version< org-version "9.3")
;; (when (not package-list-refreshed) ; package list already refreshed?
;; (package-refresh-contents) ; package list not yet refreshed!
;; (setq package-list-refreshed t))
;; (paradox-upgrade-packages)
;; (require 'org))
;; use-package
;; taken from https://github.com/jwiegley/use-package
(eval-when-compile
(require 'use-package))
(setq use-package-verbose t)
(use-package diminish ; if you use :diminish
:ensure t)
(require 'bind-key)
;; quelpa: a tool to compile and install Emacs Lisp packages
(use-package quelpa
:ensure t)
(quelpa
'(quelpa-use-package
:fetcher git
:url "https://github.com/quelpa/quelpa-use-package.git"))
(require 'quelpa-use-package)
;; straight.el: yet another (purely functional) package manager
;; https://github.com/raxod502/straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;; ;; el-get
;; ;; https://github.com/dimitri/el-get
;; (use-package el-get
;; :pin MELPA
;; :ensure t)
;; ;; (add-to-list 'el-get-recipe-path "~/.emacs.d/el-get/el-get/recipes")
;; ;; (setq el-get-recipe-path '("~/.emacs.d/el-get/el-get/recipes"))
;; (el-get 'sync)
;;==========================================================
;; LOAD REMAINING SETTINGS
;;==========================================================
;; the remaining settings are in org-init.org
(setq org-fold-core-style 'overlays) ; Org v9.6 comes with a new folding technique.
; Use the old folding technique with overlays for
; better interoperability with 3rd-party packages.
; This variable must be set before loading Org.
(require 'org)
(defvar org-init-file "org-init.org")
(org-babel-load-file
(expand-file-name org-init-file
user-emacs-directory))
(put 'dired-find-alternate-file 'disabled nil)