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.

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