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.

1579 lines
45 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. :config
  722. (defun me/org-company ()
  723. (set (make-local-variable 'company-backends)
  724. '(company-capf company-files))
  725. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  726. (message "company/org-mode-hook"))
  727. (setq org-modules (quote (org-id
  728. org-habit
  729. org-tempo ;; easy templates
  730. )))
  731. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  732. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  733. (concat MY--PATH_ORG_FILES "projects.org")
  734. (concat MY--PATH_ORG_FILES "tasks.org")))
  735. (when *sys/linux*
  736. (nconc org-agenda-files
  737. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  738. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  739. org-log-into-drawer "LOGBOOK")
  740. ;; some display customizations
  741. (setq org-pretty-entities t
  742. org-startup-truncated t
  743. org-startup-align-all-tables t)
  744. ;; some source code blocks customizations
  745. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  746. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  747. org-src-preserve-indentation t ;; no extra indentation
  748. org-src-tab-acts-natively t)
  749. (setq org-log-done 'time ;; create timestamp when task is done
  750. org-blank-before-new-entry '((heading) (plain-list-item)))) ;; prevent new line before new item
  751. #+END_SRC
  752. ** languages
  753. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  754. +BEGIN_SRC emacs-lisp
  755. (org-babel-do-load-languages
  756. 'org-babel-load-languages
  757. '((emacs-lisp . t)
  758. (gnuplot . t)
  759. (js . t)
  760. (latex . t)
  761. (lisp . t)
  762. (python . t)
  763. (shell . t)
  764. (sqlite . t)
  765. (org . t)
  766. (R . t)
  767. (scheme . t)))
  768. (setq org-confirm-babel-evaluate nil)
  769. +END_SRC
  770. Another setup, because org-babel-do-load-languages requires eager loading
  771. #+begin_src emacs-lisp
  772. (use-package ob-org
  773. :defer t
  774. :ensure org-contrib
  775. :commands
  776. (org-babel-execute:org
  777. org-babel-expand-body:org))
  778. (use-package ob-python
  779. :defer t
  780. :ensure org-contrib
  781. :commands (org-babel-execute:python))
  782. (use-package ob-js
  783. :defer t
  784. :ensure org-contrib
  785. :commands (org-babel-execute:js))
  786. (use-package ob-shell
  787. :defer t
  788. :ensure org-contrib
  789. :commands
  790. (org-babel-execute:sh
  791. org-babel-expand-body:sh
  792. org-babel-execute:bash
  793. org-babel-expand-body:bash))
  794. (use-package ob-emacs-lisp
  795. :defer t
  796. :ensure org-contrib
  797. :commands
  798. (org-babel-execute:emacs-lisp
  799. org-babel-expand-body:emacs-lisp))
  800. (use-package ob-lisp
  801. :defer t
  802. :ensure org-contrib
  803. :commands
  804. (org-babel-execute:lisp
  805. org-babel-expand-body:lisp))
  806. (use-package ob-gnuplot
  807. :defer t
  808. :ensure org-contrib
  809. :commands
  810. (org-babel-execute:gnuplot
  811. org-babel-expand-body:gnuplot))
  812. (use-package ob-sqlite
  813. :defer t
  814. :ensure org-contrib
  815. :commands
  816. (org-babel-execute:sqlite
  817. org-babel-expand-body:sqlite))
  818. (use-package ob-latex
  819. :defer t
  820. :ensure org-contrib
  821. :commands
  822. (org-babel-execute:latex
  823. org-babel-expand-body:latex))
  824. (use-package ob-R
  825. :defer t
  826. :ensure org-contrib
  827. :commands
  828. (org-babel-execute:R
  829. org-babel-expand-body:R))
  830. (use-package ob-scheme
  831. :defer t
  832. :ensure org-contrib
  833. :commands
  834. (org-babel-execute:scheme
  835. org-babel-expand-body:scheme))
  836. #+end_src
  837. ** habits
  838. #+BEGIN_SRC emacs-lisp
  839. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  840. ;; (add-to-list 'org-modules "org-habit")
  841. (setq org-habit-graph-column 80
  842. org-habit-preceding-days 30
  843. org-habit-following-days 7
  844. org-habit-show-habits-only-for-today nil)
  845. #+END_SRC
  846. ** org-agenda
  847. Custom keywords, depending on environment
  848. #+BEGIN_SRC emacs-lisp
  849. (when *work_remote*
  850. (setq org-todo-keywords
  851. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  852. #+END_SRC
  853. Add some key bindings
  854. #+BEGIN_SRC emacs-lisp
  855. (bind-key "C-c l" 'org-store-link)
  856. (bind-key "C-c c" 'org-capture)
  857. (bind-key "C-c a" 'org-agenda)
  858. #+END_SRC
  859. Sort agenda by deadline and priority
  860. #+BEGIN_SRC emacs-lisp
  861. (setq org-agenda-sorting-strategy
  862. (quote
  863. ((agenda deadline-up priority-down)
  864. (todo priority-down category-keep)
  865. (tags priority-down category-keep)
  866. (search category-keep))))
  867. #+END_SRC
  868. Customize the org agenda
  869. #+BEGIN_SRC emacs-lisp
  870. (defun me--org-skip-subtree-if-priority (priority)
  871. "Skip an agenda subtree if it has a priority of PRIORITY.
  872. PRIORITY may be one of the characters ?A, ?B, or ?C."
  873. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  874. (pri-value (* 1000 (- org-lowest-priority priority)))
  875. (pri-current (org-get-priority (thing-at-point 'line t))))
  876. (if (= pri-value pri-current)
  877. subtree-end
  878. nil)))
  879. (setq org-agenda-custom-commands
  880. '(("c" "Simple agenda view"
  881. ((tags "PRIORITY=\"A\""
  882. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  883. (org-agenda-overriding-header "Hohe Priorität:")))
  884. (agenda ""
  885. ((org-agenda-span 7)
  886. (org-agenda-start-on-weekday nil)
  887. (org-agenda-overriding-header "Nächste 7 Tage:")))
  888. (alltodo ""
  889. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  890. (org-agenda-skip-if nil '(scheduled deadline))))
  891. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  892. #+END_SRC
  893. ** *TODO*
  894. [[https://github.com/alphapapa/org-ql][org-ql]]
  895. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  896. ** org-caldav
  897. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  898. #+BEGIN_SRC emacs-lisp
  899. ;;(use-package org-caldav
  900. ;; :ensure t
  901. ;; :config
  902. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  903. ;; org-caldav-calendar-id "orgmode"
  904. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  905. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  906. #+END_SRC
  907. ** journal
  908. [[https://github.com/bastibe/org-journal][Source]]
  909. Ggf. durch org-roam-journal ersetzen
  910. #+BEGIN_SRC emacs-lisp
  911. (use-package org-journal
  912. :if *sys/linux*
  913. :ensure t
  914. :defer t
  915. :config
  916. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  917. (when (and (boundp 'org-journal-dir)
  918. (boundp 'org-journal-enable-agenda-integration))
  919. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  920. org-journal-enable-agenda-integration t)))
  921. #+END_SRC
  922. ** org-roam
  923. [[https://github.com/org-roam/org-roam][Github]]
  924. Um Headings innerhalb einer Datei zu verlinken:
  925. - org-id-get-create im Heading,
  926. - org-roam-node-insert in der verweisenden Datei
  927. Bei Problemen wie unique constraint
  928. org-roam-db-clear-all
  929. org-roam-db-sync
  930. #+BEGIN_SRC emacs-lisp
  931. (use-package org-roam
  932. :if (eq *sys/windows* t)
  933. :init
  934. (setq exec-path (append exec-path '("P:/Tools/sqlite")))
  935. (use-package emacsql-sqlite3
  936. :ensure t
  937. :init
  938. (setq emacsql-sqlite3-binary "P:/Tools/sqlite/sqlite3.exe"))
  939. :custom
  940. (org-roam-database-connector 'sqlite3))
  941. (use-package org-roam
  942. :ensure t
  943. :defer t
  944. :init
  945. (setq org-roam-v2-ack t)
  946. :config
  947. (require 'org-roam-dailies) ;; ensure the keymap is available
  948. (org-roam-db-autosync-mode)
  949. :custom
  950. (org-roam-directory MY--PATH_ORG_ROAM)
  951. (org-roam-completion-everywhere t)
  952. (org-roam-capture-templates
  953. '(("d" "default" plain
  954. "%?"
  955. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: ${title}\n")
  956. :unnarrowed t)
  957. ("n" "ndefault" plain
  958. "%?"
  959. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: ${title}\n")
  960. :unnarrowed t)
  961. ("t" "telephone call" plain
  962. "%?"
  963. :if-new (file+head "telephone/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: CALL %<%Y-%m-%d %H:%M> ${title}\n")
  964. :unnarrowed t)
  965. ("p" "new Project" plain
  966. "** ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  967. :target (file+olp "projects.org" ("Active")))
  968. ))
  969. :bind (("C-c n l" . org-roam-buffer-toggle)
  970. ("C-c n f" . org-roam-node-find)
  971. ("C-c n i" . org-roam-node-insert)
  972. :map org-mode-map
  973. ("C-M-i" . completion-at-point)
  974. :map org-roam-dailies-map
  975. ("Y" . org-roam-dailies-capture-yesterday)
  976. ("T" . org-roam-dailies-capture-tomorrow))
  977. :bind-keymap
  978. ("C-c n d" . org-roam-dailies-map))
  979. #+END_SRC
  980. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  981. * Programming
  982. ** misc
  983. #+begin_src emacs-lisp
  984. (use-package eldoc
  985. :diminish eldoc-mode
  986. :defer t)
  987. #+end_src
  988. ** Magit / Git
  989. Little crash course in magit:
  990. - magit-init to init a git project
  991. - magit-status (C-x g) to call the status window
  992. In status buffer:
  993. - s stage files
  994. - u unstage files
  995. - U unstage all files
  996. - a apply changes to staging
  997. - c c commit (type commit message, then C-c C-c to commit)
  998. - b b switch to another branch
  999. - P u git push
  1000. - F u git pull
  1001. #+BEGIN_SRC emacs-lisp
  1002. (use-package magit
  1003. :ensure t
  1004. :defer t
  1005. :init
  1006. ; set git-path in work environment
  1007. (if (string-equal user-login-name "POH")
  1008. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1009. )
  1010. :bind (("C-x g" . magit-status)))
  1011. #+END_SRC
  1012. ** LSP
  1013. Configuration for the language server protocol
  1014. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  1015. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  1016. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  1017. TODO Unterverzeichnisse wurden noch nicht getestet
  1018. #+BEGIN_SRC emacs-lisp
  1019. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  1020. (use-package lsp-mode
  1021. :defer t
  1022. :commands (lsp lsp-execute-code-action)
  1023. :custom
  1024. (lsp-auto-guess-root nil)
  1025. (lsp-prefer-flymake nil) ; use flycheck instead
  1026. (lsp-prefer-capf t)
  1027. (lsp-file-watch-threshold 5000)
  1028. (lsp-print-performance t)
  1029. (lsp-log-io nil) ; enable log only for debug
  1030. (lsp-enable-folding t) ; default, maybe evil-matchit instead for performance?
  1031. (lsp-diagnostics-modeline-scope :project)
  1032. (lsp-enable-file-watchers nil)
  1033. (lsp-session-file (concat MY--PATH_USER_LOCAL "lsp-session"))
  1034. (lsp-eslint-library-choices-file (concat MY--PATH_USER_LOCAL "lsp-eslint-choices"))
  1035. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  1036. :hook
  1037. (((python-mode
  1038. js-mode
  1039. js2-mode
  1040. typescript-mode
  1041. web-mode
  1042. ) . lsp-deferred)
  1043. (lsp-mode . lsp-enable-which-key-integration)
  1044. (lsp-mode . lsp-diagnostics-modeline-mode)
  1045. (web-mode . #'lsp-flycheck-enable)) ;; enable flycheck-lsp for web-mode locally
  1046. :config
  1047. (setq lsp-diagnostics-package :none)) ; disable flycheck-lsp for most modes
  1048. ;; (add-hook 'web-mode-hook #'lsp-flycheck-enable)) ; enable flycheck-lsp for web-mode locally
  1049. (use-package lsp-ui
  1050. :after lsp-mode
  1051. :ensure t
  1052. :defer t
  1053. :diminish
  1054. :commands lsp-ui-mode
  1055. :config
  1056. (setq lsp-ui-doc-enable t
  1057. lsp-ui-doc-header t
  1058. lsp-ui-doc-include-signature t
  1059. lsp-ui-doc-position 'top
  1060. lsp-ui-doc-border (face-foreground 'default)
  1061. lsp-ui-sideline-enable t
  1062. lsp-ui-sideline-ignore-duplicate t
  1063. lsp-ui-sideline-show-code-actions nil)
  1064. (when *sys/gui*
  1065. (setq lsp-ui-doc-use-webkit t))
  1066. ;; workaround hide mode-line of lsp-ui-imenu buffer
  1067. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  1068. (setq mode-line-format nil)))
  1069. ;;NO LONGER SUPPORTED, USE company-capf / completion-at-point
  1070. ;(use-package company-lsp
  1071. ; :requires company
  1072. ; :defer t
  1073. ; :ensure t
  1074. ; :config
  1075. ; ;;disable client-side cache because lsp server does a better job
  1076. ; (setq company-transformers nil
  1077. ; company-lsp-async t
  1078. ; company-lsp-cache-candidates nil))
  1079. #+END_SRC
  1080. ** yasnippet
  1081. For useful snippet either install yasnippet-snippets or get them from here
  1082. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1083. #+begin_src emacs-lisp
  1084. (use-package yasnippet
  1085. :ensure t
  1086. :defer t
  1087. :diminish yas-minor-mode
  1088. :config
  1089. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1090. (yas-global-mode t)
  1091. (yas-reload-all)
  1092. (unbind-key "TAB" yas-minor-mode-map)
  1093. (unbind-key "<tab>" yas-minor-mode-map))
  1094. #+end_src
  1095. ** hippie expand
  1096. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1097. #+begin_src emacs-lisp
  1098. (use-package hippie-exp
  1099. :defer t
  1100. :bind
  1101. ("C-<return>" . hippie-expand)
  1102. :config
  1103. (setq hippie-expand-try-functions-list
  1104. '(yas-hippie-try-expand emmet-expand-line)))
  1105. #+end_src
  1106. ** flycheck
  1107. #+BEGIN_SRC emacs-lisp
  1108. (use-package flycheck
  1109. :ensure t
  1110. :hook
  1111. ((css-mode . flycheck-mode)
  1112. (emacs-lisp-mode . flycheck-mode)
  1113. (python-mode . flycheck-mode))
  1114. :defer 1.0
  1115. :init
  1116. (setq flycheck-emacs-lisp-load-path 'inherit)
  1117. :config
  1118. (setq-default
  1119. flycheck-check-synta-automatically '(save mode-enabled)
  1120. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1121. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1122. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1123. #+END_SRC
  1124. ** Projectile
  1125. Manage projects and jump quickly between its files
  1126. #+BEGIN_SRC emacs-lisp
  1127. (use-package projectile
  1128. :ensure t
  1129. ; :defer 1.0
  1130. :diminish
  1131. :bind
  1132. (("C-c p" . projectile-command-map))
  1133. ;:preface
  1134. :init
  1135. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL "projectile-cache")
  1136. projectile-known-projects-file (concat MY--PATH_USER_LOCAL "projectile-bookmarks"))
  1137. :config
  1138. (projectile-mode)
  1139. ; (add-hook 'projectile-after-switch-project-hook #'set-workon_home)
  1140. (setq-default projectile-completion-system 'ivy
  1141. projectile-enable-caching t
  1142. projectile-mode-line '(:eval (projectile-project-name))))
  1143. ;; requires ripgrep on system for rg functions
  1144. ;(use-package counsel-projectile
  1145. ; :ensure t
  1146. ; :config (counsel-projectile-mode) (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer)
  1147. (use-package helm-projectile
  1148. :ensure t
  1149. :hook
  1150. (projectile-mode . helm-projectile))
  1151. #+END_SRC
  1152. ** smartparens
  1153. #+BEGIN_SRC emacs-lisp
  1154. (use-package smartparens
  1155. :ensure t
  1156. :diminish smartparens-mode
  1157. :bind
  1158. (:map smartparens-mode-map
  1159. ("C-M-f" . sp-forward-sexp)
  1160. ("C-M-b" . sp-backward-sexp)
  1161. ("C-M-a" . sp-backward-down-sexp)
  1162. ("C-M-e" . sp-up-sexp)
  1163. ("C-M-w" . sp-copy-sexp)
  1164. ("M-k" . sp-kill-sexp)
  1165. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1166. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1167. ("C-]" . sp-select-next-thing-exchange))
  1168. :config
  1169. (setq sp-show-pair-from-inside nil
  1170. sp-escape-quotes-after-insert nil)
  1171. (require 'smartparens-config))
  1172. #+END_SRC
  1173. ** lisp
  1174. #+BEGIN_SRC emacs-lisp
  1175. (use-package elisp-mode
  1176. :defer t)
  1177. #+END_SRC
  1178. ** web
  1179. apt install npm
  1180. sudo npm install -g vscode-html-languageserver-bin
  1181. evtl alternativ typescript-language-server?
  1182. Unter Windows:
  1183. Hier runterladen: https://nodejs.org/dist/latest/
  1184. und in ein Verzeichnis entpacken.
  1185. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1186. PATH=P:\path\to\node;%path%
  1187. #+BEGIN_SRC emacs-lisp
  1188. (use-package web-mode
  1189. :ensure t
  1190. :defer t
  1191. :mode
  1192. ("\\.phtml\\'"
  1193. "\\.tpl\\.php\\'"
  1194. "\\.djhtml\\'"
  1195. "\\.[t]?html?\\'")
  1196. :hook
  1197. (web-mode . smartparens-mode)
  1198. :init
  1199. (if *work_remote*
  1200. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1201. :config
  1202. (setq web-mode-enable-auto-closing t
  1203. web-mode-enable-auto-pairing t))
  1204. #+END_SRC
  1205. Emmet offers snippets, similar to yasnippet.
  1206. Default completion is C-j
  1207. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1208. #+begin_src emacs-lisp
  1209. (use-package emmet-mode
  1210. :ensure t
  1211. :defer t
  1212. :hook
  1213. ((web-mode . emmet-mode)
  1214. (css-mode . emmet-mode))
  1215. :config
  1216. (unbind-key "C-<return>" emmet-mode-keymap))
  1217. #+end_src
  1218. *** JavaScript
  1219. npm install -g typescript-language-server typescript
  1220. maybe only typescript?
  1221. npm install -g prettier
  1222. #+begin_src emacs-lisp
  1223. (use-package rjsx-mode
  1224. :ensure t
  1225. :mode ("\\.js\\'"
  1226. "\\.jsx'"))
  1227. ; :config
  1228. ; (setq js2-mode-show-parse-errors nil
  1229. ; js2-mode-show-strict-warnings nil
  1230. ; js2-basic-offset 2
  1231. ; js-indent-level 2)
  1232. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1233. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1234. (use-package tide
  1235. :ensure t
  1236. :after (rjsx-mode company flycheck)
  1237. ; :hook (rjsx-mode . setup-tide-mode)
  1238. :config
  1239. (defun setup-tide-mode ()
  1240. "Setup function for tide."
  1241. (interactive)
  1242. (tide-setup)
  1243. (flycheck-mode t)
  1244. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1245. (tide-hl-identifier-mode t)))
  1246. ;; needs npm install -g prettier
  1247. (use-package prettier-js
  1248. :ensure t
  1249. :after (rjsx-mode)
  1250. :defer t
  1251. :diminish prettier-js-mode
  1252. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1253. #+end_src
  1254. ** YAML
  1255. #+begin_src emacs-lisp
  1256. (use-package yaml-mode
  1257. :if *sys/linux*
  1258. :ensure t
  1259. :defer t
  1260. :mode ("\\.yml$" . yaml-mode))
  1261. #+end_src
  1262. ** R
  1263. #+BEGIN_SRC emacs-lisp
  1264. (use-package ess
  1265. :ensure t
  1266. :defer t
  1267. :init
  1268. (if *work_remote*
  1269. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1270. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1271. #+END_SRC
  1272. ** Python
  1273. Systemseitig muss python-language-server installiert sein:
  1274. apt install python3-pip python3-setuptools python3-wheel
  1275. apt install build-essential python3-dev
  1276. pip3 install 'python-language-server[all]'
  1277. Statt obiges: npm install -g pyright
  1278. für andere language servers
  1279. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1280. #+BEGIN_SRC emacs-lisp
  1281. ;(use-package lsp-python-ms
  1282. ; :if *sys/linux*
  1283. ; :ensure t
  1284. ; :defer t
  1285. ; :custom (lsp-python-ms-auto-install-server t))
  1286. (use-package lsp-pyright
  1287. :ensure t
  1288. :after lsp-mode
  1289. :defer t
  1290. :hook
  1291. (python-mode . (lambda ()
  1292. (require 'lsp-pyright)
  1293. (lsp-deferred)))
  1294. ; :custom
  1295. ; (lsp-pyright-auto-import-completions nil)
  1296. ; (lsp-pyright-typechecking-mode "off")
  1297. )
  1298. (use-package python
  1299. :if *sys/linux*
  1300. :delight "π "
  1301. :defer t
  1302. :bind (("M-[" . python-nav-backward-block)
  1303. ("M-]" . python-nav-forward-block)))
  1304. (use-package pyvenv
  1305. :if *sys/linux*
  1306. :ensure t
  1307. :defer t
  1308. :after python
  1309. :hook ((python-mode . pyvenv-mode)
  1310. (python-mode . (lambda ()
  1311. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  1312. (pyvenv-activate pyvenv-directory))
  1313. (lsp))))
  1314. :custom
  1315. (pyvenv-default-virtual-env-name "env")
  1316. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  1317. :preface
  1318. (defun find-pyvenv-directory (path)
  1319. "Check if a pyvenv directory exists."
  1320. (cond
  1321. ((not path) nil)
  1322. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  1323. ((file-directory-p path)
  1324. (or
  1325. (seq-find
  1326. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  1327. (directory-files path t))
  1328. (let ((parent (file-name-directory (directory-file-name path))))
  1329. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  1330. ;; manage multiple python version
  1331. ;; needs to be installed on system
  1332. ; (use-package pyenv-mode
  1333. ; :ensure t
  1334. ; :after python
  1335. ; :hook ((python-mode . pyenv-mode)
  1336. ; (projectile-switch-project . projectile-pyenv-mode-set))
  1337. ; :custom (pyenv-mode-set "3.8.5")
  1338. ; :preface
  1339. ; (defun projectile-pyenv-mode-set ()
  1340. ; "Set pyenv version matching project name."
  1341. ; (let ((project (projectile-project-name)))
  1342. ; (if (member project (pyenv-mode-versions))
  1343. ; (pyenv-mode-set project)
  1344. ; (pyenv-mode-unset)))))
  1345. ;)
  1346. #+END_SRC
  1347. * beancount
  1348. ** Installation
  1349. #+BEGIN_SRC shell :tangle no
  1350. sudo su
  1351. cd /opt
  1352. python3 -m venv beancount
  1353. source ./beancount/bin/activate
  1354. pip3 install wheel
  1355. pip3 install beancount
  1356. sleep 100
  1357. echo "shell running!"
  1358. deactivate
  1359. #+END_SRC
  1360. #+BEGIN_SRC emacs-lisp
  1361. (use-package beancount
  1362. :if *sys/linux*
  1363. :load-path "user-global/elisp"
  1364. ; :ensure t
  1365. :defer t
  1366. :mode
  1367. ("\\.beancount$" . beancount-mode)
  1368. :hook
  1369. (beancount-mode . me/beancount-company)
  1370. :init
  1371. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1372. :config
  1373. (defun me/beancount-company ()
  1374. (set (make-local-variable 'company-backends)
  1375. '(company-beancount)))
  1376. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1377. #+END_SRC
  1378. To support org-babel, check if it can find the symlink to ob-beancount.el
  1379. #+BEGIN_SRC shell :tangle no
  1380. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1381. beansym="$orgpath/ob-beancount.el
  1382. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1383. if [ -h "$beansym" ]
  1384. then
  1385. echo "$beansym found"
  1386. elif [ -e "$bean" ]
  1387. then
  1388. echo "creating symlink"
  1389. ln -s "$bean" "$beansym"
  1390. else
  1391. echo "$bean not found, symlink creation aborted"
  1392. fi
  1393. #+END_SRC
  1394. Fava is strongly recommended.
  1395. #+BEGIN_SRC shell :tangle no
  1396. cd /opt
  1397. python3 -m venv fava
  1398. source ./fava/bin/activate
  1399. pip3 install wheel
  1400. pip3 install fava
  1401. deactivate
  1402. #+END_SRC
  1403. Start fava with fava my_file.beancount
  1404. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1405. Beancount-mode can start fava and open the URL right away.
  1406. * Stuff after everything else
  1407. Set garbage collector to a smaller value to let it kick in faster.
  1408. Maybe a problem on Windows?
  1409. #+begin_src emacs-lisp
  1410. ;(setq gc-cons-threshold (* 2 1000 1000))
  1411. #+end_src