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.

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