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.

2043 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. ** 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. not sure if actually better
  1399. #+begin_src emacs-lisp
  1400. (use-package org-node
  1401. :ensure t
  1402. :after org
  1403. :config
  1404. (org-node-cache-mode)
  1405. (org-node-backlink-mode))
  1406. #+end_src
  1407. ** org-ql
  1408. [[https://github.com/alphapapa/org-ql][org-ql]]
  1409. Run queries on org files
  1410. #+begin_src emacs-lisp
  1411. (use-package org-ql
  1412. :ensure t
  1413. :custom
  1414. (org-directory MY--PATH_ORG_FILES)
  1415. (org-ql-search-directories-files-recursive t) ;;might hit performance but will search recursively in org-directory
  1416. )
  1417. #+end_src
  1418. ** org-sidebar
  1419. https://github.com/alphapapa/org-sidebar
  1420. #+begin_src emacs-lisp
  1421. (use-package org-sidebar
  1422. :ensure t
  1423. :bind (:map org-sidebar-map
  1424. ("<tab>" . org-agenda-show-and-scroll-up)
  1425. ("TAB" . org-agenda-show-and-scroll-up)))
  1426. #+end_src
  1427. ** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  1428. * Programming
  1429. ** Magit / Git
  1430. Little crash course in magit:
  1431. - magit-init to init a git project
  1432. - magit-status (C-x g) to call the status window
  1433. In status buffer:
  1434. - s stage files
  1435. - u unstage files
  1436. - U unstage all files
  1437. - a apply changes to staging
  1438. - c c commit (type commit message, then C-c C-c to commit)
  1439. - b b switch to another branch
  1440. - P u git push
  1441. - F u git pull
  1442. #+BEGIN_SRC emacs-lisp
  1443. ;; updated version needed for magit, at least on windows
  1444. (use-package transient
  1445. :ensure t)
  1446. (use-package magit
  1447. :ensure t
  1448. ; :pin melpa-stable
  1449. :defer t
  1450. :init
  1451. ; set git-path in work environment
  1452. (if (string-equal user-login-name "POH")
  1453. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1454. )
  1455. :bind (("C-x g" . magit-status)))
  1456. #+END_SRC
  1457. ** COMMENT Eglot (can't do dap-mode, maybe dape?)
  1458. for python pyls (in env: pip install python-language-server) seems to work better than pyright (npm install -g pyright),
  1459. at least pandas couldnt be resolved in pyright
  1460. #+begin_src emacs-lisp
  1461. (use-package eglot
  1462. :ensure t
  1463. :init
  1464. (setq completion-category-overrides '((eglot (styles orderless))))
  1465. :config
  1466. (add-to-list 'eglot-server-programs '(python-mode . ("pyright-langserver" "--stdio")))
  1467. (with-eval-after-load 'eglot
  1468. (load-library "project"))
  1469. :hook
  1470. (python-mode . eglot-ensure)
  1471. :custom
  1472. (eglot-ignored-server-capabilities '(:documentHighlightProvider))
  1473. (eglot-autoshutdown t)
  1474. (eglot-events-buffer-size 0)
  1475. )
  1476. ;; performance stuff if necessary
  1477. ;(fset #'jsonrpc--log-event #'ignore)
  1478. #+end_src
  1479. ** LSP-Mode
  1480. #+begin_src emacs-lisp
  1481. (defun corfu-lsp-setup ()
  1482. (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
  1483. '(orderless)))
  1484. (use-package lsp-mode
  1485. :ensure t
  1486. ; :hook
  1487. ; ((python-mode . lsp))
  1488. :custom
  1489. (lsp-completion-provider :none)
  1490. (lsp-enable-suggest-server-download nil)
  1491. :hook
  1492. (lsp-completion-mode #'corfu-lsp-setup))
  1493. ;(use-package lsp-ui
  1494. ; :ensure t
  1495. ; :commands lsp-ui-mode)
  1496. (use-package lsp-pyright
  1497. :ensure t
  1498. :after (python lsp-mode)
  1499. :custom
  1500. (lsp-pyright-multi-root nil)
  1501. :hook
  1502. (python-mode-hook . (lambda ()
  1503. (require 'lsp-pyright) (lsp))))
  1504. #+end_src
  1505. ** flymake
  1506. python in venv: pip install pyflake (or ruff?)
  1507. TODO: if ruff active, sideline stops working
  1508. #+begin_src emacs-lisp
  1509. (setq python-flymake-command '("ruff" "--quiet" "--stdin-filename=stdin" "-"))
  1510. #+end_src
  1511. ** sideline
  1512. show flymake errors on the right of code window
  1513. #+begin_src emacs-lisp
  1514. (use-package sideline
  1515. :ensure t)
  1516. (use-package sideline-flymake
  1517. :ensure t
  1518. :requires sideline
  1519. :hook
  1520. (flymake-mode . sideline-mode)
  1521. :init
  1522. (setq sideline-flymake-display-mode 'line ; 'point or 'line
  1523. ; sideline-backends-left '(sideline-lsp)
  1524. sideline-backends-right '(sideline-flymake)))
  1525. #+end_src
  1526. ** yasnippet
  1527. For useful snippet either install yasnippet-snippets or get them from here
  1528. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1529. #+begin_src emacs-lisp
  1530. (use-package yasnippet
  1531. :ensure t
  1532. :defer t
  1533. :diminish yas-minor-mode
  1534. :config
  1535. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1536. (yas-global-mode t)
  1537. (yas-reload-all)
  1538. (unbind-key "TAB" yas-minor-mode-map)
  1539. (unbind-key "<tab>" yas-minor-mode-map))
  1540. #+end_src
  1541. ** hippie expand
  1542. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1543. #+begin_src emacs-lisp
  1544. (use-package hippie-exp
  1545. :ensure nil
  1546. :defer t
  1547. :bind
  1548. ("C-<return>" . hippie-expand)
  1549. :config
  1550. (setq hippie-expand-try-functions-list
  1551. '(yas-hippie-try-expand emmet-expand-line)))
  1552. #+end_src
  1553. ** COMMENT flycheck (now flymake)
  1554. #+BEGIN_SRC emacs-lisp
  1555. (use-package flycheck
  1556. :ensure t
  1557. :hook
  1558. ((css-mode . flycheck-mode)
  1559. (emacs-lisp-mode . flycheck-mode)
  1560. (python-mode . flycheck-mode))
  1561. :defer 1.0
  1562. :init
  1563. (setq flycheck-emacs-lisp-load-path 'inherit)
  1564. :config
  1565. (setq-default
  1566. flycheck-check-synta-automatically '(save mode-enabled)
  1567. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1568. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1569. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1570. #+END_SRC
  1571. ** smartparens
  1572. #+BEGIN_SRC emacs-lisp
  1573. (use-package smartparens
  1574. :ensure t
  1575. :diminish smartparens-mode
  1576. :bind
  1577. (:map smartparens-mode-map
  1578. ("C-M-f" . sp-forward-sexp)
  1579. ("C-M-b" . sp-backward-sexp)
  1580. ("C-M-a" . sp-backward-down-sexp)
  1581. ("C-M-e" . sp-up-sexp)
  1582. ("C-M-w" . sp-copy-sexp)
  1583. ("M-k" . sp-kill-sexp)
  1584. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1585. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1586. ("C-]" . sp-select-next-thing-exchange))
  1587. :config
  1588. (setq sp-show-pair-from-inside nil
  1589. sp-escape-quotes-after-insert nil)
  1590. (require 'smartparens-config))
  1591. #+END_SRC
  1592. ** lisp
  1593. #+BEGIN_SRC emacs-lisp
  1594. (use-package elisp-mode
  1595. :ensure nil
  1596. :defer t)
  1597. #+END_SRC
  1598. ** web
  1599. apt install npm
  1600. sudo npm install -g vscode-html-languageserver-bin
  1601. evtl alternativ typescript-language-server?
  1602. Unter Windows:
  1603. Hier runterladen: https://nodejs.org/dist/latest/
  1604. und in ein Verzeichnis entpacken.
  1605. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1606. PATH=P:\path\to\node;%path%
  1607. *** web-mode
  1608. #+BEGIN_SRC emacs-lisp
  1609. (use-package web-mode
  1610. :ensure t
  1611. :defer t
  1612. :mode
  1613. ("\\.phtml\\'"
  1614. "\\.tpl\\.php\\'"
  1615. "\\.djhtml\\'"
  1616. "\\.[t]?html?\\'")
  1617. :hook
  1618. (web-mode . smartparens-mode)
  1619. :init
  1620. (if *work_remote*
  1621. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1622. :config
  1623. (setq web-mode-enable-auto-closing t
  1624. web-mode-enable-auto-pairing t))
  1625. #+END_SRC
  1626. Emmet offers snippets, similar to yasnippet.
  1627. Default completion is C-j
  1628. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1629. #+begin_src emacs-lisp
  1630. (use-package emmet-mode
  1631. :ensure t
  1632. :defer t
  1633. :hook
  1634. ((web-mode . emmet-mode)
  1635. (css-mode . emmet-mode))
  1636. :config
  1637. (unbind-key "C-<return>" emmet-mode-keymap))
  1638. #+end_src
  1639. *** JavaScript
  1640. npm install -g typescript-language-server typescript
  1641. maybe only typescript?
  1642. npm install -g prettier
  1643. #+begin_src emacs-lisp
  1644. (use-package rjsx-mode
  1645. :ensure t
  1646. :mode ("\\.js\\'"
  1647. "\\.jsx'"))
  1648. ; :config
  1649. ; (setq js2-mode-show-parse-errors nil
  1650. ; js2-mode-show-strict-warnings nil
  1651. ; js2-basic-offset 2
  1652. ; js-indent-level 2)
  1653. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1654. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1655. (use-package tide
  1656. :ensure t
  1657. :after (rjsx-mode company flycheck)
  1658. ; :hook (rjsx-mode . setup-tide-mode)
  1659. :config
  1660. (defun setup-tide-mode ()
  1661. "Setup function for tide."
  1662. (interactive)
  1663. (tide-setup)
  1664. (flycheck-mode t)
  1665. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1666. (tide-hl-identifier-mode t)))
  1667. ;; needs npm install -g prettier
  1668. (use-package prettier-js
  1669. :ensure t
  1670. :after (rjsx-mode)
  1671. :defer t
  1672. :diminish prettier-js-mode
  1673. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1674. #+end_src
  1675. ** YAML
  1676. #+begin_src emacs-lisp
  1677. (use-package yaml-mode
  1678. :if *sys/linux*
  1679. :ensure t
  1680. :defer t
  1681. :mode ("\\.yml$" . yaml-mode))
  1682. #+end_src
  1683. ** R
  1684. #+BEGIN_SRC emacs-lisp
  1685. (use-package ess
  1686. :ensure t
  1687. :defer t
  1688. :init
  1689. (if *work_remote*
  1690. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1691. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1692. #+END_SRC
  1693. ** project.el
  1694. #+begin_src emacs-lisp
  1695. (use-package project
  1696. :custom
  1697. (project-vc-extra-root-markers '(".project.el" ".project" )))
  1698. #+end_src
  1699. ** Python
  1700. Preparations:
  1701. - create env:
  1702. m-x shell
  1703. python3 -m venv ./.env
  1704. - Install language server in *each* projects venv
  1705. source ./.env/bin/activate
  1706. pip install pyright
  1707. - in project root:
  1708. touch .project.el
  1709. echo "((nil . (pyvenv-activate . "/path/to/project/.env")))" >> .dir-locals.el
  1710. für andere language servers
  1711. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1712. TODO if in a project, set venv automatically
  1713. (when-let ((project (project-current))) (project-root project))
  1714. returns project path from project.el
  1715. to recognize a project, either have git or
  1716. place a .project.el file in project root and
  1717. (setq project-vc-extra-root-markers '(".project.el" "..." ))
  1718. #+begin_src emacs-lisp
  1719. (use-package python
  1720. :if *sys/linux*
  1721. :delight "π "
  1722. :defer t
  1723. :bind (("M-[" . python-nav-backward-block)
  1724. ("M-]" . python-nav-forward-block))
  1725. :mode
  1726. (("\\.py\\'" . python-mode)))
  1727. (use-package pyvenv
  1728. ; :if *sys/linux*
  1729. :ensure t
  1730. :defer t
  1731. :after python
  1732. :hook
  1733. (python-mode . pyvenv-mode)
  1734. :custom
  1735. (pyvenv-default-virtual-env-name ".env")
  1736. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]"))))
  1737. ;; formatting to pep8
  1738. ;; requires pip install black
  1739. ;(use-package blacken
  1740. ; :ensure t)
  1741. #+end_src
  1742. TODO python mode hook:
  1743. - activate venv
  1744. - activate eglot with proper ls
  1745. - activate tree-sitter?
  1746. - have some fallback if activations fail
  1747. * beancount
  1748. ** Installation
  1749. #+BEGIN_SRC shell :tangle no
  1750. sudo su
  1751. cd /opt
  1752. python3 -m venv beancount
  1753. source ./beancount/bin/activate
  1754. pip3 install wheel
  1755. pip3 install beancount
  1756. sleep 100
  1757. echo "shell running!"
  1758. deactivate
  1759. #+END_SRC
  1760. #+begin_src emacs-lisp
  1761. (use-package beancount
  1762. :ensure nil
  1763. :if *sys/linux*
  1764. :load-path "user-global/elisp/"
  1765. ; :ensure t
  1766. :defer t
  1767. :mode
  1768. ("\\.beancount$" . beancount-mode)
  1769. :hook
  1770. (beancount-mode . my/beancount-company)
  1771. :config
  1772. (defun my/beancount-company ()
  1773. (setq-local completion-at-point-functions #'beancount-completion-at-point))
  1774. (setq beancount-filename-main "/home/marc/archiv/Finanzen/Transaktionen/transactions.beancount"))
  1775. #+end_src
  1776. +BEGIN_SRC emacs-lisp
  1777. (use-package beancount
  1778. :if *sys/linux*
  1779. :load-path "user-global/elisp"
  1780. ; :ensure t
  1781. :defer t
  1782. :mode
  1783. ("\\.beancount$" . beancount-mode)
  1784. ; :hook
  1785. ; (beancount-mode . my/beancount-company)
  1786. ; :init
  1787. ; (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1788. :config
  1789. (defun my/beancount-company ()
  1790. (setq-local completion-at-point-functions #'beancount-complete-at-point nil t))
  1791. ; (mapcar #'cape-company-to-capf
  1792. ; (list #'company-beancount #'company-dabbrev))))
  1793. (defun my--beancount-companyALT ()
  1794. (set (make-local-variable 'company-backends)
  1795. '(company-beancount)))
  1796. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1797. +END_SRC
  1798. To support org-babel, check if it can find the symlink to ob-beancount.el
  1799. #+BEGIN_SRC shell :tangle no
  1800. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1801. beansym="$orgpath/ob-beancount.el
  1802. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1803. if [ -h "$beansym" ]
  1804. then
  1805. echo "$beansym found"
  1806. elif [ -e "$bean" ]
  1807. then
  1808. echo "creating symlink"
  1809. ln -s "$bean" "$beansym"
  1810. else
  1811. echo "$bean not found, symlink creation aborted"
  1812. fi
  1813. #+END_SRC
  1814. Fava is strongly recommended.
  1815. #+BEGIN_SRC shell :tangle no
  1816. cd /opt
  1817. python3 -m venv fava
  1818. source ./fava/bin/activate
  1819. pip3 install wheel
  1820. pip3 install fava
  1821. deactivate
  1822. #+END_SRC
  1823. Start fava with fava my_file.beancount
  1824. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1825. Beancount-mode can start fava and open the URL right away.
  1826. * Stuff after everything else
  1827. Set garbage collector to a smaller value to let it kick in faster.
  1828. Maybe a problem on Windows?
  1829. #+begin_src emacs-lisp
  1830. ;(setq gc-cons-threshold (* 2 1000 1000))
  1831. #+end_src
  1832. Rest of early-init.el
  1833. #+begin_src emacs-lisp :tangle early-init.el
  1834. (defconst config-org (expand-file-name "config.org" user-emacs-directory))
  1835. (defconst init-el (expand-file-name "init.el" user-emacs-directory))
  1836. (unless (file-exists-p init-el)
  1837. (require 'org)
  1838. (org-babel-tangle-file config-org init-el))
  1839. #+end_src