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.

1592 lines
44 KiB

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