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.

1757 lines
52 KiB

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