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.

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