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-prefix 2)
  609. (corfu-auto-delay 0.0)
  610. (corfu-preselect-first nil)
  611. :init
  612. (global-corfu-mode)
  613. ; (corfu-popupinfo-mode) ; causes corfu window to stay
  614. (corfu-history-mode)
  615. ;; belongs to emacs
  616. (add-to-list 'savehist-additional-variables 'corfu-history))
  617. (use-package emacs
  618. :init
  619. ;; hide commands in M-x which do not apply to current mode
  620. (setq read-extended-command-predicate #'command-completion-default-include-p)
  621. ;; enable indentation + completion using TAB
  622. (setq tab-always-indent 'complete))
  623. #+end_src
  624. * Cape
  625. Adds completions for corfu
  626. [[https://github.com/minad/cape][Cape Github]]
  627. Available functions:
  628. dabbrev, file, history, keyword, tex, sgml, rfc1345, abbrev, ispell, dict, symbol, line
  629. #+begin_src emacs-lisp
  630. (use-package cape
  631. :ensure t
  632. :bind
  633. (("C-c p p" . completion-at-point) ;; capf
  634. ("C-c p t" . complete-tag) ;; etags
  635. ("C-c p d" . cape-dabbrev)
  636. ("C-c p h" . cape-history)
  637. ("C-c p f" . cape-file))
  638. :init
  639. (advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible) ;; for performance issues with lsp
  640. (add-to-list 'completion-at-point-functions #'cape-dabbrev)
  641. (add-to-list 'completion-at-point-functions #'cape-file)
  642. (add-to-list 'completion-at-point-functions #'cape-history))
  643. #+end_src
  644. * kind-icon
  645. Make corfu pretty
  646. [[https://github.com/jdtsmith/kind-icon][kind-icon Github]]
  647. #+begin_src emacs-lisp
  648. (use-package kind-icon
  649. :ensure t
  650. :after corfu
  651. :custom
  652. (kind-icon-default-face 'corfu-default) ;; to compute blended backgrounds correctly
  653. :config
  654. (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))
  655. #+end_src
  656. * Orderless
  657. [[https://github.com/oantolin/orderless][Orderless Github]]
  658. Orderless orders the suggestions by recency. The package prescient orders by frequency.
  659. #+begin_src emacs-lisp
  660. (use-package orderless
  661. :ensure t
  662. :init
  663. (setq completion-styles '(orderless partial-completion basic)
  664. completion-category-defaults nil
  665. completion-category-overrides nil))
  666. ; completion-category-overrides '((file (styles partial-completion)))))
  667. #+end_src
  668. * Consult
  669. [[https://github.com/minad/consult][Github]]
  670. #+begin_src emacs-lisp
  671. (use-package consult
  672. :ensure t
  673. :bind
  674. (("C-x C-r" . consult-recent-file)
  675. ("C-x b" . consult-buffer)
  676. ("C-s" . consult-line))
  677. :config
  678. ;; disable preview for some commands and buffers
  679. ;; and enable it by M-.
  680. ;; see https://github.com/minad/consult#use-package-example
  681. (consult-customize
  682. consult-theme
  683. :preview-key '(debounce 0.2 any)
  684. consult-ripgrep consult-git-grep consult-grep
  685. consult-bookmark consult-recent-file consult-xref
  686. consult--source-bookmark consult--source-file-register
  687. consult--source-recent-file consult--source-project-recent-file
  688. :preview-key "M-."))
  689. #+end_src
  690. * Marginalia
  691. [[https://github.com/minad/marginalia/][Github]]
  692. Adds additional information to the minibuffer
  693. #+begin_src emacs-lisp
  694. (use-package marginalia
  695. :ensure t
  696. :init
  697. (marginalia-mode)
  698. :bind
  699. (:map minibuffer-local-map
  700. ("M-A" . marginalia-cycle))
  701. :custom
  702. ;; switch by 'marginalia-cycle
  703. (marginalia-annotators '(marginalia-annotators-heavy
  704. marginalia-annotators-light
  705. nil)))
  706. #+end_src
  707. * Embark
  708. Does stuff in the minibuffer results
  709. #+begin_src emacs-lisp
  710. (use-package embark
  711. :ensure t
  712. :bind
  713. (("C-S-a" . embark-act)
  714. ("C-h B" . embark-bindings))
  715. :init
  716. (setq prefix-help-command #'embark-prefix-help-command)
  717. :config
  718. ;; hide modeline of the embark live/completions buffers
  719. (add-to-list 'display-buffer-alist
  720. '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
  721. nil
  722. (window-parameters (mode-line-format . none)))))
  723. (use-package embark-consult
  724. :ensure t
  725. :after (embark consult)
  726. :demand t
  727. :hook
  728. (embark-collect-mode . embark-consult-preview-minor-mode))
  729. #+end_src
  730. * COMMENT Helm
  731. As an alternative if I'm not happy with selectrum & co
  732. #+begin_src emacs-lisp
  733. (use-package helm
  734. :ensure t
  735. :hook
  736. (helm-mode . helm-autoresize-mode)
  737. ;; :bind
  738. ;; (("M-x" . helm-M-x)
  739. ;; ("C-s" . helm-occur)
  740. ;; ("C-x C-f" . helm-find-files)
  741. ;; ("C-x C-b" . helm-buffers-list)
  742. ;; ("C-x b" . helm-buffers-list)
  743. ;; ("C-x C-r" . helm-recentf)
  744. ;; ("C-x C-i" . helm-imenu))
  745. :config
  746. (helm-mode)
  747. :custom
  748. (helm-split-window-inside-p t) ;; open helm buffer inside current window
  749. (helm-move-to-line-cycle-in-source t)
  750. (helm-echo-input-in-header-line t)
  751. (helm-autoresize-max-height 20)
  752. (helm-autoresize-min-height 5)
  753. )
  754. #+end_src
  755. * COMMENT ivy / counsel / swiper
  756. #+BEGIN_SRC emacs-lisp
  757. ; (require 'ivy)
  758. (use-package ivy
  759. :ensure t
  760. :diminish
  761. (ivy-mode . "")
  762. :defer t
  763. :init
  764. (ivy-mode 1)
  765. :bind
  766. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  767. :config
  768. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  769. ivy-height 20 ;; height of ivy window
  770. ivy-count-format "%d/%d" ;; current and total number
  771. ivy-re-builders-alist ;; regex replaces spaces with *
  772. '((t . ivy--regex-plus))))
  773. ; make counsel-M-x more descriptive
  774. (use-package ivy-rich
  775. :ensure t
  776. :defer t
  777. :init
  778. (ivy-rich-mode 1))
  779. (use-package counsel
  780. :ensure t
  781. :defer t
  782. :bind
  783. (("M-x" . counsel-M-x)
  784. ("C-x C-f" . counsel-find-file)
  785. ("C-x C-r" . counsel-recentf)
  786. ("C-x b" . counsel-switch-buffer)
  787. ("C-c C-f" . counsel-git)
  788. ("C-c h f" . counsel-describe-function)
  789. ("C-c h v" . counsel-describe-variable)
  790. ("M-i" . counsel-imenu)))
  791. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  792. ; ("C-r" . 'counsel-minibuffer-history)))
  793. (use-package swiper
  794. :ensure t
  795. :bind
  796. ("C-s" . swiper))
  797. (use-package ivy-hydra
  798. :ensure t)
  799. #+END_SRC
  800. * outlook
  801. In outlook a macro is necessary, also a reference to FM20.DLL
  802. (Microsoft Forms 2.0 Object Library, in c:\windows\syswow64\fm20.dll)
  803. The macro copies the GUID of the email to the clipboard
  804. Attention: the GUID changes when the email is moved to another folder!
  805. The macro:
  806. #+BEGIN_SRC
  807. Sub AddLinkToMessageInClipboard()
  808. 'Adds a link to the currently selected message to the clipboard
  809. Dim objMail As Outlook.MailItem
  810. Dim doClipboard As New DataObject
  811. 'One and ONLY one message muse be selected
  812. If Application.ActiveExplorer.Selection.Count <> 1 Then
  813. MsgBox ("Select one and ONLY one message.")
  814. Exit Sub
  815. End If
  816. Set objMail = Application.ActiveExplorer.Selection.Item(1)
  817. doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
  818. doClipboard.PutInClipboard
  819. End Sub
  820. #+END_SRC
  821. #+BEGIN_SRC emacs-lisp
  822. (use-package org
  823. :config
  824. (org-add-link-type "outlook" 'my--org-outlook-open))
  825. (defun my--org-outlook-open (id)
  826. (w32-shell-execute "open" "outlook" (concat " /select outlook:" id)))
  827. (defun my/org-outlook-open-test ()
  828. (interactive)
  829. (w32-shell-execute "open" "outlook" " /select outlook:000000008A209C397CEF2C4FBA9E54AEB5B1F97F0700846D043B407C5B43A0C05AFC46DC5C630587BE5E020900006E48FF8F6027694BA6593777F542C19E0002A6434D000000"))'
  830. #+END_SRC
  831. * misc
  832. #+begin_src emacs-lisp
  833. (use-package autorevert
  834. :diminish auto-revert-mode)
  835. #+end_src
  836. * COMMENT company (now corfu)
  837. #+BEGIN_SRC emacs-lisp
  838. (use-package company
  839. :defer 1
  840. :diminish
  841. :defer t
  842. :bind
  843. (("C-<tab>" . company-complete)
  844. :map company-active-map
  845. ("RET" . nil)
  846. ([return] . nil)
  847. ("TAB" . company-complete-selection)
  848. ([tab] . company-complete-selection)
  849. ("<right>" . company-complete-common)
  850. ("<escape>" . company-abort))
  851. :hook
  852. (after-init . global-company-mode)
  853. (emacs-lisp-mode . my--company-elisp)
  854. (org-mode . my--company-org)
  855. :config
  856. (defun my--company-elisp ()
  857. (message "set up company for elisp")
  858. (set (make-local-variable 'company-backends)
  859. '(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp
  860. company-yasnippet
  861. company-dabbrev-code
  862. company-files)))
  863. (defun my--company-org ()
  864. (set (make-local-variable 'company-backends)
  865. '(company-capf company-files))
  866. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  867. (message "setup company for org"))
  868. (setq company-idle-delay .2
  869. company-minimum-prefix-length 1
  870. company-require-match nil
  871. company-show-numbers t
  872. company-tooltip-align-annotations t))
  873. (use-package company-statistics
  874. :ensure t
  875. :after company
  876. :defer t
  877. :init
  878. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  879. :config
  880. (company-statistics-mode 1))
  881. (use-package company-dabbrev
  882. :ensure nil
  883. :after company
  884. :defer t
  885. :config
  886. (setq-default company-dabbrev-downcase nil))
  887. ;; adds a info box right of the cursor with doc of the function
  888. (use-package company-box
  889. :ensure t
  890. :diminish
  891. :defer t
  892. :hook
  893. (company-mode . company-box-mode))
  894. ; :init
  895. ; (add-hook 'company-mode-hook 'company-box-mode))
  896. #+END_SRC
  897. * orgmode
  898. ** some notes
  899. *** copy file path within emacs
  900. Enter dired-other-window
  901. place cursor on the file
  902. M-0 w (copy absolute path)
  903. C-u w (copy relative path)
  904. *** Archiving
  905. C-c C-x C-a
  906. To keep the subheading structure when archiving, set the properties of the superheading.
  907. #+begin_src org :tangle no
  908. ,* FOO
  909. :PROPERTIES:
  910. :ARCHIVE: %s_archive::* FOO
  911. ,** DONE BAR
  912. ,** TODO BAZ
  913. #+end_src
  914. When moving BAR to archive, it will go to FILENAME.org_archive below the heading FOO.
  915. [[http://doc.endlessparentheses.com/Var/org-archive-location.html][Other examples]]
  916. ** org
  917. This seems necessary to prevent 'org is already installed' error
  918. https://github.com/jwiegley/use-package/issues/319
  919. #+begin_src emacs-lisp
  920. (assq-delete-all 'org package--builtins)'
  921. (assq-delete-all 'org package--builtin-versions)
  922. #+end_src
  923. #+BEGIN_SRC emacs-lisp
  924. (defun my--buffer-prop-set (name value)
  925. "Set a file property called NAME to VALUE in buffer file.
  926. If the property is already set, replace its value."
  927. (setq name (downcase name))
  928. (org-with-point-at 1
  929. (let ((case-fold-search t))
  930. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  931. (point-max) t)
  932. (replace-match (concat "#+" name ": " value) 'fixedcase)
  933. (while (and (not (eobp))
  934. (looking-at "^[#:]"))
  935. (if (save-excursion (end-of-line) (eobp))
  936. (progn
  937. (end-of-line)
  938. (insert "\n"))
  939. (forward-line)
  940. (beginning-of-line)))
  941. (insert "#+" name ": " value "\n")))))
  942. (defun my--buffer-prop-remove (name)
  943. "Remove a buffer property called NAME."
  944. (org-with-point-at 1
  945. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  946. (point-max) t)
  947. (replace-match ""))))
  948. (use-package org
  949. :ensure t
  950. :pin gnu
  951. :mode (("\.org$" . org-mode))
  952. :diminish org-indent-mode
  953. :defer 1
  954. :hook
  955. (org-mode . org-indent-mode)
  956. (org-source-mode . smartparens-mode)
  957. :bind (("C-c l" . org-store-link)
  958. ("C-c c" . org-capture)
  959. ("C-c a" . org-agenda)
  960. :map org-mode-map ("S-<right>" . org-shiftright)
  961. ("S-<left>" . org-shiftleft))
  962. :init
  963. (defun my--org-company ()
  964. (set (make-local-variable 'company-backends)
  965. '(company-capf company-files))
  966. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  967. (defun my--org-agenda-files-set ()
  968. "Sets default agenda files.
  969. Necessary when updating roam agenda todos."
  970. (setq org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  971. (concat MY--PATH_ORG_FILES "projects.org")
  972. (concat MY--PATH_ORG_FILES "tasks.org")))
  973. (when *sys/linux*
  974. (nconc org-agenda-files
  975. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$"))))
  976. (my--org-agenda-files-set)
  977. :config
  978. :custom
  979. (when *sys/linux*
  980. (org-pretty-entities t))
  981. (org-startup-truncated t)
  982. (org-startup-align-all-tables t)
  983. (org-src-fontify-natively t) ;; use syntax highlighting in code blocks
  984. (org-src-preserve-indentation t) ;; no extra indentation
  985. (org-src-window-setup 'current-window) ;; C-c ' opens in current window
  986. (org-modules (quote (org-id
  987. org-habit
  988. org-tempo))) ;; easy templates
  989. (org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org"))
  990. (org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations"))
  991. (org-log-into-drawer "LOGBOOK")
  992. (org-log-done 'time) ;; create timestamp when task is done
  993. (org-blank-before-new-entry '((heading) (plain-list-item))) ;; prevent new line before new item
  994. (org-src-tab-acts-natively t))
  995. #+END_SRC
  996. Custom keywords, depending on environment
  997. #+BEGIN_SRC emacs-lisp
  998. (use-package org
  999. :if *work_remote*
  1000. :custom
  1001. (org-todo-keywords
  1002. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  1003. #+END_SRC
  1004. ** org-agenda
  1005. Sort agenda by deadline and priority
  1006. #+BEGIN_SRC emacs-lisp
  1007. (use-package org
  1008. :ensure t
  1009. :custom
  1010. (org-agenda-sorting-strategy
  1011. (quote
  1012. ((agenda deadline-up priority-down)
  1013. (todo priority-down category-keep)
  1014. (tags priority-down category-keep)
  1015. (search category-keep)))))
  1016. #+END_SRC
  1017. Customize the org agenda
  1018. #+BEGIN_SRC emacs-lisp
  1019. (defun my--org-skip-subtree-if-priority (priority)
  1020. "Skip an agenda subtree if it has a priority of PRIORITY.
  1021. PRIORITY may be one of the characters ?A, ?B, or ?C."
  1022. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  1023. (pri-value (* 1000 (- org-lowest-priority priority)))
  1024. (pri-current (org-get-priority (thing-at-point 'line t))))
  1025. (if (= pri-value pri-current)
  1026. subtree-end
  1027. nil)))
  1028. (use-package org
  1029. :ensure t
  1030. :custom
  1031. (org-agenda-custom-commands
  1032. '(("c" "Simple agenda view"
  1033. ((tags "PRIORITY=\"A\""
  1034. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1035. (org-agenda-overriding-header "Hohe Priorität:")))
  1036. (agenda ""
  1037. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1038. (org-agenda-span 7)
  1039. (org-agenda-start-on-weekday nil)
  1040. (org-agenda-overriding-header "Nächste 7 Tage:")))
  1041. (alltodo ""
  1042. ((org-agenda-skip-function '(or (my--org-skip-subtree-if-priority ?A)
  1043. (org-agenda-skip-if nil '(scheduled deadline))))
  1044. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))))
  1045. #+END_SRC
  1046. ** languages
  1047. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  1048. #+begin_src emacs-lisp
  1049. (use-package ob-org
  1050. :defer t
  1051. :ensure org-contrib
  1052. :commands
  1053. (org-babel-execute:org
  1054. org-babel-expand-body:org))
  1055. (use-package ob-python
  1056. :defer t
  1057. :ensure org-contrib
  1058. :commands (org-babel-execute:python))
  1059. (use-package ob-js
  1060. :defer t
  1061. :ensure org-contrib
  1062. :commands (org-babel-execute:js))
  1063. (use-package ob-shell
  1064. :defer t
  1065. :ensure org-contrib
  1066. :commands
  1067. (org-babel-execute:sh
  1068. org-babel-expand-body:sh
  1069. org-babel-execute:bash
  1070. org-babel-expand-body:bash))
  1071. (use-package ob-emacs-lisp
  1072. :defer t
  1073. :ensure org-contrib
  1074. :commands
  1075. (org-babel-execute:emacs-lisp
  1076. org-babel-expand-body:emacs-lisp))
  1077. (use-package ob-lisp
  1078. :defer t
  1079. :ensure org-contrib
  1080. :commands
  1081. (org-babel-execute:lisp
  1082. org-babel-expand-body:lisp))
  1083. (use-package ob-gnuplot
  1084. :defer t
  1085. :ensure org-contrib
  1086. :commands
  1087. (org-babel-execute:gnuplot
  1088. org-babel-expand-body:gnuplot))
  1089. (use-package ob-sqlite
  1090. :defer t
  1091. :ensure org-contrib
  1092. :commands
  1093. (org-babel-execute:sqlite
  1094. org-babel-expand-body:sqlite))
  1095. (use-package ob-latex
  1096. :defer t
  1097. :ensure org-contrib
  1098. :commands
  1099. (org-babel-execute:latex
  1100. org-babel-expand-body:latex))
  1101. (use-package ob-R
  1102. :defer t
  1103. :ensure org-contrib
  1104. :commands
  1105. (org-babel-execute:R
  1106. org-babel-expand-body:R))
  1107. (use-package ob-scheme
  1108. :defer t
  1109. :ensure org-contrib
  1110. :commands
  1111. (org-babel-execute:scheme
  1112. org-babel-expand-body:scheme))
  1113. #+end_src
  1114. ** habits
  1115. #+BEGIN_SRC emacs-lisp
  1116. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  1117. ;; (add-to-list 'org-modules "org-habit")
  1118. (setq org-habit-graph-column 80
  1119. org-habit-preceding-days 30
  1120. org-habit-following-days 7
  1121. org-habit-show-habits-only-for-today nil)
  1122. #+END_SRC
  1123. ** *TODO*
  1124. [[https://github.com/alphapapa/org-ql][org-ql]]
  1125. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  1126. ** org-caldav
  1127. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  1128. #+BEGIN_SRC emacs-lisp
  1129. ;;(use-package org-caldav
  1130. ;; :ensure t
  1131. ;; :config
  1132. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  1133. ;; org-caldav-calendar-id "orgmode"
  1134. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  1135. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  1136. #+END_SRC
  1137. ** journal
  1138. [[https://github.com/bastibe/org-journal][Source]]
  1139. Ggf. durch org-roam-journal ersetzen
  1140. #+BEGIN_SRC emacs-lisp
  1141. (use-package org-journal
  1142. :if *sys/linux*
  1143. :ensure t
  1144. :defer t
  1145. :config
  1146. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  1147. (when (and (boundp 'org-journal-dir)
  1148. (boundp 'org-journal-enable-agenda-integration))
  1149. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  1150. org-journal-enable-agenda-integration t)))
  1151. #+END_SRC
  1152. ** org-roam
  1153. [[https://github.com/org-roam/org-roam][Github]]
  1154. Um Headings innerhalb einer Datei zu verlinken:
  1155. - org-id-get-create im Heading,
  1156. - org-roam-node-insert in der verweisenden Datei
  1157. Bei Problemen wie unique constraint
  1158. org-roam-db-clear-all
  1159. org-roam-db-sync
  1160. #+BEGIN_SRC emacs-lisp
  1161. (use-package org-roam
  1162. :ensure t
  1163. :defer 2
  1164. :after org
  1165. :init
  1166. (setq org-roam-v2-ack t)
  1167. (defun my--roamtodo-p ()
  1168. "Return non-nil if current buffer has any todo entry.
  1169. TODO entries marked as done are ignored, meaning this function
  1170. returns nil if current buffer contains only completed tasks."
  1171. (seq-find
  1172. (lambda (type)
  1173. (eq type 'todo))
  1174. (org-element-map
  1175. (org-element-parse-buffer 'headline)
  1176. 'headline
  1177. (lambda (h)
  1178. (org-element-property :todo-type h)))))
  1179. (defun my--roamtodo-update-tag ()
  1180. "Update ROAMTODO tag in the current buffer."
  1181. (when (and (not (active-minibuffer-window))
  1182. (my--buffer-roam-note-p))
  1183. (save-excursion
  1184. (goto-char (point-min))
  1185. (let* ((tags (my--buffer-tags-get))
  1186. (original-tags tags))
  1187. (if (my--roamtodo-p)
  1188. (setq tags (cons "roamtodo" tags))
  1189. (setq tags (remove "roamtodo" tags)))
  1190. ;;cleanup duplicates
  1191. (when (or (seq-difference tags original-tags)
  1192. (seq-difference original-tags tags))
  1193. (apply #'my--buffer-tags-set tags))))))
  1194. (defun my--buffer-tags-get ()
  1195. "Return filetags value in current buffer."
  1196. (my--buffer-prop-get-list "filetags" "[ :]"))
  1197. (defun my--buffer-tags-set (&rest tags)
  1198. "Set TAGS in current buffer.
  1199. If filetags value is already set, replace it."
  1200. (if tags
  1201. (my--buffer-prop-set
  1202. "filetags" (concat ":" (string-join tags ":") ":"))
  1203. (my--buffer-prop-remove "filetags")))
  1204. (defun my--buffer-tags-add (tag)
  1205. "Add a TAG to filetags in current buffer."
  1206. (let* ((tags (my--buffer-tags-get))
  1207. (tags (append tags (list tag))))
  1208. (apply #'my--buffer-tags-set tags)))
  1209. (defun my--buffer-tags-remove (tag)
  1210. "Remove a TAG from filetags in current buffer."
  1211. (let* ((tags (my--buffer-tags-get))
  1212. (tags (delete tag tags)))
  1213. (apply #'my--buffer-tags-set tags)))
  1214. (defun my--buffer-prop-set (name value)
  1215. "Set a file property called NAME to VALUE in buffer file.
  1216. If the property is already set, replace its value."
  1217. (setq name (downcase name))
  1218. (org-with-point-at 1
  1219. (let ((case-fold-search t))
  1220. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  1221. (point-max) t)
  1222. (replace-match (concat "#+" name ": " value) 'fixedcase)
  1223. (while (and (not (eobp))
  1224. (looking-at "^[#:]"))
  1225. (if (save-excursion (end-of-line) (eobp))
  1226. (progn
  1227. (end-of-line)
  1228. (insert "\n"))
  1229. (forward-line)
  1230. (beginning-of-line)))
  1231. (insert "#+" name ": " value "\n")))))
  1232. (defun my--buffer-prop-set-list (name values &optional separators)
  1233. "Set a file property called NAME to VALUES in current buffer.
  1234. VALUES are quoted and combined into single string using
  1235. `combine-and-quote-strings'.
  1236. If SEPARATORS is non-nil, it should be a regular expression
  1237. matching text that separates, but is not part of, the substrings.
  1238. If nil it defaults to `split-string-and-unquote', normally
  1239. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t.
  1240. If the property is already set, replace its value."
  1241. (my--buffer-prop-set
  1242. name (combine-and-quote-strings values separators)))
  1243. (defun my--buffer-prop-get (name)
  1244. "Get a buffer property called NAME as a string."
  1245. (org-with-point-at 1
  1246. (when (re-search-forward (concat "^#\\+" name ": \\(.*\\)")
  1247. (point-max) t)
  1248. (buffer-substring-no-properties
  1249. (match-beginning 1)
  1250. (match-end 1)))))
  1251. (defun my--buffer-prop-get-list (name &optional separators)
  1252. "Get a buffer property NAME as a list using SEPARATORS.
  1253. If SEPARATORS is non-nil, it should be a regular expression
  1254. matching text that separates, but is not part of, the substrings.
  1255. If nil it defaults to `split-string-default-separators', normally
  1256. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t."
  1257. (let ((value (my--buffer-prop-get name)))
  1258. (when (and value (not (string-empty-p value)))
  1259. (split-string-and-unquote value separators))))
  1260. (defun my--buffer-prop-remove (name)
  1261. "Remove a buffer property called NAME."
  1262. (org-with-point-at 1
  1263. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  1264. (point-max) t)
  1265. (replace-match ""))))
  1266. (defun my--buffer-roam-note-p ()
  1267. "Return non-nil if the currently visited buffer is a note."
  1268. (and buffer-file-name
  1269. (string-prefix-p
  1270. (expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM))
  1271. (file-name-directory buffer-file-name))))
  1272. (defun my--org-roam-filter-by-tag (tag-name)
  1273. (lambda (node)
  1274. (member tag-name (org-roam-node-tags node))))
  1275. (defun my--org-roam-list-notes-by-tag (tag-name)
  1276. (mapcar #'org-roam-node-file
  1277. (seq-filter
  1278. (my--org-roam-filter-by-tag tag-name)
  1279. (org-roam-node-list))))
  1280. (defun my/org-roam-refresh-agenda-list ()
  1281. "Add all org roam files with #+filetags: roamtodo"
  1282. (interactive)
  1283. (my--org-agenda-files-set)
  1284. (nconc org-agenda-files
  1285. (my--org-roam-list-notes-by-tag "roamtodo"))
  1286. (setq org-agenda-files (delete-dups org-agenda-files)))
  1287. (add-hook 'find-file-hook #'my--roamtodo-update-tag)
  1288. (add-hook 'before-save-hook #'my--roamtodo-update-tag)
  1289. (advice-add 'org-agenda :before #'my/org-roam-refresh-agenda-list)
  1290. (advice-add 'org-todo-list :before #'my/org-roam-refresh-agenda-list)
  1291. (add-to-list 'org-tags-exclude-from-inheritance "roamtodo")
  1292. :config
  1293. (require 'org-roam-dailies) ;; ensure the keymap is available
  1294. (org-roam-db-autosync-mode)
  1295. ;; build the agenda list the first ime for the session
  1296. (my/org-roam-refresh-agenda-list)
  1297. :custom
  1298. (org-roam-directory MY--PATH_ORG_ROAM)
  1299. (org-roam-completion-everywhere t)
  1300. (org-roam-capture-templates
  1301. '(("n" "note" plain
  1302. "%?"
  1303. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1304. :unnarrowed t)
  1305. ("i" "idea" plain
  1306. "%?"
  1307. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1308. :unnarrowed t)
  1309. ))
  1310. :bind (("C-c n l" . org-roam-buffer-toggle)
  1311. ("C-c n f" . org-roam-node-find)
  1312. ("C-c n i" . org-roam-node-insert)
  1313. :map org-mode-map
  1314. ("C-M-i" . completion-at-point)
  1315. :map org-roam-dailies-map
  1316. ("Y" . org-roam-dailies-capture-yesterday)
  1317. ("T" . org-roam-dailies-capture-tomorrow))
  1318. :bind-keymap
  1319. ("C-c n d" . org-roam-dailies-map))
  1320. (when *sys/windows*
  1321. (use-package emacsql-sqlite3
  1322. :ensure t
  1323. :init
  1324. (setq emacsql-sqlite3-binary "P:/Tools/sqlite/sqlite3.exe"
  1325. exec-path (append exec-path '("P:/Tools/sqlite"))))
  1326. (use-package org-roam
  1327. :requires emacsql-sqlite3
  1328. :init
  1329. :custom
  1330. (add-to-list 'org-roam-capture-templates
  1331. '("t" "telephone call" plain
  1332. "%?"
  1333. :if-new (file+head "telephone/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: CALL %<%Y-%m-%d %H:%M> ${title}\n")
  1334. :unnarrowed t) t)
  1335. (add-to-list 'org-roam-capture-templates
  1336. '("p" "project" plain
  1337. "%?"
  1338. :if-new (file+head "projects/${slug}.org" "#+title: ${title}\n#+filetags: :project:\n")
  1339. :unnarrowed t) t)
  1340. (add-to-list 'org-roam-capture-templates
  1341. '("s" "Sicherheitenmeldung" plain
  1342. "*** TODO [#A] Sicherheitenmeldung ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1343. :target (file+olp "tasks.org" ("Todos" "Sicherheitenmeldungen"))) t)
  1344. (add-to-list 'org-roam-capture-templates
  1345. '("m" "Monatsbericht" plain'
  1346. "*** TODO [#A] Monatsbericht ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1347. :target (file+olp "tasks.org" ("Todos" "Monatsberichte"))) t)
  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