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.

1997 lines
59 KiB

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