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.

1577 lines
45 KiB

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