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.

1648 lines
46 KiB

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