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.

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