-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
499 lines (450 loc) · 17.7 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
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
;;; -*- lexical-binding: t -*-
;; Configure MELPA
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(add-to-list 'package-archives (cons "jcs-elpa" (concat proto "://jcs-emacs.github.io/jcs-elpa/packages/")) t)
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)
;; Set load path
;; Add ~/.emacs.d/site-lisp
(add-to-list 'load-path
(concat user-emacs-directory "/site-lisp"))
;; Launch edit-server in daemon mode
;; Disabled, rarely used currently
;; (when (and (daemonp) (locate-library "edit-server"))
;; (setq edit-server-new-frame nil)
;; (edit-server-start))
;; Theme configuration
(defvar theme 'tangotango "The current theme")
(defun ffort-theme-configure-theme ()
"Loads the theme using the variable theme"
(load-theme theme t))
;; Allow to restore window configurations
;; Disabled for now
;; (winner-mode 1)
(defun reload-config ()
"Reload configuration file"
(interactive)
(load-file user-init-file))
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation"
(interactive)
(revert-buffer :ignore-auto :noconfirm))
(defun kill-current-buffer ()
"Kill current buffer, if it is unmodified"
(interactive)
(kill-buffer))
(defun open-config ()
"Open the emacs configuration file"
(interactive)
(find-file user-init-file))
(defun open-config-other-window ()
"Open the emacs configuration file"
(interactive)
(find-file-other-window user-init-file))
(defun show-current-filename ()
"Print the current buffer's filename"
(interactive)
(message (buffer-file-name)))
(defun split-4-ways ()
"Split the window in four. Cursor remains in the top left window. Only works if there is only one window open."
(interactive)
(when (= 1 (length (window-list)))
(split-window-right)
(split-window-below)
(other-window 2)
(split-window-below)
(other-window 2)))
;; Sync packages
(defcustom ffort-sync-last-filename
"last-sync"
"Path to the file storing the date of the last sync"
:type 'string)
(defun ffort-sync-last-path ()
(expand-file-name (concat "./" ffort-sync-last-filename) user-emacs-directory))
(defun ffort-sync-write-last ()
(condition-case nil
(f-write-text (format "%s" (current-time)) 'utf-8 (ffort-sync-last-path))
(error nil)))
(defun ffort-sync-read-last ()
(condition-case nil
(time-convert (read (f-read-text (ffort-sync-last-path))))
(error '(0 0))))
(defun ffort-sync ()
(interactive)
(package-refresh-contents)
(dolist (pkg package-selected-packages)
(let ((archive-pkg (car (cdr (assoc pkg package-archive-contents)))))
(cond
((null archive-pkg)
(lwarn :warning "Package %s is not available in the archive" pkg))
((package-desc-p archive-pkg)
(let ((local-pkg (car (cdr (assoc pkg package-alist))))
(pkg-name (package-desc-full-name archive-pkg)))
(cond
((null local-pkg) (package-install pkg))
((version-list-< (package-desc-version local-pkg)
(package-desc-version archive-pkg))
(package-reinstall pkg))
((version-list-= (package-desc-version local-pkg)
(package-desc-version archive-pkg))
(lwarn :debug "Package %s is up-to-date" pkg-name))
(t (lwarn :debug "Package %s is neither up-to-date nor too old" pkg-name))
)
)
)
(t (message "%s is not a package but a %s" pkg (symbol-name (type-of pkg))))
)
)))
(defun ffort-sync-trigger ()
;; If loading 'f fails, we just don't read/write to/from file
(require 'f nil t)
(require 'time-date)
(when (/= (time-to-day-in-year (current-time)) (time-to-day-in-year (ffort-sync-read-last)))
(ffort-sync)
(ffort-sync-write-last))
)
(defun exit-emacs-sensibly ()
(interactive)
(if server-mode
(delete-frame)
(save-buffers-kill-terminal)))
(defun wc()
(interactive)
(shell-command (shell-quote-argument (concat "wc -w " buffer-file-name))))
;; User keys
(global-set-key (kbd "C-c r") 'reload-config)
(global-set-key (kbd "C-c c r") 'comment-region)
(global-set-key (kbd "C-c c l") 'comment-line)
(global-set-key (kbd "C-c c u") 'uncomment-region)
(global-set-key (kbd "C-c c c") 'open-config)
(global-set-key (kbd "C-c 4 c") 'open-config-other-window)
;;(global-set-key (kbd "C-c l") 'revert-buffer-no-confirm)
(global-set-key (kbd "C-c k") 'kill-current-buffer)
(global-set-key (kbd "C-c y") 'browse-kill-ring)
;;(global-set-key (kbd "C-c s") 'mode-skeleton)
(global-set-key (kbd "C-c p") 'show-current-filename)
(global-set-key (kbd "C-c f f") 'fold-this)
(global-set-key (kbd "C-c f u") 'fold-this-unfold-at-point)
(global-set-key (kbd "C-c g") 'goto-line)
;;(global-set-key (kbd "C-c d") 'kill-whole-line)
(global-set-key (kbd "C-c b <left>") 'buf-move-left)
(global-set-key (kbd "C-c b <right>") 'buf-move-right)
(global-set-key (kbd "C-c i b") 'ispell-buffer)
(global-set-key (kbd "C-c i w") 'ispell-word)
(global-set-key (kbd "C-c i d") 'ispell-change-dictionary)
(global-set-key (kbd "C-c w") 'ispell-word)
(global-set-key (kbd "C-c q") 'exit-emacs-sensibly)
(global-set-key (kbd "C-c j f") 'fill-paragraph)
(global-set-key (kbd "C-c j u") 'unfill-paragraph)
(global-set-key (kbd "C-c d b") 'ediff-buffers)
(global-set-key (kbd "<insert>") nil)
;; Disable commands
;; scroll-left
(global-set-key (kbd "<C-next>") nil)
(global-set-key (kbd "C-x <") nil)
(global-set-key (kbd "C-t") nil)
(global-set-key (kbd "<menu>") nil)
;;compile file of optimization (?)
;;(defun byte-compile-if-newer-and-load (file)
;; "Byte compile file.el if newer than file.elc"
;; (if (file-newer-than-file-p (concat file ".el")
;; (concat file ".elc"))
;; (byte-compile-file (concat file ".el")))
;; (load file))
;;(byte-compile-if-newer-and-load "~/.emacs.d/init")
;; Language settings
;; Language Server Protocol (LSP)
;; (add-hook 'prog-mode-hook #'lsp-mode)
;; (add-hook 'prog-mode-hook #'lsp)
(add-hook 'ocaml-mode-hook #'lsp)
(add-hook 'prog-mode-hook #'yas-minor-mode)
;; Ocaml
(defun set-merlin-keys ()
"Set merlin keys"
(progn
(define-key merlin-mode-map (kbd "C-c &") nil)
(define-key merlin-mode-map (kbd "C-c p") 'merlin-pop-stack)))
(defun setup-merlin ()
(let ((opam-bin (ignore-errors (car (process-lines "opam" "var" "bin")))))
(when (and opam-bin (file-directory-p opam-bin))
(add-to-list 'exec-path opam-bin)
(require 'ocp-indent)
(autoload 'merlin-mode "merlin" nil t nil)
(add-hook 'tuareg-mode-hook 'merlin-mode t)
(add-hook 'caml-mode-hook 'merlin-mode t)
(require 'merlin-company)
(add-hook 'merlin-mode-hook 'company-mode t)
(add-hook 'merlin-mode-hook 'set-merlin-keys t))))
;; C/C++
(add-hook 'c++-mode-hook 'lsp)
(add-hook 'c-mode-hook 'lsp)
;;(add-hook 'c-mode-hook 'hide-ifdef-mode)
;;(add-hook 'hide-ifdef-mode-hook 'hide-ifdefs)
;; Rust
(add-hook 'rust-mode-hook 'lsp)
;; Python
(add-hook 'python-mode-hook
(lambda ()
(untabify (point-min) (point-max))))
;(add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
;(add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
;(add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
;; Prelude
(setq auto-mode-alist (cons '("\\.plu$" . prelude-mode) auto-mode-alist))
(add-to-list 'exec-path "~/site/prelude/bin")
(autoload 'prelude-mode "prelude" "Edition de code prelude" t)
;; LaTeX
(unless (image-type-available-p 'xpm)
(setq LaTeX-enable-toolbar nil))
(defun latex-config-zathura ()
"Configure LaTeX mode to support zathura"
(add-to-list 'TeX-view-program-selection
'(output-pdf "Zathura")))
(defun setup-lsp-ltex ()
;; (use-package lsp-ltex
;; :ensure t
;; :hook (text-mode . (lambda ()
;; (require 'lsp-ltex)
;; (lsp)))) ; or lsp-deferred)
(require 'lsp-ltex)
(lsp)
)
(define-skeleton latex-skeleton
"Inserts a Latex skelleton with average settings"
"Class: "
"\\documentclass{" str | "article" "}\n"
"\n"
"\\usepackage{multicol}\n"
"\\usepackage[OT1]{fontenc}\n"
"\\usepackage[utf8]{inputenc}\n"
"\n"
"\\usepackage{listings}\n"
"\\usepackage[stable]{footmisc}\n"
"\\usepackage{hyperref}\n"
"\\usepackage{amssymb}\n"
"\\usepackage{amsmath}\n"
"\\usepackage{rtsched}\n"
"\\usepackage{multido}\n"
"\\usepackage{multirow}\n"
"\\usepackage{makecell}\n"
"\\usepackage{diagbox}\n"
"\\usepackage{cite}\n"
"\n"
"\\usepackage{minted}\n"
"\\usemintedstyle{pastie}\n"
"\n"
"\\usepackage{tikz}\n"
"\\usetikzlibrary{positioning}\n"
"\\usetikzlibrary{calc}\n"
"\n"
"\\begin{document}\n"
_ "\n"
"\\end{document}\n\n"
"%%% Local"" Variables:\n"
"%%% mode: latex\n"
"%%% TeX-command-extra-options: \"-shell-escape\"\n"
"%%% TeX-master: t\n"
"%%% End:")
(defun latex-skeleton-add-key()
(local-set-key (kbd "C-c s") 'latex-skeleton))
(add-hook 'LaTeX-mode-hook 'latex-skeleton-add-key)
(add-hook 'LaTeX-mode-hook 'latex-config-zathura)
(add-hook 'LaTeX-mode-hook 'reftex-mode)
;; HTML
(defun render-html-inplace ()
(interactive)
(let (
(srcbuf (current-buffer))
(dstbuf (get-buffer-create "*html-render*")))
(message "srcbuf %s dstbuf %s" srcbuf dstbuf)
(with-current-buffer dstbuf
(erase-buffer)
(shr-insert-document
(with-current-buffer srcbuf
(libxml-parse-html-region (point-min) (point-max))))
)
;;(switch-to-buffer dstbuf)
)
)
(add-hook 'html-mode-hook 'render-html-inplace)
;; Haskell (Agda too)
(let ((haskell-bin-path (concat (getenv "HOME") "/.cabal/bin")))
(when (file-directory-p haskell-bin-path)
(add-to-list 'exec-path haskell-bin-path)))
;; (defun setup-compilation-advice ()
;; (require 'noflet)
;; (defadvice compilation-start
;; (around inhibit-display
;; (command &optional mode name-function highlight-regexp))
;; (noflet ((display-buffer (buffer-or-name &optional action frame))
;; (set-window-point (window pos))
;; (goto-char (position)))
;; (fset 'display-buffer 'ignore)
;; (fset 'goto-char 'ignore)
;; (fset 'set-window-point 'ignore)
;; (save-window-excursion
;; ad-do-it)))
;; (ad-activate 'compilation-start))
;; Windows specific
(when (or (eq system-type 'windows-nt) (eq system-type 'cygwin))
;; Default to Unix file endings
(setq-default buffer-file-coding-system 'utf-8-unix)
(setq-default default-buffer-file-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(prefer-coding-system 'utf-8-unix)
;; Font
(when (and (eq system-type 'windows-nt) (window-system))
(w32-find-non-USB-fonts))
(add-to-list 'default-frame-alist
'(font . "Consolas-11"))
)
;; Hooks
(add-hook 'after-init-hook 'ffort-sync-trigger 0)
(add-hook 'after-init-hook 'ffort-theme-configure-theme 10)
(add-hook 'after-init-hook 'setup-merlin 20)
(add-hook 'after-init-hook 'setup-lsp-ltex 20)
;; (add-hook 'after-init-hook 'setup-compilation-advice 20)
;; Custom variables
(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.
'(TeX-command-list
'(("Make" "make" TeX-run-compile nil t)
("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %(output-dir) %t" TeX-run-TeX nil
(plain-tex-mode texinfo-mode ams-tex-mode)
:help "Run plain TeX")
("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil
(latex-mode doctex-mode)
:help "Run LaTeX")
("Makeinfo" "makeinfo %(extraopts) %(o-dir) %t" TeX-run-compile nil
(texinfo-mode)
:help "Run Makeinfo with Info output")
("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir) --html %t" TeX-run-compile nil
(texinfo-mode)
:help "Run Makeinfo with HTML output")
("AmSTeX" "amstex %(PDFout) %`%(extraopts) %S%(mode)%' %(output-dir) %t" TeX-run-TeX nil
(ams-tex-mode)
:help "Run AMSTeX")
("ConTeXt" "%(cntxcom) --once --texutil %(extraopts) %(execopts)%t" TeX-run-TeX nil
(context-mode)
:help "Run ConTeXt once")
("ConTeXt Full" "%(cntxcom) %(extraopts) %(execopts)%t" TeX-run-TeX nil
(context-mode)
:help "Run ConTeXt until completion")
("BibTeX" "%(bibtex) %s" TeX-run-BibTeX nil
(plain-tex-mode latex-mode doctex-mode context-mode texinfo-mode ams-tex-mode)
:help "Run BibTeX")
("Biber" "biber %(output-dir) %s" TeX-run-Biber nil
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Run Biber")
("Texindex" "texindex %s.??" TeX-run-command nil
(texinfo-mode)
:help "Run Texindex")
("Texi2dvi" "%(PDF)texi2dvi %t" TeX-run-command nil
(texinfo-mode)
:help "Run Texi2dvi or Texi2pdf")
("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer")
("Print" "%p" TeX-run-command t t :help "Print the file")
("Queue" "%q" TeX-run-background nil t :help "View the printer queue" :visible TeX-queue-command)
("File" "%(o?)dvips %d -o %f " TeX-run-dvips t
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Generate PostScript file")
("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Convert DVI file to PostScript")
("Dvipdfmx" "dvipdfmx -o %(O?pdf) %d" TeX-run-dvipdfmx nil
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Convert DVI file to PDF with dvipdfmx")
("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Convert PostScript file to PDF")
("Glossaries" "makeglossaries %(d-dir) %s" TeX-run-command nil
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Run makeglossaries to create glossary file")
("Index" "%(makeindex) %s" TeX-run-index nil
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Run makeindex to create index file")
("upMendex" "upmendex %(O?idx)" TeX-run-index t
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Run upmendex to create index file")
("Xindy" "texindy %s" TeX-run-command nil
(plain-tex-mode latex-mode doctex-mode texinfo-mode ams-tex-mode)
:help "Run xindy to create index file")
("Check" "lacheck %s" TeX-run-compile nil
(latex-mode)
:help "Check LaTeX file for correctness")
("ChkTeX" "chktex -v6 %s" TeX-run-compile nil
(latex-mode)
:help "Check LaTeX file for common mistakes")
("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t :help "Spell-check the document")
("Clean" "TeX-clean" TeX-run-function nil t :help "Delete generated intermediate files")
("Clean All" "(TeX-clean t)" TeX-run-function nil t :help "Delete generated intermediate and output files")
("Other" "" TeX-run-command t t :help "Run an arbitrary command")))
'(TeX-master nil)
'(auto-save-default t)
'(before-save-hook '(delete-trailing-whitespace))
'(bibtex-align-at-equal-sign t)
'(bibtex-text-indentation 12)
'(c-basic-offset 2)
'(c-default-style
'((c-mode . "bsd")
(c++-mode . "bsd")
(java-mode . "java")
(awk-mode . "awk")
(other . "bsd")))
'(ccls-executable "/usr/bin/ccls")
'(column-number-mode t)
'(company-minimum-prefix-length 1)
'(coq-compile-before-require t)
'(delete-selection-mode t)
'(ffort-last-sync "last-sync")
'(global-auto-revert-mode t)
'(global-linum-mode t)
'(global-visual-line-mode t)
'(indent-tabs-mode nil)
'(inhibit-startup-screen t)
'(initial-major-mode 'text-mode)
'(initial-scratch-message "")
'(lsp-keymap-prefix "C-c l")
'(lsp-ltex-version "15.2.0-linux-x64")
'(lsp-rust-server 'rust-analyzer)
'(lua-indent-level 2)
'(make-backup-files nil)
'(mouse-autoselect-window t)
'(next-line-add-newlines nil)
'(org-adapt-indentation t)
'(org-export-show-temporary-export-buffer nil)
'(org-format-latex-options
'(:foreground default :background default :scale 1.3 :html-foreground "Black" :html-background "Transparent" :html-scale 1.0 :matchers
("begin" "$1" "$" "$$" "\\(" "\\[")))
'(org-latex-packages-alist '(("" "dsfont" t)))
'(org-log-done :time)
'(org-preview-latex-image-directory "/tmp/ltximg/")
'(org-support-shift-select 'always)
'(package-selected-packages
'(rust-mode gnu-elpa-keyring-update proof-general github-tags lsp-ltex gnuplot-mode cuda-mode merlin-company bison-mode auto-virtualenv undo-tree z3-mode cmake-mode cargo lsp-ui ccls yasnippet buttons graphviz-dot-mode tangotango-theme presentation csv-mode json-mode unfill merlin ocp-indent buffer-move auctex edit-server-htmlize edit-server tuareg projectile fold-this company yaml-mode smart-tab lua-mode browse-kill-ring))
'(python-indent-offset 2)
'(safe-local-variable-values
'((TeX-command-extra-options . "-shell-escape")
(TeX-master . "main")))
'(show-paren-mode t)
'(tab-width 2)
'(tool-bar-mode nil)
'(xterm-mouse-mode t)
'(z3-solver-cmd "/usr/bin/z3"))
(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.
)