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.

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