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