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.

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