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.

1598 lines
44 KiB

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