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.

1081 lines
31 KiB

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