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.

1985 lines
60 KiB

5 years ago
2 years ago
3 years ago
3 years ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
6 years ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
1 year ago
9 months ago
9 months ago
9 months ago
6 years ago
6 years ago
6 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
1 year ago
9 months ago
9 months ago
2 years ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
6 years ago
9 months ago
9 months ago
9 months ago
9 months ago
6 years ago
9 months ago
9 months ago
6 years ago
6 years ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
1 year ago
9 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. (setq org-todo-keywords
  1091. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED")))
  1092. (setq org-capture-templates
  1093. '(("t" "telephone call" entry
  1094. ; (file+olp+datetree (concat MY--PATH_ORG_FILES "phone_calls.org"))
  1095. (file+datetree "p:/Eigene Dateien/Notizen/phone_calls.org")
  1096. "* [%<%Y-%m-%d %H:%M>] %?"
  1097. :empty-lines 0 :jump-to-captured t))))
  1098. (when *sys/linux*
  1099. (org-pretty-entities t))
  1100. :custom
  1101. (org-startup-truncated t)
  1102. (org-startup-align-all-tables t)
  1103. (org-src-fontify-natively t) ;; use syntax highlighting in code blocks
  1104. (org-src-preserve-indentation t) ;; no extra indentation
  1105. (org-src-window-setup 'current-window) ;; C-c ' opens in current window
  1106. (org-modules (quote (org-id
  1107. org-habit
  1108. org-tempo))) ;; easy templates
  1109. (org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org"))
  1110. (org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations"))
  1111. (org-log-into-drawer "LOGBOOK")
  1112. (org-log-done 'time) ;; create timestamp when task is done
  1113. (org-blank-before-new-entry '((heading) (plain-list-item))) ;; prevent new line before new item
  1114. (org-src-tab-acts-natively t)
  1115. ;;Sort agenda by deadline and priority
  1116. (org-agenda-sorting-strategy
  1117. (quote
  1118. ((agenda deadline-up priority-down)
  1119. (todo priority-down category-keep)
  1120. (tags priority-down category-keep)
  1121. (search category-keep))))
  1122. (org-agenda-custom-commands
  1123. '(("c" "Simple agenda view"
  1124. ((tags "PRIORITY=\"A\""
  1125. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1126. (org-agenda-overriding-header "Hohe Priorität:")))
  1127. (agenda ""
  1128. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1129. (org-agenda-span 7)
  1130. (org-agenda-start-on-weekday nil)
  1131. (org-agenda-overriding-header "Nächste 7 Tage:")))
  1132. (alltodo ""
  1133. ((org-agenda-skip-function '(or (my--org-skip-subtree-if-priority ?A)
  1134. (org-agenda-skip-if nil '(scheduled deadline))))
  1135. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))))
  1136. #+END_SRC
  1137. ** COMMENT languages
  1138. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  1139. Elpaca cant find it, though it's built in org
  1140. #+begin_src emacs-lisp
  1141. (use-package ob-python
  1142. ; :elpaca nil
  1143. :defer t
  1144. :after org
  1145. ; :ensure org-contrib
  1146. :commands
  1147. (org-babel-execute:python))
  1148. #+end_src
  1149. ** COMMENT habits
  1150. #+BEGIN_SRC emacs-lisp
  1151. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  1152. ;; (add-to-list 'org-modules "org-habit")
  1153. (setq org-habit-graph-column 80
  1154. org-habit-preceding-days 30
  1155. org-habit-following-days 7
  1156. org-habit-show-habits-only-for-today nil)
  1157. #+END_SRC
  1158. ** *TODO*
  1159. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  1160. ** COMMENT journal
  1161. [[https://github.com/bastibe/org-journal][Source]]
  1162. Ggf. durch org-roam-journal ersetzen
  1163. #+BEGIN_SRC emacs-lisp
  1164. (use-package org-journal
  1165. :if *sys/linux*
  1166. :ensure t
  1167. :defer t
  1168. :config
  1169. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  1170. (when (and (boundp 'org-journal-dir)
  1171. (boundp 'org-journal-enable-agenda-integration))
  1172. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  1173. org-journal-enable-agenda-integration t)))
  1174. #+END_SRC
  1175. ** org-roam
  1176. [[https://github.com/org-roam/org-roam][Github]]
  1177. Um Headings innerhalb einer Datei zu verlinken:
  1178. - org-id-get-create im Heading,
  1179. - org-roam-node-insert in der verweisenden Datei
  1180. Bei Problemen wie unique constraint
  1181. org-roam-db-clear-all
  1182. org-roam-db-sync
  1183. #+BEGIN_SRC emacs-lisp
  1184. (use-package emacsql-sqlite-builtin
  1185. :ensure t)
  1186. (use-package org-roam
  1187. :requires emacsql-sqlite-builtin
  1188. :ensure t
  1189. :defer 2
  1190. :after org
  1191. :init
  1192. (setq org-roam-v2-ack t)
  1193. (defun my--roamtodo-p ()
  1194. "Return non-nil if current buffer has any todo entry.
  1195. TODO entries marked as done are ignored, meaning this function
  1196. returns nil if current buffer contains only completed tasks."
  1197. (seq-find
  1198. (lambda (type)
  1199. (eq type 'todo))
  1200. (org-element-map
  1201. (org-element-parse-buffer 'headline)
  1202. 'headline
  1203. (lambda (h)
  1204. (org-element-property :todo-type h)))))
  1205. (defun my--roamtodo-update-tag ()
  1206. "Update ROAMTODO tag in the current buffer."
  1207. (when (and (not (active-minibuffer-window))
  1208. (my--buffer-roam-note-p))
  1209. (save-excursion
  1210. (goto-char (point-min))
  1211. (let* ((tags (my--buffer-tags-get))
  1212. (original-tags tags))
  1213. (if (my--roamtodo-p)
  1214. (setq tags (cons "roamtodo" tags))
  1215. (setq tags (remove "roamtodo" tags)))
  1216. ;;cleanup duplicates
  1217. (when (or (seq-difference tags original-tags)
  1218. (seq-difference original-tags tags))
  1219. (apply #'my--buffer-tags-set tags))))))
  1220. (defun my--buffer-tags-get ()
  1221. "Return filetags value in current buffer."
  1222. (my--buffer-prop-get-list "filetags" "[ :]"))
  1223. (defun my--buffer-tags-set (&rest tags)
  1224. "Set TAGS in current buffer.
  1225. If filetags value is already set, replace it."
  1226. (if tags
  1227. (my--buffer-prop-set
  1228. "filetags" (concat ":" (string-join tags ":") ":"))
  1229. (my--buffer-prop-remove "filetags")))
  1230. (defun my--buffer-tags-add (tag)
  1231. "Add a TAG to filetags in current buffer."
  1232. (let* ((tags (my--buffer-tags-get))
  1233. (tags (append tags (list tag))))
  1234. (apply #'my--buffer-tags-set tags)))
  1235. (defun my--buffer-tags-remove (tag)
  1236. "Remove a TAG from filetags in current buffer."
  1237. (let* ((tags (my--buffer-tags-get))
  1238. (tags (delete tag tags)))
  1239. (apply #'my--buffer-tags-set tags)))
  1240. (defun my--buffer-prop-set (name value)
  1241. "Set a file property called NAME to VALUE in buffer file.
  1242. If the property is already set, replace its value."
  1243. (setq name (downcase name))
  1244. (org-with-point-at 1
  1245. (let ((case-fold-search t))
  1246. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  1247. (point-max) t)
  1248. (replace-match (concat "#+" name ": " value) 'fixedcase)
  1249. (while (and (not (eobp))
  1250. (looking-at "^[#:]"))
  1251. (if (save-excursion (end-of-line) (eobp))
  1252. (progn
  1253. (end-of-line)
  1254. (insert "\n"))
  1255. (forward-line)
  1256. (beginning-of-line)))
  1257. (insert "#+" name ": " value "\n")))))
  1258. (defun my--buffer-prop-set-list (name values &optional separators)
  1259. "Set a file property called NAME to VALUES in current buffer.
  1260. VALUES are quoted and combined into single string using
  1261. `combine-and-quote-strings'.
  1262. If SEPARATORS is non-nil, it should be a regular expression
  1263. matching text that separates, but is not part of, the substrings.
  1264. If nil it defaults to `split-string-and-unquote', normally
  1265. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t.
  1266. If the property is already set, replace its value."
  1267. (my--buffer-prop-set
  1268. name (combine-and-quote-strings values separators)))
  1269. (defun my--buffer-prop-get (name)
  1270. "Get a buffer property called NAME as a string."
  1271. (org-with-point-at 1
  1272. (when (re-search-forward (concat "^#\\+" name ": \\(.*\\)")
  1273. (point-max) t)
  1274. (buffer-substring-no-properties
  1275. (match-beginning 1)
  1276. (match-end 1)))))
  1277. (defun my--buffer-prop-get-list (name &optional separators)
  1278. "Get a buffer property NAME as a list using SEPARATORS.
  1279. If SEPARATORS is non-nil, it should be a regular expression
  1280. matching text that separates, but is not part of, the substrings.
  1281. If nil it defaults to `split-string-default-separators', normally
  1282. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t."
  1283. (let ((value (my--buffer-prop-get name)))
  1284. (when (and value (not (string-empty-p value)))
  1285. (split-string-and-unquote value separators))))
  1286. (defun my--buffer-prop-remove (name)
  1287. "Remove a buffer property called NAME."
  1288. (org-with-point-at 1
  1289. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  1290. (point-max) t)
  1291. (replace-match ""))))
  1292. (defun my--buffer-roam-note-p ()
  1293. "Return non-nil if the currently visited buffer is a note."
  1294. (and buffer-file-name
  1295. (string-prefix-p
  1296. (expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM))
  1297. (file-name-directory buffer-file-name))))
  1298. (defun my--org-roam-filter-by-tag (tag-name)
  1299. (lambda (node)
  1300. (member tag-name (org-roam-node-tags node))))
  1301. (defun my--org-roam-list-notes-by-tag (tag-name)
  1302. (mapcar #'org-roam-node-file
  1303. (seq-filter
  1304. (my--org-roam-filter-by-tag tag-name)
  1305. (org-roam-node-list))))
  1306. (defun my/org-roam-refresh-agenda-list ()
  1307. "Add all org roam files with #+filetags: roamtodo"
  1308. (interactive)
  1309. (my--org-agenda-files-set)
  1310. (nconc org-agenda-files
  1311. (my--org-roam-list-notes-by-tag "roamtodo"))
  1312. (setq org-agenda-files (delete-dups org-agenda-files)))
  1313. (add-hook 'find-file-hook #'my--roamtodo-update-tag)
  1314. (add-hook 'before-save-hook #'my--roamtodo-update-tag)
  1315. (advice-add 'org-agenda :before #'my/org-roam-refresh-agenda-list)
  1316. (advice-add 'org-todo-list :before #'my/org-roam-refresh-agenda-list)
  1317. (add-to-list 'org-tags-exclude-from-inheritance "roamtodo")
  1318. :config
  1319. (require 'org-roam-dailies) ;; ensure the keymap is available
  1320. (org-roam-db-autosync-mode)
  1321. ;; build the agenda list the first ime for the session
  1322. (my/org-roam-refresh-agenda-list)
  1323. (when *work_remote*
  1324. (setq org-roam-capture-templates
  1325. '(("n" "note" plain
  1326. "%?"
  1327. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1328. :unnarrowed t)
  1329. ("i" "idea" plain
  1330. "%?"
  1331. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1332. :unnarrowed t)
  1333. ("p" "project" plain
  1334. "%?"
  1335. :target (file+head "projects/${slug}.org" "#+title: ${title}\n#+filetags: :project:\n")
  1336. :unnarrowed t)
  1337. ("s" "Sicherheitenmeldung" plain
  1338. "*** TODO [#A] Sicherheitenmeldung ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1339. :target (file+olp "tasks.org" ("Todos" "Sicherheitenmeldungen")))
  1340. ("m" "Monatsbericht" plain
  1341. "*** TODO [#A] Monatsbericht ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1342. :target (file+olp "tasks.org" ("Todos" "Monatsberichte"))))))
  1343. :custom
  1344. (org-roam-database-connector 'sqlite-builtin)
  1345. (org-roam-directory MY--PATH_ORG_ROAM)
  1346. (org-roam-completion-everywhere t)
  1347. (org-roam-capture-templates
  1348. '(("n" "note" plain
  1349. "%?"
  1350. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1351. :unnarrowed t)
  1352. ("i" "idea" plain
  1353. "%?"
  1354. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1355. :unnarrowed t)
  1356. ))
  1357. :bind (("C-c n l" . org-roam-buffer-toggle)
  1358. ("C-c n f" . org-roam-node-find)
  1359. ("C-c n i" . org-roam-node-insert)
  1360. :map org-mode-map
  1361. ("C-M-i" . completion-at-point)
  1362. :map org-roam-dailies-map
  1363. ("Y" . org-roam-dailies-capture-yesterday)
  1364. ("T" . org-roam-dailies-capture-tomorrow))
  1365. :bind-keymap
  1366. ("C-c n d" . org-roam-dailies-map))
  1367. #+END_SRC
  1368. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  1369. * Programming
  1370. ** Magit / Git
  1371. Little crash course in magit:
  1372. - magit-init to init a git project
  1373. - magit-status (C-x g) to call the status window
  1374. In status buffer:
  1375. - s stage files
  1376. - u unstage files
  1377. - U unstage all files
  1378. - a apply changes to staging
  1379. - c c commit (type commit message, then C-c C-c to commit)
  1380. - b b switch to another branch
  1381. - P u git push
  1382. - F u git pull
  1383. #+BEGIN_SRC emacs-lisp
  1384. (use-package magit
  1385. :ensure t
  1386. ; :pin melpa-stable
  1387. :defer t
  1388. :init
  1389. ; set git-path in work environment
  1390. (if (string-equal user-login-name "POH")
  1391. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1392. )
  1393. :bind (("C-x g" . magit-status)))
  1394. #+END_SRC
  1395. ** COMMENT Eglot (can't do dap-mode, maybe dape?)
  1396. for python pyls (in env: pip install python-language-server) seems to work better than pyright (npm install -g pyright),
  1397. at least pandas couldnt be resolved in pyright
  1398. #+begin_src emacs-lisp
  1399. (use-package eglot
  1400. :ensure t
  1401. :init
  1402. (setq completion-category-overrides '((eglot (styles orderless))))
  1403. :config
  1404. (add-to-list 'eglot-server-programs '(python-mode . ("pyright-langserver" "--stdio")))
  1405. (with-eval-after-load 'eglot
  1406. (load-library "project"))
  1407. :hook
  1408. (python-mode . eglot-ensure)
  1409. :custom
  1410. (eglot-ignored-server-capabilities '(:documentHighlightProvider))
  1411. (eglot-autoshutdown t)
  1412. (eglot-events-buffer-size 0)
  1413. )
  1414. ;; performance stuff if necessary
  1415. ;(fset #'jsonrpc--log-event #'ignore)
  1416. #+end_src
  1417. ** LSP-Mode
  1418. #+begin_src emacs-lisp
  1419. (defun corfu-lsp-setup ()
  1420. (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
  1421. '(orderless)))
  1422. (use-package lsp-mode
  1423. :ensure t
  1424. ; :hook
  1425. ; ((python-mode . lsp))
  1426. :custom
  1427. (lsp-completion-provider :none)
  1428. (lsp-enable-suggest-server-download nil)
  1429. :hook
  1430. (lsp-completion-mode #'corfu-lsp-setup))
  1431. ;(use-package lsp-ui
  1432. ; :ensure t
  1433. ; :commands lsp-ui-mode)
  1434. (use-package lsp-pyright
  1435. :ensure t
  1436. :after (python lsp-mode)
  1437. :custom
  1438. (lsp-pyright-multi-root nil)
  1439. :hook
  1440. (python-mode-hook . (lambda ()
  1441. (require 'lsp-pyright) (lsp))))
  1442. #+end_src
  1443. ** flymake
  1444. python in venv: pip install pyflake (or ruff?)
  1445. TODO: if ruff active, sideline stops working
  1446. #+begin_src emacs-lisp
  1447. (setq python-flymake-command '("ruff" "--quiet" "--stdin-filename=stdin" "-"))
  1448. #+end_src
  1449. ** sideline
  1450. show flymake errors on the right of code window
  1451. #+begin_src emacs-lisp
  1452. (use-package sideline
  1453. :ensure t)
  1454. (use-package sideline-flymake
  1455. :ensure t
  1456. :requires sideline
  1457. :hook
  1458. (flymake-mode . sideline-mode)
  1459. :init
  1460. (setq sideline-flymake-display-mode 'line ; 'point or 'line
  1461. ; sideline-backends-left '(sideline-lsp)
  1462. sideline-backends-right '(sideline-flymake)))
  1463. #+end_src
  1464. ** yasnippet
  1465. For useful snippet either install yasnippet-snippets or get them from here
  1466. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1467. #+begin_src emacs-lisp
  1468. (use-package yasnippet
  1469. :ensure t
  1470. :defer t
  1471. :diminish yas-minor-mode
  1472. :config
  1473. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1474. (yas-global-mode t)
  1475. (yas-reload-all)
  1476. (unbind-key "TAB" yas-minor-mode-map)
  1477. (unbind-key "<tab>" yas-minor-mode-map))
  1478. #+end_src
  1479. ** hippie expand
  1480. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1481. #+begin_src emacs-lisp
  1482. (use-package hippie-exp
  1483. :elpaca nil
  1484. :defer t
  1485. :bind
  1486. ("C-<return>" . hippie-expand)
  1487. :config
  1488. (setq hippie-expand-try-functions-list
  1489. '(yas-hippie-try-expand emmet-expand-line)))
  1490. #+end_src
  1491. ** COMMENT flycheck (now flymake)
  1492. #+BEGIN_SRC emacs-lisp
  1493. (use-package flycheck
  1494. :ensure t
  1495. :hook
  1496. ((css-mode . flycheck-mode)
  1497. (emacs-lisp-mode . flycheck-mode)
  1498. (python-mode . flycheck-mode))
  1499. :defer 1.0
  1500. :init
  1501. (setq flycheck-emacs-lisp-load-path 'inherit)
  1502. :config
  1503. (setq-default
  1504. flycheck-check-synta-automatically '(save mode-enabled)
  1505. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1506. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1507. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1508. #+END_SRC
  1509. ** smartparens
  1510. #+BEGIN_SRC emacs-lisp
  1511. (use-package smartparens
  1512. :ensure t
  1513. :diminish smartparens-mode
  1514. :bind
  1515. (:map smartparens-mode-map
  1516. ("C-M-f" . sp-forward-sexp)
  1517. ("C-M-b" . sp-backward-sexp)
  1518. ("C-M-a" . sp-backward-down-sexp)
  1519. ("C-M-e" . sp-up-sexp)
  1520. ("C-M-w" . sp-copy-sexp)
  1521. ("M-k" . sp-kill-sexp)
  1522. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1523. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1524. ("C-]" . sp-select-next-thing-exchange))
  1525. :config
  1526. (setq sp-show-pair-from-inside nil
  1527. sp-escape-quotes-after-insert nil)
  1528. (require 'smartparens-config))
  1529. #+END_SRC
  1530. ** lisp
  1531. #+BEGIN_SRC emacs-lisp
  1532. (use-package elisp-mode
  1533. :elpaca nil
  1534. :defer t)
  1535. #+END_SRC
  1536. ** web
  1537. apt install npm
  1538. sudo npm install -g vscode-html-languageserver-bin
  1539. evtl alternativ typescript-language-server?
  1540. Unter Windows:
  1541. Hier runterladen: https://nodejs.org/dist/latest/
  1542. und in ein Verzeichnis entpacken.
  1543. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1544. PATH=P:\path\to\node;%path%
  1545. *** web-mode
  1546. #+BEGIN_SRC emacs-lisp
  1547. (use-package web-mode
  1548. :ensure t
  1549. :defer t
  1550. :mode
  1551. ("\\.phtml\\'"
  1552. "\\.tpl\\.php\\'"
  1553. "\\.djhtml\\'"
  1554. "\\.[t]?html?\\'")
  1555. :hook
  1556. (web-mode . smartparens-mode)
  1557. :init
  1558. (if *work_remote*
  1559. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1560. :config
  1561. (setq web-mode-enable-auto-closing t
  1562. web-mode-enable-auto-pairing t))
  1563. #+END_SRC
  1564. Emmet offers snippets, similar to yasnippet.
  1565. Default completion is C-j
  1566. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1567. #+begin_src emacs-lisp
  1568. (use-package emmet-mode
  1569. :ensure t
  1570. :defer t
  1571. :hook
  1572. ((web-mode . emmet-mode)
  1573. (css-mode . emmet-mode))
  1574. :config
  1575. (unbind-key "C-<return>" emmet-mode-keymap))
  1576. #+end_src
  1577. *** JavaScript
  1578. npm install -g typescript-language-server typescript
  1579. maybe only typescript?
  1580. npm install -g prettier
  1581. #+begin_src emacs-lisp
  1582. (use-package rjsx-mode
  1583. :ensure t
  1584. :mode ("\\.js\\'"
  1585. "\\.jsx'"))
  1586. ; :config
  1587. ; (setq js2-mode-show-parse-errors nil
  1588. ; js2-mode-show-strict-warnings nil
  1589. ; js2-basic-offset 2
  1590. ; js-indent-level 2)
  1591. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1592. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1593. (use-package tide
  1594. :ensure t
  1595. :after (rjsx-mode company flycheck)
  1596. ; :hook (rjsx-mode . setup-tide-mode)
  1597. :config
  1598. (defun setup-tide-mode ()
  1599. "Setup function for tide."
  1600. (interactive)
  1601. (tide-setup)
  1602. (flycheck-mode t)
  1603. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1604. (tide-hl-identifier-mode t)))
  1605. ;; needs npm install -g prettier
  1606. (use-package prettier-js
  1607. :ensure t
  1608. :after (rjsx-mode)
  1609. :defer t
  1610. :diminish prettier-js-mode
  1611. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1612. #+end_src
  1613. ** YAML
  1614. #+begin_src emacs-lisp
  1615. (use-package yaml-mode
  1616. :if *sys/linux*
  1617. :ensure t
  1618. :defer t
  1619. :mode ("\\.yml$" . yaml-mode))
  1620. #+end_src
  1621. ** R
  1622. #+BEGIN_SRC emacs-lisp
  1623. (use-package ess
  1624. :ensure t
  1625. :defer t
  1626. :init
  1627. (if *work_remote*
  1628. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1629. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1630. #+END_SRC
  1631. ** project.el
  1632. #+begin_src emacs-lisp
  1633. (use-package project
  1634. :custom
  1635. (project-vc-extra-root-markers '(".project.el" ".project" )))
  1636. #+end_src
  1637. ** Python
  1638. Preparations:
  1639. - Install language server in *each* projects venv
  1640. source ./bin/activate
  1641. pip install pyright
  1642. - in project root:
  1643. touch .project.el
  1644. echo "((nil . (pyvenv-activate . "/path/to/project/.env")))" >> .dir-locals.el
  1645. für andere language servers
  1646. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1647. TODO if in a project, set venv automatically
  1648. (when-let ((project (project-current))) (project-root project))
  1649. returns project path from project.el
  1650. to recognize a project, either have git or
  1651. place a .project.el file in project root and
  1652. (setq project-vc-extra-root-markers '(".project.el" "..." ))
  1653. #+begin_src emacs-lisp
  1654. (use-package python
  1655. :if *sys/linux*
  1656. :delight "π "
  1657. :defer t
  1658. :bind (("M-[" . python-nav-backward-block)
  1659. ("M-]" . python-nav-forward-block))
  1660. :mode
  1661. (("\\.py\\'" . python-mode)))
  1662. (use-package pyvenv
  1663. ; :if *sys/linux*
  1664. :ensure t
  1665. :defer t
  1666. :after python
  1667. :hook
  1668. (python-mode . pyvenv-mode)
  1669. :custom
  1670. (pyvenv-default-virtual-env-name ".env")
  1671. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]"))))
  1672. ;; formatting to pep8
  1673. ;; requires pip install black
  1674. ;(use-package blacken
  1675. ; :ensure t)
  1676. #+end_src
  1677. TODO python mode hook:
  1678. - activate venv
  1679. - activate eglot with proper ls
  1680. - activate tree-sitter?
  1681. - have some fallback if activations fail
  1682. * beancount
  1683. ** Installation
  1684. #+BEGIN_SRC shell :tangle no
  1685. sudo su
  1686. cd /opt
  1687. python3 -m venv beancount
  1688. source ./beancount/bin/activate
  1689. pip3 install wheel
  1690. pip3 install beancount
  1691. sleep 100
  1692. echo "shell running!"
  1693. deactivate
  1694. #+END_SRC
  1695. #+begin_src emacs-lisp
  1696. (use-package beancount
  1697. :elpaca nil
  1698. :if *sys/linux*
  1699. :load-path "user-global/elisp/"
  1700. ; :ensure t
  1701. :defer t
  1702. :mode
  1703. ("\\.beancount$" . beancount-mode)
  1704. :hook
  1705. (beancount-mode . my/beancount-company)
  1706. :config
  1707. (defun my/beancount-company ()
  1708. (setq-local completion-at-point-functions #'beancount-completion-at-point))
  1709. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1710. #+end_src
  1711. +BEGIN_SRC emacs-lisp
  1712. (use-package beancount
  1713. :if *sys/linux*
  1714. :load-path "user-global/elisp"
  1715. ; :ensure t
  1716. :defer t
  1717. :mode
  1718. ("\\.beancount$" . beancount-mode)
  1719. ; :hook
  1720. ; (beancount-mode . my/beancount-company)
  1721. ; :init
  1722. ; (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1723. :config
  1724. (defun my/beancount-company ()
  1725. (setq-local completion-at-point-functions #'beancount-complete-at-point nil t))
  1726. ; (mapcar #'cape-company-to-capf
  1727. ; (list #'company-beancount #'company-dabbrev))))
  1728. (defun my--beancount-companyALT ()
  1729. (set (make-local-variable 'company-backends)
  1730. '(company-beancount)))
  1731. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1732. +END_SRC
  1733. To support org-babel, check if it can find the symlink to ob-beancount.el
  1734. #+BEGIN_SRC shell :tangle no
  1735. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1736. beansym="$orgpath/ob-beancount.el
  1737. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1738. if [ -h "$beansym" ]
  1739. then
  1740. echo "$beansym found"
  1741. elif [ -e "$bean" ]
  1742. then
  1743. echo "creating symlink"
  1744. ln -s "$bean" "$beansym"
  1745. else
  1746. echo "$bean not found, symlink creation aborted"
  1747. fi
  1748. #+END_SRC
  1749. Fava is strongly recommended.
  1750. #+BEGIN_SRC shell :tangle no
  1751. cd /opt
  1752. python3 -m venv fava
  1753. source ./fava/bin/activate
  1754. pip3 install wheel
  1755. pip3 install fava
  1756. deactivate
  1757. #+END_SRC
  1758. Start fava with fava my_file.beancount
  1759. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1760. Beancount-mode can start fava and open the URL right away.
  1761. * Stuff after everything else
  1762. Set garbage collector to a smaller value to let it kick in faster.
  1763. Maybe a problem on Windows?
  1764. #+begin_src emacs-lisp
  1765. ;(setq gc-cons-threshold (* 2 1000 1000))
  1766. #+end_src
  1767. Rest of early-init.el
  1768. #+begin_src emacs-lisp :tangle early-init.el
  1769. (defconst config-org (expand-file-name "config.org" user-emacs-directory))
  1770. (defconst init-el (expand-file-name "init.el" user-emacs-directory))
  1771. (unless (file-exists-p init-el)
  1772. (require 'org)
  1773. (org-babel-tangle-file config-org init-el))
  1774. #+end_src