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.

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