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