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.

1673 lines
49 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
  1. #+TITLE: Emacs Configuration
  2. #+AUTHOR: Marc Pohling
  3. * Personal Information
  4. #+BEGIN_SRC emacs-lisp
  5. (setq user-full-name "Marc Pohling"
  6. user-mail-address "marc.pohling@googlemail.com")
  7. #+END_SRC
  8. I need a function to know what computer emacs is running on. The display width of 1152 pixel is an oddity of hyper-v and for my usecase specific enough to tell the machine.
  9. #+BEGIN_SRC emacs-lisp
  10. (defvar my/whoami
  11. (if (string-equal user-login-name "POH")
  12. "work_remote"
  13. (if (equal (display-pixel-width) 1152)
  14. "work_hyperv"
  15. (if (string-equal system-type "gnu/linux")
  16. "home"))))
  17. #+END_SRC
  18. * Stuff to add / to fix
  19. - smartparens
  20. a sane default configuration for navigation, manipulation etc. is still necessary
  21. - Spaceline / Powerline or similar
  22. I want a pretty status bar!
  23. - Git gutter:
  24. Do some configuration to make it useful (see given source link in the [[*Git][Section]] of gutter)
  25. Maybe only enable it for modes where it is likely I use git?
  26. - Some webmode stuff
  27. - markdown:
  28. add hooks for certain file extensions, maybe add a smart way to start gfm-mode if markdown-file is in a git-project
  29. - move package dependend configurations inside the package configuration itself, like keymaps for magit
  30. * Update config in a running config
  31. Two options:
  32. - reload the open file: M-x load-file, then press twice to accept
  33. the default filename, which is the currently opened
  34. - Point at the end of any sexp and press C-x C-e
  35. * Customize default settings
  36. Keep the .emacs.d clean by moving user files into separate directories.
  37. - user-local: directory for machine specific files
  38. - user-global: directory for files which work on any machine
  39. - the backup and auto-save files go right to /tmp
  40. #+BEGIN_SRC emacs-lisp
  41. (defvar PATH_USER_LOCAL (expand-file-name "~/.emacs.d/user-local/"))
  42. (defvar PATH_USER_GLOBAL (expand-file-name "~/.emacs.d/user-global/"))
  43. (setq bookmark-default-file (concat PATH_USER_LOCAL "bookmarks"))
  44. (setq recentf-save-file (concat PATH_USER_LOCAL "recentf"))
  45. (setq custom-file (concat PATH_USER_LOCAL "custom.el")) ;don't spam init.el with saved customize settings
  46. (setq abbrev-file-name (concat PATH_USER_GLOBAL "abbrev_defs"))
  47. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  48. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  49. (setq save-abbrevs 'silently) ; don't bother me with asking if new abbrevs should be saved
  50. #+END_SRC
  51. These functions are useful. Activate them.
  52. #+BEGIN_SRC emacs-lisp
  53. (put 'downcase-region 'disabled nil)
  54. (put 'upcase-region 'disabled nil)
  55. (put 'narrow-to-region 'disabled nil)
  56. (put 'dired-find-alternate-file 'disabled nil)
  57. #+END_SRC
  58. Answering just 'y' or 'n' should be enough.
  59. #+BEGIN_SRC emacs-lisp
  60. (defalias 'yes-or-no-p 'y-or-n-p)
  61. #+END_SRC
  62. Don't ask me if I want to load themes.
  63. #+BEGIN_SRC emacs-lisp
  64. (setq custom-safe-themes t)
  65. #+END_SRC
  66. Don't count two spaces after a period as the end of a sentence.
  67. Just one space is needed
  68. #+BEGIN_SRC emacs-lisp
  69. (setq sentence-end-double-space nil)
  70. #+END_SRC
  71. Delete the region when typing, just like as we expect nowadays.
  72. #+BEGIN_SRC emacs-lisp
  73. (delete-selection-mode t)
  74. #+END_SRC
  75. Auto-indent when pressing RET, just new-line when C-j
  76. #+BEGIN_SRC emacs-lisp
  77. (define-key global-map (kbd "RET") 'newline-and-indent)
  78. (define-key global-map (kbd "C-j") 'newline)
  79. #+END_SRC
  80. Set the default window size depending on the system emacs is running on.
  81. ;; TODO:
  82. ;; This size is only reasonable for linux@home
  83. ;; hyperv is way smaller, use fullscreen here
  84. ;; pm should be fullscreen, too
  85. #+BEGIN_SRC emacs-lisp
  86. (if (display-graphic-p)
  87. (pcase my/whoami
  88. ("home" (progn
  89. (setq initial-frame-alist
  90. '((width . 165)
  91. (height . 70)))
  92. (setq default-frame-alist
  93. '((width . 165)
  94. (height . 70)))))
  95. ("work_remote" (add-to-list 'initial-frame-alist '(fullscreen . maximized)))
  96. ("work_hyperv" (add-to-list 'initial-frame-alist '(fullscreen . maximized)))))
  97. #+END_SRC
  98. * Visuals
  99. ** Font
  100. Don't add the font in the work environment, which I am logged in as POH
  101. #+BEGIN_SRC emacs-lisp
  102. (pcase my/whoami
  103. ("home" (set-face-attribute 'default nil :font "Hack-10"))
  104. ("work_hyperv" (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. (global-undo-tree-mode 1))
  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. Visual feedback when using regexp on the buffer
  512. #+BEGIN_SRC emacs-lisp
  513. (use-package visual-regexp
  514. :ensure t
  515. :defer t
  516. :bind (("C-c r s" . query-replace)
  517. ("C-c r R" . vr/replace)
  518. ("C-c r r" . vr/query-replace)
  519. ("C-c r m" . vr/mc-mark)))
  520. #+END_SRC
  521. Newline at the end of file
  522. #+BEGIN_SRC emacs-lisp
  523. (setq require-final-newline t)
  524. #+END_SRC
  525. Delete the selection with a keypress
  526. #+BEGIN_SRC emacs-lisp
  527. (delete-selection-mode t)
  528. #+END_SRC
  529. Remember the current location in a file
  530. #+BEGIN_SRC emacs-lisp
  531. (use-package saveplace
  532. :unless noninteractive
  533. :config
  534. (save-place-mode))
  535. #+END_SRC
  536. * Org Mode
  537. ** Installation
  538. 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.]]
  539. Added a hook to complete org functions, company-capf is necessary for this
  540. #+BEGIN_SRC emacs-lisp
  541. (use-package org
  542. :ensure org-plus-contrib
  543. :init
  544. (add-hook 'org-mode-hook 'company/org-mode-hook)
  545. )
  546. (add-hook 'org-mode-hook 'company/org-mode-hook)
  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. New: Load languages on demand. I need to test if this works as intended.
  671. #+BEGIN_SRC emacs-lisp
  672. (defadvice org-babel-execute-src-block (around load-language nil activate)
  673. "Load language if needed"
  674. (let ((language (org-element-property :language (org-element-at-point))))
  675. (unless (cdr (assoc (intern language) org-babel-load-languages))
  676. (add-to-list 'org-babel-load-languages (cons (intern language) t))
  677. (org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages))
  678. ad-do-it))
  679. #+END_SRC
  680. BEGIN_SRC emacs-lisp
  681. (cond ((eq system-type 'gnu/linux)
  682. (org-babel-do-load-languages
  683. 'org-babel-load-languages
  684. '(
  685. (C . t)
  686. (calc . t)
  687. (java . t)
  688. (ipython . t)
  689. (js . t)
  690. (latex . t)
  691. (ledger . t)
  692. (beancount . t)
  693. (lisp . t)
  694. (python . t)
  695. (R . t)
  696. (ruby . t)
  697. (scheme . t)
  698. (shell . t)
  699. (sqlite . t)
  700. )
  701. ))
  702. )
  703. END_SRC
  704. #+BEGIN_SRC emacs-lisp
  705. (defun my-org-confirm-babel-evaluate (lang body)
  706. "Do not confirm evaluation for these languages."
  707. (not (or (string= lang "beancount")
  708. (string= lang "C")
  709. (string= lang "emacs-lisp")
  710. (string= lang "ipython")
  711. (string= lang "java")
  712. (string= lang "ledger")
  713. (string= lang "python")
  714. (string= lang "R")
  715. (string= lang "sqlite"))))
  716. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  717. #+END_SRC
  718. TODO: ess belongs to programming languages
  719. to start an ess instance C-c C-s
  720. #+BEGIN_SRC emacs-lisp
  721. (use-package ess
  722. :ensure t
  723. :init
  724. (add-hook 'ess-mode-hook 'company/ess-mode-hook)
  725. )
  726. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
  727. (add-hook 'org-mode-hook 'org-display-inline-images)
  728. #+END_SRC
  729. ** Org babel/source blocks
  730. 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
  731. 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
  732. #+BEGIN_SRC emacs-lisp
  733. (setq org-src-fontify-natively t
  734. org-src-window-setup 'current-window
  735. org-src-strip-leading-and-trailing-blank-lines t
  736. org-src-preserve-indentation nil ; these two lines respect the indentation of
  737. org-edit-src-content-indentation 0 ; the surrounding text around the source block
  738. org-src-tab-acts-natively t)
  739. #+END_SRC
  740. ** Org babel helper functions
  741. * Pandoc
  742. Convert between formats, like from org to html.
  743. Pandoc needs to be installed on the system
  744. #+BEGIN_SRC shell
  745. sudo apt install pandoc
  746. #+END_SRC
  747. Pandoc-mode is a minor mode to interact with pandoc
  748. #+BEGIN_SRC emacs-lisp
  749. (use-package pandoc-mode
  750. :ensure t
  751. :init
  752. (add-hook 'markdown-mode-hook 'pandoc-mode))
  753. #+END_SRC
  754. * Emails
  755. Currently following tools are required:
  756. - notmuch (edit, read, tag, delete emails)
  757. - isync /mbsync (fetch or sync emails)
  758. 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.
  759. TODO:
  760. - setup of mbsync on linux
  761. - setup of notmuch on linux
  762. - shell script for installation of isync and notmuch
  763. - more config for notmuch?
  764. - hydra for notmuch?
  765. - maybe org-notmuch?
  766. - some way to refresh the notmuch db before I run notmuch?
  767. #+BEGIN_SRC emacs-lisp
  768. (unless (string-equal my/whoami "work_remote")
  769. (use-package notmuch
  770. :defer t
  771. :ensure t
  772. )
  773. )
  774. #+END_SRC
  775. * Personal Finances
  776. After trying ledger, I chose beancount. It is closer to real bookkeeping and has stricter rules.
  777. Since there is no debian package, it is an option to install it via pip.
  778. I picked /opt for the installation path
  779. #+BEGIN_SRC shell
  780. sudo su
  781. cd /opt
  782. python3 -m venv beancount
  783. source ./beancount/bin/activate
  784. pip3 install wheel
  785. pip3 install beancount
  786. deactivate
  787. #+END_SRC
  788. When using beancount, it will automatically pick the created virtual environment.
  789. Activate the beancount mode. ATTENTION: This mode is made by myself.
  790. #+BEGIN_SRC emacs-lisp
  791. (unless (string-equal my/whoami "work_remote")
  792. (load "/home/marc/.emacs.d/user-local/elisp/beancount-mode.el") ; somehow load-path in use-package doesn't work
  793. (use-package beancount
  794. :load-path "/home/marc/.emacs.d/elisp"
  795. :defer t
  796. :mode ("\\.beancount$" . beancount-mode)
  797. :init
  798. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  799. (setenv "PATH"
  800. (concat
  801. "/opt/beancount/bin:"
  802. (getenv "PATH"))
  803. )
  804. :config
  805. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount")
  806. )
  807. )
  808. #+END_SRC
  809. Installing fava for reports is strongly recommended.
  810. #+BEGIN_SRC shell
  811. sudo su
  812. cd /opt
  813. python3 -m venv vava
  814. source ./vava/bin/activate
  815. pip3 install wheel
  816. pip3 install fava
  817. deactivate
  818. #+END_SRC
  819. Start fava with
  820. #+BEGIN_SRC shell
  821. fava my_file.beancount
  822. #+END_SRC
  823. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  824. Beancount-mode can start fava and open the URL right away.
  825. * Programming
  826. ** Common things
  827. List of plugins and settings which are shared between the language plugins
  828. Highlight whitespaces, tabs, empty lines.
  829. #+BEGIN_SRC emacs-lisp
  830. (use-package whitespace
  831. :demand t
  832. :ensure nil
  833. :diminish whitespace-mode;;mode shall be active, but not shown in mode line
  834. :init
  835. (dolist (hook '(prog-mode-hook
  836. text-mode-hook
  837. conf-mode-hook))
  838. (add-hook hook #'whitespace-mode))
  839. ;; :hook ;;not working in use-package 2.3
  840. ;; ((prog-mode . whitespace-turn-on)
  841. ;; (text-mode . whitespace-turn-on))
  842. :config
  843. (setq-default whitespace-style '(face empty tab trailing))
  844. )
  845. #+END_SRC
  846. Disable Eldoc, it interferes with flycheck
  847. #+BEGIN_SRC emacs-lisp
  848. (use-package eldoc
  849. :ensure nil
  850. :config
  851. (global-eldoc-mode -1)
  852. )
  853. #+END_SRC
  854. Colorize colors as text with their value
  855. #+BEGIN_SRC emacs-lisp
  856. (use-package rainbow-mode
  857. :ensure t
  858. :init
  859. (add-hook 'prog-mode-hook 'rainbow-mode t)
  860. :diminish rainbow-mode
  861. ;; :hook prog-mode ;; not working in use-package 2.3
  862. :config
  863. (setq-default rainbow-x-colors-major-mode-list '())
  864. )
  865. #+END_SRC
  866. Highlight parens etc. for improved readability
  867. #+BEGIN_SRC emacs-lisp
  868. (use-package rainbow-delimiters
  869. :ensure t
  870. :config
  871. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  872. )
  873. #+END_SRC
  874. Treat CamelCase combined words as individual words
  875. #+BEGIN_SRC emacs-lisp
  876. (use-package subword
  877. :diminish subword-mode
  878. :config
  879. (add-hook 'python-mode-hook 'subword-mode))
  880. #+END_SRC
  881. ** Smartparens
  882. Smartparens is a beast on its own, so it's worth having a dedicated section for it
  883. #+BEGIN_SRC emacs-lisp
  884. (use-package smartparens
  885. :ensure t
  886. :diminish smartparens-mode
  887. :config
  888. (add-hook 'prog-mode-hook 'smartparens-mode)
  889. )
  890. #+END_SRC
  891. ** Git
  892. *** Magit
  893. [[https://magit.vc/manual/magit/index.html][Link]]
  894. I want to do git stuff here, not in a separate terminal window
  895. Little crashcourse in magit:
  896. - magit-init to init a git project
  897. - magit-status (C-x g) to call the status window
  898. in status buffer:
  899. - s stage files
  900. - u unstage files
  901. - U unstage all files
  902. - a apply changed to staging
  903. - c c commit (type commit message, then C-c C-c to commit)
  904. - b b switch to another branch
  905. - P u git push
  906. - F u git pull
  907. #+BEGIN_SRC emacs-lisp
  908. (use-package magit
  909. :ensure t
  910. :defer t
  911. :init
  912. ;; set git-path in work environment
  913. (if (string-equal user-login-name "POH")
  914. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  915. )
  916. :defer t
  917. :bind (("C-x g" . magit-status))
  918. )
  919. #+END_SRC
  920. *** Git-gutter
  921. Display line changes in gutter based on git history. Enable it everywhere
  922. [[https://github.com/syohex/emacs-git-gutter][Source]]
  923. #+BEGIN_SRC emacs-lisp
  924. (use-package git-gutter
  925. :ensure t
  926. :defer t
  927. :config
  928. (global-git-gutter-mode t)
  929. :diminish git-gutter-mode
  930. )
  931. #+END_SRC
  932. Some persistent navigation in git-gutter is nice, so here's a hydra for it:
  933. #+BEGIN_SRC emacs-lisp
  934. (defhydra hydra-git-gutter (:body-pre (git-gutter-mode 1)
  935. :hint nil)
  936. "
  937. ^Git Gutter^ ^Git^ ^misc^
  938. ^──────────^────────^───^────────────────^────^──────────────────────────
  939. _j_: next hunk _s_tage hunk _q_uit
  940. _k_: previous hunk _r_evert hunk _g_ : call magit-status
  941. _h_: first hunk _p_opup hunk
  942. _l_: last hunk set start _R_evision
  943. ^^ ^^ ^^
  944. "
  945. ("j" git-gutter:next-hunk)
  946. ("k" git-gutter:previous-hunk)
  947. ("h" (progn (goto-char (point-min))
  948. (git-gutter:next-hunk 1)))
  949. ("l" (progn (goto-char (point-min))
  950. (git-gutter:previous-hunk 1)))
  951. ("s" git-gutter:stage-hunk)
  952. ("r" git-gutter:revert-hunk)
  953. ("p" git-gutter:popup-hunk)
  954. ("R" git-gutter:set-start-revision)
  955. ("q" nil :color blue)
  956. ("g" magit-status)
  957. )
  958. #+END_SRC
  959. *** Git-timemachine
  960. Time machine lets me step through the history of a file as recorded in git.
  961. [[https://github.com/pidu/git-timemachine][Source]]
  962. #+BEGIN_SRC emacs-lisp
  963. (use-package git-timemachine
  964. :ensure t
  965. :defer t
  966. )
  967. #+END_SRC
  968. ** Company Mode
  969. Complete Anything!
  970. Activate company and make it react nearly instantly
  971. #+BEGIN_SRC emacs-lisp
  972. (use-package company
  973. :ensure t
  974. :config
  975. (setq-default company-minimum-prefix-length 1
  976. company-tooltip-align-annotation t
  977. company-tooltop-flip-when-above t
  978. company-show-numbers t
  979. company-idle-delay 0.1)
  980. ;; (define-key company-active-map (kbd "TAB") #'company-complete-selection)
  981. ;; (define-key company-active-map (kbd "RET") nil)
  982. (company-tng-configure-default)
  983. )
  984. #+END_SRC
  985. For a nicer suggestion box: company-box ([[https://github.com/sebastiencs/company-box][Source]])
  986. It is only available for emacs 26 and higher.
  987. #+BEGIN_SRC emacs-lisp
  988. (when (> emacs-major-version 25)
  989. (use-package company-box
  990. :ensure t
  991. :init
  992. (add-hook 'company-mode-hook 'company-box-mode)))
  993. #+END_SRC
  994. *** Company backend hooks
  995. Backend configuration for python-mode
  996. Common backends are:
  997. - company-files: files & directory
  998. - company-keywords: keywords
  999. - company-capf: ??
  1000. - company-abbrev: ??
  1001. - company-dabbrev: dynamic abbreviations
  1002. - company-ispell: ??
  1003. 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.
  1004. #+BEGIN_SRC emacs-lisp
  1005. (defun company/python-mode-hook()
  1006. (message "company/python-mode-hook activated")
  1007. (set (make-local-variable 'company-backends)
  1008. '((company-ob-ipython company-jedi)))
  1009. ; '((company-jedi company-dabbrev-code company-yasnippet) company-capf company-files))
  1010. ; '((company-lsp company-yasnippet) company-capf company-dabbrev company-files))
  1011. (company-mode t)
  1012. )
  1013. #+END_SRC
  1014. I have yet to find the proper hook to call this.
  1015. #+BEGIN_SRC emacs-lisp
  1016. (defun company/ipython-mode-hook()
  1017. (message "company/ipython-mode-hook activated")
  1018. (set (make-local-variable 'company-backends)
  1019. '((company-ob-ipython)))
  1020. (company-mode t)
  1021. )
  1022. #+END_SRC
  1023. #+BEGIN_SRC emacs-lisp
  1024. (defun company/ess-mode-hook()
  1025. (message "company/ess-mode-hook activated")
  1026. ; (set (make-local-variable 'company-backends)
  1027. ; '((company-ess-backend company-R-args company-R-objects)))
  1028. (company-mode t))
  1029. #+END_SRC
  1030. (defun add-pcomplete-to-capf ()
  1031. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  1032. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  1033. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  1034. Backend for Orgmode
  1035. #+BEGIN_SRC emacs-lisp
  1036. (defun company/org-mode-hook()
  1037. (set (make-local-variable 'company-backends)
  1038. '(company-capf company-files))
  1039. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  1040. (message "company/org-mode-hook")
  1041. (company-mode t)
  1042. )
  1043. #+END_SRC
  1044. Backend configuration for lisp-mode
  1045. #+BEGIN_SRC emacs-lisp
  1046. (defun company/elisp-mode-hook()
  1047. (set (make-local-variable 'company-backends)
  1048. '((company-elisp company-dabbrev) company-capf company-files))
  1049. (company-mode t)
  1050. )
  1051. #+END_SRC
  1052. Backend configuration for beancount
  1053. #+BEGIN_SRC emacs-lisp
  1054. (defun company/beancount-mode-hook()
  1055. (set (make-local-variable 'company-backends)
  1056. '(company-beancount))
  1057. ; '((company-beancount company-dabbrev) company-capf company-files))
  1058. (company-mode t)
  1059. )
  1060. #+END_SRC
  1061. *** Misc Company packages
  1062. Addon to sort suggestions by usage
  1063. #+BEGIN_SRC emacs-lisp
  1064. (use-package company-statistics
  1065. :ensure t
  1066. :after company
  1067. :init
  1068. (setq company-statistics-file (concat PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  1069. :config
  1070. (company-statistics-mode 1)
  1071. )
  1072. #+END_SRC
  1073. Get a popup with documentation of the completion candidate.
  1074. For the popups the package pos-tip.el is used and automatically installed.
  1075. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  1076. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  1077. #+BEGIN_SRC emacs-lisp
  1078. (use-package company-quickhelp
  1079. :ensure t
  1080. :after company
  1081. :config
  1082. (company-quickhelp-mode 1)
  1083. )
  1084. #+END_SRC
  1085. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  1086. ** Flycheck
  1087. Show errors right away!
  1088. #+BEGIN_SRC emacs-lisp
  1089. (use-package flycheck
  1090. :ensure t
  1091. :diminish flycheck-mode " ✓"
  1092. :init
  1093. (setq flycheck-emacs-lisp-load-path 'inherit)
  1094. (add-hook 'after-init-hook #'global-flycheck-mode)
  1095. ; (add-hook 'python-mode-hook (lambda ()
  1096. ; (semantic-mode 1)
  1097. ; (flycheck-select-checker 'python-pylint)))
  1098. )
  1099. #+END_SRC
  1100. ** Projectile
  1101. Brings search functions on project level
  1102. #+BEGIN_SRC emacs-lisp
  1103. (use-package projectile
  1104. :ensure t
  1105. :defer t
  1106. :bind
  1107. (("C-c p p" . projectile-switch-project)
  1108. ("C-c p s s" . projectile-ag))
  1109. :init
  1110. (setq-default
  1111. projectile-cache-file (concat PATH_USER_LOCAL ".projectile-cache")
  1112. projectile-known-projects-file (concat PATH_USER_LOCAL ".projectile-bookmarks"))
  1113. :config
  1114. (projectile-mode t)
  1115. (setq-default
  1116. projectile-completion-system 'ivy
  1117. projectile-enable-caching t
  1118. projectile-mode-line '(:eval (projectile-project-name)))
  1119. )
  1120. #+END_SRC
  1121. ** Yasnippet
  1122. Snippets!
  1123. TODO: yas-minor-mode? what's that?
  1124. #+BEGIN_SRC emacs-lisp
  1125. (use-package yasnippet
  1126. :ensure t
  1127. :defer t
  1128. :diminish yas-minor-mode
  1129. :init
  1130. (setq yas-snippet-dirs (concat PATH_USER_GLOBAL "snippets"))
  1131. (yas-global-mode t)
  1132. :mode ("\\.yasnippet" . snippet-mode)
  1133. ; :config
  1134. ; (yas-reload-all) ;; ensure snippets are updated and available, necessary when not using global-mode
  1135. )
  1136. #+END_SRC
  1137. ** Lisp
  1138. #+BEGIN_SRC emacs-lisp
  1139. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  1140. #+END_SRC
  1141. Add some helpers to handle and understand macros
  1142. #+BEGIN_SRC emacs-lisp
  1143. (use-package macrostep
  1144. :ensure t
  1145. :defer t
  1146. :init
  1147. (define-key emacs-lisp-mode-map (kbd "C-c e") 'macrostep-expand)
  1148. (define-key emacs-lisp-mode-map (kbd "C-c c") 'macrostep-collapse))
  1149. #+END_SRC
  1150. ** Python
  1151. *** Intro
  1152. Systemwide following packages need to be installed:
  1153. - venv
  1154. - pylint / pylint3 (depending on default python version)
  1155. flycheck complains if no pylint is available and org tries to fontify python code natively.
  1156. The virtual environments need to have following modules installed:
  1157. - wheel (for some reason it isn't pulled by other packages, yet they complain about missing wheel)
  1158. - jedi
  1159. - epc
  1160. - pylint
  1161. *** Python-Mode
  1162. Automatically start python-mode when opening a .py-file.
  1163. Not sure if python.el is better than python-mode.el.
  1164. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  1165. 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]].
  1166. Also limit the completion backends to those which make sense in Python.
  1167. #+BEGIN_SRC emacs-lisp
  1168. (use-package python
  1169. :mode ("\\.py\\'" . python-mode)
  1170. :interpreter ("python" . python-mode)
  1171. :defer t
  1172. :init
  1173. (add-hook 'python-mode-hook (lambda ()
  1174. 'company/python-mode-hook
  1175. (semantic-mode t)
  1176. (flycheck-select-checker 'python-pylint)))
  1177. :config
  1178. (setq python-shell-completion-native-enable nil)
  1179. )
  1180. #+END_SRC
  1181. *** IPython-Mode
  1182. Not sure if this configuraton will interfere with Python-Mode
  1183. #+BEGIN_SRC emacs-lisp
  1184. (use-package ob-ipython
  1185. :ensure t
  1186. :defer t
  1187. :init
  1188. (add-hook 'ob-ipython-mode-hook (lambda ()
  1189. 'company/ipython-mode-hook
  1190. (semantic-mode t)
  1191. (flycheck-select-checker 'pylint))))
  1192. #+END_SRC
  1193. *** Python language server (inactive)
  1194. First test for lsp-python.
  1195. Source python language server: [[https://github.com/palantir/python-language-server][Link]]
  1196. Source lsp-mode:
  1197. Source lsp-python: [[https://github.com/emacs-lsp/lsp-python][Link]]
  1198. Source company-lsp: [[https://github.com/tigersoldier/company-lsp][Link]]
  1199. Source lsp-ui: [[https://github.com/emacs-lsp/lsp-ui][Link]]
  1200. BEGIN_SRC emacs-lisp
  1201. (use-package lsp-mode
  1202. :ensure t
  1203. :defer t)
  1204. (add-hook 'lsp-mode-hook #'(lambda ()
  1205. (customize-set-variable 'lsp-enable-eldoc nil)
  1206. (flycheck-mode 1)
  1207. (company-mode 1)))
  1208. (use-package lsp-ui
  1209. :ensure t
  1210. :defer t)
  1211. (use-package company-lsp
  1212. :ensure t
  1213. :defer t)
  1214. (use-package lsp-python
  1215. :ensure t
  1216. :after lsp-mode
  1217. :defer t
  1218. :init
  1219. (add-hook 'python-mode-hook #'(lambda ()
  1220. (lsp-python-enable)
  1221. (flycheck-select-checker 'python-flake8))))
  1222. END_SRC
  1223. *** Jedi / Company
  1224. Jedi is a backend for python autocompletion and needs to be installed on the server:
  1225. - pip install jedi
  1226. Code checks need to be installed, too:
  1227. - pip install flake8
  1228. If jedi doesn't work, it might be a problem with jediepcserver.py.
  1229. See [[https://github.com/tkf/emacs-jedi/issues/293][here]]
  1230. To fix it:
  1231. - Figure out which jediepcserver is running (first guess is melpa/jedi-core../jediepcserver.py
  1232. - Change some code:
  1233. #+BEGIN_SRC python
  1234. 100 return dict(
  1235. 101 # p.get_code(False) should do the job. But jedi-vim use replace.
  1236. 102 # So follow what jedi.vim does...
  1237. 103 - params=[p.get_code().replace('\n', '') for p in call_def.params],
  1238. 103 + params=[p.name for p in call_def.params],
  1239. 104 index=call-def.index,
  1240. 105 - call_name=call_def.call_name,
  1241. 105 + call_name=call_def.name,
  1242. 106 )
  1243. #+END_SRC
  1244. #+BEGIN_SRC emacs-lisp
  1245. (use-package company-jedi
  1246. :defer t
  1247. ;; :after company
  1248. :ensure t
  1249. :config
  1250. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  1251. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  1252. (add-hook 'python-mode-hook 'jedi:setup)
  1253. (setq jedi:complete-on-dot t)
  1254. (setq jedi:use-shortcuts t)
  1255. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  1256. )
  1257. #+END_SRC
  1258. *** Virtual Environments
  1259. A wrapper to handle virtual environments.
  1260. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  1261. TODO: automatically start an inferior python process or switch to it if already created
  1262. #+BEGIN_SRC emacs-lisp
  1263. (use-package pyvenv
  1264. :ensure t
  1265. :defer t
  1266. :init
  1267. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  1268. :config
  1269. (pyvenv-mode t)
  1270. (defun my/pyvenv-post-activate-hook()
  1271. (setq jedi:environment-root pyvenv-virtual-env)
  1272. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  1273. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  1274. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  1275. ;; default traceback, other option M-x jedi:toggle-log-traceback
  1276. ;; traceback is in jedi:pop-to-epc-buffer
  1277. (jedi:setup)
  1278. ;; (company/python-mode-hook)
  1279. (setq jedi:server-args '("--log-traceback"))
  1280. (message "pyvenv-post-activate-hook activated"))
  1281. (add-hook 'pyvenv-post-activate-hooks 'my/pyvenv-post-activate-hook)
  1282. )
  1283. #+END_SRC
  1284. I want Emacs to automatically start the proper virtual environment.
  1285. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  1286. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  1287. Depends on pyvenv
  1288. #+BEGIN_SRC emacs-lisp
  1289. (use-package auto-virtualenv
  1290. :ensure t
  1291. ;; :after pyvenv
  1292. :defer t
  1293. :init
  1294. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  1295. ;; activate on changing buffers
  1296. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  1297. ;; activate on focus in
  1298. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  1299. )
  1300. #+END_SRC
  1301. *** Visuals
  1302. Highlight indentations
  1303. #+BEGIN_SRC emacs-lisp
  1304. (use-package highlight-indentation
  1305. :init
  1306. (add-hook 'python-mode-hook 'highlight-indentation-current-column-mode)
  1307. (add-hook 'python-mode-hook 'highlight-indentation-mode)
  1308. :config
  1309. (set-face-background 'highlight-indentation-face "#454545")
  1310. (set-face-background 'highlight-indentation-current-column-face "#656565"))
  1311. #+END_SRC
  1312. BEGIN_SRC emacs-lisp
  1313. (use-package highlight-indent-guides
  1314. :ensure t
  1315. :defer t
  1316. :init
  1317. (add-hook 'python-mode-hook 'highlight-indent-guides-mode)
  1318. :config
  1319. (setq highlight-indent-guides-method 'column ;'character
  1320. ;highlight-indent-guides-character ?\|
  1321. highlight-indent-guides-auto-odd-face-perc 15
  1322. highlight-indent-guides-auto-even-face-perc 15
  1323. highlight-indent-guides-auto-character-face-perc 20))
  1324. END_SRC
  1325. *** Anaconda (inactive)
  1326. Anaconda test
  1327. #+BEGIN_SRC emacs-lisp
  1328. ; (use-package anaconda-mode
  1329. ; :ensure t
  1330. ; :defer t
  1331. ; :init
  1332. ; (add-hook 'python-mode-hook 'anaconda-mode)
  1333. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  1334. ; :config
  1335. ; (setq anaconda-eldoc-mode 1)
  1336. ; )
  1337. #+END_SRC
  1338. #+BEGIN_SRC emacs-lisp
  1339. ; (use-package company-anaconda
  1340. ; :ensure t
  1341. ; :defer t
  1342. ; :init
  1343. ; (defun my/company-anaconda-hook()
  1344. ; (add-to-list 'company-backends 'company-anaconda))
  1345. ; (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  1346. ; )
  1347. #+END_SRC
  1348. ** Latex
  1349. Requirements for Linux:
  1350. - Latex
  1351. - pdf-tools
  1352. The midnight mode hook is disabled for now, because CVs with my pic just look weird in this mode.
  1353. #+BEGIN_SRC emacs-lisp
  1354. (unless (string-equal my/whoami "work_remote")
  1355. (use-package pdf-tools
  1356. :ensure t
  1357. :defer t
  1358. :mode (("\\.pdf\\'" . pdf-view-mode))
  1359. :init
  1360. ; (add-hook 'pdf-view-mode-hook 'pdf-view-midnight-minor-mode)
  1361. :config
  1362. (pdf-tools-install)
  1363. (setq pdf-view-resize-factor 1.1 ;; more finegraned zoom
  1364. pdf-view-midnight-colors '("#c6c6c6" . "#363636")
  1365. TeX-view-program-selection '((output-pdf "pdf-tools"))
  1366. TeX-view-program-list '(("pdf-tools" "Tex-pdf-tools-sync-view")))
  1367. )
  1368. )
  1369. #+END_SRC
  1370. 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]]
  1371. Update 2018-03: It seems to work without this patch. I will keep it here in case something breaks again.
  1372. #+BEGIN_SRC
  1373. latex-preview-pane-update-p()
  1374. --- (doc-view-revert-buffer nil t)
  1375. +++ (revert-buffer-nil t 'preserve-modes)
  1376. #+END_SRC
  1377. After that M-x byte-compile-file
  1378. #+BEGIN_SRC emacs-lisp
  1379. (use-package latex-preview-pane
  1380. :ensure t
  1381. :defer t
  1382. :init
  1383. ;; one of these works
  1384. (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
  1385. (add-hook 'latex-mode-hook 'latex-preview-pane-mode)
  1386. (setq auto-mode-alist
  1387. (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
  1388. )
  1389. ;; necessary, because linum-mode isn't compatible and prints errors
  1390. (add-hook 'pdf-view-mode-hook (lambda () (linum-mode -1)))
  1391. #+END_SRC
  1392. ** Markdown
  1393. Major mode to edit markdown files.
  1394. For previews it needs markdown installed on the system.
  1395. For debian:
  1396. #+BEGIN_SRC shell
  1397. sudo apt install markdown
  1398. #+END_SRC
  1399. #+BEGIN_SRC emacs-lisp
  1400. (use-package markdown-mode
  1401. :ensure t
  1402. :defer t)
  1403. #+END_SRC
  1404. ** Hydra Flycheck
  1405. Flycheck is necessary, obviously
  1406. #+BEGIN_SRC emacs-lisp
  1407. (defhydra hydra-flycheck (:color blue)
  1408. "
  1409. ^
  1410. ^Flycheck^ ^Errors^ ^Checker^
  1411. ^────────^──────────^──────^────────────^───────^───────────
  1412. _q_ quit _<_ previous _?_ describe
  1413. _m_ manual _>_ next _d_ disable
  1414. _v_ verify setup _f_ check _s_ select
  1415. ^^ ^^ ^^
  1416. "
  1417. ("q" nil)
  1418. ("<" flycheck-previous-error :color red)
  1419. (">" flycheck-next-error :color red)
  1420. ("?" flycheck-describe-checker)
  1421. ("d" flycheck-disable-checker)
  1422. ("f" flycheck-buffer)
  1423. ("m" flycheck-manual)
  1424. ("s" flycheck-select-checker)
  1425. ("v" flycheck-verify-setup)
  1426. )
  1427. #+END_SRC
  1428. * Orchestrate the configuration
  1429. Some settings should be set for all systems, some need to be specific (like my job-emacs doesn't need development tools).
  1430. ** Common
  1431. ** Home
  1432. ** Work
  1433. I mainly only use org
  1434. ** Work, Hyper-V
  1435. For testing purproses I keep a working emacs in a debian on hyper-v. The demands here are different to the other work-emacs
  1436. * Finishing
  1437. Stuff which I want to run in the end
  1438. #+BEGIN_SRC emacs-lisp
  1439. (message (emacs-init-time))
  1440. #+END_SRC