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.

1594 lines
46 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. :ensure t
  935. :defer t
  936. :init
  937. (setq org-roam-v2-ack t)
  938. :config
  939. (require 'org-roam-dailies) ;; ensure the keymap is available
  940. (org-roam-db-autosync-mode)
  941. :custom
  942. (org-roam-directory MY--PATH_ORG_ROAM)
  943. (org-roam-completion-everywhere t)
  944. (org-roam-capture-templates
  945. '(("d" "default" plain
  946. "%?"
  947. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: ${title}\n")
  948. :unnarrowed t)
  949. ("n" "ndefault" plain
  950. "%?"
  951. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: ${title}\n")
  952. :unnarrowed t)
  953. ))
  954. :bind (("C-c n l" . org-roam-buffer-toggle)
  955. ("C-c n f" . org-roam-node-find)
  956. ("C-c n i" . org-roam-node-insert)
  957. :map org-mode-map
  958. ("C-M-i" . completion-at-point)
  959. :map org-roam-dailies-map
  960. ("Y" . org-roam-dailies-capture-yesterday)
  961. ("T" . org-roam-dailies-capture-tomorrow))
  962. :bind-keymap
  963. ("C-c n d" . org-roam-dailies-map))
  964. (use-package org-roam
  965. :if (eq *sys/windows* t)
  966. :init
  967. (setq exec-path (append exec-path '("P:/Tools/sqlite")))
  968. (use-package emacsql-sqlite3
  969. :ensure t
  970. :init
  971. (setq emacsql-sqlite3-binary "P:/Tools/sqlite/sqlite3.exe"))
  972. :config
  973. (add-to-list 'org-roam-capture-templates
  974. '("t" "telephone call" plain
  975. "%?"
  976. :if-new (file+head "telephone/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: CALL %<%Y-%m-%d %H:%M> ${title}\n")
  977. :unnarrowed t) t)
  978. (add-to-list 'org-roam-capture-templates
  979. '("p" "new Project" plain
  980. "** ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  981. :target (file+olp "projects.org" ("Active"))) t)
  982. (add-to-list 'org-roam-capture-templates
  983. '("s" "Sicherheitenmeldung" plain
  984. "*** TODO [#A] Sicherheitenmeldung ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  985. :target (file+olp "tasks.org" ("Todos" "Sicherheitenmeldungen"))) t)
  986. (add-to-list 'org-roam-capture-templates
  987. '("m" "Monatsbericht" plain'
  988. "*** TODO [#A] Monatsbericht ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  989. :target (file+olp "tasks.org" ("Todos" "Monatsberichte"))) t)
  990. :custom
  991. (org-roam-database-connector 'sqlite3))
  992. #+END_SRC
  993. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  994. * Programming
  995. ** misc
  996. #+begin_src emacs-lisp
  997. (use-package eldoc
  998. :diminish eldoc-mode
  999. :defer t)
  1000. #+end_src
  1001. ** Magit / Git
  1002. Little crash course in magit:
  1003. - magit-init to init a git project
  1004. - magit-status (C-x g) to call the status window
  1005. In status buffer:
  1006. - s stage files
  1007. - u unstage files
  1008. - U unstage all files
  1009. - a apply changes to staging
  1010. - c c commit (type commit message, then C-c C-c to commit)
  1011. - b b switch to another branch
  1012. - P u git push
  1013. - F u git pull
  1014. #+BEGIN_SRC emacs-lisp
  1015. (use-package magit
  1016. :ensure t
  1017. :defer t
  1018. :init
  1019. ; set git-path in work environment
  1020. (if (string-equal user-login-name "POH")
  1021. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1022. )
  1023. :bind (("C-x g" . magit-status)))
  1024. #+END_SRC
  1025. ** LSP
  1026. Configuration for the language server protocol
  1027. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  1028. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  1029. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  1030. TODO Unterverzeichnisse wurden noch nicht getestet
  1031. #+BEGIN_SRC emacs-lisp
  1032. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  1033. (use-package lsp-mode
  1034. :defer t
  1035. :commands (lsp lsp-execute-code-action)
  1036. :custom
  1037. (lsp-auto-guess-root nil)
  1038. (lsp-prefer-flymake nil) ; use flycheck instead
  1039. (lsp-prefer-capf t)
  1040. (lsp-file-watch-threshold 5000)
  1041. (lsp-print-performance t)
  1042. (lsp-log-io nil) ; enable log only for debug
  1043. (lsp-enable-folding t) ; default, maybe evil-matchit instead for performance?
  1044. (lsp-diagnostics-modeline-scope :project)
  1045. (lsp-enable-file-watchers nil)
  1046. (lsp-session-file (concat MY--PATH_USER_LOCAL "lsp-session"))
  1047. (lsp-eslint-library-choices-file (concat MY--PATH_USER_LOCAL "lsp-eslint-choices"))
  1048. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  1049. :hook
  1050. (((python-mode
  1051. js-mode
  1052. js2-mode
  1053. typescript-mode
  1054. web-mode
  1055. ) . lsp-deferred)
  1056. (lsp-mode . lsp-enable-which-key-integration)
  1057. (lsp-mode . lsp-diagnostics-modeline-mode)
  1058. (web-mode . #'lsp-flycheck-enable)) ;; enable flycheck-lsp for web-mode locally
  1059. :config
  1060. (setq lsp-diagnostics-package :none)) ; disable flycheck-lsp for most modes
  1061. ;; (add-hook 'web-mode-hook #'lsp-flycheck-enable)) ; enable flycheck-lsp for web-mode locally
  1062. (use-package lsp-ui
  1063. :after lsp-mode
  1064. :ensure t
  1065. :defer t
  1066. :diminish
  1067. :commands lsp-ui-mode
  1068. :config
  1069. (setq lsp-ui-doc-enable t
  1070. lsp-ui-doc-header t
  1071. lsp-ui-doc-include-signature t
  1072. lsp-ui-doc-position 'top
  1073. lsp-ui-doc-border (face-foreground 'default)
  1074. lsp-ui-sideline-enable t
  1075. lsp-ui-sideline-ignore-duplicate t
  1076. lsp-ui-sideline-show-code-actions nil)
  1077. (when *sys/gui*
  1078. (setq lsp-ui-doc-use-webkit t))
  1079. ;; workaround hide mode-line of lsp-ui-imenu buffer
  1080. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  1081. (setq mode-line-format nil)))
  1082. ;;NO LONGER SUPPORTED, USE company-capf / completion-at-point
  1083. ;(use-package company-lsp
  1084. ; :requires company
  1085. ; :defer t
  1086. ; :ensure t
  1087. ; :config
  1088. ; ;;disable client-side cache because lsp server does a better job
  1089. ; (setq company-transformers nil
  1090. ; company-lsp-async t
  1091. ; company-lsp-cache-candidates nil))
  1092. #+END_SRC
  1093. ** yasnippet
  1094. For useful snippet either install yasnippet-snippets or get them from here
  1095. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1096. #+begin_src emacs-lisp
  1097. (use-package yasnippet
  1098. :ensure t
  1099. :defer t
  1100. :diminish yas-minor-mode
  1101. :config
  1102. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1103. (yas-global-mode t)
  1104. (yas-reload-all)
  1105. (unbind-key "TAB" yas-minor-mode-map)
  1106. (unbind-key "<tab>" yas-minor-mode-map))
  1107. #+end_src
  1108. ** hippie expand
  1109. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1110. #+begin_src emacs-lisp
  1111. (use-package hippie-exp
  1112. :defer t
  1113. :bind
  1114. ("C-<return>" . hippie-expand)
  1115. :config
  1116. (setq hippie-expand-try-functions-list
  1117. '(yas-hippie-try-expand emmet-expand-line)))
  1118. #+end_src
  1119. ** flycheck
  1120. #+BEGIN_SRC emacs-lisp
  1121. (use-package flycheck
  1122. :ensure t
  1123. :hook
  1124. ((css-mode . flycheck-mode)
  1125. (emacs-lisp-mode . flycheck-mode)
  1126. (python-mode . flycheck-mode))
  1127. :defer 1.0
  1128. :init
  1129. (setq flycheck-emacs-lisp-load-path 'inherit)
  1130. :config
  1131. (setq-default
  1132. flycheck-check-synta-automatically '(save mode-enabled)
  1133. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1134. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1135. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1136. #+END_SRC
  1137. ** Projectile
  1138. Manage projects and jump quickly between its files
  1139. #+BEGIN_SRC emacs-lisp
  1140. (use-package projectile
  1141. :ensure t
  1142. ; :defer 1.0
  1143. :diminish
  1144. :bind
  1145. (("C-c p" . projectile-command-map))
  1146. ;:preface
  1147. :init
  1148. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL "projectile-cache")
  1149. projectile-known-projects-file (concat MY--PATH_USER_LOCAL "projectile-bookmarks"))
  1150. :config
  1151. (projectile-mode)
  1152. ; (add-hook 'projectile-after-switch-project-hook #'set-workon_home)
  1153. (setq-default projectile-completion-system 'ivy
  1154. projectile-enable-caching t
  1155. projectile-mode-line '(:eval (projectile-project-name))))
  1156. ;; requires ripgrep on system for rg functions
  1157. ;(use-package counsel-projectile
  1158. ; :ensure t
  1159. ; :config (counsel-projectile-mode) (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer)
  1160. ;(use-package helm-projectile
  1161. ; :ensure t
  1162. ; :hook
  1163. ; (projectile-mode . helm-projectile))
  1164. #+END_SRC
  1165. ** smartparens
  1166. #+BEGIN_SRC emacs-lisp
  1167. (use-package smartparens
  1168. :ensure t
  1169. :diminish smartparens-mode
  1170. :bind
  1171. (:map smartparens-mode-map
  1172. ("C-M-f" . sp-forward-sexp)
  1173. ("C-M-b" . sp-backward-sexp)
  1174. ("C-M-a" . sp-backward-down-sexp)
  1175. ("C-M-e" . sp-up-sexp)
  1176. ("C-M-w" . sp-copy-sexp)
  1177. ("M-k" . sp-kill-sexp)
  1178. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1179. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1180. ("C-]" . sp-select-next-thing-exchange))
  1181. :config
  1182. (setq sp-show-pair-from-inside nil
  1183. sp-escape-quotes-after-insert nil)
  1184. (require 'smartparens-config))
  1185. #+END_SRC
  1186. ** lisp
  1187. #+BEGIN_SRC emacs-lisp
  1188. (use-package elisp-mode
  1189. :defer t)
  1190. #+END_SRC
  1191. ** web
  1192. apt install npm
  1193. sudo npm install -g vscode-html-languageserver-bin
  1194. evtl alternativ typescript-language-server?
  1195. Unter Windows:
  1196. Hier runterladen: https://nodejs.org/dist/latest/
  1197. und in ein Verzeichnis entpacken.
  1198. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1199. PATH=P:\path\to\node;%path%
  1200. #+BEGIN_SRC emacs-lisp
  1201. (use-package web-mode
  1202. :ensure t
  1203. :defer t
  1204. :mode
  1205. ("\\.phtml\\'"
  1206. "\\.tpl\\.php\\'"
  1207. "\\.djhtml\\'"
  1208. "\\.[t]?html?\\'")
  1209. :hook
  1210. (web-mode . smartparens-mode)
  1211. :init
  1212. (if *work_remote*
  1213. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1214. :config
  1215. (setq web-mode-enable-auto-closing t
  1216. web-mode-enable-auto-pairing t))
  1217. #+END_SRC
  1218. Emmet offers snippets, similar to yasnippet.
  1219. Default completion is C-j
  1220. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1221. #+begin_src emacs-lisp
  1222. (use-package emmet-mode
  1223. :ensure t
  1224. :defer t
  1225. :hook
  1226. ((web-mode . emmet-mode)
  1227. (css-mode . emmet-mode))
  1228. :config
  1229. (unbind-key "C-<return>" emmet-mode-keymap))
  1230. #+end_src
  1231. *** JavaScript
  1232. npm install -g typescript-language-server typescript
  1233. maybe only typescript?
  1234. npm install -g prettier
  1235. #+begin_src emacs-lisp
  1236. (use-package rjsx-mode
  1237. :ensure t
  1238. :mode ("\\.js\\'"
  1239. "\\.jsx'"))
  1240. ; :config
  1241. ; (setq js2-mode-show-parse-errors nil
  1242. ; js2-mode-show-strict-warnings nil
  1243. ; js2-basic-offset 2
  1244. ; js-indent-level 2)
  1245. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1246. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1247. (use-package tide
  1248. :ensure t
  1249. :after (rjsx-mode company flycheck)
  1250. ; :hook (rjsx-mode . setup-tide-mode)
  1251. :config
  1252. (defun setup-tide-mode ()
  1253. "Setup function for tide."
  1254. (interactive)
  1255. (tide-setup)
  1256. (flycheck-mode t)
  1257. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1258. (tide-hl-identifier-mode t)))
  1259. ;; needs npm install -g prettier
  1260. (use-package prettier-js
  1261. :ensure t
  1262. :after (rjsx-mode)
  1263. :defer t
  1264. :diminish prettier-js-mode
  1265. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1266. #+end_src
  1267. ** YAML
  1268. #+begin_src emacs-lisp
  1269. (use-package yaml-mode
  1270. :if *sys/linux*
  1271. :ensure t
  1272. :defer t
  1273. :mode ("\\.yml$" . yaml-mode))
  1274. #+end_src
  1275. ** R
  1276. #+BEGIN_SRC emacs-lisp
  1277. (use-package ess
  1278. :ensure t
  1279. :defer t
  1280. :init
  1281. (if *work_remote*
  1282. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1283. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1284. #+END_SRC
  1285. ** Python
  1286. Systemseitig muss python-language-server installiert sein:
  1287. apt install python3-pip python3-setuptools python3-wheel
  1288. apt install build-essential python3-dev
  1289. pip3 install 'python-language-server[all]'
  1290. Statt obiges: npm install -g pyright
  1291. für andere language servers
  1292. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1293. #+BEGIN_SRC emacs-lisp
  1294. ;(use-package lsp-python-ms
  1295. ; :if *sys/linux*
  1296. ; :ensure t
  1297. ; :defer t
  1298. ; :custom (lsp-python-ms-auto-install-server t))
  1299. (use-package lsp-pyright
  1300. :ensure t
  1301. :after lsp-mode
  1302. :defer t
  1303. :hook
  1304. (python-mode . (lambda ()
  1305. (require 'lsp-pyright)
  1306. (lsp-deferred)))
  1307. ; :custom
  1308. ; (lsp-pyright-auto-import-completions nil)
  1309. ; (lsp-pyright-typechecking-mode "off")
  1310. )
  1311. (use-package python
  1312. :if *sys/linux*
  1313. :delight "π "
  1314. :defer t
  1315. :bind (("M-[" . python-nav-backward-block)
  1316. ("M-]" . python-nav-forward-block)))
  1317. (use-package pyvenv
  1318. :if *sys/linux*
  1319. :ensure t
  1320. :defer t
  1321. :after python
  1322. :hook ((python-mode . pyvenv-mode)
  1323. (python-mode . (lambda ()
  1324. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  1325. (pyvenv-activate pyvenv-directory))
  1326. (lsp))))
  1327. :custom
  1328. (pyvenv-default-virtual-env-name "env")
  1329. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  1330. :preface
  1331. (defun find-pyvenv-directory (path)
  1332. "Check if a pyvenv directory exists."
  1333. (cond
  1334. ((not path) nil)
  1335. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  1336. ((file-directory-p path)
  1337. (or
  1338. (seq-find
  1339. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  1340. (directory-files path t))
  1341. (let ((parent (file-name-directory (directory-file-name path))))
  1342. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  1343. ;; manage multiple python version
  1344. ;; needs to be installed on system
  1345. ; (use-package pyenv-mode
  1346. ; :ensure t
  1347. ; :after python
  1348. ; :hook ((python-mode . pyenv-mode)
  1349. ; (projectile-switch-project . projectile-pyenv-mode-set))
  1350. ; :custom (pyenv-mode-set "3.8.5")
  1351. ; :preface
  1352. ; (defun projectile-pyenv-mode-set ()
  1353. ; "Set pyenv version matching project name."
  1354. ; (let ((project (projectile-project-name)))
  1355. ; (if (member project (pyenv-mode-versions))
  1356. ; (pyenv-mode-set project)
  1357. ; (pyenv-mode-unset)))))
  1358. ;)
  1359. #+END_SRC
  1360. * beancount
  1361. ** Installation
  1362. #+BEGIN_SRC shell :tangle no
  1363. sudo su
  1364. cd /opt
  1365. python3 -m venv beancount
  1366. source ./beancount/bin/activate
  1367. pip3 install wheel
  1368. pip3 install beancount
  1369. sleep 100
  1370. echo "shell running!"
  1371. deactivate
  1372. #+END_SRC
  1373. #+BEGIN_SRC emacs-lisp
  1374. (use-package beancount
  1375. :if *sys/linux*
  1376. :load-path "user-global/elisp"
  1377. ; :ensure t
  1378. :defer t
  1379. :mode
  1380. ("\\.beancount$" . beancount-mode)
  1381. :hook
  1382. (beancount-mode . me/beancount-company)
  1383. :init
  1384. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1385. :config
  1386. (defun me/beancount-company ()
  1387. (set (make-local-variable 'company-backends)
  1388. '(company-beancount)))
  1389. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1390. #+END_SRC
  1391. To support org-babel, check if it can find the symlink to ob-beancount.el
  1392. #+BEGIN_SRC shell :tangle no
  1393. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1394. beansym="$orgpath/ob-beancount.el
  1395. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1396. if [ -h "$beansym" ]
  1397. then
  1398. echo "$beansym found"
  1399. elif [ -e "$bean" ]
  1400. then
  1401. echo "creating symlink"
  1402. ln -s "$bean" "$beansym"
  1403. else
  1404. echo "$bean not found, symlink creation aborted"
  1405. fi
  1406. #+END_SRC
  1407. Fava is strongly recommended.
  1408. #+BEGIN_SRC shell :tangle no
  1409. cd /opt
  1410. python3 -m venv fava
  1411. source ./fava/bin/activate
  1412. pip3 install wheel
  1413. pip3 install fava
  1414. deactivate
  1415. #+END_SRC
  1416. Start fava with fava my_file.beancount
  1417. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1418. Beancount-mode can start fava and open the URL right away.
  1419. * Stuff after everything else
  1420. Set garbage collector to a smaller value to let it kick in faster.
  1421. Maybe a problem on Windows?
  1422. #+begin_src emacs-lisp
  1423. ;(setq gc-cons-threshold (* 2 1000 1000))
  1424. #+end_src