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.

1628 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. (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. * Selectrum & Co.
  501. Uses default features of emacs instead of bringing a new framework in like helm or counsel
  502. #+begin_src emacs-lisp
  503. ;; either selectrum or vertico
  504. (use-package selectrum
  505. :ensure t
  506. :config
  507. (selectrum-mode)
  508. )
  509. ;; as of 2021-10-29 debian emacs 27.1 seems to cause error
  510. ;; error in post-command-hook (vertico--exhibit): (wrong-type-argument .....)
  511. ;; see https://github.com/minad/vertico/issues/41
  512. ;(use-package vertico
  513. ; :ensure t
  514. ; :init
  515. ; (vertico-mode))
  516. ;; orderless orders by recency
  517. ;; prescient orders by frequency
  518. ;; both combined order by frecency (most recent first, then by frequency, then by length)
  519. (use-package orderless
  520. :ensure t
  521. :config
  522. ;; optional performance optimizaion
  523. ;; by highlighting only visible candidates
  524. (setq orderless-skip-highlighting (lambda () selectrum-is-active)
  525. selectrum-highlight-candidates-function #'orderless-highlight-matches
  526. completion-category-defaults nil
  527. completion-category-overrides '((file (styles . (partial-completion)))))
  528. :custom
  529. (completion-styles '(orderless))
  530. )
  531. (use-package selectrum-prescient
  532. :ensure t
  533. :config
  534. (setq selectrum-prescient-enable-filtering nil) ; only if used with orderless
  535. (selectrum-prescient-mode)
  536. (prescient-persist-mode)
  537. )
  538. (use-package consult
  539. :ensure t
  540. :bind
  541. (("C-x C-r" . consult-recent-file)
  542. ("C-x b" . consult-buffer)
  543. ("C-s" . consult-line))
  544. :config
  545. ;; disable preview for some commands and buffers
  546. ;; and enable it by M-.
  547. ;; see https://github.com/minad/consult#use-package-example
  548. (consult-customize
  549. consult-theme
  550. :preview-key '(debounce 0.2 any)
  551. consult-ripgrep consult-git-grep consult-grep
  552. consult-bookmark consult-recent-file consult-xref
  553. consult--source-file consult--source-project-file consult--source-bookmark
  554. :preview-key (kbd "M-."))
  555. )
  556. ;; shows descriptions in M-x
  557. (use-package marginalia
  558. :ensure t
  559. :config
  560. (marginalia-mode)
  561. :custom
  562. ;; switch by 'marginalia-cycle
  563. (marginalia-annotators '(marginalia-annotators-heavy
  564. marginalia-annotators-light
  565. nil))
  566. )
  567. ;; do stuff on minibuffer results
  568. (use-package embark
  569. :ensure t
  570. :bind
  571. (("C-S-a" . embark-act)
  572. ("C-h B" . embark-bindings))
  573. :init
  574. (setq prefix-help-command #'embark-prefix-help-command)
  575. :config
  576. ;; for selectrum
  577. ;; (defun current-candidate+category ()
  578. ;; (when selectrum-is-active
  579. ;; (cons (selectrum--get-meta 'category)
  580. ;; (selectrum-get-current-candidate))))
  581. ;; (add-hook 'embark-target-finders #'current-candidate+category)
  582. ;; (defun current-candidates+category ()
  583. ;; (when selectrum-is-active
  584. ;; (cons (selectrum--get-meta 'category)
  585. ;; (selectrum-get-current-candidates
  586. ;; ;; pass relative file names for dired.
  587. ;; minibuffer-completing-file-name))))
  588. ;; (add-hook 'embark-candidate-collectors #'current-candidates+category)
  589. ;; ;; no unnecessary computation delay after injection.
  590. ;; (add-hook 'embark-setup-hook 'selectrum-set-selected-candidate)
  591. ;; hide modeline of the embark live/completions buffers
  592. (add-to-list 'display-buffer-alist
  593. '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
  594. nil
  595. (window-parameters (mode-line-format . none))))
  596. )
  597. (use-package embark-consult
  598. :ensure t
  599. :after (embark consult)
  600. :demand t
  601. :hook
  602. (embark-collect-mode . embark-consult-preview-minor-mode))
  603. #+end_src
  604. * Helm
  605. As an alternative if I'm not happy with selectrum & co
  606. #+begin_src emacs-lisp
  607. (use-package helm
  608. :ensure t
  609. :hook
  610. (helm-mode . helm-autoresize-mode)
  611. ;; :bind
  612. ;; (("M-x" . helm-M-x)
  613. ;; ("C-s" . helm-occur)
  614. ;; ("C-x C-f" . helm-find-files)
  615. ;; ("C-x C-b" . helm-buffers-list)
  616. ;; ("C-x b" . helm-buffers-list)
  617. ;; ("C-x C-r" . helm-recentf)
  618. ;; ("C-x C-i" . helm-imenu))
  619. :config
  620. (helm-mode)
  621. :custom
  622. (helm-split-window-inside-p t) ;; open helm buffer inside current window
  623. (helm-move-to-line-cycle-in-source t)
  624. (helm-echo-input-in-header-line t)
  625. (helm-autoresize-max-height 20)
  626. (helm-autoresize-min-height 5)
  627. )
  628. #+end_src
  629. * ivy / counsel / swiper
  630. :PROPERTIES:
  631. :ID: 55c74ba9-7761-4545-8ddd-087d6ee33e4b
  632. :END:
  633. +BEGIN_SRC emacs-lisp
  634. ; (require 'ivy)
  635. (use-package ivy
  636. :ensure t
  637. :diminish
  638. (ivy-mode . "")
  639. :defer t
  640. :init
  641. (ivy-mode 1)
  642. :bind
  643. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  644. :config
  645. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  646. ivy-height 20 ;; height of ivy window
  647. ivy-count-format "%d/%d" ;; current and total number
  648. ivy-re-builders-alist ;; regex replaces spaces with *
  649. '((t . ivy--regex-plus))))
  650. ; make counsel-M-x more descriptive
  651. (use-package ivy-rich
  652. :ensure t
  653. :defer t
  654. :init
  655. (ivy-rich-mode 1))
  656. (use-package counsel
  657. :ensure t
  658. :defer t
  659. :bind
  660. (("M-x" . counsel-M-x)
  661. ("C-x C-f" . counsel-find-file)
  662. ("C-x C-r" . counsel-recentf)
  663. ("C-x b" . counsel-switch-buffer)
  664. ("C-c C-f" . counsel-git)
  665. ("C-c h f" . counsel-describe-function)
  666. ("C-c h v" . counsel-describe-variable)
  667. ("M-i" . counsel-imenu)))
  668. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  669. ; ("C-r" . 'counsel-minibuffer-history)))
  670. (use-package swiper
  671. :ensure t
  672. :bind
  673. ("C-s" . swiper))
  674. (use-package ivy-hydra
  675. :ensure t)
  676. +END_SRC
  677. * misc
  678. #+begin_src emacs-lisp
  679. (use-package autorevert
  680. :diminish auto-revert-mode)
  681. #+end_src
  682. * company
  683. :PROPERTIES:
  684. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  685. :END:
  686. #+BEGIN_SRC emacs-lisp
  687. (use-package company
  688. :defer 1
  689. :diminish
  690. :defer t
  691. :bind
  692. (("C-<tab>" . company-complete)
  693. :map company-active-map
  694. ("RET" . nil)
  695. ([return] . nil)
  696. ("TAB" . company-complete-selection)
  697. ([tab] . company-complete-selection)
  698. ("<right>" . company-complete-common)
  699. ("<escape>" . company-abort))
  700. :hook
  701. (after-init . global-company-mode)
  702. (emacs-lisp-mode . me/company-elisp)
  703. (org-mode . me/company-org)
  704. :config
  705. (defun me/company-elisp ()
  706. (message "set up company for elisp")
  707. (set (make-local-variable 'company-backends)
  708. '(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp
  709. company-yasnippet
  710. company-dabbrev-code
  711. company-files)))
  712. (defun me/company-org ()
  713. (set (make-local-variable 'company-backends)
  714. '(company-capf company-files))
  715. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  716. (message "setup company for org"))
  717. (setq company-idle-delay .2
  718. company-minimum-prefix-length 1
  719. company-require-match nil
  720. company-show-numbers t
  721. company-tooltip-align-annotations t))
  722. (use-package company-statistics
  723. :ensure t
  724. :after company
  725. :defer t
  726. :init
  727. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  728. :config
  729. (company-statistics-mode 1))
  730. (use-package company-dabbrev
  731. :ensure nil
  732. :after company
  733. :defer t
  734. :config
  735. (setq-default company-dabbrev-downcase nil))
  736. ;; adds a info box right of the cursor with doc of the function
  737. (use-package company-box
  738. :ensure t
  739. :diminish
  740. :defer t
  741. :hook
  742. (company-mode . company-box-mode))
  743. ; :init
  744. ; (add-hook 'company-mode-hook 'company-box-mode))
  745. #+END_SRC
  746. * orgmode
  747. ** org
  748. :PROPERTIES:
  749. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  750. :END:
  751. #+BEGIN_SRC emacs-lisp
  752. (use-package org
  753. :ensure org-plus-contrib
  754. :mode (("\.org$" . org-mode))
  755. :diminish org-indent-mode
  756. :defer t
  757. :hook
  758. (org-mode . org-indent-mode)
  759. (org-source-mode . smartparens-mode)
  760. ; :init
  761. ; (add-hook 'org-mode-hook 'company/org-mode-hook)
  762. ; (add-hook 'org-src-mode-hook 'smartparens-mode)
  763. ; (add-hook 'org-mode-hook 'org-indent-mode)
  764. :config
  765. (defun me/org-company ()
  766. (set (make-local-variable 'company-backends)
  767. '(company-capf company-files))
  768. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  769. (message "company/org-mode-hook"))
  770. (setq org-modules (quote (org-id
  771. org-habit
  772. org-tempo ;; easy templates
  773. )))
  774. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  775. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  776. (concat MY--PATH_ORG_FILES "projects.org")
  777. (concat MY--PATH_ORG_FILES "tasks.org")))
  778. (when *sys/linux*
  779. (nconc org-agenda-files
  780. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  781. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  782. org-log-into-drawer "LOGBOOK")
  783. ;; some display customizations
  784. (setq org-pretty-entities t
  785. org-startup-truncated t
  786. org-startup-align-all-tables t)
  787. ;; some source code blocks customizations
  788. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  789. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  790. org-src-preserve-indentation t ;; no extra indentation
  791. org-src-tab-acts-natively t)
  792. (setq org-log-done 'time)) ;; create timestamp when task is done
  793. #+END_SRC
  794. ** languages
  795. :PROPERTIES:
  796. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  797. :END:
  798. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  799. +BEGIN_SRC emacs-lisp
  800. (org-babel-do-load-languages
  801. 'org-babel-load-languages
  802. '((emacs-lisp . t)
  803. (gnuplot . t)
  804. (js . t)
  805. (latex . t)
  806. (lisp . t)
  807. (python . t)
  808. (shell . t)
  809. (sqlite . t)
  810. (org . t)
  811. (R . t)
  812. (scheme . t)))
  813. (setq org-confirm-babel-evaluate nil)
  814. +END_SRC
  815. Another setup, because org-babel-do-load-languages requires eager loading
  816. #+begin_src emacs-lisp
  817. (use-package ob-org
  818. :defer t
  819. :ensure org-plus-contrib
  820. :commands
  821. (org-babel-execute:org
  822. org-babel-expand-body:org))
  823. (use-package ob-python
  824. :defer t
  825. :ensure org-plus-contrib
  826. :commands (org-babel-execute:python))
  827. (use-package ob-js
  828. :defer t
  829. :ensure org-plus-contrib
  830. :commands (org-babel-execute:js))
  831. (use-package ob-shell
  832. :defer t
  833. :ensure org-plus-contrib
  834. :commands
  835. (org-babel-execute:sh
  836. org-babel-expand-body:sh
  837. org-babel-execute:bash
  838. org-babel-expand-body:bash))
  839. (use-package ob-emacs-lisp
  840. :defer t
  841. :ensure org-plus-contrib
  842. :commands
  843. (org-babel-execute:emacs-lisp
  844. org-babel-expand-body:emacs-lisp))
  845. (use-package ob-lisp
  846. :defer t
  847. :ensure org-plus-contrib
  848. :commands
  849. (org-babel-execute:lisp
  850. org-babel-expand-body:lisp))
  851. (use-package ob-gnuplot
  852. :defer t
  853. :ensure org-plus-contrib
  854. :commands
  855. (org-babel-execute:gnuplot
  856. org-babel-expand-body:gnuplot))
  857. (use-package ob-sqlite
  858. :defer t
  859. :ensure org-plus-contrib
  860. :commands
  861. (org-babel-execute:sqlite
  862. org-babel-expand-body:sqlite))
  863. (use-package ob-latex
  864. :defer t
  865. :ensure org-plus-contrib
  866. :commands
  867. (org-babel-execute:latex
  868. org-babel-expand-body:latex))
  869. (use-package ob-R
  870. :defer t
  871. :ensure org-plus-contrib
  872. :commands
  873. (org-babel-execute:R
  874. org-babel-expand-body:R))
  875. (use-package ob-scheme
  876. :defer t
  877. :ensure org-plus-contrib
  878. :commands
  879. (org-babel-execute:scheme
  880. org-babel-expand-body:scheme))
  881. #+end_src
  882. ** habits
  883. :PROPERTIES:
  884. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  885. :END:
  886. #+BEGIN_SRC emacs-lisp
  887. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  888. ;; (add-to-list 'org-modules "org-habit")
  889. (setq org-habit-graph-column 80
  890. org-habit-preceding-days 30
  891. org-habit-following-days 7
  892. org-habit-show-habits-only-for-today nil)
  893. #+END_SRC
  894. ** org-id
  895. :PROPERTIES:
  896. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  897. :END:
  898. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  899. #+BEGIN_SRC emacs-lisp
  900. ;; (use-package org-id
  901. ;; :config
  902. ;; (setq org-id-link-to-org-use-id t)
  903. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  904. #+END_SRC
  905. ** org-agenda
  906. :PROPERTIES:
  907. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  908. :END:
  909. Custom keywords, depending on environment
  910. #+BEGIN_SRC emacs-lisp
  911. (when *work_remote*
  912. (setq org-todo-keywords
  913. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  914. #+END_SRC
  915. Add some key bindings
  916. #+BEGIN_SRC emacs-lisp
  917. (bind-key "C-c l" 'org-store-link)
  918. (bind-key "C-c c" 'org-capture)
  919. (bind-key "C-c a" 'org-agenda)
  920. #+END_SRC
  921. Sort agenda by deadline and priority
  922. #+BEGIN_SRC emacs-lisp
  923. (setq org-agenda-sorting-strategy
  924. (quote
  925. ((agenda deadline-up priority-down)
  926. (todo priority-down category-keep)
  927. (tags priority-down category-keep)
  928. (search category-keep))))
  929. #+END_SRC
  930. Customize the org agenda
  931. #+BEGIN_SRC emacs-lisp
  932. (defun me--org-skip-subtree-if-priority (priority)
  933. "Skip an agenda subtree if it has a priority of PRIORITY.
  934. PRIORITY may be one of the characters ?A, ?B, or ?C."
  935. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  936. (pri-value (* 1000 (- org-lowest-priority priority)))
  937. (pri-current (org-get-priority (thing-at-point 'line t))))
  938. (if (= pri-value pri-current)
  939. subtree-end
  940. nil)))
  941. (setq org-agenda-custom-commands
  942. '(("c" "Simple agenda view"
  943. ((tags "PRIORITY=\"A\""
  944. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  945. (org-agenda-overriding-header "Hohe Priorität:")))
  946. (agenda ""
  947. ((org-agenda-span 7)
  948. (org-agenda-start-on-weekday nil)
  949. (org-agenda-overriding-header "Nächste 7 Tage:")))
  950. (alltodo ""
  951. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  952. (org-agenda-skip-if nil '(scheduled deadline))))
  953. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  954. #+END_SRC
  955. ** *TODO*
  956. org-super-agenda
  957. ** org-caldav
  958. :PROPERTIES:
  959. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  960. :END:
  961. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  962. #+BEGIN_SRC emacs-lisp
  963. ;;(use-package org-caldav
  964. ;; :ensure t
  965. ;; :config
  966. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  967. ;; org-caldav-calendar-id "orgmode"
  968. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  969. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  970. #+END_SRC
  971. ** journal
  972. :PROPERTIES:
  973. :ID: a1951e18-d862-4198-9652-016e979053c8
  974. :END:
  975. [[https://github.com/bastibe/org-journal][Source]]
  976. #+BEGIN_SRC emacs-lisp
  977. (use-package org-journal
  978. :if *sys/linux*
  979. :ensure t
  980. :defer t
  981. :config
  982. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  983. (when (and (boundp 'org-journal-dir)
  984. (boundp 'org-journal-enable-agenda-integration))
  985. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  986. org-journal-enable-agenda-integration t)))
  987. #+END_SRC
  988. * Programming
  989. ** misc
  990. #+begin_src emacs-lisp
  991. (use-package eldoc
  992. :diminish eldoc-mode
  993. :defer t)
  994. #+end_src
  995. ** Magit / Git
  996. :PROPERTIES:
  997. :ID: d3589460-317f-40f6-9056-053be9ba3217
  998. :END:
  999. Little crash course in magit:
  1000. - magit-init to init a git project
  1001. - magit-status (C-x g) to call the status window
  1002. In status buffer:
  1003. - s stage files
  1004. - u unstage files
  1005. - U unstage all files
  1006. - a apply changes to staging
  1007. - c c commit (type commit message, then C-c C-c to commit)
  1008. - b b switch to another branch
  1009. - P u git push
  1010. - F u git pull
  1011. #+BEGIN_SRC emacs-lisp
  1012. (use-package magit
  1013. :ensure t
  1014. :defer t
  1015. :init
  1016. ; set git-path in work environment
  1017. (if (string-equal user-login-name "POH")
  1018. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  1019. )
  1020. :bind (("C-x g" . magit-status)))
  1021. #+END_SRC
  1022. ** LSP
  1023. :PROPERTIES:
  1024. :ID: 06ad00e0-44a6-4bfb-ba6f-b1672811e053
  1025. :END:
  1026. Configuration for the language server protocol
  1027. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  1028. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  1029. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  1030. TODO Unterverzeichnisse wurden noch nicht getestet
  1031. #+BEGIN_SRC emacs-lisp
  1032. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  1033. (use-package lsp-mode
  1034. :defer t
  1035. :commands (lsp lsp-execute-code-action)
  1036. :custom
  1037. (lsp-auto-guess-root nil)
  1038. (lsp-prefer-flymake nil) ; use flycheck instead
  1039. (lsp-prefer-capf t)
  1040. (lsp-file-watch-threshold 5000)
  1041. (lsp-print-performance t)
  1042. (lsp-log-io nil) ; enable log only for debug
  1043. (lsp-enable-folding t) ; default, maybe evil-matchit instead for performance?
  1044. (lsp-diagnostics-modeline-scope :project)
  1045. (lsp-enable-file-watchers nil)
  1046. (lsp-session-file (concat MY--PATH_USER_LOCAL "lsp-session"))
  1047. (lsp-eslint-library-choices-file (concat MY--PATH_USER_LOCAL "lsp-eslint-choices"))
  1048. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  1049. :hook
  1050. (((python-mode
  1051. js-mode
  1052. js2-mode
  1053. typescript-mode
  1054. web-mode
  1055. ) . lsp-deferred)
  1056. (lsp-mode . lsp-enable-which-key-integration)
  1057. (lsp-mode . lsp-diagnostics-modeline-mode)
  1058. (web-mode . #'lsp-flycheck-enable)) ;; enable flycheck-lsp for web-mode locally
  1059. :config
  1060. (setq lsp-diagnostics-package :none)) ; disable flycheck-lsp for most modes
  1061. ;; (add-hook 'web-mode-hook #'lsp-flycheck-enable)) ; enable flycheck-lsp for web-mode locally
  1062. (use-package lsp-ui
  1063. :after lsp-mode
  1064. :ensure t
  1065. :defer t
  1066. :diminish
  1067. :commands lsp-ui-mode
  1068. :config
  1069. (setq lsp-ui-doc-enable t
  1070. lsp-ui-doc-header t
  1071. lsp-ui-doc-include-signature t
  1072. lsp-ui-doc-position 'top
  1073. lsp-ui-doc-border (face-foreground 'default)
  1074. lsp-ui-sideline-enable t
  1075. lsp-ui-sideline-ignore-duplicate t
  1076. lsp-ui-sideline-show-code-actions nil)
  1077. (when *sys/gui*
  1078. (setq lsp-ui-doc-use-webkit t))
  1079. ;; workaround hide mode-line of lsp-ui-imenu buffer
  1080. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  1081. (setq mode-line-format nil)))
  1082. ;;NO LONGER SUPPORTED, USE company-capf / completion-at-point
  1083. ;(use-package company-lsp
  1084. ; :requires company
  1085. ; :defer t
  1086. ; :ensure t
  1087. ; :config
  1088. ; ;;disable client-side cache because lsp server does a better job
  1089. ; (setq company-transformers nil
  1090. ; company-lsp-async t
  1091. ; company-lsp-cache-candidates nil))
  1092. #+END_SRC
  1093. ** yasnippet
  1094. :PROPERTIES:
  1095. :ID: 935d89ef-645e-4e92-966f-2fe3bebb2880
  1096. :END:
  1097. For useful snippet either install yasnippet-snippets or get them from here
  1098. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1099. #+begin_src emacs-lisp
  1100. (use-package yasnippet
  1101. :ensure t
  1102. :defer t
  1103. :diminish yas-minor-mode
  1104. :config
  1105. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1106. (yas-global-mode t)
  1107. (yas-reload-all)
  1108. (unbind-key "TAB" yas-minor-mode-map)
  1109. (unbind-key "<tab>" yas-minor-mode-map))
  1110. #+end_src
  1111. ** hippie expand
  1112. :PROPERTIES:
  1113. :ID: c55245bc-813d-4816-a0ca-b4e2e793e28b
  1114. :END:
  1115. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1116. #+begin_src emacs-lisp
  1117. (use-package hippie-exp
  1118. :defer t
  1119. :bind
  1120. ("C-<return>" . hippie-expand)
  1121. :config
  1122. (setq hippie-expand-try-functions-list
  1123. '(yas-hippie-try-expand emmet-expand-line)))
  1124. #+end_src
  1125. ** flycheck
  1126. :PROPERTIES:
  1127. :ID: 3d8f2547-c5b3-46d0-91b0-9667f9ee5c47
  1128. :END:
  1129. #+BEGIN_SRC emacs-lisp
  1130. (use-package flycheck
  1131. :ensure t
  1132. :hook
  1133. ((css-mode . flycheck-mode)
  1134. (emacs-lisp-mode . flycheck-mode)
  1135. (python-mode . flycheck-mode))
  1136. :defer 1.0
  1137. :init
  1138. (setq flycheck-emacs-lisp-load-path 'inherit)
  1139. :config
  1140. (setq-default
  1141. flycheck-check-synta-automatically '(save mode-enabled)
  1142. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1143. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1144. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1145. #+END_SRC
  1146. ** Projectile
  1147. :PROPERTIES:
  1148. :ID: a90329fd-4d36-435f-8308-a2771ac4c320
  1149. :END:
  1150. Manage projects and jump quickly between its files
  1151. #+BEGIN_SRC emacs-lisp
  1152. (use-package projectile
  1153. :ensure t
  1154. ; :defer 1.0
  1155. :diminish
  1156. :bind
  1157. (("C-c p" . projectile-command-map))
  1158. ;:preface
  1159. :init
  1160. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL "projectile-cache")
  1161. projectile-known-projects-file (concat MY--PATH_USER_LOCAL "projectile-bookmarks"))
  1162. :config
  1163. (projectile-mode)
  1164. ; (add-hook 'projectile-after-switch-project-hook #'set-workon_home)
  1165. (setq-default projectile-completion-system 'ivy
  1166. projectile-enable-caching t
  1167. projectile-mode-line '(:eval (projectile-project-name))))
  1168. ;; requires ripgrep on system for rg functions
  1169. ;(use-package counsel-projectile
  1170. ; :ensure t
  1171. ; :config (counsel-projectile-mode) (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer)
  1172. (use-package helm-projectile
  1173. :ensure t
  1174. :hook
  1175. (projectile-mode . helm-projectile))
  1176. #+END_SRC
  1177. ** smartparens
  1178. :PROPERTIES:
  1179. :ID: 997ec416-33e6-41ed-8c7c-75a7bc47d285
  1180. :END:
  1181. #+BEGIN_SRC emacs-lisp
  1182. (use-package smartparens
  1183. :ensure t
  1184. :diminish smartparens-mode
  1185. :bind
  1186. (:map smartparens-mode-map
  1187. ("C-M-f" . sp-forward-sexp)
  1188. ("C-M-b" . sp-backward-sexp)
  1189. ("C-M-a" . sp-backward-down-sexp)
  1190. ("C-M-e" . sp-up-sexp)
  1191. ("C-M-w" . sp-copy-sexp)
  1192. ("M-k" . sp-kill-sexp)
  1193. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1194. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1195. ("C-]" . sp-select-next-thing-exchange))
  1196. :config
  1197. (setq sp-show-pair-from-inside nil
  1198. sp-escape-quotes-after-insert nil)
  1199. (require 'smartparens-config))
  1200. #+END_SRC
  1201. ** lisp
  1202. :PROPERTIES:
  1203. :ID: a2bc3e08-b203-49d3-b337-fb186a14eecb
  1204. :END:
  1205. #+BEGIN_SRC emacs-lisp
  1206. (use-package elisp-mode
  1207. :defer t)
  1208. #+END_SRC
  1209. ** web
  1210. :PROPERTIES:
  1211. :ID: c0b0b4e4-2162-429f-b80d-6e5334b1290e
  1212. :END:
  1213. apt install npm
  1214. sudo npm install -g vscode-html-languageserver-bin
  1215. evtl alternativ typescript-language-server?
  1216. Unter Windows:
  1217. Hier runterladen: https://nodejs.org/dist/latest/
  1218. und in ein Verzeichnis entpacken.
  1219. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1220. PATH=P:\path\to\node;%path%
  1221. #+BEGIN_SRC emacs-lisp
  1222. (use-package web-mode
  1223. :ensure t
  1224. :defer t
  1225. :mode
  1226. ("\\.phtml\\'"
  1227. "\\.tpl\\.php\\'"
  1228. "\\.djhtml\\'"
  1229. "\\.[t]?html?\\'")
  1230. :hook
  1231. (web-mode . smartparens-mode)
  1232. :init
  1233. (if *work_remote*
  1234. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1235. :config
  1236. (setq web-mode-enable-auto-closing t
  1237. web-mode-enable-auto-pairing t))
  1238. #+END_SRC
  1239. Emmet offers snippets, similar to yasnippet.
  1240. Default completion is C-j
  1241. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1242. #+begin_src emacs-lisp
  1243. (use-package emmet-mode
  1244. :ensure t
  1245. :defer t
  1246. :hook
  1247. ((web-mode . emmet-mode)
  1248. (css-mode . emmet-mode))
  1249. :config
  1250. (unbind-key "C-<return>" emmet-mode-keymap))
  1251. #+end_src
  1252. *** JavaScript
  1253. npm install -g typescript-language-server typescript
  1254. maybe only typescript?
  1255. npm install -g prettier
  1256. #+begin_src emacs-lisp
  1257. (use-package rjsx-mode
  1258. :ensure t
  1259. :mode ("\\.js\\'"
  1260. "\\.jsx'"))
  1261. ; :config
  1262. ; (setq js2-mode-show-parse-errors nil
  1263. ; js2-mode-show-strict-warnings nil
  1264. ; js2-basic-offset 2
  1265. ; js-indent-level 2)
  1266. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1267. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1268. (use-package tide
  1269. :ensure t
  1270. :after (rjsx-mode company flycheck)
  1271. ; :hook (rjsx-mode . setup-tide-mode)
  1272. :config
  1273. (defun setup-tide-mode ()
  1274. "Setup function for tide."
  1275. (interactive)
  1276. (tide-setup)
  1277. (flycheck-mode t)
  1278. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1279. (tide-hl-identifier-mode t)))
  1280. ;; needs npm install -g prettier
  1281. (use-package prettier-js
  1282. :ensure t
  1283. :after (rjsx-mode)
  1284. :defer t
  1285. :diminish prettier-js-mode
  1286. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1287. #+end_src
  1288. ** YAML
  1289. :PROPERTIES:
  1290. :ID: 95413247-04d5-4e02-8431-06c162ec8f3b
  1291. :END:
  1292. #+begin_src emacs-lisp
  1293. (use-package yaml-mode
  1294. :if *sys/linux*
  1295. :ensure t
  1296. :defer t
  1297. :mode ("\\.yml$" . yaml-mode))
  1298. #+end_src
  1299. ** R
  1300. #+BEGIN_SRC emacs-lisp
  1301. (use-package ess
  1302. :ensure t
  1303. :defer t
  1304. :init
  1305. (if *work_remote*
  1306. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1307. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1308. #+END_SRC
  1309. ** Python
  1310. :PROPERTIES:
  1311. :ID: 8c76fcd1-c57c-48ab-8af0-aa782de6337f
  1312. :END:
  1313. Systemseitig muss python-language-server installiert sein:
  1314. apt install python3-pip python3-setuptools python3-wheel
  1315. apt install build-essential python3-dev
  1316. pip3 install 'python-language-server[all]'
  1317. Statt obiges: npm install -g pyright
  1318. für andere language servers
  1319. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1320. #+BEGIN_SRC emacs-lisp
  1321. ;(use-package lsp-python-ms
  1322. ; :if *sys/linux*
  1323. ; :ensure t
  1324. ; :defer t
  1325. ; :custom (lsp-python-ms-auto-install-server t))
  1326. (use-package lsp-pyright
  1327. :ensure t
  1328. :after lsp-mode
  1329. :defer t
  1330. :hook
  1331. (python-mode . (lambda ()
  1332. (require 'lsp-pyright)
  1333. (lsp-deferred)))
  1334. ; :custom
  1335. ; (lsp-pyright-auto-import-completions nil)
  1336. ; (lsp-pyright-typechecking-mode "off")
  1337. )
  1338. (use-package python
  1339. :if *sys/linux*
  1340. :delight "π "
  1341. :defer t
  1342. :bind (("M-[" . python-nav-backward-block)
  1343. ("M-]" . python-nav-forward-block)))
  1344. (use-package pyvenv
  1345. :if *sys/linux*
  1346. :ensure t
  1347. :defer t
  1348. :after python
  1349. :hook ((python-mode . pyvenv-mode)
  1350. (python-mode . (lambda ()
  1351. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  1352. (pyvenv-activate pyvenv-directory))
  1353. (lsp))))
  1354. :custom
  1355. (pyvenv-default-virtual-env-name "env")
  1356. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  1357. :preface
  1358. (defun find-pyvenv-directory (path)
  1359. "Check if a pyvenv directory exists."
  1360. (cond
  1361. ((not path) nil)
  1362. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  1363. ((file-directory-p path)
  1364. (or
  1365. (seq-find
  1366. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  1367. (directory-files path t))
  1368. (let ((parent (file-name-directory (directory-file-name path))))
  1369. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  1370. ;; manage multiple python version
  1371. ;; needs to be installed on system
  1372. ; (use-package pyenv-mode
  1373. ; :ensure t
  1374. ; :after python
  1375. ; :hook ((python-mode . pyenv-mode)
  1376. ; (projectile-switch-project . projectile-pyenv-mode-set))
  1377. ; :custom (pyenv-mode-set "3.8.5")
  1378. ; :preface
  1379. ; (defun projectile-pyenv-mode-set ()
  1380. ; "Set pyenv version matching project name."
  1381. ; (let ((project (projectile-project-name)))
  1382. ; (if (member project (pyenv-mode-versions))
  1383. ; (pyenv-mode-set project)
  1384. ; (pyenv-mode-unset)))))
  1385. ;)
  1386. #+END_SRC
  1387. * beancount
  1388. ** Installation
  1389. :PROPERTIES:
  1390. :ID: 2c329043-b7a9-437d-a5cf-f2ad6514be91
  1391. :END:
  1392. #+BEGIN_SRC shell :tangle no
  1393. sudo su
  1394. cd /opt
  1395. python3 -m venv beancount
  1396. source ./beancount/bin/activate
  1397. pip3 install wheel
  1398. pip3 install beancount
  1399. sleep 100
  1400. echo "shell running!"
  1401. deactivate
  1402. #+END_SRC
  1403. #+BEGIN_SRC emacs-lisp
  1404. (use-package beancount
  1405. :if *sys/linux*
  1406. :load-path "user-global/elisp"
  1407. ; :ensure t
  1408. :defer t
  1409. :mode
  1410. ("\\.beancount$" . beancount-mode)
  1411. :hook
  1412. (beancount-mode . me/beancount-company)
  1413. :init
  1414. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1415. :config
  1416. (defun me/beancount-company ()
  1417. (set (make-local-variable 'company-backends)
  1418. '(company-beancount)))
  1419. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1420. #+END_SRC
  1421. To support org-babel, check if it can find the symlink to ob-beancount.el
  1422. #+BEGIN_SRC shell :tangle no
  1423. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1424. beansym="$orgpath/ob-beancount.el
  1425. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1426. if [ -h "$beansym" ]
  1427. then
  1428. echo "$beansym found"
  1429. elif [ -e "$bean" ]
  1430. then
  1431. echo "creating symlink"
  1432. ln -s "$bean" "$beansym"
  1433. else
  1434. echo "$bean not found, symlink creation aborted"
  1435. fi
  1436. #+END_SRC
  1437. Fava is strongly recommended.
  1438. #+BEGIN_SRC shell :tangle no
  1439. cd /opt
  1440. python3 -m venv fava
  1441. source ./fava/bin/activate
  1442. pip3 install wheel
  1443. pip3 install fava
  1444. deactivate
  1445. #+END_SRC
  1446. Start fava with fava my_file.beancount
  1447. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1448. Beancount-mode can start fava and open the URL right away.
  1449. * Stuff after everything else
  1450. Set garbage collector to a smaller value to let it kick in faster.
  1451. Maybe a problem on Windows?
  1452. #+begin_src emacs-lisp
  1453. ;(setq gc-cons-threshold (* 2 1000 1000))
  1454. #+end_src