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.

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