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.

1707 lines
50 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. ** Tramp
  511. With tramp you can handle remote files like local files.
  512. Usage example:
  513. C-x C-f /ssh:name@server:/path
  514. #+BEGIN_SRC emacs-lisp
  515. (use-package tramp
  516. :ensure t
  517. )
  518. #+END_SRC
  519. ** misc
  520. Visual feedback when using regexp on the buffer
  521. #+BEGIN_SRC emacs-lisp
  522. (use-package visual-regexp
  523. :ensure t
  524. :defer t
  525. :bind (("C-c r s" . query-replace)
  526. ("C-c r R" . vr/replace)
  527. ("C-c r r" . vr/query-replace)
  528. ("C-c r m" . vr/mc-mark)))
  529. #+END_SRC
  530. Newline at the end of file
  531. #+BEGIN_SRC emacs-lisp
  532. (setq require-final-newline t)
  533. #+END_SRC
  534. Delete the selection with a keypress
  535. #+BEGIN_SRC emacs-lisp
  536. (delete-selection-mode t)
  537. #+END_SRC
  538. Remember the current location in a file
  539. #+BEGIN_SRC emacs-lisp
  540. (use-package saveplace
  541. :unless noninteractive
  542. :config
  543. (save-place-mode))
  544. #+END_SRC
  545. * Org Mode
  546. ** Installation
  547. 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.]]
  548. Added a hook to complete org functions, company-capf is necessary for this
  549. #+BEGIN_SRC emacs-lisp
  550. (use-package org
  551. :ensure org-plus-contrib
  552. :init
  553. (add-hook 'org-mode-hook 'company/org-mode-hook)
  554. )
  555. (add-hook 'org-mode-hook 'company/org-mode-hook)
  556. #+END_SRC
  557. 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:
  558. #+BEGIN_SRC shell
  559. var ORG_DIR=(let* ((org-v (cadr (split-string (org-version nil t) "@"))) (len (length org-v))) (substring org-v 1 (- len 2)))
  560. rm ${ORG_DIR}/*.elc
  561. echo 'cleaned .elc from package directory'
  562. #+END_SRC
  563. ** Setup
  564. *** Paths
  565. Paths need to be different for work and home
  566. #+BEGIN_SRC emacs-lisp
  567. (if (string-equal my/whoami "work_remote")
  568. (progn
  569. (defvar PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  570. (defvar PATH_ORG_JOURNAL "p:/Eigene Dateien/Notizen/Journal/")
  571. (defvar PATH_START "p:/Eigene Dateien/Notizen/"))
  572. )
  573. (if (string-equal my/whoami "home")
  574. (progn
  575. (setq org-default-notes-file "~/Archiv/Dokumente/Notizen/notes.org")
  576. (setq org-agenda-files
  577. (delq nil
  578. (mapcar (lambda (x) (and (file-exists-p x) x))
  579. '("~/Archiv/Dokumente/Agenda")))))
  580. (if (string-equal my/whoami "work_remote")
  581. (progn
  582. (setq org-default-notes-file (concat PATH_ORG_FILES "notes.org"))
  583. (setq org-agenda-files (list(concat PATH_ORG_FILES "notes.org")
  584. (concat PATH_ORG_FILES "projects.org")
  585. (concat PATH_ORG_FILES "todo.org"))))))
  586. (setq org-id-locations-file (concat PATH_USER_LOCAL ".org-id-locations"))
  587. #+END_SRC
  588. *** Settings
  589. 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.
  590. See the doc for speed keys by checking out the documentation for speed keys in Org mode.
  591. #+BEGIN_SRC emacs-lisp
  592. (setq org-use-speed-commands t)
  593. (setq org-image-actual-width 550)
  594. (setq org-highlight-latex-and-related '(latex script entities))
  595. #+END_SRC
  596. Hide emphasis markup (e.g. / ... / for italics, etc.)
  597. #+BEGIN_SRC emacs-lisp
  598. (setq org-hide-emphasis-markers t)
  599. #+END_SRC
  600. 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.
  601. 45 is a good column number to do that.
  602. #+BEGIN_SRC emacs-lisp
  603. (setq org-tags-column 45)
  604. #+END_SRC
  605. *** Org key bindings
  606. Set up some global key bindings that integrate with Org mode features
  607. #+BEGIN_SRC emacs-lisp
  608. (bind-key "C-c l" 'org-store-link)
  609. (bind-key "C-c c" 'org-capture)
  610. (bind-key "C-c a" 'org-agenda)
  611. #+END_SRC
  612. Org overwrites RET and C-j, so I need to disable the rebinds
  613. #+BEGIN_SRC emacs-lisp
  614. (define-key org-mode-map (kbd "RET") nil) ;;org-return
  615. (define-key org-mode-map (kbd "C-j") nil) ;;org-return-indent
  616. #+END_SRC
  617. *** Org agenda
  618. For a more detailed example [[https://github.com/sachac/.emacs.d/blob/83d21e473368adb1f63e582a6595450fcd0e787c/Sacha.org#org-agenda][see here]].
  619. Custom todo-keywords, depending on environment
  620. #+BEGIN_SRC emacs-lisp
  621. (pcase my/whoami
  622. ("work_remote")
  623. (setq org-todo-keywords
  624. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE")))
  625. )
  626. #+END_SRC
  627. Sort org agenda by deadline and priority
  628. #+BEGIN_SRC emacs-lisp
  629. (setq org-agenda-sorting-strategy
  630. (quote
  631. ((agenda deadline-up priority-down)
  632. (todo priority-down category-keep)
  633. (tags priority-down category-keep)
  634. (search category-keep)))
  635. )
  636. #+END_SRC
  637. Customize the org agenda
  638. #+BEGIN_SRC emacs-lisp
  639. (defun my-org-skip-subtree-if-priority (priority)
  640. "Skip an agenda subtree if it has a priority of PRIORITY.
  641. PRIORITY may be one of the characters ?A, ?B, or ?C."
  642. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  643. (pri-value (* 1000 (- org-lowest-priority priority)))
  644. (pri-current (org-get-priority (thing-at-point 'line t))))
  645. (if (= pri-value pri-current)
  646. subtree-end
  647. nil)))
  648. (setq org-agenda-custom-commands
  649. '(("c" "Simple agenda view"
  650. ((tags "PRIORITY=\"A\""
  651. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  652. (org-agenda-overriding-header "Hohe Priorität:")))
  653. (agenda ""
  654. ((org-agenda-span 7)
  655. (org-agenda-start-on-weekday nil)
  656. (org-agenda-overriding-header "Nächsten 7 Tage:")))
  657. (alltodo ""
  658. ((org-agenda-skip-function '(or (my-org-skip-subtree-if-priority ?A)
  659. (org-agenda-skip-if nil '(scheduled deadline))))
  660. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))
  661. )
  662. #+END_SRC
  663. *** Org capture
  664. Work specific org-capture-templates
  665. #+BEGIN_SRC emacs-lisp
  666. (pcase my/whoami
  667. ("work_remote"
  668. (setq org-capture-templates
  669. '(("t" "todo" entry (file (concat PATH_ORG_FILES "todo.org"))
  670. "** TODO %\\n%u\n%a\n")
  671. ("n" "note" entry (file org-default-notes-file))
  672. ("p" "project" entry (file (concat PATH_ORG_FILES "projects.org"))
  673. "** OPEN %?\n%u\n** Beschreibung\n** Zu erledigen\n*** \n** Verlauf\n***" :clock-in t :clock-resume t)
  674. ("u" "Unterbrechung" entry (file org-default-notes-file)
  675. "* Unterbrechnung durch %? :Unterbrechung:\n%t" :clock-in t :clock-resume t))))
  676. )
  677. #+END_SRC
  678. ** Org babel languages
  679. This code block is linux specific. Loading languages which aren't available seems to be a problem.
  680. New: Load languages on demand. I need to test if this works as intended.
  681. #+BEGIN_SRC emacs-lisp
  682. (defadvice org-babel-execute-src-block (around load-language nil activate)
  683. "Load language if needed"
  684. (let ((language (org-element-property :language (org-element-at-point))))
  685. (unless (cdr (assoc (intern language) org-babel-load-languages))
  686. (add-to-list 'org-babel-load-languages (cons (intern language) t))
  687. (org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages))
  688. ad-do-it))
  689. #+END_SRC
  690. BEGIN_SRC emacs-lisp
  691. (cond ((eq system-type 'gnu/linux)
  692. (org-babel-do-load-languages
  693. 'org-babel-load-languages
  694. '(
  695. (C . t)
  696. (calc . t)
  697. (java . t)
  698. (ipython . t)
  699. (js . t)
  700. (latex . t)
  701. (ledger . t)
  702. (beancount . t)
  703. (lisp . t)
  704. (python . t)
  705. (R . t)
  706. (ruby . t)
  707. (scheme . t)
  708. (shell . t)
  709. (sqlite . t)
  710. )
  711. ))
  712. )
  713. END_SRC
  714. #+BEGIN_SRC emacs-lisp
  715. (defun my-org-confirm-babel-evaluate (lang body)
  716. "Do not confirm evaluation for these languages."
  717. (not (or (string= lang "beancount")
  718. (string= lang "C")
  719. (string= lang "emacs-lisp")
  720. (string= lang "ipython")
  721. (string= lang "java")
  722. (string= lang "ledger")
  723. (string= lang "python")
  724. (string= lang "R")
  725. (string= lang "sqlite"))))
  726. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  727. #+END_SRC
  728. TODO: ess belongs to programming languages
  729. to start an ess instance C-c C-s
  730. #+BEGIN_SRC emacs-lisp
  731. (use-package ess
  732. :ensure t
  733. :init
  734. (add-hook 'ess-mode-hook 'company/ess-mode-hook)
  735. )
  736. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
  737. (add-hook 'org-mode-hook 'org-display-inline-images)
  738. #+END_SRC
  739. ** Org babel/source blocks
  740. 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
  741. 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
  742. #+BEGIN_SRC emacs-lisp
  743. (setq org-src-fontify-natively t
  744. org-src-window-setup 'current-window
  745. org-src-strip-leading-and-trailing-blank-lines t
  746. org-src-preserve-indentation nil ; these two lines respect the indentation of
  747. org-edit-src-content-indentation 0 ; the surrounding text around the source block
  748. org-src-tab-acts-natively t)
  749. #+END_SRC
  750. ** Org babel helper functions
  751. * Pandoc
  752. Convert between formats, like from org to html.
  753. Pandoc needs to be installed on the system
  754. #+BEGIN_EXAMPLE
  755. sudo apt install pandoc
  756. #+END_EXAMPLE
  757. Pandoc-mode is a minor mode to interact with pandoc
  758. #+BEGIN_SRC emacs-lisp
  759. (use-package pandoc-mode
  760. :ensure t
  761. :init
  762. (add-hook 'markdown-mode-hook 'pandoc-mode))
  763. #+END_SRC
  764. * Emails
  765. Currently following tools are required:
  766. - notmuch (edit, read, tag, delete emails)
  767. - isync /mbsync (fetch or sync emails)
  768. 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.
  769. TODO:
  770. - setup of mbsync on linux
  771. - setup of notmuch on linux
  772. - shell script for installation of isync and notmuch
  773. - more config for notmuch?
  774. - hydra for notmuch?
  775. - maybe org-notmuch?
  776. - some way to refresh the notmuch db before I run notmuch?
  777. #+BEGIN_SRC emacs-lisp
  778. (unless (string-equal my/whoami "work_remote")
  779. (use-package notmuch
  780. :defer t
  781. :ensure t
  782. )
  783. )
  784. #+END_SRC
  785. * Personal Finances
  786. After trying ledger, I chose beancount. It is closer to real bookkeeping and has stricter rules.
  787. Since there is no debian package, it is an option to install it via pip.
  788. I picked /opt for the installation path
  789. #+BEGIN_EXAMPLE
  790. sudo su
  791. cd /opt
  792. python3 -m venv beancount
  793. source ./beancount/bin/activate
  794. pip3 install wheel
  795. pip3 install beancount
  796. sleep 100
  797. echo "shell running!"
  798. deactivate
  799. #+END_EXAMPLE
  800. When using beancount, it will automatically pick the created virtual environment.
  801. Activate the beancount mode. ATTENTION: This mode is made by myself.
  802. #+BEGIN_SRC emacs-lisp
  803. (unless (string-equal my/whoami "work_remote")
  804. (load "/home/marc/.emacs.d/user-local/elisp/beancount-mode.el") ; somehow load-path in use-package doesn't work
  805. (use-package beancount
  806. :load-path "/home/marc/.emacs.d/elisp"
  807. :defer t
  808. :mode ("\\.beancount$" . beancount-mode)
  809. :init
  810. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  811. (setenv "PATH"
  812. (concat
  813. "/opt/beancount/bin:"
  814. (getenv "PATH"))
  815. )
  816. :config
  817. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount")
  818. )
  819. )
  820. #+END_SRC
  821. To support org-babel, check if it can find the symlink to ob-beancount.el.
  822. #+BEGIN_SRC shell
  823. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  824. beansym="$orgpath/ob-beancount.el"
  825. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  826. if [ -h "$beansym" ]
  827. then
  828. echo "$beansym found"
  829. elif [ -e "$bean" ]
  830. then
  831. echo "creating symlink"
  832. ln -s "$bean" "$beansym"
  833. else
  834. echo "$bean not found, symlink creation aborted"
  835. fi
  836. #+END_SRC
  837. #+RESULTS:
  838. : /home/marc/.emacs.d/elpa/org-plus-contrib-20180521/ob-beancount.el found
  839. Installing fava for reports is strongly recommended.
  840. #+BEGIN_EXAMPLE
  841. cd /opt
  842. python3 -m venv vava
  843. source ./vava/bin/activate
  844. pip3 install wheel
  845. pip3 install fava
  846. deactivate
  847. #+END_EXAMPLE
  848. Start fava with
  849. #+BEGIN_EXAMPLE
  850. fava my_file.beancount
  851. #+END_EXAMPLE
  852. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  853. Beancount-mode can start fava and open the URL right away.
  854. * Programming
  855. ** Common things
  856. List of plugins and settings which are shared between the language plugins
  857. Highlight whitespaces, tabs, empty lines.
  858. #+BEGIN_SRC emacs-lisp
  859. (use-package whitespace
  860. :demand t
  861. :ensure nil
  862. :diminish whitespace-mode;;mode shall be active, but not shown in mode line
  863. :init
  864. (dolist (hook '(prog-mode-hook
  865. text-mode-hook
  866. conf-mode-hook))
  867. (add-hook hook #'whitespace-mode))
  868. ;; :hook ;;not working in use-package 2.3
  869. ;; ((prog-mode . whitespace-turn-on)
  870. ;; (text-mode . whitespace-turn-on))
  871. :config
  872. (setq-default whitespace-style '(face empty tab trailing))
  873. )
  874. #+END_SRC
  875. Disable Eldoc, it interferes with flycheck
  876. #+BEGIN_SRC emacs-lisp
  877. (use-package eldoc
  878. :ensure nil
  879. :config
  880. (global-eldoc-mode -1)
  881. )
  882. #+END_SRC
  883. Colorize colors as text with their value
  884. #+BEGIN_SRC emacs-lisp
  885. (use-package rainbow-mode
  886. :ensure t
  887. :init
  888. (add-hook 'prog-mode-hook 'rainbow-mode t)
  889. :diminish rainbow-mode
  890. ;; :hook prog-mode ;; not working in use-package 2.3
  891. :config
  892. (setq-default rainbow-x-colors-major-mode-list '())
  893. )
  894. #+END_SRC
  895. Highlight parens etc. for improved readability
  896. #+BEGIN_SRC emacs-lisp
  897. (use-package rainbow-delimiters
  898. :ensure t
  899. :config
  900. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  901. )
  902. #+END_SRC
  903. Treat CamelCase combined words as individual words
  904. #+BEGIN_SRC emacs-lisp
  905. (use-package subword
  906. :diminish subword-mode
  907. :config
  908. (add-hook 'python-mode-hook 'subword-mode))
  909. #+END_SRC
  910. ** Smartparens
  911. Smartparens is a beast on its own, so it's worth having a dedicated section for it
  912. #+BEGIN_SRC emacs-lisp
  913. (use-package smartparens
  914. :ensure t
  915. :diminish smartparens-mode
  916. :config
  917. (add-hook 'prog-mode-hook 'smartparens-mode)
  918. )
  919. #+END_SRC
  920. ** Git
  921. *** Magit
  922. [[https://magit.vc/manual/magit/index.html][Link]]
  923. I want to do git stuff here, not in a separate terminal window
  924. Little crashcourse in magit:
  925. - magit-init to init a git project
  926. - magit-status (C-x g) to call the status window
  927. in status buffer:
  928. - s stage files
  929. - u unstage files
  930. - U unstage all files
  931. - a apply changed to staging
  932. - c c commit (type commit message, then C-c C-c to commit)
  933. - b b switch to another branch
  934. - P u git push
  935. - F u git pull
  936. #+BEGIN_SRC emacs-lisp
  937. (use-package magit
  938. :ensure t
  939. :defer t
  940. :init
  941. ;; set git-path in work environment
  942. (if (string-equal user-login-name "POH")
  943. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  944. )
  945. :defer t
  946. :bind (("C-x g" . magit-status))
  947. )
  948. #+END_SRC
  949. *** Git-gutter
  950. Display line changes in gutter based on git history. Enable it everywhere
  951. [[https://github.com/syohex/emacs-git-gutter][Source]]
  952. #+BEGIN_SRC emacs-lisp
  953. (use-package git-gutter
  954. :ensure t
  955. :defer t
  956. :config
  957. (global-git-gutter-mode t)
  958. :diminish git-gutter-mode
  959. )
  960. #+END_SRC
  961. Some persistent navigation in git-gutter is nice, so here's a hydra for it:
  962. #+BEGIN_SRC emacs-lisp
  963. (defhydra hydra-git-gutter (:body-pre (git-gutter-mode 1)
  964. :hint nil)
  965. "
  966. ^Git Gutter^ ^Git^ ^misc^
  967. ^──────────^────────^───^────────────────^────^──────────────────────────
  968. _j_: next hunk _s_tage hunk _q_uit
  969. _k_: previous hunk _r_evert hunk _g_ : call magit-status
  970. _h_: first hunk _p_opup hunk
  971. _l_: last hunk set start _R_evision
  972. ^^ ^^ ^^
  973. "
  974. ("j" git-gutter:next-hunk)
  975. ("k" git-gutter:previous-hunk)
  976. ("h" (progn (goto-char (point-min))
  977. (git-gutter:next-hunk 1)))
  978. ("l" (progn (goto-char (point-min))
  979. (git-gutter:previous-hunk 1)))
  980. ("s" git-gutter:stage-hunk)
  981. ("r" git-gutter:revert-hunk)
  982. ("p" git-gutter:popup-hunk)
  983. ("R" git-gutter:set-start-revision)
  984. ("q" nil :color blue)
  985. ("g" magit-status)
  986. )
  987. #+END_SRC
  988. *** Git-timemachine
  989. Time machine lets me step through the history of a file as recorded in git.
  990. [[https://github.com/pidu/git-timemachine][Source]]
  991. #+BEGIN_SRC emacs-lisp
  992. (use-package git-timemachine
  993. :ensure t
  994. :defer t
  995. )
  996. #+END_SRC
  997. ** Company Mode
  998. Complete Anything!
  999. Activate company and make it react nearly instantly
  1000. #+BEGIN_SRC emacs-lisp
  1001. (use-package company
  1002. :ensure t
  1003. :config
  1004. (setq-default company-minimum-prefix-length 1
  1005. company-tooltip-align-annotation t
  1006. company-tooltop-flip-when-above t
  1007. company-show-numbers t
  1008. company-idle-delay 0.1)
  1009. ;; (define-key company-active-map (kbd "TAB") #'company-complete-selection)
  1010. ;; (define-key company-active-map (kbd "RET") nil)
  1011. (company-tng-configure-default)
  1012. )
  1013. #+END_SRC
  1014. For a nicer suggestion box: company-box ([[https://github.com/sebastiencs/company-box][Source]])
  1015. It is only available for emacs 26 and higher.
  1016. #+BEGIN_SRC emacs-lisp
  1017. (when (> emacs-major-version 25)
  1018. (use-package company-box
  1019. :ensure t
  1020. :init
  1021. (add-hook 'company-mode-hook 'company-box-mode)))
  1022. #+END_SRC
  1023. *** Company backend hooks
  1024. Backend configuration for python-mode
  1025. Common backends are:
  1026. - company-files: files & directory
  1027. - company-keywords: keywords
  1028. - company-capf: ??
  1029. - company-abbrev: ??
  1030. - company-dabbrev: dynamic abbreviations
  1031. - company-ispell: ??
  1032. 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.
  1033. #+BEGIN_SRC emacs-lisp
  1034. (defun company/python-mode-hook()
  1035. (message "company/python-mode-hook activated")
  1036. (set (make-local-variable 'company-backends)
  1037. '((company-ob-ipython company-jedi)))
  1038. ; '((company-jedi company-dabbrev-code company-yasnippet) company-capf company-files))
  1039. ; '((company-lsp company-yasnippet) company-capf company-dabbrev company-files))
  1040. (company-mode t)
  1041. )
  1042. #+END_SRC
  1043. I have yet to find the proper hook to call this.
  1044. #+BEGIN_SRC emacs-lisp
  1045. (defun company/ipython-mode-hook()
  1046. (message "company/ipython-mode-hook activated")
  1047. (set (make-local-variable 'company-backends)
  1048. '((company-ob-ipython)))
  1049. (company-mode t)
  1050. )
  1051. #+END_SRC
  1052. #+BEGIN_SRC emacs-lisp
  1053. (defun company/ess-mode-hook()
  1054. (message "company/ess-mode-hook activated")
  1055. ; (set (make-local-variable 'company-backends)
  1056. ; '((company-ess-backend company-R-args company-R-objects)))
  1057. (company-mode t))
  1058. #+END_SRC
  1059. (defun add-pcomplete-to-capf ()
  1060. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  1061. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  1062. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  1063. Backend for Orgmode
  1064. #+BEGIN_SRC emacs-lisp
  1065. (defun company/org-mode-hook()
  1066. (set (make-local-variable 'company-backends)
  1067. '(company-capf company-files))
  1068. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  1069. (message "company/org-mode-hook")
  1070. (company-mode t)
  1071. )
  1072. #+END_SRC
  1073. Backend configuration for lisp-mode
  1074. #+BEGIN_SRC emacs-lisp
  1075. (defun company/elisp-mode-hook()
  1076. (set (make-local-variable 'company-backends)
  1077. '((company-elisp company-dabbrev) company-capf company-files))
  1078. (company-mode t)
  1079. )
  1080. #+END_SRC
  1081. Backend configuration for beancount
  1082. #+BEGIN_SRC emacs-lisp
  1083. (defun company/beancount-mode-hook()
  1084. (set (make-local-variable 'company-backends)
  1085. '(company-beancount))
  1086. ; '((company-beancount company-dabbrev) company-capf company-files))
  1087. (company-mode t)
  1088. )
  1089. #+END_SRC
  1090. *** Misc Company packages
  1091. Addon to sort suggestions by usage
  1092. #+BEGIN_SRC emacs-lisp
  1093. (use-package company-statistics
  1094. :ensure t
  1095. :after company
  1096. :init
  1097. (setq company-statistics-file (concat PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  1098. :config
  1099. (company-statistics-mode 1)
  1100. )
  1101. #+END_SRC
  1102. Get a popup with documentation of the completion candidate.
  1103. For the popups the package pos-tip.el is used and automatically installed.
  1104. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  1105. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  1106. #+BEGIN_SRC emacs-lisp
  1107. (use-package company-quickhelp
  1108. :ensure t
  1109. :after company
  1110. :config
  1111. (company-quickhelp-mode 1)
  1112. )
  1113. #+END_SRC
  1114. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  1115. ** Flycheck
  1116. Show errors right away!
  1117. #+BEGIN_SRC emacs-lisp
  1118. (use-package flycheck
  1119. :ensure t
  1120. :diminish flycheck-mode " ✓"
  1121. :init
  1122. (setq flycheck-emacs-lisp-load-path 'inherit)
  1123. (add-hook 'after-init-hook #'global-flycheck-mode)
  1124. ; (add-hook 'python-mode-hook (lambda ()
  1125. ; (semantic-mode 1)
  1126. ; (flycheck-select-checker 'python-pylint)))
  1127. )
  1128. #+END_SRC
  1129. ** Projectile
  1130. Brings search functions on project level
  1131. #+BEGIN_SRC emacs-lisp
  1132. (use-package projectile
  1133. :ensure t
  1134. :defer t
  1135. :bind
  1136. (("C-c p p" . projectile-switch-project)
  1137. ("C-c p s s" . projectile-ag))
  1138. :init
  1139. (setq-default
  1140. projectile-cache-file (concat PATH_USER_LOCAL ".projectile-cache")
  1141. projectile-known-projects-file (concat PATH_USER_LOCAL ".projectile-bookmarks"))
  1142. :config
  1143. (projectile-mode t)
  1144. (setq-default
  1145. projectile-completion-system 'ivy
  1146. projectile-enable-caching t
  1147. projectile-mode-line '(:eval (projectile-project-name)))
  1148. )
  1149. #+END_SRC
  1150. ** Yasnippet
  1151. Snippets!
  1152. TODO: yas-minor-mode? what's that?
  1153. #+BEGIN_SRC emacs-lisp
  1154. (use-package yasnippet
  1155. :ensure t
  1156. :defer t
  1157. :diminish yas-minor-mode
  1158. :init
  1159. (setq yas-snippet-dirs (concat PATH_USER_GLOBAL "snippets"))
  1160. (yas-global-mode t)
  1161. :mode ("\\.yasnippet" . snippet-mode)
  1162. ; :config
  1163. ; (yas-reload-all) ;; ensure snippets are updated and available, necessary when not using global-mode
  1164. )
  1165. #+END_SRC
  1166. ** Lisp
  1167. #+BEGIN_SRC emacs-lisp
  1168. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  1169. #+END_SRC
  1170. Add some helpers to handle and understand macros
  1171. #+BEGIN_SRC emacs-lisp
  1172. (use-package macrostep
  1173. :ensure t
  1174. :defer t
  1175. :init
  1176. (define-key emacs-lisp-mode-map (kbd "C-c e") 'macrostep-expand)
  1177. (define-key emacs-lisp-mode-map (kbd "C-c c") 'macrostep-collapse))
  1178. #+END_SRC
  1179. ** Python
  1180. *** Intro
  1181. Systemwide following packages need to be installed:
  1182. - venv
  1183. - pylint / pylint3 (depending on default python version)
  1184. flycheck complains if no pylint is available and org tries to fontify python code natively.
  1185. The virtual environments need to have following modules installed:
  1186. - wheel (for some reason it isn't pulled by other packages, yet they complain about missing wheel)
  1187. - jedi
  1188. - epc
  1189. - pylint
  1190. *** Python-Mode
  1191. Automatically start python-mode when opening a .py-file.
  1192. Not sure if python.el is better than python-mode.el.
  1193. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  1194. 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]].
  1195. Also limit the completion backends to those which make sense in Python.
  1196. #+BEGIN_SRC emacs-lisp
  1197. (use-package python
  1198. :mode ("\\.py\\'" . python-mode)
  1199. :interpreter ("python" . python-mode)
  1200. :defer t
  1201. :init
  1202. (add-hook 'python-mode-hook (lambda ()
  1203. 'company/python-mode-hook
  1204. (semantic-mode t)
  1205. (flycheck-select-checker 'python-pylint)))
  1206. :config
  1207. (setq python-shell-completion-native-enable nil)
  1208. )
  1209. #+END_SRC
  1210. *** IPython-Mode
  1211. Not sure if this configuraton will interfere with Python-Mode
  1212. #+BEGIN_SRC emacs-lisp
  1213. (use-package ob-ipython
  1214. :ensure t
  1215. :defer t
  1216. :init
  1217. (add-hook 'ob-ipython-mode-hook (lambda ()
  1218. 'company/ipython-mode-hook
  1219. (semantic-mode t)
  1220. (flycheck-select-checker 'pylint))))
  1221. #+END_SRC
  1222. *** Python language server (inactive)
  1223. First test for lsp-python.
  1224. Source python language server: [[https://github.com/palantir/python-language-server][Link]]
  1225. Source lsp-mode:
  1226. Source lsp-python: [[https://github.com/emacs-lsp/lsp-python][Link]]
  1227. Source company-lsp: [[https://github.com/tigersoldier/company-lsp][Link]]
  1228. Source lsp-ui: [[https://github.com/emacs-lsp/lsp-ui][Link]]
  1229. BEGIN_SRC emacs-lisp
  1230. (use-package lsp-mode
  1231. :ensure t
  1232. :defer t)
  1233. (add-hook 'lsp-mode-hook #'(lambda ()
  1234. (customize-set-variable 'lsp-enable-eldoc nil)
  1235. (flycheck-mode 1)
  1236. (company-mode 1)))
  1237. (use-package lsp-ui
  1238. :ensure t
  1239. :defer t)
  1240. (use-package company-lsp
  1241. :ensure t
  1242. :defer t)
  1243. (use-package lsp-python
  1244. :ensure t
  1245. :after lsp-mode
  1246. :defer t
  1247. :init
  1248. (add-hook 'python-mode-hook #'(lambda ()
  1249. (lsp-python-enable)
  1250. (flycheck-select-checker 'python-flake8))))
  1251. END_SRC
  1252. *** Jedi / Company
  1253. Jedi is a backend for python autocompletion and needs to be installed on the server:
  1254. - pip install jedi
  1255. Code checks need to be installed, too:
  1256. - pip install flake8
  1257. If jedi doesn't work, it might be a problem with jediepcserver.py.
  1258. See [[https://github.com/tkf/emacs-jedi/issues/293][here]]
  1259. To fix it:
  1260. - Figure out which jediepcserver is running (first guess is melpa/jedi-core../jediepcserver.py
  1261. - Change some code:
  1262. #+BEGIN_SRC python
  1263. 100 return dict(
  1264. 101 # p.get_code(False) should do the job. But jedi-vim use replace.
  1265. 102 # So follow what jedi.vim does...
  1266. 103 - params=[p.get_code().replace('\n', '') for p in call_def.params],
  1267. 103 + params=[p.name for p in call_def.params],
  1268. 104 index=call-def.index,
  1269. 105 - call_name=call_def.call_name,
  1270. 105 + call_name=call_def.name,
  1271. 106 )
  1272. #+END_SRC
  1273. #+BEGIN_SRC emacs-lisp
  1274. (use-package company-jedi
  1275. :defer t
  1276. ;; :after company
  1277. :ensure t
  1278. :config
  1279. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  1280. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  1281. (add-hook 'python-mode-hook 'jedi:setup)
  1282. (setq jedi:complete-on-dot t)
  1283. (setq jedi:use-shortcuts t)
  1284. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  1285. )
  1286. #+END_SRC
  1287. *** Virtual Environments
  1288. A wrapper to handle virtual environments.
  1289. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  1290. TODO: automatically start an inferior python process or switch to it if already created
  1291. #+BEGIN_SRC emacs-lisp
  1292. (use-package pyvenv
  1293. :ensure t
  1294. :defer t
  1295. :init
  1296. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  1297. :config
  1298. (pyvenv-mode t)
  1299. (defun my/pyvenv-post-activate-hook()
  1300. (setq jedi:environment-root pyvenv-virtual-env)
  1301. (setq jedi:environment-virtualenv pyvenv-virtual-env)
  1302. (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  1303. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  1304. ;; default traceback, other option M-x jedi:toggle-log-traceback
  1305. ;; traceback is in jedi:pop-to-epc-buffer
  1306. (jedi:setup)
  1307. ;; (company/python-mode-hook)
  1308. (setq jedi:server-args '("--log-traceback"))
  1309. (message "pyvenv-post-activate-hook activated"))
  1310. (add-hook 'pyvenv-post-activate-hooks 'my/pyvenv-post-activate-hook)
  1311. )
  1312. #+END_SRC
  1313. I want Emacs to automatically start the proper virtual environment.
  1314. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  1315. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  1316. Depends on pyvenv
  1317. #+BEGIN_SRC emacs-lisp
  1318. (use-package auto-virtualenv
  1319. :ensure t
  1320. ;; :after pyvenv
  1321. :defer t
  1322. :init
  1323. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  1324. ;; activate on changing buffers
  1325. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  1326. ;; activate on focus in
  1327. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  1328. )
  1329. #+END_SRC
  1330. *** Visuals
  1331. Highlight indentations
  1332. #+BEGIN_SRC emacs-lisp
  1333. (use-package highlight-indentation
  1334. :init
  1335. (add-hook 'python-mode-hook 'highlight-indentation-current-column-mode)
  1336. (add-hook 'python-mode-hook 'highlight-indentation-mode)
  1337. :config
  1338. (set-face-background 'highlight-indentation-face "#454545")
  1339. (set-face-background 'highlight-indentation-current-column-face "#656565"))
  1340. #+END_SRC
  1341. BEGIN_SRC emacs-lisp
  1342. (use-package highlight-indent-guides
  1343. :ensure t
  1344. :defer t
  1345. :init
  1346. (add-hook 'python-mode-hook 'highlight-indent-guides-mode)
  1347. :config
  1348. (setq highlight-indent-guides-method 'column ;'character
  1349. ;highlight-indent-guides-character ?\|
  1350. highlight-indent-guides-auto-odd-face-perc 15
  1351. highlight-indent-guides-auto-even-face-perc 15
  1352. highlight-indent-guides-auto-character-face-perc 20))
  1353. END_SRC
  1354. *** Anaconda (inactive)
  1355. Anaconda test
  1356. #+BEGIN_SRC emacs-lisp
  1357. ; (use-package anaconda-mode
  1358. ; :ensure t
  1359. ; :defer t
  1360. ; :init
  1361. ; (add-hook 'python-mode-hook 'anaconda-mode)
  1362. ;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode)
  1363. ; :config
  1364. ; (setq anaconda-eldoc-mode 1)
  1365. ; )
  1366. #+END_SRC
  1367. #+BEGIN_SRC emacs-lisp
  1368. ; (use-package company-anaconda
  1369. ; :ensure t
  1370. ; :defer t
  1371. ; :init
  1372. ; (defun my/company-anaconda-hook()
  1373. ; (add-to-list 'company-backends 'company-anaconda))
  1374. ; (add-hook 'python-mode-hook 'my/company-anaconda-hook)
  1375. ; )
  1376. #+END_SRC
  1377. ** Latex
  1378. Requirements for Linux:
  1379. - Latex
  1380. - pdf-tools
  1381. The midnight mode hook is disabled for now, because CVs with my pic just look weird in this mode.
  1382. #+BEGIN_SRC emacs-lisp
  1383. (unless (string-equal my/whoami "work_remote")
  1384. (use-package pdf-tools
  1385. :ensure t
  1386. :defer t
  1387. :mode (("\\.pdf\\'" . pdf-view-mode))
  1388. :init
  1389. ; (add-hook 'pdf-view-mode-hook 'pdf-view-midnight-minor-mode)
  1390. :config
  1391. (pdf-tools-install)
  1392. (setq pdf-view-resize-factor 1.1 ;; more finegraned zoom
  1393. pdf-view-midnight-colors '("#c6c6c6" . "#363636")
  1394. TeX-view-program-selection '((output-pdf "pdf-tools"))
  1395. TeX-view-program-list '(("pdf-tools" "Tex-pdf-tools-sync-view")))
  1396. )
  1397. )
  1398. #+END_SRC
  1399. 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]]
  1400. Update 2018-03: It seems to work without this patch. I will keep it here in case something breaks again.
  1401. #+BEGIN_SRC
  1402. latex-preview-pane-update-p()
  1403. --- (doc-view-revert-buffer nil t)
  1404. +++ (revert-buffer-nil t 'preserve-modes)
  1405. #+END_SRC
  1406. After that M-x byte-compile-file
  1407. #+BEGIN_SRC emacs-lisp
  1408. (use-package latex-preview-pane
  1409. :ensure t
  1410. :defer t
  1411. :init
  1412. ;; one of these works
  1413. (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
  1414. (add-hook 'latex-mode-hook 'latex-preview-pane-mode)
  1415. (setq auto-mode-alist
  1416. (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
  1417. )
  1418. ;; necessary, because linum-mode isn't compatible and prints errors
  1419. (add-hook 'pdf-view-mode-hook (lambda () (linum-mode -1)))
  1420. #+END_SRC
  1421. ** Markdown
  1422. Major mode to edit markdown files.
  1423. For previews it needs markdown installed on the system.
  1424. For debian:
  1425. #+BEGIN_EXAMPLE
  1426. sudo apt install markdown
  1427. #+END_EXAMPLE
  1428. #+BEGIN_SRC emacs-lisp
  1429. (use-package markdown-mode
  1430. :ensure t
  1431. :defer t)
  1432. #+END_SRC
  1433. ** Hydra Flycheck
  1434. Flycheck is necessary, obviously
  1435. #+BEGIN_SRC emacs-lisp
  1436. (defhydra hydra-flycheck (:color blue)
  1437. "
  1438. ^
  1439. ^Flycheck^ ^Errors^ ^Checker^
  1440. ^────────^──────────^──────^────────────^───────^───────────
  1441. _q_ quit _<_ previous _?_ describe
  1442. _m_ manual _>_ next _d_ disable
  1443. _v_ verify setup _f_ check _s_ select
  1444. ^^ ^^ ^^
  1445. "
  1446. ("q" nil)
  1447. ("<" flycheck-previous-error :color red)
  1448. (">" flycheck-next-error :color red)
  1449. ("?" flycheck-describe-checker)
  1450. ("d" flycheck-disable-checker)
  1451. ("f" flycheck-buffer)
  1452. ("m" flycheck-manual)
  1453. ("s" flycheck-select-checker)
  1454. ("v" flycheck-verify-setup)
  1455. )
  1456. #+END_SRC
  1457. * Orchestrate the configuration
  1458. Some settings should be set for all systems, some need to be specific (like my job-emacs doesn't need development tools).
  1459. ** Common
  1460. ** Home
  1461. ** Work
  1462. I mainly only use org
  1463. ** Work, Hyper-V
  1464. For testing purproses I keep a working emacs in a debian on hyper-v. The demands here are different to the other work-emacs
  1465. * Finishing
  1466. Stuff which I want to run in the end
  1467. #+BEGIN_SRC emacs-lisp
  1468. (message (emacs-init-time))
  1469. #+END_SRC