summaryrefslogtreecommitdiff
path: root/emacs
blob: 772ea050caba8d0a4fd447a9fcd93f100de5da3e (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
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
(set-face-attribute 'default nil :height 150)
(set-frame-font "Iosevka SS13 Extended" nil t)

(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(display-battery-mode t)
(pixel-scroll-precision-mode)
(delete-selection-mode 1)
(fset 'yes-or-no-p 'y-or-n-p)
(setq-default frame-title-format '("%b"))
(setq ring-bell-function 'ignore)
(setq inhibit-startup-screen t)
(setq line-spacing 0.2)

(setq display-time-format "%a, %d/%m/%y %H:%M")
(display-time)
(tab-bar-mode)

;; Put Emacs auto-save and backup files to /tmp
(defconst emacs-tmp-dir (expand-file-name (format "emacs%d" (user-uid)) temporary-file-directory))
(setq
   backup-by-copying t                                        ; Avoid symlinks
   delete-old-versions t
   kept-new-versions 6
   kept-old-versions 2
   version-control t
   auto-save-list-file-prefix emacs-tmp-dir
   auto-save-file-name-transforms `((".*" ,emacs-tmp-dir t))  ; Change autosave dir to tmp
   backup-directory-alist `((".*" . ,emacs-tmp-dir)))

;; Packages
(setq package-list '(
		     magit
		     go-mode
		     devdocs
		     rec-mode
		     almost-mono-themes
		     markdown-mode
		     yasnippet
		     yasnippet-snippets
		     tldr
		     elfeed
		     yasnippet-snippets
		     mastodon
		     expand-region))

(require 'package)

;; list the repositories containing them
(setq package-archives '(("elpa" . "https://elpa.gnu.org")
                         ("gnu" . "http://elpa.gnu.org/packages/")
			 ("melpa" . "https://melpa.org/packages/")
			 ("melpa-stable" . "https://stable.melpa.org/packages/")))

;; activate all thpe packages (in particular autoloads)
(package-initialize)

;; fetch the list of packages available 
(unless package-archive-contents
  (package-refresh-contents))

;; install the missing packages
(dolist (package package-list)
  (unless (package-installed-p package)
    (package-install package)))

;; Expand Region
(require 'expand-region)
(global-set-key (kbd "C-.") 'er/expand-region)
(global-set-key (kbd "C-,") 'er/contract-region)
(global-set-key (kbd "C-h D") 'devdocs-lookup)


;; Markdown
(add-hook 'markdown-mode-hook 'variable-pitch-mode)
(add-hook 'markdown-mode-hook 'visual-line-mode)
(add-hook 'markdown-mode-hook 'markdown-toggle-url-hiding)
(add-hook 'markdown-mode-hook 'markdown-toggle-markup-hiding)
(add-hook 'markdown-mode-hook 'visual-line-mode)
(require 'markdown-mode)
(set-face-attribute 'markdown-code-face nil :inherit 'fixed-pitch)

;; Pairs
(electric-pair-mode 1)
(global-set-key (kbd "M-{") 'insert-pair)
(global-set-key (kbd "M-\"") 'insert-pair)
(global-set-key (kbd "M-\'") 'insert-pair)
(global-set-key (kbd "M-<") 'insert-pair)
(global-set-key (kbd "M-[") 'insert-pair)

;; IDO
(ido-mode t)

;; Eglot
(require 'eglot)
(define-key eglot-mode-map (kbd "C-c r") 'eglot-rename)
(define-key eglot-mode-map (kbd "C-c o") 'eglot-code-actions)
(define-key eglot-mode-map (kbd "C-c h") 'eldoc)

(add-hook 'go-mode-hook 'eglot-ensure)

(set 'eldoc-print-after-edit t)
(global-eldoc-mode t)
(setq eldoc-echo-area-prefer-doc-buffer t) 

(setq make-backup-files nil)

(use-package go-mode
  :ensure t
  :hook ((before-save . eglot-format-buffer)))


;; X integration
(setq x-select-enable-clipboard t)
(setq x-select-enable-primary t)

(add-to-list 'load-path "~/.emacs.d/elisp")
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")

(setq-default grep-template (string-join '("ugrep"
                                           "--color=never"
                                           "--ignore-binary"
                                           "--ignore-case"
                                           "--include=<F>"
                                           "--line-number"
                                           "--null"
                                           "--recursive"
                                           "--regexp=<R>")
                                         " "))

(require 'secrets)
(require 'auth-source-pass (auth-source-pass-enable))


(global-set-key 
 "\C-cef"
 (lambda ()
   (interactive)
   (erc :server
	"irc.libera.chat" :port "6667" :nick "mccd"
	:password (shell-command-to-string "pass show libera.chat"))))

(setq shr-max-image-proportion 0.3
	mastodon-active-user "marcc"
	mastodon-instance-url "https://fosstodon.org")

;; Org

(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)

(require 'org)
(setq org-agenda-files '("~/personal-db/notes"))
(setq org-default-notes-file "~/personal-db/todo.org")
(setq org-log-done 'time)
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(add-hook 'org-mode-hook 'org-indent-mode)
(add-hook 'org-mode-hook 'visual-line-mode)
(add-hook 'org-mode-hook 'variable-pitch-mode)
(set-face-attribute 'org-block nil :inherit 'fixed-pitch)
(set-face-attribute 'org-table nil :inherit 'fixed-pitch)

(setq org-capture-templates
      '(    
        ("t" "Todo"
         entry (file+headline "~/personal-db/todo.org" "Todo")
         "* TODO %?\n%i\n%a\n:Created: %T\n "
         :empty-lines 0)
	("n" "Notes"
	 entry (file+headline "~/personal-db/notes/general.org" "Notes")
	 "** %?"
	 :empty-lines 1)))

;; Magit
(global-set-key (kbd "C-c g") 'magit)

;; Yasnippet
(require 'yasnippet)
(yas-global-mode 1)

;; Mu4e
(defun marc/set-msmtp-account ()
  (if (message-mail-p)
      (save-excursion
        (let*
            ((from (save-restriction
                     (message-narrow-to-headers)
                     (message-fetch-field "from")))
             (account
              (cond
               ((string-match "marcc@fastmail.fr" from) "home")
               ((string-match "marc.coquand@sustainably.app" from) "work")
               ((string-match "marc@mccd.space" from) "home"))))
          (setq message-sendmail-extra-arguments (list '"-a" account))))))

(add-hook 'message-send-mail-hook 'marc/set-msmtp-account)

(use-package mu4e
  :ensure nil
  :load-path "/usr/share/emacs/site-lisp/mu4e/"
  :config

  ;; This is set to 't' to avoid mail syncing issues when using mbsync
  (setq mu4e-change-filenames-when-moving t)
  
  ;; don't keep message compose buffers around after sending:
  (setq message-kill-buffer-on-exit t)

  ;; send function:
  (setq send-mail-function 'sendmail-send-it
	message-send-mail-function 'sendmail-send-it)

  ;; send program:
  ;; this is exeranal. remember we installed it before.
  (setq sendmail-program (executable-find "msmtp"))

  ;; select the right sender email from the context.
  (setq message-sendmail-envelope-from 'header)  
    
  ;; Refresh mail using isync every 10 minutes
  (setq mu4e-update-interval (* 10 60)
        mu4e-get-mail-command "mbsync -a"
	mu4e-view-show-images t
	mu4e-view-show-addresses t
	mu4e-attachment-dir "~/Downloads"
	mu4e-view-prefer-html t
	mu4e-maildir "~/mail")

  (setq mu4e-contexts
        (list
	 ;; Home
	 (make-mu4e-context
          :name "home"
	  :enter-func (lambda () (mu4e-message "Entering personal context"))
	  :leave-func (lambda () (mu4e-message "Leaving personal context"))
          :match-func
          (lambda (msg)
            (when msg
              (string-prefix-p "/home" (mu4e-message-field msg :maildir))))
          :vars '((user-mail-address . "marc@mccd.space")
                  (user-full-name    . "Marc Coquand")
                  (mu4e-drafts-folder  . "/home/Drafts")
                  (mu4e-sent-folder  . "/home/Sent")
                  (mu4e-refile-folder  . "/home/Archive")
                  (mu4e-trash-folder  . "/home/Trash")
		  (mu4e-sent-messages-behavior . sent)

		  (mu4e-maildir-shortcuts .
					  (("/home/INBOX" . ?i)
					   ("/home/Archive/Done" . ?d)
					   ("/home/Archive" . ?a)
					    ("/home/Archive/Todo" . ?t)))))
         ;; Work account
         (make-mu4e-context
          :name "work"
	  :enter-func (lambda () (mu4e-message "Entering work context"))
	  :leave-func (lambda () (mu4e-message "Leaving work context"))
          :match-func
          (lambda (msg)
            (when msg
              (string-prefix-p "/work" (mu4e-message-field msg :maildir))))
          :vars '((user-mail-address . "marc.coquand@sustainably.app")
                  (user-full-name    . "Marc Coquand")
                  (mu4e-drafts-folder  . "/work/[Gmail]/Drafts")
                  (mu4e-sent-folder  . "/work/[Gmail]/Sent Mail")
                  (mu4e-refile-folder  . "/work/[Gmail]/All Mail")
		  (mu4e-sent-messages-behavior . delete)
                  (mu4e-trash-folder  . "/work/[Gmail]/Trash")
		  (mu4e-maildir-shortcuts .
					  (("/work/[Gmail]/All Mail" . ?a)
					   ("/work/INBOX" . ?i))))))))


(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.
 '(eglot-highlight-symbol-face ((t (:weight bold))))
 '(eglot-mode-line ((t (:weight regular))))
 '(erc-timestamp-face ((t (:foreground "blue" :weight bold))))
 '(eww-valid-certificate ((t (:foreground "black" :weight bold))))
 '(fixed-pitch ((t (:family "Iosevka SS13 Extended"))))
 '(font-lock-builtin-face ((t (:weight regular))))
 '(font-lock-comment-face ((t (:foreground "#0000FF" :slant normal))))
 '(font-lock-constant-face ((t (:slant italic :weight regular))))
 '(font-lock-function-name-face ((t (:weight regular))))
 '(font-lock-keyword-face ((t (:weight regular))))
 '(font-lock-string-face ((t (:foreground "black" :slant italic))))
 '(font-lock-type-face ((t (:foreground "black"))))
 '(font-lock-variable-name-face ((t (:foreground "black"))))
 '(fringe ((t (:background "white"))))
 '(header-line ((t (:inherit nil :background "white" :foreground "grey20" :box (:line-width (2 . 2) :color "white") :underline (:color "gray50" :style line :position 0)))))
 '(highlight ((t (:background "white smoke"))))
 '(info-header-xref ((t (:inherit info-xref :underline (:color "RoyalBlue3" :style line :position t)))))
 '(markdown-inline-code-face ((t (:inherit markdown-code-face))))
 '(markdown-pre-face ((t (:inherit markdown-code-face))))
 '(mastodon-display-name-face ((t (:inherit nil :weight bold))))
 '(mode-line ((t (:inherit variable-pitch :background "white" :foreground "black" :box (:line-width (2 . 2) :style flat-button) :overline "gray50"))))
 '(mode-line-inactive ((t (:inherit mode-line :background "grey90" :foreground "grey20" :underline (:color "black" :style line :position 0) :weight light))))
 '(mu4e-header-highlight-face ((t (:inherit hl-line :extend t :weight bold))))
 '(mu4e-highlight-face ((t (:inherit highlight))))
 '(org-level-1 ((t (:inherit outline-1 :extend nil :weight bold))))
 '(tab-bar ((t (:inherit variable-pitch :background "white" :foreground "gray20" :box (:line-width (4 . 4) :color "white" :style flat-button)))))
 '(tldr-code-block ((t (:background "cornsilk" :foreground "black"))))
 '(tldr-command-argument ((t (:background "cornsilk" :foreground "black"))))
 '(tldr-command-itself ((t (:background "khaki" :foreground "black" :weight bold))))
 '(tldr-introduction ((t (:foreground "black" :slant italic))))
 '(tldr-title ((t (:inherit variable-pitch :foreground "black" :weight bold :height 1.2))))
 '(variable-pitch ((t (:family "Iosevka Aile")))))
(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.
 '(custom-safe-themes
   '("cbd85ab34afb47003fa7f814a462c24affb1de81ebf172b78cb4e65186ba59d2" default))
 '(markdown-list-item-bullets '("-"))
 '(mastodon-tl--enable-proportional-fonts t)
 '(mastodon-use-emojify t)
 '(mode-line-compact 'long)
 '(mode-line-format
   '("%e" mode-line-front-space
     (:propertize
      ("" mode-line-mule-info mode-line-client mode-line-modified mode-line-remote)
      display
      (min-width
       (5.0)))
     mode-line-frame-identification mode-line-buffer-identification "   " mode-line-position
     (vc-mode vc-mode)
     "  " mode-line-modes mode-line-end-spaces))
 '(mode-line-percent-position nil)
 '(mode-line-position-line-format '(" "))
 '(mu4e-bookmarks
   '((:name "Last 7 days" :query "date:7d..now" :hide-unread t :key 119)
     (:name "Messages with images" :query "mime:image/*" :key 112)))
 '(org-agenda-files '("~/personal-db/todo.org"))
 '(org-fold-core-style 'overlays)
 '(package-selected-packages
   '(yasnippet-snippets elfeed yasnippet smartparens markdown-mode mastodon tldr almost-mono-themes rec-mode magit go-mode expand-region devdocs))
 '(tab-bar-format
   '(tab-bar-separator tab-bar-format-align-right tab-bar-format-global))
 '(yank-from-kill-ring-rotate t))
(put 'secrets-mode 'disabled nil)