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.

1584 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. (use-package rainbow-delimiters
  345. :ensure t
  346. :hook
  347. (prog-mode . rainbow-delimiters-mode))
  348. #+END_SRC
  349. * Bookmarks
  350. Usage:
  351. - C-x r m (bookmark-set): add bookmark
  352. - C-x r l (list-bookmark): list bookmarks
  353. - C-x r b (bookmark-jump): open bookmark
  354. Edit bookmarks (while in bookmark file):
  355. - d: mark current item
  356. - x: delete marked items
  357. - r: rename current item
  358. - s: save changes
  359. #+begin_src emacs-lisp
  360. (use-package bookmark
  361. :custom
  362. (bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks")))
  363. #+end_src
  364. Some windows specific stuff
  365. #+BEGIN_SRC emacs-lisp
  366. (when *sys/windows*
  367. (remove-hook 'find-file-hook 'vc-refresh-state)
  368. ; (progn
  369. ; (setq gc-cons-threshold (* 511 1024 1024)
  370. ; gc-cons-percentage 0.5
  371. ; garbage-collection-messages t)
  372. ; (run-with-idle-timer 5 t #'garbage-collect))
  373. (when (boundp 'w32-pipe-read-delay)
  374. (setq w32-pipe-read-delay 0))
  375. (when (boundp 'w32-get-true-file-attributes)
  376. (setq w32-get-true-file-attributes nil)))
  377. #+END_SRC
  378. * recentf
  379. Exclude some dirs from spamming recentf
  380. #+begin_src emacs-lisp
  381. (use-package recentf
  382. :config
  383. (recentf-mode)
  384. :custom
  385. (recentf-exclude '(".*-autoloads\\.el\\'"
  386. "[/\\]\\elpa/"
  387. "COMMIT_EDITMSG\\'"))
  388. (recentf-save-file (concat MY--PATH_USER_LOCAL "recentf"))
  389. (recentf-max-menu-items 600)
  390. (recentf-max-saved-items 600))
  391. #+end_src
  392. * undo
  393. :PROPERTIES:
  394. :ID: d57621b2-5472-4c89-a520-b4133db0b9af
  395. :END:
  396. #+BEGIN_SRC emacs-lisp
  397. (use-package undo-tree
  398. :ensure t
  399. :diminish undo-tree-mode
  400. :init
  401. (global-undo-tree-mode 1))
  402. #+END_SRC
  403. * ace-window
  404. #+begin_src emacs-lisp
  405. (use-package ace-window
  406. :ensure t
  407. :bind
  408. (:map global-map
  409. ("C-x o" . ace-window)))
  410. #+end_src
  411. * imenu-list
  412. :PROPERTIES:
  413. :ID: 0ae27ec9-5d77-43cf-ac76-5e12cc959046
  414. :END:
  415. A minor mode to show imenu in a sidebar.
  416. Call imenu-list-smart-toggle.
  417. [[https://github.com/bmag/imenu-list][Source]]
  418. #+BEGIN_SRC emacs-lisp
  419. (use-package imenu-list
  420. :ensure t
  421. :demand t ; otherwise mode loads too late and won't work on first file it's being activated on
  422. :config
  423. (setq imenu-list-focus-after-activation t
  424. imenu-list-auto-resize t
  425. imenu-list-position 'right)
  426. :bind
  427. (:map global-map
  428. ([f9] . imenu-list-smart-toggle))
  429. :custom
  430. (org-imenu-depth 4))
  431. #+END_SRC
  432. * which-key
  433. :PROPERTIES:
  434. :ID: a880f079-b3a3-4706-bf1e-5f6c680101f1
  435. :END:
  436. #+BEGIN_SRC emacs-lisp
  437. (use-package which-key
  438. :ensure t
  439. :diminish which-key-mode
  440. :defer t
  441. :hook
  442. (after-init . which-key-mode)
  443. :config
  444. (which-key-setup-side-window-bottom)
  445. (setq which-key-idle-delay 0.5))
  446. #+END_SRC
  447. * abbrev
  448. #+begin_src emacs-lisp
  449. (use-package abbrev
  450. :diminish abbrev-mode
  451. :hook
  452. ((text-mode org-mode) . abbrev-mode)
  453. :init
  454. (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_tables.el"))
  455. :config
  456. (if (file-exists-p abbrev-file-name)
  457. (quietly-read-abbrev-file))
  458. (setq save-abbrevs 'silently)) ;; don't bother me with asking for abbrev saving
  459. #+end_src
  460. * Evil
  461. :PROPERTIES:
  462. :ID: 80ca70e2-a146-46db-b581-418d655dc1fc
  463. :END:
  464. #+BEGIN_SRC emacs-lisp
  465. (use-package evil
  466. :ensure t
  467. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  468. :config
  469. (evil-mode 1))
  470. #+END_SRC
  471. * General (key mapper)
  472. :PROPERTIES:
  473. :ID: a20f183f-d41a-4dff-bc37-3bc4e25c8036
  474. :END:
  475. #+BEGIN_SRC emacs-lisp
  476. (use-package general
  477. :ensure t)
  478. (general-define-key
  479. :states 'normal
  480. :keymaps 'imenu-list-major-mode-map
  481. "RET" '(imenu-list-goto-entry :which-key "goto")
  482. "TAB" '(hs-toggle-hiding :which-key "collapse")
  483. "d" '(imenu-list-display-entry :which-key "show")
  484. "q" '(imenu-list-quit-window :which-key "quit"))
  485. #+END_SRC
  486. * ivy / counsel / swiper
  487. :PROPERTIES:
  488. :ID: 55c74ba9-7761-4545-8ddd-087d6ee33e4b
  489. :END:
  490. +BEGIN_SRC emacs-lisp
  491. ; (require 'ivy)
  492. (use-package ivy
  493. :ensure t
  494. :diminish
  495. (ivy-mode . "")
  496. :defer t
  497. :init
  498. (ivy-mode 1)
  499. :bind
  500. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  501. :config
  502. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  503. ivy-height 20 ;; height of ivy window
  504. ivy-count-format "%d/%d" ;; current and total number
  505. ivy-re-builders-alist ;; regex replaces spaces with *
  506. '((t . ivy--regex-plus))))
  507. ; make counsel-M-x more descriptive
  508. (use-package ivy-rich
  509. :ensure t
  510. :defer t
  511. :init
  512. (ivy-rich-mode 1))
  513. (use-package counsel
  514. :ensure t
  515. :defer t
  516. :bind
  517. (("M-x" . counsel-M-x)
  518. ("C-x C-f" . counsel-find-file)
  519. ("C-x C-r" . counsel-recentf)
  520. ("C-x b" . counsel-switch-buffer)
  521. ("C-c C-f" . counsel-git)
  522. ("C-c h f" . counsel-describe-function)
  523. ("C-c h v" . counsel-describe-variable)
  524. ("M-i" . counsel-imenu)))
  525. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  526. ; ("C-r" . 'counsel-minibuffer-history)))
  527. (use-package swiper
  528. :ensure t
  529. :bind
  530. ("C-s" . swiper))
  531. (use-package ivy-hydra
  532. :ensure t)
  533. +END_SRC
  534. * Helm
  535. As an alternative to ivy/counsel/swiper?
  536. +begin_src emacs-lisp
  537. (use-package helm
  538. :ensure t
  539. :hook
  540. (helm-mode . helm-autoresize-mode)
  541. :bind
  542. (("M-x" . helm-M-x)
  543. ("C-s" . helm-occur)
  544. ("C-x C-f" . helm-find-files)
  545. ("C-x C-b" . helm-buffers-list)
  546. ("C-x b" . helm-buffers-list)
  547. ("C-x C-r" . helm-recentf)
  548. ("C-x C-i" . helm-imenu))
  549. :config
  550. (helm-mode)
  551. :custom
  552. (helm-split-window-inside-p t) ;; open helm buffer inside current window
  553. (helm-move-to-line-cycle-in-source t)
  554. (helm-echo-input-in-header-line t)
  555. (helm-autoresize-max-height 20)
  556. (helm-autoresize-min-height 5)
  557. )
  558. +end_src
  559. * Selectrum & Co.
  560. Uses default features of emacs instead of bringing a new framework in like helm or counsel
  561. #+begin_src emacs-lisp
  562. ;; either selectrum or vertico
  563. (use-package selectrum
  564. :ensure t
  565. :config
  566. (selectrum-mode)
  567. )
  568. ;; as of 2021-10-29 debian emacs 27.1 seems to cause error
  569. ;; error in post-command-hook (vertico--exhibit): (wrong-type-argument .....)
  570. ;; see https://github.com/minad/vertico/issues/41
  571. ;(use-package vertico
  572. ; :ensure t
  573. ; :init
  574. ; (vertico-mode))
  575. ;; orderless orders by recency
  576. ;; prescient orders by frequency
  577. ;; both combined order by frecency (most recent first, then by frequency, then by length)
  578. (use-package orderless
  579. :ensure t
  580. :config
  581. ;; optional performance optimizaion
  582. ;; by highlighting only visible candidates
  583. (setq orderless-skip-highlighting (lambda () selectrum-is-active)
  584. selectrum-highlight-candidates-function #'orderless-highlight-matches
  585. completion-category-defaults nil
  586. completion-category-overrides '((file (styles . (partial-completion)))))
  587. :custom
  588. (completion-styles '(orderless))
  589. (savehist-mode)
  590. )
  591. (use-package selectrum-prescient
  592. :ensure t
  593. :config
  594. (setq selectrum-prescient-enable-filtering nil) ; only if used with orderless
  595. (selectrum-prescient-mode)
  596. (prescient-persist-mode)
  597. )
  598. (use-package consult
  599. :ensure t
  600. :bind
  601. (("C-x C-r" . consult-recent-file)
  602. ("C-x b" . consult-buffer)
  603. ("C-s" . consult-line))
  604. )
  605. ;; shows descriptions in M-x
  606. (use-package marginalia
  607. :ensure t
  608. :config
  609. (marginalia-mode)
  610. :custom
  611. ;; switch by 'marginalia-cycle
  612. (marginalia-annotators '(marginalia-annotators-heavy
  613. marginalia-annotators-light
  614. nil))
  615. )
  616. ;; do stuff on minibuffer results
  617. (use-package embark
  618. :ensure t
  619. :bind
  620. (("C-S-a" . embark-act)
  621. ("C-h B" . embark-bindings))
  622. :init
  623. (setq prefix-help-command #'embark-prefix-help-command)
  624. :config
  625. ;; hide modeline of the embark live/completions buffers
  626. (add-to-list 'display-buffer-alist
  627. '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
  628. nil
  629. (window-parameters (mode-line-format . none))))
  630. )
  631. (use-package embark-consult
  632. :ensure t
  633. :after (embark consult)
  634. :demand t
  635. :hook
  636. (embark-collect-mode . embark-consult-preview-minor-mode))
  637. #+end_src
  638. * misc
  639. #+begin_src emacs-lisp
  640. (use-package autorevert
  641. :diminish auto-revert-mode)
  642. #+end_src
  643. * company
  644. :PROPERTIES:
  645. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  646. :END:
  647. #+BEGIN_SRC emacs-lisp
  648. (use-package company
  649. :defer 1
  650. :diminish
  651. :defer t
  652. :bind
  653. (("C-<tab>" . company-complete)
  654. :map company-active-map
  655. ("RET" . nil)
  656. ([return] . nil)
  657. ("TAB" . company-complete-selection)
  658. ([tab] . company-complete-selection)
  659. ("<right>" . company-complete-common)
  660. ("<escape>" . company-abort))
  661. :hook
  662. (after-init . global-company-mode)
  663. (emacs-lisp-mode . me/company-elisp)
  664. (org-mode . me/company-org)
  665. :config
  666. (defun me/company-elisp ()
  667. (message "set up company for elisp")
  668. (set (make-local-variable 'company-backends)
  669. '(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp
  670. company-yasnippet
  671. company-dabbrev-code
  672. company-files)))
  673. (defun me/company-org ()
  674. (set (make-local-variable 'company-backends)
  675. '(company-capf company-files))
  676. ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  677. (message "setup company for org"))
  678. (setq company-idle-delay .2
  679. company-minimum-prefix-length 1
  680. company-require-match nil
  681. company-show-numbers t
  682. company-tooltip-align-annotations t))
  683. (use-package company-statistics
  684. :ensure t
  685. :after company
  686. :defer t
  687. :init
  688. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  689. :config
  690. (company-statistics-mode 1))
  691. (use-package company-dabbrev
  692. :ensure nil
  693. :after company
  694. :defer t
  695. :config
  696. (setq-default company-dabbrev-downcase nil))
  697. ;; adds a info box right of the cursor with doc of the function
  698. (use-package company-box
  699. :ensure t
  700. :diminish
  701. :defer t
  702. :hook
  703. (company-mode . company-box-mode))
  704. ; :init
  705. ; (add-hook 'company-mode-hook 'company-box-mode))
  706. #+END_SRC
  707. * orgmode
  708. ** org
  709. :PROPERTIES:
  710. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  711. :END:
  712. #+BEGIN_SRC emacs-lisp
  713. (use-package org
  714. :ensure org-plus-contrib
  715. :mode (("\.org$" . org-mode))
  716. :diminish org-indent-mode
  717. :defer t
  718. :hook
  719. (org-mode . org-indent-mode)
  720. (org-source-mode . smartparens-mode)
  721. ; :init
  722. ; (add-hook 'org-mode-hook 'company/org-mode-hook)
  723. ; (add-hook 'org-src-mode-hook 'smartparens-mode)
  724. ; (add-hook 'org-mode-hook 'org-indent-mode)
  725. :config
  726. (defun me/org-company ()
  727. (set (make-local-variable 'company-backends)
  728. '(company-capf company-files))
  729. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  730. (message "company/org-mode-hook"))
  731. (setq org-modules (quote (org-id
  732. org-habit
  733. org-tempo ;; easy templates
  734. )))
  735. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  736. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  737. (concat MY--PATH_ORG_FILES "projects.org")
  738. (concat MY--PATH_ORG_FILES "tasks.org")))
  739. (when *sys/linux*
  740. (nconc org-agenda-files
  741. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  742. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  743. org-log-into-drawer "LOGBOOK")
  744. ;; some display customizations
  745. (setq org-pretty-entities t
  746. org-startup-truncated t
  747. org-startup-align-all-tables t)
  748. ;; some source code blocks customizations
  749. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  750. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  751. org-src-preserve-indentation t ;; no extra indentation
  752. org-src-tab-acts-natively t)
  753. (setq org-log-done 'time)) ;; create timestamp when task is done
  754. #+END_SRC
  755. ** languages
  756. :PROPERTIES:
  757. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  758. :END:
  759. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  760. +BEGIN_SRC emacs-lisp
  761. (org-babel-do-load-languages
  762. 'org-babel-load-languages
  763. '((emacs-lisp . t)
  764. (gnuplot . t)
  765. (js . t)
  766. (latex . t)
  767. (lisp . t)
  768. (python . t)
  769. (shell . t)
  770. (sqlite . t)
  771. (org . t)
  772. (R . t)
  773. (scheme . t)))
  774. (setq org-confirm-babel-evaluate nil)
  775. +END_SRC
  776. Another setup, because org-babel-do-load-languages requires eager loading
  777. #+begin_src emacs-lisp
  778. (use-package ob-org
  779. :defer t
  780. :ensure org-plus-contrib
  781. :commands
  782. (org-babel-execute:org
  783. org-babel-expand-body:org))
  784. (use-package ob-python
  785. :defer t
  786. :ensure org-plus-contrib
  787. :commands (org-babel-execute:python))
  788. (use-package ob-js
  789. :defer t
  790. :ensure org-plus-contrib
  791. :commands (org-babel-execute:js))
  792. (use-package ob-shell
  793. :defer t
  794. :ensure org-plus-contrib
  795. :commands
  796. (org-babel-execute:sh
  797. org-babel-expand-body:sh
  798. org-babel-execute:bash
  799. org-babel-expand-body:bash))
  800. (use-package ob-emacs-lisp
  801. :defer t
  802. :ensure org-plus-contrib
  803. :commands
  804. (org-babel-execute:emacs-lisp
  805. org-babel-expand-body:emacs-lisp))
  806. (use-package ob-lisp
  807. :defer t
  808. :ensure org-plus-contrib
  809. :commands
  810. (org-babel-execute:lisp
  811. org-babel-expand-body:lisp))
  812. (use-package ob-gnuplot
  813. :defer t
  814. :ensure org-plus-contrib
  815. :commands
  816. (org-babel-execute:gnuplot
  817. org-babel-expand-body:gnuplot))
  818. (use-package ob-sqlite
  819. :defer t
  820. :ensure org-plus-contrib
  821. :commands
  822. (org-babel-execute:sqlite
  823. org-babel-expand-body:sqlite))
  824. (use-package ob-latex
  825. :defer t
  826. :ensure org-plus-contrib
  827. :commands
  828. (org-babel-execute:latex
  829. org-babel-expand-body:latex))
  830. (use-package ob-R
  831. :defer t
  832. :ensure org-plus-contrib
  833. :commands
  834. (org-babel-execute:R
  835. org-babel-expand-body:R))
  836. (use-package ob-scheme
  837. :defer t
  838. :ensure org-plus-contrib
  839. :commands
  840. (org-babel-execute:scheme
  841. org-babel-expand-body:scheme))
  842. #+end_src
  843. ** habits
  844. :PROPERTIES:
  845. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  846. :END:
  847. #+BEGIN_SRC emacs-lisp
  848. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  849. ;; (add-to-list 'org-modules "org-habit")
  850. (setq org-habit-graph-column 80
  851. org-habit-preceding-days 30
  852. org-habit-following-days 7
  853. org-habit-show-habits-only-for-today nil)
  854. #+END_SRC
  855. ** org-id
  856. :PROPERTIES:
  857. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  858. :END:
  859. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  860. #+BEGIN_SRC emacs-lisp
  861. ;; (use-package org-id
  862. ;; :config
  863. ;; (setq org-id-link-to-org-use-id t)
  864. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  865. #+END_SRC
  866. ** org-agenda
  867. :PROPERTIES:
  868. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  869. :END:
  870. Custom keywords, depending on environment
  871. #+BEGIN_SRC emacs-lisp
  872. (when *work_remote*
  873. (setq org-todo-keywords
  874. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  875. #+END_SRC
  876. Add some key bindings
  877. #+BEGIN_SRC emacs-lisp
  878. (bind-key "C-c l" 'org-store-link)
  879. (bind-key "C-c c" 'org-capture)
  880. (bind-key "C-c a" 'org-agenda)
  881. #+END_SRC
  882. Sort agenda by deadline and priority
  883. #+BEGIN_SRC emacs-lisp
  884. (setq org-agenda-sorting-strategy
  885. (quote
  886. ((agenda deadline-up priority-down)
  887. (todo priority-down category-keep)
  888. (tags priority-down category-keep)
  889. (search category-keep))))
  890. #+END_SRC
  891. Customize the org agenda
  892. #+BEGIN_SRC emacs-lisp
  893. (defun me--org-skip-subtree-if-priority (priority)
  894. "Skip an agenda subtree if it has a priority of PRIORITY.
  895. PRIORITY may be one of the characters ?A, ?B, or ?C."
  896. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  897. (pri-value (* 1000 (- org-lowest-priority priority)))
  898. (pri-current (org-get-priority (thing-at-point 'line t))))
  899. (if (= pri-value pri-current)
  900. subtree-end
  901. nil)))
  902. (setq org-agenda-custom-commands
  903. '(("c" "Simple agenda view"
  904. ((tags "PRIORITY=\"A\""
  905. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  906. (org-agenda-overriding-header "Hohe Priorität:")))
  907. (agenda ""
  908. ((org-agenda-span 7)
  909. (org-agenda-start-on-weekday nil)
  910. (org-agenda-overriding-header "Nächste 7 Tage:")))
  911. (alltodo ""
  912. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  913. (org-agenda-skip-if nil '(scheduled deadline))))
  914. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  915. #+END_SRC
  916. ** *TODO*
  917. org-super-agenda
  918. ** org-caldav
  919. :PROPERTIES:
  920. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  921. :END:
  922. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  923. #+BEGIN_SRC emacs-lisp
  924. ;;(use-package org-caldav
  925. ;; :ensure t
  926. ;; :config
  927. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  928. ;; org-caldav-calendar-id "orgmode"
  929. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  930. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  931. #+END_SRC
  932. ** journal
  933. :PROPERTIES:
  934. :ID: a1951e18-d862-4198-9652-016e979053c8
  935. :END:
  936. [[https://github.com/bastibe/org-journal][Source]]
  937. #+BEGIN_SRC emacs-lisp
  938. (use-package org-journal
  939. :if *sys/linux*
  940. :ensure t
  941. :defer t
  942. :config
  943. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  944. (when (and (boundp 'org-journal-dir)
  945. (boundp 'org-journal-enable-agenda-integration))
  946. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  947. org-journal-enable-agenda-integration t)))
  948. #+END_SRC
  949. * Programming
  950. ** misc
  951. #+begin_src emacs-lisp
  952. (use-package eldoc
  953. :diminish eldoc-mode
  954. :defer t)
  955. #+end_src
  956. ** Magit / Git
  957. :PROPERTIES:
  958. :ID: d3589460-317f-40f6-9056-053be9ba3217
  959. :END:
  960. Little crash course in magit:
  961. - magit-init to init a git project
  962. - magit-status (C-x g) to call the status window
  963. In status buffer:
  964. - s stage files
  965. - u unstage files
  966. - U unstage all files
  967. - a apply changes to staging
  968. - c c commit (type commit message, then C-c C-c to commit)
  969. - b b switch to another branch
  970. - P u git push
  971. - F u git pull
  972. #+BEGIN_SRC emacs-lisp
  973. (use-package magit
  974. :ensure t
  975. :defer t
  976. :init
  977. ; set git-path in work environment
  978. (if (string-equal user-login-name "POH")
  979. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  980. )
  981. :bind (("C-x g" . magit-status)))
  982. #+END_SRC
  983. ** LSP
  984. :PROPERTIES:
  985. :ID: 06ad00e0-44a6-4bfb-ba6f-b1672811e053
  986. :END:
  987. Configuration for the language server protocol
  988. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  989. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  990. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  991. TODO Unterverzeichnisse wurden noch nicht getestet
  992. #+BEGIN_SRC emacs-lisp
  993. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  994. (use-package lsp-mode
  995. :defer t
  996. :commands (lsp lsp-execute-code-action)
  997. :custom
  998. (lsp-auto-guess-root nil)
  999. (lsp-prefer-flymake nil) ; use flycheck instead
  1000. (lsp-prefer-capf t)
  1001. (lsp-file-watch-threshold 5000)
  1002. (lsp-print-performance t)
  1003. (lsp-log-io nil) ; enable log only for debug
  1004. (lsp-enable-folding t) ; default, maybe evil-matchit instead for performance?
  1005. (lsp-diagnostics-modeline-scope :project)
  1006. (lsp-enable-file-watchers nil)
  1007. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  1008. :hook
  1009. (((python-mode
  1010. js-mode
  1011. js2-mode
  1012. typescript-mode
  1013. web-mode
  1014. ) . lsp-deferred)
  1015. (lsp-mode . lsp-enable-which-key-integration)
  1016. (lsp-mode . lsp-diagnostics-modeline-mode)
  1017. (web-mode . #'lsp-flycheck-enable)) ;; enable flycheck-lsp for web-mode locally
  1018. :config
  1019. (setq lsp-diagnostics-package :none)) ; disable flycheck-lsp for most modes
  1020. ;; (add-hook 'web-mode-hook #'lsp-flycheck-enable)) ; enable flycheck-lsp for web-mode locally
  1021. (use-package lsp-ui
  1022. :after lsp-mode
  1023. :ensure t
  1024. :defer t
  1025. :diminish
  1026. :commands lsp-ui-mode
  1027. :config
  1028. (setq lsp-ui-doc-enable t
  1029. lsp-ui-doc-header t
  1030. lsp-ui-doc-include-signature t
  1031. lsp-ui-doc-position 'top
  1032. lsp-ui-doc-border (face-foreground 'default)
  1033. lsp-ui-sideline-enable t
  1034. lsp-ui-sideline-ignore-duplicate t
  1035. lsp-ui-sideline-show-code-actions nil)
  1036. (when *sys/gui*
  1037. (setq lsp-ui-doc-use-webkit t))
  1038. ;; workaround hide mode-line of lsp-ui-imenu buffer
  1039. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  1040. (setq mode-line-format nil)))
  1041. ;;NO LONGER SUPPORTED, USE company-capf / completion-at-point
  1042. ;(use-package company-lsp
  1043. ; :requires company
  1044. ; :defer t
  1045. ; :ensure t
  1046. ; :config
  1047. ; ;;disable client-side cache because lsp server does a better job
  1048. ; (setq company-transformers nil
  1049. ; company-lsp-async t
  1050. ; company-lsp-cache-candidates nil))
  1051. #+END_SRC
  1052. ** yasnippet
  1053. :PROPERTIES:
  1054. :ID: 935d89ef-645e-4e92-966f-2fe3bebb2880
  1055. :END:
  1056. For useful snippet either install yasnippet-snippets or get them from here
  1057. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  1058. #+begin_src emacs-lisp
  1059. (use-package yasnippet
  1060. :ensure t
  1061. :defer t
  1062. :diminish yas-minor-mode
  1063. :config
  1064. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  1065. (yas-global-mode t)
  1066. (yas-reload-all)
  1067. (unbind-key "TAB" yas-minor-mode-map)
  1068. (unbind-key "<tab>" yas-minor-mode-map))
  1069. #+end_src
  1070. ** hippie expand
  1071. :PROPERTIES:
  1072. :ID: c55245bc-813d-4816-a0ca-b4e2e793e28b
  1073. :END:
  1074. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  1075. #+begin_src emacs-lisp
  1076. (use-package hippie-exp
  1077. :defer t
  1078. :bind
  1079. ("C-<return>" . hippie-expand)
  1080. :config
  1081. (setq hippie-expand-try-functions-list
  1082. '(yas-hippie-try-expand emmet-expand-line)))
  1083. #+end_src
  1084. ** flycheck
  1085. :PROPERTIES:
  1086. :ID: 3d8f2547-c5b3-46d0-91b0-9667f9ee5c47
  1087. :END:
  1088. #+BEGIN_SRC emacs-lisp
  1089. (use-package flycheck
  1090. :ensure t
  1091. :hook
  1092. ((css-mode . flycheck-mode)
  1093. (emacs-lisp-mode . flycheck-mode)
  1094. (python-mode . flycheck-mode))
  1095. :defer 1.0
  1096. :init
  1097. (setq flycheck-emacs-lisp-load-path 'inherit)
  1098. :config
  1099. (setq-default
  1100. flycheck-check-synta-automatically '(save mode-enabled)
  1101. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  1102. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  1103. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  1104. #+END_SRC
  1105. ** Projectile
  1106. :PROPERTIES:
  1107. :ID: a90329fd-4d36-435f-8308-a2771ac4c320
  1108. :END:
  1109. Manage projects and jump quickly between its files
  1110. #+BEGIN_SRC emacs-lisp
  1111. (use-package projectile
  1112. :ensure t
  1113. ; :defer 1.0
  1114. :diminish
  1115. :bind
  1116. (("C-c p" . projectile-command-map))
  1117. ;:preface
  1118. :init
  1119. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL ".projectile-cache")
  1120. projectile-known-projects-file (concat MY--PATH_USER_LOCAL ".projectile-bookmarks"))
  1121. :config
  1122. (projectile-mode)
  1123. ; (add-hook 'projectile-after-switch-project-hook #'set-workon_home)
  1124. (setq-default projectile-completion-system 'ivy
  1125. projectile-enable-caching t
  1126. projectile-mode-line '(:eval (projectile-project-name))))
  1127. ;; requires ripgrep on system for rg functions
  1128. ;(use-package counsel-projectile
  1129. ; :ensure t
  1130. ; :config (counsel-projectile-mode))
  1131. (use-package helm-projectile
  1132. :ensure t
  1133. :hook
  1134. (projectile-mode . helm-projectile))
  1135. #+END_SRC
  1136. ** smartparens
  1137. :PROPERTIES:
  1138. :ID: 997ec416-33e6-41ed-8c7c-75a7bc47d285
  1139. :END:
  1140. #+BEGIN_SRC emacs-lisp
  1141. (use-package smartparens
  1142. :ensure t
  1143. :diminish smartparens-mode
  1144. :bind
  1145. (:map smartparens-mode-map
  1146. ("C-M-f" . sp-forward-sexp)
  1147. ("C-M-b" . sp-backward-sexp)
  1148. ("C-M-a" . sp-backward-down-sexp)
  1149. ("C-M-e" . sp-up-sexp)
  1150. ("C-M-w" . sp-copy-sexp)
  1151. ("M-k" . sp-kill-sexp)
  1152. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  1153. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  1154. ("C-]" . sp-select-next-thing-exchange))
  1155. :config
  1156. (setq sp-show-pair-from-inside nil
  1157. sp-escape-quotes-after-insert nil)
  1158. (require 'smartparens-config))
  1159. #+END_SRC
  1160. ** lisp
  1161. :PROPERTIES:
  1162. :ID: a2bc3e08-b203-49d3-b337-fb186a14eecb
  1163. :END:
  1164. #+BEGIN_SRC emacs-lisp
  1165. (use-package elisp-mode
  1166. :defer t)
  1167. #+END_SRC
  1168. ** web
  1169. :PROPERTIES:
  1170. :ID: c0b0b4e4-2162-429f-b80d-6e5334b1290e
  1171. :END:
  1172. apt install npm
  1173. sudo npm install -g vscode-html-languageserver-bin
  1174. evtl alternativ typescript-language-server?
  1175. Unter Windows:
  1176. Hier runterladen: https://nodejs.org/dist/latest/
  1177. und in ein Verzeichnis entpacken.
  1178. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  1179. PATH=P:\path\to\node;%path%
  1180. #+BEGIN_SRC emacs-lisp
  1181. (use-package web-mode
  1182. :ensure t
  1183. :defer t
  1184. :mode
  1185. ("\\.phtml\\'"
  1186. "\\.tpl\\.php\\'"
  1187. "\\.djhtml\\'"
  1188. "\\.[t]?html?\\'")
  1189. :hook
  1190. (web-mode . smartparens-mode)
  1191. :init
  1192. (if *work_remote*
  1193. (setq exec-path (append exec-path '("P:/Tools/node"))))
  1194. :config
  1195. (setq web-mode-enable-auto-closing t
  1196. web-mode-enable-auto-pairing t))
  1197. #+END_SRC
  1198. Emmet offers snippets, similar to yasnippet.
  1199. Default completion is C-j
  1200. [[https://github.com/smihica/emmet-mode#usage][Github]]
  1201. #+begin_src emacs-lisp
  1202. (use-package emmet-mode
  1203. :ensure t
  1204. :defer t
  1205. :hook
  1206. ((web-mode . emmet-mode)
  1207. (css-mode . emmet-mode))
  1208. :config
  1209. (unbind-key "C-<return>" emmet-mode-keymap))
  1210. #+end_src
  1211. *** JavaScript
  1212. npm install -g typescript-language-server typescript
  1213. maybe only typescript?
  1214. npm install -g prettier
  1215. #+begin_src emacs-lisp
  1216. (use-package rjsx-mode
  1217. :ensure t
  1218. :mode ("\\.js\\'"
  1219. "\\.jsx'"))
  1220. ; :config
  1221. ; (setq js2-mode-show-parse-errors nil
  1222. ; js2-mode-show-strict-warnings nil
  1223. ; js2-basic-offset 2
  1224. ; js-indent-level 2)
  1225. ; (setq-local flycheck-disabled-checkers (cl-union flycheck-disable-checkers
  1226. ; '(javascript-jshint)))) ; jshint doesn"t work for JSX
  1227. (use-package tide
  1228. :ensure t
  1229. :after (rjsx-mode company flycheck)
  1230. ; :hook (rjsx-mode . setup-tide-mode)
  1231. :config
  1232. (defun setup-tide-mode ()
  1233. "Setup function for tide."
  1234. (interactive)
  1235. (tide-setup)
  1236. (flycheck-mode t)
  1237. (setq flycheck-check-synta-automatically '(save mode-enabled))
  1238. (tide-hl-identifier-mode t)))
  1239. ;; needs npm install -g prettier
  1240. (use-package prettier-js
  1241. :ensure t
  1242. :after (rjsx-mode)
  1243. :defer t
  1244. :diminish prettier-js-mode
  1245. :hook ((js2-mode rsjx-mode) . prettier-js-mode))
  1246. #+end_src
  1247. ** YAML
  1248. :PROPERTIES:
  1249. :ID: 95413247-04d5-4e02-8431-06c162ec8f3b
  1250. :END:
  1251. #+begin_src emacs-lisp
  1252. (use-package yaml-mode
  1253. :if *sys/linux*
  1254. :ensure t
  1255. :defer t
  1256. :mode ("\\.yml$" . yaml-mode))
  1257. #+end_src
  1258. ** R
  1259. #+BEGIN_SRC emacs-lisp
  1260. (use-package ess
  1261. :ensure t
  1262. :defer t
  1263. :init
  1264. (if *work_remote*
  1265. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  1266. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  1267. #+END_SRC
  1268. ** Python
  1269. :PROPERTIES:
  1270. :ID: 8c76fcd1-c57c-48ab-8af0-aa782de6337f
  1271. :END:
  1272. Systemseitig muss python-language-server installiert sein:
  1273. apt install python3-pip python3-setuptools python3-wheel
  1274. apt install build-essential python3-dev
  1275. pip3 install 'python-language-server[all]'
  1276. Statt obiges: npm install -g pyright
  1277. für andere language servers
  1278. https://github.com/emacs-lsp/lsp-mode#install-language-server
  1279. #+BEGIN_SRC emacs-lisp
  1280. ;(use-package lsp-python-ms
  1281. ; :if *sys/linux*
  1282. ; :ensure t
  1283. ; :defer t
  1284. ; :custom (lsp-python-ms-auto-install-server t))
  1285. (use-package lsp-pyright
  1286. :ensure t
  1287. :after lsp-mode
  1288. :defer t
  1289. :hook
  1290. (python-mode . (lambda ()
  1291. (require 'lsp-pyright)
  1292. (lsp-deferred)))
  1293. ; :custom
  1294. ; (lsp-pyright-auto-import-completions nil)
  1295. ; (lsp-pyright-typechecking-mode "off")
  1296. )
  1297. (use-package python
  1298. :if *sys/linux*
  1299. :delight "π "
  1300. :defer t
  1301. :bind (("M-[" . python-nav-backward-block)
  1302. ("M-]" . python-nav-forward-block)))
  1303. (use-package pyvenv
  1304. :if *sys/linux*
  1305. :ensure t
  1306. :defer t
  1307. :after python
  1308. :hook ((python-mode . pyvenv-mode)
  1309. (python-mode . (lambda ()
  1310. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  1311. (pyvenv-activate pyvenv-directory))
  1312. (lsp))))
  1313. :custom
  1314. (pyvenv-default-virtual-env-name "env")
  1315. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  1316. :preface
  1317. (defun find-pyvenv-directory (path)
  1318. "Check if a pyvenv directory exists."
  1319. (cond
  1320. ((not path) nil)
  1321. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  1322. ((file-directory-p path)
  1323. (or
  1324. (seq-find
  1325. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  1326. (directory-files path t))
  1327. (let ((parent (file-name-directory (directory-file-name path))))
  1328. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  1329. ;; manage multiple python version
  1330. ;; needs to be installed on system
  1331. ; (use-package pyenv-mode
  1332. ; :ensure t
  1333. ; :after python
  1334. ; :hook ((python-mode . pyenv-mode)
  1335. ; (projectile-switch-project . projectile-pyenv-mode-set))
  1336. ; :custom (pyenv-mode-set "3.8.5")
  1337. ; :preface
  1338. ; (defun projectile-pyenv-mode-set ()
  1339. ; "Set pyenv version matching project name."
  1340. ; (let ((project (projectile-project-name)))
  1341. ; (if (member project (pyenv-mode-versions))
  1342. ; (pyenv-mode-set project)
  1343. ; (pyenv-mode-unset)))))
  1344. ;)
  1345. #+END_SRC
  1346. * beancount
  1347. ** Installation
  1348. :PROPERTIES:
  1349. :ID: 2c329043-b7a9-437d-a5cf-f2ad6514be91
  1350. :END:
  1351. #+BEGIN_SRC shell
  1352. sudo su
  1353. cd /opt
  1354. python3 -m venv beancount
  1355. source ./beancount/bin/activate
  1356. pip3 install wheel
  1357. pip3 install beancount
  1358. sleep 100
  1359. echo "shell running!"
  1360. deactivate
  1361. #+END_SRC
  1362. #+BEGIN_SRC emacs-lisp
  1363. (use-package beancount
  1364. :if *sys/linux*
  1365. :load-path "user-global/elisp"
  1366. ; :ensure t
  1367. :defer t
  1368. :mode
  1369. ("\\.beancount$" . beancount-mode)
  1370. :hook
  1371. (beancount-mode . me/beancount-company)
  1372. :init
  1373. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  1374. :config
  1375. (defun me/beancount-company ()
  1376. (set (make-local-variable 'company-backends)
  1377. '(company-beancount)))
  1378. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1379. #+END_SRC
  1380. To support org-babel, check if it can find the symlink to ob-beancount.el
  1381. #+BEGIN_SRC shell
  1382. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1383. beansym="$orgpath/ob-beancount.el
  1384. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1385. if [ -h "$beansym" ]
  1386. then
  1387. echo "$beansym found"
  1388. elif [ -e "$bean" ]
  1389. then
  1390. echo "creating symlink"
  1391. ln -s "$bean" "$beansym"
  1392. else
  1393. echo "$bean not found, symlink creation aborted"
  1394. fi
  1395. #+END_SRC
  1396. Fava is strongly recommended.
  1397. #+BEGIN_SRC shell
  1398. cd /opt
  1399. python3 -m venv fava
  1400. source ./fava/bin/activate
  1401. pip3 install wheel
  1402. pip3 install fava
  1403. deactivate
  1404. #+END_SRC
  1405. Start fava with fava my_file.beancount
  1406. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1407. Beancount-mode can start fava and open the URL right away.
  1408. * Stuff after everything else
  1409. Set garbage collector to a smaller value to let it kick in faster.
  1410. Maybe a problem on Windows?
  1411. #+begin_src emacs-lisp
  1412. ;(setq gc-cons-threshold (* 2 1000 1000))
  1413. #+end_src