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.

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