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.

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