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.

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