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.

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