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.

1902 lines
57 KiB

5 years ago
1 year ago
3 years ago
3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
6 years ago
3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #+TITLE: Emacs configuration file
  2. #+AUTHOR: Marc
  3. #+BABEL: :cache yes
  4. #+PROPERTY: header-args :tangle yes
  5. #+OPTIONS: ^:nil
  6. * TODOS
  7. - early-init.el? What to outsource here?
  8. - Paket exec-path-from-shell, um PATH aus Linux auch in emacs zu haben
  9. - Smart mode line?
  10. - Theme
  11. - evil-collection or custom in init file?
  12. - meow instead of evil? Testing
  13. - flymake instead of flycheck?
  14. - eglot instead of lsp?
  15. - project.el instead of projectile
  16. - Hydra
  17. - General
  18. - (defalias 'list-buffers 'ibuffer) ;; change default to ibuffer
  19. - ido?
  20. - treemacs (for linux)
  21. - treemacs-evil?
  22. - treemacs-projectile
  23. windmove?
  24. - tramp (in linux)
  25. - visual-regexp
  26. - org configuration: paths
  27. - org custom agenda
  28. - org-ql (related to org agendas)
  29. - org configuration: everything else
  30. - beancount configuration from config.org
  31. - CONTINUE TODO from config.org at Programming
  32. - all-the-icons?
  33. - lispy? [[https://github.com/abo-abo/lispy]]
  34. * Header
  35. Emacs variables are dynamically scoped. That's unusual for most languages, so disable it here, too
  36. #+begin_src emacs-lisp
  37. ;;; init.el --- -*- lexical-binding: t -*-
  38. #+end_src
  39. * First start
  40. These functions updates config.el whenever changes in config.org are made. The update will be active after saving.
  41. #+BEGIN_SRC emacs-lisp
  42. (defun my/tangle-config ()
  43. "Export code blocks from the literate config file."
  44. (interactive)
  45. ;; prevent emacs from killing until tangle-process finished
  46. (add-to-list 'kill-emacs-query-functions
  47. (lambda ()
  48. (or (not (process-live-p (get-process "tangle-process")))
  49. (y-or-n-p "\"my/tangle-config\" is running; kill it? "))))
  50. (org-babel-tangle-file config-org config-el)
  51. (message "reloading user-init-file")
  52. (load-file config-el))
  53. (add-hook 'org-mode-hook
  54. (lambda ()
  55. (if (equal (buffer-file-name) config-org)
  56. (my--add-local-hook 'after-save-hook 'my/tangle-config))))
  57. (defun my--add-local-hook (hook function)
  58. "Add buffer-local hook."
  59. (add-hook hook function :local t))
  60. (defun my/async-process (command &optional name filter)
  61. "Start an async process by running the COMMAND string with bash. Return the
  62. process object for it.
  63. NAME is name for the process. Default is \"async-process\".
  64. FILTER is function that runs after the process is finished, its args should be
  65. \"(process output)\". Default is just messages the output."
  66. (make-process
  67. :command `("bash" "-c" ,command)
  68. :name (if name name
  69. "async-process")
  70. :filter (if filter filter
  71. (lambda (process output) (message output)))))
  72. #+END_SRC
  73. A small function to measure start up time.
  74. Compare that to
  75. emacs -q --eval='(message "%s" (emacs-init-time))'
  76. (roughly 0.27s)
  77. https://blog.d46.us/advanced-emacs-startup/
  78. #+begin_src emacs-lisp
  79. (add-hook 'emacs-startup-hook
  80. (lambda ()
  81. (message "Emacs ready in %s with %d garbage collections."
  82. (format "%.2f seconds"
  83. (float-time
  84. (time-subtract after-init-time before-init-time)))
  85. gcs-done)))
  86. ;(setq gc-cons-threshold (* 50 1000 1000))
  87. #+end_src
  88. #+BEGIN_SRC emacs-lisp
  89. (require 'package)
  90. (add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/") t)
  91. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  92. (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  93. (add-to-list 'package-archives '("nongnu" . "https://elpa.nongnu.org/nongnu/") t)
  94. ; fix for bug 34341
  95. (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
  96. (when (< emacs-major-version 27)
  97. (package-initialize))
  98. #+END_SRC
  99. #+BEGIN_SRC emacs-lisp
  100. (unless (package-installed-p 'use-package)
  101. (package-refresh-contents)
  102. (package-install 'use-package))
  103. (eval-when-compile
  104. (setq use-package-enable-imenu-support t)
  105. (require 'use-package))
  106. (require 'bind-key)
  107. (setq use-package-verbose t)
  108. (use-package diminish
  109. :ensure t)
  110. #+END_SRC
  111. cl is deprecated in favor for cl-lib, some packages like emmet still depend on cl.
  112. Shut off the compiler warning about it.
  113. Maybe turn it on again at some point before the next major emacs upgrade
  114. #+begin_src emacs-lisp
  115. (setq byte-compile-warnings '(cl-functions))
  116. #+end_src
  117. * Performance Optimization
  118. ** Garbage Collection
  119. Make startup faster by reducing the frequency of garbage collection.
  120. Set gc-cons-threshold (default is 800kb) to maximum value available, to prevent any garbage collection from happening during load time.
  121. #+BEGIN_SRC emacs-lisp :tangle early-init.el
  122. (setq gc-cons-threshold most-positive-fixnum)
  123. #+END_SRC
  124. Restore it to reasonable value after init. Also stop garbage collection during minibuffer interaction (helm etc.)
  125. #+begin_src emacs-lisp
  126. (defconst 1mb 1048576)
  127. (defconst 20mb 20971520)
  128. (defconst 30mb 31457280)
  129. (defconst 50mb 52428800)
  130. (defun my--defer-garbage-collection ()
  131. (setq gc-cons-threshold most-positive-fixnum))
  132. (defun my--restore-garbage-collection ()
  133. (run-at-time 1 nil (lambda () (setq gc-cons-threshold 30mb))))
  134. (add-hook 'emacs-startup-hook 'my--restore-garbage-collection 100)
  135. (add-hook 'minibuffer-setup-hook 'my--defer-garbage-collection)
  136. (add-hook 'minibuffer-exit-hook 'my--restore-garbage-collection)
  137. (setq read-process-output-max 1mb) ;; lsp-mode's performance suggest
  138. #+end_src
  139. ** File Handler
  140. #+begin_src emacs-lisp :tangle early-init.el
  141. (defvar default-file-name-handler-alist file-name-handler-alist)
  142. (setq file-name-handler-alist nil)
  143. (add-hook 'emacs-startup-hook
  144. (lambda ()
  145. (setq file-name-handler-alist default-file-name-handler-alist)) 100)
  146. #+end_src
  147. ** Others
  148. #+begin_src emacs-lisp :tangle early-init.el
  149. ;; Resizing the emacs frame can be a terriblu expensive part of changing the font.
  150. ;; By inhibiting this, we easily hale startup times with fonts that are larger
  151. ;; than the system default.
  152. (setq frame-inhibit-implied-resize t)
  153. #+end_src
  154. * Default settings
  155. ** paths
  156. #+BEGIN_SRC emacs-lisp
  157. (defconst *sys/gui*
  158. (display-graphic-p)
  159. "Is emacs running in a gui?")
  160. (defconst *sys/linux*
  161. (string-equal system-type 'gnu/linux)
  162. "Is the system running Linux?")
  163. (defconst *sys/windows*
  164. (string-equal system-type 'windows-nt)
  165. "Is the system running Windows?")
  166. (defconst *home_desktop*
  167. (string-equal (system-name) "marc")
  168. "Is emacs running on my desktop?")
  169. (defconst *home_laptop*
  170. (string-equal (system-name) "laptop")
  171. "Is emacs running on my laptop?")
  172. (defconst *work_local*
  173. (string-equal (system-name) "PMPCNEU08")
  174. "Is emacs running at work on the local system?")
  175. (defconst *work_remote*
  176. (or (string-equal (system-name) "PMTS01")
  177. (string-equal (system-name) "PMTSNEU01"))
  178. "Is emacs running at work on the remote system?")
  179. #+END_SRC
  180. #+BEGIN_SRC emacs-lisp
  181. (defvar MY--PATH_USER_LOCAL (concat user-emacs-directory "user-local/"))
  182. (defvar MY--PATH_USER_GLOBAL (concat user-emacs-directory "user-global/"))
  183. (add-to-list 'custom-theme-load-path (concat MY--PATH_USER_GLOBAL "themes"))
  184. (when *sys/linux*
  185. (defconst MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/"))
  186. (defconst MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/"))
  187. (defconst MY--PATH_ORG_JOURNAl (expand-file-name "~/Archiv/Organisieren/Journal/"))
  188. (defconst MY--PATH_ORG_ROAM (file-truename "~/Archiv/Organisieren/")))
  189. (when *work_remote*
  190. (defconst MY--PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  191. (defconst MY--PATH_ORG_FILES_MOBILE nil) ;; hacky way to prevent "free variable" compiler error
  192. (defconst MY--PATH_ORG_JOURNAL nil) ;; hacky way to prevent "free variable" compiler error
  193. (defconst MY--PATH_START "p:/Eigene Dateien/Notizen/")
  194. (defconst MY--PATH_ORG_ROAM (expand-file-name "p:/Eigene Dateien/Notizen/")))
  195. (setq custom-file (concat MY--PATH_USER_LOCAL "custom.el")) ;; don't spam init.e with saved customization settings
  196. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  197. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  198. (customize-set-variable 'auth-sources (list (concat MY--PATH_USER_LOCAL "authinfo")
  199. (concat MY--PATH_USER_LOCAL "authinfo.gpg")
  200. (concat MY--PATH_USER_LOCAL "netrc")))
  201. #+end_src
  202. ** sane defaults
  203. #+begin_src emacs-lisp
  204. (setq-default create-lockfiles nil) ;; disable lock files, can cause trouble in e.g. lsp-mode
  205. (defalias 'yes-or-no-p 'y-or-n-p) ;; answer with y and n
  206. (setq custom-safe-themes t) ;; don't ask me if I want to load a theme
  207. (setq sentence-end-double-space nil) ;; don't coun two spaces after a period as the end of a sentence.
  208. (delete-selection-mode t) ;; delete selected region when typing
  209. (use-package saveplace
  210. :config
  211. (save-place-mode 1) ;; saves position in file when it's closed
  212. :custom
  213. (save-place-file (concat MY--PATH_USER_LOCAL "places")))
  214. (setq save-place-forget-unreadable-files nil) ;; checks if file is readable before saving position
  215. (global-set-key (kbd "RET") 'newline-and-indent) ;; indent after newline
  216. (setq save-interprogram-paste-before-kill t) ;; put replaced text into killring
  217. #+END_SRC
  218. ** Browser
  219. #+begin_src emacs-lisp
  220. (setq browse-url-function 'browse-url-generic
  221. browse-url-generic-program "firefox")
  222. #+end_src
  223. * Appearance
  224. ** Defaults
  225. #+begin_src emacs-lisp
  226. (set-charset-priority 'unicode)
  227. (setq-default locale-coding-system 'utf-8
  228. default-process-coding-system '(utf-8-unix . utf-8-unix))
  229. (set-terminal-coding-system 'utf-8)
  230. (set-keyboard-coding-system 'utf-8)
  231. (set-selection-coding-system 'utf-8)
  232. (if *sys/windows*
  233. (prefer-coding-system 'utf-8-dos)
  234. (prefer-coding-system 'utf-8))
  235. (setq-default bidi-paragraph-direction 'left-to-right
  236. bidi-inhibit-bpa t ;; both settings reduce line rescans
  237. uniquify-buffer-name-style 'forward
  238. indent-tabs-mode nil ;; avoid tabs in place of multiple spaces (they look bad in tex)
  239. indicate-empty-lines t ;; show empty lines
  240. scroll-margin 5 ;; smooth scrolling
  241. scroll-conservatively 10000
  242. scroll-preserve-screen-position 1
  243. scroll-step 1
  244. ring-bell-function 'ignore ;; disable pc speaker bell
  245. visible-bell t)
  246. (global-hl-line-mode t) ;; highlight current line
  247. (blink-cursor-mode -1) ;; turn off blinking cursor
  248. (column-number-mode t)
  249. #+end_src
  250. ** Remove redundant UI
  251. #+begin_src emacs-lisp :tangle early-init.el
  252. (menu-bar-mode -1) ;; disable menu bar
  253. (tool-bar-mode -1) ;; disable tool bar
  254. (scroll-bar-mode -1) ;; disable scroll bar
  255. #+end_src
  256. ** Font
  257. #+BEGIN_SRC emacs-lisp
  258. (when *sys/linux*
  259. (set-face-font 'default "Hack-10"))
  260. (when *work_remote*
  261. (set-face-font 'default "Lucida Sans Typewriter-11"))
  262. #+END_SRC
  263. ** Themes
  264. #+BEGIN_SRC emacs-lisp
  265. (defun my/toggle-theme ()
  266. (interactive)
  267. (when (or *sys/windows* *sys/linux*)
  268. (if (eq (car custom-enabled-themes) 'tango-dark)
  269. (progn (disable-theme 'tango-dark)
  270. (load-theme 'tango))
  271. (progn
  272. (disable-theme 'tango)
  273. (load-theme 'tango-dark)))))
  274. (bind-key "C-c t" 'my/toggle-theme)
  275. #+END_SRC
  276. Windows Theme:
  277. #+BEGIN_SRC emacs-lisp
  278. (when *sys/windows*
  279. (load-theme 'tango))
  280. (when *sys/linux*
  281. (load-theme 'plastic))
  282. #+END_SRC
  283. ** line wrappings
  284. #+BEGIN_SRC emacs-lisp
  285. (global-visual-line-mode)
  286. (diminish 'visual-line-mode)
  287. (use-package adaptive-wrap
  288. :ensure t
  289. :hook
  290. (visual-line-mode . adaptive-wrap-prefix-mode))
  291. ; :init
  292. ; (when (fboundp 'adaptive-wrap-prefix-mode)
  293. ; (defun me/activate-adaptive-wrap-prefix-mode ()
  294. ; "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  295. ; (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  296. ; (add-hook 'visual-line-mode-hook 'me/activate-adaptive-wrap-prefix-mode)))
  297. #+END_SRC
  298. ** line numbers
  299. #+BEGIN_SRC emacs-lisp
  300. (use-package display-line-numbers
  301. :init
  302. :hook
  303. ((prog-mode
  304. org-src-mode) . display-line-numbers-mode)
  305. :config
  306. (setq-default display-line-numbers-type 'visual
  307. display-line-numbers-current-absolute t
  308. display-line-numbers-with 4
  309. display-line-numbers-widen t))
  310. #+END_SRC
  311. ** misc
  312. Delight can replace mode names with custom names ,
  313. e.g. python-mode with just "π ".
  314. #+BEGIN_SRC emacs-lisp
  315. (use-package rainbow-mode
  316. :ensure t
  317. :diminish
  318. :hook
  319. ((org-mode
  320. emacs-lisp-mode) . rainbow-mode))
  321. (use-package delight
  322. :if *sys/linux*
  323. :ensure t)
  324. (show-paren-mode t) ;; show other part of brackets
  325. (setq blink-matching-paren nil) ;; not necessary with show-paren-mode, bugs out on C-s counsel-line
  326. (use-package rainbow-delimiters
  327. :ensure t
  328. :hook
  329. (prog-mode . rainbow-delimiters-mode))
  330. #+END_SRC
  331. * Bookmarks
  332. Usage:
  333. - C-x r m (bookmark-set): add bookmark
  334. - C-x r l (list-bookmark): list bookmarks
  335. - C-x r b (bookmark-jump): open bookmark
  336. Edit bookmarks (while in bookmark file):
  337. - d: mark current item
  338. - x: delete marked items
  339. - r: rename current item
  340. - s: save changes
  341. #+begin_src emacs-lisp
  342. (use-package bookmark
  343. :custom
  344. (bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks")))
  345. #+end_src
  346. Some windows specific stuff
  347. #+BEGIN_SRC emacs-lisp
  348. (when *sys/windows*
  349. (remove-hook 'find-file-hook 'vc-refresh-state)
  350. ; (progn
  351. ; (setq gc-cons-threshold (* 511 1024 1024)
  352. ; gc-cons-percentage 0.5
  353. ; garbage-collection-messages t
  354. ; (run-with-idle-timer 5 t #'garbage-collect))
  355. (when (boundp 'w32-pipe-read-delay)
  356. (setq w32-pipe-read-delay 0))
  357. (when (boundp 'w32-get-true-file-attributes)
  358. (setq w32-get-true-file-attributes nil)))
  359. #+END_SRC
  360. * recentf
  361. Exclude some dirs from spamming recentf
  362. #+begin_src emacs-lisp
  363. (use-package recentf
  364. ; :defer 1
  365. :config
  366. (recentf-mode)
  367. :custom
  368. (recentf-exclude '(".*-autoloads\\.el\\'"
  369. "[/\\]\\elpa/"
  370. "COMMIT_EDITMSG\\'"))
  371. (recentf-save-file (concat MY--PATH_USER_LOCAL "recentf"))
  372. (recentf-max-menu-items 600)
  373. (recentf-max-saved-items 600))
  374. #+end_src
  375. * savehist
  376. #+begin_src emacs-lisp
  377. (use-package savehist
  378. :config
  379. (savehist-mode)
  380. :custom
  381. (savehist-file (concat MY--PATH_USER_LOCAL "history")))
  382. #+end_src
  383. * undo
  384. #+BEGIN_SRC emacs-lisp
  385. (use-package undo-tree
  386. :ensure t
  387. :diminish undo-tree-mode
  388. :init
  389. (global-undo-tree-mode 1)
  390. :custom
  391. (undo-tree-auto-save-history nil))
  392. #+END_SRC
  393. * COMMENT ace-window (now avy)
  394. #+begin_src emacs-lisp
  395. (use-package ace-window
  396. :ensure t
  397. :bind
  398. (:map global-map
  399. ("C-x o" . ace-window)))
  400. #+end_src
  401. * imenu-list
  402. A minor mode to show imenu in a sidebar.
  403. Call imenu-list-smart-toggle.
  404. [[https://github.com/bmag/imenu-list][Source]]
  405. #+BEGIN_SRC emacs-lisp
  406. (use-package imenu-list
  407. :ensure t
  408. :demand t ; otherwise mode loads too late and won't work on first file it's being activated on
  409. :config
  410. (setq imenu-list-focus-after-activation t
  411. imenu-list-auto-resize t
  412. imenu-list-position 'right)
  413. :bind
  414. (:map global-map
  415. ([f9] . imenu-list-smart-toggle))
  416. :custom
  417. (org-imenu-depth 4))
  418. #+END_SRC
  419. * which-key
  420. #+BEGIN_SRC emacs-lisp
  421. (use-package which-key
  422. :ensure t
  423. :diminish which-key-mode
  424. :defer t
  425. :hook
  426. (after-init . which-key-mode)
  427. :config
  428. (which-key-setup-side-window-bottom)
  429. (setq which-key-idle-delay 0.5))
  430. #+END_SRC
  431. * abbrev
  432. #+begin_src emacs-lisp
  433. (use-package abbrev
  434. :diminish abbrev-mode
  435. :hook
  436. ((text-mode org-mode) . abbrev-mode)
  437. :init
  438. (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_tables.el"))
  439. :config
  440. (if (file-exists-p abbrev-file-name)
  441. (quietly-read-abbrev-file))
  442. (setq save-abbrevs 'silently)) ;; don't bother me with asking for abbrev saving
  443. #+end_src
  444. * COMMENT Evil (now meow)
  445. #+BEGIN_SRC emacs-lisp
  446. (use-package evil
  447. :ensure t
  448. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  449. :init
  450. (setq evil-want-C-i-jump nil) ;; prevent evil from blocking TAB in org tree expanding
  451. :config
  452. (evil-mode 1))
  453. #+END_SRC
  454. * Meow
  455. #+begin_src emacs-lisp
  456. (use-package meow
  457. :ensure t
  458. :config
  459. (setq meow-cheatsheet-layout meow-cheatsheet-layout-qwerty)
  460. (meow-motion-overwrite-define-key
  461. '("j" . meow-next)
  462. '("k" . meow-prev)
  463. '("<escape>" . ignore))
  464. (meow-leader-define-key
  465. ;; SPC j/k will run the original command in MOTION state.
  466. '("j" . "H-j")
  467. '("k" . "H-k")
  468. ;; Use SPC (0-9) for digit arguments.
  469. '("1" . meow-digit-argument)
  470. '("2" . meow-digit-argument)
  471. '("3" . meow-digit-argument)
  472. '("4" . meow-digit-argument)
  473. '("5" . meow-digit-argument)
  474. '("6" . meow-digit-argument)
  475. '("7" . meow-digit-argument)
  476. '("8" . meow-digit-argument)
  477. '("9" . meow-digit-argument)
  478. '("0" . meow-digit-argument)
  479. '("/" . meow-keypad-describe-key)
  480. '("?" . meow-cheatsheet))
  481. (meow-normal-define-key
  482. '("0" . meow-expand-0)
  483. '("9" . meow-expand-9)
  484. '("8" . meow-expand-8)
  485. '("7" . meow-expand-7)
  486. '("6" . meow-expand-6)
  487. '("5" . meow-expand-5)
  488. '("4" . meow-expand-4)
  489. '("3" . meow-expand-3)
  490. '("2" . meow-expand-2)
  491. '("1" . meow-expand-1)
  492. '("-" . negative-argument)
  493. '(";" . meow-reverse)
  494. '("," . meow-inner-of-thing)
  495. '("." . meow-bounds-of-thing)
  496. '("[" . meow-beginning-of-thing)
  497. '("]" . meow-end-of-thing)
  498. '("a" . meow-append)
  499. '("A" . meow-open-below)
  500. '("b" . meow-back-word)
  501. '("B" . meow-back-symbol)
  502. '("c" . meow-change)
  503. '("d" . meow-delete)
  504. '("D" . meow-backward-delete)
  505. '("e" . meow-next-word)
  506. '("E" . meow-next-symbol)
  507. '("f" . meow-find)
  508. '("g" . meow-cancel-selection)
  509. '("G" . meow-grab)
  510. '("h" . meow-left)
  511. '("H" . meow-left-expand)
  512. '("i" . meow-insert)
  513. '("I" . meow-open-above)
  514. '("j" . meow-next)
  515. '("J" . meow-next-expand)
  516. '("k" . meow-prev)
  517. '("K" . meow-prev-expand)
  518. '("l" . meow-right)
  519. '("L" . meow-right-expand)
  520. '("m" . meow-join)
  521. '("n" . meow-search)
  522. '("o" . meow-block)
  523. '("O" . meow-to-block)
  524. '("p" . meow-yank)
  525. '("q" . meow-quit)
  526. '("Q" . meow-goto-line)
  527. '("r" . meow-replace)
  528. '("R" . meow-swap-grab)
  529. '("s" . meow-kill)
  530. '("t" . meow-till)
  531. '("u" . meow-undo)
  532. '("U" . meow-undo-in-selection)
  533. '("v" . meow-visit)
  534. '("w" . meow-mark-word)
  535. '("W" . meow-mark-symbol)
  536. '("x" . meow-line)
  537. '("X" . meow-goto-line)
  538. '("y" . meow-save)
  539. '("Y" . meow-sync-grab)
  540. '("z" . meow-pop-selection)
  541. '("'" . repeat)
  542. '("<escape>" . ignore))
  543. ; :config
  544. (meow-global-mode t))
  545. #+end_src
  546. * General (key mapper)
  547. #+BEGIN_SRC emacs-lisp
  548. (use-package general
  549. :ensure t)
  550. (general-define-key
  551. :states 'normal
  552. :keymaps 'imenu-list-major-mode-map
  553. "RET" '(imenu-list-goto-entry :which-key "goto")
  554. "TAB" '(hs-toggle-hiding :which-key "collapse")
  555. "d" '(imenu-list-display-entry :which-key "show")
  556. "q" '(imenu-list-quit-window :which-key "quit"))
  557. #+END_SRC
  558. * avy
  559. Search, move, copy, delete text within all visible buffers.
  560. Also replaces ace-window for buffer switching.
  561. [[https://github.com/abo-abo/avy]]
  562. #+BEGIN_SRC emacs-lisp
  563. (use-package avy
  564. :ensure t
  565. :bind ("M-s w" . avy-goto-char-2))
  566. #+END_SRC
  567. * Vertico & Orderless
  568. Vertico is a completion ui.
  569. Orderless orders the suggestions by recency. The package prescient orders by frequency.
  570. [[https://github.com/minad/vertico][Vertico Github]]
  571. [[https://github.com/oantolin/orderless][Orderless Github]]
  572. #+begin_src emacs-lisp
  573. ;; completion ui
  574. (use-package vertico
  575. :ensure t
  576. :init
  577. (vertico-mode))
  578. (use-package orderless
  579. :ensure t
  580. :init
  581. (setq completion-styles '(orderless basic)
  582. completion-category-defaults nil
  583. completion-category-overrides '((file (styles partial-completion)))))
  584. #+end_src
  585. * Consult
  586. [[https://github.com/minad/consult][Github]]
  587. #+begin_src emacs-lisp
  588. (use-package consult
  589. :ensure t
  590. :bind
  591. (("C-x C-r" . consult-recent-file)
  592. ("C-x b" . consult-buffer)
  593. ("C-s" . consult-line))
  594. :config
  595. ;; disable preview for some commands and buffers
  596. ;; and enable it by M-.
  597. ;; see https://github.com/minad/consult#use-package-example
  598. (consult-customize
  599. consult-theme
  600. :preview-key '(debounce 0.2 any)
  601. consult-ripgrep consult-git-grep consult-grep
  602. consult-bookmark consult-recent-file consult-xref
  603. consult--source-bookmark consult--source-file-register
  604. consult--source-recent-file consult--source-project-recent-file
  605. :preview-key (kbd "M-.")))
  606. #+end_src
  607. * Marginalia
  608. [[https://github.com/minad/marginalia/][Github]]
  609. Adds additional information to the minibuffer
  610. #+begin_src emacs-lisp
  611. (use-package marginalia
  612. :ensure t
  613. :init
  614. (marginalia-mode)
  615. :bind
  616. (:map minibuffer-local-map
  617. ("M-A" . marginalia-cycle))
  618. :custom
  619. ;; switch by 'marginalia-cycle
  620. (marginalia-annotators '(marginalia-annotators-heavy
  621. marginalia-annotators-light
  622. nil)))
  623. #+end_src
  624. * Embark
  625. Does stuff in the minibuffer results
  626. #+begin_src emacs-lisp
  627. (use-package embark
  628. :ensure t
  629. :bind
  630. (("C-S-a" . embark-act)
  631. ("C-h B" . embark-bindings))
  632. :init
  633. (setq prefix-help-command #'embark-prefix-help-command)
  634. :config
  635. ;; hide modeline of the embark live/completions buffers
  636. (add-to-list 'display-buffer-alist
  637. '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
  638. nil
  639. (window-parameters (mode-line-format . none)))))
  640. (use-package embark-consult
  641. :ensure t
  642. :after (embark consult)
  643. :demand t
  644. :hook
  645. (embark-collect-mode . embark-consult-preview-minor-mode))
  646. #+end_src
  647. * COMMENT Helm
  648. As an alternative if I'm not happy with selectrum & co
  649. #+begin_src emacs-lisp
  650. (use-package helm
  651. :ensure t
  652. :hook
  653. (helm-mode . helm-autoresize-mode)
  654. ;; :bind
  655. ;; (("M-x" . helm-M-x)
  656. ;; ("C-s" . helm-occur)
  657. ;; ("C-x C-f" . helm-find-files)
  658. ;; ("C-x C-b" . helm-buffers-list)
  659. ;; ("C-x b" . helm-buffers-list)
  660. ;; ("C-x C-r" . helm-recentf)
  661. ;; ("C-x C-i" . helm-imenu))
  662. :config
  663. (helm-mode)
  664. :custom
  665. (helm-split-window-inside-p t) ;; open helm buffer inside current window
  666. (helm-move-to-line-cycle-in-source t)
  667. (helm-echo-input-in-header-line t)
  668. (helm-autoresize-max-height 20)
  669. (helm-autoresize-min-height 5)
  670. )
  671. #+end_src
  672. * COMMENT ivy / counsel / swiper
  673. #+BEGIN_SRC emacs-lisp
  674. ; (require 'ivy)
  675. (use-package ivy
  676. :ensure t
  677. :diminish
  678. (ivy-mode . "")
  679. :defer t
  680. :init
  681. (ivy-mode 1)
  682. :bind
  683. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  684. :config
  685. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  686. ivy-height 20 ;; height of ivy window
  687. ivy-count-format "%d/%d" ;; current and total number
  688. ivy-re-builders-alist ;; regex replaces spaces with *
  689. '((t . ivy--regex-plus))))
  690. ; make counsel-M-x more descriptive
  691. (use-package ivy-rich
  692. :ensure t
  693. :defer t
  694. :init
  695. (ivy-rich-mode 1))
  696. (use-package counsel
  697. :ensure t
  698. :defer t
  699. :bind
  700. (("M-x" . counsel-M-x)
  701. ("C-x C-f" . counsel-find-file)
  702. ("C-x C-r" . counsel-recentf)
  703. ("C-x b" . counsel-switch-buffer)
  704. ("C-c C-f" . counsel-git)
  705. ("C-c h f" . counsel-describe-function)
  706. ("C-c h v" . counsel-describe-variable)
  707. ("M-i" . counsel-imenu)))
  708. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  709. ; ("C-r" . 'counsel-minibuffer-history)))
  710. (use-package swiper
  711. :ensure t
  712. :bind
  713. ("C-s" . swiper))
  714. (use-package ivy-hydra
  715. :ensure t)
  716. #+END_SRC
  717. * outlook
  718. In outlook a macro is necessary, also a reference to FM20.DLL
  719. (Microsoft Forms 2.0 Object Library, in c:\windows\syswow64\fm20.dll)
  720. The macro copies the GUID of the email to the clipboard
  721. Attention: the GUID changes when the email is moved to another folder!
  722. The macro:
  723. #+BEGIN_SRC
  724. Sub AddLinkToMessageInClipboard()
  725. 'Adds a link to the currently selected message to the clipboard
  726. Dim objMail As Outlook.MailItem
  727. Dim doClipboard As New DataObject
  728. 'One and ONLY one message muse be selected
  729. If Application.ActiveExplorer.Selection.Count <> 1 Then
  730. MsgBox ("Select one and ONLY one message.")
  731. Exit Sub
  732. End If
  733. Set objMail = Application.ActiveExplorer.Selection.Item(1)
  734. doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
  735. doClipboard.PutInClipboard
  736. End Sub
  737. #+END_SRC
  738. #+BEGIN_SRC emacs-lisp
  739. (use-package org
  740. :config
  741. (org-add-link-type "outlook" 'my--org-outlook-open))
  742. (defun my--org-outlook-open (id)
  743. (w32-shell-execute "open" "outlook" (concat " /select outlook:" id)))
  744. (defun my/org-outlook-open-test ()
  745. (interactive)
  746. (w32-shell-execute "open" "outlook" " /select outlook:000000008A209C397CEF2C4FBA9E54AEB5B1F97F0700846D043B407C5B43A0C05AFC46DC5C630587BE5E020900006E48FF8F6027694BA6593777F542C19E0002A6434D000000"))'
  747. #+END_SRC
  748. (w32-shell-execute "open" "outlook" " /select outlook:000000008A209C397CEF2C4FBA9E54AEB5B1F97F0700846D043B407C5B43A0C05AFC46DC5C630587BE5E020900006E48FF8F6027694BA6593777F542C19E0002A6434D000000")
  749. [[outlook:000000008A209C397CEF2C4FBA9E54AEB5B1F97F0700846D043B407C5B43A0C05AFC46DC5C630587BE5E020900006E48FF8F6027694BA6593777F542C19E0002A6434D000000][MESSAGE: AW: Offene LS Doray (Dennis Cornels)]]
  750. [[outlook:000000008A209C397CEF2C4FBA9E54AEB5B1F97F0700846D043B407C5B43A0C05AFC46DC5C630587BE5E020900006E48FF8F6027694BA6593777F542C19E0002A6434D000000]]
  751. * misc
  752. #+begin_src emacs-lisp
  753. (use-package autorevert
  754. :diminish auto-revert-mode)
  755. #+end_src
  756. * company
  757. #+BEGIN_SRC emacs-lisp
  758. (use-package company
  759. :defer 1
  760. :diminish
  761. :defer t
  762. :bind
  763. (("C-<tab>" . company-complete)
  764. :map company-active-map
  765. ("RET" . nil)
  766. ([return] . nil)
  767. ("TAB" . company-complete-selection)
  768. ([tab] . company-complete-selection)
  769. ("<right>" . company-complete-common)
  770. ("<escape>" . company-abort))
  771. :hook
  772. (after-init . global-company-mode)
  773. (emacs-lisp-mode . my--company-elisp)
  774. (org-mode . my--company-org)
  775. :config
  776. (defun my--company-elisp ()
  777. (message "set up company for elisp")
  778. (set (make-local-variable 'company-backends)
  779. '(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp
  780. company-yasnippet
  781. company-dabbrev-code
  782. company-files)))
  783. (defun my--company-org ()
  784. (set (make-local-variable 'company-backends)
  785. '(company-capf company-files))
  786. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  787. (message "setup company for org"))
  788. (setq company-idle-delay .2
  789. company-minimum-prefix-length 1
  790. company-require-match nil
  791. company-show-numbers t
  792. company-tooltip-align-annotations t))
  793. (use-package company-statistics
  794. :ensure t
  795. :after company
  796. :defer t
  797. :init
  798. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  799. :config
  800. (company-statistics-mode 1))
  801. (use-package company-dabbrev
  802. :ensure nil
  803. :after company
  804. :defer t
  805. :config
  806. (setq-default company-dabbrev-downcase nil))
  807. ;; adds a info box right of the cursor with doc of the function
  808. (use-package company-box
  809. :ensure t
  810. :diminish
  811. :defer t
  812. :hook
  813. (company-mode . company-box-mode))
  814. ; :init
  815. ; (add-hook 'company-mode-hook 'company-box-mode))
  816. #+END_SRC
  817. * orgmode
  818. ** some notes
  819. *** copy file path within emacs
  820. Enter dired-other-window
  821. place cursor on the file
  822. M-0 w (copy absolute path)
  823. C-u w (copy relative path)
  824. *** Archiving
  825. C-c C-x C-a
  826. To keep the subheading structure when archiving, set the properties of the superheading.
  827. #+begin_src org :tangle no
  828. ,* FOO
  829. :PROPERTIES:
  830. :ARCHIVE: %s_archive::* FOO
  831. ,** DONE BAR
  832. ,** TODO BAZ
  833. #+end_src
  834. When moving BAR to archive, it will go to FILENAME.org_archive below the heading FOO.
  835. [[http://doc.endlessparentheses.com/Var/org-archive-location.html][Other examples]]
  836. ** org
  837. #+BEGIN_SRC emacs-lisp
  838. (defun my--buffer-prop-set (name value)
  839. "Set a file property called NAME to VALUE in buffer file.
  840. If the property is already set, replace its value."
  841. (setq name (downcase name))
  842. (org-with-point-at 1
  843. (let ((case-fold-search t))
  844. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  845. (point-max) t)
  846. (replace-match (concat "#+" name ": " value) 'fixedcase)
  847. (while (and (not (eobp))
  848. (looking-at "^[#:]"))
  849. (if (save-excursion (end-of-line) (eobp))
  850. (progn
  851. (end-of-line)
  852. (insert "\n"))
  853. (forward-line)
  854. (beginning-of-line)))
  855. (insert "#+" name ": " value "\n")))))
  856. (defun my--buffer-prop-remove (name)
  857. "Remove a buffer property called NAME."
  858. (org-with-point-at 1
  859. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  860. (point-max) t)
  861. (replace-match ""))))
  862. (use-package org
  863. :ensure t
  864. :mode (("\.org$" . org-mode))
  865. :diminish org-indent-mode
  866. :defer 1
  867. :hook
  868. (org-mode . org-indent-mode)
  869. (org-source-mode . smartparens-mode)
  870. :bind (("C-c l" . org-store-link)
  871. ("C-c c" . org-capture)
  872. ("C-c a" . org-agenda)
  873. :map org-mode-map ("S-<right>" . org-shiftright)
  874. ("S-<left>" . org-shiftleft))
  875. :init
  876. (defun my--org-company ()
  877. (set (make-local-variable 'company-backends)
  878. '(company-capf company-files))
  879. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  880. (defun my--org-agenda-files-set ()
  881. "Sets default agenda files.
  882. Necessary when updating roam agenda todos."
  883. (setq org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  884. (concat MY--PATH_ORG_FILES "projects.org")
  885. (concat MY--PATH_ORG_FILES "tasks.org")))
  886. (when *sys/linux*
  887. (nconc org-agenda-files
  888. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$"))))
  889. (my--org-agenda-files-set)
  890. :config
  891. :custom
  892. (when *sys/linux*
  893. (org-pretty-entities t))
  894. (org-startup-truncated t)
  895. (org-startup-align-all-tables t)
  896. (org-src-fontify-natively t) ;; use syntax highlighting in code blocks
  897. (org-src-preserve-indentation t) ;; no extra indentation
  898. (org-src-window-setup 'current-window) ;; C-c ' opens in current window
  899. (org-modules (quote (org-id
  900. org-habit
  901. org-tempo))) ;; easy templates
  902. (org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org"))
  903. (org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations"))
  904. (org-log-into-drawer "LOGBOOK")
  905. (org-log-done 'time) ;; create timestamp when task is done
  906. (org-blank-before-new-entry '((heading) (plain-list-item))) ;; prevent new line before new item
  907. (org-src-tab-acts-natively t))
  908. #+END_SRC
  909. Custom keywords, depending on environment
  910. #+BEGIN_SRC emacs-lisp
  911. (use-package org
  912. :if *work_remote*
  913. :custom
  914. (org-todo-keywords
  915. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  916. #+END_SRC
  917. ** org-agenda
  918. Sort agenda by deadline and priority
  919. #+BEGIN_SRC emacs-lisp
  920. (use-package org
  921. :ensure t
  922. :custom
  923. (org-agenda-sorting-strategy
  924. (quote
  925. ((agenda deadline-up priority-down)
  926. (todo priority-down category-keep)
  927. (tags priority-down category-keep)
  928. (search category-keep)))))
  929. #+END_SRC
  930. Customize the org agenda
  931. #+BEGIN_SRC emacs-lisp
  932. (defun my--org-skip-subtree-if-priority (priority)
  933. "Skip an agenda subtree if it has a priority of PRIORITY.
  934. PRIORITY may be one of the characters ?A, ?B, or ?C."
  935. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  936. (pri-value (* 1000 (- org-lowest-priority priority)))
  937. (pri-current (org-get-priority (thing-at-point 'line t))))
  938. (if (= pri-value pri-current)
  939. subtree-end
  940. nil)))
  941. (use-package org
  942. :ensure t
  943. :custom
  944. (org-agenda-custom-commands
  945. '(("c" "Simple agenda view"
  946. ((tags "PRIORITY=\"A\""
  947. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  948. (org-agenda-overriding-header "Hohe Priorität:")))
  949. (agenda ""
  950. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  951. (org-agenda-span 7)
  952. (org-agenda-start-on-weekday nil)
  953. (org-agenda-overriding-header "Nächste 7 Tage:")))
  954. (alltodo ""
  955. ((org-agenda-skip-function '(or (my--org-skip-subtree-if-priority ?A)
  956. (org-agenda-skip-if nil '(scheduled deadline))))
  957. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))))
  958. #+END_SRC
  959. ** languages
  960. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  961. #+begin_src emacs-lisp
  962. (use-package ob-org
  963. :defer t
  964. :ensure org-contrib
  965. :commands
  966. (org-babel-execute:org
  967. org-babel-expand-body:org))
  968. (use-package ob-python
  969. :defer t
  970. :ensure org-contrib
  971. :commands (org-babel-execute:python))
  972. (use-package ob-js
  973. :defer t
  974. :ensure org-contrib
  975. :commands (org-babel-execute:js))
  976. (use-package ob-shell
  977. :defer t
  978. :ensure org-contrib
  979. :commands
  980. (org-babel-execute:sh
  981. org-babel-expand-body:sh
  982. org-babel-execute:bash
  983. org-babel-expand-body:bash))
  984. (use-package ob-emacs-lisp
  985. :defer t
  986. :ensure org-contrib
  987. :commands
  988. (org-babel-execute:emacs-lisp
  989. org-babel-expand-body:emacs-lisp))
  990. (use-package ob-lisp
  991. :defer t
  992. :ensure org-contrib
  993. :commands
  994. (org-babel-execute:lisp
  995. org-babel-expand-body:lisp))
  996. (use-package ob-gnuplot
  997. :defer t
  998. :ensure org-contrib
  999. :commands
  1000. (org-babel-execute:gnuplot
  1001. org-babel-expand-body:gnuplot))
  1002. (use-package ob-sqlite
  1003. :defer t
  1004. :ensure org-contrib
  1005. :commands
  1006. (org-babel-execute:sqlite
  1007. org-babel-expand-body:sqlite))
  1008. (use-package ob-latex
  1009. :defer t
  1010. :ensure org-contrib
  1011. :commands
  1012. (org-babel-execute:latex
  1013. org-babel-expand-body:latex))
  1014. (use-package ob-R
  1015. :defer t
  1016. :ensure org-contrib
  1017. :commands
  1018. (org-babel-execute:R
  1019. org-babel-expand-body:R))
  1020. (use-package ob-scheme
  1021. :defer t
  1022. :ensure org-contrib
  1023. :commands
  1024. (org-babel-execute:scheme
  1025. org-babel-expand-body:scheme))
  1026. #+end_src
  1027. ** habits
  1028. #+BEGIN_SRC emacs-lisp
  1029. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  1030. ;; (add-to-list 'org-modules "org-habit")
  1031. (setq org-habit-graph-column 80
  1032. org-habit-preceding-days 30
  1033. org-habit-following-days 7
  1034. org-habit-show-habits-only-for-today nil)
  1035. #+END_SRC
  1036. ** *TODO*
  1037. [[https://github.com/alphapapa/org-ql][org-ql]]
  1038. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  1039. ** org-caldav
  1040. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  1041. #+BEGIN_SRC emacs-lisp
  1042. ;;(use-package org-caldav
  1043. ;; :ensure t
  1044. ;; :config
  1045. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  1046. ;; org-caldav-calendar-id "orgmode"
  1047. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  1048. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  1049. #+END_SRC
  1050. ** journal
  1051. [[https://github.com/bastibe/org-journal][Source]]
  1052. Ggf. durch org-roam-journal ersetzen
  1053. #+BEGIN_SRC emacs-lisp
  1054. (use-package org-journal
  1055. :if *sys/linux*
  1056. :ensure t
  1057. :defer t
  1058. :config
  1059. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  1060. (when (and (boundp 'org-journal-dir)
  1061. (boundp 'org-journal-enable-agenda-integration))
  1062. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  1063. org-journal-enable-agenda-integration t)))
  1064. #+END_SRC
  1065. ** org-roam
  1066. [[https://github.com/org-roam/org-roam][Github]]
  1067. Um Headings innerhalb einer Datei zu verlinken:
  1068. - org-id-get-create im Heading,
  1069. - org-roam-node-insert in der verweisenden Datei
  1070. Bei Problemen wie unique constraint
  1071. org-roam-db-clear-all
  1072. org-roam-db-sync
  1073. #+BEGIN_SRC emacs-lisp
  1074. (use-package org-roam
  1075. :ensure t
  1076. :defer 2
  1077. :after org
  1078. :init
  1079. (setq org-roam-v2-ack t)
  1080. (defun my--roamtodo-p ()
  1081. "Return non-nil if current buffer has any todo entry.
  1082. TODO entries marked as done are ignored, meaning this function
  1083. returns nil if current buffer contains only completed tasks."
  1084. (seq-find
  1085. (lambda (type)
  1086. (eq type 'todo))
  1087. (org-element-map
  1088. (org-element-parse-buffer 'headline)
  1089. 'headline
  1090. (lambda (h)
  1091. (org-element-property :todo-type h)))))
  1092. (defun my--roamtodo-update-tag ()
  1093. "Update ROAMTODO tag in the current buffer."
  1094. (when (and (not (active-minibuffer-window))
  1095. (my--buffer-roam-note-p))
  1096. (save-excursion
  1097. (goto-char (point-min))
  1098. (let* ((tags (my--buffer-tags-get))
  1099. (original-tags tags))
  1100. (if (my--roamtodo-p)
  1101. (setq tags (cons "roamtodo" tags))
  1102. (setq tags (remove "roamtodo" tags)))
  1103. ;;cleanup duplicates
  1104. (when (or (seq-difference tags original-tags)
  1105. (seq-difference original-tags tags))
  1106. (apply #'my--buffer-tags-set tags))))))
  1107. (defun my--buffer-tags-get ()
  1108. "Return filetags value in current buffer."
  1109. (my--buffer-prop-get-list "filetags" "[ :]"))
  1110. (defun my--buffer-tags-set (&rest tags)
  1111. "Set TAGS in current buffer.
  1112. If filetags value is already set, replace it."
  1113. (if tags
  1114. (my--buffer-prop-set
  1115. "filetags" (concat ":" (string-join tags ":") ":"))
  1116. (my--buffer-prop-remove "filetags")))
  1117. (defun my--buffer-tags-add (tag)
  1118. "Add a TAG to filetags in current buffer."
  1119. (let* ((tags (my--buffer-tags-get))
  1120. (tags (append tags (list tag))))
  1121. (apply #'my--buffer-tags-set tags)))
  1122. (defun my--buffer-tags-remove (tag)
  1123. "Remove a TAG from filetags in current buffer."
  1124. (let* ((tags (my--buffer-tags-get))
  1125. (tags (delete tag tags)))
  1126. (apply #'my--buffer-tags-set tags)))
  1127. (defun my--buffer-prop-set (name value)
  1128. "Set a file property called NAME to VALUE in buffer file.
  1129. If the property is already set, replace its value."
  1130. (setq name (downcase name))
  1131. (org-with-point-at 1
  1132. (let ((case-fold-search t))
  1133. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  1134. (point-max) t)
  1135. (replace-match (concat "#+" name ": " value) 'fixedcase)
  1136. (while (and (not (eobp))
  1137. (looking-at "^[#:]"))
  1138. (if (save-excursion (end-of-line) (eobp))
  1139. (progn
  1140. (end-of-line)
  1141. (insert "\n"))
  1142. (forward-line)
  1143. (beginning-of-line)))
  1144. (insert "#+" name ": " value "\n")))))
  1145. (defun my--buffer-prop-set-list (name values &optional separators)
  1146. "Set a file property called NAME to VALUES in current buffer.
  1147. VALUES are quoted and combined into single string using
  1148. `combine-and-quote-strings'.
  1149. If SEPARATORS is non-nil, it should be a regular expression
  1150. matching text that separates, but is not part of, the substrings.
  1151. If nil it defaults to `split-string-and-unquote', normally
  1152. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t.
  1153. If the property is already set, replace its value."
  1154. (my--buffer-prop-set
  1155. name (combine-and-quote-strings values separators)))
  1156. (defun my--buffer-prop-get (name)
  1157. "Get a buffer property called NAME as a string."
  1158. (org-with-point-at 1
  1159. (when (re-search-forward (concat "^#\\+" name ": \\(.*\\)")
  1160. (point-max) t)
  1161. (buffer-substring-no-properties
  1162. (match-beginning 1)
  1163. (match-end 1)))))
  1164. (defun my--buffer-prop-get-list (name &optional separators)
  1165. "Get a buffer property NAME as a list using SEPARATORS.
  1166. If SEPARATORS is non-nil, it should be a regular expression
  1167. matching text that separates, but is not part of, the substrings.
  1168. If nil it defaults to `split-string-default-separators', normally
  1169. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t."
  1170. (let ((value (my--buffer-prop-get name)))
  1171. (when (and value (not (string-empty-p value)))
  1172. (split-string-and-unquote value separators))))
  1173. (defun my--buffer-prop-remove (name)
  1174. "Remove a buffer property called NAME."
  1175. (org-with-point-at 1
  1176. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  1177. (point-max) t)
  1178. (replace-match ""))))
  1179. (defun my--buffer-roam-note-p ()
  1180. "Return non-nil if the currently visited buffer is a note."
  1181. (and buffer-file-name
  1182. (string-prefix-p
  1183. (expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM))
  1184. (file-name-directory buffer-file-name))))
  1185. (defun my--org-roam-filter-by-tag (tag-name)
  1186. (lambda (node)
  1187. (member tag-name (org-roam-node-tags node))))
  1188. (defun my--org-roam-list-notes-by-tag (tag-name)
  1189. (mapcar #'org-roam-node-file
  1190. (seq-filter
  1191. (my--org-roam-filter-by-tag tag-name)
  1192. (org-roam-node-list))))
  1193. (defun my/org-roam-refresh-agenda-list ()
  1194. "Add all org roam files with #+filetags: roamtodo"
  1195. (interactive)
  1196. (my--org-agenda-files-set)
  1197. (nconc org-agenda-files
  1198. (my--org-roam-list-notes-by-tag "roamtodo"))
  1199. (setq org-agenda-files (delete-dups org-agenda-files)))
  1200. (add-hook 'find-file-hook #'my--roamtodo-update-tag)
  1201. (add-hook 'before-save-hook #'my--roamtodo-update-tag)
  1202. (advice-add 'org-agenda :before #'my/org-roam-refresh-agenda-list)
  1203. (advice-add 'org-todo-list :before #'my/org-roam-refresh-agenda-list)
  1204. (add-to-list 'org-tags-exclude-from-inheritance "roamtodo")
  1205. :config
  1206. (require 'org-roam-dailies) ;; ensure the keymap is available
  1207. (org-roam-db-autosync-mode)
  1208. ;; build the agenda list the first ime for the session
  1209. (my/org-roam-refresh-agenda-list)
  1210. :custom
  1211. (org-roam-directory MY--PATH_ORG_ROAM)
  1212. (org-roam-completion-everywhere t)
  1213. (org-roam-capture-templates
  1214. '(("n" "note" plain
  1215. "%?"
  1216. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1217. :unnarrowed t)
  1218. ("i" "idea" plain
  1219. "%?"
  1220. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1221. :unnarrowed t)
  1222. ))
  1223. :bind (("C-c n l" . org-roam-buffer-toggle)
  1224. ("C-c n f" . org-roam-node-find)
  1225. ("C-c n i" . org-roam-node-insert)
  1226. :map org-mode-map
  1227. ("C-M-i" . completion-at-point)
  1228. :map org-roam-dailies-map
  1229. ("Y" . org-roam-dailies-capture-yesterday)
  1230. ("T" . org-roam-dailies-capture-tomorrow))
  1231. :bind-keymap
  1232. ("C-c n d" . org-roam-dailies-map))
  1233. (when *sys/windows*
  1234. (use-package emacsql-sqlite3
  1235. :ensure t
  1236. :init
  1237. (setq emacsql-sqlite3-binary "P:/Tools/sqlite/sqlite3.exe")
  1238. exec-path (append exec-path '("P:/Tools/sqlite")))
  1239. (use-package org-roam
  1240. :requires emacsql-sqlite3
  1241. :init
  1242. :custom
  1243. (add-to-list 'org-roam-capture-templates
  1244. '("t" "telephone call" plain
  1245. "%?"
  1246. :if-new (file+head "telephone/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: CALL %<%Y-%m-%d %H:%M> ${title}\n")
  1247. :unnarrowed t) t)
  1248. (add-to-list 'org-roam-capture-templates
  1249. '("p" "project" plain
  1250. "%?"
  1251. :if-new (file+head "projects/${slug}.org" "#+title: ${title}\n#+filetags: :project:\n")
  1252. :unnarrowed t) t)
  1253. (add-to-list 'org-roam-capture-templates
  1254. '("s" "Sicherheitenmeldung" plain
  1255. "*** TODO [#A] Sicherheitenmeldung ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1256. :target (file+olp "tasks.org" ("Todos" "Sicherheitenmeldungen"))) t)
  1257. (add-to-list 'org-roam-capture-templates
  1258. '("m" "Monatsbericht" plain'
  1259. "*** TODO [#A] Monatsbericht ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1260. :target (file+olp "tasks.org" ("Todos" "Monatsberichte"))) t)
  1261. (org-roam-database-connector 'sqlite3)))
  1262. #+END_SRC
  1263. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  1264. * Programming
  1265. ** misc
  1266. #+begin_src emacs-lisp
  1267. (use-package eldoc
  1268. :diminish eldoc-mode
  1269. :defer t)
  1270. #+end_src
  1271. ** Magit / Git
  1272. Little crash course in magit:
  1273. - magit-init to init a git project
  1274. - magit-status (C-x g) to call the status window
  1275. In status buffer:
  1276. - s stage files
  1277. - u unstage files
  1278. - U unstage all files
  1279. - a apply changes to staging
  1280. - c c commit (type commit message, then C-c C-c to commit)
  1281. - b b switch to another branch
  1282. - P u git push
  1283. - F u git pull
  1284. #+BEGIN_SRC emacs-lisp
  1285. (use-package magit
  1286. :ensure t
  1287. ; :pin melpa-stable
  1288. :defer t
  1289. :init
  1290. ; set git-path in work environment
  1291. (if (string-equal user-login-name "POH")
  1292. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1293. )
  1294. :bind (("C-x g" . magit-status)))
  1295. #+END_SRC
  1296. ** COMMENT Eglot (can't do dap-mode)
  1297. for python pyls (in env: pip install python-language-server) seems to work better than pyright (npm install -g pyright),
  1298. at least pandas couldnt be resolved in pyright
  1299. #+begin_src emacs-lisp
  1300. (use-package eglot
  1301. :ensure t
  1302. :init
  1303. (setq completion-category-overrides '((eglot (styles orderless)))))
  1304. #+end_src
  1305. ** LSP (now eglot)
  1306. Configuration for the language server protocol
  1307. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  1308. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  1309. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  1310. TODO Unterverzeichnisse wurden noch nicht getestet
  1311. #+BEGIN_SRC emacs-lisp
  1312. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  1313. (use-package lsp-mode
  1314. :defer t
  1315. :commands (lsp lsp-execute-code-action)
  1316. :custom
  1317. (lsp-auto-guess-root nil)
  1318. (lsp-prefer-flymake nil) ; use flycheck instead
  1319. (lsp-prefer-capf t)
  1320. (lsp-file-watch-threshold 5000)
  1321. (lsp-print-performance t)
  1322. (lsp-log-io nil) ; enable log only for debug
  1323. (lsp-enable-folding t) ; default, maybe evil-matchit instead for performance?
  1324. (lsp-diagnostics-modeline-scope :project)
  1325. (lsp-enable-file-watchers nil)
  1326. (lsp-session-file (concat MY--PATH_USER_LOCAL "lsp-session"))
  1327. (lsp-eslint-library-choices-file (concat MY--PATH_USER_LOCAL "lsp-eslint-choices"))
  1328. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  1329. :hook
  1330. (((python-mode
  1331. js-mode
  1332. js2-mode
  1333. typescript-mode
  1334. web-mode
  1335. ) . lsp-deferred)
  1336. (lsp-mode . lsp-enable-which-key-integration)
  1337. (lsp-mode . lsp-diagnostics-modeline-mode)
  1338. (web-mode . #'lsp-flycheck-enable)) ;; enable flycheck-lsp for web-mode locally
  1339. :config
  1340. (setq lsp-diagnostics-package :none)) ; disable flycheck-lsp for most modes
  1341. ;; (add-hook 'web-mode-hook #'lsp-flycheck-enable)) ; enable flycheck-lsp for web-mode locally
  1342. (use-package lsp-ui
  1343. :after lsp-mode
  1344. :ensure t
  1345. :defer t
  1346. :diminish
  1347. :commands lsp-ui-mode
  1348. :config
  1349. (setq lsp-ui-doc-enable t
  1350. lsp-ui-doc-header t
  1351. lsp-ui-doc-include-signature t
  1352. lsp-ui-doc-position 'top
  1353. lsp-ui-doc-border (face-foreground 'default)
  1354. lsp-ui-sideline-enable t
  1355. lsp-ui-sideline-ignore-duplicate t
  1356. lsp-ui-sideline-show-code-actions nil)
  1357. (when *sys/gui*
  1358. (setq lsp-ui-doc-use-webkit t))
  1359. ;; workaround hide mode-line of lsp-ui-imenu buffer
  1360. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  1361. (setq mode-line-format nil)))
  1362. ;;NO LONGER SUPPORTED, USE company-capf / completion-at-point
  1363. ;(use-package company-lsp
  1364. ; :requires company
  1365. ; :defer t
  1366. ; :ensure t
  1367. ; :config
  1368. ; ;;disable client-side cache because lsp server does a better job
  1369. ; (setq company-transformers nil
  1370. ; company-lsp-async t
  1371. ; company-lsp-cache-candidates nil))
  1372. #+END_SRC
  1373. ** yasnippet
  1374. For useful snippet either install yasnippet-snippets or get them from here
  1375. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1376. #+begin_src emacs-lisp
  1377. (use-package yasnippet
  1378. :ensure t
  1379. :defer t
  1380. :diminish yas-minor-mode
  1381. :config
  1382. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1383. (yas-global-mode t)
  1384. (yas-reload-all)
  1385. (unbind-key "TAB" yas-minor-mode-map)
  1386. (unbind-key "<tab>" yas-minor-mode-map))
  1387. #+end_src
  1388. ** hippie expand
  1389. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1390. #+begin_src emacs-lisp
  1391. (use-package hippie-exp
  1392. :defer t
  1393. :bind
  1394. ("C-<return>" . hippie-expand)
  1395. :config
  1396. (setq hippie-expand-try-functions-list
  1397. '(yas-hippie-try-expand emmet-expand-line)))
  1398. #+end_src
  1399. ** flycheck
  1400. #+BEGIN_SRC emacs-lisp
  1401. (use-package flycheck
  1402. :ensure t
  1403. :hook
  1404. ((css-mode . flycheck-mode)
  1405. (emacs-lisp-mode . flycheck-mode)
  1406. (python-mode . flycheck-mode))
  1407. :defer 1.0
  1408. :init
  1409. (setq flycheck-emacs-lisp-load-path 'inherit)
  1410. :config
  1411. (setq-default
  1412. flycheck-check-synta-automatically '(save mode-enabled)
  1413. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1414. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1415. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1416. #+END_SRC
  1417. ** COMMENT Projectile (now project.el, if any)
  1418. Manage projects and jump quickly between its files
  1419. #+BEGIN_SRC emacs-lisp
  1420. (use-package projectile
  1421. :ensure t
  1422. ; :defer 1.0
  1423. :diminish
  1424. :bind
  1425. (("C-c p" . projectile-command-map))
  1426. ;:preface
  1427. :init
  1428. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL "projectile-cache")
  1429. projectile-known-projects-file (concat MY--PATH_USER_LOCAL "projectile-bookmarks"))
  1430. :config
  1431. (projectile-mode)
  1432. ; (add-hook 'projectile-after-switch-project-hook #'set-workon_home)
  1433. (setq-default projectile-completion-system 'ivy
  1434. projectile-enable-caching t
  1435. projectile-mode-line '(:eval (projectile-project-name))))
  1436. ;; requires ripgrep on system for rg functions
  1437. ;(use-package counsel-projectile
  1438. ; :ensure t
  1439. ; :config (counsel-projectile-mode) (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer)
  1440. ;(use-package helm-projectile
  1441. ; :ensure t
  1442. ; :hook
  1443. ; (projectile-mode . helm-projectile))
  1444. #+END_SRC
  1445. ** smartparens
  1446. #+BEGIN_SRC emacs-lisp
  1447. (use-package smartparens
  1448. :ensure t
  1449. :diminish smartparens-mode
  1450. :bind
  1451. (:map smartparens-mode-map
  1452. ("C-M-f" . sp-forward-sexp)
  1453. ("C-M-b" . sp-backward-sexp)
  1454. ("C-M-a" . sp-backward-down-sexp)
  1455. ("C-M-e" . sp-up-sexp)
  1456. ("C-M-w" . sp-copy-sexp)
  1457. ("M-k" . sp-kill-sexp)
  1458. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1459. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1460. ("C-]" . sp-select-next-thing-exchange))
  1461. :config
  1462. (setq sp-show-pair-from-inside nil
  1463. sp-escape-quotes-after-insert nil)
  1464. (require 'smartparens-config))
  1465. #+END_SRC
  1466. ** lisp
  1467. #+BEGIN_SRC emacs-lisp
  1468. (use-package elisp-mode
  1469. :defer t)
  1470. #+END_SRC
  1471. ** web
  1472. apt install npm
  1473. sudo npm install -g vscode-html-languageserver-bin
  1474. evtl alternativ typescript-language-server?
  1475. Unter Windows:
  1476. Hier runterladen: https://nodejs.org/dist/latest/
  1477. und in ein Verzeichnis entpacken.
  1478. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1479. PATH=P:\path\to\node;%path%
  1480. #+BEGIN_SRC emacs-lisp
  1481. (use-package web-mode
  1482. :ensure t
  1483. :defer t
  1484. :mode
  1485. ("\\.phtml\\'"
  1486. "\\.tpl\\.php\\'"
  1487. "\\.djhtml\\'"
  1488. "\\.[t]?html?\\'")
  1489. :hook
  1490. (web-mode . smartparens-mode)
  1491. :init
  1492. (if *work_remote*
  1493. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1494. :config
  1495. (setq web-mode-enable-auto-closing t
  1496. web-mode-enable-auto-pairing t))
  1497. #+END_SRC
  1498. Emmet offers snippets, similar to yasnippet.
  1499. Default completion is C-j
  1500. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1501. #+begin_src emacs-lisp
  1502. (use-package emmet-mode
  1503. :ensure t
  1504. :defer t
  1505. :hook
  1506. ((web-mode . emmet-mode)
  1507. (css-mode . emmet-mode))
  1508. :config
  1509. (unbind-key "C-<return>" emmet-mode-keymap))
  1510. #+end_src
  1511. *** JavaScript
  1512. npm install -g typescript-language-server typescript
  1513. maybe only typescript?
  1514. npm install -g prettier
  1515. #+begin_src emacs-lisp
  1516. (use-package rjsx-mode
  1517. :ensure t
  1518. :mode ("\\.js\\'"
  1519. "\\.jsx'"))
  1520. ; :config
  1521. ; (setq js2-mode-show-parse-errors nil
  1522. ; js2-mode-show-strict-warnings nil
  1523. ; js2-basic-offset 2
  1524. ; js-indent-level 2)
  1525. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1526. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1527. (use-package tide
  1528. :ensure t
  1529. :after (rjsx-mode company flycheck)
  1530. ; :hook (rjsx-mode . setup-tide-mode)
  1531. :config
  1532. (defun setup-tide-mode ()
  1533. "Setup function for tide."
  1534. (interactive)
  1535. (tide-setup)
  1536. (flycheck-mode t)
  1537. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1538. (tide-hl-identifier-mode t)))
  1539. ;; needs npm install -g prettier
  1540. (use-package prettier-js
  1541. :ensure t
  1542. :after (rjsx-mode)
  1543. :defer t
  1544. :diminish prettier-js-mode
  1545. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1546. #+end_src
  1547. ** YAML
  1548. #+begin_src emacs-lisp
  1549. (use-package yaml-mode
  1550. :if *sys/linux*
  1551. :ensure t
  1552. :defer t
  1553. :mode ("\\.yml$" . yaml-mode))
  1554. #+end_src
  1555. ** R
  1556. #+BEGIN_SRC emacs-lisp
  1557. (use-package ess
  1558. :ensure t
  1559. :defer t
  1560. :init
  1561. (if *work_remote*
  1562. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1563. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1564. #+END_SRC
  1565. ** Python
  1566. Systemseitig muss python-language-server installiert sein:
  1567. apt install python3-pip python3-setuptools python3-wheel
  1568. apt install build-essential python3-dev
  1569. pip3 install 'python-language-server[all]'
  1570. Statt obiges: npm install -g pyright
  1571. für andere language servers
  1572. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1573. #+BEGIN_SRC emacs-lisp
  1574. ;(use-package lsp-python-ms
  1575. ; :if *sys/linux*
  1576. ; :ensure t
  1577. ; :defer t
  1578. ; :custom (lsp-python-ms-auto-install-server t))
  1579. (use-package lsp-pyright
  1580. :ensure t
  1581. :after lsp-mode
  1582. :defer t
  1583. :hook
  1584. (python-mode . (lambda ()
  1585. (require 'lsp-pyright)
  1586. (lsp-deferred)))
  1587. ; :custom
  1588. ; (lsp-pyright-auto-import-completions nil)
  1589. ; (lsp-pyright-typechecking-mode "off")
  1590. )
  1591. (use-package python
  1592. :if *sys/linux*
  1593. :delight "π "
  1594. :defer t
  1595. :bind (("M-[" . python-nav-backward-block)
  1596. ("M-]" . python-nav-forward-block)))
  1597. (use-package pyvenv
  1598. :if *sys/linux*
  1599. :ensure t
  1600. :defer t
  1601. :after python
  1602. :hook ((python-mode . pyvenv-mode)
  1603. (python-mode . (lambda ()
  1604. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  1605. (pyvenv-activate pyvenv-directory))
  1606. (lsp))))
  1607. :custom
  1608. (pyvenv-default-virtual-env-name "env")
  1609. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  1610. :preface
  1611. (defun find-pyvenv-directory (path)
  1612. "Check if a pyvenv directory exists."
  1613. (cond
  1614. ((not path) nil)
  1615. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  1616. ((file-directory-p path)
  1617. (or
  1618. (seq-find
  1619. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  1620. (directory-files path t))
  1621. (let ((parent (file-name-directory (directory-file-name path))))
  1622. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  1623. ;; manage multiple python version
  1624. ;; needs to be installed on system
  1625. ; (use-package pyenv-mode
  1626. ; :ensure t
  1627. ; :after python
  1628. ; :hook ((python-mode . pyenv-mode)
  1629. ; (projectile-switch-project . projectile-pyenv-mode-set))
  1630. ; :custom (pyenv-mode-set "3.8.5")
  1631. ; :preface
  1632. ; (defun projectile-pyenv-mode-set ()
  1633. ; "Set pyenv version matching project name."
  1634. ; (let ((project (projectile-project-name)))
  1635. ; (if (member project (pyenv-mode-versions))
  1636. ; (pyenv-mode-set project)
  1637. ; (pyenv-mode-unset)))))
  1638. ;)
  1639. #+END_SRC
  1640. * beancount
  1641. ** Installation
  1642. #+BEGIN_SRC shell :tangle no
  1643. sudo su
  1644. cd /opt
  1645. python3 -m venv beancount
  1646. source ./beancount/bin/activate
  1647. pip3 install wheel
  1648. pip3 install beancount
  1649. sleep 100
  1650. echo "shell running!"
  1651. deactivate
  1652. #+END_SRC
  1653. #+BEGIN_SRC emacs-lisp
  1654. (use-package beancount
  1655. :if *sys/linux*
  1656. :load-path "user-global/elisp"
  1657. ; :ensure t
  1658. :defer t
  1659. :mode
  1660. ("\\.beancount$" . beancount-mode)
  1661. :hook
  1662. (beancount-mode . my--beancount-company)
  1663. :init
  1664. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1665. :config
  1666. (defun my--beancount-company ()
  1667. (set (make-local-variable 'company-backends)
  1668. '(company-beancount)))
  1669. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1670. #+END_SRC
  1671. To support org-babel, check if it can find the symlink to ob-beancount.el
  1672. #+BEGIN_SRC shell :tangle no
  1673. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1674. beansym="$orgpath/ob-beancount.el
  1675. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1676. if [ -h "$beansym" ]
  1677. then
  1678. echo "$beansym found"
  1679. elif [ -e "$bean" ]
  1680. then
  1681. echo "creating symlink"
  1682. ln -s "$bean" "$beansym"
  1683. else
  1684. echo "$bean not found, symlink creation aborted"
  1685. fi
  1686. #+END_SRC
  1687. Fava is strongly recommended.
  1688. #+BEGIN_SRC shell :tangle no
  1689. cd /opt
  1690. python3 -m venv fava
  1691. source ./fava/bin/activate
  1692. pip3 install wheel
  1693. pip3 install fava
  1694. deactivate
  1695. #+END_SRC
  1696. Start fava with fava my_file.beancount
  1697. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1698. Beancount-mode can start fava and open the URL right away.
  1699. * Stuff after everything else
  1700. Set garbage collector to a smaller value to let it kick in faster.
  1701. Maybe a problem on Windows?
  1702. #+begin_src emacs-lisp
  1703. ;(setq gc-cons-threshold (* 2 1000 1000))
  1704. #+end_src