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.

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