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.

2015 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
2 years 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. * Org-ql
  827. [[https://github.com/alphapapa/org-ql][org-ql]]
  828. Run queries on org files
  829. #+begin_src emacs-lisp
  830. (use-package org-ql
  831. :ensure t
  832. )
  833. #+end_src
  834. * COMMENT Xeft (needs xapian, not really windows compatible)
  835. Fast full text search for stuff org-ql cannot cover
  836. #+begin_src emacs-lisp
  837. (use-package xeft
  838. :ensure t
  839. :custom
  840. (xeft-recursive 'follow-symlinks))
  841. #+end_src
  842. * COMMENT Helm
  843. As an alternative if I'm not happy with selectrum & co
  844. #+begin_src emacs-lisp
  845. (use-package helm
  846. :ensure t
  847. :hook
  848. (helm-mode . helm-autoresize-mode)
  849. ;; :bind
  850. ;; (("M-x" . helm-M-x)
  851. ;; ("C-s" . helm-occur)
  852. ;; ("C-x C-f" . helm-find-files)
  853. ;; ("C-x C-b" . helm-buffers-list)
  854. ;; ("C-x b" . helm-buffers-list)
  855. ;; ("C-x C-r" . helm-recentf)
  856. ;; ("C-x C-i" . helm-imenu))
  857. :config
  858. (helm-mode)
  859. :custom
  860. (helm-split-window-inside-p t) ;; open helm buffer inside current window
  861. (helm-move-to-line-cycle-in-source t)
  862. (helm-echo-input-in-header-line t)
  863. (helm-autoresize-max-height 20)
  864. (helm-autoresize-min-height 5)
  865. )
  866. #+end_src
  867. * Emails
  868. Requires on system
  869. - isync to sync emails between host and local
  870. - mu / mu4e4e (apt nstall mu4e/bookworm-backports)
  871. After installing mu4e it needs to be initialized
  872. #+begin_src shell :tangle no
  873. mu init --maildir=/path/to/mail/folder --my-address=mu@adress.com --my-address=another@adress.com...
  874. mu index
  875. #+end_src
  876. for credentials see
  877. https://www.emacswiki.org/emacs/SmtpAuth
  878. #+begin_src emacs-lisp
  879. ;(use-package notmuch
  880. ; :ensure t)
  881. (use-feature mu4e
  882. :if *sys/linux*
  883. ; :ensure nil
  884. :after (org)
  885. :init
  886. (require 'mu4e)
  887. :custom
  888. ;; this is set to 't' to avoid mail syncing issues when using mbsync
  889. (mu4e-change-filenames-when-moving t)
  890. (smtpmail-servers-requiring-authorization ".*")
  891. (mu4e-update-interval (* 10 60))
  892. (mu4e-get-mail-command "mbsync -a")
  893. (mu4e-maildir "~/archiv/Dokumente/email")
  894. (mu4e-attachment-dir "/mnt/backup/downloads")
  895. (mu4e-org-support t)
  896. (mu4e-completion-read-function 'completion-read)
  897. (mu4e-use-fancy-chars t)
  898. (mu4e-view-show-addresses t)
  899. (mu4e-view-show-images t)
  900. (mu4e-sent-messages-behaviour 'sent) ;works better with mbsync
  901. (mu4e-headers-fields
  902. '((:human-date . 12)
  903. (:flags . 6)
  904. (:from . 22)
  905. (:to . 25)
  906. (:subject)))
  907. :config
  908. (setq mu4e-contexts
  909. `( ,(make-mu4e-context
  910. :name "mail.de"
  911. :enter-func (lambda () (mu4e-message "switch to mail.de context"))
  912. :match-func (lambda (msg)
  913. (when msg
  914. (string-match-p "^/mailde" (mu4e-message-field msg :maildir))))
  915. :vars '((user-mail-address . "marc.pohling@mail.de")
  916. (user-full-name . "Marc Pohling")
  917. (message-send-mail-function . smtpmail-send-it)
  918. (smtpmail-smtp-user . "marc.pohling@mail.de")
  919. (smtpmail-smtp-server . "smtp.mail.de")
  920. (smtpmail-smtp-service . 587)
  921. (smtpmail-stream-type . starttls)
  922. (mu4e-drafts-folder . "/mailde/drafts")
  923. (mu4e-sent-folder . "/mailde/sent")
  924. (mu4e-refile-folder . "/mailde/archive")
  925. (mu4e-trash-folder . "/mailde/trash")))
  926. ,(make-mu4e-context
  927. :name "web.de"
  928. :enter-func (lambda () (mu4e-message "switch to web.de context"))
  929. :match-func (lambda (msg)
  930. (when msg
  931. (string-match-p "^/mailde" (mu4e-message-field msg :maildir))))
  932. :vars '((user-mail-address . "marc.pohling@web.de")
  933. (user-full-name . "Marc Pohling")
  934. (mu4e-drafts-folder . "/webde/drafts")
  935. (mu4e-sent-folder . "/webde/sent")
  936. (mu4e-refile-folder . "/webde/archive")
  937. (mu4e-trash-folder . "/webde/trash")))
  938. ,(make-mu4e-context
  939. :name "gmail loui"
  940. :enter-func (lambda () (mu4e-message "switch to gmail loui context"))
  941. :match-func (lambda (msg)
  942. (when msg
  943. (string-match-p "^/gmailloui" (mu4e-message-field msg :maildir))))
  944. :vars '((user-mail-address . "louithelou1@gmail.com")
  945. (user-full-name . "Loui")
  946. (message-send-mail-function . smtpmail-send-it)
  947. (smtpmail-smtp-user . "louithelou1@gmail.com")
  948. (smtpmail-smtp-server . "smtp.gmail.com")
  949. (smtpmail-smtp-service . 587)
  950. (smtpmail-stream-type . starttls)
  951. (mu4e-drafts-folder . "/gmailloui/drafts")
  952. (mu4e-sent-folder . "/gmailloui/sent")
  953. (mu4e-refile-folder . "/gmailloui/archive")
  954. (mu4e-trash-folder . "/gmailloui/trash")))))
  955. )
  956. #+end_src
  957. mu4e-dashboard
  958. https://github.com/rougier/mu4e-dashboard
  959. #+begin_src emacs-lisp
  960. (push 'mu4e elpaca-ignored-dependencies)
  961. (use-package mu4e-dashboard
  962. :if *sys/linux*
  963. :ensure (:host github :repo "rougier/mu4e-dashboard")
  964. :after mu4e
  965. :hook
  966. (mu4e-dashboard-mode . (lambda () (display-line-numbers-mode -1)))
  967. :custom
  968. (mu4e-dashboard-file (concat MY--PATH_USER_GLOBAL "mu4e-dashboard.org"))
  969. :config
  970. ; (require 'mu4e)
  971. (defun mu4e-dashboard-edit ()
  972. (interactive)
  973. (let ((edit-buffer "*edit-mu4e-dashboard*"))
  974. (when (get-buffer edit-buffer)
  975. (kill-buffer (get-buffer edit-buffer)))
  976. (make-indirect-buffer (current-buffer) edit-buffer)
  977. (switch-to-buffer-other-window (get-buffer edit-buffer))
  978. (org-mode 1)))
  979. (display-line-numbers-mode -1)
  980. (flyspell-mode -1))
  981. #+end_src
  982. * outlook
  983. In outlook a macro is necessary, also a reference to FM20.DLL
  984. (Microsoft Forms 2.0 Object Library, in c:\windows\syswow64\fm20.dll)
  985. The macro copies the GUID of the email to the clipboard
  986. Attention: the GUID changes when the email is moved to another folder!
  987. The macro:
  988. #+BEGIN_SRC
  989. Sub AddLinkToMessageInClipboard()
  990. 'Adds a link to the currently selected message to the clipboard
  991. Dim objMail As Outlook.MailItem
  992. Dim doClipboard As New DataObject
  993. 'One and ONLY one message muse be selected
  994. If Application.ActiveExplorer.Selection.Count <> 1 Then
  995. MsgBox ("Select one and ONLY one message.")
  996. Exit Sub
  997. End If
  998. Set objMail = Application.ActiveExplorer.Selection.Item(1)
  999. doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
  1000. doClipboard.PutInClipboard
  1001. End Sub
  1002. #+END_SRC
  1003. #+BEGIN_SRC emacs-lisp
  1004. ;(org-add-link-type "outlook" 'my--org-outlook-open)
  1005. ;(org-add-link-type "outlooknewmail" 'my--org-outlook-new-mail)
  1006. (defun my--org-outlook-open (id)
  1007. (w32-shell-execute "open" "outlook" (concat " /select outlook:" id)))
  1008. (defun my--org-outlook-new-mail (receipients)
  1009. ; separate RECEIPIENTS for main, cc and bcc by |
  1010. (setq recp (split-string receipients "|"))
  1011. (setq mailstring (concat " /c ipm.note /m " (nth 0 recp)))
  1012. (if (nth 1 recp)
  1013. ; this check has tp be separated because (and..) would stumble over a nil
  1014. (if (not (equal "" (nth 1 recp)))
  1015. (setq mailstring (concat mailstring "&cc=" (nth 1 recp)))))
  1016. (if (nth 2 recp)
  1017. (setq mailstring (concat mailstring "&bcc=" (nth 2 recp))))
  1018. (w32-shell-execute "open" "outlook" mailstring))
  1019. (defun my/org-outlook-open-test ()
  1020. (interactive)
  1021. (w32-shell-execute "open" "outlook" " /select outlook:000000008A209C397CEF2C4FBA9E54AEB5B1F97F0700846D043B407C5B43A0C05AFC46DC5C630587BE5E020900006E48FF8F6027694BA6593777F542C19E0002A6434D000000"))'
  1022. #+END_SRC
  1023. * misc
  1024. #+begin_src emacs-lisp
  1025. (use-package autorevert
  1026. :diminish auto-revert-mode)
  1027. #+end_src
  1028. * orgmode
  1029. ** some notes
  1030. *** copy file path within emacs
  1031. Enter dired-other-window
  1032. place cursor on the file
  1033. M-0 w (copy absolute path)
  1034. C-u w (copy relative path)
  1035. *** Archiving
  1036. C-c C-x C-a
  1037. To keep the subheading structure when archiving, set the properties of the superheading.
  1038. #+begin_src org :tangle no
  1039. ,* FOO
  1040. :PROPERTIES:
  1041. :ARCHIVE: %s_archive::* FOO
  1042. ,** DONE BAR
  1043. ,** TODO BAZ
  1044. #+end_src
  1045. When moving BAR to archive, it will go to FILENAME.org_archive below the heading FOO.
  1046. [[http://doc.endlessparentheses.com/Var/org-archive-location.html][Other examples]]
  1047. ** org
  1048. This seems necessary to prevent 'org is already installed' error
  1049. https://github.com/jwiegley/use-package/issues/319
  1050. #+begin_src emacs-lisp
  1051. ;(assq-delete-all 'org package--builtins)'
  1052. ;(assq-delete-all 'org package--builtin-versions)
  1053. #+end_src
  1054. #+BEGIN_SRC emacs-lisp
  1055. (defun my--buffer-prop-set (name value)
  1056. "Set a file property called NAME to VALUE in buffer file.
  1057. If the property is already set, replace its value."
  1058. (setq name (downcase name))
  1059. (org-with-point-at 1
  1060. (let ((case-fold-search t))
  1061. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  1062. (point-max) t)
  1063. (replace-match (concat "#+" name ": " value) 'fixedcase)
  1064. (while (and (not (eobp))
  1065. (looking-at "^[#:]"))
  1066. (if (save-excursion (end-of-line) (eobp))
  1067. (progn
  1068. (end-of-line)
  1069. (insert "\n"))
  1070. (forward-line)
  1071. (beginning-of-line)))
  1072. (insert "#+" name ": " value "\n")))))
  1073. (defun my--buffer-prop-remove (name)
  1074. "Remove a buffer property called NAME."
  1075. (org-with-point-at 1
  1076. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  1077. (point-max) t)
  1078. (replace-match ""))))
  1079. (use-package org
  1080. :ensure t
  1081. ; :pin gnu
  1082. :mode (("\.org$" . org-mode))
  1083. :diminish org-indent-mode
  1084. :defer 1
  1085. :hook
  1086. (org-mode . org-indent-mode)
  1087. (org-source-mode . smartparens-mode)
  1088. :bind (("C-c l" . org-store-link)
  1089. ("C-c c" . org-capture)
  1090. ("C-c a" . org-agenda)
  1091. :map org-mode-map ("S-<right>" . org-shiftright)
  1092. ("S-<left>" . org-shiftleft))
  1093. :init
  1094. (defun my--org-agenda-files-set ()
  1095. "Sets default agenda files.
  1096. Necessary when updating roam agenda todos."
  1097. (setq org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  1098. (concat MY--PATH_ORG_FILES "projects.org")
  1099. (concat MY--PATH_ORG_FILES "tasks.org")))
  1100. (when *sys/linux*
  1101. (nconc org-agenda-files
  1102. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$"))))
  1103. (my--org-agenda-files-set)
  1104. (defun my--org-skip-subtree-if-priority (priority)
  1105. "Skip an agenda subtree if it has a priority of PRIORITY.
  1106. PRIORITY may be one of the characters ?A, ?B, or ?C."
  1107. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  1108. (pri-value (* 1000 (- org-lowest-priority priority)))
  1109. (pri-current (org-get-priority (thing-at-point 'line t))))
  1110. (if (= pri-value pri-current)
  1111. subtree-end
  1112. nil)))
  1113. :config
  1114. (when *work_remote*
  1115. (org-add-link-type "outlook" 'my--org-outlook-open)
  1116. (org-add-link-type "outlooknewmail" 'my--org-outlook-new-mail)
  1117. (setq org-todo-keywords
  1118. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED")))
  1119. (setq org-capture-templates
  1120. '(("t" "telephone call" entry
  1121. ; (file+olp+datetree (concat MY--PATH_ORG_FILES "phone_calls.org"))
  1122. (file+datetree "p:/Eigene Dateien/Notizen/phone_calls.org")
  1123. "* [%<%Y-%m-%d %H:%M>] %?"
  1124. :empty-lines 0 :jump-to-captured t))))
  1125. (when *sys/linux*
  1126. (setq org-pretty-entities t))
  1127. :custom
  1128. (org-startup-truncated t)
  1129. (org-startup-align-all-tables t)
  1130. (org-src-fontify-natively t) ;; use syntax highlighting in code blocks
  1131. (org-src-preserve-indentation t) ;; no extra indentation
  1132. (org-src-window-setup 'current-window) ;; C-c ' opens in current window
  1133. (org-modules (quote (org-id
  1134. org-habit
  1135. org-tempo))) ;; easy templates
  1136. (org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org"))
  1137. (org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations"))
  1138. (org-log-into-drawer "LOGBOOK")
  1139. (org-log-done 'time) ;; create timestamp when task is done
  1140. (org-blank-before-new-entry '((heading) (plain-list-item))) ;; prevent new line before new item
  1141. (org-src-tab-acts-natively t)
  1142. ;;Sort agenda by deadline and priority
  1143. (org-agenda-sorting-strategy
  1144. (quote
  1145. ((agenda deadline-up priority-down)
  1146. (todo priority-down category-keep)
  1147. (tags priority-down category-keep)
  1148. (search category-keep))))
  1149. (org-agenda-custom-commands
  1150. '(("c" "Simple agenda view"
  1151. ((tags "PRIORITY=\"A\""
  1152. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1153. (org-agenda-overriding-header "Hohe Priorität:")))
  1154. (agenda ""
  1155. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  1156. (org-agenda-span 7)
  1157. (org-agenda-start-on-weekday nil)
  1158. (org-agenda-overriding-header "Nächste 7 Tage:")))
  1159. (alltodo ""
  1160. ((org-agenda-skip-function '(or (my--org-skip-subtree-if-priority ?A)
  1161. (org-agenda-skip-if nil '(scheduled deadline))))
  1162. (org-agenda-overriding-header "Sonstige Aufgaben:"))))))))
  1163. #+END_SRC
  1164. ** COMMENT languages
  1165. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  1166. Elpaca cant find it, though it's built in org
  1167. #+begin_src emacs-lisp
  1168. (use-package ob-python
  1169. ; :ensure nil
  1170. :defer t
  1171. :after org
  1172. ; :ensure org-contrib
  1173. :commands
  1174. (org-babel-execute:python))
  1175. #+end_src
  1176. ** COMMENT habits
  1177. #+BEGIN_SRC emacs-lisp
  1178. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  1179. ;; (add-to-list 'org-modules "org-habit")
  1180. (setq org-habit-graph-column 80
  1181. org-habit-preceding-days 30
  1182. org-habit-following-days 7
  1183. org-habit-show-habits-only-for-today nil)
  1184. #+END_SRC
  1185. ** contacts
  1186. #+BEGIN_SRC emacs-lisp
  1187. (use-package org-contacts
  1188. :ensure (:host nil :repo "https://repo.or.cz/org-contacts.git")
  1189. :after org
  1190. :custom
  1191. (org-contacts-files (list (concat MY--PATH_ORG_ROAM "contacts.org"))))
  1192. #+END_SRC
  1193. ** *TODO*
  1194. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  1195. ** COMMENT journal
  1196. [[https://github.com/bastibe/org-journal][Source]]
  1197. Ggf. durch org-roam-journal ersetzen
  1198. #+BEGIN_SRC emacs-lisp
  1199. (use-package org-journal
  1200. :if *sys/linux*
  1201. :ensure t
  1202. :defer t
  1203. :config
  1204. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  1205. (when (and (boundp 'org-journal-dir)
  1206. (boundp 'org-journal-enable-agenda-integration))
  1207. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  1208. org-journal-enable-agenda-integration t)))
  1209. #+END_SRC
  1210. ** org-roam
  1211. [[https://github.com/org-roam/org-roam][Github]]
  1212. Um Headings innerhalb einer Datei zu verlinken:
  1213. - org-id-get-create im Heading,
  1214. - org-roam-node-insert in der verweisenden Datei
  1215. Bei Problemen wie unique constraint
  1216. org-roam-db-clear-all
  1217. org-roam-db-sync
  1218. #+BEGIN_SRC emacs-lisp
  1219. (use-package emacsql-sqlite-builtin
  1220. :ensure t)
  1221. (use-package org-roam
  1222. :requires emacsql-sqlite-builtin
  1223. :ensure t
  1224. :defer 2
  1225. :after org
  1226. :init
  1227. (setq org-roam-v2-ack t)
  1228. (defun my--roamtodo-p ()
  1229. "Return non-nil if current buffer has any todo entry.
  1230. TODO entries marked as done are ignored, meaning this function
  1231. returns nil if current buffer contains only completed tasks."
  1232. (seq-find
  1233. (lambda (type)
  1234. (eq type 'todo))
  1235. (org-element-map
  1236. (org-element-parse-buffer 'headline)
  1237. 'headline
  1238. (lambda (h)
  1239. (org-element-property :todo-type h)))))
  1240. (defun my--roamtodo-update-tag ()
  1241. "Update ROAMTODO tag in the current buffer."
  1242. (when (and (not (active-minibuffer-window))
  1243. (my--buffer-roam-note-p))
  1244. (save-excursion
  1245. (goto-char (point-min))
  1246. (let* ((tags (my--buffer-tags-get))
  1247. (original-tags tags))
  1248. (if (my--roamtodo-p)
  1249. (setq tags (cons "roamtodo" tags))
  1250. (setq tags (remove "roamtodo" tags)))
  1251. ;;cleanup duplicates
  1252. (when (or (seq-difference tags original-tags)
  1253. (seq-difference original-tags tags))
  1254. (apply #'my--buffer-tags-set tags))))))
  1255. (defun my--buffer-tags-get ()
  1256. "Return filetags value in current buffer."
  1257. (my--buffer-prop-get-list "filetags" "[ :]"))
  1258. (defun my--buffer-tags-set (&rest tags)
  1259. "Set TAGS in current buffer.
  1260. If filetags value is already set, replace it."
  1261. (if tags
  1262. (my--buffer-prop-set
  1263. "filetags" (concat ":" (string-join tags ":") ":"))
  1264. (my--buffer-prop-remove "filetags")))
  1265. (defun my--buffer-tags-add (tag)
  1266. "Add a TAG to filetags in current buffer."
  1267. (let* ((tags (my--buffer-tags-get))
  1268. (tags (append tags (list tag))))
  1269. (apply #'my--buffer-tags-set tags)))
  1270. (defun my--buffer-tags-remove (tag)
  1271. "Remove a TAG from filetags in current buffer."
  1272. (let* ((tags (my--buffer-tags-get))
  1273. (tags (delete tag tags)))
  1274. (apply #'my--buffer-tags-set tags)))
  1275. (defun my--buffer-prop-set (name value)
  1276. "Set a file property called NAME to VALUE in buffer file.
  1277. If the property is already set, replace its value."
  1278. (setq name (downcase name))
  1279. (org-with-point-at 1
  1280. (let ((case-fold-search t))
  1281. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  1282. (point-max) t)
  1283. (replace-match (concat "#+" name ": " value) 'fixedcase)
  1284. (while (and (not (eobp))
  1285. (looking-at "^[#:]"))
  1286. (if (save-excursion (end-of-line) (eobp))
  1287. (progn
  1288. (end-of-line)
  1289. (insert "\n"))
  1290. (forward-line)
  1291. (beginning-of-line)))
  1292. (insert "#+" name ": " value "\n")))))
  1293. (defun my--buffer-prop-set-list (name values &optional separators)
  1294. "Set a file property called NAME to VALUES in current buffer.
  1295. VALUES are quoted and combined into single string using
  1296. `combine-and-quote-strings'.
  1297. If SEPARATORS is non-nil, it should be a regular expression
  1298. matching text that separates, but is not part of, the substrings.
  1299. If nil it defaults to `split-string-and-unquote', normally
  1300. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t.
  1301. If the property is already set, replace its value."
  1302. (my--buffer-prop-set
  1303. name (combine-and-quote-strings values separators)))
  1304. (defun my--buffer-prop-get (name)
  1305. "Get a buffer property called NAME as a string."
  1306. (org-with-point-at 1
  1307. (when (re-search-forward (concat "^#\\+" name ": \\(.*\\)")
  1308. (point-max) t)
  1309. (buffer-substring-no-properties
  1310. (match-beginning 1)
  1311. (match-end 1)))))
  1312. (defun my--buffer-prop-get-list (name &optional separators)
  1313. "Get a buffer property NAME as a list using SEPARATORS.
  1314. If SEPARATORS is non-nil, it should be a regular expression
  1315. matching text that separates, but is not part of, the substrings.
  1316. If nil it defaults to `split-string-default-separators', normally
  1317. \"[ \f\t\n\r\v]+\", and OMIT-NULLS is forced to t."
  1318. (let ((value (my--buffer-prop-get name)))
  1319. (when (and value (not (string-empty-p value)))
  1320. (split-string-and-unquote value separators))))
  1321. (defun my--buffer-prop-remove (name)
  1322. "Remove a buffer property called NAME."
  1323. (org-with-point-at 1
  1324. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  1325. (point-max) t)
  1326. (replace-match ""))))
  1327. (defun my--buffer-roam-note-p ()
  1328. "Return non-nil if the currently visited buffer is a note."
  1329. (and buffer-file-name
  1330. (string-prefix-p
  1331. (expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM))
  1332. (file-name-directory buffer-file-name))))
  1333. (defun my--org-roam-filter-by-tag (tag-name)
  1334. (lambda (node)
  1335. (member tag-name (org-roam-node-tags node))))
  1336. (defun my--org-roam-list-notes-by-tag (tag-name)
  1337. (mapcar #'org-roam-node-file
  1338. (seq-filter
  1339. (my--org-roam-filter-by-tag tag-name)
  1340. (org-roam-node-list))))
  1341. (defun my/org-roam-refresh-agenda-list ()
  1342. "Add all org roam files with #+filetags: roamtodo"
  1343. (interactive)
  1344. (my--org-agenda-files-set)
  1345. (nconc org-agenda-files
  1346. (my--org-roam-list-notes-by-tag "roamtodo"))
  1347. (setq org-agenda-files (delete-dups org-agenda-files)))
  1348. (add-hook 'find-file-hook #'my--roamtodo-update-tag)
  1349. (add-hook 'before-save-hook #'my--roamtodo-update-tag)
  1350. (advice-add 'org-agenda :before #'my/org-roam-refresh-agenda-list)
  1351. (advice-add 'org-todo-list :before #'my/org-roam-refresh-agenda-list)
  1352. (add-to-list 'org-tags-exclude-from-inheritance "roamtodo")
  1353. :config
  1354. (require 'org-roam-dailies) ;; ensure the keymap is available
  1355. (org-roam-db-autosync-mode)
  1356. ;; build the agenda list the first ime for the session
  1357. (my/org-roam-refresh-agenda-list)
  1358. (when *work_remote*
  1359. (setq org-roam-capture-templates
  1360. '(("n" "note" plain
  1361. "%?"
  1362. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1363. :unnarrowed t)
  1364. ("i" "idea" plain
  1365. "%?"
  1366. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1367. :unnarrowed t)
  1368. ("p" "project" plain
  1369. "%?"
  1370. :target (file+head "projects/${slug}.org" "#+title: ${title}\n#+filetags: :project:\n")
  1371. :unnarrowed t)
  1372. ("s" "Sicherheitenmeldung" plain
  1373. "*** TODO [#A] Sicherheitenmeldung ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1374. :target (file+olp "tasks.org" ("Todos" "Sicherheitenmeldungen")))
  1375. ("m" "Monatsbericht" plain
  1376. "*** TODO [#A] Monatsbericht ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1377. :target (file+olp "tasks.org" ("Todos" "Monatsberichte"))))))
  1378. :custom
  1379. (org-roam-database-connector 'sqlite-builtin)
  1380. (org-roam-directory MY--PATH_ORG_ROAM)
  1381. (org-roam-completion-everywhere t)
  1382. (org-roam-capture-templates
  1383. '(("n" "note" plain
  1384. "%?"
  1385. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1386. :unnarrowed t)
  1387. ("i" "idea" plain
  1388. "%?"
  1389. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
  1390. :unnarrowed t)
  1391. ))
  1392. :bind (("C-c n l" . org-roam-buffer-toggle)
  1393. ("C-c n f" . org-roam-node-find)
  1394. ("C-c n i" . org-roam-node-insert)
  1395. :map org-mode-map
  1396. ("C-M-i" . completion-at-point)
  1397. :map org-roam-dailies-map
  1398. ("Y" . org-roam-dailies-capture-yesterday)
  1399. ("T" . org-roam-dailies-capture-tomorrow))
  1400. :bind-keymap
  1401. ("C-c n d" . org-roam-dailies-map))
  1402. #+END_SRC
  1403. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  1404. * Programming
  1405. ** Magit / Git
  1406. Little crash course in magit:
  1407. - magit-init to init a git project
  1408. - magit-status (C-x g) to call the status window
  1409. In status buffer:
  1410. - s stage files
  1411. - u unstage files
  1412. - U unstage all files
  1413. - a apply changes to staging
  1414. - c c commit (type commit message, then C-c C-c to commit)
  1415. - b b switch to another branch
  1416. - P u git push
  1417. - F u git pull
  1418. #+BEGIN_SRC emacs-lisp
  1419. ;; updated version needed for magit, at least on windows
  1420. (use-package transient
  1421. :ensure t)
  1422. (use-package magit
  1423. :ensure t
  1424. ; :pin melpa-stable
  1425. :defer t
  1426. :init
  1427. ; set git-path in work environment
  1428. (if (string-equal user-login-name "POH")
  1429. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1430. )
  1431. :bind (("C-x g" . magit-status)))
  1432. #+END_SRC
  1433. ** COMMENT Eglot (can't do dap-mode, maybe dape?)
  1434. for python pyls (in env: pip install python-language-server) seems to work better than pyright (npm install -g pyright),
  1435. at least pandas couldnt be resolved in pyright
  1436. #+begin_src emacs-lisp
  1437. (use-package eglot
  1438. :ensure t
  1439. :init
  1440. (setq completion-category-overrides '((eglot (styles orderless))))
  1441. :config
  1442. (add-to-list 'eglot-server-programs '(python-mode . ("pyright-langserver" "--stdio")))
  1443. (with-eval-after-load 'eglot
  1444. (load-library "project"))
  1445. :hook
  1446. (python-mode . eglot-ensure)
  1447. :custom
  1448. (eglot-ignored-server-capabilities '(:documentHighlightProvider))
  1449. (eglot-autoshutdown t)
  1450. (eglot-events-buffer-size 0)
  1451. )
  1452. ;; performance stuff if necessary
  1453. ;(fset #'jsonrpc--log-event #'ignore)
  1454. #+end_src
  1455. ** LSP-Mode
  1456. #+begin_src emacs-lisp
  1457. (defun corfu-lsp-setup ()
  1458. (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
  1459. '(orderless)))
  1460. (use-package lsp-mode
  1461. :ensure t
  1462. ; :hook
  1463. ; ((python-mode . lsp))
  1464. :custom
  1465. (lsp-completion-provider :none)
  1466. (lsp-enable-suggest-server-download nil)
  1467. :hook
  1468. (lsp-completion-mode #'corfu-lsp-setup))
  1469. ;(use-package lsp-ui
  1470. ; :ensure t
  1471. ; :commands lsp-ui-mode)
  1472. (use-package lsp-pyright
  1473. :ensure t
  1474. :after (python lsp-mode)
  1475. :custom
  1476. (lsp-pyright-multi-root nil)
  1477. :hook
  1478. (python-mode-hook . (lambda ()
  1479. (require 'lsp-pyright) (lsp))))
  1480. #+end_src
  1481. ** flymake
  1482. python in venv: pip install pyflake (or ruff?)
  1483. TODO: if ruff active, sideline stops working
  1484. #+begin_src emacs-lisp
  1485. (setq python-flymake-command '("ruff" "--quiet" "--stdin-filename=stdin" "-"))
  1486. #+end_src
  1487. ** sideline
  1488. show flymake errors on the right of code window
  1489. #+begin_src emacs-lisp
  1490. (use-package sideline
  1491. :ensure t)
  1492. (use-package sideline-flymake
  1493. :ensure t
  1494. :requires sideline
  1495. :hook
  1496. (flymake-mode . sideline-mode)
  1497. :init
  1498. (setq sideline-flymake-display-mode 'line ; 'point or 'line
  1499. ; sideline-backends-left '(sideline-lsp)
  1500. sideline-backends-right '(sideline-flymake)))
  1501. #+end_src
  1502. ** yasnippet
  1503. For useful snippet either install yasnippet-snippets or get them from here
  1504. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1505. #+begin_src emacs-lisp
  1506. (use-package yasnippet
  1507. :ensure t
  1508. :defer t
  1509. :diminish yas-minor-mode
  1510. :config
  1511. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1512. (yas-global-mode t)
  1513. (yas-reload-all)
  1514. (unbind-key "TAB" yas-minor-mode-map)
  1515. (unbind-key "<tab>" yas-minor-mode-map))
  1516. #+end_src
  1517. ** hippie expand
  1518. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1519. #+begin_src emacs-lisp
  1520. (use-package hippie-exp
  1521. :ensure nil
  1522. :defer t
  1523. :bind
  1524. ("C-<return>" . hippie-expand)
  1525. :config
  1526. (setq hippie-expand-try-functions-list
  1527. '(yas-hippie-try-expand emmet-expand-line)))
  1528. #+end_src
  1529. ** COMMENT flycheck (now flymake)
  1530. #+BEGIN_SRC emacs-lisp
  1531. (use-package flycheck
  1532. :ensure t
  1533. :hook
  1534. ((css-mode . flycheck-mode)
  1535. (emacs-lisp-mode . flycheck-mode)
  1536. (python-mode . flycheck-mode))
  1537. :defer 1.0
  1538. :init
  1539. (setq flycheck-emacs-lisp-load-path 'inherit)
  1540. :config
  1541. (setq-default
  1542. flycheck-check-synta-automatically '(save mode-enabled)
  1543. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1544. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1545. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1546. #+END_SRC
  1547. ** smartparens
  1548. #+BEGIN_SRC emacs-lisp
  1549. (use-package smartparens
  1550. :ensure t
  1551. :diminish smartparens-mode
  1552. :bind
  1553. (:map smartparens-mode-map
  1554. ("C-M-f" . sp-forward-sexp)
  1555. ("C-M-b" . sp-backward-sexp)
  1556. ("C-M-a" . sp-backward-down-sexp)
  1557. ("C-M-e" . sp-up-sexp)
  1558. ("C-M-w" . sp-copy-sexp)
  1559. ("M-k" . sp-kill-sexp)
  1560. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1561. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1562. ("C-]" . sp-select-next-thing-exchange))
  1563. :config
  1564. (setq sp-show-pair-from-inside nil
  1565. sp-escape-quotes-after-insert nil)
  1566. (require 'smartparens-config))
  1567. #+END_SRC
  1568. ** lisp
  1569. #+BEGIN_SRC emacs-lisp
  1570. (use-package elisp-mode
  1571. :ensure nil
  1572. :defer t)
  1573. #+END_SRC
  1574. ** web
  1575. apt install npm
  1576. sudo npm install -g vscode-html-languageserver-bin
  1577. evtl alternativ typescript-language-server?
  1578. Unter Windows:
  1579. Hier runterladen: https://nodejs.org/dist/latest/
  1580. und in ein Verzeichnis entpacken.
  1581. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1582. PATH=P:\path\to\node;%path%
  1583. *** web-mode
  1584. #+BEGIN_SRC emacs-lisp
  1585. (use-package web-mode
  1586. :ensure t
  1587. :defer t
  1588. :mode
  1589. ("\\.phtml\\'"
  1590. "\\.tpl\\.php\\'"
  1591. "\\.djhtml\\'"
  1592. "\\.[t]?html?\\'")
  1593. :hook
  1594. (web-mode . smartparens-mode)
  1595. :init
  1596. (if *work_remote*
  1597. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1598. :config
  1599. (setq web-mode-enable-auto-closing t
  1600. web-mode-enable-auto-pairing t))
  1601. #+END_SRC
  1602. Emmet offers snippets, similar to yasnippet.
  1603. Default completion is C-j
  1604. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1605. #+begin_src emacs-lisp
  1606. (use-package emmet-mode
  1607. :ensure t
  1608. :defer t
  1609. :hook
  1610. ((web-mode . emmet-mode)
  1611. (css-mode . emmet-mode))
  1612. :config
  1613. (unbind-key "C-<return>" emmet-mode-keymap))
  1614. #+end_src
  1615. *** JavaScript
  1616. npm install -g typescript-language-server typescript
  1617. maybe only typescript?
  1618. npm install -g prettier
  1619. #+begin_src emacs-lisp
  1620. (use-package rjsx-mode
  1621. :ensure t
  1622. :mode ("\\.js\\'"
  1623. "\\.jsx'"))
  1624. ; :config
  1625. ; (setq js2-mode-show-parse-errors nil
  1626. ; js2-mode-show-strict-warnings nil
  1627. ; js2-basic-offset 2
  1628. ; js-indent-level 2)
  1629. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1630. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1631. (use-package tide
  1632. :ensure t
  1633. :after (rjsx-mode company flycheck)
  1634. ; :hook (rjsx-mode . setup-tide-mode)
  1635. :config
  1636. (defun setup-tide-mode ()
  1637. "Setup function for tide."
  1638. (interactive)
  1639. (tide-setup)
  1640. (flycheck-mode t)
  1641. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1642. (tide-hl-identifier-mode t)))
  1643. ;; needs npm install -g prettier
  1644. (use-package prettier-js
  1645. :ensure t
  1646. :after (rjsx-mode)
  1647. :defer t
  1648. :diminish prettier-js-mode
  1649. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1650. #+end_src
  1651. ** YAML
  1652. #+begin_src emacs-lisp
  1653. (use-package yaml-mode
  1654. :if *sys/linux*
  1655. :ensure t
  1656. :defer t
  1657. :mode ("\\.yml$" . yaml-mode))
  1658. #+end_src
  1659. ** R
  1660. #+BEGIN_SRC emacs-lisp
  1661. (use-package ess
  1662. :ensure t
  1663. :defer t
  1664. :init
  1665. (if *work_remote*
  1666. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1667. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1668. #+END_SRC
  1669. ** project.el
  1670. #+begin_src emacs-lisp
  1671. (use-package project
  1672. :custom
  1673. (project-vc-extra-root-markers '(".project.el" ".project" )))
  1674. #+end_src
  1675. ** Python
  1676. Preparations:
  1677. - create env:
  1678. m-x shell
  1679. python3 -m venv ./.env
  1680. - Install language server in *each* projects venv
  1681. source ./.env/bin/activate
  1682. pip install pyright
  1683. - in project root:
  1684. touch .project.el
  1685. echo "((nil . (pyvenv-activate . "/path/to/project/.env")))" >> .dir-locals.el
  1686. für andere language servers
  1687. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1688. TODO if in a project, set venv automatically
  1689. (when-let ((project (project-current))) (project-root project))
  1690. returns project path from project.el
  1691. to recognize a project, either have git or
  1692. place a .project.el file in project root and
  1693. (setq project-vc-extra-root-markers '(".project.el" "..." ))
  1694. #+begin_src emacs-lisp
  1695. (use-package python
  1696. :if *sys/linux*
  1697. :delight "π "
  1698. :defer t
  1699. :bind (("M-[" . python-nav-backward-block)
  1700. ("M-]" . python-nav-forward-block))
  1701. :mode
  1702. (("\\.py\\'" . python-mode)))
  1703. (use-package pyvenv
  1704. ; :if *sys/linux*
  1705. :ensure t
  1706. :defer t
  1707. :after python
  1708. :hook
  1709. (python-mode . pyvenv-mode)
  1710. :custom
  1711. (pyvenv-default-virtual-env-name ".env")
  1712. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]"))))
  1713. ;; formatting to pep8
  1714. ;; requires pip install black
  1715. ;(use-package blacken
  1716. ; :ensure t)
  1717. #+end_src
  1718. TODO python mode hook:
  1719. - activate venv
  1720. - activate eglot with proper ls
  1721. - activate tree-sitter?
  1722. - have some fallback if activations fail
  1723. * beancount
  1724. ** Installation
  1725. #+BEGIN_SRC shell :tangle no
  1726. sudo su
  1727. cd /opt
  1728. python3 -m venv beancount
  1729. source ./beancount/bin/activate
  1730. pip3 install wheel
  1731. pip3 install beancount
  1732. sleep 100
  1733. echo "shell running!"
  1734. deactivate
  1735. #+END_SRC
  1736. #+begin_src emacs-lisp
  1737. (use-package beancount
  1738. :ensure nil
  1739. :if *sys/linux*
  1740. :load-path "user-global/elisp/"
  1741. ; :ensure t
  1742. :defer t
  1743. :mode
  1744. ("\\.beancount$" . beancount-mode)
  1745. :hook
  1746. (beancount-mode . my/beancount-company)
  1747. :config
  1748. (defun my/beancount-company ()
  1749. (setq-local completion-at-point-functions #'beancount-completion-at-point))
  1750. (setq beancount-filename-main "/home/marc/archiv/Finanzen/Transaktionen/transactions.beancount"))
  1751. #+end_src
  1752. +BEGIN_SRC emacs-lisp
  1753. (use-package beancount
  1754. :if *sys/linux*
  1755. :load-path "user-global/elisp"
  1756. ; :ensure t
  1757. :defer t
  1758. :mode
  1759. ("\\.beancount$" . beancount-mode)
  1760. ; :hook
  1761. ; (beancount-mode . my/beancount-company)
  1762. ; :init
  1763. ; (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1764. :config
  1765. (defun my/beancount-company ()
  1766. (setq-local completion-at-point-functions #'beancount-complete-at-point nil t))
  1767. ; (mapcar #'cape-company-to-capf
  1768. ; (list #'company-beancount #'company-dabbrev))))
  1769. (defun my--beancount-companyALT ()
  1770. (set (make-local-variable 'company-backends)
  1771. '(company-beancount)))
  1772. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1773. +END_SRC
  1774. To support org-babel, check if it can find the symlink to ob-beancount.el
  1775. #+BEGIN_SRC shell :tangle no
  1776. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1777. beansym="$orgpath/ob-beancount.el
  1778. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1779. if [ -h "$beansym" ]
  1780. then
  1781. echo "$beansym found"
  1782. elif [ -e "$bean" ]
  1783. then
  1784. echo "creating symlink"
  1785. ln -s "$bean" "$beansym"
  1786. else
  1787. echo "$bean not found, symlink creation aborted"
  1788. fi
  1789. #+END_SRC
  1790. Fava is strongly recommended.
  1791. #+BEGIN_SRC shell :tangle no
  1792. cd /opt
  1793. python3 -m venv fava
  1794. source ./fava/bin/activate
  1795. pip3 install wheel
  1796. pip3 install fava
  1797. deactivate
  1798. #+END_SRC
  1799. Start fava with fava my_file.beancount
  1800. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1801. Beancount-mode can start fava and open the URL right away.
  1802. * Stuff after everything else
  1803. Set garbage collector to a smaller value to let it kick in faster.
  1804. Maybe a problem on Windows?
  1805. #+begin_src emacs-lisp
  1806. ;(setq gc-cons-threshold (* 2 1000 1000))
  1807. #+end_src
  1808. Rest of early-init.el
  1809. #+begin_src emacs-lisp :tangle early-init.el
  1810. (defconst config-org (expand-file-name "config.org" user-emacs-directory))
  1811. (defconst init-el (expand-file-name "init.el" user-emacs-directory))
  1812. (unless (file-exists-p init-el)
  1813. (require 'org)
  1814. (org-babel-tangle-file config-org init-el))
  1815. #+end_src