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.

1806 lines
54 KiB

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