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.

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