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.

1440 lines
40 KiB

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