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.

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