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.

1875 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))
  1138. ; '((company-jedi company-yasnippet company-dabbrev-code) company-dabbrev))
  1139. ; '((company-ob-ipython company-lsp)))
  1140. ; '((company-ob-ipython company-jedi)))
  1141. ; '((company-jedi company-dabbrev-code company-yasnippet) company-capf company-files))
  1142. ; '((company-lsp company-yasnippet) company-capf company-dabbrev company-files))
  1143. (company-mode t)
  1144. )
  1145. #+END_SRC
  1146. I have yet to find the proper hook to call this.
  1147. #+BEGIN_SRC emacs-lisp
  1148. (defun company/ipython-mode-hook()
  1149. (message "company/ipython-mode-hook activated")
  1150. (set (make-local-variable 'company-backends)
  1151. '((company-ob-ipython)))
  1152. (company-mode t)
  1153. )
  1154. #+END_SRC
  1155. #+BEGIN_SRC emacs-lisp
  1156. (defun company/ess-mode-hook()
  1157. (message "company/ess-mode-hook activated")
  1158. ; (set (make-local-variable 'company-backends)
  1159. ; '((company-ess-backend company-R-args company-R-objects)))
  1160. (company-mode t))
  1161. #+END_SRC
  1162. (defun add-pcomplete-to-capf ()
  1163. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  1164. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  1165. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  1166. Backend for Orgmode
  1167. #+BEGIN_SRC emacs-lisp
  1168. (defun company/org-mode-hook()
  1169. (set (make-local-variable 'company-backends)
  1170. '(company-capf company-files))
  1171. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  1172. (message "company/org-mode-hook")
  1173. (company-mode t)
  1174. )
  1175. #+END_SRC
  1176. Backend configuration for lisp-mode
  1177. #+BEGIN_SRC emacs-lisp
  1178. (defun company/elisp-mode-hook()
  1179. (set (make-local-variable 'company-backends)
  1180. '((company-elisp company-dabbrev) company-capf company-files))
  1181. (company-mode t)
  1182. )
  1183. #+END_SRC
  1184. Backend configuration for beancount
  1185. #+BEGIN_SRC emacs-lisp
  1186. (defun company/beancount-mode-hook()
  1187. (set (make-local-variable 'company-backends)
  1188. '(company-beancount))
  1189. ; '((company-beancount company-dabbrev) company-capf company-files))
  1190. (company-mode t)
  1191. )
  1192. #+END_SRC
  1193. *** Misc Company packages
  1194. Addon to sort suggestions by usage
  1195. #+BEGIN_SRC emacs-lisp
  1196. (use-package company-statistics
  1197. :ensure t
  1198. :after company
  1199. :init
  1200. (setq company-statistics-file (concat PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  1201. :config
  1202. (company-statistics-mode 1)
  1203. )
  1204. #+END_SRC
  1205. Get a popup with documentation of the completion candidate.
  1206. For the popups the package pos-tip.el is used and automatically installed.
  1207. [[https://github.com/expez/company-quickhelp][Company Quickhelp]]
  1208. [[https://www.emacswiki.org/emacs/PosTip][See here for Pos-Tip details]]
  1209. #+BEGIN_SRC emacs-lisp
  1210. (use-package company-quickhelp
  1211. :ensure t
  1212. :after company
  1213. :config
  1214. (company-quickhelp-mode 1)
  1215. )
  1216. #+END_SRC
  1217. Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's a dictionary based on major modes, plus it has Yasnippet integration.
  1218. ** Flycheck
  1219. Show errors right away!
  1220. #+BEGIN_SRC emacs-lisp
  1221. (use-package flycheck
  1222. :ensure t
  1223. :diminish flycheck-mode " ✓"
  1224. :init
  1225. (setq flycheck-emacs-lisp-load-path 'inherit)
  1226. (add-hook 'after-init-hook #'global-flycheck-mode)
  1227. ; (add-hook 'python-mode-hook (lambda ()
  1228. ; (semantic-mode 1)
  1229. ; (flycheck-select-checker 'python-pylint)))
  1230. )
  1231. #+END_SRC
  1232. ** Projectile
  1233. Brings search functions on project level
  1234. #+BEGIN_SRC emacs-lisp
  1235. (use-package projectile
  1236. :ensure t
  1237. :defer t
  1238. :bind
  1239. (("C-c p p" . projectile-switch-project)
  1240. ("C-c p s s" . projectile-ag))
  1241. :init
  1242. (setq-default
  1243. projectile-cache-file (concat PATH_USER_LOCAL ".projectile-cache")
  1244. projectile-known-projects-file (concat PATH_USER_LOCAL ".projectile-bookmarks"))
  1245. :config
  1246. (projectile-mode t)
  1247. (setq-default
  1248. projectile-completion-system 'ivy
  1249. projectile-enable-caching t
  1250. projectile-mode-line '(:eval (projectile-project-name)))
  1251. )
  1252. #+END_SRC
  1253. ** Yasnippet
  1254. Snippets!
  1255. TODO: yas-minor-mode? what's that?
  1256. #+BEGIN_SRC emacs-lisp
  1257. (use-package yasnippet
  1258. :ensure t
  1259. :defer t
  1260. :diminish yas-minor-mode
  1261. :init
  1262. (yas-global-mode t)
  1263. (setq yas-snippet-dirs (concat PATH_USER_GLOBAL "snippets"))
  1264. :mode ("\\.yasnippet" . snippet-mode)
  1265. :config
  1266. (yas-reload-all) ;; ensure snippets are updated and available, necessary when not using global-mode
  1267. )
  1268. #+END_SRC
  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-site
  1294. :ensure ess
  1295. :defer t
  1296. :mode (("\\.R\\'" . r-mode))
  1297. :init (require 'ess-site)
  1298. :config
  1299. (use-package ess-R-data-view :ensure t)
  1300. (use-package ess-smart-equals :ensure t)
  1301. (use-package ess-smart-underscore :ensure t)
  1302. (use-package ess-view :ensure t)
  1303. (setq ess-use-flymake nil
  1304. ess-use-ido nil ;;else ESS will use ido whenever possible
  1305. ess-eval-visibly 'nowait
  1306. ess-ask-for-ess-directory nil
  1307. ess-local-process-name "R"
  1308. ess-use-tracebug t
  1309. ess-describe-at-point-method 'tooltip))) ; 'tooltip or nil (buffer)
  1310. )
  1311. #+END_SRC
  1312. ** Lua
  1313. #+BEGIN_SRC emacs-lisp
  1314. (use-package lua-mode
  1315. :defer t
  1316. :ensure t
  1317. :mode "\\.lua\\'"
  1318. :config
  1319. (setq lua-indent-level 2))
  1320. #+END_SRC
  1321. ** Python
  1322. *** Intro
  1323. Systemwide following packages need to be installed:
  1324. - venv
  1325. - pylint / pylint3 (depending on default python version)
  1326. flycheck complains if no pylint is available and org tries to fontify python code natively.
  1327. The virtual environments need to have following modules installed:
  1328. - wheel (for some reason it isn't pulled by other packages, yet they complain about missing wheel)
  1329. - jedi
  1330. - epc
  1331. - pylint
  1332. *** Python-Mode
  1333. Automatically start python-mode when opening a .py-file.
  1334. Not sure if python.el is better than python-mode.el.
  1335. See [[https://github.com/jorgenschaefer/elpy/issues/887][here]] for info about ~python-shell-completion-native-enable~.
  1336. 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]].
  1337. Also limit the completion backends to those which make sense in Python.
  1338. #+BEGIN_SRC emacs-lisp
  1339. (use-package python
  1340. :mode ("\\.py\\'" . python-mode)
  1341. :interpreter ("python" . python-mode)
  1342. :defer t
  1343. :after company-mode
  1344. :init
  1345. (message "python mode init")
  1346. (add-hook 'python-mode-hook (lambda ()
  1347. (company/python-mode-hook)
  1348. (semantic-mode t)
  1349. (flycheck-select-checker 'python-pylint)))
  1350. :config
  1351. (setq python-shell-completion-native-enable nil)
  1352. )
  1353. #+END_SRC
  1354. *** IPython-Mode
  1355. Not sure if this configuraton will interfere with Python-Mode
  1356. #+BEGIN_SRC emacs-lisp
  1357. (use-package ob-ipython
  1358. :ensure t
  1359. :defer t
  1360. :init
  1361. (add-hook 'ob-ipython-mode-hook (lambda ()
  1362. 'company/ipython-mode-hook
  1363. (semantic-mode t)
  1364. (flycheck-select-checker 'pylint))))
  1365. #+END_SRC
  1366. *** Jedi / Company
  1367. Jedi is a backend for python autocompletion and needs to be installed on the server:
  1368. - pip install jedi
  1369. Code checks need to be installed, too:
  1370. - pip install flake8
  1371. If jedi doesn't work, it might be a problem with jediepcserver.py.
  1372. See [[https://github.com/tkf/emacs-jedi/issues/293][here]]
  1373. To fix it:
  1374. - Figure out which jediepcserver is running (first guess is melpa/jedi-core../jediepcserver.py
  1375. - Change some code:
  1376. #+BEGIN_SRC python
  1377. 100 return dict(
  1378. 101 # p.get_code(False) should do the job. But jedi-vim use replace.
  1379. 102 # So follow what jedi.vim does...
  1380. 103 - params=[p.get_code().replace('\n', '') for p in call_def.params],
  1381. 103 + params=[p.name for p in call_def.params],
  1382. 104 index=call-def.index,
  1383. 105 - call_name=call_def.call_name,
  1384. 105 + call_name=call_def.name,
  1385. 106 )
  1386. #+END_SRC
  1387. #+BEGIN_SRC emacs-lisp
  1388. (use-package company-jedi
  1389. :defer t
  1390. ;; :after company
  1391. :ensure t
  1392. :config
  1393. (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  1394. (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  1395. (add-hook 'python-mode-hook 'jedi:setup)
  1396. (setq jedi:complete-on-dot t)
  1397. (setq jedi:use-shortcuts t)
  1398. ;; (add-hook 'python-mode-hook 'company/python-mode-hook)
  1399. )
  1400. #+END_SRC
  1401. *** Virtual Environments
  1402. A wrapper to handle virtual environments.
  1403. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine.
  1404. TODO: automatically start an inferior python process or switch to it if already created
  1405. #+BEGIN_SRC emacs-lisp
  1406. (use-package pyvenv
  1407. :ensure t
  1408. :defer t
  1409. :init
  1410. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  1411. :config
  1412. (pyvenv-mode t)
  1413. (defun my/pyvenv-post-activate-hook()
  1414. ; (setq jedi:environment-root pyvenv-virtual-env)
  1415. ; (setq jedi:environment-virtualenv pyvenv-virtual-env)
  1416. ; (setq jedi:tooltip-method '(nil)) ;; variants: nil or pos-tip and/or popup
  1417. (setq python-shell-virtualenv-root pyvenv-virtual-env)
  1418. ;; default traceback, other option M-x jedi:toggle-log-traceback
  1419. ;; traceback is in jedi:pop-to-epc-buffer
  1420. ; (jedi:setup)
  1421. ;; (company/python-mode-hook)
  1422. ; (setq jedi:server-args '("--log-traceback"))
  1423. (message "pyvenv-post-activate-hook activated"))
  1424. (add-hook 'pyvenv-post-activate-hooks 'my/pyvenv-post-activate-hook)
  1425. )
  1426. #+END_SRC
  1427. I want Emacs to automatically start the proper virtual environment.
  1428. Required is a .python-version file with, content in the first line being /path/to/virtualenv/
  1429. [[https://github.com/marcwebbie/auto-virtualenv][Github source]]
  1430. Depends on pyvenv
  1431. #+BEGIN_SRC emacs-lisp
  1432. (use-package auto-virtualenv
  1433. :ensure t
  1434. ;; :after pyvenv
  1435. :defer t
  1436. :init
  1437. (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
  1438. ;; activate on changing buffers
  1439. ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv)
  1440. ;; activate on focus in
  1441. ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv)
  1442. )
  1443. #+END_SRC
  1444. *** Visuals
  1445. Highlight indentations
  1446. #+BEGIN_SRC emacs-lisp
  1447. (use-package highlight-indentation
  1448. :init
  1449. (add-hook 'python-mode-hook 'highlight-indentation-current-column-mode)
  1450. (add-hook 'python-mode-hook 'highlight-indentation-mode)
  1451. :config
  1452. (set-face-background 'highlight-indentation-face "#454545")
  1453. (set-face-background 'highlight-indentation-current-column-face "#656565"))
  1454. #+END_SRC
  1455. *** Python language server (inactive)
  1456. On python side following needs to be installed:
  1457. - python-language-server[all]
  1458. First test for lsp-python.
  1459. Some intro: [[https://vxlabs.com/2018/06/08/python-language-server-with-emacs-and-lsp-mode/][Intro]]
  1460. Source python language server: [[https://github.com/palantir/python-language-server][Link]]
  1461. Source lsp-mode:
  1462. Source lsp-python: [[https://github.com/emacs-lsp/lsp-python][Link]]
  1463. Source company-lsp: [[https://github.com/tigersoldier/company-lsp][Link]]
  1464. Source lsp-ui: [[https://github.com/emacs-lsp/lsp-ui][Link]]
  1465. BEGIN_SRC emacs-lisp
  1466. (use-package lsp-mode
  1467. :ensure t
  1468. :config
  1469. ;; make sure we have lsp-imenu everywhere we have lsp
  1470. (require 'lsp-imenu)
  1471. (add-hook 'lsp-after-open-hook 'lsp-enable-imenu)
  1472. ;; get lsp-python-enable defined
  1473. ;; nb: use either projectile-project-root or ffip-get-project-root-directory
  1474. ;; or any other function that can be used to find the root dir of a project
  1475. (lsp-define-stdio-client lsp-python "python"
  1476. #'projectile-project-root
  1477. '("pyls"))
  1478. ;; make sure this is activated when python-mode is activated
  1479. ;; lsp-python-enable is created by macro above
  1480. (add-hook 'python-mode-hook
  1481. (lambda ()
  1482. (lsp-python-enable)
  1483. (company/python-mode-hook)))
  1484. ;; lsp extras
  1485. (use-package lsp-ui
  1486. :ensure t
  1487. :config
  1488. (setq lsp-ui-sideline-ignore-duplicate t)
  1489. (add-hook 'lsp-mode-hook 'lsp-ui-mode))
  1490. (use-package company-lsp
  1491. :ensure t)
  1492. ; :config
  1493. ; (push 'company-lsp company-backends))
  1494. ;; NB: only required if you prefer flake8 instead of the default
  1495. ;; send pyls config via lsp-after-initialize-hook -- harmless for
  1496. ;; other servers due to pyls key, but would prefer only sending this
  1497. ;; when pyls gets initialised (:initialize function in
  1498. ;; lsp-define-stdio-client is invoked too early (before server
  1499. ;; start))
  1500. (defun lsp-set-cfg ()
  1501. (let ((lsp-cfg `(:pyls (:configurationSources ("flake8")))))
  1502. ;; TODO: check lsp--cur-workspace here to decide per server / project
  1503. (lsp--set-configuration lsp-cfg)))
  1504. (add-hook 'lsp-after-initialize-hook 'lsp-set-cfg)
  1505. )
  1506. END_SRC
  1507. BEGIN_SRC emacs-lisp
  1508. (use-package lsp-mode
  1509. :ensure t
  1510. :defer t)
  1511. (add-hook 'lsp-mode-hook #'(lambda ()
  1512. (customize-set-variable 'lsp-enable-eldoc nil)
  1513. (flycheck-mode 1)
  1514. (company-mode 1)))
  1515. (use-package lsp-ui
  1516. :ensure t
  1517. :defer t)
  1518. (use-package company-lsp
  1519. :ensure t
  1520. :defer t)
  1521. (use-package lsp-python
  1522. :ensure t
  1523. :after lsp-mode
  1524. :defer t
  1525. :init
  1526. (add-hook 'python-mode-hook #'(lambda ()
  1527. (lsp-python-enable)
  1528. (flycheck-select-checker 'python-flake8))))
  1529. END_SRC
  1530. ** Latex
  1531. Requirements for Linux:
  1532. - Latex
  1533. - pdf-tools
  1534. The midnight mode hook is disabled for now, because CVs with my pic just look weird in this mode.
  1535. #+BEGIN_SRC emacs-lisp
  1536. (unless (string-equal my/whoami "work_remote")
  1537. (use-package pdf-tools
  1538. :ensure t
  1539. :defer t
  1540. :mode (("\\.pdf\\'" . pdf-view-mode))
  1541. :init
  1542. ; (add-hook 'pdf-view-mode-hook 'pdf-view-midnight-minor-mode)
  1543. :config
  1544. (pdf-tools-install)
  1545. (setq pdf-view-resize-factor 1.1 ;; more finegraned zoom
  1546. pdf-view-midnight-colors '("#c6c6c6" . "#363636")
  1547. TeX-view-program-selection '((output-pdf "pdf-tools"))
  1548. TeX-view-program-list '(("pdf-tools" "Tex-pdf-tools-sync-view")))
  1549. )
  1550. )
  1551. #+END_SRC
  1552. 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]]
  1553. Update 2018-03: It seems to work without this patch. I will keep it here in case something breaks again.
  1554. #+BEGIN_SRC
  1555. latex-preview-pane-update-p()
  1556. --- (doc-view-revert-buffer nil t)
  1557. +++ (revert-buffer-nil t 'preserve-modes)
  1558. #+END_SRC
  1559. After that M-x byte-compile-file
  1560. #+BEGIN_SRC emacs-lisp
  1561. (use-package latex-preview-pane
  1562. :ensure t
  1563. :defer t
  1564. :init
  1565. ;; one of these works
  1566. (add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
  1567. (add-hook 'latex-mode-hook 'latex-preview-pane-mode)
  1568. (setq auto-mode-alist
  1569. (append '(("\\.tex$" . latex-mode)) auto-mode-alist))
  1570. )
  1571. ;; necessary, because linum-mode isn't compatible and prints errors
  1572. (add-hook 'pdf-view-mode-hook (lambda () (linum-mode -1)))
  1573. #+END_SRC
  1574. ** Markdown
  1575. Major mode to edit markdown files.
  1576. For previews it needs markdown installed on the system.
  1577. For debian:
  1578. #+BEGIN_EXAMPLE
  1579. sudo apt install markdown
  1580. #+END_EXAMPLE
  1581. #+BEGIN_SRC emacs-lisp
  1582. (use-package markdown-mode
  1583. :ensure t
  1584. :defer t)
  1585. #+END_SRC
  1586. ** Config languages
  1587. #+BEGIN_SRC emacs-lisp
  1588. (use-package nginx-mode
  1589. :ensure t
  1590. :defer t)
  1591. #+END_SRC
  1592. ** Hydra Flycheck
  1593. Flycheck is necessary, obviously
  1594. #+BEGIN_SRC emacs-lisp
  1595. (defhydra hydra-flycheck (:color blue)
  1596. "
  1597. ^
  1598. ^Flycheck^ ^Errors^ ^Checker^
  1599. ^────────^──────────^──────^────────────^───────^───────────
  1600. _q_ quit _<_ previous _?_ describe
  1601. _m_ manual _>_ next _d_ disable
  1602. _v_ verify setup _f_ check _s_ select
  1603. ^^ ^^ ^^
  1604. "
  1605. ("q" nil)
  1606. ("<" flycheck-previous-error :color red)
  1607. (">" flycheck-next-error :color red)
  1608. ("?" flycheck-describe-checker)
  1609. ("d" flycheck-disable-checker)
  1610. ("f" flycheck-buffer)
  1611. ("m" flycheck-manual)
  1612. ("s" flycheck-select-checker)
  1613. ("v" flycheck-verify-setup)
  1614. )
  1615. #+END_SRC
  1616. * Orchestrate the configuration
  1617. Some settings should be set for all systems, some need to be specific (like my job-emacs doesn't need development tools).
  1618. ** Common
  1619. ** Home
  1620. ** Work
  1621. I mainly only use org
  1622. ** Work, Hyper-V
  1623. For testing purproses I keep a working emacs in a debian on hyper-v. The demands here are different to the other work-emacs
  1624. * Finishing
  1625. Stuff which I want to run in the end
  1626. #+BEGIN_SRC emacs-lisp
  1627. (message (emacs-init-time))
  1628. #+END_SRC