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.

2012 lines
62 KiB

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