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.

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