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.

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