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.

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