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.

1956 lines
60 KiB

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