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