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.

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