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.

1083 lines
31 KiB

5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 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. * Header
  29. :PROPERTIES:
  30. :ID: a14d7c89-24ea-41ae-b185-944bab49aa02
  31. :END:
  32. Emacs variables are dynamically scoped. That's unusual for most languages, so disable it here, too
  33. #+begin_src emacs-lisp
  34. ;;; init.el --- -*- lexical-binding: t -*-
  35. #+end_src
  36. * First start
  37. :PROPERTIES:
  38. :ID: 1c24d48e-0124-4a0b-8e78-82e4c531e818
  39. :END:
  40. When pulling the repository the first time, an initial init.el needs to be setup. After start it will replace itself with the configuration from init.org
  41. #+BEGIN_SRC emacs-lisp :tangle no
  42. (require 'org')
  43. (find-file (concat user-emacs-directory "init.org"))
  44. (org-babel-tangle)
  45. (load-file (concat user-emacs-directory "init.el"))
  46. (byte-compile-file (concat user-emacs-directory "init.el"))
  47. #+END_SRC
  48. This function updates init.el whenever changes in init.org are made. The update will be active after saving.
  49. #+BEGIN_SRC emacs-lisp
  50. (defun me/tangle-init ()
  51. "If the current buffer is 'init.org', the code blocks are tangled, and the tangled file is compiled."
  52. (when (equal (buffer-file-name)
  53. (expand-file-name (concat user-emacs-directory "init.org")))
  54. ;; avoid running hooks
  55. (let ((prog-mode-hook nil))
  56. (org-babel-tangle)
  57. (byte-compile-file (concat user-emacs-directory "init.el"))
  58. (load-file user-init-file))))
  59. (add-hook 'after-save-hook 'me/tangle-init)
  60. #+END_SRC
  61. #+BEGIN_SRC emacs-lisp
  62. (require 'package)
  63. (add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/") t)
  64. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  65. (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  66. (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
  67. (when (< emacs-major-version 27)
  68. (package-initialize))
  69. #+END_SRC
  70. #+BEGIN_SRC emacs-lisp
  71. (unless (package-installed-p 'use-package)
  72. (package-refresh-contents)
  73. (package-install 'use-package))
  74. (setq use-package-verbose nil)
  75. (eval-when-compile
  76. (require 'use-package))
  77. (require 'bind-key)
  78. (use-package diminish
  79. :ensure t)
  80. #+END_SRC
  81. cl is deprecated in favor for cl-lib, some packages like emmet still depend on cl.
  82. Shut off the compiler warning about it.
  83. Maybe turn it on again at some point before the next major emacs upgrade
  84. #+begin_src emacs-lisp
  85. (setq byte-compile-warnings '(cl-functions))
  86. #+end_src
  87. * Default settings
  88. :PROPERTIES:
  89. :ID: 3512d679-d111-4ccd-8372-6fc2acbc0374
  90. :END:
  91. #+BEGIN_SRC emacs-lisp
  92. (defconst *sys/gui*
  93. (display-graphic-p)
  94. "Is emacs running in a gui?")
  95. (defconst *sys/linux*
  96. (string-equal system-type 'gnu/linux)
  97. "Is the system running Linux?")
  98. (defconst *sys/windows*
  99. (string-equal system-type 'windows-nt)
  100. "Is the system running Windows?")
  101. (defconst *home_desktop*
  102. (string-equal (system-name) "marc")
  103. "Is emacs running on my desktop?")
  104. (defconst *home_laptop*
  105. (string-equal (system-name) "laptop")
  106. "Is emacs running on my laptop?")
  107. (defconst *work_local*
  108. (string-equal (system-name) "PMPCNEU08")
  109. "Is emacs running at work on the local system?")
  110. (defconst *work_remote*
  111. (string-equal (system-name) "PMTS01")
  112. "Is emacs running at work on the remote system?")
  113. #+END_SRC
  114. #+BEGIN_SRC emacs-lisp
  115. (defvar MY--PATH_USER_LOCAL (concat user-emacs-directory "user-local/"))
  116. (defvar MY--PATH_USER_GLOBAL (concat user-emacs-directory "user-global/"))
  117. (add-to-list 'custom-theme-load-path (concat MY--PATH_USER_GLOBAL "themes"))
  118. (when *sys/linux*
  119. (defconst MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/"))
  120. (defconst MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/")))
  121. (defconst MY--PATH_ORG_JOURNAl (expand-file-name "~/Archiv/Organisieren/Journal/"))
  122. (when *work_remote*
  123. (defconst MY--PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  124. (defconst MY--PATH_ORG_FILES_MOBILE nil) ;; hacky way to prevent "free variable" compiler error
  125. (defconst MY--PATH_ORG_JOURNAL nil) ;; hacky way to prevent "free variable" compiler error
  126. (defconst MY--PATH_START "p:/Eigene Dateien/Notizen/"))
  127. (setq recentf-save-file (concat MY--PATH_USER_LOCAL "recentf"))
  128. (add-to-list 'recentf-exclude "\\elpa") ;; don't spam recentf with downloaded packages
  129. (setq custom-file (concat MY--PATH_USER_LOCAL "custom.el")) ;; don't spam init.e with saved customization settings
  130. (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_defs"))
  131. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  132. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  133. (setq save-abbrevs 'silently) ;; don't bother me with asking for abbrev saving
  134. (setq-default create-lockfiles nil) ;; disable lock files, can cause trouble in e.g. lsp-mode
  135. (defalias 'yes-or-no-p 'y-or-n-p) ;; answer with y and n
  136. (setq custom-safe-themes t) ;; don't ask me if I want to load a theme
  137. (setq sentence-end-double-space nil) ;; don't coun two spaces after a period as the end of a sentence.
  138. (delete-selection-mode t) ;; delete selected region when typing
  139. (save-place-mode 1) ;; saves position in file when it's closed
  140. (setq save-place-forget-unreadable-files nil) ;; checks if file is readable before saving position
  141. (set-charset-priority 'unicode)
  142. (setq locale-coding-system 'utf-8)
  143. (set-terminal-coding-system 'utf-8)
  144. (set-keyboard-coding-system 'utf-8)
  145. (set-selection-coding-system 'utf-8)
  146. (setq default-process-coding-system '(utf-8-unix . utf-8-unix))
  147. (if *sys/windows*
  148. (prefer-coding-system 'utf-8-dos)
  149. (prefer-coding-system 'utf-8))
  150. (blink-cursor-mode -1) ;; turn off blinking cursor
  151. (show-paren-mode t) ;; show other part of brackets
  152. (column-number-mode t)
  153. (setq uniquify-buffer-name-style 'forward)
  154. (setq-default indent-tabs-mode nil) ;; avoid tabs in place of multiple spaces (they look bad in tex)
  155. (setq-default indicate-empty-lines t) ;; show empty lines
  156. (setq scroll-margin 5 ;; smooth scrolling
  157. scroll-conservatively 10000
  158. scroll-preserve-screen-position 1
  159. scroll-step 1)
  160. (global-hl-line-mode t) ;; highlight current line
  161. (menu-bar-mode 0) ;; disable menu bar
  162. (tool-bar-mode 0) ;; disable tool bar
  163. (scroll-bar-mode 0) ;; disable scroll bar
  164. #+END_SRC
  165. Bookmarks
  166. Usage:
  167. - C-x r m (bookmark-set): add bookmark
  168. - C-x r l (list-bookmark): list bookmarks
  169. - C-x r b (bookmark-jump): open bookmark
  170. Edit bookmarks (while in bookmark file):
  171. - d: mark current item
  172. - x: delete marked items
  173. - r: rename current item
  174. - s: save changes
  175. #+begin_src emacs-lisp
  176. (use-package bookmark
  177. :custom
  178. (bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks")))
  179. #+end_src
  180. Some windows specific stuff
  181. #+BEGIN_SRC emacs-lisp
  182. (when *sys/windows*
  183. (remove-hook 'find-file-hook 'vc-refresh-state)
  184. (progn
  185. (setq gc-cons-threshold (* 511 1024 1024)
  186. gc-cons-percentage 0.5
  187. garbage-collection-messages t)
  188. (run-with-idle-timer 5 t #'garbage-collect))
  189. (when (boundp 'w32-pipe-read-delay)
  190. (setq w32-pipe-read-delay 0))
  191. (when (boundp 'w32-get-true-file-attributes)
  192. (setq w32-get-true-file-attributes nil)))
  193. #+END_SRC
  194. * visuals
  195. ** Font
  196. :PROPERTIES:
  197. :ID: dc8eb670-e6bb-4bfb-98f0-aae1860234fb
  198. :END:
  199. #+BEGIN_SRC emacs-lisp
  200. (when *sys/linux*
  201. (set-face-font 'default "Hack-10"))
  202. (when *work_remote*
  203. (set-face-font 'default "Lucida Sans Typewriter-11"))
  204. #+END_SRC
  205. ** Themes
  206. :PROPERTIES:
  207. :ID: 9ccf37c0-6837-43cb-bed8-5a353799d8b1
  208. :END:
  209. #+BEGIN_SRC emacs-lisp
  210. (defun my/toggle-theme ()
  211. (interactive)
  212. (when (or *sys/windows* *sys/linux*)
  213. (if (eq (car custom-enabled-themes) 'tango-dark)
  214. (progn (disable-theme 'tango-dark)
  215. (load-theme 'tango))
  216. (progn
  217. (disable-theme 'tango)
  218. (load-theme 'tango-dark)))))
  219. (bind-key "C-c t" 'my/toggle-theme)
  220. #+END_SRC
  221. Windows Theme:
  222. #+BEGIN_SRC emacs-lisp
  223. (when *sys/windows*
  224. (load-theme 'tango))
  225. (when *sys/linux*
  226. (load-theme 'plastic))
  227. #+END_SRC
  228. ** line wrappings
  229. :PROPERTIES:
  230. :ID: 14ae933e-2941-4cc3-82de-38f90f91bfd3
  231. :END:
  232. #+BEGIN_SRC emacs-lisp
  233. (global-visual-line-mode)
  234. (diminish 'visual-line-mode)
  235. (use-package adaptive-wrap
  236. :ensure t
  237. :config
  238. (add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode))
  239. ; :init
  240. ; (when (fboundp 'adaptive-wrap-prefix-mode)
  241. ; (defun my/activate-adaptive-wrap-prefix-mode ()
  242. ; "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  243. ; (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  244. ; (add-hook 'visual-line-mode-hook 'my/activate-adaptive-wrap-prefix-mode)))
  245. #+END_SRC
  246. ** line numbers
  247. :PROPERTIES:
  248. :ID: 7b969436-98c9-4b61-ba7a-9fb22c9781ad
  249. :END:
  250. #+BEGIN_SRC emacs-lisp
  251. (use-package display-line-numbers
  252. :init
  253. (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  254. (add-hook 'org-src-mode-hook 'display-line-numbers-mode)
  255. :config
  256. (setq-default display-line-numbers-type 'visual
  257. display-line-numbers-current-absolute t
  258. display-line-numbers-with 4
  259. display-line-numbers-widen t))
  260. ; (add-hook 'emacs-lisp-mode-hook 'display-line-numbers-mode)
  261. #+END_SRC
  262. ** misc
  263. :PROPERTIES:
  264. :ID: a2873138-16ee-4990-89a2-26eab778ea74
  265. :END:
  266. #+BEGIN_SRC emacs-lisp
  267. (use-package rainbow-mode
  268. :ensure t
  269. :diminish
  270. :hook ((org-mode
  271. emacs-lisp-mode) . rainbow-mode))
  272. (use-package delight
  273. :ensure t)
  274. #+END_SRC
  275. * undo
  276. :PROPERTIES:
  277. :ID: d57621b2-5472-4c89-a520-b4133db0b9af
  278. :END:
  279. #+BEGIN_SRC emacs-lisp
  280. (use-package undo-tree
  281. :ensure t
  282. :diminish undo-tree-mode
  283. :init
  284. (global-undo-tree-mode 1))
  285. #+END_SRC
  286. * ace-window
  287. #+begin_src emacs-lisp
  288. (use-package ace-window
  289. :ensure t
  290. :bind
  291. (:map global-map
  292. ("C-x o" . ace-window)))
  293. #+end_src
  294. * imenu-list
  295. :PROPERTIES:
  296. :ID: 0ae27ec9-5d77-43cf-ac76-5e12cc959046
  297. :END:
  298. A minor mode to show imenu in a sidebar.
  299. Call imenu-list-smart-toggle.
  300. [[https://github.com/bmag/imenu-list][Source]]
  301. #+BEGIN_SRC emacs-lisp
  302. (use-package imenu-list
  303. :ensure t
  304. :config
  305. (setq imenu-list-focus-after-activation t
  306. imenu-list-auto-resize t
  307. imenu-list-position 'right)
  308. :bind
  309. (:map global-map
  310. ([f9] . imenu-list-smart-toggle))
  311. )
  312. #+END_SRC
  313. * which-key
  314. :PROPERTIES:
  315. :ID: a880f079-b3a3-4706-bf1e-5f6c680101f1
  316. :END:
  317. #+BEGIN_SRC emacs-lisp
  318. (use-package which-key
  319. :ensure t
  320. :diminish which-key-mode
  321. :config
  322. (which-key-mode)
  323. (which-key-setup-side-window-right-bottom)
  324. (which-key-setup-minibuffer)
  325. (setq which-key-idle-delay 0.5))
  326. #+END_SRC
  327. * Evil
  328. :PROPERTIES:
  329. :ID: 80ca70e2-a146-46db-b581-418d655dc1fc
  330. :END:
  331. #+BEGIN_SRC emacs-lisp
  332. (use-package evil
  333. :ensure t
  334. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  335. :config
  336. (evil-mode 1))
  337. #+END_SRC
  338. * General (key mapper)
  339. :PROPERTIES:
  340. :ID: a20f183f-d41a-4dff-bc37-3bc4e25c8036
  341. :END:
  342. #+BEGIN_SRC emacs-lisp
  343. (use-package general
  344. :ensure t)
  345. (general-define-key
  346. :states 'normal
  347. :keymaps 'imenu-list-major-mode-map
  348. (kbd "RET") '(imenu-list-goto-entry :which-key "goto")
  349. (kbd "TAB") '(hs-toggle-hiding :which-key "collapse")
  350. "d" '(imenu-list-display-entry :which-key "show")
  351. "q" '(imenu-list-quit-window :which-key "quit"))
  352. #+END_SRC
  353. * ivy / counsel / swiper
  354. :PROPERTIES:
  355. :ID: 55c74ba9-7761-4545-8ddd-087d6ee33e4b
  356. :END:
  357. #+BEGIN_SRC emacs-lisp
  358. ; (require 'ivy)
  359. (use-package ivy
  360. :ensure t
  361. :diminish
  362. (ivy-mode . "")
  363. :init
  364. (ivy-mode 1)
  365. :bind
  366. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  367. :config
  368. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  369. ivy-height 20 ;; height of ivy window
  370. ivy-count-format "%d/%d" ;; current and total number
  371. ivy-re-builders-alist ;; regex replaces spaces with *
  372. '((t . ivy--regex-plus))))
  373. (use-package counsel
  374. :ensure t
  375. :bind*
  376. (("M-x" . counsel-M-x)
  377. ("C-x C-f" . counsel-find-file)
  378. ("C-x C-r" . counsel-recentf)
  379. ("C-c C-f" . counsel-git)
  380. ("C-c h f" . counsel-describe-function)
  381. ("C-c h v" . counsel-describe-variable)
  382. ("M-i" . counsel-imenu)))
  383. (use-package swiper
  384. :ensure t
  385. :bind
  386. ("C-s" . swiper))
  387. (use-package ivy-hydra
  388. :ensure t)
  389. #+END_SRC
  390. * company
  391. :PROPERTIES:
  392. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  393. :END:
  394. #+BEGIN_SRC emacs-lisp
  395. (use-package company
  396. :defer 1
  397. :bind
  398. (("C-<tab>" . company-complete)
  399. :map company-active-map
  400. ("RET" . nil)
  401. ([return] . nil)
  402. ("TAB" . company-complete-selection)
  403. ([tab] . company-complete-selection)
  404. ("<right>" . company-complete-common))
  405. :hook
  406. (after-init . global-company-mode)
  407. :config
  408. (setq company-idle-delay .2
  409. company-minimum-prefix-length 1
  410. company-require-match nil
  411. company-show-numbers t
  412. company-tooltip-align-annotations t))
  413. (use-package company-statistics
  414. :ensure t
  415. :after company
  416. :init
  417. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  418. :config
  419. (company-statistics-mode 1))
  420. (use-package company-dabbrev
  421. :ensure nil
  422. :after company
  423. :config
  424. (setq-default company-dabbrev-downcase nil))
  425. (use-package company-box
  426. :ensure t
  427. :init
  428. (add-hook 'company-mode-hook 'company-box-mode))
  429. #+END_SRC
  430. ** company backends
  431. :PROPERTIES:
  432. :ID: 4ce2e728-276d-41f9-9538-84e6e08afd8d
  433. :END:
  434. #+BEGIN_SRC emacs-lisp
  435. (defun company/org-mode-hook()
  436. (set (make-local-variable 'company-backends)
  437. '(company-capf company-files))
  438. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  439. (message "company/org-mode-hook"))
  440. (defun company/elisp-mode-hook()
  441. (set (make-local-variable 'company-backends)
  442. '(company-capf company-files))
  443. (message "company/elisp-mode-hook"))
  444. (defun company/beancount-mode-hook()
  445. (set (make-local-variable 'company-backends)
  446. '(company-beancount)))
  447. #+END_SRC
  448. * orgmode
  449. ** org
  450. :PROPERTIES:
  451. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  452. :END:
  453. #+BEGIN_SRC emacs-lisp
  454. (use-package org
  455. :ensure org-plus-contrib
  456. :mode (("\.org$" . org-mode))
  457. :init
  458. (add-hook 'org-mode-hook 'company/org-mode-hook)
  459. (add-hook 'org-src-mode-hook 'smartparens-mode)
  460. (add-hook 'org-mode-hook 'org-indent-mode)
  461. :config
  462. (setq org-modules (quote (org-id
  463. org-habit
  464. org-tempo ;; easy templates
  465. )))
  466. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  467. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  468. (concat MY--PATH_ORG_FILES "projects.org")
  469. (concat MY--PATH_ORG_FILES "tasks.org")))
  470. (when *sys/linux*
  471. (nconc org-agenda-files
  472. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  473. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  474. org-log-into-drawer "LOGBOOK")
  475. ;; some display customizations
  476. (setq org-pretty-entities t
  477. org-startup-truncated t
  478. org-startup-align-all-tables t)
  479. ;; some source code blocks customizations
  480. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  481. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  482. org-src-preserve-indentation t ;; no extra indentation
  483. org-src-tab-acts-natively t)
  484. (setq org-log-done 'time)) ;; create timestamp when task is done
  485. #+END_SRC
  486. ** languages
  487. :PROPERTIES:
  488. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  489. :END:
  490. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  491. #+BEGIN_SRC emacs-lisp
  492. (org-babel-do-load-languages
  493. 'org-babel-load-languages
  494. '((emacs-lisp . t)
  495. (gnuplot . t)
  496. (js . t)
  497. (latex . t)
  498. (lisp . t)
  499. (python . t)
  500. (shell . t)
  501. (sqlite . t)
  502. (org . t)
  503. (R . t)
  504. (scheme . t)))
  505. (setq org-confirm-babel-evaluate nil)
  506. #+END_SRC
  507. ** habits
  508. :PROPERTIES:
  509. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  510. :END:
  511. #+BEGIN_SRC emacs-lisp
  512. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  513. ;; (add-to-list 'org-modules "org-habit")
  514. (setq org-habit-graph-column 80
  515. org-habit-preceding-days 30
  516. org-habit-following-days 7
  517. org-habit-show-habits-only-for-today nil)
  518. #+END_SRC
  519. ** org-id
  520. :PROPERTIES:
  521. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  522. :END:
  523. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  524. #+BEGIN_SRC emacs-lisp
  525. ;; (use-package org-id
  526. ;; :config
  527. ;; (setq org-id-link-to-org-use-id t)
  528. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  529. #+END_SRC
  530. ** org-agenda
  531. :PROPERTIES:
  532. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  533. :END:
  534. Custom keywords, depending on environment
  535. #+BEGIN_SRC emacs-lisp
  536. (when *work_remote*
  537. (setq org-todo-keywords
  538. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  539. #+END_SRC
  540. Add some key bindings
  541. #+BEGIN_SRC emacs-lisp
  542. (bind-key "C-c l" 'org-store-link)
  543. (bind-key "C-c c" 'org-capture)
  544. (bind-key "C-c a" 'org-agenda)
  545. #+END_SRC
  546. Sort agenda by deadline and priority
  547. #+BEGIN_SRC emacs-lisp
  548. (setq org-agenda-sorting-strategy
  549. (quote
  550. ((agenda deadline-up priority-down)
  551. (todo priority-down category-keep)
  552. (tags priority-down category-keep)
  553. (search category-keep))))
  554. #+END_SRC
  555. Customize the org agenda
  556. #+BEGIN_SRC emacs-lisp
  557. (defun me--org-skip-subtree-if-priority (priority)
  558. "Skip an agenda subtree if it has a priority of PRIORITY.
  559. PRIORITY may be one of the characters ?A, ?B, or ?C."
  560. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  561. (pri-value (* 1000 (- org-lowest-priority priority)))
  562. (pri-current (org-get-priority (thing-at-point 'line t))))
  563. (if (= pri-value pri-current)
  564. subtree-end
  565. nil)))
  566. (setq org-agenda-custom-commands
  567. '(("c" "Simple agenda view"
  568. ((tags "PRIORITY=\"A\""
  569. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  570. (org-agenda-overriding-header "Hohe Priorität:")))
  571. (agenda ""
  572. ((org-agenda-span 7)
  573. (org-agenda-start-on-weekday nil)
  574. (org-agenda-overriding-header "Nächste 7 Tage:")))
  575. (alltodo ""
  576. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  577. (org-agenda-skip-if nil '(scheduled deadline))))
  578. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  579. #+END_SRC
  580. ** *TODO*
  581. org-super-agenda
  582. ** org-caldav
  583. :PROPERTIES:
  584. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  585. :END:
  586. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  587. #+BEGIN_SRC emacs-lisp
  588. ;;(use-package org-caldav
  589. ;; :ensure t
  590. ;; :config
  591. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  592. ;; org-caldav-calendar-id "orgmode"
  593. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  594. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  595. #+END_SRC
  596. ** journal
  597. :PROPERTIES:
  598. :ID: a1951e18-d862-4198-9652-016e979053c8
  599. :END:
  600. [[https://github.com/bastibe/org-journal][Source]]
  601. #+BEGIN_SRC emacs-lisp
  602. (use-package org-journal
  603. :if *sys/linux*
  604. :ensure t
  605. :defer t
  606. :config
  607. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  608. (when (and (boundp 'org-journal-dir)
  609. (boundp 'org-journal-enable-agenda-integration))
  610. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  611. org-journal-enable-agenda-integration t)))
  612. #+END_SRC
  613. * Programming
  614. ** Magit / Git
  615. :PROPERTIES:
  616. :ID: d3589460-317f-40f6-9056-053be9ba3217
  617. :END:
  618. Little crash course in magit:
  619. - magit-init to init a git project
  620. - magit-status (C-x g) to call the status window
  621. In status buffer:
  622. - s stage files
  623. - u unstage files
  624. - U unstage all files
  625. - a apply changes to staging
  626. - c c commit (type commit message, then C-c C-c to commit)
  627. - b b switch to another branch
  628. - P u git push
  629. - F u git pull
  630. #+BEGIN_SRC emacs-lisp
  631. (use-package magit
  632. :ensure t
  633. :defer t
  634. :init
  635. ; set git-path in work environment
  636. (if (string-equal user-login-name "POH")
  637. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  638. )
  639. :bind (("C-x g" . magit-status)))
  640. #+END_SRC
  641. ** LSP
  642. :PROPERTIES:
  643. :ID: 06ad00e0-44a6-4bfb-ba6f-b1672811e053
  644. :END:
  645. Configuration for the language server protocol
  646. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  647. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  648. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  649. TODO Unterverzeichnisse wurden noch nicht getestet
  650. #+BEGIN_SRC emacs-lisp
  651. (use-package lsp-mode
  652. :defer t
  653. :commands lsp
  654. :custom
  655. (lsp-auto-guess-root nil)
  656. (lsp-prefer-flymake nil) ; use flycheck instead
  657. (lsp-file-watch-threshold 2000)
  658. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  659. :hook ((python-mode
  660. js-mode
  661. js2-mode
  662. typescript-mode
  663. web-mode) . lsp))
  664. (use-package lsp-ui
  665. :after lsp-mode
  666. :ensure t
  667. :diminish
  668. :commands lsp-ui-mode
  669. :config
  670. (setq lsp-ui-doc-enable t
  671. lsp-ui-doc-header t
  672. lsp-ui-doc-include-signature t
  673. lsp-ui-doc-position 'top
  674. lsp-ui-doc-border (face-foreground 'default)
  675. lsp-ui-sideline-enable nil
  676. lsp-ui-sideline-ignore-duplicate t
  677. lsp-ui-sideline-show-code-actions nil)
  678. (when *sys/gui*
  679. (setq lsp-ui-doc-use-webkit t))
  680. ;; workaround hide mode-line of lsp-ui-imenu buffer
  681. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  682. (setq mode-line-format nil)))
  683. (use-package company-lsp
  684. :requires company
  685. :defer t
  686. :ensure t
  687. :config
  688. ;;disable client-side cache because lsp server does a better job
  689. (setq company-transformers nil
  690. company-lsp-async t
  691. company-lsp-cache-candidates nil))
  692. #+END_SRC
  693. ** yasnippet
  694. :PROPERTIES:
  695. :ID: 935d89ef-645e-4e92-966f-2fe3bebb2880
  696. :END:
  697. For useful snippet either install yasnippet-snippets or get them from here
  698. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  699. #+begin_src emacs-lisp
  700. (use-package yasnippet
  701. :ensure t
  702. :diminish yas-minor-mode
  703. :config
  704. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  705. (yas-global-mode t)
  706. (yas-reload-all)
  707. (unbind-key "TAB" yas-minor-mode-map)
  708. (unbind-key "<tab>" yas-minor-mode-map))
  709. #+end_src
  710. ** hippie expand
  711. :PROPERTIES:
  712. :ID: c55245bc-813d-4816-a0ca-b4e2e793e28b
  713. :END:
  714. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  715. #+begin_src emacs-lisp
  716. (use-package hippie-exp
  717. :defer t
  718. :bind
  719. ("C-<return>" . hippie-expand)
  720. :config
  721. (setq hippie-expand-try-functions-list
  722. '(yas-hippie-try-expand emmet-expand-line)))
  723. #+end_src
  724. ** flycheck
  725. :PROPERTIES:
  726. :ID: 3d8f2547-c5b3-46d0-91b0-9667f9ee5c47
  727. :END:
  728. #+BEGIN_SRC emacs-lisp
  729. (use-package flycheck
  730. :ensure t
  731. :hook
  732. ((css-mode . flycheck-mode)
  733. (emacs-lisp-mode . flycheck-mode)
  734. (python-mode . flycheck-mode))
  735. :init
  736. (setq flycheck-emacs-lisp-load-path 'inherit)
  737. :config
  738. (setq-default
  739. flycheck-check-synta-automatically '(save mode-enabled)
  740. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  741. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  742. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  743. #+END_SRC
  744. ** Projectile
  745. :PROPERTIES:
  746. :ID: a90329fd-4d36-435f-8308-a2771ac4c320
  747. :END:
  748. Manage projects and jump quickly between its files
  749. #+BEGIN_SRC emacs-lisp
  750. (use-package projectile
  751. :ensure t
  752. :defer t
  753. :hook (projectile-after-switch-project . (lambda () (set-workon_home)))
  754. :bind
  755. (("C-c p p" . projectile-switch-project)
  756. ("C-c p c" . projectile-command-map)
  757. ("C-c p s s" . projectile-ag))
  758. :preface
  759. (defun set-workon_home()
  760. (setenv "WORKON_HOME" (projectile-project-root)))
  761. :init
  762. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL ".projectile-cache")
  763. projectile-known-projects-file (concat MY--PATH_USER_LOCAL ".projectile-bookmarks"))
  764. :config
  765. (projectile-mode t)
  766. (setq-default projectile-completion-system 'ivy
  767. projectile-enable-caching t
  768. projectile-mode-line '(:eval (projectile-project-name))))
  769. #+END_SRC
  770. ** smartparens
  771. :PROPERTIES:
  772. :ID: 997ec416-33e6-41ed-8c7c-75a7bc47d285
  773. :END:
  774. #+BEGIN_SRC emacs-lisp
  775. (use-package smartparens
  776. :ensure t
  777. :diminish smartparens-mode
  778. :bind
  779. (:map smartparens-mode-map
  780. ("C-M-f" . sp-forward-sexp)
  781. ("C-M-b" . sp-backward-sexp)
  782. ("C-M-a" . sp-backward-down-sexp)
  783. ("C-M-e" . sp-up-sexp)
  784. ("C-M-w" . sp-copy-sexp)
  785. ("M-k" . sp-kill-sexp)
  786. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  787. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  788. ("C-]" . sp-select-next-thing-exchange))
  789. :config
  790. (setq sp-show-pair-from-inside nil
  791. sp-escape-quotes-after-insert nil)
  792. (require 'smartparens-config))
  793. #+END_SRC
  794. ** lisp
  795. :PROPERTIES:
  796. :ID: a2bc3e08-b203-49d3-b337-fb186a14eecb
  797. :END:
  798. #+BEGIN_SRC emacs-lisp
  799. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  800. #+END_SRC
  801. ** web
  802. :PROPERTIES:
  803. :ID: c0b0b4e4-2162-429f-b80d-6e5334b1290e
  804. :END:
  805. apt install npm
  806. sudo npm install -g vscode-html-languageserver-bin
  807. evtl alternativ typescript-language-server?
  808. Unter Windows:
  809. Hier runterladen: https://nodejs.org/dist/latest/
  810. und in ein Verzeichnis entpacken.
  811. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  812. PATH=P:\path\to\node;%path%
  813. #+BEGIN_SRC emacs-lisp
  814. (use-package web-mode
  815. :ensure t
  816. :defer t
  817. :mode
  818. ("\\.phtml\\'"
  819. "\\.tpl\\.php\\'"
  820. "\\.djhtml\\'"
  821. "\\.[t]?html?\\'")
  822. :init
  823. (if *work_remote*
  824. (setq exec-path (append exec-path '("P:/Tools/node"))))
  825. :config
  826. (setq web-mode-enable-auto-closing t
  827. web-mode-enable-auto-pairing t)
  828. (add-hook 'web-mode-hook 'smartparens-mode))
  829. #+END_SRC
  830. Emmet offers snippets, similar to yasnippet.
  831. Default completion is C-j
  832. [[https://github.com/smihica/emmet-mode#usage][Github]]
  833. #+begin_src emacs-lisp
  834. (use-package emmet-mode
  835. :ensure t
  836. :defer t
  837. :hook
  838. ((web-mode . emmet-mode)
  839. (css-mode . emmet-mode))
  840. :config
  841. (unbind-key "C-<return>" emmet-mode-keymap))
  842. #+end_src
  843. ** YAML
  844. :PROPERTIES:
  845. :ID: 95413247-04d5-4e02-8431-06c162ec8f3b
  846. :END:
  847. #+begin_src emacs-lisp
  848. (use-package yaml-mode
  849. :if *sys/linux*
  850. :ensure t
  851. :mode ("\\.yml$" . yaml-mode))
  852. #+end_src
  853. ** R
  854. #+BEGIN_SRC emacs-lisp
  855. (use-package ess
  856. :ensure t
  857. :init
  858. (if *work_remote*
  859. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  860. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  861. #+END_SRC
  862. ** Python
  863. :PROPERTIES:
  864. :ID: 8c76fcd1-c57c-48ab-8af0-aa782de6337f
  865. :END:
  866. Systemseitig muss python-language-server installiert sein:
  867. apt install python3-pip python3-setuptools python3-wheel
  868. apt install build-essential python3-dev
  869. pip3 install 'python-language-server[all]'
  870. für andere language servers
  871. https://github.com/emacs-lsp/lsp-mode#install-language-server
  872. #+BEGIN_SRC emacs-lisp
  873. (use-package lsp-python-ms
  874. :if *sys/linux*
  875. :ensure t
  876. :defer 0.3
  877. :custom (lsp-python-ms-auto-install-server t))
  878. (use-package python
  879. :if *sys/linux*
  880. :delight "π "
  881. :bind (("M-[" . python-nav-backward-block)
  882. ("M-]" . python-nav-forward-block)))
  883. (use-package pyvenv
  884. :if *sys/linux*
  885. :ensure t
  886. :after python
  887. :hook ((python-mode . pyvenv-mode)
  888. (python-mode . (lambda ()
  889. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  890. (pyvenv-activate pyvenv-directory))
  891. (lsp))))
  892. :custom
  893. (pyvenv-default-virtual-env-name "env")
  894. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  895. :preface
  896. (defun find-pyvenv-directory (path)
  897. "Check if a pyvenv directory exists."
  898. (cond
  899. ((not path) nil)
  900. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  901. ((file-directory-p path)
  902. (or
  903. (seq-find
  904. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  905. (directory-files path t))
  906. (let ((parent (file-name-directory (directory-file-name path))))
  907. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  908. ;; manage multiple python version
  909. ;; needs to be installed on system
  910. ; (use-package pyenv-mode
  911. ; :ensure t
  912. ; :after python
  913. ; :hook ((python-mode . pyenv-mode)
  914. ; (projectile-switch-project . projectile-pyenv-mode-set))
  915. ; :custom (pyenv-mode-set "3.8.5")
  916. ; :preface
  917. ; (defun projectile-pyenv-mode-set ()
  918. ; "Set pyenv version matching project name."
  919. ; (let ((project (projectile-project-name)))
  920. ; (if (member project (pyenv-mode-versions))
  921. ; (pyenv-mode-set project)
  922. ; (pyenv-mode-unset)))))
  923. ;)
  924. #+END_SRC
  925. * beancount
  926. ** Installation
  927. :PROPERTIES:
  928. :ID: 2c329043-b7a9-437d-a5cf-f2ad6514be91
  929. :END:
  930. #+BEGIN_SRC shell
  931. sudo su
  932. cd /opt
  933. python3 -m venv beancount
  934. source ./beancount/bin/activate
  935. pip3 install wheel
  936. pip3 install beancount
  937. sleep 100
  938. echo "shell running!"
  939. deactivate
  940. #+END_SRC
  941. #+BEGIN_SRC emacs-lisp
  942. (use-package beancount
  943. :if *sys/linux*
  944. :load-path "user-global/elisp"
  945. ; :ensure t
  946. :defer t
  947. :mode
  948. ("\\.beancount$" . beancount-mode)
  949. :init
  950. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  951. ; (add-hook 'beancount-mode-hook (pyvenv-activate "/opt/beancount"))
  952. ; (setenv "PATH"
  953. ; (concat "/opt/beancount/bin:"
  954. ; (getenv "PATH")))
  955. :config
  956. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  957. #+END_SRC
  958. To support org-babel, check if it can find the symlink to ob-beancount.el
  959. #+BEGIN_SRC shell
  960. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  961. beansym="$orgpath/ob-beancount.el
  962. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  963. if [ -h "$beansym" ]
  964. then
  965. echo "$beansym found"
  966. elif [ -e "$bean" ]
  967. then
  968. echo "creating symlink"
  969. ln -s "$bean" "$beansym"
  970. else
  971. echo "$bean not found, symlink creation aborted"
  972. fi
  973. #+END_SRC
  974. Fava is strongly recommended.
  975. #+BEGIN_SRC shell
  976. cd /opt
  977. python3 -m venv fava
  978. source ./fava/bin/activate
  979. pip3 install wheel
  980. pip3 install fava
  981. deactivate
  982. #+END_SRC
  983. Start fava with fava my_file.beancount
  984. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  985. Beancount-mode can start fava and open the URL right away.