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.

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