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.

1664 lines
47 KiB

5 years ago
2 years ago
3 years ago
3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
2 years ago
2 years ago
2 years ago
2 years ago
6 years ago
3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #+TITLE: Emacs configuration file
  2. #+AUTHOR: Marc
  3. #+BABEL: :cache yes
  4. #+PROPERTY: header-args :tangle yes
  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. - evil-collection or custom in init file?
  12. - Hydra
  13. - General
  14. - (defalias 'list-buffers 'ibuffer) ;; change default to ibuffer
  15. - ido?
  16. - treemacs (for linux)
  17. - treemacs-evil?
  18. - treemacs-projectile
  19. windmove?
  20. - tramp (in linux)
  21. - visual-regexp
  22. - org configuration: paths
  23. - org custom agenda
  24. - org-ql (related to org agendas)
  25. - org configuration: everything else
  26. - beancount configuration from config.org
  27. - CONTINUE TODO from config.org at Programming
  28. - all-the-icons?
  29. - lispy? [[https://github.com/abo-abo/lispy]]
  30. * Header
  31. :PROPERTIES:
  32. :ID: a14d7c89-24ea-41ae-b185-944bab49aa02
  33. :END:
  34. Emacs variables are dynamically scoped. That's unusual for most languages, so disable it here, too
  35. #+begin_src emacs-lisp
  36. ;;; init.el --- -*- lexical-binding: t -*-
  37. #+end_src
  38. * First start
  39. :PROPERTIES:
  40. :ID: 1c24d48e-0124-4a0b-8e78-82e4c531e818
  41. :END:
  42. These functions updates config.el whenever changes in config.org are made. The update will be active after saving.
  43. #+BEGIN_SRC emacs-lisp
  44. (defun me/tangle-config ()
  45. "Export code blocks from the literate config file
  46. asynchronously."
  47. (interactive)
  48. ;; prevent emacs from killing until tangle-process finished
  49. (add-to-list 'kill-emacs-query-functions
  50. (lambda ()
  51. (or (not (process-live-p (get-process "tangle-process")))
  52. (y-or-n-p "\"me/tangle-config\" is running; kill it? "))))
  53. ;; tangle config asynchronously
  54. (me/async-process
  55. (format "emacs %s --batch --eval '(org-babel-tangle nil \"%s\")'" config-org config-el)
  56. "tangle-process")
  57. (message "reloading user-init-file")
  58. (load-file config-el))
  59. (add-hook 'org-mode-hook
  60. (lambda ()
  61. (if (equal (buffer-file-name) config-org)
  62. (me/add-local-hook 'after-save-hook 'me/tangle-config))))
  63. (defun me/add-local-hook (hook function)
  64. "Add buffer-local hook."
  65. (add-hook hook function :local t))
  66. (defun me/async-process (command &optional name filter)
  67. "Start an async process by running the COMMAND string with bash. Return the
  68. process object for it.
  69. NAME is name for the process. Default is \"async-process\".
  70. FILTER is function that runs after the process is finished, its args should be
  71. \"(process output)\". Default is just messages the output."
  72. (make-process
  73. :command `("bash" "-c" ,command)
  74. :name (if name name
  75. "async-process")
  76. :filter (if filter filter
  77. (lambda (process output) (message output)))))
  78. ; (lambda (process output) (message (s-trim output))))))
  79. ;; Examples:
  80. ;;
  81. ;; (me/async-process "ls")
  82. ;;
  83. ;; (me/async-process "ls" "my ls process"
  84. ;; (lambda (process output) (message "Output:\n\n%s" output)))
  85. ;;
  86. ;; (me/async-process "unknown command")
  87. #+END_SRC
  88. A small function to measure start up time.
  89. Compare that to
  90. emacs -q --eval='(message "%s" (emacs-init-time))'
  91. (roughly 0.27s)
  92. https://blog.d46.us/advanced-emacs-startup/
  93. #+begin_src emacs-lisp
  94. (add-hook 'emacs-startup-hook
  95. (lambda ()
  96. (message "Emacs ready in %s with %d garbage collections."
  97. (format "%.2f seconds"
  98. (float-time
  99. (time-subtract after-init-time before-init-time)))
  100. gcs-done)))
  101. ;(setq gc-cons-threshold (* 50 1000 1000))
  102. #+end_src
  103. #+BEGIN_SRC emacs-lisp
  104. (require 'package)
  105. (add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/") t)
  106. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  107. (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  108. (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
  109. ; fix for bug 34341
  110. (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
  111. (when (< emacs-major-version 27)
  112. (package-initialize))
  113. #+END_SRC
  114. #+BEGIN_SRC emacs-lisp
  115. (unless (package-installed-p 'use-package)
  116. (package-refresh-contents)
  117. (package-install 'use-package))
  118. (eval-when-compile
  119. (setq use-package-enable-imenu-support t)
  120. (require 'use-package))
  121. (require 'bind-key)
  122. (setq use-package-verbose nil)
  123. (use-package diminish
  124. :ensure t)
  125. #+END_SRC
  126. cl is deprecated in favor for cl-lib, some packages like emmet still depend on cl.
  127. Shut off the compiler warning about it.
  128. Maybe turn it on again at some point before the next major emacs upgrade
  129. #+begin_src emacs-lisp
  130. (setq byte-compile-warnings '(cl-functions))
  131. #+end_src
  132. * Performance Optimization
  133. ** Garbage Collection
  134. Make startup faster by reducing the frequency of garbage collection.
  135. Set gc-cons-threshold (default is 800kb) to maximum value available, to prevent any garbage collection from happening during load time.
  136. #+BEGIN_SRC emacs-lisp :tangle early-init.el
  137. (setq gc-cons-threshold most-positive-fixnum)
  138. #+END_SRC
  139. Restore it to reasonable value after init. Also stop garbage collection during minibuffer interaction (helm etc.)
  140. #+begin_src emacs-lisp
  141. (defconst 1mb 1048576)
  142. (defconst 20mb 20971520)
  143. (defconst 30mb 31457280)
  144. (defconst 50mb 52428800)
  145. (defun me/defer-garbage-collection ()
  146. (setq gc-cons-threshold most-positive-fixnum))
  147. (defun me/restore-garbage-collection ()
  148. (run-at-time 1 nil (lambda () (setq gc-cons-threshold 30mb))))
  149. (add-hook 'emacs-startup-hook 'me/restore-garbage-collection 100)
  150. (add-hook 'minibuffer-setup-hook 'me/defer-garbage-collection)
  151. (add-hook 'minibuffer-exit-hook 'me/restore-garbage-collection)
  152. (setq read-process-output-max 1mb) ;; lsp-mode's performance suggest
  153. #+end_src
  154. ** File Handler
  155. #+begin_src emacs-lisp :tangle early-init.el
  156. (defvar default-file-name-handler-alist file-name-handler-alist)
  157. (setq file-name-handler-alist nil)
  158. (add-hook 'emacs-startup-hook
  159. (lambda ()
  160. (setq file-name-handler-alist default-file-name-handler-alist)) 100)
  161. #+end_src
  162. ** Others
  163. #+begin_src emacs-lisp :tangle early-init.el
  164. ;; Resizing the emacs frame can be a terriblu expensive part of changing the font.
  165. ;; By inhibiting this, we easily hale startup times with fonts that are larger
  166. ;; than the system default.
  167. (setq frame-inhibit-implied-resize t)
  168. #+end_src
  169. * Default settings
  170. :PROPERTIES:
  171. :ID: 3512d679-d111-4ccd-8372-6fc2acbc0374
  172. :END:
  173. ** paths
  174. #+BEGIN_SRC emacs-lisp
  175. (defconst *sys/gui*
  176. (display-graphic-p)
  177. "Is emacs running in a gui?")
  178. (defconst *sys/linux*
  179. (string-equal system-type 'gnu/linux)
  180. "Is the system running Linux?")
  181. (defconst *sys/windows*
  182. (string-equal system-type 'windows-nt)
  183. "Is the system running Windows?")
  184. (defconst *home_desktop*
  185. (string-equal (system-name) "marc")
  186. "Is emacs running on my desktop?")
  187. (defconst *home_laptop*
  188. (string-equal (system-name) "laptop")
  189. "Is emacs running on my laptop?")
  190. (defconst *work_local*
  191. (string-equal (system-name) "PMPCNEU08")
  192. "Is emacs running at work on the local system?")
  193. (defconst *work_remote*
  194. (or (string-equal (system-name) "PMTS01")
  195. (string-equal (system-name) "PMTSNEU01"))
  196. "Is emacs running at work on the remote system?")
  197. #+END_SRC
  198. #+BEGIN_SRC emacs-lisp
  199. (defvar MY--PATH_USER_LOCAL (concat user-emacs-directory "user-local/"))
  200. (defvar MY--PATH_USER_GLOBAL (concat user-emacs-directory "user-global/"))
  201. (add-to-list 'custom-theme-load-path (concat MY--PATH_USER_GLOBAL "themes"))
  202. (when *sys/linux*
  203. (defconst MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/"))
  204. (defconst MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/"))
  205. (defconst MY--PATH_ORG_JOURNAl (expand-file-name "~/Archiv/Organisieren/Journal/"))
  206. (defconst MY--PATH_ORG_ROAM (file-truename "~/Archiv/Organisieren/")))
  207. (when *work_remote*
  208. (defconst MY--PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  209. (defconst MY--PATH_ORG_FILES_MOBILE nil) ;; hacky way to prevent "free variable" compiler error
  210. (defconst MY--PATH_ORG_JOURNAL nil) ;; hacky way to prevent "free variable" compiler error
  211. (defconst MY--PATH_START "p:/Eigene Dateien/Notizen/")
  212. (defconst MY--PATH_ORG_ROAM (expand-file-name "p:/Eigene Dateien/Notizen/")))
  213. (setq custom-file (concat MY--PATH_USER_LOCAL "custom.el")) ;; don't spam init.e with saved customization settings
  214. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  215. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  216. #+end_src
  217. ** sane defaults
  218. #+begin_src emacs-lisp
  219. (setq-default create-lockfiles nil) ;; disable lock files, can cause trouble in e.g. lsp-mode
  220. (defalias 'yes-or-no-p 'y-or-n-p) ;; answer with y and n
  221. (setq custom-safe-themes t) ;; don't ask me if I want to load a theme
  222. (setq sentence-end-double-space nil) ;; don't coun two spaces after a period as the end of a sentence.
  223. (delete-selection-mode t) ;; delete selected region when typing
  224. (use-package saveplace
  225. :config
  226. (save-place-mode 1) ;; saves position in file when it's closed
  227. :custom
  228. (save-place-file (concat MY--PATH_USER_LOCAL "places")))
  229. (setq save-place-forget-unreadable-files nil) ;; checks if file is readable before saving position
  230. (global-set-key (kbd "RET") 'newline-and-indent) ;; indent after newline
  231. (setq save-interprogram-paste-before-kill t) ;; put replaced text into killring
  232. #+END_SRC
  233. ** Browser
  234. #+begin_src emacs-lisp
  235. (setq browse-url-function 'browse-url-generic
  236. browse-url-generic-program "firefox")
  237. #+end_src
  238. * Appearance
  239. ** Defaults
  240. #+begin_src emacs-lisp
  241. (set-charset-priority 'unicode)
  242. (setq-default locale-coding-system 'utf-8
  243. default-process-coding-system '(utf-8-unix . utf-8-unix))
  244. (set-terminal-coding-system 'utf-8)
  245. (set-keyboard-coding-system 'utf-8)
  246. (set-selection-coding-system 'utf-8)
  247. (if *sys/windows*
  248. (prefer-coding-system 'utf-8-dos)
  249. (prefer-coding-system 'utf-8))
  250. (setq-default bidi-paragraph-direction 'left-to-right
  251. bidi-inhibit-bpa t ;; both settings reduce line rescans
  252. uniquify-buffer-name-style 'forward
  253. indent-tabs-mode nil ;; avoid tabs in place of multiple spaces (they look bad in tex)
  254. indicate-empty-lines t ;; show empty lines
  255. scroll-margin 5 ;; smooth scrolling
  256. scroll-conservatively 10000
  257. scroll-preserve-screen-position 1
  258. scroll-step 1
  259. ring-bell-function 'ignore ;; disable pc speaker bell
  260. visible-bell t)
  261. (global-hl-line-mode t) ;; highlight current line
  262. (blink-cursor-mode -1) ;; turn off blinking cursor
  263. (column-number-mode t)
  264. #+end_src
  265. ** Remove redundant UI
  266. #+begin_src emacs-lisp :tangle early-init.el
  267. (menu-bar-mode -1) ;; disable menu bar
  268. (tool-bar-mode -1) ;; disable tool bar
  269. (scroll-bar-mode -1) ;; disable scroll bar
  270. #+end_src
  271. ** Font
  272. :PROPERTIES:
  273. :ID: dc8eb670-e6bb-4bfb-98f0-aae1860234fb
  274. :END:
  275. #+BEGIN_SRC emacs-lisp
  276. (when *sys/linux*
  277. (set-face-font 'default "Hack-10"))
  278. (when *work_remote*
  279. (set-face-font 'default "Lucida Sans Typewriter-11"))
  280. #+END_SRC
  281. ** Themes
  282. :PROPERTIES:
  283. :ID: 9ccf37c0-6837-43cb-bed8-5a353799d8b1
  284. :END:
  285. #+BEGIN_SRC emacs-lisp
  286. (defun me/toggle-theme ()
  287. (interactive)
  288. (when (or *sys/windows* *sys/linux*)
  289. (if (eq (car custom-enabled-themes) 'tango-dark)
  290. (progn (disable-theme 'tango-dark)
  291. (load-theme 'tango))
  292. (progn
  293. (disable-theme 'tango)
  294. (load-theme 'tango-dark)))))
  295. (bind-key "C-c t" 'me/toggle-theme)
  296. #+END_SRC
  297. Windows Theme:
  298. #+BEGIN_SRC emacs-lisp
  299. (when *sys/windows*
  300. (load-theme 'tango))
  301. (when *sys/linux*
  302. (load-theme 'plastic))
  303. #+END_SRC
  304. ** line wrappings
  305. :PROPERTIES:
  306. :ID: 14ae933e-2941-4cc3-82de-38f90f91bfd3
  307. :END:
  308. #+BEGIN_SRC emacs-lisp
  309. (global-visual-line-mode)
  310. (diminish 'visual-line-mode)
  311. (use-package adaptive-wrap
  312. :ensure t
  313. :hook
  314. (visual-line-mode . adaptive-wrap-prefix-mode))
  315. ; :init
  316. ; (when (fboundp 'adaptive-wrap-prefix-mode)
  317. ; (defun me/activate-adaptive-wrap-prefix-mode ()
  318. ; "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  319. ; (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  320. ; (add-hook 'visual-line-mode-hook 'me/activate-adaptive-wrap-prefix-mode)))
  321. #+END_SRC
  322. ** line numbers
  323. :PROPERTIES:
  324. :ID: 7b969436-98c9-4b61-ba7a-9fb22c9781ad
  325. :END:
  326. #+BEGIN_SRC emacs-lisp
  327. (use-package display-line-numbers
  328. :init
  329. :hook
  330. ((prog-mode
  331. org-src-mode) . display-line-numbers-mode)
  332. :config
  333. (setq-default display-line-numbers-type 'visual
  334. display-line-numbers-current-absolute t
  335. display-line-numbers-with 4
  336. display-line-numbers-widen t))
  337. #+END_SRC
  338. ** misc
  339. :PROPERTIES:
  340. :ID: a2873138-16ee-4990-89a2-26eab778ea74
  341. :END:
  342. #+BEGIN_SRC emacs-lisp
  343. (use-package rainbow-mode
  344. :ensure t
  345. :diminish
  346. :hook
  347. ((org-mode
  348. emacs-lisp-mode) . rainbow-mode))
  349. (use-package delight
  350. :ensure t)
  351. (show-paren-mode t) ;; show other part of brackets
  352. (setq blink-matching-paren nil) ;; not necessary with show-paren-mode, bugs out on C-s counsel-line
  353. (use-package rainbow-delimiters
  354. :ensure t
  355. :hook
  356. (prog-mode . rainbow-delimiters-mode))
  357. #+END_SRC
  358. * Bookmarks
  359. Usage:
  360. - C-x r m (bookmark-set): add bookmark
  361. - C-x r l (list-bookmark): list bookmarks
  362. - C-x r b (bookmark-jump): open bookmark
  363. Edit bookmarks (while in bookmark file):
  364. - d: mark current item
  365. - x: delete marked items
  366. - r: rename current item
  367. - s: save changes
  368. #+begin_src emacs-lisp
  369. (use-package bookmark
  370. :custom
  371. (bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks")))
  372. #+end_src
  373. Some windows specific stuff
  374. #+BEGIN_SRC emacs-lisp
  375. (when *sys/windows*
  376. (remove-hook 'find-file-hook 'vc-refresh-state)
  377. ; (progn
  378. ; (setq gc-cons-threshold (* 511 1024 1024)
  379. ; gc-cons-percentage 0.5
  380. ; garbage-collection-messages t)
  381. ; (run-with-idle-timer 5 t #'garbage-collect))
  382. (when (boundp 'w32-pipe-read-delay)
  383. (setq w32-pipe-read-delay 0))
  384. (when (boundp 'w32-get-true-file-attributes)
  385. (setq w32-get-true-file-attributes nil)))
  386. #+END_SRC
  387. * recentf
  388. Exclude some dirs from spamming recentf
  389. #+begin_src emacs-lisp
  390. (use-package recentf
  391. :config
  392. (recentf-mode)
  393. :custom
  394. (recentf-exclude '(".*-autoloads\\.el\\'"
  395. "[/\\]\\elpa/"
  396. "COMMIT_EDITMSG\\'"))
  397. (recentf-save-file (concat MY--PATH_USER_LOCAL "recentf"))
  398. (recentf-max-menu-items 600)
  399. (recentf-max-saved-items 600))
  400. #+end_src
  401. * savehist
  402. #+begin_src emacs-lisp
  403. (use-package savehist
  404. :config
  405. (savehist-mode)
  406. :custom
  407. (savehist-file (concat MY--PATH_USER_LOCAL "history")))
  408. #+end_src
  409. * undo
  410. :PROPERTIES:
  411. :ID: d57621b2-5472-4c89-a520-b4133db0b9af
  412. :END:
  413. #+BEGIN_SRC emacs-lisp
  414. (use-package undo-tree
  415. :ensure t
  416. :diminish undo-tree-mode
  417. :init
  418. (global-undo-tree-mode 1))
  419. #+END_SRC
  420. * ace-window
  421. #+begin_src emacs-lisp
  422. (use-package ace-window
  423. :ensure t
  424. :bind
  425. (:map global-map
  426. ("C-x o" . ace-window)))
  427. #+end_src
  428. * imenu-list
  429. :PROPERTIES:
  430. :ID: 0ae27ec9-5d77-43cf-ac76-5e12cc959046
  431. :END:
  432. A minor mode to show imenu in a sidebar.
  433. Call imenu-list-smart-toggle.
  434. [[https://github.com/bmag/imenu-list][Source]]
  435. #+BEGIN_SRC emacs-lisp
  436. (use-package imenu-list
  437. :ensure t
  438. :demand t ; otherwise mode loads too late and won't work on first file it's being activated on
  439. :config
  440. (setq imenu-list-focus-after-activation t
  441. imenu-list-auto-resize t
  442. imenu-list-position 'right)
  443. :bind
  444. (:map global-map
  445. ([f9] . imenu-list-smart-toggle))
  446. :custom
  447. (org-imenu-depth 4))
  448. #+END_SRC
  449. * which-key
  450. :PROPERTIES:
  451. :ID: a880f079-b3a3-4706-bf1e-5f6c680101f1
  452. :END:
  453. #+BEGIN_SRC emacs-lisp
  454. (use-package which-key
  455. :ensure t
  456. :diminish which-key-mode
  457. :defer t
  458. :hook
  459. (after-init . which-key-mode)
  460. :config
  461. (which-key-setup-side-window-bottom)
  462. (setq which-key-idle-delay 0.5))
  463. #+END_SRC
  464. * abbrev
  465. #+begin_src emacs-lisp
  466. (use-package abbrev
  467. :diminish abbrev-mode
  468. :hook
  469. ((text-mode org-mode) . abbrev-mode)
  470. :init
  471. (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_tables.el"))
  472. :config
  473. (if (file-exists-p abbrev-file-name)
  474. (quietly-read-abbrev-file))
  475. (setq save-abbrevs 'silently)) ;; don't bother me with asking for abbrev saving
  476. #+end_src
  477. * Evil
  478. :PROPERTIES:
  479. :ID: 80ca70e2-a146-46db-b581-418d655dc1fc
  480. :END:
  481. #+BEGIN_SRC emacs-lisp
  482. (use-package evil
  483. :ensure t
  484. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  485. :init
  486. (setq evil-want-C-i-jump nil) ;; prevent evil from blocking TAB in org tree expanding
  487. :config
  488. (evil-mode 1))
  489. #+END_SRC
  490. * General (key mapper)
  491. :PROPERTIES:
  492. :ID: a20f183f-d41a-4dff-bc37-3bc4e25c8036
  493. :END:
  494. #+BEGIN_SRC emacs-lisp
  495. (use-package general
  496. :ensure t)
  497. (general-define-key
  498. :states 'normal
  499. :keymaps 'imenu-list-major-mode-map
  500. "RET" '(imenu-list-goto-entry :which-key "goto")
  501. "TAB" '(hs-toggle-hiding :which-key "collapse")
  502. "d" '(imenu-list-display-entry :which-key "show")
  503. "q" '(imenu-list-quit-window :which-key "quit"))
  504. #+END_SRC
  505. * Vertico & Orderless
  506. Vertico is a completion ui.
  507. Orderless orders the suggestions by recency. The package prescient orders by frequency.
  508. [[https://github.com/minad/vertico][Vertico Github]]
  509. [[https://github.com/oantolin/orderless][Orderless Github]]
  510. #+begin_src emacs-lisp
  511. ;; completion ui
  512. (use-package vertico
  513. :init
  514. (vertico-mode))
  515. (use-package orderless
  516. :init
  517. (setq completion-styles '(orderless basic)
  518. completion-category-defaults nil
  519. completion-category-overrides '((file (styles partial-completion)))))
  520. #+end_src
  521. * Consult
  522. [[https://github.com/minad/consult][Github]]
  523. #+begin_src emacs-lisp
  524. (use-package consult
  525. :ensure t
  526. :bind
  527. (("C-x C-r" . consult-recent-file)
  528. ("C-x b" . consult-buffer)
  529. ("C-s" . consult-line))
  530. :config
  531. ;; disable preview for some commands and buffers
  532. ;; and enable it by M-.
  533. ;; see https://github.com/minad/consult#use-package-example
  534. (consult-customize
  535. consult-theme
  536. :preview-key '(debounce 0.2 any)
  537. consult-ripgrep consult-git-grep consult-grep
  538. consult-bookmark consult-recent-file consult-xref
  539. consult--source-file consult--source-project-file consult--source-bookmark
  540. :preview-key (kbd "M-.")))
  541. #+end_src
  542. * Marginalia
  543. [[https://github.com/minad/marginalia/][Github]]
  544. Adds additional information to the minibuffer
  545. #+begin_src emacs-lisp
  546. (use-package marginalia
  547. :ensure t
  548. :init
  549. (marginalia-mode)
  550. :bind
  551. (:map minibuffer-local-map
  552. ("M-A" . marginalia-cycle))
  553. :custom
  554. ;; switch by 'marginalia-cycle
  555. (marginalia-annotators '(marginalia-annotators-heavy
  556. marginalia-annotators-light
  557. nil)))
  558. #+end_src
  559. * Embark
  560. Does stuff in the minibuffer results
  561. #+begin_src emacs-lisp
  562. (use-package embark
  563. :ensure t
  564. :bind
  565. (("C-S-a" . embark-act)
  566. ("C-h B" . embark-bindings))
  567. :init
  568. (setq prefix-help-command #'embark-prefix-help-command)
  569. :config
  570. ;; hide modeline of the embark live/completions buffers
  571. (add-to-list 'display-buffer-alist
  572. '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
  573. nil
  574. (window-parameters (mode-line-format . none)))))
  575. (use-package embark-consult
  576. :ensure t
  577. :after (embark consult)
  578. :demand t
  579. :hook
  580. (embark-collect-mode . embark-consult-preview-minor-mode))
  581. #+end_src
  582. * Helm
  583. As an alternative if I'm not happy with selectrum & co
  584. begin_src emacs-lisp
  585. (use-package helm
  586. :ensure t
  587. :hook
  588. (helm-mode . helm-autoresize-mode)
  589. ;; :bind
  590. ;; (("M-x" . helm-M-x)
  591. ;; ("C-s" . helm-occur)
  592. ;; ("C-x C-f" . helm-find-files)
  593. ;; ("C-x C-b" . helm-buffers-list)
  594. ;; ("C-x b" . helm-buffers-list)
  595. ;; ("C-x C-r" . helm-recentf)
  596. ;; ("C-x C-i" . helm-imenu))
  597. :config
  598. (helm-mode)
  599. :custom
  600. (helm-split-window-inside-p t) ;; open helm buffer inside current window
  601. (helm-move-to-line-cycle-in-source t)
  602. (helm-echo-input-in-header-line t)
  603. (helm-autoresize-max-height 20)
  604. (helm-autoresize-min-height 5)
  605. )
  606. end_src
  607. * ivy / counsel / swiper
  608. :PROPERTIES:
  609. :ID: 55c74ba9-7761-4545-8ddd-087d6ee33e4b
  610. :END:
  611. +BEGIN_SRC emacs-lisp
  612. ; (require 'ivy)
  613. (use-package ivy
  614. :ensure t
  615. :diminish
  616. (ivy-mode . "")
  617. :defer t
  618. :init
  619. (ivy-mode 1)
  620. :bind
  621. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  622. :config
  623. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  624. ivy-height 20 ;; height of ivy window
  625. ivy-count-format "%d/%d" ;; current and total number
  626. ivy-re-builders-alist ;; regex replaces spaces with *
  627. '((t . ivy--regex-plus))))
  628. ; make counsel-M-x more descriptive
  629. (use-package ivy-rich
  630. :ensure t
  631. :defer t
  632. :init
  633. (ivy-rich-mode 1))
  634. (use-package counsel
  635. :ensure t
  636. :defer t
  637. :bind
  638. (("M-x" . counsel-M-x)
  639. ("C-x C-f" . counsel-find-file)
  640. ("C-x C-r" . counsel-recentf)
  641. ("C-x b" . counsel-switch-buffer)
  642. ("C-c C-f" . counsel-git)
  643. ("C-c h f" . counsel-describe-function)
  644. ("C-c h v" . counsel-describe-variable)
  645. ("M-i" . counsel-imenu)))
  646. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  647. ; ("C-r" . 'counsel-minibuffer-history)))
  648. (use-package swiper
  649. :ensure t
  650. :bind
  651. ("C-s" . swiper))
  652. (use-package ivy-hydra
  653. :ensure t)
  654. +END_SRC
  655. * misc
  656. #+begin_src emacs-lisp
  657. (use-package autorevert
  658. :diminish auto-revert-mode)
  659. #+end_src
  660. * company
  661. :PROPERTIES:
  662. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  663. :END:
  664. #+BEGIN_SRC emacs-lisp
  665. (use-package company
  666. :defer 1
  667. :diminish
  668. :defer t
  669. :bind
  670. (("C-<tab>" . company-complete)
  671. :map company-active-map
  672. ("RET" . nil)
  673. ([return] . nil)
  674. ("TAB" . company-complete-selection)
  675. ([tab] . company-complete-selection)
  676. ("<right>" . company-complete-common)
  677. ("<escape>" . company-abort))
  678. :hook
  679. (after-init . global-company-mode)
  680. (emacs-lisp-mode . me/company-elisp)
  681. (org-mode . me/company-org)
  682. :config
  683. (defun me/company-elisp ()
  684. (message "set up company for elisp")
  685. (set (make-local-variable 'company-backends)
  686. '(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp
  687. company-yasnippet
  688. company-dabbrev-code
  689. company-files)))
  690. (defun me/company-org ()
  691. (set (make-local-variable 'company-backends)
  692. '(company-capf company-files))
  693. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  694. (message "setup company for org"))
  695. (setq company-idle-delay .2
  696. company-minimum-prefix-length 1
  697. company-require-match nil
  698. company-show-numbers t
  699. company-tooltip-align-annotations t))
  700. (use-package company-statistics
  701. :ensure t
  702. :after company
  703. :defer t
  704. :init
  705. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  706. :config
  707. (company-statistics-mode 1))
  708. (use-package company-dabbrev
  709. :ensure nil
  710. :after company
  711. :defer t
  712. :config
  713. (setq-default company-dabbrev-downcase nil))
  714. ;; adds a info box right of the cursor with doc of the function
  715. (use-package company-box
  716. :ensure t
  717. :diminish
  718. :defer t
  719. :hook
  720. (company-mode . company-box-mode))
  721. ; :init
  722. ; (add-hook 'company-mode-hook 'company-box-mode))
  723. #+END_SRC
  724. * orgmode
  725. ** some notes
  726. *** Archiving
  727. C-c C-x C-a
  728. To keep the subheading structure when archiving, set the properties of the superheading
  729. #+begin_src org :tangle no
  730. ,* FOO
  731. :PROPERTIES:
  732. :ARCHIVE: %s_archive::* FOO
  733. ,** DONE BAR
  734. ,** TODO BAZ
  735. #+end_src
  736. When moving BAR to archive, it will go to FILENAME.org_archive below the heading FOO
  737. ** org
  738. :PROPERTIES:
  739. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  740. :END:
  741. #+BEGIN_SRC emacs-lisp
  742. (use-package org
  743. :ensure org-plus-contrib
  744. :mode (("\.org$" . org-mode))
  745. :diminish org-indent-mode
  746. :defer t
  747. :hook
  748. (org-mode . org-indent-mode)
  749. (org-source-mode . smartparens-mode)
  750. ; :init
  751. ; (add-hook 'org-mode-hook 'company/org-mode-hook)
  752. ; (add-hook 'org-src-mode-hook 'smartparens-mode)
  753. ; (add-hook 'org-mode-hook 'org-indent-mode)
  754. :config
  755. (defun me/org-company ()
  756. (set (make-local-variable 'company-backends)
  757. '(company-capf company-files))
  758. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  759. (message "company/org-mode-hook"))
  760. (setq org-modules (quote (org-id
  761. org-habit
  762. org-tempo ;; easy templates
  763. )))
  764. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  765. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  766. (concat MY--PATH_ORG_FILES "projects.org")
  767. (concat MY--PATH_ORG_FILES "tasks.org")))
  768. (when *sys/linux*
  769. (nconc org-agenda-files
  770. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  771. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  772. org-log-into-drawer "LOGBOOK")
  773. ;; some display customizations
  774. (setq org-pretty-entities t
  775. org-startup-truncated t
  776. org-startup-align-all-tables t)
  777. ;; some source code blocks customizations
  778. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  779. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  780. org-src-preserve-indentation t ;; no extra indentation
  781. org-src-tab-acts-natively t)
  782. (setq org-log-done 'time ;; create timestamp when task is done
  783. org-blank-before-new-entry '((heading) (plain-list-item)))) ;; prevent new line before new item
  784. #+END_SRC
  785. ** languages
  786. :PROPERTIES:
  787. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  788. :END:
  789. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  790. +BEGIN_SRC emacs-lisp
  791. (org-babel-do-load-languages
  792. 'org-babel-load-languages
  793. '((emacs-lisp . t)
  794. (gnuplot . t)
  795. (js . t)
  796. (latex . t)
  797. (lisp . t)
  798. (python . t)
  799. (shell . t)
  800. (sqlite . t)
  801. (org . t)
  802. (R . t)
  803. (scheme . t)))
  804. (setq org-confirm-babel-evaluate nil)
  805. +END_SRC
  806. Another setup, because org-babel-do-load-languages requires eager loading
  807. #+begin_src emacs-lisp
  808. (use-package ob-org
  809. :defer t
  810. :ensure org-plus-contrib
  811. :commands
  812. (org-babel-execute:org
  813. org-babel-expand-body:org))
  814. (use-package ob-python
  815. :defer t
  816. :ensure org-plus-contrib
  817. :commands (org-babel-execute:python))
  818. (use-package ob-js
  819. :defer t
  820. :ensure org-plus-contrib
  821. :commands (org-babel-execute:js))
  822. (use-package ob-shell
  823. :defer t
  824. :ensure org-plus-contrib
  825. :commands
  826. (org-babel-execute:sh
  827. org-babel-expand-body:sh
  828. org-babel-execute:bash
  829. org-babel-expand-body:bash))
  830. (use-package ob-emacs-lisp
  831. :defer t
  832. :ensure org-plus-contrib
  833. :commands
  834. (org-babel-execute:emacs-lisp
  835. org-babel-expand-body:emacs-lisp))
  836. (use-package ob-lisp
  837. :defer t
  838. :ensure org-plus-contrib
  839. :commands
  840. (org-babel-execute:lisp
  841. org-babel-expand-body:lisp))
  842. (use-package ob-gnuplot
  843. :defer t
  844. :ensure org-plus-contrib
  845. :commands
  846. (org-babel-execute:gnuplot
  847. org-babel-expand-body:gnuplot))
  848. (use-package ob-sqlite
  849. :defer t
  850. :ensure org-plus-contrib
  851. :commands
  852. (org-babel-execute:sqlite
  853. org-babel-expand-body:sqlite))
  854. (use-package ob-latex
  855. :defer t
  856. :ensure org-plus-contrib
  857. :commands
  858. (org-babel-execute:latex
  859. org-babel-expand-body:latex))
  860. (use-package ob-R
  861. :defer t
  862. :ensure org-plus-contrib
  863. :commands
  864. (org-babel-execute:R
  865. org-babel-expand-body:R))
  866. (use-package ob-scheme
  867. :defer t
  868. :ensure org-plus-contrib
  869. :commands
  870. (org-babel-execute:scheme
  871. org-babel-expand-body:scheme))
  872. #+end_src
  873. ** habits
  874. :PROPERTIES:
  875. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  876. :END:
  877. #+BEGIN_SRC emacs-lisp
  878. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  879. ;; (add-to-list 'org-modules "org-habit")
  880. (setq org-habit-graph-column 80
  881. org-habit-preceding-days 30
  882. org-habit-following-days 7
  883. org-habit-show-habits-only-for-today nil)
  884. #+END_SRC
  885. ** org-id
  886. :PROPERTIES:
  887. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  888. :END:
  889. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  890. #+BEGIN_SRC emacs-lisp
  891. ;; (use-package org-id
  892. ;; :config
  893. ;; (setq org-id-link-to-org-use-id t)
  894. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  895. #+END_SRC
  896. ** org-agenda
  897. :PROPERTIES:
  898. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  899. :END:
  900. Custom keywords, depending on environment
  901. #+BEGIN_SRC emacs-lisp
  902. (when *work_remote*
  903. (setq org-todo-keywords
  904. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  905. #+END_SRC
  906. Add some key bindings
  907. #+BEGIN_SRC emacs-lisp
  908. (bind-key "C-c l" 'org-store-link)
  909. (bind-key "C-c c" 'org-capture)
  910. (bind-key "C-c a" 'org-agenda)
  911. #+END_SRC
  912. Sort agenda by deadline and priority
  913. #+BEGIN_SRC emacs-lisp
  914. (setq org-agenda-sorting-strategy
  915. (quote
  916. ((agenda deadline-up priority-down)
  917. (todo priority-down category-keep)
  918. (tags priority-down category-keep)
  919. (search category-keep))))
  920. #+END_SRC
  921. Customize the org agenda
  922. #+BEGIN_SRC emacs-lisp
  923. (defun me--org-skip-subtree-if-priority (priority)
  924. "Skip an agenda subtree if it has a priority of PRIORITY.
  925. PRIORITY may be one of the characters ?A, ?B, or ?C."
  926. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  927. (pri-value (* 1000 (- org-lowest-priority priority)))
  928. (pri-current (org-get-priority (thing-at-point 'line t))))
  929. (if (= pri-value pri-current)
  930. subtree-end
  931. nil)))
  932. (setq org-agenda-custom-commands
  933. '(("c" "Simple agenda view"
  934. ((tags "PRIORITY=\"A\""
  935. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  936. (org-agenda-overriding-header "Hohe Priorität:")))
  937. (agenda ""
  938. ((org-agenda-span 7)
  939. (org-agenda-start-on-weekday nil)
  940. (org-agenda-overriding-header "Nächste 7 Tage:")))
  941. (alltodo ""
  942. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  943. (org-agenda-skip-if nil '(scheduled deadline))))
  944. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  945. #+END_SRC
  946. ** *TODO*
  947. org-super-agenda
  948. [[https://github.com/alphapapa/org-ql][org-ql]]
  949. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  950. ** org-caldav
  951. :PROPERTIES:
  952. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  953. :END:
  954. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  955. #+BEGIN_SRC emacs-lisp
  956. ;;(use-package org-caldav
  957. ;; :ensure t
  958. ;; :config
  959. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  960. ;; org-caldav-calendar-id "orgmode"
  961. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  962. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  963. #+END_SRC
  964. ** journal
  965. :PROPERTIES:
  966. :ID: a1951e18-d862-4198-9652-016e979053c8
  967. :END:
  968. [[https://github.com/bastibe/org-journal][Source]]
  969. Ggf. durch org-roam-journal ersetzen
  970. #+BEGIN_SRC emacs-lisp
  971. (use-package org-journal
  972. :if *sys/linux*
  973. :ensure t
  974. :defer t
  975. :config
  976. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  977. (when (and (boundp 'org-journal-dir)
  978. (boundp 'org-journal-enable-agenda-integration))
  979. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  980. org-journal-enable-agenda-integration t)))
  981. #+END_SRC
  982. ** org-roam
  983. [[https://github.com/org-roam/org-roam][Github]]
  984. Um Headings innerhalb einer Datei zu verlinken:
  985. - org-id-get-create im Heading,
  986. - org-roam-node-insert in der verweisenden Datei
  987. Bei Problemen wie unique constraint
  988. org-roam-db-clear-all
  989. org-roam-db-sync
  990. #+BEGIN_SRC emacs-lisp
  991. (use-package org-roam
  992. :ensure t
  993. :init
  994. (setq org-roam-v2-ack t)
  995. :custom
  996. (org-roam-directory MY--PATH_ORG_ROAM)
  997. (org-roam-completion-everywhere t)
  998. (org-roam-capture-templates
  999. '(("d" "default" plain
  1000. "%?"
  1001. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: ${title}\n")
  1002. :unnarrowed t)
  1003. ("n" "ndefault" plain
  1004. "%?"
  1005. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: ${title}\n")
  1006. :unnarrowed t)
  1007. ("p" "new Project" plain
  1008. "** ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1009. :target (file+olp "projects.org" ("Active")))
  1010. ))
  1011. :bind (("C-c n l" . org-roam-buffer-toggle)
  1012. ("C-c n f" . org-roam-node-find)
  1013. ("C-c n i" . org-roam-node-insert)
  1014. :map org-mode-map
  1015. ("C-M-i" . completion-at-point)
  1016. :map org-roam-dailies-map
  1017. ("Y" . org-roam-dailies-capture-yesterday)
  1018. ("T" . org-roam-dailies-capture-tomorrow))
  1019. :bind-keymap
  1020. ("C-c n d" . org-roam-dailies-map)
  1021. :config
  1022. (require 'org-roam-dailies) ;; ensure the keymap is available
  1023. (org-roam-db-autosync-mode))
  1024. #+END_SRC
  1025. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  1026. * Programming
  1027. ** misc
  1028. #+begin_src emacs-lisp
  1029. (use-package eldoc
  1030. :diminish eldoc-mode
  1031. :defer t)
  1032. #+end_src
  1033. ** Magit / Git
  1034. :PROPERTIES:
  1035. :ID: d3589460-317f-40f6-9056-053be9ba3217
  1036. :END:
  1037. Little crash course in magit:
  1038. - magit-init to init a git project
  1039. - magit-status (C-x g) to call the status window
  1040. In status buffer:
  1041. - s stage files
  1042. - u unstage files
  1043. - U unstage all files
  1044. - a apply changes to staging
  1045. - c c commit (type commit message, then C-c C-c to commit)
  1046. - b b switch to another branch
  1047. - P u git push
  1048. - F u git pull
  1049. #+BEGIN_SRC emacs-lisp
  1050. (use-package magit
  1051. :ensure t
  1052. :defer t
  1053. :init
  1054. ; set git-path in work environment
  1055. (if (string-equal user-login-name "POH")
  1056. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1057. )
  1058. :bind (("C-x g" . magit-status)))
  1059. #+END_SRC
  1060. ** LSP
  1061. :PROPERTIES:
  1062. :ID: 06ad00e0-44a6-4bfb-ba6f-b1672811e053
  1063. :END:
  1064. Configuration for the language server protocol
  1065. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  1066. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  1067. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  1068. TODO Unterverzeichnisse wurden noch nicht getestet
  1069. #+BEGIN_SRC emacs-lisp
  1070. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  1071. (use-package lsp-mode
  1072. :defer t
  1073. :commands (lsp lsp-execute-code-action)
  1074. :custom
  1075. (lsp-auto-guess-root nil)
  1076. (lsp-prefer-flymake nil) ; use flycheck instead
  1077. (lsp-prefer-capf t)
  1078. (lsp-file-watch-threshold 5000)
  1079. (lsp-print-performance t)
  1080. (lsp-log-io nil) ; enable log only for debug
  1081. (lsp-enable-folding t) ; default, maybe evil-matchit instead for performance?
  1082. (lsp-diagnostics-modeline-scope :project)
  1083. (lsp-enable-file-watchers nil)
  1084. (lsp-session-file (concat MY--PATH_USER_LOCAL "lsp-session"))
  1085. (lsp-eslint-library-choices-file (concat MY--PATH_USER_LOCAL "lsp-eslint-choices"))
  1086. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  1087. :hook
  1088. (((python-mode
  1089. js-mode
  1090. js2-mode
  1091. typescript-mode
  1092. web-mode
  1093. ) . lsp-deferred)
  1094. (lsp-mode . lsp-enable-which-key-integration)
  1095. (lsp-mode . lsp-diagnostics-modeline-mode)
  1096. (web-mode . #'lsp-flycheck-enable)) ;; enable flycheck-lsp for web-mode locally
  1097. :config
  1098. (setq lsp-diagnostics-package :none)) ; disable flycheck-lsp for most modes
  1099. ;; (add-hook 'web-mode-hook #'lsp-flycheck-enable)) ; enable flycheck-lsp for web-mode locally
  1100. (use-package lsp-ui
  1101. :after lsp-mode
  1102. :ensure t
  1103. :defer t
  1104. :diminish
  1105. :commands lsp-ui-mode
  1106. :config
  1107. (setq lsp-ui-doc-enable t
  1108. lsp-ui-doc-header t
  1109. lsp-ui-doc-include-signature t
  1110. lsp-ui-doc-position 'top
  1111. lsp-ui-doc-border (face-foreground 'default)
  1112. lsp-ui-sideline-enable t
  1113. lsp-ui-sideline-ignore-duplicate t
  1114. lsp-ui-sideline-show-code-actions nil)
  1115. (when *sys/gui*
  1116. (setq lsp-ui-doc-use-webkit t))
  1117. ;; workaround hide mode-line of lsp-ui-imenu buffer
  1118. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  1119. (setq mode-line-format nil)))
  1120. ;;NO LONGER SUPPORTED, USE company-capf / completion-at-point
  1121. ;(use-package company-lsp
  1122. ; :requires company
  1123. ; :defer t
  1124. ; :ensure t
  1125. ; :config
  1126. ; ;;disable client-side cache because lsp server does a better job
  1127. ; (setq company-transformers nil
  1128. ; company-lsp-async t
  1129. ; company-lsp-cache-candidates nil))
  1130. #+END_SRC
  1131. ** yasnippet
  1132. :PROPERTIES:
  1133. :ID: 935d89ef-645e-4e92-966f-2fe3bebb2880
  1134. :END:
  1135. For useful snippet either install yasnippet-snippets or get them from here
  1136. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1137. #+begin_src emacs-lisp
  1138. (use-package yasnippet
  1139. :ensure t
  1140. :defer t
  1141. :diminish yas-minor-mode
  1142. :config
  1143. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1144. (yas-global-mode t)
  1145. (yas-reload-all)
  1146. (unbind-key "TAB" yas-minor-mode-map)
  1147. (unbind-key "<tab>" yas-minor-mode-map))
  1148. #+end_src
  1149. ** hippie expand
  1150. :PROPERTIES:
  1151. :ID: c55245bc-813d-4816-a0ca-b4e2e793e28b
  1152. :END:
  1153. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1154. #+begin_src emacs-lisp
  1155. (use-package hippie-exp
  1156. :defer t
  1157. :bind
  1158. ("C-<return>" . hippie-expand)
  1159. :config
  1160. (setq hippie-expand-try-functions-list
  1161. '(yas-hippie-try-expand emmet-expand-line)))
  1162. #+end_src
  1163. ** flycheck
  1164. :PROPERTIES:
  1165. :ID: 3d8f2547-c5b3-46d0-91b0-9667f9ee5c47
  1166. :END:
  1167. #+BEGIN_SRC emacs-lisp
  1168. (use-package flycheck
  1169. :ensure t
  1170. :hook
  1171. ((css-mode . flycheck-mode)
  1172. (emacs-lisp-mode . flycheck-mode)
  1173. (python-mode . flycheck-mode))
  1174. :defer 1.0
  1175. :init
  1176. (setq flycheck-emacs-lisp-load-path 'inherit)
  1177. :config
  1178. (setq-default
  1179. flycheck-check-synta-automatically '(save mode-enabled)
  1180. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1181. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1182. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1183. #+END_SRC
  1184. ** Projectile
  1185. :PROPERTIES:
  1186. :ID: a90329fd-4d36-435f-8308-a2771ac4c320
  1187. :END:
  1188. Manage projects and jump quickly between its files
  1189. #+BEGIN_SRC emacs-lisp
  1190. (use-package projectile
  1191. :ensure t
  1192. ; :defer 1.0
  1193. :diminish
  1194. :bind
  1195. (("C-c p" . projectile-command-map))
  1196. ;:preface
  1197. :init
  1198. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL "projectile-cache")
  1199. projectile-known-projects-file (concat MY--PATH_USER_LOCAL "projectile-bookmarks"))
  1200. :config
  1201. (projectile-mode)
  1202. ; (add-hook 'projectile-after-switch-project-hook #'set-workon_home)
  1203. (setq-default projectile-completion-system 'ivy
  1204. projectile-enable-caching t
  1205. projectile-mode-line '(:eval (projectile-project-name))))
  1206. ;; requires ripgrep on system for rg functions
  1207. ;(use-package counsel-projectile
  1208. ; :ensure t
  1209. ; :config (counsel-projectile-mode) (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer)
  1210. (use-package helm-projectile
  1211. :ensure t
  1212. :hook
  1213. (projectile-mode . helm-projectile))
  1214. #+END_SRC
  1215. ** smartparens
  1216. :PROPERTIES:
  1217. :ID: 997ec416-33e6-41ed-8c7c-75a7bc47d285
  1218. :END:
  1219. #+BEGIN_SRC emacs-lisp
  1220. (use-package smartparens
  1221. :ensure t
  1222. :diminish smartparens-mode
  1223. :bind
  1224. (:map smartparens-mode-map
  1225. ("C-M-f" . sp-forward-sexp)
  1226. ("C-M-b" . sp-backward-sexp)
  1227. ("C-M-a" . sp-backward-down-sexp)
  1228. ("C-M-e" . sp-up-sexp)
  1229. ("C-M-w" . sp-copy-sexp)
  1230. ("M-k" . sp-kill-sexp)
  1231. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1232. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1233. ("C-]" . sp-select-next-thing-exchange))
  1234. :config
  1235. (setq sp-show-pair-from-inside nil
  1236. sp-escape-quotes-after-insert nil)
  1237. (require 'smartparens-config))
  1238. #+END_SRC
  1239. ** lisp
  1240. :PROPERTIES:
  1241. :ID: a2bc3e08-b203-49d3-b337-fb186a14eecb
  1242. :END:
  1243. #+BEGIN_SRC emacs-lisp
  1244. (use-package elisp-mode
  1245. :defer t)
  1246. #+END_SRC
  1247. ** web
  1248. :PROPERTIES:
  1249. :ID: c0b0b4e4-2162-429f-b80d-6e5334b1290e
  1250. :END:
  1251. apt install npm
  1252. sudo npm install -g vscode-html-languageserver-bin
  1253. evtl alternativ typescript-language-server?
  1254. Unter Windows:
  1255. Hier runterladen: https://nodejs.org/dist/latest/
  1256. und in ein Verzeichnis entpacken.
  1257. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1258. PATH=P:\path\to\node;%path%
  1259. #+BEGIN_SRC emacs-lisp
  1260. (use-package web-mode
  1261. :ensure t
  1262. :defer t
  1263. :mode
  1264. ("\\.phtml\\'"
  1265. "\\.tpl\\.php\\'"
  1266. "\\.djhtml\\'"
  1267. "\\.[t]?html?\\'")
  1268. :hook
  1269. (web-mode . smartparens-mode)
  1270. :init
  1271. (if *work_remote*
  1272. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1273. :config
  1274. (setq web-mode-enable-auto-closing t
  1275. web-mode-enable-auto-pairing t))
  1276. #+END_SRC
  1277. Emmet offers snippets, similar to yasnippet.
  1278. Default completion is C-j
  1279. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1280. #+begin_src emacs-lisp
  1281. (use-package emmet-mode
  1282. :ensure t
  1283. :defer t
  1284. :hook
  1285. ((web-mode . emmet-mode)
  1286. (css-mode . emmet-mode))
  1287. :config
  1288. (unbind-key "C-<return>" emmet-mode-keymap))
  1289. #+end_src
  1290. *** JavaScript
  1291. npm install -g typescript-language-server typescript
  1292. maybe only typescript?
  1293. npm install -g prettier
  1294. #+begin_src emacs-lisp
  1295. (use-package rjsx-mode
  1296. :ensure t
  1297. :mode ("\\.js\\'"
  1298. "\\.jsx'"))
  1299. ; :config
  1300. ; (setq js2-mode-show-parse-errors nil
  1301. ; js2-mode-show-strict-warnings nil
  1302. ; js2-basic-offset 2
  1303. ; js-indent-level 2)
  1304. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1305. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1306. (use-package tide
  1307. :ensure t
  1308. :after (rjsx-mode company flycheck)
  1309. ; :hook (rjsx-mode . setup-tide-mode)
  1310. :config
  1311. (defun setup-tide-mode ()
  1312. "Setup function for tide."
  1313. (interactive)
  1314. (tide-setup)
  1315. (flycheck-mode t)
  1316. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1317. (tide-hl-identifier-mode t)))
  1318. ;; needs npm install -g prettier
  1319. (use-package prettier-js
  1320. :ensure t
  1321. :after (rjsx-mode)
  1322. :defer t
  1323. :diminish prettier-js-mode
  1324. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1325. #+end_src
  1326. ** YAML
  1327. :PROPERTIES:
  1328. :ID: 95413247-04d5-4e02-8431-06c162ec8f3b
  1329. :END:
  1330. #+begin_src emacs-lisp
  1331. (use-package yaml-mode
  1332. :if *sys/linux*
  1333. :ensure t
  1334. :defer t
  1335. :mode ("\\.yml$" . yaml-mode))
  1336. #+end_src
  1337. ** R
  1338. #+BEGIN_SRC emacs-lisp
  1339. (use-package ess
  1340. :ensure t
  1341. :defer t
  1342. :init
  1343. (if *work_remote*
  1344. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1345. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1346. #+END_SRC
  1347. ** Python
  1348. :PROPERTIES:
  1349. :ID: 8c76fcd1-c57c-48ab-8af0-aa782de6337f
  1350. :END:
  1351. Systemseitig muss python-language-server installiert sein:
  1352. apt install python3-pip python3-setuptools python3-wheel
  1353. apt install build-essential python3-dev
  1354. pip3 install 'python-language-server[all]'
  1355. Statt obiges: npm install -g pyright
  1356. für andere language servers
  1357. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1358. #+BEGIN_SRC emacs-lisp
  1359. ;(use-package lsp-python-ms
  1360. ; :if *sys/linux*
  1361. ; :ensure t
  1362. ; :defer t
  1363. ; :custom (lsp-python-ms-auto-install-server t))
  1364. (use-package lsp-pyright
  1365. :ensure t
  1366. :after lsp-mode
  1367. :defer t
  1368. :hook
  1369. (python-mode . (lambda ()
  1370. (require 'lsp-pyright)
  1371. (lsp-deferred)))
  1372. ; :custom
  1373. ; (lsp-pyright-auto-import-completions nil)
  1374. ; (lsp-pyright-typechecking-mode "off")
  1375. )
  1376. (use-package python
  1377. :if *sys/linux*
  1378. :delight "π "
  1379. :defer t
  1380. :bind (("M-[" . python-nav-backward-block)
  1381. ("M-]" . python-nav-forward-block)))
  1382. (use-package pyvenv
  1383. :if *sys/linux*
  1384. :ensure t
  1385. :defer t
  1386. :after python
  1387. :hook ((python-mode . pyvenv-mode)
  1388. (python-mode . (lambda ()
  1389. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  1390. (pyvenv-activate pyvenv-directory))
  1391. (lsp))))
  1392. :custom
  1393. (pyvenv-default-virtual-env-name "env")
  1394. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  1395. :preface
  1396. (defun find-pyvenv-directory (path)
  1397. "Check if a pyvenv directory exists."
  1398. (cond
  1399. ((not path) nil)
  1400. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  1401. ((file-directory-p path)
  1402. (or
  1403. (seq-find
  1404. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  1405. (directory-files path t))
  1406. (let ((parent (file-name-directory (directory-file-name path))))
  1407. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  1408. ;; manage multiple python version
  1409. ;; needs to be installed on system
  1410. ; (use-package pyenv-mode
  1411. ; :ensure t
  1412. ; :after python
  1413. ; :hook ((python-mode . pyenv-mode)
  1414. ; (projectile-switch-project . projectile-pyenv-mode-set))
  1415. ; :custom (pyenv-mode-set "3.8.5")
  1416. ; :preface
  1417. ; (defun projectile-pyenv-mode-set ()
  1418. ; "Set pyenv version matching project name."
  1419. ; (let ((project (projectile-project-name)))
  1420. ; (if (member project (pyenv-mode-versions))
  1421. ; (pyenv-mode-set project)
  1422. ; (pyenv-mode-unset)))))
  1423. ;)
  1424. #+END_SRC
  1425. * beancount
  1426. ** Installation
  1427. :PROPERTIES:
  1428. :ID: 2c329043-b7a9-437d-a5cf-f2ad6514be91
  1429. :END:
  1430. #+BEGIN_SRC shell :tangle no
  1431. sudo su
  1432. cd /opt
  1433. python3 -m venv beancount
  1434. source ./beancount/bin/activate
  1435. pip3 install wheel
  1436. pip3 install beancount
  1437. sleep 100
  1438. echo "shell running!"
  1439. deactivate
  1440. #+END_SRC
  1441. #+BEGIN_SRC emacs-lisp
  1442. (use-package beancount
  1443. :if *sys/linux*
  1444. :load-path "user-global/elisp"
  1445. ; :ensure t
  1446. :defer t
  1447. :mode
  1448. ("\\.beancount$" . beancount-mode)
  1449. :hook
  1450. (beancount-mode . me/beancount-company)
  1451. :init
  1452. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1453. :config
  1454. (defun me/beancount-company ()
  1455. (set (make-local-variable 'company-backends)
  1456. '(company-beancount)))
  1457. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1458. #+END_SRC
  1459. To support org-babel, check if it can find the symlink to ob-beancount.el
  1460. #+BEGIN_SRC shell :tangle no
  1461. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1462. beansym="$orgpath/ob-beancount.el
  1463. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1464. if [ -h "$beansym" ]
  1465. then
  1466. echo "$beansym found"
  1467. elif [ -e "$bean" ]
  1468. then
  1469. echo "creating symlink"
  1470. ln -s "$bean" "$beansym"
  1471. else
  1472. echo "$bean not found, symlink creation aborted"
  1473. fi
  1474. #+END_SRC
  1475. Fava is strongly recommended.
  1476. #+BEGIN_SRC shell :tangle no
  1477. cd /opt
  1478. python3 -m venv fava
  1479. source ./fava/bin/activate
  1480. pip3 install wheel
  1481. pip3 install fava
  1482. deactivate
  1483. #+END_SRC
  1484. Start fava with fava my_file.beancount
  1485. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1486. Beancount-mode can start fava and open the URL right away.
  1487. * Stuff after everything else
  1488. Set garbage collector to a smaller value to let it kick in faster.
  1489. Maybe a problem on Windows?
  1490. #+begin_src emacs-lisp
  1491. ;(setq gc-cons-threshold (* 2 1000 1000))
  1492. #+end_src