~q3cpma/dotfiles

dotfiles/.emacs.d/init.el -rw-r--r-- 6.9 KiB
6c727bdcq3cpma Update a day ago
                                                                                
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
(add-to-list 'load-path "~/.emacs.d/lisp/")

(defmacro add-hooks (hooks &rest body)
  "Add BODY as lambda body to all the specified HOOKS\n
Example: (add-hooks '(c-mode c++-mode) (message \"C/C++\"))"
  (let ((var (gensym)))
	`(dolist (,var ,hooks)
	   (add-hook ,var (lambda () ,@body)))))

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

(defun x-config ()
  (message "Applying X config")
  ;; Misc
  (set-face-attribute 'default nil :family "Terminus" :height 120)
  (load-theme 'deeper-blue)
  (setq-default cursor-type '(bar . 1))
  (setq inhibit-startup-screen t)
  (scroll-bar-mode -1)
  (tool-bar-mode -1)
  (setq frame-resize-pixelwise t)
  ;; prog-mode
  (add-hook 'prog-mode-hook
			(lambda ()
			  (electric-pair-mode)
			  (linum-mode)
			  (show-paren-mode 1)
			  (setq whitespace-line-column 100)
			  (require 'company)
			  (company-mode)
			  (setq
			   company-backends '(company-capf)
			   company-minimum-prefix-length 3
			   company-idle-delay 0
			   company-tooltip-limit 10
			   company-dabbrev-downcase nil)
			  (local-set-key (kbd "C-c C-c")       'comment-or-uncomment-region)
			  (local-set-key (kbd "C-c <right>")   'hs-show-block)
			  (local-set-key (kbd "C-c <left>")    'hs-hide-block)
			  (local-set-key (kbd "C-c <up>")      'hs-hide-level)
			  (local-set-key (kbd "C-c <down>")    'hs-show-all)
			  (hs-minor-mode t)
			  (local-set-key (kbd "C-c C-<right>") 'show-ifdef-block)
			  (local-set-key (kbd "C-c C-<left>")  'hide-ifdef-block)
			  (local-set-key (kbd "C-c C-<up>")    'hide-ifdefs)
			  (local-set-key (kbd "C-c C-<down>")  'show-ifdefs)
			  (hide-ifdef-mode t)
			  (local-set-key (kbd "C-c n")         'flymake-goto-next-error)
			  (local-set-key (kbd "C-c p")         'flymake-goto-prev-error)))
  ;; c-mode/c++-mode
  (add-hooks '(c-mode-hook c++-mode-hook)
			 (require 'eglot)
			 (add-to-list 'eglot-server-programs
						  '((c++-mode c-mode)
							"clangd" "--cross-file-rename" "--header-insertion=never"))
			 (advice-add 'eglot-eldoc-function :around
  						 (lambda (oldfun)
  						   (let ((help (help-at-pt-kbd-string)))
  							 (if help (message "%s" help) (funcall oldfun)))))
			 (custom-set-faces
			  '(eglot-highlight-symbol-face ((t (:inherit highlight)))))
			 (eglot-ensure)
			 (c-set-style "bsd")
			 (setq
			  c-backspace-function 'delete-backward-char
			  c-basic-offset 4)
			 (c-set-offset 'case-label '+)
			 (c-set-offset 'arglist-cont-nonempty '+)
			 (c-set-offset 'statement-cont '+))
  ;; c++-mode
  (add-hook 'c++-mode-hook
			(lambda ()
			  (custom-set-variables '(c-noise-macro-names '("constexpr")))
			  (setq c-macro-preprocessor "cpp -xc++ -C")))
  )

(defun term-config ()
  (disable-theme 'deeper-blue))

(defun apply-config (&optional frame)
  (if (display-graphic-p frame)
	  (x-config)
	  (term-config)))
(add-hook 'after-make-frame-functions 'apply-config)
(apply-config)

;; sh-mode
(setq sh-indent-after-continuation 'always)

;; tcl-mode
(setq tcl-application "tclsh")

;; web-mode
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(add-hook 'web-mode-hook
	  (lambda ()
	    (setq web-mode-markup-indent-offset 2)
	    (setq web-mode-enable-auto-pairing t)
	    (setq web-mode-enable-css-colorization t)
	    (setq web-mode-style-padding 0)
	    (setq web-mode-enable-block-face t)
	    (setq web-mode-enable-current-element-highlight t)))

;; python-mode
(add-hook 'python-mode-hook
		  (lambda ()
			(setq python-indent-offset 4)
			(setq indent-tabs-mode t)
			(setq tab-width 4)))

;; elisp-mode
(put 'if 'lisp-indent-function nil)

;; lisp-mode
(setq browse-url-handlers
	  '(("hyperspec" . eww-browse-url)
		("." . browse-url-default-browser)))
(setq common-lisp-hyperspec-root "file:///usr/share/hyperspec/HyperSpec/")
(setq inferior-lisp-program "/usr/bin/sbcl")
(add-hook 'sly-mode-hook
		  (lambda () (define-key sly-editing-mode-map (kbd "C-c C-c") nil)))

;; diff-mode
(defun custom-diff-colors ()
  (set-face-foreground 'diff-added "green")
  (set-face-background 'diff-added "unspecified")
  (set-face-foreground 'diff-removed "red")
  (set-face-background 'diff-removed "unspecified")
  (set-face-background 'diff-file-header "unspecified"))
(eval-after-load "diff-mode" '(custom-diff-colors))

;; smerge-mode
(setq smerge-command-prefix "\C-cm")

;; latex-mode
(add-hook 'LaTeX-mode-hook 'auto-fill-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(setq-default TeX-master nil)
(setq TeX-auto-save t)
(setq TeX-parse-self t)

;; vapoursynth
(add-to-list 'auto-mode-alist '("\\.vpy\\'" . python-mode))

;; ispell
(setq ispell-dictionary "fr_FR")

;; whitespace-mode
(require 'whitespace)
(setq whitespace-line-column 80)
(setq whitespace-style '(face lines-tail))
(global-whitespace-mode 1)

;; imageboard-mode
(load-library "imageboard-mode")
(add-hook 'imageboard-mode-hook
		  (lambda ()
			(fringe-mode 0)
			(visual-line-mode t)
			(setq left-margin-width 1)
			(set-window-buffer nil (current-buffer))))
(setq imageboard-mode-face 'yotsuba-b)
(setq imageboard-mode-add-face-attrs '(:family "Liberation Sans"))

;; Misc stuff
(menu-bar-mode -1)
(setq-default fill-column 79)
(setq-default indent-tabs-mode t)
(setq-default tab-width 4)
(setq-default truncate-lines t)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/autosave/" t)))
(setq backup-directory-alist '(("" . "~/.emacs.d/backup")))
;; (setq auto-save-default nil)
;; (setq make-backup-files nil)
(savehist-mode t)
(setq savehist-additional-variables '(search-ring regexp-search-ring))
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(setq tramp-default-method "ssh")
(setq native-comp-async-report-warnings-errors nil)

;; Global bindings
(defun sed-on-region (b e script)
  "Run a sed script on a region"
  (interactive "r\nsSed script on region: ")
  (call-process-region b e "sed" t t t "-E" "--" script))
(global-set-key (kbd "C-c e") 'sed-on-region)
(global-set-key (kbd "M-s") 'shell-command-on-region)

;; org-mode
(if (require 'toc-org nil t)
	(add-hook 'org-mode-hook 'toc-org-mode))
(add-hook 'org-mode-hook
          (lambda ()
            (setq org-cycle-include-plain-lists 'integrate)))

(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.
 '(package-selected-packages
   '(go-mode toc-org auto-overlays sly sly-asdf sly-macrostep sly-named-readtables sly-repl-ansi-color markdown-mode web-mode yasnippet eglot company auctex))
 '(warning-suppress-log-types '((auto-save))))
(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.
 )