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.

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