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.

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