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.

1778 lines
52 KiB

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