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.

2042 lines
63 KiB

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