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.

1133 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
4 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
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. ; make counsel-M-x more descriptive
  382. (use-package ivy-rich
  383. :ensure t
  384. :init
  385. (ivy-rich-mode 1))
  386. (use-package counsel
  387. :ensure t
  388. :bind
  389. (("M-x" . counsel-M-x)
  390. ("C-x C-f" . counsel-find-file)
  391. ("C-x C-r" . counsel-recentf)
  392. ("C-x b" . counsel-switch-buffer)
  393. ("C-c C-f" . counsel-git)
  394. ("C-c h f" . counsel-describe-function)
  395. ("C-c h v" . counsel-describe-variable)
  396. ("M-i" . counsel-imenu)))
  397. ; :map minibuffer-local-map ;;currently mapped to evil-redo
  398. ; ("C-r" . 'counsel-minibuffer-history)))
  399. (use-package swiper
  400. :ensure t
  401. :bind
  402. ("C-s" . swiper))
  403. (use-package ivy-hydra
  404. :ensure t)
  405. #+END_SRC
  406. * misc
  407. #+begin_src emacs-lisp
  408. (use-package autorevert
  409. :diminish auto-revert-mode)
  410. #+end_src
  411. * company
  412. :PROPERTIES:
  413. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  414. :END:
  415. #+BEGIN_SRC emacs-lisp
  416. (use-package company
  417. :defer 1
  418. :diminish
  419. :bind
  420. (("C-<tab>" . company-complete)
  421. :map company-active-map
  422. ("RET" . nil)
  423. ([return] . nil)
  424. ("TAB" . company-complete-selection)
  425. ([tab] . company-complete-selection)
  426. ("<right>" . company-complete-common))
  427. :hook
  428. (after-init . global-company-mode)
  429. :config
  430. (setq company-idle-delay .2
  431. company-minimum-prefix-length 1
  432. company-require-match nil
  433. company-show-numbers t
  434. company-tooltip-align-annotations t))
  435. (use-package company-statistics
  436. :ensure t
  437. :after company
  438. :init
  439. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  440. :config
  441. (company-statistics-mode 1))
  442. (use-package company-dabbrev
  443. :ensure nil
  444. :after company
  445. :config
  446. (setq-default company-dabbrev-downcase nil))
  447. (use-package company-box
  448. :ensure t
  449. :diminish
  450. :init
  451. (add-hook 'company-mode-hook 'company-box-mode))
  452. #+END_SRC
  453. ** company backends
  454. :PROPERTIES:
  455. :ID: 4ce2e728-276d-41f9-9538-84e6e08afd8d
  456. :END:
  457. #+BEGIN_SRC emacs-lisp
  458. (defun company/org-mode-hook()
  459. (set (make-local-variable 'company-backends)
  460. '(company-capf company-files))
  461. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  462. (message "company/org-mode-hook"))
  463. (defun company/elisp-mode-hook()
  464. (set (make-local-variable 'company-backends)
  465. '(company-capf company-files))
  466. (message "company/elisp-mode-hook"))
  467. (defun company/beancount-mode-hook()
  468. (set (make-local-variable 'company-backends)
  469. '(company-beancount)))
  470. #+END_SRC
  471. * orgmode
  472. ** org
  473. :PROPERTIES:
  474. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  475. :END:
  476. #+BEGIN_SRC emacs-lisp
  477. (use-package org
  478. :ensure org-plus-contrib
  479. :mode (("\.org$" . org-mode))
  480. :diminish org-indent-mode
  481. :init
  482. (add-hook 'org-mode-hook 'company/org-mode-hook)
  483. (add-hook 'org-src-mode-hook 'smartparens-mode)
  484. (add-hook 'org-mode-hook 'org-indent-mode)
  485. :config
  486. (setq org-modules (quote (org-id
  487. org-habit
  488. org-tempo ;; easy templates
  489. )))
  490. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  491. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  492. (concat MY--PATH_ORG_FILES "projects.org")
  493. (concat MY--PATH_ORG_FILES "tasks.org")))
  494. (when *sys/linux*
  495. (nconc org-agenda-files
  496. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  497. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  498. org-log-into-drawer "LOGBOOK")
  499. ;; some display customizations
  500. (setq org-pretty-entities t
  501. org-startup-truncated t
  502. org-startup-align-all-tables t)
  503. ;; some source code blocks customizations
  504. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  505. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  506. org-src-preserve-indentation t ;; no extra indentation
  507. org-src-tab-acts-natively t)
  508. (setq org-log-done 'time)) ;; create timestamp when task is done
  509. #+END_SRC
  510. ** languages
  511. :PROPERTIES:
  512. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  513. :END:
  514. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  515. #+BEGIN_SRC emacs-lisp
  516. (org-babel-do-load-languages
  517. 'org-babel-load-languages
  518. '((emacs-lisp . t)
  519. (gnuplot . t)
  520. (js . t)
  521. (latex . t)
  522. (lisp . t)
  523. (python . t)
  524. (shell . t)
  525. (sqlite . t)
  526. (org . t)
  527. (R . t)
  528. (scheme . t)))
  529. (setq org-confirm-babel-evaluate nil)
  530. #+END_SRC
  531. ** habits
  532. :PROPERTIES:
  533. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  534. :END:
  535. #+BEGIN_SRC emacs-lisp
  536. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  537. ;; (add-to-list 'org-modules "org-habit")
  538. (setq org-habit-graph-column 80
  539. org-habit-preceding-days 30
  540. org-habit-following-days 7
  541. org-habit-show-habits-only-for-today nil)
  542. #+END_SRC
  543. ** org-id
  544. :PROPERTIES:
  545. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  546. :END:
  547. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  548. #+BEGIN_SRC emacs-lisp
  549. ;; (use-package org-id
  550. ;; :config
  551. ;; (setq org-id-link-to-org-use-id t)
  552. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  553. #+END_SRC
  554. ** org-agenda
  555. :PROPERTIES:
  556. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  557. :END:
  558. Custom keywords, depending on environment
  559. #+BEGIN_SRC emacs-lisp
  560. (when *work_remote*
  561. (setq org-todo-keywords
  562. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  563. #+END_SRC
  564. Add some key bindings
  565. #+BEGIN_SRC emacs-lisp
  566. (bind-key "C-c l" 'org-store-link)
  567. (bind-key "C-c c" 'org-capture)
  568. (bind-key "C-c a" 'org-agenda)
  569. #+END_SRC
  570. Sort agenda by deadline and priority
  571. #+BEGIN_SRC emacs-lisp
  572. (setq org-agenda-sorting-strategy
  573. (quote
  574. ((agenda deadline-up priority-down)
  575. (todo priority-down category-keep)
  576. (tags priority-down category-keep)
  577. (search category-keep))))
  578. #+END_SRC
  579. Customize the org agenda
  580. #+BEGIN_SRC emacs-lisp
  581. (defun me--org-skip-subtree-if-priority (priority)
  582. "Skip an agenda subtree if it has a priority of PRIORITY.
  583. PRIORITY may be one of the characters ?A, ?B, or ?C."
  584. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  585. (pri-value (* 1000 (- org-lowest-priority priority)))
  586. (pri-current (org-get-priority (thing-at-point 'line t))))
  587. (if (= pri-value pri-current)
  588. subtree-end
  589. nil)))
  590. (setq org-agenda-custom-commands
  591. '(("c" "Simple agenda view"
  592. ((tags "PRIORITY=\"A\""
  593. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  594. (org-agenda-overriding-header "Hohe Priorität:")))
  595. (agenda ""
  596. ((org-agenda-span 7)
  597. (org-agenda-start-on-weekday nil)
  598. (org-agenda-overriding-header "Nächste 7 Tage:")))
  599. (alltodo ""
  600. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  601. (org-agenda-skip-if nil '(scheduled deadline))))
  602. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  603. #+END_SRC
  604. ** *TODO*
  605. org-super-agenda
  606. ** org-caldav
  607. :PROPERTIES:
  608. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  609. :END:
  610. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  611. #+BEGIN_SRC emacs-lisp
  612. ;;(use-package org-caldav
  613. ;; :ensure t
  614. ;; :config
  615. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  616. ;; org-caldav-calendar-id "orgmode"
  617. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  618. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  619. #+END_SRC
  620. ** journal
  621. :PROPERTIES:
  622. :ID: a1951e18-d862-4198-9652-016e979053c8
  623. :END:
  624. [[https://github.com/bastibe/org-journal][Source]]
  625. #+BEGIN_SRC emacs-lisp
  626. (use-package org-journal
  627. :if *sys/linux*
  628. :ensure t
  629. :defer t
  630. :config
  631. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  632. (when (and (boundp 'org-journal-dir)
  633. (boundp 'org-journal-enable-agenda-integration))
  634. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  635. org-journal-enable-agenda-integration t)))
  636. #+END_SRC
  637. * Programming
  638. ** misc
  639. #+begin_src emacs-lisp
  640. (use-package eldoc
  641. :diminish eldoc-mode)
  642. #+end_src
  643. ** Magit / Git
  644. :PROPERTIES:
  645. :ID: d3589460-317f-40f6-9056-053be9ba3217
  646. :END:
  647. Little crash course in magit:
  648. - magit-init to init a git project
  649. - magit-status (C-x g) to call the status window
  650. In status buffer:
  651. - s stage files
  652. - u unstage files
  653. - U unstage all files
  654. - a apply changes to staging
  655. - c c commit (type commit message, then C-c C-c to commit)
  656. - b b switch to another branch
  657. - P u git push
  658. - F u git pull
  659. #+BEGIN_SRC emacs-lisp
  660. (use-package magit
  661. :ensure t
  662. :defer t
  663. :init
  664. ; set git-path in work environment
  665. (if (string-equal user-login-name "POH")
  666. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  667. )
  668. :bind (("C-x g" . magit-status)))
  669. #+END_SRC
  670. ** LSP
  671. :PROPERTIES:
  672. :ID: 06ad00e0-44a6-4bfb-ba6f-b1672811e053
  673. :END:
  674. Configuration for the language server protocol
  675. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  676. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  677. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  678. TODO Unterverzeichnisse wurden noch nicht getestet
  679. #+BEGIN_SRC emacs-lisp
  680. (setq read-process-output-max (* 1024 1024)) ;; support reading large blobs of data for LSP's sake
  681. (use-package lsp-mode
  682. :defer t
  683. :commands (lsp lsp-execute-code-action)
  684. :custom
  685. (lsp-auto-guess-root nil)
  686. (lsp-prefer-flymake nil) ; use flycheck instead
  687. (lsp-file-watch-threshold 5000)
  688. (lsb-print-performance t)
  689. (lsp-log-io t)
  690. (lsp-diagnostics-modeline-scope :project)
  691. (lsp-enable-file-watchers nil)
  692. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  693. :hook
  694. (((python-mode
  695. js-mode
  696. js2-mode
  697. typescript-mode
  698. web-mode) . lsp)
  699. (lsp-mode . lsp-enable-which-key-integration)
  700. (lsp-mode . lsp-diagnostics-modeline-mode)))
  701. (use-package lsp-ui
  702. :after lsp-mode
  703. :ensure t
  704. :diminish
  705. :commands lsp-ui-mode
  706. :config
  707. (setq lsp-ui-doc-enable t
  708. lsp-ui-doc-header t
  709. lsp-ui-doc-include-signature t
  710. lsp-ui-doc-position 'top
  711. lsp-ui-doc-border (face-foreground 'default)
  712. lsp-ui-sideline-enable nil
  713. lsp-ui-sideline-ignore-duplicate t
  714. lsp-ui-sideline-show-code-actions nil)
  715. (when *sys/gui*
  716. (setq lsp-ui-doc-use-webkit t))
  717. ;; workaround hide mode-line of lsp-ui-imenu buffer
  718. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  719. (setq mode-line-format nil)))
  720. (use-package company-lsp
  721. :requires company
  722. :defer t
  723. :ensure t
  724. :config
  725. ;;disable client-side cache because lsp server does a better job
  726. (setq company-transformers nil
  727. company-lsp-async t
  728. company-lsp-cache-candidates nil))
  729. #+END_SRC
  730. ** yasnippet
  731. :PROPERTIES:
  732. :ID: 935d89ef-645e-4e92-966f-2fe3bebb2880
  733. :END:
  734. For useful snippet either install yasnippet-snippets or get them from here
  735. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  736. #+begin_src emacs-lisp
  737. (use-package yasnippet
  738. :ensure t
  739. :diminish yas-minor-mode
  740. :config
  741. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  742. (yas-global-mode t)
  743. (yas-reload-all)
  744. (unbind-key "TAB" yas-minor-mode-map)
  745. (unbind-key "<tab>" yas-minor-mode-map))
  746. #+end_src
  747. ** hippie expand
  748. :PROPERTIES:
  749. :ID: c55245bc-813d-4816-a0ca-b4e2e793e28b
  750. :END:
  751. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  752. #+begin_src emacs-lisp
  753. (use-package hippie-exp
  754. :defer t
  755. :bind
  756. ("C-<return>" . hippie-expand)
  757. :config
  758. (setq hippie-expand-try-functions-list
  759. '(yas-hippie-try-expand emmet-expand-line)))
  760. #+end_src
  761. ** flycheck
  762. :PROPERTIES:
  763. :ID: 3d8f2547-c5b3-46d0-91b0-9667f9ee5c47
  764. :END:
  765. #+BEGIN_SRC emacs-lisp
  766. (use-package flycheck
  767. :ensure t
  768. :hook
  769. ((css-mode . flycheck-mode)
  770. (emacs-lisp-mode . flycheck-mode)
  771. (python-mode . flycheck-mode))
  772. :init
  773. (setq flycheck-emacs-lisp-load-path 'inherit)
  774. :config
  775. (setq-default
  776. flycheck-check-synta-automatically '(save mode-enabled)
  777. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  778. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  779. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  780. #+END_SRC
  781. ** Projectile
  782. :PROPERTIES:
  783. :ID: a90329fd-4d36-435f-8308-a2771ac4c320
  784. :END:
  785. Manage projects and jump quickly between its files
  786. #+BEGIN_SRC emacs-lisp
  787. (use-package projectile
  788. :ensure t
  789. :defer t
  790. :diminish
  791. :hook (projectile-after-switch-project . (lambda () (set-workon_home))) ;; for pyvenv to auto activate environment
  792. :bind-keymap
  793. ("C-c p" . projectile-command-map)
  794. ; :bind
  795. ; (("C-c p p" . projectile-switch-project)
  796. ; ("C-c p c" . projectile-command-map)
  797. ; ("C-c p s s" . projectile-ag))
  798. :preface
  799. (defun set-workon_home()
  800. (setenv "WORKON_HOME" (projectile-project-root)))
  801. :init
  802. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL ".projectile-cache")
  803. projectile-known-projects-file (concat MY--PATH_USER_LOCAL ".projectile-bookmarks"))
  804. :config
  805. (projectile-mode t)
  806. (setq-default projectile-completion-system 'ivy
  807. projectile-enable-caching t
  808. projectile-mode-line '(:eval (projectile-project-name))))
  809. ;; requires ripgrep on system for rg functions
  810. (use-package counsel-projectile
  811. :ensure t
  812. :config (counsel-projectile-mode))
  813. #+END_SRC
  814. ** smartparens
  815. :PROPERTIES:
  816. :ID: 997ec416-33e6-41ed-8c7c-75a7bc47d285
  817. :END:
  818. #+BEGIN_SRC emacs-lisp
  819. (use-package smartparens
  820. :ensure t
  821. :diminish smartparens-mode
  822. :bind
  823. (:map smartparens-mode-map
  824. ("C-M-f" . sp-forward-sexp)
  825. ("C-M-b" . sp-backward-sexp)
  826. ("C-M-a" . sp-backward-down-sexp)
  827. ("C-M-e" . sp-up-sexp)
  828. ("C-M-w" . sp-copy-sexp)
  829. ("M-k" . sp-kill-sexp)
  830. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  831. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  832. ("C-]" . sp-select-next-thing-exchange))
  833. :config
  834. (setq sp-show-pair-from-inside nil
  835. sp-escape-quotes-after-insert nil)
  836. (require 'smartparens-config))
  837. #+END_SRC
  838. ** lisp
  839. :PROPERTIES:
  840. :ID: a2bc3e08-b203-49d3-b337-fb186a14eecb
  841. :END:
  842. #+BEGIN_SRC emacs-lisp
  843. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  844. #+END_SRC
  845. ** web
  846. :PROPERTIES:
  847. :ID: c0b0b4e4-2162-429f-b80d-6e5334b1290e
  848. :END:
  849. apt install npm
  850. sudo npm install -g vscode-html-languageserver-bin
  851. evtl alternativ typescript-language-server?
  852. Unter Windows:
  853. Hier runterladen: https://nodejs.org/dist/latest/
  854. und in ein Verzeichnis entpacken.
  855. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  856. PATH=P:\path\to\node;%path%
  857. #+BEGIN_SRC emacs-lisp
  858. (use-package web-mode
  859. :ensure t
  860. :defer t
  861. :mode
  862. ("\\.phtml\\'"
  863. "\\.tpl\\.php\\'"
  864. "\\.djhtml\\'"
  865. "\\.[t]?html?\\'")
  866. :init
  867. (if *work_remote*
  868. (setq exec-path (append exec-path '("P:/Tools/node"))))
  869. :config
  870. (setq web-mode-enable-auto-closing t
  871. web-mode-enable-auto-pairing t)
  872. (add-hook 'web-mode-hook 'smartparens-mode))
  873. #+END_SRC
  874. Emmet offers snippets, similar to yasnippet.
  875. Default completion is C-j
  876. [[https://github.com/smihica/emmet-mode#usage][Github]]
  877. #+begin_src emacs-lisp
  878. (use-package emmet-mode
  879. :ensure t
  880. :defer t
  881. :hook
  882. ((web-mode . emmet-mode)
  883. (css-mode . emmet-mode))
  884. :config
  885. (unbind-key "C-<return>" emmet-mode-keymap))
  886. #+end_src
  887. ** YAML
  888. :PROPERTIES:
  889. :ID: 95413247-04d5-4e02-8431-06c162ec8f3b
  890. :END:
  891. #+begin_src emacs-lisp
  892. (use-package yaml-mode
  893. :if *sys/linux*
  894. :ensure t
  895. :mode ("\\.yml$" . yaml-mode))
  896. #+end_src
  897. ** R
  898. #+BEGIN_SRC emacs-lisp
  899. (use-package ess
  900. :ensure t
  901. :init
  902. (if *work_remote*
  903. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  904. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  905. #+END_SRC
  906. ** Python
  907. :PROPERTIES:
  908. :ID: 8c76fcd1-c57c-48ab-8af0-aa782de6337f
  909. :END:
  910. Systemseitig muss python-language-server installiert sein:
  911. apt install python3-pip python3-setuptools python3-wheel
  912. apt install build-essential python3-dev
  913. pip3 install 'python-language-server[all]'
  914. für andere language servers
  915. https://github.com/emacs-lsp/lsp-mode#install-language-server
  916. #+BEGIN_SRC emacs-lisp
  917. (use-package lsp-python-ms
  918. :if *sys/linux*
  919. :ensure t
  920. :defer 0.3
  921. :custom (lsp-python-ms-auto-install-server t))
  922. (use-package python
  923. :if *sys/linux*
  924. :delight "π "
  925. :bind (("M-[" . python-nav-backward-block)
  926. ("M-]" . python-nav-forward-block)))
  927. (use-package pyvenv
  928. :if *sys/linux*
  929. :ensure t
  930. :after python
  931. :hook ((python-mode . pyvenv-mode)
  932. (python-mode . (lambda ()
  933. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  934. (pyvenv-activate pyvenv-directory))
  935. (lsp))))
  936. :custom
  937. (pyvenv-default-virtual-env-name "env")
  938. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  939. :preface
  940. (defun find-pyvenv-directory (path)
  941. "Check if a pyvenv directory exists."
  942. (cond
  943. ((not path) nil)
  944. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  945. ((file-directory-p path)
  946. (or
  947. (seq-find
  948. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  949. (directory-files path t))
  950. (let ((parent (file-name-directory (directory-file-name path))))
  951. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  952. ;; manage multiple python version
  953. ;; needs to be installed on system
  954. ; (use-package pyenv-mode
  955. ; :ensure t
  956. ; :after python
  957. ; :hook ((python-mode . pyenv-mode)
  958. ; (projectile-switch-project . projectile-pyenv-mode-set))
  959. ; :custom (pyenv-mode-set "3.8.5")
  960. ; :preface
  961. ; (defun projectile-pyenv-mode-set ()
  962. ; "Set pyenv version matching project name."
  963. ; (let ((project (projectile-project-name)))
  964. ; (if (member project (pyenv-mode-versions))
  965. ; (pyenv-mode-set project)
  966. ; (pyenv-mode-unset)))))
  967. ;)
  968. #+END_SRC
  969. * beancount
  970. ** Installation
  971. :PROPERTIES:
  972. :ID: 2c329043-b7a9-437d-a5cf-f2ad6514be91
  973. :END:
  974. #+BEGIN_SRC shell
  975. sudo su
  976. cd /opt
  977. python3 -m venv beancount
  978. source ./beancount/bin/activate
  979. pip3 install wheel
  980. pip3 install beancount
  981. sleep 100
  982. echo "shell running!"
  983. deactivate
  984. #+END_SRC
  985. #+BEGIN_SRC emacs-lisp
  986. (use-package beancount
  987. :if *sys/linux*
  988. :load-path "user-global/elisp"
  989. ; :ensure t
  990. :defer t
  991. :mode
  992. ("\\.beancount$" . beancount-mode)
  993. :init
  994. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  995. ; (add-hook 'beancount-mode-hook (pyvenv-activate "/opt/beancount"))
  996. ; (setenv "PATH"
  997. ; (concat "/opt/beancount/bin:"
  998. ; (getenv "PATH")))
  999. :config
  1000. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  1001. #+END_SRC
  1002. To support org-babel, check if it can find the symlink to ob-beancount.el
  1003. #+BEGIN_SRC shell
  1004. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  1005. beansym="$orgpath/ob-beancount.el
  1006. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  1007. if [ -h "$beansym" ]
  1008. then
  1009. echo "$beansym found"
  1010. elif [ -e "$bean" ]
  1011. then
  1012. echo "creating symlink"
  1013. ln -s "$bean" "$beansym"
  1014. else
  1015. echo "$bean not found, symlink creation aborted"
  1016. fi
  1017. #+END_SRC
  1018. Fava is strongly recommended.
  1019. #+BEGIN_SRC shell
  1020. cd /opt
  1021. python3 -m venv fava
  1022. source ./fava/bin/activate
  1023. pip3 install wheel
  1024. pip3 install fava
  1025. deactivate
  1026. #+END_SRC
  1027. Start fava with fava my_file.beancount
  1028. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  1029. Beancount-mode can start fava and open the URL right away.