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.

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