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.

1585 lines
44 KiB

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