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.

1591 lines
46 KiB

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