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.

1999 lines
60 KiB

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