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.

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