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.

1887 lines
56 KiB

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