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.

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