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.

2032 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. :general
  617. (:states 'insert
  618. :definer 'minor-mode
  619. :predicate 'corfu-map
  620. :keymaps 'completion-in-region-mode
  621. "C-d" 'corfu-info-documentation))
  622. ;; (general-define-key
  623. ;; :states 'insert
  624. ;; :definer 'minor-mode
  625. ;; :keymaps 'completion-in-region-mode
  626. ;; :predicate 'corfu-mode
  627. ;; "C-d" 'corfu-info-documentation)
  628. (use-package emacs
  629. :init
  630. ;; hide commands in M-x which do not apply to current mode
  631. (setq read-extended-command-predicate #'command-completion-default-include-p)
  632. ;; enable indentation + completion using TAB
  633. (setq tab-always-indent 'complete))
  634. #+end_src
  635. * Cape
  636. Adds completions for corfu
  637. [[https://github.com/minad/cape][Cape Github]]
  638. Available functions:
  639. dabbrev, file, history, keyword, tex, sgml, rfc1345, abbrev, ispell, dict, symbol, line
  640. #+begin_src emacs-lisp
  641. (use-package cape
  642. :ensure t
  643. :bind
  644. (("C-c p p" . completion-at-point) ;; capf
  645. ("C-c p t" . complete-tag) ;; etags
  646. ("C-c p d" . cape-dabbrev)
  647. ("C-c p h" . cape-history)
  648. ("C-c p f" . cape-file))
  649. :init
  650. (advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible) ;; for performance issues with lsp
  651. (add-to-list 'completion-at-point-functions #'cape-dabbrev)
  652. (add-to-list 'completion-at-point-functions #'cape-file)
  653. (add-to-list 'completion-at-point-functions #'cape-history))
  654. #+end_src
  655. * kind-icon
  656. Make corfu pretty
  657. [[https://github.com/jdtsmith/kind-icon][kind-icon Github]]
  658. #+begin_src emacs-lisp
  659. (use-package kind-icon
  660. :ensure t
  661. :after corfu
  662. :custom
  663. (kind-icon-default-face 'corfu-default) ;; to compute blended backgrounds correctly
  664. :config
  665. (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))
  666. #+end_src
  667. * Orderless
  668. [[https://github.com/oantolin/orderless][Orderless Github]]
  669. Orderless orders the suggestions by recency. The package prescient orders by frequency.
  670. #+begin_src emacs-lisp
  671. (use-package orderless
  672. :ensure t
  673. :init
  674. (setq completion-styles '(orderless partial-completion basic)
  675. completion-category-defaults nil
  676. completion-category-overrides nil))
  677. ; completion-category-overrides '((file (styles partial-completion)))))
  678. #+end_src
  679. * Consult
  680. [[https://github.com/minad/consult][Github]]
  681. #+begin_src emacs-lisp
  682. (use-package consult
  683. :ensure t
  684. :bind
  685. (("C-x C-r" . consult-recent-file)
  686. ("C-x b" . consult-buffer)
  687. ("C-s" . consult-line))
  688. :config
  689. ;; disable preview for some commands and buffers
  690. ;; and enable it by M-.
  691. ;; see https://github.com/minad/consult#use-package-example
  692. (consult-customize
  693. consult-theme
  694. :preview-key '(debounce 0.2 any)
  695. consult-ripgrep consult-git-grep consult-grep
  696. consult-bookmark consult-recent-file consult-xref
  697. consult--source-bookmark consult--source-file-register
  698. consult--source-recent-file consult--source-project-recent-file
  699. :preview-key "M-."))
  700. #+end_src
  701. * Marginalia
  702. [[https://github.com/minad/marginalia/][Github]]
  703. Adds additional information to the minibuffer
  704. #+begin_src emacs-lisp
  705. (use-package marginalia
  706. :ensure t
  707. :init
  708. (marginalia-mode)
  709. :bind
  710. (:map minibuffer-local-map
  711. ("M-A" . marginalia-cycle))
  712. :custom
  713. ;; switch by 'marginalia-cycle
  714. (marginalia-annotators '(marginalia-annotators-heavy
  715. marginalia-annotators-light
  716. nil)))
  717. #+end_src
  718. * Embark
  719. Does stuff in the minibuffer results
  720. #+begin_src emacs-lisp
  721. (use-package embark
  722. :ensure t
  723. :bind
  724. (("C-S-a" . embark-act)
  725. ("C-h B" . embark-bindings))
  726. :init
  727. (setq prefix-help-command #'embark-prefix-help-command)
  728. :config
  729. ;; hide modeline of the embark live/completions buffers
  730. (add-to-list 'display-buffer-alist
  731. '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
  732. nil
  733. (window-parameters (mode-line-format . none)))))
  734. (use-package embark-consult
  735. :ensure t
  736. :after (embark consult)
  737. :demand t
  738. :hook
  739. (embark-collect-mode . embark-consult-preview-minor-mode))
  740. #+end_src
  741. * COMMENT Helm
  742. As an alternative if I'm not happy with selectrum & co
  743. #+begin_src emacs-lisp
  744. (use-package helm
  745. :ensure t
  746. :hook
  747. (helm-mode . helm-autoresize-mode)
  748. ;; :bind
  749. ;; (("M-x" . helm-M-x)
  750. ;; ("C-s" . helm-occur)
  751. ;; ("C-x C-f" . helm-find-files)
  752. ;; ("C-x C-b" . helm-buffers-list)
  753. ;; ("C-x b" . helm-buffers-list)
  754. ;; ("C-x C-r" . helm-recentf)
  755. ;; ("C-x C-i" . helm-imenu))
  756. :config
  757. (helm-mode)
  758. :custom
  759. (helm-split-window-inside-p t) ;; open helm buffer inside current window
  760. (helm-move-to-line-cycle-in-source t)
  761. (helm-echo-input-in-header-line t)
  762. (helm-autoresize-max-height 20)
  763. (helm-autoresize-min-height 5)
  764. )
  765. #+end_src
  766. * COMMENT ivy / counsel / swiper
  767. #+BEGIN_SRC emacs-lisp
  768. ; (require 'ivy)
  769. (use-package ivy
  770. :ensure t
  771. :diminish
  772. (ivy-mode . "")
  773. :defer t
  774. :init
  775. (ivy-mode 1)
  776. :bind
  777. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  778. :config
  779. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  780. ivy-height 20 ;; height of ivy window
  781. ivy-count-format "%d/%d" ;; current and total number
  782. ivy-re-builders-alist ;; regex replaces spaces with *
  783. '((t . ivy--regex-plus))))
  784. ; make counsel-M-x more descriptive
  785. (use-package ivy-rich
  786. :ensure t
  787. :defer t
  788. :init
  789. (ivy-rich-mode 1))
  790. (use-package counsel
  791. :ensure t
  792. :defer t
  793. :bind
  794. (("M-x" . counsel-M-x)
  795. ("C-x C-f" . counsel-find-file)
  796. ("C-x C-r" . counsel-recentf)
  797. ("C-x b" . counsel-switch-buffer)
  798. ("C-c C-f" . counsel-git)
  799. ("C-c h f" . counsel-describe-function)
  800. ("C-c h v" . counsel-describe-variable)
  801. ("M-i" . counsel-imenu)))
  802. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  803. ; ("C-r" . 'counsel-minibuffer-history)))
  804. (use-package swiper
  805. :ensure t
  806. :bind
  807. ("C-s" . swiper))
  808. (use-package ivy-hydra
  809. :ensure t)
  810. #+END_SRC
  811. * outlook
  812. In outlook a macro is necessary, also a reference to FM20.DLL
  813. (Microsoft Forms 2.0 Object Library, in c:\windows\syswow64\fm20.dll)
  814. The macro copies the GUID of the email to the clipboard
  815. Attention: the GUID changes when the email is moved to another folder!
  816. The macro:
  817. #+BEGIN_SRC
  818. Sub AddLinkToMessageInClipboard()
  819. 'Adds a link to the currently selected message to the clipboard
  820. Dim objMail As Outlook.MailItem
  821. Dim doClipboard As New DataObject
  822. 'One and ONLY one message muse be selected
  823. If Application.ActiveExplorer.Selection.Count <> 1 Then
  824. MsgBox ("Select one and ONLY one message.")
  825. Exit Sub
  826. End If
  827. Set objMail = Application.ActiveExplorer.Selection.Item(1)
  828. doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
  829. doClipboard.PutInClipboard
  830. End Sub
  831. #+END_SRC
  832. #+BEGIN_SRC emacs-lisp
  833. (use-package org
  834. :config
  835. (org-add-link-type "outlook" 'my--org-outlook-open))
  836. (defun my--org-outlook-open (id)
  837. (w32-shell-execute "open" "outlook" (concat " /select outlook:" id)))
  838. (defun my/org-outlook-open-test ()
  839. (interactive)
  840. (w32-shell-execute "open" "outlook" " /select outlook:000000008A209C397CEF2C4FBA9E54AEB5B1F97F0700846D043B407C5B43A0C05AFC46DC5C630587BE5E020900006E48FF8F6027694BA6593777F542C19E0002A6434D000000"))'
  841. #+END_SRC
  842. * misc
  843. #+begin_src emacs-lisp
  844. (use-package autorevert
  845. :diminish auto-revert-mode)
  846. #+end_src
  847. * COMMENT company (now corfu)
  848. #+BEGIN_SRC emacs-lisp
  849. (use-package company
  850. :defer 1
  851. :diminish
  852. :defer t
  853. :bind
  854. (("C-<tab>" . company-complete)
  855. :map company-active-map
  856. ("RET" . nil)
  857. ([return] . nil)
  858. ("TAB" . company-complete-selection)
  859. ([tab] . company-complete-selection)
  860. ("<right>" . company-complete-common)
  861. ("<escape>" . company-abort))
  862. :hook
  863. (after-init . global-company-mode)
  864. (emacs-lisp-mode . my--company-elisp)
  865. (org-mode . my--company-org)
  866. :config
  867. (defun my--company-elisp ()
  868. (message "set up company for elisp")
  869. (set (make-local-variable 'company-backends)
  870. '(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp
  871. company-yasnippet
  872. company-dabbrev-code
  873. company-files)))
  874. (defun my--company-org ()
  875. (set (make-local-variable 'company-backends)
  876. '(company-capf company-files))
  877. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  878. (message "setup company for org"))
  879. (setq company-idle-delay .2
  880. company-minimum-prefix-length 1
  881. company-require-match nil
  882. company-show-numbers t
  883. company-tooltip-align-annotations t))
  884. (use-package company-statistics
  885. :ensure t
  886. :after company
  887. :defer t
  888. :init
  889. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  890. :config
  891. (company-statistics-mode 1))
  892. (use-package company-dabbrev
  893. :ensure nil
  894. :after company
  895. :defer t
  896. :config
  897. (setq-default company-dabbrev-downcase nil))
  898. ;; adds a info box right of the cursor with doc of the function
  899. (use-package company-box
  900. :ensure t
  901. :diminish
  902. :defer t
  903. :hook
  904. (company-mode . company-box-mode))
  905. ; :init
  906. ; (add-hook 'company-mode-hook 'company-box-mode))
  907. #+END_SRC
  908. * orgmode
  909. ** some notes
  910. *** copy file path within emacs
  911. Enter dired-other-window
  912. place cursor on the file
  913. M-0 w (copy absolute path)
  914. C-u w (copy relative path)
  915. *** Archiving
  916. C-c C-x C-a
  917. To keep the subheading structure when archiving, set the properties of the superheading.
  918. #+begin_src org :tangle no
  919. ,* FOO
  920. :PROPERTIES:
  921. :ARCHIVE: %s_archive::* FOO
  922. ,** DONE BAR
  923. ,** TODO BAZ
  924. #+end_src
  925. When moving BAR to archive, it will go to FILENAME.org_archive below the heading FOO.
  926. [[http://doc.endlessparentheses.com/Var/org-archive-location.html][Other examples]]
  927. ** org
  928. This seems necessary to prevent 'org is already installed' error
  929. https://github.com/jwiegley/use-package/issues/319
  930. #+begin_src emacs-lisp
  931. (assq-delete-all 'org package--builtins)'
  932. (assq-delete-all 'org package--builtin-versions)
  933. #+end_src
  934. #+BEGIN_SRC emacs-lisp
  935. (defun my--buffer-prop-set (name value)
  936. "Set a file property called NAME to VALUE in buffer file.
  937. If the property is already set, replace its value."
  938. (setq name (downcase name))
  939. (org-with-point-at 1
  940. (let ((case-fold-search t))
  941. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  942. (point-max) t)
  943. (replace-match (concat "#+" name ": " value) 'fixedcase)
  944. (while (and (not (eobp))
  945. (looking-at "^[#:]"))
  946. (if (save-excursion (end-of-line) (eobp))
  947. (progn
  948. (end-of-line)
  949. (insert "\n"))
  950. (forward-line)
  951. (beginning-of-line)))
  952. (insert "#+" name ": " value "\n")))))
  953. (defun my--buffer-prop-remove (name)
  954. "Remove a buffer property called NAME."
  955. (org-with-point-at 1
  956. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  957. (point-max) t)
  958. (replace-match ""))))
  959. (use-package org
  960. :ensure t
  961. :pin gnu
  962. :mode (("\.org$" . org-mode))
  963. :diminish org-indent-mode
  964. :defer 1
  965. :hook
  966. (org-mode . org-indent-mode)
  967. (org-source-mode . smartparens-mode)
  968. :bind (("C-c l" . org-store-link)
  969. ("C-c c" . org-capture)
  970. ("C-c a" . org-agenda)
  971. :map org-mode-map ("S-<right>" . org-shiftright)
  972. ("S-<left>" . org-shiftleft))
  973. :init
  974. (defun my--org-company ()
  975. (set (make-local-variable 'company-backends)
  976. '(company-capf company-files))
  977. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  978. (defun my--org-agenda-files-set ()
  979. "Sets default agenda files.
  980. Necessary when updating roam agenda todos."
  981. (setq org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  982. (concat MY--PATH_ORG_FILES "projects.org")
  983. (concat MY--PATH_ORG_FILES "tasks.org")))
  984. (when *sys/linux*
  985. (nconc org-agenda-files
  986. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$"))))
  987. (my--org-agenda-files-set)
  988. :config
  989. :custom
  990. (when *sys/linux*
  991. (org-pretty-entities t))
  992. (org-startup-truncated t)
  993. (org-startup-align-all-tables t)
  994. (org-src-fontify-natively t) ;; use syntax highlighting in code blocks
  995. (org-src-preserve-indentation t) ;; no extra indentation
  996. (org-src-window-setup 'current-window) ;; C-c ' opens in current window
  997. (org-modules (quote (org-id
  998. org-habit
  999. org-tempo))) ;; easy templates
  1000. (org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org"))
  1001. (org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations"))
  1002. (org-log-into-drawer "LOGBOOK")
  1003. (org-log-done 'time) ;; create timestamp when task is done
  1004. (org-blank-before-new-entry '((heading) (plain-list-item))) ;; prevent new line before new item
  1005. (org-src-tab-acts-natively t))
  1006. #+END_SRC
  1007. Custom keywords, depending on environment
  1008. #+BEGIN_SRC emacs-lisp
  1009. (use-package org
  1010. :if *work_remote*
  1011. :custom
  1012. (org-todo-keywords
  1013. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  1014. #+END_SRC
  1015. ** org-agenda
  1016. Sort agenda by deadline and priority
  1017. #+BEGIN_SRC emacs-lisp
  1018. (use-package org
  1019. :ensure t
  1020. :custom
  1021. (org-agenda-sorting-strategy
  1022. (quote
  1023. ((agenda deadline-up priority-down)
  1024. (todo priority-down category-keep)
  1025. (tags priority-down category-keep)
  1026. (search category-keep)))))
  1027. #+END_SRC
  1028. Customize the org agenda
  1029. #+BEGIN_SRC emacs-lisp
  1030. (defun my--org-skip-subtree-if-priority (priority)
  1031. "Skip an agenda subtree if it has a priority of PRIORITY.
  1032. PRIORITY may be one of the characters ?A, ?B, or ?C."
  1033. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  1034. (pri-value (* 1000 (- org-lowest-priority priority)))
  1035. (pri-current (org-get-priority (thing-at-point 'line t))))
  1036. (if (= pri-value pri-current)
  1037. subtree-end
  1038. nil)))
  1039. (use-package org
  1040. :ensure t
  1041. :custom
  1042. (org-agenda-custom-commands
  1043. '(("c" "Simple agenda view"
  1044. ((tags "PRIORITY=\"A\""
  1045. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1046. (org-agenda-overriding-header "Hohe Priorität:")))
  1047. (agenda ""
  1048. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1049. (org-agenda-span 7)
  1050. (org-agenda-start-on-weekday nil)
  1051. (org-agenda-overriding-header "Nächste 7 Tage:")))
  1052. (alltodo ""
  1053. ((org-agenda-skip-function '(or (my--org-skip-subtree-if-priority ?A)
  1054. (org-agenda-skip-if nil '(scheduled deadline))))
  1055. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))))
  1056. #+END_SRC
  1057. ** languages
  1058. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  1059. #+begin_src emacs-lisp
  1060. (use-package ob-org
  1061. :defer t
  1062. :ensure org-contrib
  1063. :commands
  1064. (org-babel-execute:org
  1065. org-babel-expand-body:org))
  1066. (use-package ob-python
  1067. :defer t
  1068. :ensure org-contrib
  1069. :commands (org-babel-execute:python))
  1070. (use-package ob-js
  1071. :defer t
  1072. :ensure org-contrib
  1073. :commands (org-babel-execute:js))
  1074. (use-package ob-shell
  1075. :defer t
  1076. :ensure org-contrib
  1077. :commands
  1078. (org-babel-execute:sh
  1079. org-babel-expand-body:sh
  1080. org-babel-execute:bash
  1081. org-babel-expand-body:bash))
  1082. (use-package ob-emacs-lisp
  1083. :defer t
  1084. :ensure org-contrib
  1085. :commands
  1086. (org-babel-execute:emacs-lisp
  1087. org-babel-expand-body:emacs-lisp))
  1088. (use-package ob-lisp
  1089. :defer t
  1090. :ensure org-contrib
  1091. :commands
  1092. (org-babel-execute:lisp
  1093. org-babel-expand-body:lisp))
  1094. (use-package ob-gnuplot
  1095. :defer t
  1096. :ensure org-contrib
  1097. :commands
  1098. (org-babel-execute:gnuplot
  1099. org-babel-expand-body:gnuplot))
  1100. (use-package ob-sqlite
  1101. :defer t
  1102. :ensure org-contrib
  1103. :commands
  1104. (org-babel-execute:sqlite
  1105. org-babel-expand-body:sqlite))
  1106. (use-package ob-latex
  1107. :defer t
  1108. :ensure org-contrib
  1109. :commands
  1110. (org-babel-execute:latex
  1111. org-babel-expand-body:latex))
  1112. (use-package ob-R
  1113. :defer t
  1114. :ensure org-contrib
  1115. :commands
  1116. (org-babel-execute:R
  1117. org-babel-expand-body:R))
  1118. (use-package ob-scheme
  1119. :defer t
  1120. :ensure org-contrib
  1121. :commands
  1122. (org-babel-execute:scheme
  1123. org-babel-expand-body:scheme))
  1124. #+end_src
  1125. ** habits
  1126. #+BEGIN_SRC emacs-lisp
  1127. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  1128. ;; (add-to-list 'org-modules "org-habit")
  1129. (setq org-habit-graph-column 80
  1130. org-habit-preceding-days 30
  1131. org-habit-following-days 7
  1132. org-habit-show-habits-only-for-today nil)
  1133. #+END_SRC
  1134. ** *TODO*
  1135. [[https://github.com/alphapapa/org-ql][org-ql]]
  1136. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  1137. ** org-caldav
  1138. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  1139. #+BEGIN_SRC emacs-lisp
  1140. ;;(use-package org-caldav
  1141. ;; :ensure t
  1142. ;; :config
  1143. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  1144. ;; org-caldav-calendar-id "orgmode"
  1145. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  1146. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  1147. #+END_SRC
  1148. ** journal
  1149. [[https://github.com/bastibe/org-journal][Source]]
  1150. Ggf. durch org-roam-journal ersetzen
  1151. #+BEGIN_SRC emacs-lisp
  1152. (use-package org-journal
  1153. :if *sys/linux*
  1154. :ensure t
  1155. :defer t
  1156. :config
  1157. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  1158. (when (and (boundp 'org-journal-dir)
  1159. (boundp 'org-journal-enable-agenda-integration))
  1160. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  1161. org-journal-enable-agenda-integration t)))
  1162. #+END_SRC
  1163. ** org-roam
  1164. [[https://github.com/org-roam/org-roam][Github]]
  1165. Um Headings innerhalb einer Datei zu verlinken:
  1166. - org-id-get-create im Heading,
  1167. - org-roam-node-insert in der verweisenden Datei
  1168. Bei Problemen wie unique constraint
  1169. org-roam-db-clear-all
  1170. org-roam-db-sync
  1171. #+BEGIN_SRC emacs-lisp
  1172. (use-package org-roam
  1173. :ensure t
  1174. :defer 2
  1175. :after org
  1176. :init
  1177. (setq org-roam-v2-ack t)
  1178. (defun my--roamtodo-p ()
  1179. "Return non-nil if current buffer has any todo entry.
  1180. TODO entries marked as done are ignored, meaning this function
  1181. returns nil if current buffer contains only completed tasks."
  1182. (seq-find
  1183. (lambda (type)
  1184. (eq type 'todo))
  1185. (org-element-map
  1186. (org-element-parse-buffer 'headline)
  1187. 'headline
  1188. (lambda (h)
  1189. (org-element-property :todo-type h)))))
  1190. (defun my--roamtodo-update-tag ()
  1191. "Update ROAMTODO tag in the current buffer."
  1192. (when (and (not (active-minibuffer-window))
  1193. (my--buffer-roam-note-p))
  1194. (save-excursion
  1195. (goto-char (point-min))
  1196. (let* ((tags (my--buffer-tags-get))
  1197. (original-tags tags))
  1198. (if (my--roamtodo-p)
  1199. (setq tags (cons "roamtodo" tags))
  1200. (setq tags (remove "roamtodo" tags)))
  1201. ;;cleanup duplicates
  1202. (when (or (seq-difference tags original-tags)
  1203. (seq-difference original-tags tags))
  1204. (apply #'my--buffer-tags-set tags))))))
  1205. (defun my--buffer-tags-get ()
  1206. "Return filetags value in current buffer."
  1207. (my--buffer-prop-get-list "filetags" "[ :]"))
  1208. (defun my--buffer-tags-set (&rest tags)
  1209. "Set TAGS in current buffer.
  1210. If filetags value is already set, replace it."
  1211. (if tags
  1212. (my--buffer-prop-set
  1213. "filetags" (concat ":" (string-join tags ":") ":"))
  1214. (my--buffer-prop-remove "filetags")))
  1215. (defun my--buffer-tags-add (tag)
  1216. "Add a TAG to filetags in current buffer."
  1217. (let* ((tags (my--buffer-tags-get))
  1218. (tags (append tags (list tag))))
  1219. (apply #'my--buffer-tags-set tags)))
  1220. (defun my--buffer-tags-remove (tag)
  1221. "Remove a TAG from filetags in current buffer."
  1222. (let* ((tags (my--buffer-tags-get))
  1223. (tags (delete tag tags)))
  1224. (apply #'my--buffer-tags-set tags)))
  1225. (defun my--buffer-prop-set (name value)
  1226. "Set a file property called NAME to VALUE in buffer file.
  1227. If the property is already set, replace its value."
  1228. (setq name (downcase name))
  1229. (org-with-point-at 1
  1230. (let ((case-fold-search t))
  1231. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  1232. (point-max) t)
  1233. (replace-match (concat "#+" name ": " value) 'fixedcase)
  1234. (while (and (not (eobp))
  1235. (looking-at "^[#:]"))
  1236. (if (save-excursion (end-of-line) (eobp))
  1237. (progn
  1238. (end-of-line)
  1239. (insert "\n"))
  1240. (forward-line)
  1241. (beginning-of-line)))
  1242. (insert "#+" name ": " value "\n")))))
  1243. (defun my--buffer-prop-set-list (name values &optional separators)
  1244. "Set a file property called NAME to VALUES in current buffer.
  1245. VALUES are quoted and combined into single string using
  1246. `combine-and-quote-strings'.
  1247. If SEPARATORS is non-nil, it should be a regular expression
  1248. matching text that separates, but is not part of, the substrings.
  1249. If nil it defaults to `split-string-and-unquote', normally
  1250. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t.
  1251. If the property is already set, replace its value."
  1252. (my--buffer-prop-set
  1253. name (combine-and-quote-strings values separators)))
  1254. (defun my--buffer-prop-get (name)
  1255. "Get a buffer property called NAME as a string."
  1256. (org-with-point-at 1
  1257. (when (re-search-forward (concat "^#\\+" name ": \\(.*\\)")
  1258. (point-max) t)
  1259. (buffer-substring-no-properties
  1260. (match-beginning 1)
  1261. (match-end 1)))))
  1262. (defun my--buffer-prop-get-list (name &optional separators)
  1263. "Get a buffer property NAME as a list using SEPARATORS.
  1264. If SEPARATORS is non-nil, it should be a regular expression
  1265. matching text that separates, but is not part of, the substrings.
  1266. If nil it defaults to `split-string-default-separators', normally
  1267. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t."
  1268. (let ((value (my--buffer-prop-get name)))
  1269. (when (and value (not (string-empty-p value)))
  1270. (split-string-and-unquote value separators))))
  1271. (defun my--buffer-prop-remove (name)
  1272. "Remove a buffer property called NAME."
  1273. (org-with-point-at 1
  1274. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  1275. (point-max) t)
  1276. (replace-match ""))))
  1277. (defun my--buffer-roam-note-p ()
  1278. "Return non-nil if the currently visited buffer is a note."
  1279. (and buffer-file-name
  1280. (string-prefix-p
  1281. (expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM))
  1282. (file-name-directory buffer-file-name))))
  1283. (defun my--org-roam-filter-by-tag (tag-name)
  1284. (lambda (node)
  1285. (member tag-name (org-roam-node-tags node))))
  1286. (defun my--org-roam-list-notes-by-tag (tag-name)
  1287. (mapcar #'org-roam-node-file
  1288. (seq-filter
  1289. (my--org-roam-filter-by-tag tag-name)
  1290. (org-roam-node-list))))
  1291. (defun my/org-roam-refresh-agenda-list ()
  1292. "Add all org roam files with #+filetags: roamtodo"
  1293. (interactive)
  1294. (my--org-agenda-files-set)
  1295. (nconc org-agenda-files
  1296. (my--org-roam-list-notes-by-tag "roamtodo"))
  1297. (setq org-agenda-files (delete-dups org-agenda-files)))
  1298. (add-hook 'find-file-hook #'my--roamtodo-update-tag)
  1299. (add-hook 'before-save-hook #'my--roamtodo-update-tag)
  1300. (advice-add 'org-agenda :before #'my/org-roam-refresh-agenda-list)
  1301. (advice-add 'org-todo-list :before #'my/org-roam-refresh-agenda-list)
  1302. (add-to-list 'org-tags-exclude-from-inheritance "roamtodo")
  1303. :config
  1304. (require 'org-roam-dailies) ;; ensure the keymap is available
  1305. (org-roam-db-autosync-mode)
  1306. ;; build the agenda list the first ime for the session
  1307. (my/org-roam-refresh-agenda-list)
  1308. :custom
  1309. (org-roam-directory MY--PATH_ORG_ROAM)
  1310. (org-roam-completion-everywhere t)
  1311. (org-roam-capture-templates
  1312. '(("n" "note" plain
  1313. "%?"
  1314. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1315. :unnarrowed t)
  1316. ("i" "idea" plain
  1317. "%?"
  1318. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1319. :unnarrowed t)
  1320. ))
  1321. :bind (("C-c n l" . org-roam-buffer-toggle)
  1322. ("C-c n f" . org-roam-node-find)
  1323. ("C-c n i" . org-roam-node-insert)
  1324. :map org-mode-map
  1325. ("C-M-i" . completion-at-point)
  1326. :map org-roam-dailies-map
  1327. ("Y" . org-roam-dailies-capture-yesterday)
  1328. ("T" . org-roam-dailies-capture-tomorrow))
  1329. :bind-keymap
  1330. ("C-c n d" . org-roam-dailies-map))
  1331. (when *sys/windows*
  1332. (use-package emacsql-sqlite3
  1333. :ensure t
  1334. :init
  1335. (setq emacsql-sqlite3-binary "P:/Tools/sqlite/sqlite3.exe"
  1336. exec-path (append exec-path '("P:/Tools/sqlite"))))
  1337. (use-package org-roam
  1338. :requires emacsql-sqlite3
  1339. :init
  1340. :config
  1341. (add-to-list 'org-roam-capture-templates
  1342. '("t" "telephone call" plain
  1343. "%?"
  1344. :target (file+head "telephone/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: CALL %<%Y-%m-%d %H:%M> ${title}\n")
  1345. :unnarrowed t) t)
  1346. (add-to-list 'org-roam-capture-templates
  1347. '("p" "project" plain
  1348. "%?"
  1349. :target (file+head "projects/${slug}.org" "#+title: ${title}\n#+filetags: :project:\n")
  1350. :unnarrowed t) t)
  1351. (add-to-list 'org-roam-capture-templates
  1352. '("s" "Sicherheitenmeldung" plain
  1353. "*** TODO [#A] Sicherheitenmeldung ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1354. :target (file+olp "tasks.org" ("Todos" "Sicherheitenmeldungen"))) t)
  1355. (add-to-list 'org-roam-capture-templates
  1356. '("m" "Monatsbericht" plain'
  1357. "*** TODO [#A] Monatsbericht ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1358. :target (file+olp "tasks.org" ("Todos" "Monatsberichte"))) t)
  1359. :custom
  1360. (org-roam-database-connector 'sqlite3)))
  1361. #+END_SRC
  1362. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  1363. * Programming
  1364. ** misc
  1365. #+begin_src emacs-lisp
  1366. (use-package eldoc
  1367. :diminish eldoc-mode
  1368. :defer t)
  1369. #+end_src
  1370. ** Magit / Git
  1371. Little crash course in magit:
  1372. - magit-init to init a git project
  1373. - magit-status (C-x g) to call the status window
  1374. In status buffer:
  1375. - s stage files
  1376. - u unstage files
  1377. - U unstage all files
  1378. - a apply changes to staging
  1379. - c c commit (type commit message, then C-c C-c to commit)
  1380. - b b switch to another branch
  1381. - P u git push
  1382. - F u git pull
  1383. #+BEGIN_SRC emacs-lisp
  1384. (use-package magit
  1385. :ensure t
  1386. ; :pin melpa-stable
  1387. :defer t
  1388. :init
  1389. ; set git-path in work environment
  1390. (if (string-equal user-login-name "POH")
  1391. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1392. )
  1393. :bind (("C-x g" . magit-status)))
  1394. #+END_SRC
  1395. ** COMMENT Eglot (can't do dap-mode)
  1396. for python pyls (in env: pip install python-language-server) seems to work better than pyright (npm install -g pyright),
  1397. at least pandas couldnt be resolved in pyright
  1398. #+begin_src emacs-lisp
  1399. (use-package eglot
  1400. :ensure t
  1401. :init
  1402. (setq completion-category-overrides '((eglot (styles orderless)))))
  1403. #+end_src
  1404. ** LSP
  1405. Configuration for the language server protocol
  1406. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  1407. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  1408. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  1409. TODO Unterverzeichnisse wurden noch nicht getestet
  1410. #+BEGIN_SRC emacs-lisp
  1411. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  1412. (use-package lsp-mode
  1413. :defer t
  1414. :commands (lsp lsp-execute-code-action)
  1415. :custom
  1416. (lsp-auto-guess-root nil)
  1417. (lsp-prefer-flymake nil) ; use flycheck instead
  1418. (lsp-prefer-capf t)
  1419. (lsp-file-watch-threshold 5000)
  1420. (lsp-print-performance t)
  1421. (lsp-log-io nil) ; enable log only for debug
  1422. (lsp-enable-folding t) ; default, maybe evil-matchit instead for performance?
  1423. (lsp-diagnostics-modeline-scope :project)
  1424. (lsp-enable-file-watchers nil)
  1425. (lsp-keymap-prefix "C-c l")
  1426. (lsp-session-file (concat MY--PATH_USER_LOCAL "lsp-session"))
  1427. (lsp-eslint-library-choices-file (concat MY--PATH_USER_LOCAL "lsp-eslint-choices"))
  1428. (lsp-completion-provider :none) ;; use corfu
  1429. :bind
  1430. (:map lsp-mode-map
  1431. ("C-c C-f" . lsp-format-buffer))
  1432. :hook
  1433. (lsp-mode . lsp-enable-which-key-integration)
  1434. (lsp-mode . lsp-diagnostics-modeline-mode)
  1435. (web-mode . #'lsp-flycheck-enable) ;; enable flycheck-lsp for web-mode locally
  1436. (lsp-completion-mode . my/lsp-mode-setup-completion)
  1437. :init
  1438. (defun my/lsp-mode-setup-completion ()
  1439. "Setup orderless for lsp"
  1440. (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
  1441. '(orderless))) ;; configure orderless
  1442. :config
  1443. (setq lsp-diagnostic-package :none)) ; disable flycheck-lsp for most modes
  1444. (use-package lsp-ui
  1445. :after lsp-mode
  1446. :ensure t
  1447. :defer t
  1448. :diminish
  1449. :commands lsp-ui-mode
  1450. :config
  1451. (setq lsp-ui-doc-enable t
  1452. lsp-ui-doc-header t
  1453. lsp-ui-doc-include-signature t
  1454. lsp-ui-doc-position 'top
  1455. lsp-ui-doc-border (face-foreground 'default)
  1456. lsp-ui-sideline-enable t
  1457. lsp-ui-sideline-ignore-duplicate t
  1458. ; lsp-ui-sideline-show-symbol t ; show symbol definition in sideline
  1459. lsp-ui-sideline-show-code-actions nil)
  1460. (when *sys/gui*
  1461. (setq lsp-ui-doc-use-webkit t))
  1462. ;; workaround hide mode-line of lsp-ui-imenu buffer
  1463. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  1464. (setq mode-line-format nil)))
  1465. #+END_SRC
  1466. ** yasnippet
  1467. For useful snippet either install yasnippet-snippets or get them from here
  1468. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1469. #+begin_src emacs-lisp
  1470. (use-package yasnippet
  1471. :ensure t
  1472. :defer t
  1473. :diminish yas-minor-mode
  1474. :config
  1475. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1476. (yas-global-mode t)
  1477. (yas-reload-all)
  1478. (unbind-key "TAB" yas-minor-mode-map)
  1479. (unbind-key "<tab>" yas-minor-mode-map))
  1480. #+end_src
  1481. ** hippie expand
  1482. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1483. #+begin_src emacs-lisp
  1484. (use-package hippie-exp
  1485. :defer t
  1486. :bind
  1487. ("C-<return>" . hippie-expand)
  1488. :config
  1489. (setq hippie-expand-try-functions-list
  1490. '(yas-hippie-try-expand emmet-expand-line)))
  1491. #+end_src
  1492. ** flycheck
  1493. #+BEGIN_SRC emacs-lisp
  1494. (use-package flycheck
  1495. :ensure t
  1496. :hook
  1497. ((css-mode . flycheck-mode)
  1498. (emacs-lisp-mode . flycheck-mode)
  1499. (python-mode . flycheck-mode))
  1500. :defer 1.0
  1501. :init
  1502. (setq flycheck-emacs-lisp-load-path 'inherit)
  1503. :config
  1504. (setq-default
  1505. flycheck-check-synta-automatically '(save mode-enabled)
  1506. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1507. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1508. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1509. #+END_SRC
  1510. ** COMMENT Projectile (now project.el, if any)
  1511. Manage projects and jump quickly between its files
  1512. #+BEGIN_SRC emacs-lisp
  1513. (use-package projectile
  1514. :ensure t
  1515. ; :defer 1.0
  1516. :diminish
  1517. :bind
  1518. (("C-c p" . projectile-command-map))
  1519. ;:preface
  1520. :init
  1521. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL "projectile-cache")
  1522. projectile-known-projects-file (concat MY--PATH_USER_LOCAL "projectile-bookmarks"))
  1523. :config
  1524. (projectile-mode)
  1525. ; (add-hook 'projectile-after-switch-project-hook #'set-workon_home)
  1526. (setq-default projectile-completion-system 'ivy
  1527. projectile-enable-caching t
  1528. projectile-mode-line '(:eval (projectile-project-name))))
  1529. ;; requires ripgrep on system for rg functions
  1530. ;(use-package counsel-projectile
  1531. ; :ensure t
  1532. ; :config (counsel-projectile-mode) (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer)
  1533. ;(use-package helm-projectile
  1534. ; :ensure t
  1535. ; :hook
  1536. ; (projectile-mode . helm-projectile))
  1537. #+END_SRC
  1538. ** smartparens
  1539. #+BEGIN_SRC emacs-lisp
  1540. (use-package smartparens
  1541. :ensure t
  1542. :diminish smartparens-mode
  1543. :bind
  1544. (:map smartparens-mode-map
  1545. ("C-M-f" . sp-forward-sexp)
  1546. ("C-M-b" . sp-backward-sexp)
  1547. ("C-M-a" . sp-backward-down-sexp)
  1548. ("C-M-e" . sp-up-sexp)
  1549. ("C-M-w" . sp-copy-sexp)
  1550. ("M-k" . sp-kill-sexp)
  1551. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1552. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1553. ("C-]" . sp-select-next-thing-exchange))
  1554. :config
  1555. (setq sp-show-pair-from-inside nil
  1556. sp-escape-quotes-after-insert nil)
  1557. (require 'smartparens-config))
  1558. #+END_SRC
  1559. ** lisp
  1560. #+BEGIN_SRC emacs-lisp
  1561. (use-package elisp-mode
  1562. :defer t)
  1563. #+END_SRC
  1564. ** web
  1565. apt install npm
  1566. sudo npm install -g vscode-html-languageserver-bin
  1567. evtl alternativ typescript-language-server?
  1568. Unter Windows:
  1569. Hier runterladen: https://nodejs.org/dist/latest/
  1570. und in ein Verzeichnis entpacken.
  1571. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1572. PATH=P:\path\to\node;%path%
  1573. #+BEGIN_SRC emacs-lisp
  1574. (use-package web-mode
  1575. :ensure t
  1576. :defer t
  1577. :mode
  1578. ("\\.phtml\\'"
  1579. "\\.tpl\\.php\\'"
  1580. "\\.djhtml\\'"
  1581. "\\.[t]?html?\\'")
  1582. :hook
  1583. (web-mode . smartparens-mode)
  1584. :init
  1585. (if *work_remote*
  1586. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1587. :config
  1588. (setq web-mode-enable-auto-closing t
  1589. web-mode-enable-auto-pairing t))
  1590. #+END_SRC
  1591. Emmet offers snippets, similar to yasnippet.
  1592. Default completion is C-j
  1593. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1594. #+begin_src emacs-lisp
  1595. (use-package emmet-mode
  1596. :ensure t
  1597. :defer t
  1598. :hook
  1599. ((web-mode . emmet-mode)
  1600. (css-mode . emmet-mode))
  1601. :config
  1602. (unbind-key "C-<return>" emmet-mode-keymap))
  1603. #+end_src
  1604. *** JavaScript
  1605. npm install -g typescript-language-server typescript
  1606. maybe only typescript?
  1607. npm install -g prettier
  1608. #+begin_src emacs-lisp
  1609. (use-package rjsx-mode
  1610. :ensure t
  1611. :mode ("\\.js\\'"
  1612. "\\.jsx'"))
  1613. ; :config
  1614. ; (setq js2-mode-show-parse-errors nil
  1615. ; js2-mode-show-strict-warnings nil
  1616. ; js2-basic-offset 2
  1617. ; js-indent-level 2)
  1618. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1619. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1620. (use-package tide
  1621. :ensure t
  1622. :after (rjsx-mode company flycheck)
  1623. ; :hook (rjsx-mode . setup-tide-mode)
  1624. :config
  1625. (defun setup-tide-mode ()
  1626. "Setup function for tide."
  1627. (interactive)
  1628. (tide-setup)
  1629. (flycheck-mode t)
  1630. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1631. (tide-hl-identifier-mode t)))
  1632. ;; needs npm install -g prettier
  1633. (use-package prettier-js
  1634. :ensure t
  1635. :after (rjsx-mode)
  1636. :defer t
  1637. :diminish prettier-js-mode
  1638. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1639. #+end_src
  1640. ** YAML
  1641. #+begin_src emacs-lisp
  1642. (use-package yaml-mode
  1643. :if *sys/linux*
  1644. :ensure t
  1645. :defer t
  1646. :mode ("\\.yml$" . yaml-mode))
  1647. #+end_src
  1648. ** R
  1649. #+BEGIN_SRC emacs-lisp
  1650. (use-package ess
  1651. :ensure t
  1652. :defer t
  1653. :init
  1654. (if *work_remote*
  1655. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1656. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1657. #+END_SRC
  1658. ** Python
  1659. Systemseitig muss python-language-server installiert sein:
  1660. apt install python3-pip python3-setuptools python3-wheel
  1661. apt install build-essential python3-dev
  1662. pip3 install 'python-language-server[all]'
  1663. Statt obiges: npm install -g pyright
  1664. für andere language servers
  1665. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1666. #+BEGIN_SRC emacs-lisp
  1667. ;(use-package lsp-python-ms
  1668. ; :if *sys/linux*
  1669. ; :ensure t
  1670. ; :defer t
  1671. ; :custom (lsp-python-ms-auto-install-server t))
  1672. (use-package lsp-pyright
  1673. :ensure t
  1674. :after lsp-mode
  1675. :defer t
  1676. :hook
  1677. (python-mode . (lambda ()
  1678. (require 'lsp-pyright)
  1679. (lsp-deferred)))
  1680. ; :custom
  1681. ; (lsp-pyright-auto-import-completions nil)
  1682. ; (lsp-pyright-typechecking-mode "off")
  1683. )
  1684. (use-package python
  1685. :if *sys/linux*
  1686. :delight "π "
  1687. :defer t
  1688. :bind (("M-[" . python-nav-backward-block)
  1689. ("M-]" . python-nav-forward-block)))
  1690. (use-package pyvenv
  1691. :if *sys/linux*
  1692. :ensure t
  1693. :defer t
  1694. :after python
  1695. :hook ((python-mode . pyvenv-mode)
  1696. (python-mode . (lambda ()
  1697. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  1698. (pyvenv-activate pyvenv-directory))
  1699. (lsp))))
  1700. :custom
  1701. (pyvenv-default-virtual-env-name "env")
  1702. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  1703. :preface
  1704. (defun find-pyvenv-directory (path)
  1705. "Check if a pyvenv directory exists."
  1706. (cond
  1707. ((not path) nil)
  1708. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  1709. ((file-directory-p path)
  1710. (or
  1711. (seq-find
  1712. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  1713. (directory-files path t))
  1714. (let ((parent (file-name-directory (directory-file-name path))))
  1715. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  1716. ;; manage multiple python version
  1717. ;; needs to be installed on system
  1718. ; (use-package pyenv-mode
  1719. ; :ensure t
  1720. ; :after python
  1721. ; :hook ((python-mode . pyenv-mode)
  1722. ; (projectile-switch-project . projectile-pyenv-mode-set))
  1723. ; :custom (pyenv-mode-set "3.8.5")
  1724. ; :preface
  1725. ; (defun projectile-pyenv-mode-set ()
  1726. ; "Set pyenv version matching project name."
  1727. ; (let ((project (projectile-project-name)))
  1728. ; (if (member project (pyenv-mode-versions))
  1729. ; (pyenv-mode-set project)
  1730. ; (pyenv-mode-unset)))))
  1731. ;)
  1732. #+END_SRC
  1733. * beancount
  1734. ** Installation
  1735. #+BEGIN_SRC shell :tangle no
  1736. sudo su
  1737. cd /opt
  1738. python3 -m venv beancount
  1739. source ./beancount/bin/activate
  1740. pip3 install wheel
  1741. pip3 install beancount
  1742. sleep 100
  1743. echo "shell running!"
  1744. deactivate
  1745. #+END_SRC
  1746. #+begin_src emacs-lisp
  1747. (use-package beancount
  1748. :if *sys/linux*
  1749. :load-path "user-global/elisp/"
  1750. ; :ensure t
  1751. :defer t
  1752. :mode
  1753. ("\\.beancount$" . beancount-mode)
  1754. :hook
  1755. (beancount-mode . my/beancount-company)
  1756. :config
  1757. (defun my/beancount-company ()
  1758. (setq-local completion-at-point-functions #'beancount-completion-at-point))
  1759. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1760. #+end_src
  1761. +BEGIN_SRC emacs-lisp
  1762. (use-package beancount
  1763. :if *sys/linux*
  1764. :load-path "user-global/elisp"
  1765. ; :ensure t
  1766. :defer t
  1767. :mode
  1768. ("\\.beancount$" . beancount-mode)
  1769. ; :hook
  1770. ; (beancount-mode . my/beancount-company)
  1771. ; :init
  1772. ; (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1773. :config
  1774. (defun my/beancount-company ()
  1775. (setq-local completion-at-point-functions #'beancount-complete-at-point nil t))
  1776. ; (mapcar #'cape-company-to-capf
  1777. ; (list #'company-beancount #'company-dabbrev))))
  1778. (defun my--beancount-companyALT ()
  1779. (set (make-local-variable 'company-backends)
  1780. '(company-beancount)))
  1781. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1782. +END_SRC
  1783. To support org-babel, check if it can find the symlink to ob-beancount.el
  1784. #+BEGIN_SRC shell :tangle no
  1785. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1786. beansym="$orgpath/ob-beancount.el
  1787. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1788. if [ -h "$beansym" ]
  1789. then
  1790. echo "$beansym found"
  1791. elif [ -e "$bean" ]
  1792. then
  1793. echo "creating symlink"
  1794. ln -s "$bean" "$beansym"
  1795. else
  1796. echo "$bean not found, symlink creation aborted"
  1797. fi
  1798. #+END_SRC
  1799. Fava is strongly recommended.
  1800. #+BEGIN_SRC shell :tangle no
  1801. cd /opt
  1802. python3 -m venv fava
  1803. source ./fava/bin/activate
  1804. pip3 install wheel
  1805. pip3 install fava
  1806. deactivate
  1807. #+END_SRC
  1808. Start fava with fava my_file.beancount
  1809. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1810. Beancount-mode can start fava and open the URL right away.
  1811. * Stuff after everything else
  1812. Set garbage collector to a smaller value to let it kick in faster.
  1813. Maybe a problem on Windows?
  1814. #+begin_src emacs-lisp
  1815. ;(setq gc-cons-threshold (* 2 1000 1000))
  1816. #+end_src