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.

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