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.

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