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
37 KiB

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