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.

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