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.

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