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.

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