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.

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