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.

1647 lines
48 KiB

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