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.

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