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.

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