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.

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