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.

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