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.

1756 lines
51 KiB

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