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.

1585 lines
45 KiB

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