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.

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