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.

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