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.

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