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.

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