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.

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