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.

1999 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
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
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. * Tree-sitter
  822. #+begin_src emacs-lisp
  823. (when *sys/linux*
  824. (use-package tree-sitter
  825. :ensure t
  826. :init
  827. (global-tree-sitter-mode t)
  828. :hook
  829. (tree-sitter-after-on . tree-sitter-hl-mode))
  830. (use-package tree-sitter-langs
  831. :ensure t
  832. :after tree-sitter)
  833. )
  834. #+end_src
  835. * Org-ql
  836. [[https://github.com/alphapapa/org-ql][org-ql]]
  837. Run queries on org files
  838. #+begin_src emacs-lisp
  839. (use-package org-ql
  840. :ensure t
  841. )
  842. #+end_src
  843. * COMMENT Xeft (needs xapian, not really windows compatible)
  844. Fast full text search for stuff org-ql cannot cover
  845. #+begin_src emacs-lisp
  846. (use-package xeft
  847. :ensure t
  848. :custom
  849. (xeft-recursive 'follow-symlinks))
  850. #+end_src
  851. * COMMENT Helm
  852. As an alternative if I'm not happy with selectrum & co
  853. #+begin_src emacs-lisp
  854. (use-package helm
  855. :ensure t
  856. :hook
  857. (helm-mode . helm-autoresize-mode)
  858. ;; :bind
  859. ;; (("M-x" . helm-M-x)
  860. ;; ("C-s" . helm-occur)
  861. ;; ("C-x C-f" . helm-find-files)
  862. ;; ("C-x C-b" . helm-buffers-list)
  863. ;; ("C-x b" . helm-buffers-list)
  864. ;; ("C-x C-r" . helm-recentf)
  865. ;; ("C-x C-i" . helm-imenu))
  866. :config
  867. (helm-mode)
  868. :custom
  869. (helm-split-window-inside-p t) ;; open helm buffer inside current window
  870. (helm-move-to-line-cycle-in-source t)
  871. (helm-echo-input-in-header-line t)
  872. (helm-autoresize-max-height 20)
  873. (helm-autoresize-min-height 5)
  874. )
  875. #+end_src
  876. * COMMENT ivy / counsel / swiper
  877. #+BEGIN_SRC emacs-lisp
  878. ; (require 'ivy)
  879. (use-package ivy
  880. :ensure t
  881. :diminish
  882. (ivy-mode . "")
  883. :defer t
  884. :init
  885. (ivy-mode 1)
  886. :bind
  887. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  888. :config
  889. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  890. ivy-height 20 ;; height of ivy window
  891. ivy-count-format "%d/%d" ;; current and total number
  892. ivy-re-builders-alist ;; regex replaces spaces with *
  893. '((t . ivy--regex-plus))))
  894. ; make counsel-M-x more descriptive
  895. (use-package ivy-rich
  896. :ensure t
  897. :defer t
  898. :init
  899. (ivy-rich-mode 1))
  900. (use-package counsel
  901. :ensure t
  902. :defer t
  903. :bind
  904. (("M-x" . counsel-M-x)
  905. ("C-x C-f" . counsel-find-file)
  906. ("C-x C-r" . counsel-recentf)
  907. ("C-x b" . counsel-switch-buffer)
  908. ("C-c C-f" . counsel-git)
  909. ("C-c h f" . counsel-describe-function)
  910. ("C-c h v" . counsel-describe-variable)
  911. ("M-i" . counsel-imenu)))
  912. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  913. ; ("C-r" . 'counsel-minibuffer-history)))
  914. (use-package swiper
  915. :ensure t
  916. :bind
  917. ("C-s" . swiper))
  918. (use-package ivy-hydra
  919. :ensure t)
  920. #+END_SRC
  921. * outlook
  922. In outlook a macro is necessary, also a reference to FM20.DLL
  923. (Microsoft Forms 2.0 Object Library, in c:\windows\syswow64\fm20.dll)
  924. The macro copies the GUID of the email to the clipboard
  925. Attention: the GUID changes when the email is moved to another folder!
  926. The macro:
  927. #+BEGIN_SRC
  928. Sub AddLinkToMessageInClipboard()
  929. 'Adds a link to the currently selected message to the clipboard
  930. Dim objMail As Outlook.MailItem
  931. Dim doClipboard As New DataObject
  932. 'One and ONLY one message muse be selected
  933. If Application.ActiveExplorer.Selection.Count <> 1 Then
  934. MsgBox ("Select one and ONLY one message.")
  935. Exit Sub
  936. End If
  937. Set objMail = Application.ActiveExplorer.Selection.Item(1)
  938. doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
  939. doClipboard.PutInClipboard
  940. End Sub
  941. #+END_SRC
  942. #+BEGIN_SRC emacs-lisp
  943. ;(org-add-link-type "outlook" 'my--org-outlook-open)
  944. (defun my--org-outlook-open (id)
  945. (w32-shell-execute "open" "outlook" (concat " /select outlook:" id)))
  946. (defun my/org-outlook-open-test ()
  947. (interactive)
  948. (w32-shell-execute "open" "outlook" " /select outlook:000000008A209C397CEF2C4FBA9E54AEB5B1F97F0700846D043B407C5B43A0C05AFC46DC5C630587BE5E020900006E48FF8F6027694BA6593777F542C19E0002A6434D000000"))'
  949. #+END_SRC
  950. * misc
  951. #+begin_src emacs-lisp
  952. (use-package autorevert
  953. :diminish auto-revert-mode)
  954. #+end_src
  955. * COMMENT company (now corfu)
  956. #+BEGIN_SRC emacs-lisp
  957. (use-package company
  958. :defer 1
  959. :diminish
  960. :defer t
  961. :bind
  962. (("C-<tab>" . company-complete)
  963. :map company-active-map
  964. ("RET" . nil)
  965. ([return] . nil)
  966. ("TAB" . company-complete-selection)
  967. ([tab] . company-complete-selection)
  968. ("<right>" . company-complete-common)
  969. ("<escape>" . company-abort))
  970. :hook
  971. (after-init . global-company-mode)
  972. (emacs-lisp-mode . my--company-elisp)
  973. (org-mode . my--company-org)
  974. :config
  975. (defun my--company-elisp ()
  976. (message "set up company for elisp")
  977. (set (make-local-variable 'company-backends)
  978. '(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp
  979. company-yasnippet
  980. company-dabbrev-code
  981. company-files)))
  982. (defun my--company-org ()
  983. (set (make-local-variable 'company-backends)
  984. '(company-capf company-files))
  985. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  986. (message "setup company for org"))
  987. (setq company-idle-delay .2
  988. company-minimum-prefix-length 1
  989. company-require-match nil
  990. company-show-numbers t
  991. company-tooltip-align-annotations t))
  992. (use-package company-statistics
  993. :ensure t
  994. :after company
  995. :defer t
  996. :init
  997. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  998. :config
  999. (company-statistics-mode 1))
  1000. (use-package company-dabbrev
  1001. :ensure nil
  1002. :after company
  1003. :defer t
  1004. :config
  1005. (setq-default company-dabbrev-downcase nil))
  1006. ;; adds a info box right of the cursor with doc of the function
  1007. (use-package company-box
  1008. :ensure t
  1009. :diminish
  1010. :defer t
  1011. :hook
  1012. (company-mode . company-box-mode))
  1013. ; :init
  1014. ; (add-hook 'company-mode-hook 'company-box-mode))
  1015. #+END_SRC
  1016. * orgmode
  1017. ** some notes
  1018. *** copy file path within emacs
  1019. Enter dired-other-window
  1020. place cursor on the file
  1021. M-0 w (copy absolute path)
  1022. C-u w (copy relative path)
  1023. *** Archiving
  1024. C-c C-x C-a
  1025. To keep the subheading structure when archiving, set the properties of the superheading.
  1026. #+begin_src org :tangle no
  1027. ,* FOO
  1028. :PROPERTIES:
  1029. :ARCHIVE: %s_archive::* FOO
  1030. ,** DONE BAR
  1031. ,** TODO BAZ
  1032. #+end_src
  1033. When moving BAR to archive, it will go to FILENAME.org_archive below the heading FOO.
  1034. [[http://doc.endlessparentheses.com/Var/org-archive-location.html][Other examples]]
  1035. ** org
  1036. This seems necessary to prevent 'org is already installed' error
  1037. https://github.com/jwiegley/use-package/issues/319
  1038. #+begin_src emacs-lisp
  1039. ;(assq-delete-all 'org package--builtins)'
  1040. ;(assq-delete-all 'org package--builtin-versions)
  1041. #+end_src
  1042. #+BEGIN_SRC emacs-lisp
  1043. (defun my--buffer-prop-set (name value)
  1044. "Set a file property called NAME to VALUE in buffer file.
  1045. If the property is already set, replace its value."
  1046. (setq name (downcase name))
  1047. (org-with-point-at 1
  1048. (let ((case-fold-search t))
  1049. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  1050. (point-max) t)
  1051. (replace-match (concat "#+" name ": " value) 'fixedcase)
  1052. (while (and (not (eobp))
  1053. (looking-at "^[#:]"))
  1054. (if (save-excursion (end-of-line) (eobp))
  1055. (progn
  1056. (end-of-line)
  1057. (insert "\n"))
  1058. (forward-line)
  1059. (beginning-of-line)))
  1060. (insert "#+" name ": " value "\n")))))
  1061. (defun my--buffer-prop-remove (name)
  1062. "Remove a buffer property called NAME."
  1063. (org-with-point-at 1
  1064. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  1065. (point-max) t)
  1066. (replace-match ""))))
  1067. (use-package org
  1068. :ensure t
  1069. :pin gnu
  1070. :mode (("\.org$" . org-mode))
  1071. :diminish org-indent-mode
  1072. :defer 1
  1073. :hook
  1074. (org-mode . org-indent-mode)
  1075. (org-source-mode . smartparens-mode)
  1076. :bind (("C-c l" . org-store-link)
  1077. ("C-c c" . org-capture)
  1078. ("C-c a" . org-agenda)
  1079. :map org-mode-map ("S-<right>" . org-shiftright)
  1080. ("S-<left>" . org-shiftleft))
  1081. :init
  1082. (defun my--org-agenda-files-set ()
  1083. "Sets default agenda files.
  1084. Necessary when updating roam agenda todos."
  1085. (setq org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  1086. (concat MY--PATH_ORG_FILES "projects.org")
  1087. (concat MY--PATH_ORG_FILES "tasks.org")))
  1088. (when *sys/linux*
  1089. (nconc org-agenda-files
  1090. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$"))))
  1091. (my--org-agenda-files-set)
  1092. (defun my--org-skip-subtree-if-priority (priority)
  1093. "Skip an agenda subtree if it has a priority of PRIORITY.
  1094. PRIORITY may be one of the characters ?A, ?B, or ?C."
  1095. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  1096. (pri-value (* 1000 (- org-lowest-priority priority)))
  1097. (pri-current (org-get-priority (thing-at-point 'line t))))
  1098. (if (= pri-value pri-current)
  1099. subtree-end
  1100. nil)))
  1101. :config
  1102. (when *work_remote*
  1103. (org-add-link-type "outlook" 'my--org-outlook-open)
  1104. (setq org-todo-keywords
  1105. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED")))
  1106. (setq org-capture-templates
  1107. '(("t" "telephone call" entry
  1108. ; (file+olp+datetree (concat MY--PATH_ORG_FILES "phone_calls.org"))
  1109. (file+datetree "p:/Eigene Dateien/Notizen/phone_calls.org")
  1110. "* [%<%Y-%m-%d %H:%M>] %?"
  1111. :empty-lines 0 :jump-to-captured t))))
  1112. (when *sys/linux*
  1113. (setq org-pretty-entities t))
  1114. :custom
  1115. (org-startup-truncated t)
  1116. (org-startup-align-all-tables t)
  1117. (org-src-fontify-natively t) ;; use syntax highlighting in code blocks
  1118. (org-src-preserve-indentation t) ;; no extra indentation
  1119. (org-src-window-setup 'current-window) ;; C-c ' opens in current window
  1120. (org-modules (quote (org-id
  1121. org-habit
  1122. org-tempo))) ;; easy templates
  1123. (org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org"))
  1124. (org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations"))
  1125. (org-log-into-drawer "LOGBOOK")
  1126. (org-log-done 'time) ;; create timestamp when task is done
  1127. (org-blank-before-new-entry '((heading) (plain-list-item))) ;; prevent new line before new item
  1128. (org-src-tab-acts-natively t)
  1129. ;;Sort agenda by deadline and priority
  1130. (org-agenda-sorting-strategy
  1131. (quote
  1132. ((agenda deadline-up priority-down)
  1133. (todo priority-down category-keep)
  1134. (tags priority-down category-keep)
  1135. (search category-keep))))
  1136. (org-agenda-custom-commands
  1137. '(("c" "Simple agenda view"
  1138. ((tags "PRIORITY=\"A\""
  1139. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1140. (org-agenda-overriding-header "Hohe Priorität:")))
  1141. (agenda ""
  1142. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1143. (org-agenda-span 7)
  1144. (org-agenda-start-on-weekday nil)
  1145. (org-agenda-overriding-header "Nächste 7 Tage:")))
  1146. (alltodo ""
  1147. ((org-agenda-skip-function '(or (my--org-skip-subtree-if-priority ?A)
  1148. (org-agenda-skip-if nil '(scheduled deadline))))
  1149. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))))
  1150. #+END_SRC
  1151. ** COMMENT languages
  1152. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  1153. Elpaca cant find it, though it's built in org
  1154. #+begin_src emacs-lisp
  1155. (use-package ob-python
  1156. ; :elpaca nil
  1157. :defer t
  1158. :after org
  1159. ; :ensure org-contrib
  1160. :commands
  1161. (org-babel-execute:python))
  1162. #+end_src
  1163. ** COMMENT habits
  1164. #+BEGIN_SRC emacs-lisp
  1165. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  1166. ;; (add-to-list 'org-modules "org-habit")
  1167. (setq org-habit-graph-column 80
  1168. org-habit-preceding-days 30
  1169. org-habit-following-days 7
  1170. org-habit-show-habits-only-for-today nil)
  1171. #+END_SRC
  1172. ** *TODO*
  1173. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  1174. ** COMMENT journal
  1175. [[https://github.com/bastibe/org-journal][Source]]
  1176. Ggf. durch org-roam-journal ersetzen
  1177. #+BEGIN_SRC emacs-lisp
  1178. (use-package org-journal
  1179. :if *sys/linux*
  1180. :ensure t
  1181. :defer t
  1182. :config
  1183. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  1184. (when (and (boundp 'org-journal-dir)
  1185. (boundp 'org-journal-enable-agenda-integration))
  1186. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  1187. org-journal-enable-agenda-integration t)))
  1188. #+END_SRC
  1189. ** org-roam
  1190. [[https://github.com/org-roam/org-roam][Github]]
  1191. Um Headings innerhalb einer Datei zu verlinken:
  1192. - org-id-get-create im Heading,
  1193. - org-roam-node-insert in der verweisenden Datei
  1194. Bei Problemen wie unique constraint
  1195. org-roam-db-clear-all
  1196. org-roam-db-sync
  1197. #+BEGIN_SRC emacs-lisp
  1198. (use-package emacsql-sqlite-builtin
  1199. :ensure t)
  1200. (use-package org-roam
  1201. :requires emacsql-sqlite-builtin
  1202. :ensure t
  1203. :defer 2
  1204. :after org
  1205. :init
  1206. (setq org-roam-v2-ack t)
  1207. (defun my--roamtodo-p ()
  1208. "Return non-nil if current buffer has any todo entry.
  1209. TODO entries marked as done are ignored, meaning this function
  1210. returns nil if current buffer contains only completed tasks."
  1211. (seq-find
  1212. (lambda (type)
  1213. (eq type 'todo))
  1214. (org-element-map
  1215. (org-element-parse-buffer 'headline)
  1216. 'headline
  1217. (lambda (h)
  1218. (org-element-property :todo-type h)))))
  1219. (defun my--roamtodo-update-tag ()
  1220. "Update ROAMTODO tag in the current buffer."
  1221. (when (and (not (active-minibuffer-window))
  1222. (my--buffer-roam-note-p))
  1223. (save-excursion
  1224. (goto-char (point-min))
  1225. (let* ((tags (my--buffer-tags-get))
  1226. (original-tags tags))
  1227. (if (my--roamtodo-p)
  1228. (setq tags (cons "roamtodo" tags))
  1229. (setq tags (remove "roamtodo" tags)))
  1230. ;;cleanup duplicates
  1231. (when (or (seq-difference tags original-tags)
  1232. (seq-difference original-tags tags))
  1233. (apply #'my--buffer-tags-set tags))))))
  1234. (defun my--buffer-tags-get ()
  1235. "Return filetags value in current buffer."
  1236. (my--buffer-prop-get-list "filetags" "[ :]"))
  1237. (defun my--buffer-tags-set (&rest tags)
  1238. "Set TAGS in current buffer.
  1239. If filetags value is already set, replace it."
  1240. (if tags
  1241. (my--buffer-prop-set
  1242. "filetags" (concat ":" (string-join tags ":") ":"))
  1243. (my--buffer-prop-remove "filetags")))
  1244. (defun my--buffer-tags-add (tag)
  1245. "Add a TAG to filetags in current buffer."
  1246. (let* ((tags (my--buffer-tags-get))
  1247. (tags (append tags (list tag))))
  1248. (apply #'my--buffer-tags-set tags)))
  1249. (defun my--buffer-tags-remove (tag)
  1250. "Remove a TAG from filetags in current buffer."
  1251. (let* ((tags (my--buffer-tags-get))
  1252. (tags (delete tag tags)))
  1253. (apply #'my--buffer-tags-set tags)))
  1254. (defun my--buffer-prop-set (name value)
  1255. "Set a file property called NAME to VALUE in buffer file.
  1256. If the property is already set, replace its value."
  1257. (setq name (downcase name))
  1258. (org-with-point-at 1
  1259. (let ((case-fold-search t))
  1260. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  1261. (point-max) t)
  1262. (replace-match (concat "#+" name ": " value) 'fixedcase)
  1263. (while (and (not (eobp))
  1264. (looking-at "^[#:]"))
  1265. (if (save-excursion (end-of-line) (eobp))
  1266. (progn
  1267. (end-of-line)
  1268. (insert "\n"))
  1269. (forward-line)
  1270. (beginning-of-line)))
  1271. (insert "#+" name ": " value "\n")))))
  1272. (defun my--buffer-prop-set-list (name values &optional separators)
  1273. "Set a file property called NAME to VALUES in current buffer.
  1274. VALUES are quoted and combined into single string using
  1275. `combine-and-quote-strings'.
  1276. If SEPARATORS is non-nil, it should be a regular expression
  1277. matching text that separates, but is not part of, the substrings.
  1278. If nil it defaults to `split-string-and-unquote', normally
  1279. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t.
  1280. If the property is already set, replace its value."
  1281. (my--buffer-prop-set
  1282. name (combine-and-quote-strings values separators)))
  1283. (defun my--buffer-prop-get (name)
  1284. "Get a buffer property called NAME as a string."
  1285. (org-with-point-at 1
  1286. (when (re-search-forward (concat "^#\\+" name ": \\(.*\\)")
  1287. (point-max) t)
  1288. (buffer-substring-no-properties
  1289. (match-beginning 1)
  1290. (match-end 1)))))
  1291. (defun my--buffer-prop-get-list (name &optional separators)
  1292. "Get a buffer property NAME as a list using SEPARATORS.
  1293. If SEPARATORS is non-nil, it should be a regular expression
  1294. matching text that separates, but is not part of, the substrings.
  1295. If nil it defaults to `split-string-default-separators', normally
  1296. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t."
  1297. (let ((value (my--buffer-prop-get name)))
  1298. (when (and value (not (string-empty-p value)))
  1299. (split-string-and-unquote value separators))))
  1300. (defun my--buffer-prop-remove (name)
  1301. "Remove a buffer property called NAME."
  1302. (org-with-point-at 1
  1303. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  1304. (point-max) t)
  1305. (replace-match ""))))
  1306. (defun my--buffer-roam-note-p ()
  1307. "Return non-nil if the currently visited buffer is a note."
  1308. (and buffer-file-name
  1309. (string-prefix-p
  1310. (expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM))
  1311. (file-name-directory buffer-file-name))))
  1312. (defun my--org-roam-filter-by-tag (tag-name)
  1313. (lambda (node)
  1314. (member tag-name (org-roam-node-tags node))))
  1315. (defun my--org-roam-list-notes-by-tag (tag-name)
  1316. (mapcar #'org-roam-node-file
  1317. (seq-filter
  1318. (my--org-roam-filter-by-tag tag-name)
  1319. (org-roam-node-list))))
  1320. (defun my/org-roam-refresh-agenda-list ()
  1321. "Add all org roam files with #+filetags: roamtodo"
  1322. (interactive)
  1323. (my--org-agenda-files-set)
  1324. (nconc org-agenda-files
  1325. (my--org-roam-list-notes-by-tag "roamtodo"))
  1326. (setq org-agenda-files (delete-dups org-agenda-files)))
  1327. (add-hook 'find-file-hook #'my--roamtodo-update-tag)
  1328. (add-hook 'before-save-hook #'my--roamtodo-update-tag)
  1329. (advice-add 'org-agenda :before #'my/org-roam-refresh-agenda-list)
  1330. (advice-add 'org-todo-list :before #'my/org-roam-refresh-agenda-list)
  1331. (add-to-list 'org-tags-exclude-from-inheritance "roamtodo")
  1332. :config
  1333. (require 'org-roam-dailies) ;; ensure the keymap is available
  1334. (org-roam-db-autosync-mode)
  1335. ;; build the agenda list the first ime for the session
  1336. (my/org-roam-refresh-agenda-list)
  1337. (when *work_remote*
  1338. (setq org-roam-capture-templates
  1339. '(("n" "note" plain
  1340. "%?"
  1341. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1342. :unnarrowed t)
  1343. ("i" "idea" plain
  1344. "%?"
  1345. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1346. :unnarrowed t)
  1347. ("p" "project" plain
  1348. "%?"
  1349. :target (file+head "projects/${slug}.org" "#+title: ${title}\n#+filetags: :project:\n")
  1350. :unnarrowed t)
  1351. ("s" "Sicherheitenmeldung" plain
  1352. "*** TODO [#A] Sicherheitenmeldung ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1353. :target (file+olp "tasks.org" ("Todos" "Sicherheitenmeldungen")))
  1354. ("m" "Monatsbericht" plain
  1355. "*** TODO [#A] Monatsbericht ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1356. :target (file+olp "tasks.org" ("Todos" "Monatsberichte"))))))
  1357. :custom
  1358. (org-roam-database-connector 'sqlite-builtin)
  1359. (org-roam-directory MY--PATH_ORG_ROAM)
  1360. (org-roam-completion-everywhere t)
  1361. (org-roam-capture-templates
  1362. '(("n" "note" plain
  1363. "%?"
  1364. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1365. :unnarrowed t)
  1366. ("i" "idea" plain
  1367. "%?"
  1368. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1369. :unnarrowed t)
  1370. ))
  1371. :bind (("C-c n l" . org-roam-buffer-toggle)
  1372. ("C-c n f" . org-roam-node-find)
  1373. ("C-c n i" . org-roam-node-insert)
  1374. :map org-mode-map
  1375. ("C-M-i" . completion-at-point)
  1376. :map org-roam-dailies-map
  1377. ("Y" . org-roam-dailies-capture-yesterday)
  1378. ("T" . org-roam-dailies-capture-tomorrow))
  1379. :bind-keymap
  1380. ("C-c n d" . org-roam-dailies-map))
  1381. #+END_SRC
  1382. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  1383. * Programming
  1384. ** Magit / Git
  1385. Little crash course in magit:
  1386. - magit-init to init a git project
  1387. - magit-status (C-x g) to call the status window
  1388. In status buffer:
  1389. - s stage files
  1390. - u unstage files
  1391. - U unstage all files
  1392. - a apply changes to staging
  1393. - c c commit (type commit message, then C-c C-c to commit)
  1394. - b b switch to another branch
  1395. - P u git push
  1396. - F u git pull
  1397. #+BEGIN_SRC emacs-lisp
  1398. (use-package magit
  1399. :ensure t
  1400. ; :pin melpa-stable
  1401. :defer t
  1402. :init
  1403. ; set git-path in work environment
  1404. (if (string-equal user-login-name "POH")
  1405. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1406. )
  1407. :bind (("C-x g" . magit-status)))
  1408. #+END_SRC
  1409. ** COMMENT Eglot (can't do dap-mode, maybe dape?)
  1410. for python pyls (in env: pip install python-language-server) seems to work better than pyright (npm install -g pyright),
  1411. at least pandas couldnt be resolved in pyright
  1412. #+begin_src emacs-lisp
  1413. (use-package eglot
  1414. :ensure t
  1415. :init
  1416. (setq completion-category-overrides '((eglot (styles orderless))))
  1417. :config
  1418. (add-to-list 'eglot-server-programs '(python-mode . ("pyright-langserver" "--stdio")))
  1419. (with-eval-after-load 'eglot
  1420. (load-library "project"))
  1421. :hook
  1422. (python-mode . eglot-ensure)
  1423. :custom
  1424. (eglot-ignored-server-capabilities '(:documentHighlightProvider))
  1425. (eglot-autoshutdown t)
  1426. (eglot-events-buffer-size 0)
  1427. )
  1428. ;; performance stuff if necessary
  1429. ;(fset #'jsonrpc--log-event #'ignore)
  1430. #+end_src
  1431. ** LSP-Mode
  1432. #+begin_src emacs-lisp
  1433. (defun corfu-lsp-setup ()
  1434. (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
  1435. '(orderless)))
  1436. (use-package lsp-mode
  1437. :ensure t
  1438. ; :hook
  1439. ; ((python-mode . lsp))
  1440. :custom
  1441. (lsp-completion-provider :none)
  1442. (lsp-enable-suggest-server-download nil)
  1443. :hook
  1444. (lsp-completion-mode #'corfu-lsp-setup))
  1445. ;(use-package lsp-ui
  1446. ; :ensure t
  1447. ; :commands lsp-ui-mode)
  1448. (use-package lsp-pyright
  1449. :ensure t
  1450. :after (python lsp-mode)
  1451. :custom
  1452. (lsp-pyright-multi-root nil)
  1453. :hook
  1454. (python-mode-hook . (lambda ()
  1455. (require 'lsp-pyright) (lsp))))
  1456. #+end_src
  1457. ** flymake
  1458. python in venv: pip install pyflake (or ruff?)
  1459. TODO: if ruff active, sideline stops working
  1460. #+begin_src emacs-lisp
  1461. (setq python-flymake-command '("ruff" "--quiet" "--stdin-filename=stdin" "-"))
  1462. #+end_src
  1463. ** sideline
  1464. show flymake errors on the right of code window
  1465. #+begin_src emacs-lisp
  1466. (use-package sideline
  1467. :ensure t)
  1468. (use-package sideline-flymake
  1469. :ensure t
  1470. :requires sideline
  1471. :hook
  1472. (flymake-mode . sideline-mode)
  1473. :init
  1474. (setq sideline-flymake-display-mode 'line ; 'point or 'line
  1475. ; sideline-backends-left '(sideline-lsp)
  1476. sideline-backends-right '(sideline-flymake)))
  1477. #+end_src
  1478. ** yasnippet
  1479. For useful snippet either install yasnippet-snippets or get them from here
  1480. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1481. #+begin_src emacs-lisp
  1482. (use-package yasnippet
  1483. :ensure t
  1484. :defer t
  1485. :diminish yas-minor-mode
  1486. :config
  1487. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1488. (yas-global-mode t)
  1489. (yas-reload-all)
  1490. (unbind-key "TAB" yas-minor-mode-map)
  1491. (unbind-key "<tab>" yas-minor-mode-map))
  1492. #+end_src
  1493. ** hippie expand
  1494. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1495. #+begin_src emacs-lisp
  1496. (use-package hippie-exp
  1497. :elpaca nil
  1498. :defer t
  1499. :bind
  1500. ("C-<return>" . hippie-expand)
  1501. :config
  1502. (setq hippie-expand-try-functions-list
  1503. '(yas-hippie-try-expand emmet-expand-line)))
  1504. #+end_src
  1505. ** COMMENT flycheck (now flymake)
  1506. #+BEGIN_SRC emacs-lisp
  1507. (use-package flycheck
  1508. :ensure t
  1509. :hook
  1510. ((css-mode . flycheck-mode)
  1511. (emacs-lisp-mode . flycheck-mode)
  1512. (python-mode . flycheck-mode))
  1513. :defer 1.0
  1514. :init
  1515. (setq flycheck-emacs-lisp-load-path 'inherit)
  1516. :config
  1517. (setq-default
  1518. flycheck-check-synta-automatically '(save mode-enabled)
  1519. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1520. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1521. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1522. #+END_SRC
  1523. ** smartparens
  1524. #+BEGIN_SRC emacs-lisp
  1525. (use-package smartparens
  1526. :ensure t
  1527. :diminish smartparens-mode
  1528. :bind
  1529. (:map smartparens-mode-map
  1530. ("C-M-f" . sp-forward-sexp)
  1531. ("C-M-b" . sp-backward-sexp)
  1532. ("C-M-a" . sp-backward-down-sexp)
  1533. ("C-M-e" . sp-up-sexp)
  1534. ("C-M-w" . sp-copy-sexp)
  1535. ("M-k" . sp-kill-sexp)
  1536. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1537. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1538. ("C-]" . sp-select-next-thing-exchange))
  1539. :config
  1540. (setq sp-show-pair-from-inside nil
  1541. sp-escape-quotes-after-insert nil)
  1542. (require 'smartparens-config))
  1543. #+END_SRC
  1544. ** lisp
  1545. #+BEGIN_SRC emacs-lisp
  1546. (use-package elisp-mode
  1547. :elpaca nil
  1548. :defer t)
  1549. #+END_SRC
  1550. ** web
  1551. apt install npm
  1552. sudo npm install -g vscode-html-languageserver-bin
  1553. evtl alternativ typescript-language-server?
  1554. Unter Windows:
  1555. Hier runterladen: https://nodejs.org/dist/latest/
  1556. und in ein Verzeichnis entpacken.
  1557. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1558. PATH=P:\path\to\node;%path%
  1559. *** web-mode
  1560. #+BEGIN_SRC emacs-lisp
  1561. (use-package web-mode
  1562. :ensure t
  1563. :defer t
  1564. :mode
  1565. ("\\.phtml\\'"
  1566. "\\.tpl\\.php\\'"
  1567. "\\.djhtml\\'"
  1568. "\\.[t]?html?\\'")
  1569. :hook
  1570. (web-mode . smartparens-mode)
  1571. :init
  1572. (if *work_remote*
  1573. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1574. :config
  1575. (setq web-mode-enable-auto-closing t
  1576. web-mode-enable-auto-pairing t))
  1577. #+END_SRC
  1578. Emmet offers snippets, similar to yasnippet.
  1579. Default completion is C-j
  1580. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1581. #+begin_src emacs-lisp
  1582. (use-package emmet-mode
  1583. :ensure t
  1584. :defer t
  1585. :hook
  1586. ((web-mode . emmet-mode)
  1587. (css-mode . emmet-mode))
  1588. :config
  1589. (unbind-key "C-<return>" emmet-mode-keymap))
  1590. #+end_src
  1591. *** JavaScript
  1592. npm install -g typescript-language-server typescript
  1593. maybe only typescript?
  1594. npm install -g prettier
  1595. #+begin_src emacs-lisp
  1596. (use-package rjsx-mode
  1597. :ensure t
  1598. :mode ("\\.js\\'"
  1599. "\\.jsx'"))
  1600. ; :config
  1601. ; (setq js2-mode-show-parse-errors nil
  1602. ; js2-mode-show-strict-warnings nil
  1603. ; js2-basic-offset 2
  1604. ; js-indent-level 2)
  1605. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1606. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1607. (use-package tide
  1608. :ensure t
  1609. :after (rjsx-mode company flycheck)
  1610. ; :hook (rjsx-mode . setup-tide-mode)
  1611. :config
  1612. (defun setup-tide-mode ()
  1613. "Setup function for tide."
  1614. (interactive)
  1615. (tide-setup)
  1616. (flycheck-mode t)
  1617. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1618. (tide-hl-identifier-mode t)))
  1619. ;; needs npm install -g prettier
  1620. (use-package prettier-js
  1621. :ensure t
  1622. :after (rjsx-mode)
  1623. :defer t
  1624. :diminish prettier-js-mode
  1625. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1626. #+end_src
  1627. ** YAML
  1628. #+begin_src emacs-lisp
  1629. (use-package yaml-mode
  1630. :if *sys/linux*
  1631. :ensure t
  1632. :defer t
  1633. :mode ("\\.yml$" . yaml-mode))
  1634. #+end_src
  1635. ** R
  1636. #+BEGIN_SRC emacs-lisp
  1637. (use-package ess
  1638. :ensure t
  1639. :defer t
  1640. :init
  1641. (if *work_remote*
  1642. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1643. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1644. #+END_SRC
  1645. ** project.el
  1646. #+begin_src emacs-lisp
  1647. (use-package project
  1648. :custom
  1649. (project-vc-extra-root-markers '(".project.el" ".project" )))
  1650. #+end_src
  1651. ** Python
  1652. Preparations:
  1653. - Install language server in *each* projects venv
  1654. source ./bin/activate
  1655. pip install pyright
  1656. - in project root:
  1657. touch .project.el
  1658. echo "((nil . (pyvenv-activate . "/path/to/project/.env")))" >> .dir-locals.el
  1659. für andere language servers
  1660. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1661. TODO if in a project, set venv automatically
  1662. (when-let ((project (project-current))) (project-root project))
  1663. returns project path from project.el
  1664. to recognize a project, either have git or
  1665. place a .project.el file in project root and
  1666. (setq project-vc-extra-root-markers '(".project.el" "..." ))
  1667. #+begin_src emacs-lisp
  1668. (use-package python
  1669. :if *sys/linux*
  1670. :delight "π "
  1671. :defer t
  1672. :bind (("M-[" . python-nav-backward-block)
  1673. ("M-]" . python-nav-forward-block))
  1674. :mode
  1675. (("\\.py\\'" . python-mode)))
  1676. (use-package pyvenv
  1677. ; :if *sys/linux*
  1678. :ensure t
  1679. :defer t
  1680. :after python
  1681. :hook
  1682. (python-mode . pyvenv-mode)
  1683. :custom
  1684. (pyvenv-default-virtual-env-name ".env")
  1685. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]"))))
  1686. ;; formatting to pep8
  1687. ;; requires pip install black
  1688. ;(use-package blacken
  1689. ; :ensure t)
  1690. #+end_src
  1691. TODO python mode hook:
  1692. - activate venv
  1693. - activate eglot with proper ls
  1694. - activate tree-sitter?
  1695. - have some fallback if activations fail
  1696. * beancount
  1697. ** Installation
  1698. #+BEGIN_SRC shell :tangle no
  1699. sudo su
  1700. cd /opt
  1701. python3 -m venv beancount
  1702. source ./beancount/bin/activate
  1703. pip3 install wheel
  1704. pip3 install beancount
  1705. sleep 100
  1706. echo "shell running!"
  1707. deactivate
  1708. #+END_SRC
  1709. #+begin_src emacs-lisp
  1710. (use-package beancount
  1711. :elpaca nil
  1712. :if *sys/linux*
  1713. :load-path "user-global/elisp/"
  1714. ; :ensure t
  1715. :defer t
  1716. :mode
  1717. ("\\.beancount$" . beancount-mode)
  1718. :hook
  1719. (beancount-mode . my/beancount-company)
  1720. :config
  1721. (defun my/beancount-company ()
  1722. (setq-local completion-at-point-functions #'beancount-completion-at-point))
  1723. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1724. #+end_src
  1725. +BEGIN_SRC emacs-lisp
  1726. (use-package beancount
  1727. :if *sys/linux*
  1728. :load-path "user-global/elisp"
  1729. ; :ensure t
  1730. :defer t
  1731. :mode
  1732. ("\\.beancount$" . beancount-mode)
  1733. ; :hook
  1734. ; (beancount-mode . my/beancount-company)
  1735. ; :init
  1736. ; (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1737. :config
  1738. (defun my/beancount-company ()
  1739. (setq-local completion-at-point-functions #'beancount-complete-at-point nil t))
  1740. ; (mapcar #'cape-company-to-capf
  1741. ; (list #'company-beancount #'company-dabbrev))))
  1742. (defun my--beancount-companyALT ()
  1743. (set (make-local-variable 'company-backends)
  1744. '(company-beancount)))
  1745. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1746. +END_SRC
  1747. To support org-babel, check if it can find the symlink to ob-beancount.el
  1748. #+BEGIN_SRC shell :tangle no
  1749. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1750. beansym="$orgpath/ob-beancount.el
  1751. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1752. if [ -h "$beansym" ]
  1753. then
  1754. echo "$beansym found"
  1755. elif [ -e "$bean" ]
  1756. then
  1757. echo "creating symlink"
  1758. ln -s "$bean" "$beansym"
  1759. else
  1760. echo "$bean not found, symlink creation aborted"
  1761. fi
  1762. #+END_SRC
  1763. Fava is strongly recommended.
  1764. #+BEGIN_SRC shell :tangle no
  1765. cd /opt
  1766. python3 -m venv fava
  1767. source ./fava/bin/activate
  1768. pip3 install wheel
  1769. pip3 install fava
  1770. deactivate
  1771. #+END_SRC
  1772. Start fava with fava my_file.beancount
  1773. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1774. Beancount-mode can start fava and open the URL right away.
  1775. * Stuff after everything else
  1776. Set garbage collector to a smaller value to let it kick in faster.
  1777. Maybe a problem on Windows?
  1778. #+begin_src emacs-lisp
  1779. ;(setq gc-cons-threshold (* 2 1000 1000))
  1780. #+end_src
  1781. Rest of early-init.el
  1782. #+begin_src emacs-lisp :tangle early-init.el
  1783. (defconst config-org (expand-file-name "config.org" user-emacs-directory))
  1784. (defconst init-el (expand-file-name "init.el" user-emacs-directory))
  1785. (unless (file-exists-p init-el)
  1786. (require 'org)
  1787. (org-babel-tangle-file config-org init-el))
  1788. #+end_src