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.

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