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.

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