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.

1588 lines
45 KiB

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