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.

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