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.

1539 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
  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. (if (string-equal my/whoami "work_remote")
  523. (progn
  524. (defvar PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  525. (defvar PATH_ORG_JOURNAL "p:/Eigene Dateien/Notizen/Journal/")
  526. (defvar PATH_START "p:/Eigene Dateien/Notizen/"))
  527. )
  528. (if (string-equal my/whoami "home")
  529. (progn
  530. (setq org-default-notes-file "~/Archiv/Dokumente/Notizen/notes.org")
  531. (setq org-agenda-files
  532. (delq nil
  533. (mapcar (lambda (x) (and (file-exists-p x) x))
  534. '("~/Archiv/Dokumente/Agenda")))))
  535. (if (string-equal my/whoami "work_remote")
  536. (progn
  537. (setq org-default-notes-file (concat PATH_ORG_FILES "notes.org"))
  538. (setq org-agenda-files (list(concat PATH_ORG_FILES "notes.org")
  539. (concat PATH_ORG_FILES "projects.org")
  540. (concat PATH_ORG_FILES "todo.org"))))))
  541. #+END_SRC
  542. *** Org key bindings
  543. Set up some global key bindings that integrate with Org mode features
  544. #+BEGIN_SRC emacs-lisp
  545. (bind-key "C-c l" 'org-store-link)
  546. (bind-key "C-c c" 'org-capture)
  547. (bind-key "C-c a" 'org-agenda)
  548. #+END_SRC
  549. Org overwrites RET and C-j, so I need to disable the rebinds
  550. #+BEGIN_SRC emacs-lisp
  551. (define-key org-mode-map (kbd "RET") nil) ;;org-return
  552. (define-key org-mode-map (kbd "C-j") nil) ;;org-return-indent
  553. #+END_SRC
  554. *** Org agenda
  555. For a more detailed example [[https://github.com/sachac/.emacs.d/blob/83d21e473368adb1f63e582a6595450fcd0e787c/Sacha.org#org-agenda][see here]].
  556. BEGIN_SRC emacs-lisp
  557. (setq org-agenda-files
  558. (delq nil
  559. (mapcar (lambda (x) (and (file-exists-p x) x))
  560. '("~/Archiv/Dokumente/Agenda"))
  561. )
  562. )
  563. END_SRC
  564. *** Org capture
  565. 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.
  566. See the doc for speed keys by checking out the documentation for speed keys in Org mode.
  567. #+BEGIN_SRC emacs-lisp
  568. (setq org-use-speed-commands t)
  569. (setq org-image-actual-width 550)
  570. (setq org-highlight-latex-and-related '(latex script entities))
  571. #+END_SRC
  572. Hide emphasis markup (e.g. / ... / for italics, etc.)
  573. #+BEGIN_SRC emacs-lisp
  574. (setq org-hide-emphasis-markers t)
  575. #+END_SRC
  576. Sort org agenda by deadline and priority
  577. #+BEGIN_SRC emacs-lisp
  578. (setq org-agenda-sorting-strategy
  579. (quote
  580. ((agenda deadline-up priority-down)
  581. (todo priority-down category-keep)
  582. (tags priority-down category-keep)
  583. (search category-keep)))
  584. )
  585. #+END_SRC
  586. Custom todo-keywords, depending on environment
  587. #+BEGIN_SRC emacs-lisp
  588. (if (string-equal user-login-name "POH")
  589. (setq org-todo-keywords
  590. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE")))
  591. )
  592. #+END_SRC
  593. Set locations of some org files
  594. #+BEGIN_SRC emacs-lisp
  595. (if (string-equal user-login-name "POH")
  596. (progn
  597. (setq org-default-notes-file (concat PATH_ORG_FILES "notes.org"))
  598. (setq org-agenda-files (list(concat PATH_ORG_FILES "notes.org")
  599. (concat PATH_ORG_FILES "projects.org")
  600. (concat PATH_ORG_FILES "todo.org"))))
  601. )
  602. (setq org-id-locations-file (concat PATH_USER_LOCAL ".org-id-locations"))
  603. #+END_SRC
  604. Work specific org-capture-templates
  605. #+BEGIN_SRC emacs-lisp
  606. (if (string-equal user-login-name "POH")
  607. (setq org-capture-templates
  608. '(("t" "todo" entry (file (concat PATH_ORG_FILES "todo.org"))
  609. "** TODO %\\n%u\n%a\n")
  610. ("n" "note" entry (file org-default-notes-file))
  611. ("p" "project" entry (file (concat PATH_ORG_FILES "projects.org"))
  612. "** OPEN %?\n%u\n** Beschreibung\n** Zu erledigen\n*** \n** Verlauf\n***" :clock-in t :clock-resume t)
  613. ("u" "Unterbrechung" entry (file org-default-notes-file)
  614. "* Unterbrechnung durch %? :Unterbrechung:\n%t" :clock-in t :clock-resume t)))
  615. )
  616. #+END_SRC
  617. Customize the org agenda
  618. #+BEGIN_SRC emacs-lisp
  619. (defun my-org-skip-subtree-if-priority (priority)
  620. "Skip an agenda subtree if it has a priority of PRIORITY.
  621. PRIORITY may be one of the characters ?A, ?B, or ?C."
  622. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  623. (pri-value (* 1000 (- org-lowest-priority priority)))
  624. (pri-current (org-get-priority (thing-at-point 'line t))))
  625. (if (= pri-value pri-current)
  626. subtree-end
  627. nil)))
  628. (setq org-agenda-custom-commands
  629. '(("c" "Simple agenda view"
  630. ((tags "PRIORITY=\"A\""
  631. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  632. (org-agenda-overriding-header "Hohe Priorität:")))
  633. (agenda ""
  634. ((org-agenda-span 7)
  635. (org-agenda-start-on-weekday nil)
  636. (org-agenda-overriding-header "Nächsten 7 Tage:")))
  637. (alltodo ""
  638. ((org-agenda-skip-function '(or (my-org-skip-subtree-if-priority ?A)
  639. (org-agenda-skip-if nil '(scheduled deadline))))
  640. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))
  641. )
  642. #+END_SRC
  643. ** Org tags
  644. The default value is -77, which is weird for smaller width windows. I'd rather have the tags align horizontally with the header.
  645. 45 is a good column number to do that.
  646. #+BEGIN_SRC emacs-lisp
  647. (setq org-tags-column 45)
  648. #+END_SRC
  649. ** Org babel languages
  650. This code block is linux specific. Loading languages which aren't available seems to be a problem
  651. #+BEGIN_SRC emacs-lisp
  652. (cond ((eq system-type 'gnu/linux)
  653. (org-babel-do-load-languages
  654. 'org-babel-load-languages
  655. '(
  656. (C . t)
  657. (calc . t)
  658. (java . t)
  659. (js . t)
  660. (latex . t)
  661. (ledger . t)
  662. (beancount . t)
  663. (lisp . t)
  664. (python . t)
  665. (R . t)
  666. (ruby . t)
  667. (scheme . t)
  668. (shell . t)
  669. (sqlite . t)
  670. )
  671. ))
  672. )
  673. #+END_SRC
  674. #+BEGIN_SRC emacs-lisp
  675. (defun my-org-confirm-babel-evaluate (lang body)
  676. "Do not confirm evaluation for these languages."
  677. (not (or (string= lang "beancount")
  678. (string= lang "C")
  679. (string= lang "emacs-lisp")
  680. (string= lang "java")
  681. (string= lang "ledger")
  682. (string= lang "python")
  683. (string= lang "R")
  684. (string= lang "sqlite"))))
  685. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  686. #+END_SRC
  687. I want plots!
  688. #+BEGIN_SRC emacs-lisp
  689. (use-package ess
  690. :ensure t
  691. )
  692. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
  693. (add-hook 'org-mode-hook 'org-display-inline-images)
  694. #+END_SRC
  695. ** Org babel/source blocks
  696. 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
  697. 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
  698. #+BEGIN_SRC emacs-lisp
  699. (setq org-src-fontify-natively t
  700. org-src-window-setup 'current-window
  701. org-src-strip-leading-and-trailing-blank-lines t
  702. org-src-preserve-indentation nil ; these two lines respect the indentation of
  703. org-edit-src-content-indentation 0 ; the surrounding text around the source block
  704. org-src-tab-acts-natively t)
  705. #+END_SRC
  706. * Pandoc
  707. Convert between formats, like from org to html.
  708. Pandoc needs to be installed on the system
  709. #+BEGIN_SRC shell
  710. sudo apt install pandoc
  711. #+END_SRC
  712. Pandoc-mode is a minor mode to interact with pandoc
  713. #+BEGIN_SRC emacs-lisp
  714. (use-package pandoc-mode
  715. :ensure t
  716. :init
  717. (add-hook 'markdown-mode-hook 'pandoc-mode))
  718. #+END_SRC
  719. * Emails
  720. Currently following tools are required:
  721. - notmuch (edit, read, tag, delete emails)
  722. - isync /mbsync (fetch or sync emails)
  723. 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.
  724. TODO:
  725. - setup of mbsync on linux
  726. - setup of notmuch on linux
  727. - shell script for installation of isync and notmuch
  728. - more config for notmuch?
  729. - hydra for notmuch?
  730. - maybe org-notmuch?
  731. - some way to refresh the notmuch db before I run notmuch?
  732. #+BEGIN_SRC emacs-lisp
  733. (unless (string-equal user-login-name "POH")
  734. (use-package notmuch
  735. :defer t
  736. :ensure t
  737. )
  738. )
  739. #+END_SRC
  740. * Personal Finances
  741. After trying ledger, I chose beancount. It is closer to real bookkeeping and has stricter rules.
  742. Since there is no debian package, it is an option to install it via pip.
  743. I picked /opt for the installation path
  744. #+BEGIN_SRC shell
  745. sudo su
  746. cd /opt
  747. python3 -m venv beancount
  748. source ./beancount/bin/activate
  749. pip3 install wheel
  750. pip3 install beancount
  751. deactivate
  752. #+END_SRC
  753. When using beancount, it will automatically pick the created virtual environment.
  754. Activate the beancount mode. ATTENTION: This mode is made by myself.
  755. #+BEGIN_SRC emacs-lisp
  756. (unless (string-equal user-login-name "POH")
  757. (load "/home/marc/.emacs.d/user-local/elisp/beancount-mode.el") ; somehow load-path in use-package doesn't work
  758. (use-package beancount
  759. :load-path "/home/marc/.emacs.d/elisp"
  760. :defer t
  761. :mode ("\\.beancount$" . beancount-mode)
  762. :init
  763. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  764. (setenv "PATH"
  765. (concat
  766. "/opt/beancount/bin:"
  767. (getenv "PATH"))
  768. )
  769. :config
  770. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/transactions.beancount")
  771. )
  772. )
  773. #+END_SRC
  774. Installing fava for reports is strongly recommended.
  775. #+BEGIN_SRC shell
  776. sudo su
  777. cd /opt
  778. python3 -m venv vava
  779. source ./vava/bin/activate
  780. pip3 install wheel
  781. pip3 install fava
  782. deactivate
  783. #+END_SRC
  784. Start fava with
  785. #+BEGIN_SRC shell
  786. fava my_file.beancount
  787. #+END_SRC
  788. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  789. Beancount-mode can start fava and open the URL right away.
  790. * Programming
  791. ** Common things
  792. List of plugins and settings which are shared between the language plugins
  793. Highlight whitespaces, tabs, empty lines.
  794. #+BEGIN_SRC emacs-lisp
  795. (use-package whitespace
  796. :demand t
  797. :ensure nil
  798. :diminish whitespace-mode;;mode shall be active, but not shown in mode line
  799. :init
  800. (dolist (hook '(prog-mode-hook
  801. text-mode-hook
  802. conf-mode-hook))
  803. (add-hook hook #'whitespace-mode))
  804. ;; :hook ;;not working in use-package 2.3
  805. ;; ((prog-mode . whitespace-turn-on)
  806. ;; (text-mode . whitespace-turn-on))
  807. :config
  808. (setq-default whitespace-style '(face empty tab trailing))
  809. )
  810. #+END_SRC
  811. Disable Eldoc, it interferes with flycheck
  812. #+BEGIN_SRC emacs-lisp
  813. (use-package eldoc
  814. :ensure nil
  815. :config
  816. (global-eldoc-mode -1)
  817. )
  818. #+END_SRC
  819. Colorize colors as text with their value
  820. #+BEGIN_SRC emacs-lisp
  821. (use-package rainbow-mode
  822. :ensure t
  823. :init
  824. (add-hook 'prog-mode-hook 'rainbow-mode t)
  825. :diminish rainbow-mode
  826. ;; :hook prog-mode ;; not working in use-package 2.3
  827. :config
  828. (setq-default rainbow-x-colors-major-mode-list '())
  829. )
  830. #+END_SRC
  831. Highlight parens etc. for improved readability
  832. #+BEGIN_SRC emacs-lisp
  833. (use-package rainbow-delimiters
  834. :ensure t
  835. :config
  836. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  837. )
  838. #+END_SRC
  839. ** Smartparens
  840. Smartparens is a beast on its own, so it's worth having a dedicated section for it
  841. #+BEGIN_SRC emacs-lisp
  842. (use-package smartparens
  843. :ensure t
  844. :diminish smartparens-mode
  845. :config
  846. (add-hook 'prog-mode-hook 'smartparens-mode)
  847. )
  848. #+END_SRC
  849. ** Git
  850. *** Magit
  851. [[https://magit.vc/manual/magit/index.html][Link]]
  852. I want to do git stuff here, not in a separate terminal window
  853. Little crashcourse in magit:
  854. - magit-init to init a git project
  855. - magit-status (C-x g) to call the status window
  856. in status buffer:
  857. - s stage files
  858. - u unstage files
  859. - U unstage all files
  860. - a apply changed to staging
  861. - c c commit (type commit message, then C-c C-c to commit)
  862. - b b switch to another branch
  863. - P u git push
  864. - F u git pull
  865. #+BEGIN_SRC emacs-lisp
  866. (use-package magit
  867. :ensure t
  868. :defer t
  869. :init
  870. ;; set git-path in work environment
  871. (if (string-equal user-login-name "POH")
  872. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  873. )
  874. :defer t
  875. :bind (("C-x g" . magit-status))
  876. )
  877. #+END_SRC
  878. *** Git-gutter
  879. Display line changes in gutter based on git history. Enable it everywhere
  880. [[https://github.com/syohex/emacs-git-gutter][Source]]
  881. #+BEGIN_SRC emacs-lisp
  882. (use-package git-gutter
  883. :ensure t
  884. :defer t
  885. :config
  886. (global-git-gutter-mode t)
  887. :diminish git-gutter-mode
  888. )
  889. #+END_SRC
  890. Some persistent navigation in git-gutter is nice, so here's a hydra for it:
  891. #+BEGIN_SRC emacs-lisp
  892. (defhydra hydra-git-gutter (:body-pre (git-gutter-mode 1)
  893. :hint nil)
  894. "
  895. ^Git Gutter^ ^Git^ ^misc^
  896. ^──────────^────────^───^────────────────^────^──────────────────────────
  897. _j_: next hunk _s_tage hunk _q_uit
  898. _k_: previous hunk _r_evert hunk _g_ : call magit-status
  899. _h_: first hunk _p_opup hunk
  900. _l_: last hunk set start _R_evision
  901. ^^ ^^ ^^
  902. "
  903. ("j" git-gutter:next-hunk)
  904. ("k" git-gutter:previous-hunk)
  905. ("h" (progn (goto-char (point-min))
  906. (git-gutter:next-hunk 1)))
  907. ("l" (progn (goto-char (point-min))
  908. (git-gutter:previous-hunk 1)))
  909. ("s" git-gutter:stage-hunk)
  910. ("r" git-gutter:revert-hunk)
  911. ("p" git-gutter:popup-hunk)
  912. ("R" git-gutter:set-start-revision)
  913. ("q" nil :color blue)
  914. ("g" magit-status)
  915. )
  916. #+END_SRC
  917. *** Git-timemachine
  918. Time machine lets me step through the history of a file as recorded in git.
  919. [[https://github.com/pidu/git-timemachine][Source]]
  920. #+BEGIN_SRC emacs-lisp
  921. (use-package git-timemachine
  922. :ensure t
  923. :defer t
  924. )
  925. #+END_SRC
  926. ** Company Mode
  927. Complete Anything!
  928. Activate company and make it react nearly instantly
  929. #+BEGIN_SRC emacs-lisp
  930. (use-package company
  931. :ensure t
  932. :config
  933. (setq-default company-minimum-prefix-length 1
  934. company-tooltip-align-annotation t
  935. company-tooltop-flip-when-above t
  936. company-show-numbers t
  937. company-idle-delay 0.1)
  938. ;; (define-key company-active-map (kbd "TAB") #'company-complete-selection)
  939. ;; (define-key company-active-map (kbd "RET") nil)
  940. (company-tng-configure-default)
  941. )
  942. #+END_SRC
  943. For a nicer suggestion box: company-box ([[https://github.com/sebastiencs/company-box][Source]])
  944. It is only available for emacs 26 and higher.
  945. #+BEGIN_SRC emacs-lisp
  946. (when (> emacs-major-version 25)
  947. (use-package company-box
  948. :ensure t
  949. :init
  950. (add-hook 'company-mode-hook 'company-box-mode)))
  951. #+END_SRC
  952. *** Company backend hooks
  953. Backend configuration for python-mode
  954. Common backends are:
  955. - company-files: files & directory
  956. - company-keywords: keywords
  957. - company-capf: ??
  958. - company-abbrev: ??
  959. - company-dabbrev: dynamic abbreviations
  960. - company-ispell: ??
  961. #+BEGIN_SRC emacs-lisp
  962. (defun company/python-mode-hook()
  963. (set (make-local-variable 'company-backends)
  964. '((company-jedi)))
  965. ; '((company-jedi company-dabbrev-code company-yasnippet) company-capf company-files))
  966. ; '((company-lsp company-yasnippet) company-capf company-dabbrev company-files))
  967. (company-mode t)
  968. )
  969. #+END_SRC
  970. (defun add-pcomplete-to-capf ()
  971. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  972. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  973. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  974. Backend for Orgmode
  975. #+BEGIN_SRC emacs-lisp
  976. (defun company/org-mode-hook()
  977. (set (make-local-variable 'company-backends)
  978. '(company-capf company-files))
  979. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  980. (company-mode t)
  981. )
  982. #+END_SRC
  983. Backend configuration for lisp-mode
  984. #+BEGIN_SRC emacs-lisp
  985. (defun company/elisp-mode-hook()
  986. (set (make-local-variable 'company-backends)
  987. '((company-elisp company-dabbrev) company-capf company-files))
  988. (company-mode t)
  989. )
  990. #+END_SRC
  991. Backend configuration for beancount
  992. #+BEGIN_SRC emacs-lisp
  993. (defun company/beancount-mode-hook()
  994. (set (make-local-variable 'company-backends)
  995. '(company-beancount))
  996. ; '((company-beancount company-dabbrev) company-capf company-files))
  997. (company-mode t)
  998. )
  999. #+END_SRC
  1000. *** Misc Company packages
  1001. Addon to sort suggestions by usage
  1002. #+BEGIN_SRC emacs-lisp
  1003. (use-package company-statistics
  1004. :ensure t
  1005. :after company
  1006. :init
  1007. (setq company-statistics-file (concat PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  1008. :config
  1009. (company-statistics-mode 1)
  1010. )
  1011. #+END_SRC
  1012. Get a popup with documentation of the completion candidate.
  1013. For the popups the package pos-tip.el is used and automatically installed.
  1014. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  1015. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  1016. #+BEGIN_SRC emacs-lisp
  1017. (use-package company-quickhelp
  1018. :ensure t
  1019. :after company
  1020. :config
  1021. (company-quickhelp-mode 1)
  1022. )
  1023. #+END_SRC
  1024. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  1025. ** Flycheck
  1026. Show errors right away!
  1027. #+BEGIN_SRC emacs-lisp
  1028. (use-package flycheck
  1029. :ensure t
  1030. :diminish flycheck-mode " ✓"
  1031. :init
  1032. (setq flycheck-emacs-lisp-load-path 'inherit)
  1033. (add-hook 'after-init-hook #'global-flycheck-mode)
  1034. ; (add-hook 'python-mode-hook (lambda ()
  1035. ; (semantic-mode 1)
  1036. ; (flycheck-select-checker 'python-pylint)))
  1037. )
  1038. #+END_SRC
  1039. ** Projectile
  1040. Brings search functions on project level
  1041. #+BEGIN_SRC emacs-lisp
  1042. (use-package projectile
  1043. :ensure t
  1044. :defer t
  1045. :bind
  1046. (("C-c p p" . projectile-switch-project)
  1047. ("C-c p s s" . projectile-ag))
  1048. :init
  1049. (setq-default
  1050. projectile-cache-file (concat PATH_USER_LOCAL ".projectile-cache")
  1051. projectile-known-projects-file (concat PATH_USER_LOCAL ".projectile-bookmarks"))
  1052. :config
  1053. (projectile-mode t)
  1054. (setq-default
  1055. projectile-completion-system 'ivy
  1056. projectile-enable-caching t
  1057. projectile-mode-line '(:eval (projectile-project-name)))
  1058. )
  1059. #+END_SRC
  1060. ** Yasnippet
  1061. Snippets!
  1062. TODO: yas-minor-mode? what's that?
  1063. #+BEGIN_SRC emacs-lisp
  1064. (use-package yasnippet
  1065. :ensure t
  1066. :defer t
  1067. :diminish yas-minor-mode
  1068. :init
  1069. (setq yas-snippet-dirs (concat PATH_USER_GLOBAL "snippets"))
  1070. (yas-global-mode t)
  1071. :mode ("\\.yasnippet" . snippet-mode)
  1072. ; :config
  1073. ; (yas-reload-all) ;; ensure snippets are updated and available, necessary when not using global-mode
  1074. )
  1075. #+END_SRC
  1076. ** Lisp
  1077. #+BEGIN_SRC emacs-lisp
  1078. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  1079. #+END_SRC
  1080. Add some helpers to handle and understand macros
  1081. #+BEGIN_SRC emacs-lisp
  1082. (use-package macrostep
  1083. :ensure t
  1084. :defer t
  1085. :init
  1086. (define-key emacs-lisp-mode-map (kbd "C-c e") 'macrostep-expand)
  1087. (define-key emacs-lisp-mode-map (kbd "C-c c") 'macrostep-collapse))
  1088. #+END_SRC
  1089. ** Python
  1090. Systemwide following packages need to be installed:
  1091. - venv
  1092. The virtual environments need to have following modules installed:
  1093. - wheel (for some reason it isn't pulled by other packages, yet they complain about missing wheel)
  1094. - jedi
  1095. - epc
  1096. - pylint
  1097. - NEW: python-language-server[all]
  1098. - instead of [all] there are
  1099. for python-language-server see here: [[https://github.com/palantir/python-language-server][Link]]
  1100. Automatically start python-mode when opening a .py-file.
  1101. Not sure if python.el is better than python-mode.el.
  1102. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  1103. 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]].
  1104. Also limit the completion backends to those which make sense in Python.
  1105. #+BEGIN_SRC emacs-lisp
  1106. (use-package python
  1107. :mode ("\\.py\\'" . python-mode)
  1108. :interpreter ("python" . python-mode)
  1109. :defer t
  1110. :init
  1111. (add-hook 'python-mode-hook (lambda ()
  1112. 'company/python-mode-hook
  1113. (semantic-mode t)
  1114. (flycheck-select-checker 'python-pylint)))
  1115. :config
  1116. (setq python-shell-completion-native-enable nil)
  1117. )
  1118. #+END_SRC
  1119. First test for lsp-python.
  1120. Source python language server: [[https://github.com/palantir/python-language-server][Link]]
  1121. Source lsp-mode:
  1122. Source lsp-python: [[https://github.com/emacs-lsp/lsp-python][Link]]
  1123. Source company-lsp: [[https://github.com/tigersoldier/company-lsp][Link]]
  1124. Source lsp-ui: [[https://github.com/emacs-lsp/lsp-ui][Link]]
  1125. BEGIN_SRC emacs-lisp
  1126. (use-package lsp-mode
  1127. :ensure t
  1128. :defer t)
  1129. (add-hook 'lsp-mode-hook #'(lambda ()
  1130. (customize-set-variable 'lsp-enable-eldoc nil)
  1131. (flycheck-mode 1)
  1132. (company-mode 1)))
  1133. (use-package lsp-ui
  1134. :ensure t
  1135. :defer t)
  1136. (use-package company-lsp
  1137. :ensure t
  1138. :defer t)
  1139. (use-package lsp-python
  1140. :ensure t
  1141. :after lsp-mode
  1142. :defer t
  1143. :init
  1144. (add-hook 'python-mode-hook #'(lambda ()
  1145. (lsp-python-enable)
  1146. (flycheck-select-checker 'python-flake8))))
  1147. END_SRC
  1148. Jedi is a backend for python autocompletion and needs to be installed on the server:
  1149. - pip install jedi
  1150. Code checks need to be installed, too:
  1151. - pip install flake8
  1152. #+BEGIN_SRC emacs-lisp
  1153. (use-package company-jedi
  1154. :defer t
  1155. ;; :after company
  1156. :ensure t
  1157. :config
  1158. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  1159. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  1160. (add-hook 'python-mode-hook 'jedi:setup)
  1161. (setq jedi:complete-on-dot t)
  1162. (setq jedi:use-shortcuts t)
  1163. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  1164. )
  1165. #+END_SRC
  1166. A wrapper to handle virtual environments.
  1167. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  1168. TODO: automatically start an inferior python process or switch to it if already created
  1169. #+BEGIN_SRC emacs-lisp
  1170. (use-package pyvenv
  1171. :ensure t
  1172. :defer t
  1173. :init
  1174. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  1175. :config
  1176. (pyvenv-mode t)
  1177. (defun my/post-activate-hook()
  1178. (setq jedi:environment-root pyvenv-virtual-env)
  1179. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  1180. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  1181. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  1182. ;; default traceback, other option M-x jedi:toggle-log-traceback
  1183. ;; traceback is in jedi:pop-to-epc-buffer
  1184. (jedi:setup)
  1185. (company/python-mode-hook)
  1186. (setq jedi:server-args '("--log-traceback")))
  1187. (add-hook 'pyvenv-post-activate-hooks 'my/post-activate-hook)
  1188. )
  1189. #+END_SRC
  1190. I want Emacs to automatically start the proper virtual environment.
  1191. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  1192. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  1193. Depends on pyvenv
  1194. #+BEGIN_SRC emacs-lisp
  1195. (use-package auto-virtualenv
  1196. :ensure t
  1197. ;; :after pyvenv
  1198. :defer t
  1199. :init
  1200. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  1201. ;; activate on changing buffers
  1202. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  1203. ;; activate on focus in
  1204. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  1205. )
  1206. #+END_SRC
  1207. Anaconda test
  1208. #+BEGIN_SRC emacs-lisp
  1209. ; (use-package anaconda-mode
  1210. ; :ensure t
  1211. ; :defer t
  1212. ; :init
  1213. ; (add-hook 'python-mode-hook 'anaconda-mode)
  1214. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  1215. ; :config
  1216. ; (setq anaconda-eldoc-mode 1)
  1217. ; )
  1218. #+END_SRC
  1219. #+BEGIN_SRC emacs-lisp
  1220. ; (use-package company-anaconda
  1221. ; :ensure t
  1222. ; :defer t
  1223. ; :init
  1224. ; (defun my/company-anaconda-hook()
  1225. ; (add-to-list 'company-backends 'company-anaconda))
  1226. ; (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  1227. ; )
  1228. #+END_SRC
  1229. ** Latex
  1230. Requirements for Linux:
  1231. - Latex
  1232. - pdf-tools
  1233. #+BEGIN_SRC emacs-lisp
  1234. (unless (string-equal user-login-name "POH")
  1235. (use-package pdf-tools
  1236. :ensure t
  1237. :defer t
  1238. :config
  1239. (pdf-tools-install)
  1240. (setq TeX-view-program-selection '((output-pdf "pdf-tools")))
  1241. (setq TeX-view-program-list '(("pdf-tools" "Tex-pdf-tools-sync-view")))
  1242. )
  1243. )
  1244. #+END_SRC
  1245. 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]]
  1246. Update 2018-03: It seems to work without this patch. I will keep it here in case something breaks again.
  1247. #+BEGIN_SRC
  1248. latex-preview-pane-update-p()
  1249. --- (doc-view-revert-buffer nil t)
  1250. +++ (revert-buffer-nil t 'preserve-modes)
  1251. #+END_SRC
  1252. After that M-x byte-compile-file
  1253. #+BEGIN_SRC emacs-lisp
  1254. (use-package latex-preview-pane
  1255. :ensure t
  1256. :defer t
  1257. :init
  1258. ;; one of these works
  1259. (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
  1260. (add-hook 'latex-mode-hook 'latex-preview-pane-mode)
  1261. (setq auto-mode-alist
  1262. (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
  1263. )
  1264. ;; necessary, because linum-mode isn't compatible and prints errors
  1265. (add-hook 'pdf-view-mode-hook (lambda () (linum-mode -1)))
  1266. #+END_SRC
  1267. ** Markdown
  1268. Major mode to edit markdown files.
  1269. For previews it needs markdown installed on the system.
  1270. For debian:
  1271. #+BEGIN_SRC shell
  1272. sudo apt install markdown
  1273. #+END_SRC
  1274. #+BEGIN_SRC emacs-lisp
  1275. (use-package markdown-mode
  1276. :ensure t
  1277. :defer t)
  1278. #+END_SRC
  1279. ** Hydra Flycheck
  1280. Flycheck is necessary, obviously
  1281. #+BEGIN_SRC emacs-lisp
  1282. (defhydra hydra-flycheck (:color blue)
  1283. "
  1284. ^
  1285. ^Flycheck^ ^Errors^ ^Checker^
  1286. ^────────^──────────^──────^────────────^───────^───────────
  1287. _q_ quit _<_ previous _?_ describe
  1288. _m_ manual _>_ next _d_ disable
  1289. _v_ verify setup _f_ check _s_ select
  1290. ^^ ^^ ^^
  1291. "
  1292. ("q" nil)
  1293. ("<" flycheck-previous-error :color red)
  1294. (">" flycheck-next-error :color red)
  1295. ("?" flycheck-describe-checker)
  1296. ("d" flycheck-disable-checker)
  1297. ("f" flycheck-buffer)
  1298. ("m" flycheck-manual)
  1299. ("s" flycheck-select-checker)
  1300. ("v" flycheck-verify-setup)
  1301. )
  1302. #+END_SRC
  1303. * Orchestrate the configuration
  1304. Some settings should be set for all systems, some need to be specific (like my job-emacs doesn't need development tools).
  1305. ** Common
  1306. ** Home
  1307. ** Work
  1308. I mainly only use org
  1309. ** Work, Hyper-V
  1310. For testing purproses I keep a working emacs in a debian on hyper-v. The demands here are different to the other work-emacs
  1311. * Finishing
  1312. Stuff which I want to run in the end
  1313. #+BEGIN_SRC emacs-lisp
  1314. (message (emacs-init-time))
  1315. #+END_SRC