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.

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