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.

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