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.

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