You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1338 lines
37 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #+TITLE: Emacs Configuration
  2. #+AUTHOR: Marc Pohling
  3. * Personal Information
  4. #+begin_src emacs-lisp
  5. (setq user-full-name "Marc Pohling"
  6. user-mail-address "marc.pohling@googlemail.com")
  7. #+end_src
  8. * Stuff to add / to fix
  9. - smartparens
  10. a sane default configuration for navigation, manipulation etc. is still necessary
  11. - Spaceline / Powerline or similar
  12. I want a pretty status bar!
  13. - Markdown mode
  14. There might be more than one package for this.
  15. - Git gutter:
  16. Do some configuration to make it useful (see given source link in the [[*Git][Section]] of gutter)
  17. Maybe only enable it for modes where it is likely I use git?
  18. - Some webmode stuff
  19. * Update config in a running config
  20. Two options:
  21. - reload the open file: M-x load-file, then press twice to accept
  22. the default filename, which is the currently opened
  23. - Point at the end of any sexp and press C-x C-e
  24. * Customize settings
  25. Move the customize settings to its own file, instead of saving
  26. customize settings in [[file:init.el][init.el]].
  27. #+begin_src emacs-lisp
  28. (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  29. (load custom-file)
  30. #+end_src
  31. Keep the .emacs.d clean by moving user files into separate directories.
  32. - user-local: directory for machine specific files
  33. - user-global: directory for files which work on any machine
  34. #+BEGIN_SRC emacs-lisp
  35. (defvar PATH_USER_LOCAL (expand-file-name "~/.emacs.d/user-local/"))
  36. (defvar PATH_USER_GLOBAL (expand-file-name "~/.emacs.d/user-global/"))
  37. (setq bookmark-default-file (concat PATH_USER_LOCAL "bookmarks")) ;"~/.emacs.d/user-dir/bookmarks")
  38. (setq abbrev-file-name (concat PATH_USER_GLOBAL "abbrev_defs"))
  39. (setq save-abbrevs 'silently) ; don't bother me with asking if new abbrevs should be saved
  40. #+END_SRC
  41. * Theme
  42. ** Font
  43. Don't add the font in the work environment, which I am logged in as POH
  44. #+begin_src emacs-lisp
  45. (unless (string-equal user-login-name "POH")
  46. (set-face-attribute 'default nil :font "Hack-12")
  47. )
  48. #+end_src
  49. ** Material Theme
  50. The [[https://github.com/cpaulik/emacs-material-theme][Material Theme]] comes in a dark and a light variant. Not too dark
  51. to be strenious though.
  52. b
  53. #+begin_src emacs-lisp
  54. (use-package material-theme
  55. :if (window-system)
  56. :defer t
  57. :ensure t
  58. ;; :init
  59. ;; (load-theme 'material t)
  60. )
  61. #+end_src
  62. ** Apropospriate Theme
  63. Variants dark and light
  64. #+begin_src emacs-lisp
  65. (use-package apropospriate-theme
  66. :if (window-system)
  67. :defer t
  68. :ensure t
  69. :config
  70. ; (load-theme 'apropospriate-dark t)
  71. )
  72. #+end_src
  73. ** Ample Theme
  74. Variants:
  75. - ample
  76. - ample-flat
  77. - ample-light
  78. #+begin_src emacs-lisp
  79. (use-package ample-theme
  80. :defer t
  81. :ensure t
  82. :init
  83. (load-theme 'ample-flat)
  84. ; (load-theme 'ample-light)
  85. ; (enable-theme 'ample-flat)
  86. )
  87. #+end_src
  88. * Sane defaults
  89. Sources for this section include [[https://github.com/magnars/.emacs.d/blob/master/settings/sane-defaults.el][Magnars Sveen]] and [[http://pages.sachachua.com/.emacs.d/Sacha.html][Sacha Chua]]
  90. These functions are useful. Activate them.
  91. #+begin_src emacs-lisp
  92. (put 'downcase-region 'disabled nil)
  93. (put 'upcase-region 'disabled nil)
  94. (put 'narrow-to-region 'disabled nil)
  95. (put 'dired-find-alternate-file 'disabled nil)
  96. #+end_src
  97. Answering just 'y' or 'n' should be enough.
  98. #+begin_src emacs-lisp
  99. (defalias 'yes-or-no-p 'y-or-n-p)
  100. #+end_src
  101. Keep all backup and auto-save files in one directory
  102. #+begin_src emacs-lisp
  103. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  104. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  105. #+end_src
  106. UTF-8 please
  107. #+begin_src emacs-lisp
  108. (setq locale-coding-system 'utf-8)
  109. (set-terminal-coding-system 'utf-8)
  110. (set-keyboard-coding-system 'utf-8)
  111. (set-selection-coding-system 'utf-8)
  112. (prefer-coding-system 'utf-8)
  113. #+end_src
  114. Avoid tabs in place of multiple spaces (they look bad in TeX)
  115. and show empty lines
  116. #+begin_src emacs-lisp
  117. (setq-default indent-tabs-mode nil)
  118. (setq-default indicate-empty-lines t)
  119. #+end_src
  120. Turn off blinking cursor
  121. #+begin_src emacs-lisp
  122. (blink-cursor-mode -1)
  123. #+end_src
  124. Don't count two spaces after a period as the end of a sentence.
  125. Just one space is needed
  126. #+begin_src emacs-lisp
  127. (setq sentence-end-double-space nil)
  128. #+end_src
  129. Delete the region when typing, just like as we expect nowadays.
  130. #+begin_src emacs-lisp
  131. (delete-selection-mode t)
  132. #+end_src
  133. Auto-indent when pressing RET, just new-line when C-j
  134. #+begin_src emacs-lisp
  135. (define-key global-map (kbd "RET") 'newline-and-indent)
  136. (define-key global-map (kbd "C-j") 'newline)
  137. #+end_src
  138. Various stuff
  139. #+begin_src emacs-lisp
  140. (show-paren-mode t)
  141. (column-number-mode t)
  142. (setq uniquify-buffer-name-style 'forward)
  143. #+end_src
  144. Smooth scrolling. Emacs tends to be jumpy, this should change it.
  145. #+BEGIN_SRC emacs-lisp
  146. (setq scroll-margin 5
  147. scroll-conservatively 9999
  148. scroll-step 1)
  149. #+END_SRC
  150. * Prettier Line Wraps
  151. By default there is no line wrapping. M-q actually modifies the buffer, which might not be wanted.
  152. So: enable visual wrapping and keep indentation if there are any.
  153. #+begin_src emacs-lisp
  154. (global-visual-line-mode)
  155. (diminish 'visual-line-mode)
  156. (use-package adaptive-wrap
  157. :ensure t
  158. :init
  159. (when (fboundp 'adaptive-wrap-prefix-mode)
  160. (defun my-activate-adaptive-wrap-prefix-mode ()
  161. "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  162. (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  163. (add-hook 'visual-line-mode-hook 'my-activate-adaptive-wrap-prefix-mode))
  164. )
  165. #+end_src
  166. * Mode Line
  167. Change the default mode line to something prettier. [[https://github.com/Malabarba/smart-mode-line][Source]]
  168. #+BEGIN_SRC emacs-lisp
  169. (use-package smart-mode-line
  170. :ensure t
  171. :config
  172. (tool-bar-mode -1)
  173. (setq sml/theme 'respectful)
  174. (setq sml/name-width 40)
  175. (setq sml/mode-width 'full)
  176. (set-face-attribute 'mode-line nil
  177. :box nil)
  178. (sml/setup))
  179. #+END_SRC
  180. * List buffers
  181. Ibuffer is the improved version of list-buffers.
  182. Make ibuffer the default buffer lister. [[http://ergoemacs.org/emacs/emacs_buffer_management.html][Source]]
  183. #+begin_src emacs-lisp
  184. (defalias 'list-buffers 'ibuffer)
  185. #+end_src
  186. Also auto refresh dired, but be quiet about it. [[http://whattheemacsd.com/sane-defaults.el-01.html][Source]]
  187. #+begin_src emacs-lisp
  188. (add-hook 'dired-mode-hook 'auto-revert-mode)
  189. (setq global-auto-revert-non-file-buffers t)
  190. (setq auto-revert-verbose nil)
  191. #+end_src
  192. * Org Mode
  193. ** Installation
  194. Although org mode ships with Emacs, the latest version can be installed externally. The configuration here follows the [[http://orgmode.org/elpa.html][Org mode ELPA Installation instructions.]]
  195. Added a hook to complete org functions, company-capf is necessary for this
  196. #+begin_src emacs-lisp
  197. (use-package org
  198. :ensure org-plus-contrib
  199. :init
  200. (add-hook 'org-mode-hook 'company/org-mode-hook)
  201. )
  202. #+end_src
  203. To avoid problems executing source blocks out of the box. [[https://emacs.stackexchange.com/a/28604][Others have the same problem, too]]. The solution is to remove the .elc files form the package directory:
  204. #+begin_src sh:
  205. var ORG_DIR=(let* ((org-v (cadr (split-string (org-version nil t) "@"))) (len (length org-v))) (substring org-v 1 (- len 2)))
  206. rm ${ORG_DIR}/*.elc
  207. #+end_src
  208. *** Org key bindings
  209. Set up some global key bindings that integrate with Org mode features
  210. #+begin_src emacs-lisp
  211. (bind-key "C-c l" 'org-store-link)
  212. (bind-key "C-c c" 'org-capture)
  213. (bind-key "C-c a" 'org-agenda)
  214. #+end_src
  215. Org overwrites RET and C-j, so I need to disable the rebinds
  216. #+begin_src emacs-lisp
  217. (define-key org-mode-map (kbd "RET") nil) ;;org-return
  218. (define-key org-mode-map (kbd "C-j") nil) ;;org-return-indent
  219. #+end_src
  220. *** Org agenda
  221. For a more detailed example [[https://github.com/sachac/.emacs.d/blob/83d21e473368adb1f63e582a6595450fcd0e787c/Sacha.org#org-agenda][see here]].
  222. #+begin_src emacs-lisp
  223. (setq org-agenda-files
  224. (delq nil
  225. (mapcar (lambda (x) (and (file-exists-p x) x))
  226. '("~/Archiv/Dokumente/Agenda"))
  227. )
  228. )
  229. #+end_src
  230. *** Org capture
  231. #+begin_src emacs-lisp
  232. (bind-key "C-c c" 'org-capture)
  233. (setq org-default-notes-file "~/Archiv/Dokumente/Notizen/notes.org")
  234. #+end_src
  235. ** Org Setup
  236. Speed commands are a nice and quick way to perform certain actions while at the beginning of a heading. It's not activated by default.
  237. See the doc for speed keys by checking out the documentation for speed keys in Org mode.
  238. #+begin_src emacs-lisp
  239. (setq org-use-speed-commands t)
  240. (setq org-image-actual-width 550)
  241. (setq org-highlight-latex-and-related '(latex script entities))
  242. #+end_src
  243. Hide emphasis markup (e.g. / ... / for italics, etc.)
  244. #+begin_src emacs-lisp
  245. (setq org-hide-emphasis-markers t)
  246. #+end_src
  247. Setting some environment paths
  248. #+begin_src emacs-lisp
  249. (if (string-equal user-login-name "POH")
  250. (progn
  251. (defvar PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  252. (defvar PATH_ORG_JOURNAL "p:/Eigene Dateien/Notizen/Journal/")
  253. (defvar PATH_START "p:/Eigene Dateien/Notizen/"))
  254. )
  255. #+end_src
  256. Sort org agenda by deadline and priority
  257. #+begin_src emacs-lisp
  258. (setq org-agenda-sorting-strategy
  259. (quote
  260. ((agenda deadline-up priority-down)
  261. (todo priority-down category-keep)
  262. (tags priority-down category-keep)
  263. (search category-keep)))
  264. )
  265. #+end_src
  266. Custom todo-keywords, depending on environment
  267. #+begin_src emacs-lisp
  268. (if (string-equal user-login-name "POH")
  269. (setq org-todo-keywords
  270. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE")))
  271. )
  272. #+end_src
  273. Set locations of some org files
  274. #+begin_src emacs-lisp
  275. (if (string-equal user-login-name "POH")
  276. (progn
  277. (setq org-default-notes-file (concat PATH_ORG_FILES "notes.org"))
  278. (setq org-agenda-files (list(concat PATH_ORG_FILES "notes.org")
  279. (concat PATH_ORG_FILES "projects.org")
  280. (concat PATH_ORG_FILES "todo.org"))))
  281. )
  282. (setq org-id-locations-file (concat PATH_USER_LOCAL ".org-id-locations"))
  283. #+end_src
  284. Work specific org-capture-templates
  285. #+begin_src emacs-lisp
  286. (if (string-equal user-login-name "POH")
  287. (setq org-capture-templates
  288. '(("t" "todo" entry (file (concat PATH_ORG_FILES "todo.org"))
  289. "** TODO %\\n%u\n%a\n")
  290. ("n" "note" entry (file org-default-notes-file))
  291. ("p" "project" entry (file (concat PATH_ORG_FILES "projects.org"))
  292. "** OPEN %?\n%u\n** Beschreibung\n** Zu erledigen\n*** \n** Verlauf\n***" :clock-in t :clock-resume t)
  293. ("u" "Unterbrechung" entry (file org-default-notes-file)
  294. "* Unterbrechnung durch %? :Unterbrechung:\n%t" :clock-in t :clock-resume t)))
  295. )
  296. #+end_src
  297. Customize the org agenda
  298. #+begin_src emacs-lisp
  299. (defun my-org-skip-subtree-if-priority (priority)
  300. "Skip an agenda subtree if it has a priority of PRIORITY.
  301. PRIORITY may be one of the characters ?A, ?B, or ?C."
  302. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  303. (pri-value (* 1000 (- org-lowest-priority priority)))
  304. (pri-current (org-get-priority (thing-at-point 'line t))))
  305. (if (= pri-value pri-current)
  306. subtree-end
  307. nil)))
  308. (setq org-agenda-custom-commands
  309. '(("c" "Simple agenda view"
  310. ((tags "PRIORITY=\"A\""
  311. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  312. (org-agenda-overriding-header "Hohe Priorität:")))
  313. (agenda ""
  314. ((org-agenda-span 7)
  315. (org-agenda-start-on-weekday nil)
  316. (org-agenda-overriding-header "Nächsten 7 Tage:")))
  317. (alltodo ""
  318. ((org-agenda-skip-function '(or (my-org-skip-subtree-if-priority ?A)
  319. (org-agenda-skip-if nil '(scheduled deadline))))
  320. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))
  321. )
  322. #+end_src
  323. ** Org tags
  324. The default value is -77, which is weird for smaller width windows. I'd rather have the tags align horizontally with the header.
  325. 45 is a good column number to do that.
  326. #+begin_src emacs-lisp
  327. (setq org-tags-column 45)
  328. #+end_src
  329. ** Org babel languages
  330. This code block is linux specific. Loading languages which aren't available seems to be a problem
  331. #+begin_src emacs-lisp
  332. (cond ((eq system-type 'gnu/linux)
  333. (org-babel-do-load-languages
  334. 'org-babel-load-languages
  335. '(
  336. (C . t)
  337. (calc . t)
  338. (java . t)
  339. (js . t)
  340. (latex . t)
  341. (ledger . t)
  342. (beancount . t)
  343. (lisp . t)
  344. (python . t)
  345. (R . t)
  346. (ruby . t)
  347. (scheme . t)
  348. (shell . t)
  349. (sqlite . t)
  350. )
  351. ))
  352. )
  353. #+end_src
  354. #+begin_src emacs-lisp
  355. (defun my-org-confirm-babel-evaluate (lang body)
  356. "Do not confirm evaluation for these languages."
  357. (not (or (string= lang "beancount")
  358. (string= lang "C")
  359. (string= lang "emacs-lisp")
  360. (string= lang "java")
  361. (string= lang "ledger")
  362. (string= lang "python")
  363. (string= lang "R")
  364. (string= lang "sqlite"))))
  365. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  366. #+end_src
  367. I want plots!
  368. #+begin_src emacs-lisp
  369. (use-package ess
  370. :ensure t
  371. )
  372. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
  373. (add-hook 'org-mode-hook 'org-display-inline-images)
  374. #+end_src
  375. ** Org babel/source blocks
  376. I like to have source blocks properly syntax highlighted and with the editing popup window staying within the same window so all the windows don't jump around. Also, having the top and bottom trailing lines in the block is a waste of space, so we can remove them
  377. I noticed that fontification doesn't work with markdown mode when the block is indented after editing it in the org src buffer - the leading #s for headers don't get fontified properly because they apppear as Org comments. Setting ~org-src-preserve-identation~ makes things consistent as it doesn't pad source blocks with leading spaces
  378. #+begin_src emacs-lisp
  379. (setq org-src-fontify-natively t
  380. org-src-window-setup 'current-window
  381. org-src-strip-leading-and-trailing-blank-lines t
  382. org-src-preserve-indentation t
  383. org-src-tab-acts-natively t)
  384. #+end_src
  385. * which-key
  386. Greatly increases discovery of functions!
  387. Click [[https://github.com/justbur/emacs-which-key][here]] for source and more info.
  388. Info in Emacs: M-x customize-group which-key
  389. #+begin_src emacs-lisp
  390. (use-package which-key
  391. :ensure t
  392. :diminish which-key-mode
  393. :config
  394. (which-key-mode)
  395. (which-key-setup-side-window-right-bottom)
  396. (which-key-setup-minibuffer)
  397. (setq which-key-idle-delay 0.5)
  398. )
  399. #+end_src
  400. * Hydra
  401. Hydra allows grouping of commands
  402. #+begin_src emacs-lisp
  403. (use-package hydra
  404. :ensure t
  405. :bind
  406. ("C-c f" . hydra-flycheck/body)
  407. :config
  408. (setq-default hydra-default-hint nil)
  409. )
  410. #+end_src
  411. * Undo
  412. #+BEGIN_SRC emacs-lisp
  413. (use-package undo-tree
  414. :ensure t
  415. :diminish undo-tree-mode
  416. :init
  417. (undo-tree-mode))
  418. #+END_SRC
  419. * Ido (currently inactive)
  420. better completion
  421. begin_src emacs-lisp
  422. (use-package ido
  423. :init
  424. (setq ido-enable-flex-matching t)
  425. (setq ido-everywhere t)
  426. (ido-mode t)
  427. (use-package ido-vertical-mode
  428. :ensure t
  429. :defer t
  430. :init
  431. (ido-vertical-mode 1)
  432. (setq ido-vertical-define-keys 'C-n-and-C-p-only)
  433. )
  434. )
  435. end_src
  436. * Recentf
  437. #+begin_src emacs-lisp
  438. (use-package recentf
  439. :init
  440. (setq recentf-save-file (concat PATH_USER_LOCAL "recentf"))
  441. :config
  442. (recentf-mode t)
  443. (setq recentf-max-saved-items 200)
  444. )
  445. #+end_src
  446. * ivy / counsel / swiper
  447. Flx is required for fuzzy-matching
  448. Is it really necessary?
  449. begin_src emacs-lisp
  450. (use-package flx)
  451. end_src
  452. Ivy displays a window with suggestions for hotkeys and M-x
  453. #+begin_src emacs-lisp
  454. (use-package ivy
  455. :ensure t
  456. :diminish
  457. (ivy-mode . "") ;; does not display ivy in the mode line
  458. :init
  459. (ivy-mode 1)
  460. :bind
  461. ("C-c C-r" . ivy-resume)
  462. :config
  463. (setq ivy-use-virtual-buffers t) ;; recent files and bookmarks in ivy-switch-buffer
  464. (setq ivy-height 20) ;; height of ivy window
  465. (setq ivy-count-format "%d/%d") ;; current and total number
  466. (setq ivy-re-builders-alist ;; regex replaces spaces with *
  467. '((t . ivy--regex-plus)))
  468. )
  469. #+end_src
  470. The find-file replacement is nicer to navigate
  471. #+begin_src emacs-lisp
  472. (use-package counsel
  473. :ensure t
  474. :bind* ;; load counsel when pressed
  475. (("M-x" . counsel-M-x)
  476. ("C-x C-f" . counsel-find-file)
  477. ("C-x C-r" . counsel-recentf)
  478. ("C-c C-f" . counsel-git)
  479. ("C-c h f" . counsel-describe-function)
  480. ("C-c h v" . counsel-describe-variable)
  481. ("M-i" . counsel-imenu)
  482. )
  483. )
  484. #+end_src
  485. Swiper ivy-enhances isearch
  486. #+begin_src emacs-lisp
  487. (use-package swiper
  488. :ensure t
  489. :bind
  490. (("C-s" . swiper)
  491. ("C-c C-r" . ivy-resume)
  492. )
  493. )
  494. #+end_src
  495. Ivy-Hydra adds stuff in minibuffer when you press C-o
  496. #+BEGIN_SRC emacs-lisp
  497. (use-package ivy-hydra
  498. :ensure t)
  499. #+END_SRC
  500. * Latex
  501. Requirements for Linux:
  502. - Latex
  503. - pdf-tools
  504. #+begin_src emacs-lisp
  505. (unless (string-equal user-login-name "POH")
  506. (use-package pdf-tools
  507. :ensure t
  508. :config
  509. (pdf-tools-install)
  510. (setq TeX-view-program-selection '((output-pdf "pdf-tools")))
  511. (setq TeX-view-program-list '(("pdf-tools" "Tex-pdf-tools-sync-view")))
  512. )
  513. )
  514. #+end_src
  515. For latex-preview-pane a patch might be necessary (as of 2017-10), see the issue [[https://github.com/jsinglet/latex-preview-pane/issues/37][here]]
  516. Update 2018-03: It seems to work without this patch. I will keep it here in case something breaks again.
  517. #+begin_src
  518. latex-preview-pane-update-p()
  519. --- (doc-view-revert-buffer nil t)
  520. +++ (revert-buffer-nil t 'preserve-modes)
  521. #+end_src
  522. After that M-x byte-compile-file
  523. #+begin_src emacs-lisp
  524. (use-package latex-preview-pane
  525. :ensure t
  526. )
  527. (setq auto-mode-alist
  528. (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
  529. ;; one of these works
  530. (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
  531. (add-hook 'latex-mode-hook 'latex-preview-pane-mode)
  532. ;; necessary, because linum-mode isn't compatible and prints errors
  533. (add-hook 'pdf-view-mode-hook (lambda () (linum-mode -1)))
  534. #+end_src
  535. * Emails
  536. Currently following tools are required:
  537. - notmuch (edit, read, tag, delete emails)
  538. - isync /mbsync (fetch or sync emails)
  539. After setting up mbsync, notmuch must be configured. Execute "notmuch" from the command line to launch the setup wizard. After it, "notmuch new" to create a new database, which will index the available local e-mails.
  540. TODO:
  541. - setup of mbsync on linux
  542. - setup of notmuch on linux
  543. - shell script for installation of isync and notmuch
  544. - more config for notmuch?
  545. - hydra for notmuch?
  546. - maybe org-notmuch?
  547. - some way to refresh the notmuch db before I run notmuch?
  548. #+begin_src emacs-lisp
  549. (unless (string-equal user-login-name "POH")
  550. (use-package notmuch
  551. :ensure t
  552. )
  553. )
  554. #+end_src
  555. * Personal Finances
  556. I picked ledger for my personal accounting and will test if it's beneficial over gnucash.
  557. ..and don't activate the modules at work.
  558. #+begin_src emacs-lisp
  559. (unless (string-equal user-login-name "POH")
  560. (use-package ledger-mode
  561. :ensure t
  562. :mode ("\\.ledger$" . ledger-mode)
  563. :init
  564. (setq clear-whole-transactions t)
  565. )
  566. )
  567. #+end_src
  568. Ok, maybe beancount is better.
  569. Since there is no debian package, it is an option to install it via pip.
  570. I picked /opt for the installation path
  571. #+begin_src shell
  572. sudo su
  573. cd /opt
  574. python3 -m venv beancount
  575. source ./beancount/bin/activate
  576. pip3 install wheel
  577. pip3 install beancount
  578. deactivate
  579. #+end_src
  580. When using beancount, it will automatically pick the created virtual environment.
  581. Activate the beancount mode
  582. #+begin_src emacs-lisp
  583. (unless (string-equal user-login-name "POH")
  584. ;; (add-to-list 'package-archives
  585. ;; '("beancount" . "/opt/beancount/elisp") t)
  586. ; (use-package beancount
  587. ; :load-path "/opt/beancount/elisp/"
  588. ;; :ensure t
  589. ; :mode ("\\.beancount$" . beancount-mode)
  590. (load "/home/marc/.emacs.d/elisp/beancount-mode.el") ; somehow load-path in use-package doesn't work
  591. (use-package beancount
  592. :load-path "/home/marc/.emacs.d/elisp"
  593. :mode ("\\.beancount$" . beancount-mode)
  594. :init
  595. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  596. (setenv "PATH"
  597. (concat
  598. "/opt/beancount/bin:"
  599. (getenv "PATH"))
  600. )
  601. )
  602. )
  603. #+end_src
  604. For a nice frontend fava seems nice
  605. #+begin_src shell
  606. sudo su
  607. cd /opt
  608. python3 -m venv vava
  609. source ./vava/bin/activate
  610. pip3 install wheel
  611. pip3 install fava
  612. deactivate
  613. #+end_src
  614. Start fava with
  615. #+begin_src shell
  616. fava my_file.beancount
  617. #+end_src
  618. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  619. * Programming
  620. ** Common things
  621. List of plugins and settings which are shared between the language plugins
  622. Highlight whitespaces, tabs, empty lines.
  623. #+begin_src emacs-lisp
  624. (use-package whitespace
  625. :demand t
  626. :ensure nil
  627. :diminish whitespace-mode;;mode shall be active, but not shown in mode line
  628. :init
  629. (dolist (hook '(prog-mode-hook
  630. text-mode-hook
  631. conf-mode-hook))
  632. (add-hook hook #'whitespace-mode))
  633. ;; :hook ;;not working in use-package 2.3
  634. ;; ((prog-mode . whitespace-turn-on)
  635. ;; (text-mode . whitespace-turn-on))
  636. :config
  637. (setq-default whitespace-style '(face empty tab trailing))
  638. )
  639. #+end_src
  640. Disable Eldoc, it interferes with flycheck
  641. #+begin_src emacs-lisp
  642. (use-package eldoc
  643. :ensure nil
  644. :config
  645. (global-eldoc-mode -1)
  646. )
  647. #+end_src
  648. Colorize colors as text with their value
  649. #+begin_src emacs-lisp
  650. (use-package rainbow-mode
  651. :ensure t
  652. :init
  653. (add-hook 'prog-mode-hook 'rainbow-mode t)
  654. :diminish rainbow-mode
  655. ;; :hook prog-mode ;; not working in use-package 2.3
  656. :config
  657. (setq-default rainbow-x-colors-major-mode-list '())
  658. )
  659. #+end_src
  660. Highlight parens etc. for improved readability
  661. #+begin_src emacs-lisp
  662. (use-package rainbow-delimiters
  663. :ensure t
  664. :config
  665. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  666. )
  667. #+end_src
  668. ** Smartparens
  669. Smartparens is a beast on its own, so it's worth having a dedicated section for it
  670. #+begin_src emacs-lisp
  671. (use-package smartparens
  672. :ensure t
  673. :diminish smartparens-mode
  674. :config
  675. (add-hook 'prog-mode-hook 'smartparens-mode)
  676. )
  677. #+end_src
  678. ** Git
  679. [[https://magit.vc/manual/magit/index.html][Link]]
  680. I want to do git stuff here, not in a separate terminal window
  681. Little crashcourse in magit:
  682. - magit-init to init a git project
  683. - magit-status (C-x g) to call the status window
  684. in status buffer:
  685. - s stage files
  686. - u unstage files
  687. - U unstage all files
  688. - a apply changed to staging
  689. - c c commit (type commit message, then C-c C-c to commit)
  690. - b b switch to another branch
  691. - P u git push
  692. - F u git pull
  693. #+begin_src emacs-lisp
  694. (use-package magit
  695. :ensure t
  696. :init
  697. ;; set git-path in work environment
  698. (if (string-equal user-login-name "POH")
  699. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  700. )
  701. :defer t
  702. :bind (("C-x g" . magit-status))
  703. )
  704. #+end_src
  705. Display line changes in gutter based on git history. Enable it everywhere
  706. [[https://github.com/syohex/emacs-git-gutter][Source]]
  707. #+begin_src emacs-lisp
  708. (use-package git-gutter
  709. :ensure t
  710. :config
  711. (global-git-gutter-mode t)
  712. :diminish git-gutter-mode
  713. )
  714. #+end_src
  715. Time machine lets me step through the history of a file as recorded in git.
  716. [[https://github.com/pidu/git-timemachine][Source]]
  717. #+begin_src emacs-lisp
  718. (use-package git-timemachine
  719. :ensure t
  720. )
  721. #+end_src
  722. ** Company Mode
  723. Complete Anything!
  724. Activate company and make it react nearly instantly
  725. #+begin_src emacs-lisp
  726. (use-package company
  727. :ensure t
  728. :config
  729. (setq-default company-minimum-prefix-length 1
  730. company-tooltip-align-annotation t
  731. company-tooltop-flip-when-above t
  732. company-show-numbers t
  733. company-idle-delay 0.1)
  734. ;; (define-key company-active-map (kbd "TAB") #'company-complete-selection)
  735. ;; (define-key company-active-map (kbd "RET") nil)
  736. (company-tng-configure-default)
  737. )
  738. #+end_src
  739. For a nicer suggestion box: company-box ([[https://github.com/sebastiencs/company-box][Source]])
  740. It is only available for emacs 26 and higher.
  741. #+begin_src emacs-lisp
  742. (when (> emacs-major-version 25)
  743. (use-package company-box
  744. :ensure t
  745. :init
  746. (add-hook 'company-mode-hook 'company-box-mode)))
  747. #+end_src
  748. *** Company backend hooks
  749. Backend configuration for python-mode
  750. Common backends are:
  751. - company-files: files & directory
  752. - company-keywords: keywords
  753. - company-capf: ??
  754. - company-abbrev: ??
  755. - company-dabbrev: dynamic abbreviations
  756. - company-ispell: ??
  757. #+begin_src emacs-lisp
  758. (defun company/python-mode-hook()
  759. (set (make-local-variable 'company-backends)
  760. '((company-jedi company-dabbrev company-yasnippet) company-capf company-files))
  761. ;; '((company-jedi company-dabbrev) company-capf company-files))
  762. (company-mode t)
  763. )
  764. #+end_src
  765. (defun add-pcomplete-to-capf ()
  766. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  767. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  768. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  769. Backend for Orgmode
  770. #+begin_src emacs-lisp
  771. (defun company/org-mode-hook()
  772. (set (make-local-variable 'company-backends)
  773. '(company-capf company-files))
  774. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  775. (company-mode t)
  776. )
  777. #+end_src
  778. Backend configuration for lisp-mode
  779. #+begin_src emacs-lisp
  780. (defun company/elisp-mode-hook()
  781. (set (make-local-variable 'company-backends)
  782. '((company-elisp company-dabbrev) company-capf company-files))
  783. (company-mode t)
  784. )
  785. #+end_src
  786. Backend configuration for beancount
  787. #+begin_src emacs-lisp
  788. (defun company/beancount-mode-hook()
  789. (set (make-local-variable 'company-backends)
  790. '(company-beancount))
  791. ; '((company-beancount company-dabbrev) company-capf company-files))
  792. (company-mode t)
  793. )
  794. #+end_src
  795. *** Misc Company packages
  796. Addon to sort suggestions by usage
  797. #+begin_src emacs-lisp
  798. (use-package company-statistics
  799. :ensure t
  800. :after company
  801. :init
  802. (setq company-statistics-file (concat PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  803. :config
  804. (company-statistics-mode 1)
  805. )
  806. #+end_src
  807. Get a popup with documentation of the completion candidate.
  808. For the popups the package pos-tip.el is used and automatically installed.
  809. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  810. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  811. #+begin_src emacs-lisp
  812. (use-package company-quickhelp
  813. :ensure t
  814. :after company
  815. :config
  816. (company-quickhelp-mode 1)
  817. )
  818. #+end_src
  819. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  820. ** Projectile
  821. Brings search functions on project level
  822. #+begin_src emacs-lisp
  823. (use-package projectile
  824. :ensure t
  825. :defer t
  826. :bind
  827. (("C-c p p" . projectile-switch-project)
  828. ("C-c p s s" . projectile-ag))
  829. :init
  830. (setq-default
  831. projectile-cache-file (concat PATH_USER_LOCAL ".projectile-cache")
  832. projectile-known-projects-file (concat PATH_USER_LOCAL ".projectile-bookmarks"))
  833. :config
  834. (projectile-mode t)
  835. (setq-default
  836. projectile-completion-system 'ivy
  837. projectile-enable-caching t
  838. projectile-mode-line '(:eval (projectile-project-name)))
  839. )
  840. #+end_src
  841. ** Yasnippet
  842. Snippets!
  843. TODO: yas-minor-mode? what's that?
  844. #+begin_src emacs-lisp
  845. (use-package yasnippet
  846. :ensure t
  847. :diminish yas-minor-mode
  848. :init
  849. (setq yas-snippet-dirs (concat PATH_USER_GLOBAL "snippets"))
  850. (yas-global-mode t)
  851. :mode ("\\.yasnippet" . snippet-mode)
  852. ; :config
  853. ; (yas-reload-all) ;; ensure snippets are updated and available, necessary when not using global-mode
  854. )
  855. #+end_src
  856. ** Lisp
  857. #+begin_src emacs-lisp
  858. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  859. #+end_src
  860. Add some helpers to handle and understand macros
  861. #+begin_src emacs-lisp
  862. (use-package macrostep
  863. :ensure t
  864. :init
  865. (define-key emacs-lisp-mode-map (kbd "C-c e") 'macrostep-expand)
  866. (define-key emacs-lisp-mode-map (kbd "C-c c") 'macrostep-collapse))
  867. #+end_src
  868. ** Python
  869. Systemwide following packages need to be installed:
  870. - venv
  871. The virtual environments need to have following modules installed:
  872. - jedi
  873. - epc
  874. - pylint
  875. #+begin_src emacs-lisp
  876. (use-package flycheck
  877. :ensure t
  878. :diminish flycheck-mode " ✓"
  879. :init
  880. (setq flycheck-emacs-lisp-load-path 'inherit)
  881. (add-hook 'after-init-hook #'global-flycheck-mode)
  882. (add-hook 'python-mode-hook (lambda ()
  883. (semantic-mode 1)
  884. (flycheck-select-checker 'python-pylint)))
  885. )
  886. #+end_src
  887. Automatically start python-mode when opening a .py-file.
  888. Not sure if python.el is better than python-mode.el.
  889. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  890. The custom function is to run inferiour processes (do I really need that?), see [[https://emacs.stackexchange.com/questions/16361/how-to-automatically-run-inferior-process-when-loading-major-mode][here]].
  891. Also limit the completion backends to those which make sense in Python.
  892. #+begin_src emacs-lisp
  893. (use-package python
  894. :mode ("\\.py\\'" . python-mode)
  895. :interpreter ("python" . python-mode)
  896. :init
  897. (add-hook 'python-mode-hook 'company/python-mode-hook)
  898. :config
  899. (setq python-shell-completion-native-enable nil)
  900. )
  901. #+end_src
  902. Jedi is a backend for python autocompletion and needs to be installed on the server:
  903. - pip install jedi
  904. Code checks need to be installed, too:
  905. - pip install flake8
  906. #+begin_src emacs-lisp
  907. (use-package company-jedi
  908. :defer t
  909. ;; :after company
  910. :ensure t
  911. :config
  912. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  913. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  914. (add-hook 'python-mode-hook 'jedi:setup)
  915. (setq jedi:complete-on-dot t)
  916. (setq jedi:use-shortcuts t)
  917. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  918. )
  919. #+end_src
  920. A wrapper to handle virtual environments.
  921. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  922. TODO: automatically start an inferior python process or switch to it if already created
  923. #+begin_src emacs-lisp
  924. (use-package pyvenv
  925. :ensure t
  926. :init
  927. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  928. :config
  929. (pyvenv-mode t)
  930. (defun my/post-activate-hook()
  931. (setq jedi:environment-root pyvenv-virtual-env)
  932. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  933. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  934. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  935. ;; default traceback, other option M-x jedi:toggle-log-traceback
  936. ;; traceback is in jedi:pop-to-epc-buffer
  937. (jedi:setup)
  938. (company/python-mode-hook)
  939. (setq jedi:server-args '("--log-traceback")))
  940. ;; (add-to-list 'company-backends 'company-jedi)
  941. ;; (add-to-list 'company-backends 'company-anaconda)
  942. ;; (lambda ()
  943. ;; (set (make-local-variable 'company-backends)
  944. ;; '((company-jedi company-dabbrev) company-capf company-files)))
  945. ;; (setq flycheck-checker 'python-pylint))
  946. ;; (flycheck-select-checker 'python-pylint))
  947. ;; (setq flycheck-checker 'python-flake8)
  948. (add-hook 'pyvenv-post-activate-hooks 'my/post-activate-hook)
  949. )
  950. #+end_src
  951. I want Emacs to automatically start the proper virtual environment.
  952. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  953. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  954. Depends on pyvenv
  955. #+begin_src emacs-lisp
  956. (use-package auto-virtualenv
  957. :ensure t
  958. ;; :after pyvenv
  959. ;; :defer t
  960. :init
  961. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  962. ;; activate on changing buffers
  963. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  964. ;; activate on focus in
  965. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  966. )
  967. #+end_src
  968. Anaconda test
  969. begin_src emacs-lisp
  970. (use-package anaconda-mode
  971. :ensure t
  972. :defer t
  973. :init
  974. (add-hook 'python-mode-hook 'anaconda-mode)
  975. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  976. :config
  977. (setq anaconda-eldoc-mode 1)
  978. )
  979. end_src
  980. begin_src emacs-lisp
  981. (use-package company-anaconda
  982. :ensure t
  983. :defer t
  984. :init
  985. (defun my/company-anaconda-hook()
  986. (add-to-list 'company-backends 'company-anaconda))
  987. (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  988. )
  989. end_src
  990. ** Hydra Flycheck
  991. Flycheck is necessary, obviously
  992. #+begin_src emacs-lisp
  993. (defhydra hydra-flycheck (:color blue)
  994. "
  995. ^
  996. ^Flycheck^ ^Errors^ ^Checker^
  997. ^────────^──────────^──────^────────────^───────^───────────
  998. _q_ quit _<_ previous _?_ describe
  999. _m_ manual _>_ next _d_ disable
  1000. _v_ verify setup _f_ check _s_ select
  1001. ^^ ^^ ^^
  1002. "
  1003. ("q" nil)
  1004. ("<" flycheck-previous-error :color red)
  1005. (">" flycheck-next-error :color red)
  1006. ("?" flycheck-describe-checker)
  1007. ("d" flycheck-disable-checker)
  1008. ("f" flycheck-buffer)
  1009. ("m" flycheck-manual)
  1010. ("s" flycheck-select-checker)
  1011. ("v" flycheck-verify-setup)
  1012. )
  1013. #+end_src
  1014. * Treemacs
  1015. A file manager comparable to neotree.
  1016. [[https://github.com/Alexander-Miller/treemacs][Github]]
  1017. It has some requirements, which gets used here anyway:
  1018. - ace-window
  1019. - hydra
  1020. - projectile
  1021. - python
  1022. I copied the configuration example from the github site.
  1023. No idea what this executable-find is about.
  1024. TODO check it out!
  1025. #+begin_src emacs-lisp
  1026. (use-package treemacs
  1027. :ensure t
  1028. :defer t
  1029. :config
  1030. (setq treemacs-change-root-without-asking nil
  1031. treemacs-collapse-dirs (if (executable-find "python") 3 0)
  1032. treemacs-file-event-delay 5000
  1033. treemacs-follow-after-init t
  1034. treemacs-follow-recenter-distance 0.1
  1035. treemacs-goto-tag-strategy 'refetch-index
  1036. treemacs-indentation 2
  1037. treemacs-indentation-string " "
  1038. treemacs-is-never-other-window nil
  1039. treemacs-never-persist nil
  1040. treemacs-no-png-images nil
  1041. treemacs-recenter-after-file-follow nil
  1042. treemacs-recenter-after-tag-follow nil
  1043. treemacs-show-hidden-files t
  1044. treemacs-silent-filewatch nil
  1045. treemacs-silent-refresh nil
  1046. treemacs-sorting 'alphabetic-desc
  1047. treemacs-tag-follow-cleanup t
  1048. treemacs-tag-follow-delay 1.5
  1049. treemacs-width 35)
  1050. (treemacs-follow-mode t)
  1051. (treemacs-filewatch-mode t)
  1052. (pcase (cons (not (null (executable-find "git")))
  1053. (not (null (executable-find "python3"))))
  1054. (`(t . t)
  1055. (treemacs-git-mode 'extended))
  1056. (`(t . _)
  1057. (treemacs-git-mode 'simple)))
  1058. :bind
  1059. (:map global-map
  1060. ([f8] . treemacs-toggle))
  1061. )
  1062. #+end_src
  1063. Treemacs-projectile is useful for uhh.. TODO explain!
  1064. #+begin_src emacs-lisp
  1065. (use-package treemacs-projectile
  1066. :ensure t
  1067. :defer t
  1068. :config
  1069. (setq treemacs-header-function #'treemacs-projectile-create-header)
  1070. )
  1071. #+end_src
  1072. TODO
  1073. Hydrastuff or keybindings for functions:
  1074. - treemacs-projectile
  1075. - treemacs-projectile-toggle
  1076. - treemacs-toggle
  1077. - treemacs-bookmark
  1078. - treemacs-find-file
  1079. - treemacs-find-tag
  1080. * Evil
  1081. So... Evil Mode might be worth a try
  1082. #+BEGIN_SRC emacs-lisp
  1083. (use-package evil
  1084. :ensure t
  1085. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  1086. :init
  1087. (setq evil-want-integration nil) ;; required by evil-collection
  1088. :config
  1089. (evil-mode 0)) ;; for now deactivate per default
  1090. #+END_SRC
  1091. Evil-collection is a bundle of configs for different modes
  1092. #+BEGIN_SRC emacs-lisp
  1093. (use-package evil-collection
  1094. :after evil
  1095. :ensure t
  1096. :config
  1097. (evil-collection-init))
  1098. #+END_SRC
  1099. * Window Handling
  1100. Some tools to easen the navigation, creation and deletion of windows
  1101. ** Ace-Window
  1102. #+begin_src emacs-lisp
  1103. (use-package ace-window
  1104. :ensure t
  1105. :init
  1106. (global-set-key (kbd "C-x o") 'ace-window)
  1107. )
  1108. #+end_src
  1109. ** Windmove
  1110. Windmove easens the navigation between windows.
  1111. Here we are setting the default keybindings (shift+arrow)
  1112. CURRENTLY NOT WORKING, defaults are blocked.
  1113. Also not sure if necessary when using ace-window.
  1114. #+begin_src emacs-lisp
  1115. (use-package windmove
  1116. :ensure t
  1117. :config
  1118. (windmove-default-keybindings)
  1119. )
  1120. #+end_src
  1121. * Quality of Life