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.

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