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.

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