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.

1173 lines
33 KiB

5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #+TITLE: Emacs configuration file
  2. #+AUTHOR: Marc
  3. #+BABEL: :cache yes
  4. #+PROPERTY: header-args :tangle yes
  5. * TODOS
  6. - early-init.el? What to outsource here?
  7. - Paket exec-path-from-shell, um PATH aus Linux auch in emacs zu haben
  8. - Smart mode line?
  9. - Theme
  10. - evil-collection or custom in init file?
  11. - Hydra
  12. - General
  13. - (defalias 'list-buffers 'ibuffer) ;; change default to ibuffer
  14. - ido?
  15. - treemacs (for linux)
  16. - treemacs-evil?
  17. - treemacs-projectile
  18. windmove?
  19. - tramp (in linux)
  20. - visual-regexp
  21. - org configuration: paths
  22. - org custom agenda
  23. - org-ql (related to org agendas)
  24. - org configuration: everything else
  25. - beancount configuration from config.org
  26. - CONTINUE TODO from config.org at Programming
  27. - all-the-icons?
  28. * Header
  29. :PROPERTIES:
  30. :ID: a14d7c89-24ea-41ae-b185-944bab49aa02
  31. :END:
  32. Emacs variables are dynamically scoped. That's unusual for most languages, so disable it here, too
  33. #+begin_src emacs-lisp
  34. ;;; init.el --- -*- lexical-binding: t -*-
  35. #+end_src
  36. * First start
  37. :PROPERTIES:
  38. :ID: 1c24d48e-0124-4a0b-8e78-82e4c531e818
  39. :END:
  40. When pulling the repository the first time, an initial init.el needs to be setup. After start it will replace itself with the configuration from init.org
  41. #+BEGIN_SRC emacs-lisp :tangle no
  42. (require 'org')
  43. (find-file (concat user-emacs-directory "init.org"))
  44. (org-babel-tangle)
  45. (load-file (concat user-emacs-directory "init.el"))
  46. (byte-compile-file (concat user-emacs-directory "init.el"))
  47. #+END_SRC
  48. This function updates init.el whenever changes in init.org are made. The update will be active after saving.
  49. #+BEGIN_SRC emacs-lisp
  50. (defun me/tangle-init ()
  51. "If the current buffer is 'init.org', the code blocks are tangled, and the tangled file is compiled."
  52. (when (equal (buffer-file-name)
  53. (expand-file-name (concat user-emacs-directory "init.org")))
  54. ;; avoid running hooks
  55. (let ((prog-mode-hook nil))
  56. (org-babel-tangle)
  57. (byte-compile-file (concat user-emacs-directory "init.el"))
  58. (load-file user-init-file))))
  59. (add-hook 'after-save-hook 'me/tangle-init)
  60. #+END_SRC
  61. A small function to measure start up time.
  62. Compare that to
  63. emacs -q --eval='(message "%s" (emacs-init-time))'
  64. (roughly 0.27s)
  65. https://blog.d46.us/advanced-emacs-startup/
  66. #+begin_src emacs-lisp
  67. (add-hook 'emacs-startup-hook
  68. (lambda ()
  69. (message "Emacs ready in %s with %d garbage collections."
  70. (format "%.2f seconds"
  71. (float-time
  72. (time-subtract after-init-time before-init-time)))
  73. gcs-done)))
  74. (setq gc-cons-threshold (* 50 1000 1000))
  75. #+end_src
  76. #+BEGIN_SRC emacs-lisp
  77. (require 'package)
  78. (add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/") t)
  79. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  80. (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  81. (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
  82. ;(when (< emacs-major-version 27)
  83. ; (package-initialize))
  84. #+END_SRC
  85. #+BEGIN_SRC emacs-lisp
  86. (unless (package-installed-p 'use-package)
  87. (package-refresh-contents)
  88. (package-install 'use-package))
  89. (eval-when-compile
  90. (require 'use-package))
  91. (require 'bind-key)
  92. (setq use-package-verbose nil)
  93. (use-package diminish
  94. :ensure t)
  95. #+END_SRC
  96. cl is deprecated in favor for cl-lib, some packages like emmet still depend on cl.
  97. Shut off the compiler warning about it.
  98. Maybe turn it on again at some point before the next major emacs upgrade
  99. #+begin_src emacs-lisp
  100. (setq byte-compile-warnings '(cl-functions))
  101. #+end_src
  102. * Default settings
  103. :PROPERTIES:
  104. :ID: 3512d679-d111-4ccd-8372-6fc2acbc0374
  105. :END:
  106. #+BEGIN_SRC emacs-lisp
  107. (defconst *sys/gui*
  108. (display-graphic-p)
  109. "Is emacs running in a gui?")
  110. (defconst *sys/linux*
  111. (string-equal system-type 'gnu/linux)
  112. "Is the system running Linux?")
  113. (defconst *sys/windows*
  114. (string-equal system-type 'windows-nt)
  115. "Is the system running Windows?")
  116. (defconst *home_desktop*
  117. (string-equal (system-name) "marc")
  118. "Is emacs running on my desktop?")
  119. (defconst *home_laptop*
  120. (string-equal (system-name) "laptop")
  121. "Is emacs running on my laptop?")
  122. (defconst *work_local*
  123. (string-equal (system-name) "PMPCNEU08")
  124. "Is emacs running at work on the local system?")
  125. (defconst *work_remote*
  126. (string-equal (system-name) "PMTS01")
  127. "Is emacs running at work on the remote system?")
  128. #+END_SRC
  129. #+BEGIN_SRC emacs-lisp
  130. (defvar MY--PATH_USER_LOCAL (concat user-emacs-directory "user-local/"))
  131. (defvar MY--PATH_USER_GLOBAL (concat user-emacs-directory "user-global/"))
  132. (add-to-list 'custom-theme-load-path (concat MY--PATH_USER_GLOBAL "themes"))
  133. (when *sys/linux*
  134. (defconst MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/"))
  135. (defconst MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/")))
  136. (defconst MY--PATH_ORG_JOURNAl (expand-file-name "~/Archiv/Organisieren/Journal/"))
  137. (when *work_remote*
  138. (defconst MY--PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  139. (defconst MY--PATH_ORG_FILES_MOBILE nil) ;; hacky way to prevent "free variable" compiler error
  140. (defconst MY--PATH_ORG_JOURNAL nil) ;; hacky way to prevent "free variable" compiler error
  141. (defconst MY--PATH_START "p:/Eigene Dateien/Notizen/"))
  142. (setq recentf-save-file (concat MY--PATH_USER_LOCAL "recentf"))
  143. ;; exclude some dirs from spamming recentf
  144. (use-package recentf
  145. :config
  146. (recentf-mode)
  147. (setq recentf-exclude '(".*-autoloads\\.el\\"
  148. "[/\\]\\.elpa/")))
  149. (setq custom-file (concat MY--PATH_USER_LOCAL "custom.el")) ;; don't spam init.e with saved customization settings
  150. (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_defs"))
  151. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  152. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  153. (setq save-abbrevs 'silently) ;; don't bother me with asking for abbrev saving
  154. (setq-default create-lockfiles nil) ;; disable lock files, can cause trouble in e.g. lsp-mode
  155. (defalias 'yes-or-no-p 'y-or-n-p) ;; answer with y and n
  156. (setq custom-safe-themes t) ;; don't ask me if I want to load a theme
  157. (setq sentence-end-double-space nil) ;; don't coun two spaces after a period as the end of a sentence.
  158. (delete-selection-mode t) ;; delete selected region when typing
  159. (save-place-mode 1) ;; saves position in file when it's closed
  160. (setq save-place-forget-unreadable-files nil) ;; checks if file is readable before saving position
  161. (set-charset-priority 'unicode)
  162. (setq locale-coding-system 'utf-8)
  163. (set-terminal-coding-system 'utf-8)
  164. (set-keyboard-coding-system 'utf-8)
  165. (set-selection-coding-system 'utf-8)
  166. (setq default-process-coding-system '(utf-8-unix . utf-8-unix))
  167. (if *sys/windows*
  168. (prefer-coding-system 'utf-8-dos)
  169. (prefer-coding-system 'utf-8))
  170. (blink-cursor-mode -1) ;; turn off blinking cursor
  171. (column-number-mode t)
  172. (setq uniquify-buffer-name-style 'forward)
  173. (setq-default indent-tabs-mode nil) ;; avoid tabs in place of multiple spaces (they look bad in tex)
  174. (setq-default indicate-empty-lines t) ;; show empty lines
  175. (setq scroll-margin 5 ;; smooth scrolling
  176. scroll-conservatively 10000
  177. scroll-preserve-screen-position 1
  178. scroll-step 1)
  179. (global-hl-line-mode t) ;; highlight current line
  180. (menu-bar-mode 0) ;; disable menu bar
  181. (tool-bar-mode 0) ;; disable tool bar
  182. (scroll-bar-mode 0) ;; disable scroll bar
  183. #+END_SRC
  184. Bookmarks
  185. Usage:
  186. - C-x r m (bookmark-set): add bookmark
  187. - C-x r l (list-bookmark): list bookmarks
  188. - C-x r b (bookmark-jump): open bookmark
  189. Edit bookmarks (while in bookmark file):
  190. - d: mark current item
  191. - x: delete marked items
  192. - r: rename current item
  193. - s: save changes
  194. #+begin_src emacs-lisp
  195. (use-package bookmark
  196. :custom
  197. (bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks")))
  198. #+end_src
  199. Some windows specific stuff
  200. #+BEGIN_SRC emacs-lisp
  201. (when *sys/windows*
  202. (remove-hook 'find-file-hook 'vc-refresh-state)
  203. (progn
  204. (setq gc-cons-threshold (* 511 1024 1024)
  205. gc-cons-percentage 0.5
  206. garbage-collection-messages t)
  207. (run-with-idle-timer 5 t #'garbage-collect))
  208. (when (boundp 'w32-pipe-read-delay)
  209. (setq w32-pipe-read-delay 0))
  210. (when (boundp 'w32-get-true-file-attributes)
  211. (setq w32-get-true-file-attributes nil)))
  212. #+END_SRC
  213. * visuals
  214. ** Font
  215. :PROPERTIES:
  216. :ID: dc8eb670-e6bb-4bfb-98f0-aae1860234fb
  217. :END:
  218. #+BEGIN_SRC emacs-lisp
  219. (when *sys/linux*
  220. (set-face-font 'default "Hack-10"))
  221. (when *work_remote*
  222. (set-face-font 'default "Lucida Sans Typewriter-11"))
  223. #+END_SRC
  224. ** Themes
  225. :PROPERTIES:
  226. :ID: 9ccf37c0-6837-43cb-bed8-5a353799d8b1
  227. :END:
  228. #+BEGIN_SRC emacs-lisp
  229. (defun my/toggle-theme ()
  230. (interactive)
  231. (when (or *sys/windows* *sys/linux*)
  232. (if (eq (car custom-enabled-themes) 'tango-dark)
  233. (progn (disable-theme 'tango-dark)
  234. (load-theme 'tango))
  235. (progn
  236. (disable-theme 'tango)
  237. (load-theme 'tango-dark)))))
  238. (bind-key "C-c t" 'my/toggle-theme)
  239. #+END_SRC
  240. Windows Theme:
  241. #+BEGIN_SRC emacs-lisp
  242. (when *sys/windows*
  243. (load-theme 'tango))
  244. (when *sys/linux*
  245. (load-theme 'plastic))
  246. #+END_SRC
  247. ** line wrappings
  248. :PROPERTIES:
  249. :ID: 14ae933e-2941-4cc3-82de-38f90f91bfd3
  250. :END:
  251. #+BEGIN_SRC emacs-lisp
  252. (global-visual-line-mode)
  253. (diminish 'visual-line-mode)
  254. (use-package adaptive-wrap
  255. :ensure t
  256. :config
  257. (add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode))
  258. ; :init
  259. ; (when (fboundp 'adaptive-wrap-prefix-mode)
  260. ; (defun my/activate-adaptive-wrap-prefix-mode ()
  261. ; "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  262. ; (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  263. ; (add-hook 'visual-line-mode-hook 'my/activate-adaptive-wrap-prefix-mode)))
  264. #+END_SRC
  265. ** line numbers
  266. :PROPERTIES:
  267. :ID: 7b969436-98c9-4b61-ba7a-9fb22c9781ad
  268. :END:
  269. #+BEGIN_SRC emacs-lisp
  270. (use-package display-line-numbers
  271. :init
  272. (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  273. (add-hook 'org-src-mode-hook 'display-line-numbers-mode)
  274. :config
  275. (setq-default display-line-numbers-type 'visual
  276. display-line-numbers-current-absolute t
  277. display-line-numbers-with 4
  278. display-line-numbers-widen t))
  279. ; (add-hook 'emacs-lisp-mode-hook 'display-line-numbers-mode)
  280. #+END_SRC
  281. ** misc
  282. :PROPERTIES:
  283. :ID: a2873138-16ee-4990-89a2-26eab778ea74
  284. :END:
  285. #+BEGIN_SRC emacs-lisp
  286. (use-package rainbow-mode
  287. :ensure t
  288. :diminish
  289. :hook ((org-mode
  290. emacs-lisp-mode) . rainbow-mode))
  291. (use-package delight
  292. :ensure t)
  293. (show-paren-mode t) ;; show other part of brackets
  294. (use-package rainbow-delimiters
  295. :ensure t
  296. :hook ((prog-mode . rainbow-delimiters-mode)))
  297. #+END_SRC
  298. * undo
  299. :PROPERTIES:
  300. :ID: d57621b2-5472-4c89-a520-b4133db0b9af
  301. :END:
  302. #+BEGIN_SRC emacs-lisp
  303. (use-package undo-tree
  304. :ensure t
  305. :diminish undo-tree-mode
  306. :init
  307. (global-undo-tree-mode 1))
  308. #+END_SRC
  309. * ace-window
  310. #+begin_src emacs-lisp
  311. (use-package ace-window
  312. :ensure t
  313. :bind
  314. (:map global-map
  315. ("C-x o" . ace-window)))
  316. #+end_src
  317. * imenu-list
  318. :PROPERTIES:
  319. :ID: 0ae27ec9-5d77-43cf-ac76-5e12cc959046
  320. :END:
  321. A minor mode to show imenu in a sidebar.
  322. Call imenu-list-smart-toggle.
  323. [[https://github.com/bmag/imenu-list][Source]]
  324. #+BEGIN_SRC emacs-lisp
  325. (use-package imenu-list
  326. :ensure t
  327. :defer t
  328. :config
  329. (setq imenu-list-focus-after-activation t
  330. imenu-list-auto-resize t
  331. imenu-list-position 'right)
  332. :bind
  333. (:map global-map
  334. ([f9] . imenu-list-smart-toggle))
  335. )
  336. #+END_SRC
  337. * which-key
  338. :PROPERTIES:
  339. :ID: a880f079-b3a3-4706-bf1e-5f6c680101f1
  340. :END:
  341. #+BEGIN_SRC emacs-lisp
  342. (use-package which-key
  343. :ensure t
  344. :diminish which-key-mode
  345. :defer t
  346. :config
  347. (which-key-mode)
  348. (which-key-setup-side-window-right-bottom)
  349. (which-key-setup-minibuffer)
  350. (setq which-key-idle-delay 0.5))
  351. #+END_SRC
  352. * Evil
  353. :PROPERTIES:
  354. :ID: 80ca70e2-a146-46db-b581-418d655dc1fc
  355. :END:
  356. #+BEGIN_SRC emacs-lisp
  357. (use-package evil
  358. :ensure t
  359. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  360. :config
  361. (evil-mode 1))
  362. #+END_SRC
  363. * General (key mapper)
  364. :PROPERTIES:
  365. :ID: a20f183f-d41a-4dff-bc37-3bc4e25c8036
  366. :END:
  367. #+BEGIN_SRC emacs-lisp
  368. (use-package general
  369. :ensure t)
  370. (general-define-key
  371. :states 'normal
  372. :keymaps 'imenu-list-major-mode-map
  373. (kbd "RET") '(imenu-list-goto-entry :which-key "goto")
  374. (kbd "TAB") '(hs-toggle-hiding :which-key "collapse")
  375. "d" '(imenu-list-display-entry :which-key "show")
  376. "q" '(imenu-list-quit-window :which-key "quit"))
  377. #+END_SRC
  378. * ivy / counsel / swiper
  379. :PROPERTIES:
  380. :ID: 55c74ba9-7761-4545-8ddd-087d6ee33e4b
  381. :END:
  382. #+BEGIN_SRC emacs-lisp
  383. ; (require 'ivy)
  384. (use-package ivy
  385. :ensure t
  386. :diminish
  387. (ivy-mode . "")
  388. :defer t
  389. :init
  390. (ivy-mode 1)
  391. :bind
  392. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  393. :config
  394. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  395. ivy-height 20 ;; height of ivy window
  396. ivy-count-format "%d/%d" ;; current and total number
  397. ivy-re-builders-alist ;; regex replaces spaces with *
  398. '((t . ivy--regex-plus))))
  399. ; make counsel-M-x more descriptive
  400. (use-package ivy-rich
  401. :ensure t
  402. :defer t
  403. :init
  404. (ivy-rich-mode 1))
  405. (use-package counsel
  406. :ensure t
  407. :defer t
  408. :bind
  409. (("M-x" . counsel-M-x)
  410. ("C-x C-f" . counsel-find-file)
  411. ("C-x C-r" . counsel-recentf)
  412. ("C-x b" . counsel-switch-buffer)
  413. ("C-c C-f" . counsel-git)
  414. ("C-c h f" . counsel-describe-function)
  415. ("C-c h v" . counsel-describe-variable)
  416. ("M-i" . counsel-imenu)))
  417. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  418. ; ("C-r" . 'counsel-minibuffer-history)))
  419. (use-package swiper
  420. :ensure t
  421. :bind
  422. ("C-s" . swiper))
  423. (use-package ivy-hydra
  424. :ensure t)
  425. #+END_SRC
  426. * misc
  427. #+begin_src emacs-lisp
  428. (use-package autorevert
  429. :diminish auto-revert-mode)
  430. #+end_src
  431. * company
  432. :PROPERTIES:
  433. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  434. :END:
  435. #+BEGIN_SRC emacs-lisp
  436. (use-package company
  437. :defer 1
  438. :diminish
  439. :defer t
  440. :bind
  441. (("C-<tab>" . company-complete)
  442. :map company-active-map
  443. ("RET" . nil)
  444. ([return] . nil)
  445. ("TAB" . company-complete-selection)
  446. ([tab] . company-complete-selection)
  447. ("<right>" . company-complete-common))
  448. :hook
  449. (after-init . global-company-mode)
  450. :config
  451. (setq company-idle-delay .2
  452. company-minimum-prefix-length 1
  453. company-require-match nil
  454. company-show-numbers t
  455. company-tooltip-align-annotations t))
  456. (use-package company-statistics
  457. :ensure t
  458. :after company
  459. :defer t
  460. :init
  461. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  462. :config
  463. (company-statistics-mode 1))
  464. (use-package company-dabbrev
  465. :ensure nil
  466. :after company
  467. :defer t
  468. :config
  469. (setq-default company-dabbrev-downcase nil))
  470. (use-package company-box
  471. :ensure t
  472. :diminish
  473. :defer t
  474. :init
  475. (add-hook 'company-mode-hook 'company-box-mode))
  476. #+END_SRC
  477. ** company backends
  478. :PROPERTIES:
  479. :ID: 4ce2e728-276d-41f9-9538-84e6e08afd8d
  480. :END:
  481. #+BEGIN_SRC emacs-lisp
  482. (defun company/org-mode-hook()
  483. (set (make-local-variable 'company-backends)
  484. '(company-capf company-files))
  485. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  486. (message "company/org-mode-hook"))
  487. (defun company/elisp-mode-hook()
  488. (set (make-local-variable 'company-backends)
  489. '(company-capf company-files))
  490. (message "company/elisp-mode-hook"))
  491. (defun company/beancount-mode-hook()
  492. (set (make-local-variable 'company-backends)
  493. '(company-beancount)))
  494. #+END_SRC
  495. * orgmode
  496. ** org
  497. :PROPERTIES:
  498. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  499. :END:
  500. #+BEGIN_SRC emacs-lisp
  501. (use-package org
  502. :ensure org-plus-contrib
  503. :mode (("\.org$" . org-mode))
  504. :diminish org-indent-mode
  505. :defer t
  506. :init
  507. (add-hook 'org-mode-hook 'company/org-mode-hook)
  508. (add-hook 'org-src-mode-hook 'smartparens-mode)
  509. (add-hook 'org-mode-hook 'org-indent-mode)
  510. :config
  511. (setq org-modules (quote (org-id
  512. org-habit
  513. org-tempo ;; easy templates
  514. )))
  515. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  516. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  517. (concat MY--PATH_ORG_FILES "projects.org")
  518. (concat MY--PATH_ORG_FILES "tasks.org")))
  519. (when *sys/linux*
  520. (nconc org-agenda-files
  521. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  522. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  523. org-log-into-drawer "LOGBOOK")
  524. ;; some display customizations
  525. (setq org-pretty-entities t
  526. org-startup-truncated t
  527. org-startup-align-all-tables t)
  528. ;; some source code blocks customizations
  529. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  530. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  531. org-src-preserve-indentation t ;; no extra indentation
  532. org-src-tab-acts-natively t)
  533. (setq org-log-done 'time)) ;; create timestamp when task is done
  534. #+END_SRC
  535. ** languages
  536. :PROPERTIES:
  537. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  538. :END:
  539. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  540. #+BEGIN_SRC emacs-lisp
  541. (org-babel-do-load-languages
  542. 'org-babel-load-languages
  543. '((emacs-lisp . t)
  544. (gnuplot . t)
  545. (js . t)
  546. (latex . t)
  547. (lisp . t)
  548. (python . t)
  549. (shell . t)
  550. (sqlite . t)
  551. (org . t)
  552. (R . t)
  553. (scheme . t)))
  554. (setq org-confirm-babel-evaluate nil)
  555. #+END_SRC
  556. ** habits
  557. :PROPERTIES:
  558. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  559. :END:
  560. #+BEGIN_SRC emacs-lisp
  561. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  562. ;; (add-to-list 'org-modules "org-habit")
  563. (setq org-habit-graph-column 80
  564. org-habit-preceding-days 30
  565. org-habit-following-days 7
  566. org-habit-show-habits-only-for-today nil)
  567. #+END_SRC
  568. ** org-id
  569. :PROPERTIES:
  570. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  571. :END:
  572. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  573. #+BEGIN_SRC emacs-lisp
  574. ;; (use-package org-id
  575. ;; :config
  576. ;; (setq org-id-link-to-org-use-id t)
  577. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  578. #+END_SRC
  579. ** org-agenda
  580. :PROPERTIES:
  581. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  582. :END:
  583. Custom keywords, depending on environment
  584. #+BEGIN_SRC emacs-lisp
  585. (when *work_remote*
  586. (setq org-todo-keywords
  587. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  588. #+END_SRC
  589. Add some key bindings
  590. #+BEGIN_SRC emacs-lisp
  591. (bind-key "C-c l" 'org-store-link)
  592. (bind-key "C-c c" 'org-capture)
  593. (bind-key "C-c a" 'org-agenda)
  594. #+END_SRC
  595. Sort agenda by deadline and priority
  596. #+BEGIN_SRC emacs-lisp
  597. (setq org-agenda-sorting-strategy
  598. (quote
  599. ((agenda deadline-up priority-down)
  600. (todo priority-down category-keep)
  601. (tags priority-down category-keep)
  602. (search category-keep))))
  603. #+END_SRC
  604. Customize the org agenda
  605. #+BEGIN_SRC emacs-lisp
  606. (defun me--org-skip-subtree-if-priority (priority)
  607. "Skip an agenda subtree if it has a priority of PRIORITY.
  608. PRIORITY may be one of the characters ?A, ?B, or ?C."
  609. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  610. (pri-value (* 1000 (- org-lowest-priority priority)))
  611. (pri-current (org-get-priority (thing-at-point 'line t))))
  612. (if (= pri-value pri-current)
  613. subtree-end
  614. nil)))
  615. (setq org-agenda-custom-commands
  616. '(("c" "Simple agenda view"
  617. ((tags "PRIORITY=\"A\""
  618. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  619. (org-agenda-overriding-header "Hohe Priorität:")))
  620. (agenda ""
  621. ((org-agenda-span 7)
  622. (org-agenda-start-on-weekday nil)
  623. (org-agenda-overriding-header "Nächste 7 Tage:")))
  624. (alltodo ""
  625. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  626. (org-agenda-skip-if nil '(scheduled deadline))))
  627. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  628. #+END_SRC
  629. ** *TODO*
  630. org-super-agenda
  631. ** org-caldav
  632. :PROPERTIES:
  633. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  634. :END:
  635. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  636. #+BEGIN_SRC emacs-lisp
  637. ;;(use-package org-caldav
  638. ;; :ensure t
  639. ;; :config
  640. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  641. ;; org-caldav-calendar-id "orgmode"
  642. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  643. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  644. #+END_SRC
  645. ** journal
  646. :PROPERTIES:
  647. :ID: a1951e18-d862-4198-9652-016e979053c8
  648. :END:
  649. [[https://github.com/bastibe/org-journal][Source]]
  650. #+BEGIN_SRC emacs-lisp
  651. (use-package org-journal
  652. :if *sys/linux*
  653. :ensure t
  654. :defer t
  655. :config
  656. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  657. (when (and (boundp 'org-journal-dir)
  658. (boundp 'org-journal-enable-agenda-integration))
  659. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  660. org-journal-enable-agenda-integration t)))
  661. #+END_SRC
  662. * Programming
  663. ** misc
  664. #+begin_src emacs-lisp
  665. (use-package eldoc
  666. :diminish eldoc-mode
  667. :defer t)
  668. #+end_src
  669. ** Magit / Git
  670. :PROPERTIES:
  671. :ID: d3589460-317f-40f6-9056-053be9ba3217
  672. :END:
  673. Little crash course in magit:
  674. - magit-init to init a git project
  675. - magit-status (C-x g) to call the status window
  676. In status buffer:
  677. - s stage files
  678. - u unstage files
  679. - U unstage all files
  680. - a apply changes to staging
  681. - c c commit (type commit message, then C-c C-c to commit)
  682. - b b switch to another branch
  683. - P u git push
  684. - F u git pull
  685. #+BEGIN_SRC emacs-lisp
  686. (use-package magit
  687. :ensure t
  688. :defer t
  689. :init
  690. ; set git-path in work environment
  691. (if (string-equal user-login-name "POH")
  692. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  693. )
  694. :bind (("C-x g" . magit-status)))
  695. #+END_SRC
  696. ** LSP
  697. :PROPERTIES:
  698. :ID: 06ad00e0-44a6-4bfb-ba6f-b1672811e053
  699. :END:
  700. Configuration for the language server protocol
  701. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  702. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  703. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  704. TODO Unterverzeichnisse wurden noch nicht getestet
  705. #+BEGIN_SRC emacs-lisp
  706. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  707. (use-package lsp-mode
  708. :defer t
  709. :commands (lsp lsp-execute-code-action)
  710. :custom
  711. (lsp-auto-guess-root nil)
  712. (lsp-prefer-flymake nil) ; use flycheck instead
  713. (lsp-file-watch-threshold 5000)
  714. (lsb-print-performance t)
  715. (lsp-log-io t)
  716. (lsp-diagnostics-modeline-scope :project)
  717. (lsp-enable-file-watchers nil)
  718. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  719. :hook
  720. (((python-mode
  721. js-mode
  722. js2-mode
  723. typescript-mode
  724. web-mode) . lsp)
  725. (lsp-mode . lsp-enable-which-key-integration)
  726. (lsp-mode . lsp-diagnostics-modeline-mode)))
  727. (use-package lsp-ui
  728. :after lsp-mode
  729. :ensure t
  730. :defer t
  731. :diminish
  732. :commands lsp-ui-mode
  733. :config
  734. (setq lsp-ui-doc-enable t
  735. lsp-ui-doc-header t
  736. lsp-ui-doc-include-signature t
  737. lsp-ui-doc-position 'top
  738. lsp-ui-doc-border (face-foreground 'default)
  739. lsp-ui-sideline-enable nil
  740. lsp-ui-sideline-ignore-duplicate t
  741. lsp-ui-sideline-show-code-actions nil)
  742. (when *sys/gui*
  743. (setq lsp-ui-doc-use-webkit t))
  744. ;; workaround hide mode-line of lsp-ui-imenu buffer
  745. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  746. (setq mode-line-format nil)))
  747. (use-package company-lsp
  748. :requires company
  749. :defer t
  750. :ensure t
  751. :config
  752. ;;disable client-side cache because lsp server does a better job
  753. (setq company-transformers nil
  754. company-lsp-async t
  755. company-lsp-cache-candidates nil))
  756. #+END_SRC
  757. ** yasnippet
  758. :PROPERTIES:
  759. :ID: 935d89ef-645e-4e92-966f-2fe3bebb2880
  760. :END:
  761. For useful snippet either install yasnippet-snippets or get them from here
  762. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  763. #+begin_src emacs-lisp
  764. (use-package yasnippet
  765. :ensure t
  766. :defer t
  767. :diminish yas-minor-mode
  768. :config
  769. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  770. (yas-global-mode t)
  771. (yas-reload-all)
  772. (unbind-key "TAB" yas-minor-mode-map)
  773. (unbind-key "<tab>" yas-minor-mode-map))
  774. #+end_src
  775. ** hippie expand
  776. :PROPERTIES:
  777. :ID: c55245bc-813d-4816-a0ca-b4e2e793e28b
  778. :END:
  779. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  780. #+begin_src emacs-lisp
  781. (use-package hippie-exp
  782. :defer t
  783. :bind
  784. ("C-<return>" . hippie-expand)
  785. :config
  786. (setq hippie-expand-try-functions-list
  787. '(yas-hippie-try-expand emmet-expand-line)))
  788. #+end_src
  789. ** flycheck
  790. :PROPERTIES:
  791. :ID: 3d8f2547-c5b3-46d0-91b0-9667f9ee5c47
  792. :END:
  793. #+BEGIN_SRC emacs-lisp
  794. (use-package flycheck
  795. :ensure t
  796. :hook
  797. ((css-mode . flycheck-mode)
  798. (emacs-lisp-mode . flycheck-mode)
  799. (python-mode . flycheck-mode))
  800. :defer 1.0
  801. :init
  802. (setq flycheck-emacs-lisp-load-path 'inherit)
  803. :config
  804. (setq-default
  805. flycheck-check-synta-automatically '(save mode-enabled)
  806. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  807. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  808. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  809. #+END_SRC
  810. ** Projectile
  811. :PROPERTIES:
  812. :ID: a90329fd-4d36-435f-8308-a2771ac4c320
  813. :END:
  814. Manage projects and jump quickly between its files
  815. #+BEGIN_SRC emacs-lisp
  816. (use-package projectile
  817. :ensure t
  818. :defer 1.0
  819. :diminish
  820. :hook (projectile-after-switch-project . (lambda () (set-workon_home))) ;; for pyvenv to auto activate environment
  821. :bind-keymap
  822. ("C-c p" . projectile-command-map)
  823. ; :bind
  824. ; (("C-c p p" . projectile-switch-project)
  825. ; ("C-c p c" . projectile-command-map)
  826. ; ("C-c p s s" . projectile-ag))
  827. :preface
  828. (defun set-workon_home()
  829. (setenv "WORKON_HOME" (projectile-project-root)))
  830. :init
  831. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL ".projectile-cache")
  832. projectile-known-projects-file (concat MY--PATH_USER_LOCAL ".projectile-bookmarks"))
  833. :config
  834. (projectile-mode t)
  835. (setq-default projectile-completion-system 'ivy
  836. projectile-enable-caching t
  837. projectile-mode-line '(:eval (projectile-project-name))))
  838. ;; requires ripgrep on system for rg functions
  839. (use-package counsel-projectile
  840. :ensure t
  841. :config (counsel-projectile-mode))
  842. #+END_SRC
  843. ** smartparens
  844. :PROPERTIES:
  845. :ID: 997ec416-33e6-41ed-8c7c-75a7bc47d285
  846. :END:
  847. #+BEGIN_SRC emacs-lisp
  848. (use-package smartparens
  849. :ensure t
  850. :diminish smartparens-mode
  851. :bind
  852. (:map smartparens-mode-map
  853. ("C-M-f" . sp-forward-sexp)
  854. ("C-M-b" . sp-backward-sexp)
  855. ("C-M-a" . sp-backward-down-sexp)
  856. ("C-M-e" . sp-up-sexp)
  857. ("C-M-w" . sp-copy-sexp)
  858. ("M-k" . sp-kill-sexp)
  859. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  860. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  861. ("C-]" . sp-select-next-thing-exchange))
  862. :config
  863. (setq sp-show-pair-from-inside nil
  864. sp-escape-quotes-after-insert nil)
  865. (require 'smartparens-config))
  866. #+END_SRC
  867. ** lisp
  868. :PROPERTIES:
  869. :ID: a2bc3e08-b203-49d3-b337-fb186a14eecb
  870. :END:
  871. #+BEGIN_SRC emacs-lisp
  872. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  873. #+END_SRC
  874. ** web
  875. :PROPERTIES:
  876. :ID: c0b0b4e4-2162-429f-b80d-6e5334b1290e
  877. :END:
  878. apt install npm
  879. sudo npm install -g vscode-html-languageserver-bin
  880. evtl alternativ typescript-language-server?
  881. Unter Windows:
  882. Hier runterladen: https://nodejs.org/dist/latest/
  883. und in ein Verzeichnis entpacken.
  884. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  885. PATH=P:\path\to\node;%path%
  886. #+BEGIN_SRC emacs-lisp
  887. (use-package web-mode
  888. :ensure t
  889. :defer t
  890. :mode
  891. ("\\.phtml\\'"
  892. "\\.tpl\\.php\\'"
  893. "\\.djhtml\\'"
  894. "\\.[t]?html?\\'")
  895. :init
  896. (if *work_remote*
  897. (setq exec-path (append exec-path '("P:/Tools/node"))))
  898. :config
  899. (setq web-mode-enable-auto-closing t
  900. web-mode-enable-auto-pairing t)
  901. (add-hook 'web-mode-hook 'smartparens-mode))
  902. #+END_SRC
  903. Emmet offers snippets, similar to yasnippet.
  904. Default completion is C-j
  905. [[https://github.com/smihica/emmet-mode#usage][Github]]
  906. #+begin_src emacs-lisp
  907. (use-package emmet-mode
  908. :ensure t
  909. :defer t
  910. :hook
  911. ((web-mode . emmet-mode)
  912. (css-mode . emmet-mode))
  913. :config
  914. (unbind-key "C-<return>" emmet-mode-keymap))
  915. #+end_src
  916. ** YAML
  917. :PROPERTIES:
  918. :ID: 95413247-04d5-4e02-8431-06c162ec8f3b
  919. :END:
  920. #+begin_src emacs-lisp
  921. (use-package yaml-mode
  922. :if *sys/linux*
  923. :ensure t
  924. :defer t
  925. :mode ("\\.yml$" . yaml-mode))
  926. #+end_src
  927. ** R
  928. #+BEGIN_SRC emacs-lisp
  929. (use-package ess
  930. :ensure t
  931. :defer t
  932. :init
  933. (if *work_remote*
  934. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  935. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  936. #+END_SRC
  937. ** Python
  938. :PROPERTIES:
  939. :ID: 8c76fcd1-c57c-48ab-8af0-aa782de6337f
  940. :END:
  941. Systemseitig muss python-language-server installiert sein:
  942. apt install python3-pip python3-setuptools python3-wheel
  943. apt install build-essential python3-dev
  944. pip3 install 'python-language-server[all]'
  945. für andere language servers
  946. https://github.com/emacs-lsp/lsp-mode#install-language-server
  947. #+BEGIN_SRC emacs-lisp
  948. (use-package lsp-python-ms
  949. :if *sys/linux*
  950. :ensure t
  951. :defer t
  952. :custom (lsp-python-ms-auto-install-server t))
  953. (use-package python
  954. :if *sys/linux*
  955. :delight "π "
  956. :defer t
  957. :bind (("M-[" . python-nav-backward-block)
  958. ("M-]" . python-nav-forward-block)))
  959. (use-package pyvenv
  960. :if *sys/linux*
  961. :ensure t
  962. :defer t
  963. :after python
  964. :hook ((python-mode . pyvenv-mode)
  965. (python-mode . (lambda ()
  966. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  967. (pyvenv-activate pyvenv-directory))
  968. (lsp))))
  969. :custom
  970. (pyvenv-default-virtual-env-name "env")
  971. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  972. :preface
  973. (defun find-pyvenv-directory (path)
  974. "Check if a pyvenv directory exists."
  975. (cond
  976. ((not path) nil)
  977. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  978. ((file-directory-p path)
  979. (or
  980. (seq-find
  981. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  982. (directory-files path t))
  983. (let ((parent (file-name-directory (directory-file-name path))))
  984. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  985. ;; manage multiple python version
  986. ;; needs to be installed on system
  987. ; (use-package pyenv-mode
  988. ; :ensure t
  989. ; :after python
  990. ; :hook ((python-mode . pyenv-mode)
  991. ; (projectile-switch-project . projectile-pyenv-mode-set))
  992. ; :custom (pyenv-mode-set "3.8.5")
  993. ; :preface
  994. ; (defun projectile-pyenv-mode-set ()
  995. ; "Set pyenv version matching project name."
  996. ; (let ((project (projectile-project-name)))
  997. ; (if (member project (pyenv-mode-versions))
  998. ; (pyenv-mode-set project)
  999. ; (pyenv-mode-unset)))))
  1000. ;)
  1001. #+END_SRC
  1002. * beancount
  1003. ** Installation
  1004. :PROPERTIES:
  1005. :ID: 2c329043-b7a9-437d-a5cf-f2ad6514be91
  1006. :END:
  1007. #+BEGIN_SRC shell
  1008. sudo su
  1009. cd /opt
  1010. python3 -m venv beancount
  1011. source ./beancount/bin/activate
  1012. pip3 install wheel
  1013. pip3 install beancount
  1014. sleep 100
  1015. echo "shell running!"
  1016. deactivate
  1017. #+END_SRC
  1018. #+BEGIN_SRC emacs-lisp
  1019. (use-package beancount
  1020. :if *sys/linux*
  1021. :load-path "user-global/elisp"
  1022. ; :ensure t
  1023. :defer t
  1024. :mode
  1025. ("\\.beancount$" . beancount-mode)
  1026. :init
  1027. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1028. ; (add-hook 'beancount-mode-hook (pyvenv-activate "/opt/beancount"))
  1029. ; (setenv "PATH"
  1030. ; (concat "/opt/beancount/bin:"
  1031. ; (getenv "PATH")))
  1032. :config
  1033. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1034. #+END_SRC
  1035. To support org-babel, check if it can find the symlink to ob-beancount.el
  1036. #+BEGIN_SRC shell
  1037. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1038. beansym="$orgpath/ob-beancount.el
  1039. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1040. if [ -h "$beansym" ]
  1041. then
  1042. echo "$beansym found"
  1043. elif [ -e "$bean" ]
  1044. then
  1045. echo "creating symlink"
  1046. ln -s "$bean" "$beansym"
  1047. else
  1048. echo "$bean not found, symlink creation aborted"
  1049. fi
  1050. #+END_SRC
  1051. Fava is strongly recommended.
  1052. #+BEGIN_SRC shell
  1053. cd /opt
  1054. python3 -m venv fava
  1055. source ./fava/bin/activate
  1056. pip3 install wheel
  1057. pip3 install fava
  1058. deactivate
  1059. #+END_SRC
  1060. Start fava with fava my_file.beancount
  1061. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1062. Beancount-mode can start fava and open the URL right away.
  1063. * Stuff after everything else
  1064. Set garbage collector to a smaller value to let it kick in faster.
  1065. Maybe a problem on Windows?
  1066. #+begin_src emacs-lisp
  1067. (setq gc-cons-threshold (* 2 1000 1000))
  1068. #+end_src