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.

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