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.

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