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.

1409 lines
39 KiB

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