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.

1082 lines
31 KiB

5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #+TITLE: Emacs configuration file
  2. #+AUTHOR: Marc
  3. #+BABEL: :cache yes
  4. #+PROPERTY: header-args :tangle yes
  5. * TODOS
  6. - early-init.el? What to outsource here?
  7. - Paket exec-path-from-shell, um PATH aus Linux auch in emacs zu haben
  8. - Smart mode line?
  9. - Theme
  10. - evil-collection or custom in init file?
  11. - Hydra
  12. - General
  13. - (defalias 'list-buffers 'ibuffer) ;; change default to ibuffer
  14. - ido?
  15. - treemacs (for linux)
  16. - treemacs-evil?
  17. - treemacs-projectile
  18. windmove?
  19. - tramp (in linux)
  20. - visual-regexp
  21. - org configuration: paths
  22. - org custom agenda
  23. - org-ql (related to org agendas)
  24. - org configuration: everything else
  25. - beancount configuration from config.org
  26. - CONTINUE TODO from config.org at Programming
  27. - all-the-icons?
  28. * Header
  29. :PROPERTIES:
  30. :ID: a14d7c89-24ea-41ae-b185-944bab49aa02
  31. :END:
  32. Emacs variables are dynamically scoped. That's unusual for most languages, so disable it here, too
  33. #+begin_src emacs-lisp
  34. ;;; init.el --- -*- lexical-binding: t -*-
  35. #+end_src
  36. * First start
  37. :PROPERTIES:
  38. :ID: 1c24d48e-0124-4a0b-8e78-82e4c531e818
  39. :END:
  40. When pulling the repository the first time, an initial init.el needs to be setup. After start it will replace itself with the configuration from init.org
  41. #+BEGIN_SRC emacs-lisp :tangle no
  42. (require 'org')
  43. (find-file (concat user-emacs-directory "init.org"))
  44. (org-babel-tangle)
  45. (load-file (concat user-emacs-directory "init.el"))
  46. (byte-compile-file (concat user-emacs-directory "init.el"))
  47. #+END_SRC
  48. This function updates init.el whenever changes in init.org are made. The update will be active after saving.
  49. #+BEGIN_SRC emacs-lisp
  50. (defun me/tangle-init ()
  51. "If the current buffer is 'init.org', the code blocks are tangled, and the tangled file is compiled."
  52. (when (equal (buffer-file-name)
  53. (expand-file-name (concat user-emacs-directory "init.org")))
  54. ;; avoid running hooks
  55. (let ((prog-mode-hook nil))
  56. (org-babel-tangle)
  57. (byte-compile-file (concat user-emacs-directory "init.el"))
  58. (load-file user-init-file))))
  59. (add-hook 'after-save-hook 'me/tangle-init)
  60. #+END_SRC
  61. #+BEGIN_SRC emacs-lisp
  62. (require 'package)
  63. (add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/") t)
  64. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  65. (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  66. (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
  67. (when (< emacs-major-version 27)
  68. (package-initialize))
  69. #+END_SRC
  70. #+BEGIN_SRC emacs-lisp
  71. (unless (package-installed-p 'use-package)
  72. (package-refresh-contents)
  73. (package-install 'use-package))
  74. (setq use-package-verbose nil)
  75. (eval-when-compile
  76. (require 'use-package))
  77. (require 'bind-key)
  78. (use-package diminish
  79. :ensure t)
  80. #+END_SRC
  81. cl is deprecated in favor for cl-lib, some packages like emmet still depend on cl.
  82. Shut off the compiler warning about it.
  83. Maybe turn it on again at some point before the next major emacs upgrade
  84. #+begin_src emacs-lisp
  85. (setq byte-compile-warnings '(cl-functions))
  86. #+end_src
  87. * Default settings
  88. :PROPERTIES:
  89. :ID: 3512d679-d111-4ccd-8372-6fc2acbc0374
  90. :END:
  91. #+BEGIN_SRC emacs-lisp
  92. (defconst *sys/gui*
  93. (display-graphic-p)
  94. "Is emacs running in a gui?")
  95. (defconst *sys/linux*
  96. (string-equal system-type 'gnu/linux)
  97. "Is the system running Linux?")
  98. (defconst *sys/windows*
  99. (string-equal system-type 'windows-nt)
  100. "Is the system running Windows?")
  101. (defconst *home_desktop*
  102. (string-equal (system-name) "marc")
  103. "Is emacs running on my desktop?")
  104. (defconst *home_laptop*
  105. (string-equal (system-name) "laptop")
  106. "Is emacs running on my laptop?")
  107. (defconst *work_local*
  108. (string-equal (system-name) "PMPCNEU08")
  109. "Is emacs running at work on the local system?")
  110. (defconst *work_remote*
  111. (string-equal (system-name) "PMTS01")
  112. "Is emacs running at work on the remote system?")
  113. #+END_SRC
  114. #+BEGIN_SRC emacs-lisp
  115. (defvar MY--PATH_USER_LOCAL (concat user-emacs-directory "user-local/"))
  116. (defvar MY--PATH_USER_GLOBAL (concat user-emacs-directory "user-global/"))
  117. (add-to-list 'custom-theme-load-path (concat MY--PATH_USER_GLOBAL "themes"))
  118. (when *sys/linux*
  119. (defconst MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/"))
  120. (defconst MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/")))
  121. (defconst MY--PATH_ORG_JOURNAl (expand-file-name "~/Archiv/Organisieren/Journal/"))
  122. (when *work_remote*
  123. (defconst MY--PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  124. (defconst MY--PATH_ORG_FILES_MOBILE nil) ;; hacky way to prevent "free variable" compiler error
  125. (defconst MY--PATH_ORG_JOURNAL nil) ;; hacky way to prevent "free variable" compiler error
  126. (defconst MY--PATH_START "p:/Eigene Dateien/Notizen/"))
  127. (setq recentf-save-file (concat MY--PATH_USER_LOCAL "recentf"))
  128. (setq custom-file (concat MY--PATH_USER_LOCAL "custom.el")) ;; don't spam init.e with saved customization settings
  129. (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_defs"))
  130. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  131. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  132. (setq save-abbrevs 'silently) ;; don't bother me with asking for abbrev saving
  133. (setq-default create-lockfiles nil) ;; disable lock files, can cause trouble in e.g. lsp-mode
  134. (defalias 'yes-or-no-p 'y-or-n-p) ;; answer with y and n
  135. (setq custom-safe-themes t) ;; don't ask me if I want to load a theme
  136. (setq sentence-end-double-space nil) ;; don't coun two spaces after a period as the end of a sentence.
  137. (delete-selection-mode t) ;; delete selected region when typing
  138. (save-place-mode 1) ;; saves position in file when it's closed
  139. (setq save-place-forget-unreadable-files nil) ;; checks if file is readable before saving position
  140. (set-charset-priority 'unicode)
  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. (setq default-process-coding-system '(utf-8-unix . utf-8-unix))
  146. (if *sys/windows*
  147. (prefer-coding-system 'utf-8-dos)
  148. (prefer-coding-system 'utf-8))
  149. (blink-cursor-mode -1) ;; turn off blinking cursor
  150. (show-paren-mode t) ;; show other part of brackets
  151. (column-number-mode t)
  152. (setq uniquify-buffer-name-style 'forward)
  153. (setq-default indent-tabs-mode nil) ;; avoid tabs in place of multiple spaces (they look bad in tex)
  154. (setq-default indicate-empty-lines t) ;; show empty lines
  155. (setq scroll-margin 5 ;; smooth scrolling
  156. scroll-conservatively 10000
  157. scroll-preserve-screen-position 1
  158. scroll-step 1)
  159. (global-hl-line-mode t) ;; highlight current line
  160. (menu-bar-mode 0) ;; disable menu bar
  161. (tool-bar-mode 0) ;; disable tool bar
  162. (scroll-bar-mode 0) ;; disable scroll bar
  163. #+END_SRC
  164. Bookmarks
  165. Usage:
  166. - C-x r m (bookmark-set): add bookmark
  167. - C-x r l (list-bookmark): list bookmarks
  168. - C-x r b (bookmark-jump): open bookmark
  169. Edit bookmarks (while in bookmark file):
  170. - d: mark current item
  171. - x: delete marked items
  172. - r: rename current item
  173. - s: save changes
  174. #+begin_src emacs-lisp
  175. (use-package bookmark
  176. :custom
  177. (bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks")))
  178. #+end_src
  179. Some windows specific stuff
  180. #+BEGIN_SRC emacs-lisp
  181. (when *sys/windows*
  182. (remove-hook 'find-file-hook 'vc-refresh-state)
  183. (progn
  184. (setq gc-cons-threshold (* 511 1024 1024)
  185. gc-cons-percentage 0.5
  186. garbage-collection-messages t)
  187. (run-with-idle-timer 5 t #'garbage-collect))
  188. (when (boundp 'w32-pipe-read-delay)
  189. (setq w32-pipe-read-delay 0))
  190. (when (boundp 'w32-get-true-file-attributes)
  191. (setq w32-get-true-file-attributes nil)))
  192. #+END_SRC
  193. * visuals
  194. ** Font
  195. :PROPERTIES:
  196. :ID: dc8eb670-e6bb-4bfb-98f0-aae1860234fb
  197. :END:
  198. #+BEGIN_SRC emacs-lisp
  199. (when *sys/linux*
  200. (set-face-font 'default "Hack-10"))
  201. (when *work_remote*
  202. (set-face-font 'default "Lucida Sans Typewriter-11"))
  203. #+END_SRC
  204. ** Themes
  205. :PROPERTIES:
  206. :ID: 9ccf37c0-6837-43cb-bed8-5a353799d8b1
  207. :END:
  208. #+BEGIN_SRC emacs-lisp
  209. (defun my/toggle-theme ()
  210. (interactive)
  211. (when (or *sys/windows* *sys/linux*)
  212. (if (eq (car custom-enabled-themes) 'tango-dark)
  213. (progn (disable-theme 'tango-dark)
  214. (load-theme 'tango))
  215. (progn
  216. (disable-theme 'tango)
  217. (load-theme 'tango-dark)))))
  218. (bind-key "C-c t" 'my/toggle-theme)
  219. #+END_SRC
  220. Windows Theme:
  221. #+BEGIN_SRC emacs-lisp
  222. (when *sys/windows*
  223. (load-theme 'tango))
  224. (when *sys/linux*
  225. (load-theme 'plastic))
  226. #+END_SRC
  227. ** line wrappings
  228. :PROPERTIES:
  229. :ID: 14ae933e-2941-4cc3-82de-38f90f91bfd3
  230. :END:
  231. #+BEGIN_SRC emacs-lisp
  232. (global-visual-line-mode)
  233. (diminish 'visual-line-mode)
  234. (use-package adaptive-wrap
  235. :ensure t
  236. :config
  237. (add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode))
  238. ; :init
  239. ; (when (fboundp 'adaptive-wrap-prefix-mode)
  240. ; (defun my/activate-adaptive-wrap-prefix-mode ()
  241. ; "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  242. ; (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  243. ; (add-hook 'visual-line-mode-hook 'my/activate-adaptive-wrap-prefix-mode)))
  244. #+END_SRC
  245. ** line numbers
  246. :PROPERTIES:
  247. :ID: 7b969436-98c9-4b61-ba7a-9fb22c9781ad
  248. :END:
  249. #+BEGIN_SRC emacs-lisp
  250. (use-package display-line-numbers
  251. :init
  252. (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  253. (add-hook 'org-src-mode-hook 'display-line-numbers-mode)
  254. :config
  255. (setq-default display-line-numbers-type 'visual
  256. display-line-numbers-current-absolute t
  257. display-line-numbers-with 4
  258. display-line-numbers-widen t))
  259. ; (add-hook 'emacs-lisp-mode-hook 'display-line-numbers-mode)
  260. #+END_SRC
  261. ** misc
  262. :PROPERTIES:
  263. :ID: a2873138-16ee-4990-89a2-26eab778ea74
  264. :END:
  265. #+BEGIN_SRC emacs-lisp
  266. (use-package rainbow-mode
  267. :ensure t
  268. :diminish
  269. :hook ((org-mode
  270. emacs-lisp-mode) . rainbow-mode))
  271. (use-package delight
  272. :ensure t)
  273. #+END_SRC
  274. * undo
  275. :PROPERTIES:
  276. :ID: d57621b2-5472-4c89-a520-b4133db0b9af
  277. :END:
  278. #+BEGIN_SRC emacs-lisp
  279. (use-package undo-tree
  280. :ensure t
  281. :diminish undo-tree-mode
  282. :init
  283. (global-undo-tree-mode 1))
  284. #+END_SRC
  285. * ace-window
  286. #+begin_src emacs-lisp
  287. (use-package ace-window
  288. :ensure t
  289. :bind
  290. (:map global-map
  291. ("C-x o" . ace-window)))
  292. #+end_src
  293. * imenu-list
  294. :PROPERTIES:
  295. :ID: 0ae27ec9-5d77-43cf-ac76-5e12cc959046
  296. :END:
  297. A minor mode to show imenu in a sidebar.
  298. Call imenu-list-smart-toggle.
  299. [[https://github.com/bmag/imenu-list][Source]]
  300. #+BEGIN_SRC emacs-lisp
  301. (use-package imenu-list
  302. :ensure t
  303. :config
  304. (setq imenu-list-focus-after-activation t
  305. imenu-list-auto-resize t
  306. imenu-list-position 'right)
  307. :bind
  308. (:map global-map
  309. ([f9] . imenu-list-smart-toggle))
  310. )
  311. #+END_SRC
  312. * which-key
  313. :PROPERTIES:
  314. :ID: a880f079-b3a3-4706-bf1e-5f6c680101f1
  315. :END:
  316. #+BEGIN_SRC emacs-lisp
  317. (use-package which-key
  318. :ensure t
  319. :diminish which-key-mode
  320. :config
  321. (which-key-mode)
  322. (which-key-setup-side-window-right-bottom)
  323. (which-key-setup-minibuffer)
  324. (setq which-key-idle-delay 0.5))
  325. #+END_SRC
  326. * Evil
  327. :PROPERTIES:
  328. :ID: 80ca70e2-a146-46db-b581-418d655dc1fc
  329. :END:
  330. #+BEGIN_SRC emacs-lisp
  331. (use-package evil
  332. :ensure t
  333. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  334. :config
  335. (evil-mode 1))
  336. #+END_SRC
  337. * General (key mapper)
  338. :PROPERTIES:
  339. :ID: a20f183f-d41a-4dff-bc37-3bc4e25c8036
  340. :END:
  341. #+BEGIN_SRC emacs-lisp
  342. (use-package general
  343. :ensure t)
  344. (general-define-key
  345. :states 'normal
  346. :keymaps 'imenu-list-major-mode-map
  347. (kbd "RET") '(imenu-list-goto-entry :which-key "goto")
  348. (kbd "TAB") '(hs-toggle-hiding :which-key "collapse")
  349. "d" '(imenu-list-display-entry :which-key "show")
  350. "q" '(imenu-list-quit-window :which-key "quit"))
  351. #+END_SRC
  352. * ivy / counsel / swiper
  353. :PROPERTIES:
  354. :ID: 55c74ba9-7761-4545-8ddd-087d6ee33e4b
  355. :END:
  356. #+BEGIN_SRC emacs-lisp
  357. ; (require 'ivy)
  358. (use-package ivy
  359. :ensure t
  360. :diminish
  361. (ivy-mode . "")
  362. :init
  363. (ivy-mode 1)
  364. :bind
  365. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  366. :config
  367. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  368. ivy-height 20 ;; height of ivy window
  369. ivy-count-format "%d/%d" ;; current and total number
  370. ivy-re-builders-alist ;; regex replaces spaces with *
  371. '((t . ivy--regex-plus))))
  372. (use-package counsel
  373. :ensure t
  374. :bind*
  375. (("M-x" . counsel-M-x)
  376. ("C-x C-f" . counsel-find-file)
  377. ("C-x C-r" . counsel-recentf)
  378. ("C-c C-f" . counsel-git)
  379. ("C-c h f" . counsel-describe-function)
  380. ("C-c h v" . counsel-describe-variable)
  381. ("M-i" . counsel-imenu)))
  382. (use-package swiper
  383. :ensure t
  384. :bind
  385. ("C-s" . swiper))
  386. (use-package ivy-hydra
  387. :ensure t)
  388. #+END_SRC
  389. * company
  390. :PROPERTIES:
  391. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  392. :END:
  393. #+BEGIN_SRC emacs-lisp
  394. (use-package company
  395. :defer 1
  396. :bind
  397. (("C-<tab>" . company-complete)
  398. :map company-active-map
  399. ("RET" . nil)
  400. ([return] . nil)
  401. ("TAB" . company-complete-selection)
  402. ([tab] . company-complete-selection)
  403. ("<right>" . company-complete-common))
  404. :hook
  405. (after-init . global-company-mode)
  406. :config
  407. (setq company-idle-delay .2
  408. company-minimum-prefix-length 1
  409. company-require-match nil
  410. company-show-numbers t
  411. company-tooltip-align-annotations t))
  412. (use-package company-statistics
  413. :ensure t
  414. :after company
  415. :init
  416. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  417. :config
  418. (company-statistics-mode 1))
  419. (use-package company-dabbrev
  420. :ensure nil
  421. :after company
  422. :config
  423. (setq-default company-dabbrev-downcase nil))
  424. (use-package company-box
  425. :ensure t
  426. :init
  427. (add-hook 'company-mode-hook 'company-box-mode))
  428. #+END_SRC
  429. ** company backends
  430. :PROPERTIES:
  431. :ID: 4ce2e728-276d-41f9-9538-84e6e08afd8d
  432. :END:
  433. #+BEGIN_SRC emacs-lisp
  434. (defun company/org-mode-hook()
  435. (set (make-local-variable 'company-backends)
  436. '(company-capf company-files))
  437. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  438. (message "company/org-mode-hook"))
  439. (defun company/elisp-mode-hook()
  440. (set (make-local-variable 'company-backends)
  441. '(company-capf company-files))
  442. (message "company/elisp-mode-hook"))
  443. (defun company/beancount-mode-hook()
  444. (set (make-local-variable 'company-backends)
  445. '(company-beancount)))
  446. #+END_SRC
  447. * orgmode
  448. ** org
  449. :PROPERTIES:
  450. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  451. :END:
  452. #+BEGIN_SRC emacs-lisp
  453. (use-package org
  454. :ensure org-plus-contrib
  455. :mode (("\.org$" . org-mode))
  456. :init
  457. (add-hook 'org-mode-hook 'company/org-mode-hook)
  458. (add-hook 'org-src-mode-hook 'smartparens-mode)
  459. (add-hook 'org-mode-hook 'org-indent-mode)
  460. :config
  461. (setq org-modules (quote (org-id
  462. org-habit
  463. org-tempo ;; easy templates
  464. )))
  465. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  466. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  467. (concat MY--PATH_ORG_FILES "projects.org")
  468. (concat MY--PATH_ORG_FILES "tasks.org")))
  469. (when *sys/linux*
  470. (nconc org-agenda-files
  471. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  472. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  473. org-log-into-drawer "LOGBOOK")
  474. ;; some display customizations
  475. (setq org-pretty-entities t
  476. org-startup-truncated t
  477. org-startup-align-all-tables t)
  478. ;; some source code blocks customizations
  479. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  480. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  481. org-src-preserve-indentation t ;; no extra indentation
  482. org-src-tab-acts-natively t)
  483. (setq org-log-done 'time)) ;; create timestamp when task is done
  484. #+END_SRC
  485. ** languages
  486. :PROPERTIES:
  487. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  488. :END:
  489. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  490. #+BEGIN_SRC emacs-lisp
  491. (org-babel-do-load-languages
  492. 'org-babel-load-languages
  493. '((emacs-lisp . t)
  494. (gnuplot . t)
  495. (js . t)
  496. (latex . t)
  497. (lisp . t)
  498. (python . t)
  499. (shell . t)
  500. (sqlite . t)
  501. (org . t)
  502. (R . t)
  503. (scheme . t)))
  504. (setq org-confirm-babel-evaluate nil)
  505. #+END_SRC
  506. ** habits
  507. :PROPERTIES:
  508. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  509. :END:
  510. #+BEGIN_SRC emacs-lisp
  511. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  512. ;; (add-to-list 'org-modules "org-habit")
  513. (setq org-habit-graph-column 80
  514. org-habit-preceding-days 30
  515. org-habit-following-days 7
  516. org-habit-show-habits-only-for-today nil)
  517. #+END_SRC
  518. ** org-id
  519. :PROPERTIES:
  520. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  521. :END:
  522. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  523. #+BEGIN_SRC emacs-lisp
  524. ;; (use-package org-id
  525. ;; :config
  526. ;; (setq org-id-link-to-org-use-id t)
  527. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  528. #+END_SRC
  529. ** org-agenda
  530. :PROPERTIES:
  531. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  532. :END:
  533. Custom keywords, depending on environment
  534. #+BEGIN_SRC emacs-lisp
  535. (when *work_remote*
  536. (setq org-todo-keywords
  537. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  538. #+END_SRC
  539. Add some key bindings
  540. #+BEGIN_SRC emacs-lisp
  541. (bind-key "C-c l" 'org-store-link)
  542. (bind-key "C-c c" 'org-capture)
  543. (bind-key "C-c a" 'org-agenda)
  544. #+END_SRC
  545. Sort agenda by deadline and priority
  546. #+BEGIN_SRC emacs-lisp
  547. (setq org-agenda-sorting-strategy
  548. (quote
  549. ((agenda deadline-up priority-down)
  550. (todo priority-down category-keep)
  551. (tags priority-down category-keep)
  552. (search category-keep))))
  553. #+END_SRC
  554. Customize the org agenda
  555. #+BEGIN_SRC emacs-lisp
  556. (defun me--org-skip-subtree-if-priority (priority)
  557. "Skip an agenda subtree if it has a priority of PRIORITY.
  558. PRIORITY may be one of the characters ?A, ?B, or ?C."
  559. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  560. (pri-value (* 1000 (- org-lowest-priority priority)))
  561. (pri-current (org-get-priority (thing-at-point 'line t))))
  562. (if (= pri-value pri-current)
  563. subtree-end
  564. nil)))
  565. (setq org-agenda-custom-commands
  566. '(("c" "Simple agenda view"
  567. ((tags "PRIORITY=\"A\""
  568. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  569. (org-agenda-overriding-header "Hohe Priorität:")))
  570. (agenda ""
  571. ((org-agenda-span 7)
  572. (org-agenda-start-on-weekday nil)
  573. (org-agenda-overriding-header "Nächste 7 Tage:")))
  574. (alltodo ""
  575. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  576. (org-agenda-skip-if nil '(scheduled deadline))))
  577. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  578. #+END_SRC
  579. ** *TODO*
  580. org-super-agenda
  581. ** org-caldav
  582. :PROPERTIES:
  583. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  584. :END:
  585. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  586. #+BEGIN_SRC emacs-lisp
  587. ;;(use-package org-caldav
  588. ;; :ensure t
  589. ;; :config
  590. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  591. ;; org-caldav-calendar-id "orgmode"
  592. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  593. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  594. #+END_SRC
  595. ** journal
  596. :PROPERTIES:
  597. :ID: a1951e18-d862-4198-9652-016e979053c8
  598. :END:
  599. [[https://github.com/bastibe/org-journal][Source]]
  600. #+BEGIN_SRC emacs-lisp
  601. (use-package org-journal
  602. :if *sys/linux*
  603. :ensure t
  604. :defer t
  605. :config
  606. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  607. (when (and (boundp 'org-journal-dir)
  608. (boundp 'org-journal-enable-agenda-integration))
  609. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  610. org-journal-enable-agenda-integration t)))
  611. #+END_SRC
  612. * Programming
  613. ** Magit / Git
  614. :PROPERTIES:
  615. :ID: d3589460-317f-40f6-9056-053be9ba3217
  616. :END:
  617. Little crash course in magit:
  618. - magit-init to init a git project
  619. - magit-status (C-x g) to call the status window
  620. In status buffer:
  621. - s stage files
  622. - u unstage files
  623. - U unstage all files
  624. - a apply changes to staging
  625. - c c commit (type commit message, then C-c C-c to commit)
  626. - b b switch to another branch
  627. - P u git push
  628. - F u git pull
  629. #+BEGIN_SRC emacs-lisp
  630. (use-package magit
  631. :ensure t
  632. :defer t
  633. :init
  634. ; set git-path in work environment
  635. (if (string-equal user-login-name "POH")
  636. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  637. )
  638. :bind (("C-x g" . magit-status)))
  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.