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.

1479 lines
42 KiB

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