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.

1636 lines
47 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. (defun me--buffer-prop-set (name value)
  698. "Set a file property called NAME to VALUE in buffer file.
  699. If the property is already set, replace its value."
  700. (setq name (downcase name))
  701. (org-with-point-at 1
  702. (let ((case-fold-search t))
  703. (if (re-search-forward (concat "^#\\+" name ":\\(.*\\)")
  704. (point-max) t)
  705. (replace-match (concat "#+" name ": " value) 'fixedcase)
  706. (while (and (not (eobp))
  707. (looking-at "^[#:]"))
  708. (if (save-excursion (end-of-line) (eobp))
  709. (progn
  710. (end-of-line)
  711. (insert "\n"))
  712. (forward-line)
  713. (beginning-of-line)))
  714. (insert "#+" name ": " value "\n")))))
  715. (defun me--buffer-prop-remove (name)
  716. "Remove a buffer property called NAME."
  717. (org-with-point-at 1
  718. (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
  719. (point-max) t)
  720. (replace-match ""))))
  721. (use-package org
  722. :ensure t
  723. :mode (("\.org$" . org-mode))
  724. :diminish org-indent-mode
  725. :defer t
  726. :hook
  727. (org-mode . org-indent-mode)
  728. (org-source-mode . smartparens-mode)
  729. ; :init
  730. ; (add-hook 'org-mode-hook 'company/org-mode-hook)
  731. ; (add-hook 'org-src-mode-hook 'smartparens-mode)
  732. ; (add-hook 'org-mode-hook 'org-indent-mode)
  733. :bind (:map org-mode-map ("S-<right>" . org-shiftright)
  734. ("S-<left>" . org-shiftleft))
  735. :config
  736. (defun me/org-company ()
  737. (set (make-local-variable 'company-backends)
  738. '(company-capf company-files))
  739. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  740. (message "company/org-mode-hook"))
  741. (setq org-modules (quote (org-id
  742. org-habit
  743. org-tempo ;; easy templates
  744. )))
  745. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  746. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  747. (concat MY--PATH_ORG_FILES "projects.org")
  748. (concat MY--PATH_ORG_FILES "tasks.org")))
  749. (when *sys/linux*
  750. (nconc org-agenda-files
  751. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  752. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  753. org-log-into-drawer "LOGBOOK")
  754. ;; some display customizations
  755. (setq org-pretty-entities t
  756. org-startup-truncated t
  757. org-startup-align-all-tables t)
  758. ;; some source code blocks customizations
  759. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  760. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  761. org-src-preserve-indentation t ;; no extra indentation
  762. org-src-tab-acts-natively t)
  763. (setq org-log-done 'time ;; create timestamp when task is done
  764. org-blank-before-new-entry '((heading) (plain-list-item)))) ;; prevent new line before new item
  765. #+END_SRC
  766. ** languages
  767. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  768. +BEGIN_SRC emacs-lisp
  769. (org-babel-do-load-languages
  770. 'org-babel-load-languages
  771. '((emacs-lisp . t)
  772. (gnuplot . t)
  773. (js . t)
  774. (latex . t)
  775. (lisp . t)
  776. (python . t)
  777. (shell . t)
  778. (sqlite . t)
  779. (org . t)
  780. (R . t)
  781. (scheme . t)))
  782. (setq org-confirm-babel-evaluate nil)
  783. +END_SRC
  784. Another setup, because org-babel-do-load-languages requires eager loading
  785. #+begin_src emacs-lisp
  786. (use-package ob-org
  787. :defer t
  788. :ensure org-contrib
  789. :commands
  790. (org-babel-execute:org
  791. org-babel-expand-body:org))
  792. (use-package ob-python
  793. :defer t
  794. :ensure org-contrib
  795. :commands (org-babel-execute:python))
  796. (use-package ob-js
  797. :defer t
  798. :ensure org-contrib
  799. :commands (org-babel-execute:js))
  800. (use-package ob-shell
  801. :defer t
  802. :ensure org-contrib
  803. :commands
  804. (org-babel-execute:sh
  805. org-babel-expand-body:sh
  806. org-babel-execute:bash
  807. org-babel-expand-body:bash))
  808. (use-package ob-emacs-lisp
  809. :defer t
  810. :ensure org-contrib
  811. :commands
  812. (org-babel-execute:emacs-lisp
  813. org-babel-expand-body:emacs-lisp))
  814. (use-package ob-lisp
  815. :defer t
  816. :ensure org-contrib
  817. :commands
  818. (org-babel-execute:lisp
  819. org-babel-expand-body:lisp))
  820. (use-package ob-gnuplot
  821. :defer t
  822. :ensure org-contrib
  823. :commands
  824. (org-babel-execute:gnuplot
  825. org-babel-expand-body:gnuplot))
  826. (use-package ob-sqlite
  827. :defer t
  828. :ensure org-contrib
  829. :commands
  830. (org-babel-execute:sqlite
  831. org-babel-expand-body:sqlite))
  832. (use-package ob-latex
  833. :defer t
  834. :ensure org-contrib
  835. :commands
  836. (org-babel-execute:latex
  837. org-babel-expand-body:latex))
  838. (use-package ob-R
  839. :defer t
  840. :ensure org-contrib
  841. :commands
  842. (org-babel-execute:R
  843. org-babel-expand-body:R))
  844. (use-package ob-scheme
  845. :defer t
  846. :ensure org-contrib
  847. :commands
  848. (org-babel-execute:scheme
  849. org-babel-expand-body:scheme))
  850. #+end_src
  851. ** habits
  852. #+BEGIN_SRC emacs-lisp
  853. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  854. ;; (add-to-list 'org-modules "org-habit")
  855. (setq org-habit-graph-column 80
  856. org-habit-preceding-days 30
  857. org-habit-following-days 7
  858. org-habit-show-habits-only-for-today nil)
  859. #+END_SRC
  860. ** org-agenda
  861. Custom keywords, depending on environment
  862. #+BEGIN_SRC emacs-lisp
  863. (when *work_remote*
  864. (setq org-todo-keywords
  865. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  866. #+END_SRC
  867. Add some key bindings
  868. #+BEGIN_SRC emacs-lisp
  869. (bind-key "C-c l" 'org-store-link)
  870. (bind-key "C-c c" 'org-capture)
  871. (bind-key "C-c a" 'org-agenda)
  872. #+END_SRC
  873. Sort agenda by deadline and priority
  874. #+BEGIN_SRC emacs-lisp
  875. (setq org-agenda-sorting-strategy
  876. (quote
  877. ((agenda deadline-up priority-down)
  878. (todo priority-down category-keep)
  879. (tags priority-down category-keep)
  880. (search category-keep))))
  881. #+END_SRC
  882. Customize the org agenda
  883. #+BEGIN_SRC emacs-lisp
  884. (defun me--org-skip-subtree-if-priority (priority)
  885. "Skip an agenda subtree if it has a priority of PRIORITY.
  886. PRIORITY may be one of the characters ?A, ?B, or ?C."
  887. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  888. (pri-value (* 1000 (- org-lowest-priority priority)))
  889. (pri-current (org-get-priority (thing-at-point 'line t))))
  890. (if (= pri-value pri-current)
  891. subtree-end
  892. nil)))
  893. (setq org-agenda-custom-commands
  894. '(("c" "Simple agenda view"
  895. ((tags "PRIORITY=\"A\""
  896. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  897. (org-agenda-overriding-header "Hohe Priorität:")))
  898. (agenda ""
  899. ((org-agenda-span 7)
  900. (org-agenda-start-on-weekday nil)
  901. (org-agenda-overriding-header "Nächste 7 Tage:")))
  902. (alltodo ""
  903. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  904. (org-agenda-skip-if nil '(scheduled deadline))))
  905. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  906. #+END_SRC
  907. ** *TODO*
  908. [[https://github.com/alphapapa/org-ql][org-ql]]
  909. [[https://github.com/nobiot/org-transclusion][org-transclusion]]?
  910. ** org-caldav
  911. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  912. #+BEGIN_SRC emacs-lisp
  913. ;;(use-package org-caldav
  914. ;; :ensure t
  915. ;; :config
  916. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  917. ;; org-caldav-calendar-id "orgmode"
  918. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  919. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  920. #+END_SRC
  921. ** journal
  922. [[https://github.com/bastibe/org-journal][Source]]
  923. Ggf. durch org-roam-journal ersetzen
  924. #+BEGIN_SRC emacs-lisp
  925. (use-package org-journal
  926. :if *sys/linux*
  927. :ensure t
  928. :defer t
  929. :config
  930. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  931. (when (and (boundp 'org-journal-dir)
  932. (boundp 'org-journal-enable-agenda-integration))
  933. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  934. org-journal-enable-agenda-integration t)))
  935. #+END_SRC
  936. ** org-roam
  937. [[https://github.com/org-roam/org-roam][Github]]
  938. Um Headings innerhalb einer Datei zu verlinken:
  939. - org-id-get-create im Heading,
  940. - org-roam-node-insert in der verweisenden Datei
  941. Bei Problemen wie unique constraint
  942. org-roam-db-clear-all
  943. org-roam-db-sync
  944. #+BEGIN_SRC emacs-lisp
  945. (use-package org-roam
  946. :ensure t
  947. :defer t
  948. :after org
  949. :init
  950. (setq org-roam-v2-ack t)
  951. (defun me--buffer-roam-note-p ()
  952. "Return non-nil if the currently visited buffer is a note."
  953. (and buffer-file-name
  954. (string-prefix-p
  955. (expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM))
  956. (file-name-directory buffer-file-name))))
  957. (defun me/org-roam-filter-by-tag (tag-name)
  958. (lambda (node)
  959. (member tag-name (org-roam-node-tags node))))
  960. (defun me/org-roam-list-notes-by-tag (tag-name)
  961. (mapcar #'org-roam-node-file
  962. (seq-filter
  963. (me/org-roam-filter-by-tag tag-name)
  964. (org-roam-node-list))))
  965. (defun me/org-roam-refresh-agenda-list ()
  966. "Add all org roam files with #+filetags: Project"
  967. (interactive)
  968. (nconc org-agenda-files
  969. (me/org-roam-list-notes-by-tag "Project")))
  970. :config
  971. (require 'org-roam-dailies) ;; ensure the keymap is available
  972. (org-roam-db-autosync-mode)
  973. ;; build the agenda list the first ime for the session
  974. (me/org-roam-refresh-agenda-list)
  975. :custom
  976. (org-roam-directory MY--PATH_ORG_ROAM)
  977. (org-roam-completion-everywhere t)
  978. (org-roam-capture-templates
  979. '(("d" "default" plain
  980. "%?"
  981. :if-new (file+head "notes/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: ${title}\n")
  982. :unnarrowed t)
  983. ("n" "ndefault" plain
  984. "%?"
  985. :if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: ${title}\n")
  986. :unnarrowed t)
  987. ))
  988. :bind (("C-c n l" . org-roam-buffer-toggle)
  989. ("C-c n f" . org-roam-node-find)
  990. ("C-c n i" . org-roam-node-insert)
  991. :map org-mode-map
  992. ("C-M-i" . completion-at-point)
  993. :map org-roam-dailies-map
  994. ("Y" . org-roam-dailies-capture-yesterday)
  995. ("T" . org-roam-dailies-capture-tomorrow))
  996. :bind-keymap
  997. ("C-c n d" . org-roam-dailies-map))
  998. (use-package org-roam
  999. :if (eq *sys/windows* t)
  1000. :init
  1001. (setq exec-path (append exec-path '("P:/Tools/sqlite")))
  1002. (use-package emacsql-sqlite3
  1003. :ensure t
  1004. :init
  1005. (setq emacsql-sqlite3-binary "P:/Tools/sqlite/sqlite3.exe"))
  1006. :config
  1007. (add-to-list 'org-roam-capture-templates
  1008. '("t" "telephone call" plain
  1009. "%?"
  1010. :if-new (file+head "telephone/%<%Y%m%d%H%M%S>-${plug}.org" "#+title: CALL %<%Y-%m-%d %H:%M> ${title}\n")
  1011. :unnarrowed t) t)
  1012. (add-to-list 'org-roam-capture-templates
  1013. '("p" "new Project" plain
  1014. "** ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1015. :target (file+olp "projects.org" ("Active"))) t)
  1016. (add-to-list 'org-roam-capture-templates
  1017. '("s" "Sicherheitenmeldung" plain
  1018. "*** TODO [#A] Sicherheitenmeldung ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1019. :target (file+olp "tasks.org" ("Todos" "Sicherheitenmeldungen"))) t)
  1020. (add-to-list 'org-roam-capture-templates
  1021. '("m" "Monatsbericht" plain'
  1022. "*** TODO [#A] Monatsbericht ${title}\n :PROPERTIES:\n :ID: %(org-id-uuid)\n:END:\n%u\n"
  1023. :target (file+olp "tasks.org" ("Todos" "Monatsberichte"))) t)
  1024. :custom
  1025. (org-roam-database-connector 'sqlite3))
  1026. #+END_SRC
  1027. *** TODO Verzeichnis außerhalb roam zum Archivieren (u.a. für erledigte Monatsmeldungen etc.)
  1028. * Programming
  1029. ** misc
  1030. #+begin_src emacs-lisp
  1031. (use-package eldoc
  1032. :diminish eldoc-mode
  1033. :defer t)
  1034. #+end_src
  1035. ** Magit / Git
  1036. Little crash course in magit:
  1037. - magit-init to init a git project
  1038. - magit-status (C-x g) to call the status window
  1039. In status buffer:
  1040. - s stage files
  1041. - u unstage files
  1042. - U unstage all files
  1043. - a apply changes to staging
  1044. - c c commit (type commit message, then C-c C-c to commit)
  1045. - b b switch to another branch
  1046. - P u git push
  1047. - F u git pull
  1048. #+BEGIN_SRC emacs-lisp
  1049. (use-package magit
  1050. :ensure t
  1051. :pin melpa-stable
  1052. :defer t
  1053. :init
  1054. ; set git-path in work environment
  1055. (if (string-equal user-login-name "POH")
  1056. (setq magit-git-executable "P:/Tools/Git/bin/git.exe")
  1057. )
  1058. :bind (("C-x g" . magit-status)))
  1059. #+END_SRC
  1060. ** LSP
  1061. Configuration for the language server protocol
  1062. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  1063. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  1064. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  1065. TODO Unterverzeichnisse wurden noch nicht getestet
  1066. #+BEGIN_SRC emacs-lisp
  1067. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  1068. (use-package lsp-mode
  1069. :defer t
  1070. :commands (lsp lsp-execute-code-action)
  1071. :custom
  1072. (lsp-auto-guess-root nil)
  1073. (lsp-prefer-flymake nil) ; use flycheck instead
  1074. (lsp-prefer-capf t)
  1075. (lsp-file-watch-threshold 5000)
  1076. (lsp-print-performance t)
  1077. (lsp-log-io nil) ; enable log only for debug
  1078. (lsp-enable-folding t) ; default, maybe evil-matchit instead for performance?
  1079. (lsp-diagnostics-modeline-scope :project)
  1080. (lsp-enable-file-watchers nil)
  1081. (lsp-session-file (concat MY--PATH_USER_LOCAL "lsp-session"))
  1082. (lsp-eslint-library-choices-file (concat MY--PATH_USER_LOCAL "lsp-eslint-choices"))
  1083. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  1084. :hook
  1085. (((python-mode
  1086. js-mode
  1087. js2-mode
  1088. typescript-mode
  1089. web-mode
  1090. ) . lsp-deferred)
  1091. (lsp-mode . lsp-enable-which-key-integration)
  1092. (lsp-mode . lsp-diagnostics-modeline-mode)
  1093. (web-mode . #'lsp-flycheck-enable)) ;; enable flycheck-lsp for web-mode locally
  1094. :config
  1095. (setq lsp-diagnostics-package :none)) ; disable flycheck-lsp for most modes
  1096. ;; (add-hook 'web-mode-hook #'lsp-flycheck-enable)) ; enable flycheck-lsp for web-mode locally
  1097. (use-package lsp-ui
  1098. :after lsp-mode
  1099. :ensure t
  1100. :defer t
  1101. :diminish
  1102. :commands lsp-ui-mode
  1103. :config
  1104. (setq lsp-ui-doc-enable t
  1105. lsp-ui-doc-header t
  1106. lsp-ui-doc-include-signature t
  1107. lsp-ui-doc-position 'top
  1108. lsp-ui-doc-border (face-foreground 'default)
  1109. lsp-ui-sideline-enable t
  1110. lsp-ui-sideline-ignore-duplicate t
  1111. lsp-ui-sideline-show-code-actions nil)
  1112. (when *sys/gui*
  1113. (setq lsp-ui-doc-use-webkit t))
  1114. ;; workaround hide mode-line of lsp-ui-imenu buffer
  1115. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  1116. (setq mode-line-format nil)))
  1117. ;;NO LONGER SUPPORTED, USE company-capf / completion-at-point
  1118. ;(use-package company-lsp
  1119. ; :requires company
  1120. ; :defer t
  1121. ; :ensure t
  1122. ; :config
  1123. ; ;;disable client-side cache because lsp server does a better job
  1124. ; (setq company-transformers nil
  1125. ; company-lsp-async t
  1126. ; company-lsp-cache-candidates nil))
  1127. #+END_SRC
  1128. ** yasnippet
  1129. For useful snippet either install yasnippet-snippets or get them from here
  1130. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1131. #+begin_src emacs-lisp
  1132. (use-package yasnippet
  1133. :ensure t
  1134. :defer t
  1135. :diminish yas-minor-mode
  1136. :config
  1137. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1138. (yas-global-mode t)
  1139. (yas-reload-all)
  1140. (unbind-key "TAB" yas-minor-mode-map)
  1141. (unbind-key "<tab>" yas-minor-mode-map))
  1142. #+end_src
  1143. ** hippie expand
  1144. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1145. #+begin_src emacs-lisp
  1146. (use-package hippie-exp
  1147. :defer t
  1148. :bind
  1149. ("C-<return>" . hippie-expand)
  1150. :config
  1151. (setq hippie-expand-try-functions-list
  1152. '(yas-hippie-try-expand emmet-expand-line)))
  1153. #+end_src
  1154. ** flycheck
  1155. #+BEGIN_SRC emacs-lisp
  1156. (use-package flycheck
  1157. :ensure t
  1158. :hook
  1159. ((css-mode . flycheck-mode)
  1160. (emacs-lisp-mode . flycheck-mode)
  1161. (python-mode . flycheck-mode))
  1162. :defer 1.0
  1163. :init
  1164. (setq flycheck-emacs-lisp-load-path 'inherit)
  1165. :config
  1166. (setq-default
  1167. flycheck-check-synta-automatically '(save mode-enabled)
  1168. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1169. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1170. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1171. #+END_SRC
  1172. ** Projectile
  1173. Manage projects and jump quickly between its files
  1174. #+BEGIN_SRC emacs-lisp
  1175. (use-package projectile
  1176. :ensure t
  1177. ; :defer 1.0
  1178. :diminish
  1179. :bind
  1180. (("C-c p" . projectile-command-map))
  1181. ;:preface
  1182. :init
  1183. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL "projectile-cache")
  1184. projectile-known-projects-file (concat MY--PATH_USER_LOCAL "projectile-bookmarks"))
  1185. :config
  1186. (projectile-mode)
  1187. ; (add-hook 'projectile-after-switch-project-hook #'set-workon_home)
  1188. (setq-default projectile-completion-system 'ivy
  1189. projectile-enable-caching t
  1190. projectile-mode-line '(:eval (projectile-project-name))))
  1191. ;; requires ripgrep on system for rg functions
  1192. ;(use-package counsel-projectile
  1193. ; :ensure t
  1194. ; :config (counsel-projectile-mode) (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer)
  1195. ;(use-package helm-projectile
  1196. ; :ensure t
  1197. ; :hook
  1198. ; (projectile-mode . helm-projectile))
  1199. #+END_SRC
  1200. ** smartparens
  1201. #+BEGIN_SRC emacs-lisp
  1202. (use-package smartparens
  1203. :ensure t
  1204. :diminish smartparens-mode
  1205. :bind
  1206. (:map smartparens-mode-map
  1207. ("C-M-f" . sp-forward-sexp)
  1208. ("C-M-b" . sp-backward-sexp)
  1209. ("C-M-a" . sp-backward-down-sexp)
  1210. ("C-M-e" . sp-up-sexp)
  1211. ("C-M-w" . sp-copy-sexp)
  1212. ("M-k" . sp-kill-sexp)
  1213. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1214. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1215. ("C-]" . sp-select-next-thing-exchange))
  1216. :config
  1217. (setq sp-show-pair-from-inside nil
  1218. sp-escape-quotes-after-insert nil)
  1219. (require 'smartparens-config))
  1220. #+END_SRC
  1221. ** lisp
  1222. #+BEGIN_SRC emacs-lisp
  1223. (use-package elisp-mode
  1224. :defer t)
  1225. #+END_SRC
  1226. ** web
  1227. apt install npm
  1228. sudo npm install -g vscode-html-languageserver-bin
  1229. evtl alternativ typescript-language-server?
  1230. Unter Windows:
  1231. Hier runterladen: https://nodejs.org/dist/latest/
  1232. und in ein Verzeichnis entpacken.
  1233. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1234. PATH=P:\path\to\node;%path%
  1235. #+BEGIN_SRC emacs-lisp
  1236. (use-package web-mode
  1237. :ensure t
  1238. :defer t
  1239. :mode
  1240. ("\\.phtml\\'"
  1241. "\\.tpl\\.php\\'"
  1242. "\\.djhtml\\'"
  1243. "\\.[t]?html?\\'")
  1244. :hook
  1245. (web-mode . smartparens-mode)
  1246. :init
  1247. (if *work_remote*
  1248. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1249. :config
  1250. (setq web-mode-enable-auto-closing t
  1251. web-mode-enable-auto-pairing t))
  1252. #+END_SRC
  1253. Emmet offers snippets, similar to yasnippet.
  1254. Default completion is C-j
  1255. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1256. #+begin_src emacs-lisp
  1257. (use-package emmet-mode
  1258. :ensure t
  1259. :defer t
  1260. :hook
  1261. ((web-mode . emmet-mode)
  1262. (css-mode . emmet-mode))
  1263. :config
  1264. (unbind-key "C-<return>" emmet-mode-keymap))
  1265. #+end_src
  1266. *** JavaScript
  1267. npm install -g typescript-language-server typescript
  1268. maybe only typescript?
  1269. npm install -g prettier
  1270. #+begin_src emacs-lisp
  1271. (use-package rjsx-mode
  1272. :ensure t
  1273. :mode ("\\.js\\'"
  1274. "\\.jsx'"))
  1275. ; :config
  1276. ; (setq js2-mode-show-parse-errors nil
  1277. ; js2-mode-show-strict-warnings nil
  1278. ; js2-basic-offset 2
  1279. ; js-indent-level 2)
  1280. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1281. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1282. (use-package tide
  1283. :ensure t
  1284. :after (rjsx-mode company flycheck)
  1285. ; :hook (rjsx-mode . setup-tide-mode)
  1286. :config
  1287. (defun setup-tide-mode ()
  1288. "Setup function for tide."
  1289. (interactive)
  1290. (tide-setup)
  1291. (flycheck-mode t)
  1292. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1293. (tide-hl-identifier-mode t)))
  1294. ;; needs npm install -g prettier
  1295. (use-package prettier-js
  1296. :ensure t
  1297. :after (rjsx-mode)
  1298. :defer t
  1299. :diminish prettier-js-mode
  1300. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1301. #+end_src
  1302. ** YAML
  1303. #+begin_src emacs-lisp
  1304. (use-package yaml-mode
  1305. :if *sys/linux*
  1306. :ensure t
  1307. :defer t
  1308. :mode ("\\.yml$" . yaml-mode))
  1309. #+end_src
  1310. ** R
  1311. #+BEGIN_SRC emacs-lisp
  1312. (use-package ess
  1313. :ensure t
  1314. :defer t
  1315. :init
  1316. (if *work_remote*
  1317. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1318. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1319. #+END_SRC
  1320. ** Python
  1321. Systemseitig muss python-language-server installiert sein:
  1322. apt install python3-pip python3-setuptools python3-wheel
  1323. apt install build-essential python3-dev
  1324. pip3 install 'python-language-server[all]'
  1325. Statt obiges: npm install -g pyright
  1326. für andere language servers
  1327. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1328. #+BEGIN_SRC emacs-lisp
  1329. ;(use-package lsp-python-ms
  1330. ; :if *sys/linux*
  1331. ; :ensure t
  1332. ; :defer t
  1333. ; :custom (lsp-python-ms-auto-install-server t))
  1334. (use-package lsp-pyright
  1335. :ensure t
  1336. :after lsp-mode
  1337. :defer t
  1338. :hook
  1339. (python-mode . (lambda ()
  1340. (require 'lsp-pyright)
  1341. (lsp-deferred)))
  1342. ; :custom
  1343. ; (lsp-pyright-auto-import-completions nil)
  1344. ; (lsp-pyright-typechecking-mode "off")
  1345. )
  1346. (use-package python
  1347. :if *sys/linux*
  1348. :delight "π "
  1349. :defer t
  1350. :bind (("M-[" . python-nav-backward-block)
  1351. ("M-]" . python-nav-forward-block)))
  1352. (use-package pyvenv
  1353. :if *sys/linux*
  1354. :ensure t
  1355. :defer t
  1356. :after python
  1357. :hook ((python-mode . pyvenv-mode)
  1358. (python-mode . (lambda ()
  1359. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  1360. (pyvenv-activate pyvenv-directory))
  1361. (lsp))))
  1362. :custom
  1363. (pyvenv-default-virtual-env-name "env")
  1364. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  1365. :preface
  1366. (defun find-pyvenv-directory (path)
  1367. "Check if a pyvenv directory exists."
  1368. (cond
  1369. ((not path) nil)
  1370. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  1371. ((file-directory-p path)
  1372. (or
  1373. (seq-find
  1374. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  1375. (directory-files path t))
  1376. (let ((parent (file-name-directory (directory-file-name path))))
  1377. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  1378. ;; manage multiple python version
  1379. ;; needs to be installed on system
  1380. ; (use-package pyenv-mode
  1381. ; :ensure t
  1382. ; :after python
  1383. ; :hook ((python-mode . pyenv-mode)
  1384. ; (projectile-switch-project . projectile-pyenv-mode-set))
  1385. ; :custom (pyenv-mode-set "3.8.5")
  1386. ; :preface
  1387. ; (defun projectile-pyenv-mode-set ()
  1388. ; "Set pyenv version matching project name."
  1389. ; (let ((project (projectile-project-name)))
  1390. ; (if (member project (pyenv-mode-versions))
  1391. ; (pyenv-mode-set project)
  1392. ; (pyenv-mode-unset)))))
  1393. ;)
  1394. #+END_SRC
  1395. * beancount
  1396. ** Installation
  1397. #+BEGIN_SRC shell :tangle no
  1398. sudo su
  1399. cd /opt
  1400. python3 -m venv beancount
  1401. source ./beancount/bin/activate
  1402. pip3 install wheel
  1403. pip3 install beancount
  1404. sleep 100
  1405. echo "shell running!"
  1406. deactivate
  1407. #+END_SRC
  1408. #+BEGIN_SRC emacs-lisp
  1409. (use-package beancount
  1410. :if *sys/linux*
  1411. :load-path "user-global/elisp"
  1412. ; :ensure t
  1413. :defer t
  1414. :mode
  1415. ("\\.beancount$" . beancount-mode)
  1416. :hook
  1417. (beancount-mode . me/beancount-company)
  1418. :init
  1419. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1420. :config
  1421. (defun me/beancount-company ()
  1422. (set (make-local-variable 'company-backends)
  1423. '(company-beancount)))
  1424. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1425. #+END_SRC
  1426. To support org-babel, check if it can find the symlink to ob-beancount.el
  1427. #+BEGIN_SRC shell :tangle no
  1428. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1429. beansym="$orgpath/ob-beancount.el
  1430. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1431. if [ -h "$beansym" ]
  1432. then
  1433. echo "$beansym found"
  1434. elif [ -e "$bean" ]
  1435. then
  1436. echo "creating symlink"
  1437. ln -s "$bean" "$beansym"
  1438. else
  1439. echo "$bean not found, symlink creation aborted"
  1440. fi
  1441. #+END_SRC
  1442. Fava is strongly recommended.
  1443. #+BEGIN_SRC shell :tangle no
  1444. cd /opt
  1445. python3 -m venv fava
  1446. source ./fava/bin/activate
  1447. pip3 install wheel
  1448. pip3 install fava
  1449. deactivate
  1450. #+END_SRC
  1451. Start fava with fava my_file.beancount
  1452. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1453. Beancount-mode can start fava and open the URL right away.
  1454. * Stuff after everything else
  1455. Set garbage collector to a smaller value to let it kick in faster.
  1456. Maybe a problem on Windows?
  1457. #+begin_src emacs-lisp
  1458. ;(setq gc-cons-threshold (* 2 1000 1000))
  1459. #+end_src