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.

1582 lines
45 KiB

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