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.

1595 lines
46 KiB

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