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.

1080 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. (setq locale-coding-system 'utf-8)
  141. (set-terminal-coding-system 'utf-8)
  142. (set-keyboard-coding-system 'utf-8)
  143. (set-selection-coding-system 'utf-8)
  144. (if *sys/windows*
  145. (prefer-coding-system 'utf-8-dos)
  146. (prefer-coding-system 'utf-8))
  147. (blink-cursor-mode -1) ;; turn off blinking cursor
  148. (show-paren-mode t) ;; show other part of brackets
  149. (column-number-mode t)
  150. (setq uniquify-buffer-name-style 'forward)
  151. (setq-default indent-tabs-mode nil) ;; avoid tabs in place of multiple spaces (they look bad in tex)
  152. (setq-default indicate-empty-lines t) ;; show empty lines
  153. (setq scroll-margin 5 ;; smooth scrolling
  154. scroll-conservatively 10000
  155. scroll-preserve-screen-position 1
  156. scroll-step 1)
  157. (global-hl-line-mode t) ;; highlight current line
  158. (menu-bar-mode 0) ;; disable menu bar
  159. (tool-bar-mode 0) ;; disable tool bar
  160. (scroll-bar-mode 0) ;; disable scroll bar
  161. #+END_SRC
  162. Bookmarks
  163. Usage:
  164. - C-x r m (bookmark-set): add bookmark
  165. - C-x r l (list-bookmark): list bookmarks
  166. - C-x r b (bookmark-jump): open bookmark
  167. Edit bookmarks (while in bookmark file):
  168. - d: mark current item
  169. - x: delete marked items
  170. - r: rename current item
  171. - s: save changes
  172. #+begin_src emacs-lisp
  173. (use-package bookmark
  174. :custom
  175. (bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks")))
  176. #+end_src
  177. Some windows specific stuff
  178. #+BEGIN_SRC emacs-lisp
  179. (when *sys/windows*
  180. (remove-hook 'find-file-hook 'vc-refresh-state)
  181. (progn
  182. (setq gc-cons-threshold (* 511 1024 1024)
  183. gc-cons-percentage 0.5
  184. garbage-collection-messages t)
  185. (run-with-idle-timer 5 t #'garbage-collect))
  186. (when (boundp 'w32-pipe-read-delay)
  187. (setq w32-pipe-read-delay 0))
  188. (when (boundp 'w32-get-true-file-attributes)
  189. (setq w32-get-true-file-attributes nil)))
  190. #+END_SRC
  191. * visuals
  192. ** Font
  193. :PROPERTIES:
  194. :ID: dc8eb670-e6bb-4bfb-98f0-aae1860234fb
  195. :END:
  196. #+BEGIN_SRC emacs-lisp
  197. (when *sys/linux*
  198. (set-face-font 'default "Hack-10"))
  199. (when *work_remote*
  200. (set-face-font 'default "Lucida Sans Typewriter-11"))
  201. #+END_SRC
  202. ** Themes
  203. :PROPERTIES:
  204. :ID: 9ccf37c0-6837-43cb-bed8-5a353799d8b1
  205. :END:
  206. #+BEGIN_SRC emacs-lisp
  207. (defun my/toggle-theme ()
  208. (interactive)
  209. (when (or *sys/windows* *sys/linux*)
  210. (if (eq (car custom-enabled-themes) 'tango-dark)
  211. (progn (disable-theme 'tango-dark)
  212. (load-theme 'tango))
  213. (progn
  214. (disable-theme 'tango)
  215. (load-theme 'tango-dark)))))
  216. (bind-key "C-c t" 'my/toggle-theme)
  217. #+END_SRC
  218. Windows Theme:
  219. #+BEGIN_SRC emacs-lisp
  220. (when *sys/windows*
  221. (load-theme 'tango))
  222. (when *sys/linux*
  223. (load-theme 'plastic))
  224. #+END_SRC
  225. ** line wrappings
  226. :PROPERTIES:
  227. :ID: 14ae933e-2941-4cc3-82de-38f90f91bfd3
  228. :END:
  229. #+BEGIN_SRC emacs-lisp
  230. (global-visual-line-mode)
  231. (diminish 'visual-line-mode)
  232. (use-package adaptive-wrap
  233. :ensure t
  234. :config
  235. (add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode))
  236. ; :init
  237. ; (when (fboundp 'adaptive-wrap-prefix-mode)
  238. ; (defun my/activate-adaptive-wrap-prefix-mode ()
  239. ; "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  240. ; (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  241. ; (add-hook 'visual-line-mode-hook 'my/activate-adaptive-wrap-prefix-mode)))
  242. #+END_SRC
  243. ** line numbers
  244. :PROPERTIES:
  245. :ID: 7b969436-98c9-4b61-ba7a-9fb22c9781ad
  246. :END:
  247. #+BEGIN_SRC emacs-lisp
  248. (use-package display-line-numbers
  249. :init
  250. (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  251. (add-hook 'org-src-mode-hook 'display-line-numbers-mode)
  252. :config
  253. (setq-default display-line-numbers-type 'visual
  254. display-line-numbers-current-absolute t
  255. display-line-numbers-with 4
  256. display-line-numbers-widen t))
  257. ; (add-hook 'emacs-lisp-mode-hook 'display-line-numbers-mode)
  258. #+END_SRC
  259. ** misc
  260. :PROPERTIES:
  261. :ID: a2873138-16ee-4990-89a2-26eab778ea74
  262. :END:
  263. #+BEGIN_SRC emacs-lisp
  264. (use-package rainbow-mode
  265. :ensure t
  266. :diminish
  267. :hook ((org-mode
  268. emacs-lisp-mode) . rainbow-mode))
  269. (use-package delight
  270. :ensure t)
  271. #+END_SRC
  272. * undo
  273. :PROPERTIES:
  274. :ID: d57621b2-5472-4c89-a520-b4133db0b9af
  275. :END:
  276. #+BEGIN_SRC emacs-lisp
  277. (use-package undo-tree
  278. :ensure t
  279. :diminish undo-tree-mode
  280. :init
  281. (global-undo-tree-mode 1))
  282. #+END_SRC
  283. * ace-window
  284. #+begin_src emacs-lisp
  285. (use-package ace-window
  286. :ensure t
  287. :bind
  288. (:map global-map
  289. ("C-x o" . ace-window)))
  290. #+end_src
  291. * imenu-list
  292. :PROPERTIES:
  293. :ID: 0ae27ec9-5d77-43cf-ac76-5e12cc959046
  294. :END:
  295. A minor mode to show imenu in a sidebar.
  296. Call imenu-list-smart-toggle.
  297. [[https://github.com/bmag/imenu-list][Source]]
  298. #+BEGIN_SRC emacs-lisp
  299. (use-package imenu-list
  300. :ensure t
  301. :config
  302. (setq imenu-list-focus-after-activation t
  303. imenu-list-auto-resize t
  304. imenu-list-position 'right)
  305. :bind
  306. (:map global-map
  307. ([f9] . imenu-list-smart-toggle))
  308. )
  309. #+END_SRC
  310. * which-key
  311. :PROPERTIES:
  312. :ID: a880f079-b3a3-4706-bf1e-5f6c680101f1
  313. :END:
  314. #+BEGIN_SRC emacs-lisp
  315. (use-package which-key
  316. :ensure t
  317. :diminish which-key-mode
  318. :config
  319. (which-key-mode)
  320. (which-key-setup-side-window-right-bottom)
  321. (which-key-setup-minibuffer)
  322. (setq which-key-idle-delay 0.5))
  323. #+END_SRC
  324. * Evil
  325. :PROPERTIES:
  326. :ID: 80ca70e2-a146-46db-b581-418d655dc1fc
  327. :END:
  328. #+BEGIN_SRC emacs-lisp
  329. (use-package evil
  330. :ensure t
  331. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  332. :config
  333. (evil-mode 1))
  334. #+END_SRC
  335. * General (key mapper)
  336. :PROPERTIES:
  337. :ID: a20f183f-d41a-4dff-bc37-3bc4e25c8036
  338. :END:
  339. #+BEGIN_SRC emacs-lisp
  340. (use-package general
  341. :ensure t)
  342. (general-define-key
  343. :states 'normal
  344. :keymaps 'imenu-list-major-mode-map
  345. (kbd "RET") '(imenu-list-goto-entry :which-key "goto")
  346. (kbd "TAB") '(hs-toggle-hiding :which-key "collapse")
  347. "d" '(imenu-list-display-entry :which-key "show")
  348. "q" '(imenu-list-quit-window :which-key "quit"))
  349. #+END_SRC
  350. * ivy / counsel / swiper
  351. :PROPERTIES:
  352. :ID: 55c74ba9-7761-4545-8ddd-087d6ee33e4b
  353. :END:
  354. #+BEGIN_SRC emacs-lisp
  355. ; (require 'ivy)
  356. (use-package ivy
  357. :ensure t
  358. :diminish
  359. (ivy-mode . "")
  360. :init
  361. (ivy-mode 1)
  362. :bind
  363. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  364. :config
  365. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  366. ivy-height 20 ;; height of ivy window
  367. ivy-count-format "%d/%d" ;; current and total number
  368. ivy-re-builders-alist ;; regex replaces spaces with *
  369. '((t . ivy--regex-plus))))
  370. (use-package counsel
  371. :ensure t
  372. :bind*
  373. (("M-x" . counsel-M-x)
  374. ("C-x C-f" . counsel-find-file)
  375. ("C-x C-r" . counsel-recentf)
  376. ("C-c C-f" . counsel-git)
  377. ("C-c h f" . counsel-describe-function)
  378. ("C-c h v" . counsel-describe-variable)
  379. ("M-i" . counsel-imenu)))
  380. (use-package swiper
  381. :ensure t
  382. :bind
  383. ("C-s" . swiper))
  384. (use-package ivy-hydra
  385. :ensure t)
  386. #+END_SRC
  387. * company
  388. :PROPERTIES:
  389. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  390. :END:
  391. #+BEGIN_SRC emacs-lisp
  392. (use-package company
  393. :defer 1
  394. :bind
  395. (("C-<tab>" . company-complete)
  396. :map company-active-map
  397. ("RET" . nil)
  398. ([return] . nil)
  399. ("TAB" . company-complete-selection)
  400. ([tab] . company-complete-selection)
  401. ("<right>" . company-complete-common))
  402. :hook
  403. (after-init . global-company-mode)
  404. :config
  405. (setq company-idle-delay .2
  406. company-minimum-prefix-length 1
  407. company-require-match nil
  408. company-show-numbers t
  409. company-tooltip-align-annotations t))
  410. (use-package company-statistics
  411. :ensure t
  412. :after company
  413. :init
  414. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  415. :config
  416. (company-statistics-mode 1))
  417. (use-package company-dabbrev
  418. :ensure nil
  419. :after company
  420. :config
  421. (setq-default company-dabbrev-downcase nil))
  422. (use-package company-box
  423. :ensure t
  424. :init
  425. (add-hook 'company-mode-hook 'company-box-mode))
  426. #+END_SRC
  427. ** company backends
  428. :PROPERTIES:
  429. :ID: 4ce2e728-276d-41f9-9538-84e6e08afd8d
  430. :END:
  431. #+BEGIN_SRC emacs-lisp
  432. (defun company/org-mode-hook()
  433. (set (make-local-variable 'company-backends)
  434. '(company-capf company-files))
  435. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  436. (message "company/org-mode-hook"))
  437. (defun company/elisp-mode-hook()
  438. (set (make-local-variable 'company-backends)
  439. '(company-capf company-files))
  440. (message "company/elisp-mode-hook"))
  441. (defun company/beancount-mode-hook()
  442. (set (make-local-variable 'company-backends)
  443. '(company-beancount)))
  444. #+END_SRC
  445. * orgmode
  446. ** org
  447. :PROPERTIES:
  448. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  449. :END:
  450. #+BEGIN_SRC emacs-lisp
  451. (use-package org
  452. :ensure org-plus-contrib
  453. :mode (("\.org$" . org-mode))
  454. :init
  455. (add-hook 'org-mode-hook 'company/org-mode-hook)
  456. (add-hook 'org-src-mode-hook 'smartparens-mode)
  457. (add-hook 'org-mode-hook 'org-indent-mode)
  458. :config
  459. (setq org-modules (quote (org-id
  460. org-habit
  461. org-tempo ;; easy templates
  462. )))
  463. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  464. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  465. (concat MY--PATH_ORG_FILES "projects.org")
  466. (concat MY--PATH_ORG_FILES "tasks.org")))
  467. (when *sys/linux*
  468. (nconc org-agenda-files
  469. (directory-files-recursively MY--PATH_ORG_FILES_MOBILE "\\.org$")))
  470. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  471. org-log-into-drawer "LOGBOOK")
  472. ;; some display customizations
  473. (setq org-pretty-entities t
  474. org-startup-truncated t
  475. org-startup-align-all-tables t)
  476. ;; some source code blocks customizations
  477. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  478. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  479. org-src-preserve-indentation t ;; no extra indentation
  480. org-src-tab-acts-natively t)
  481. (setq org-log-done 'time)) ;; create timestamp when task is done
  482. #+END_SRC
  483. ** languages
  484. :PROPERTIES:
  485. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  486. :END:
  487. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  488. #+BEGIN_SRC emacs-lisp
  489. (org-babel-do-load-languages
  490. 'org-babel-load-languages
  491. '((emacs-lisp . t)
  492. (gnuplot . t)
  493. (js . t)
  494. (latex . t)
  495. (lisp . t)
  496. (python . t)
  497. (shell . t)
  498. (sqlite . t)
  499. (org . t)
  500. (R . t)
  501. (scheme . t)))
  502. (setq org-confirm-babel-evaluate nil)
  503. #+END_SRC
  504. ** habits
  505. :PROPERTIES:
  506. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  507. :END:
  508. #+BEGIN_SRC emacs-lisp
  509. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  510. ;; (add-to-list 'org-modules "org-habit")
  511. (setq org-habit-graph-column 80
  512. org-habit-preceding-days 30
  513. org-habit-following-days 7
  514. org-habit-show-habits-only-for-today nil)
  515. #+END_SRC
  516. ** org-id
  517. :PROPERTIES:
  518. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  519. :END:
  520. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  521. #+BEGIN_SRC emacs-lisp
  522. ;; (use-package org-id
  523. ;; :config
  524. ;; (setq org-id-link-to-org-use-id t)
  525. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  526. #+END_SRC
  527. ** org-agenda
  528. :PROPERTIES:
  529. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  530. :END:
  531. Custom keywords, depending on environment
  532. #+BEGIN_SRC emacs-lisp
  533. (when *work_remote*
  534. (setq org-todo-keywords
  535. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  536. #+END_SRC
  537. Add some key bindings
  538. #+BEGIN_SRC emacs-lisp
  539. (bind-key "C-c l" 'org-store-link)
  540. (bind-key "C-c c" 'org-capture)
  541. (bind-key "C-c a" 'org-agenda)
  542. #+END_SRC
  543. Sort agenda by deadline and priority
  544. #+BEGIN_SRC emacs-lisp
  545. (setq org-agenda-sorting-strategy
  546. (quote
  547. ((agenda deadline-up priority-down)
  548. (todo priority-down category-keep)
  549. (tags priority-down category-keep)
  550. (search category-keep))))
  551. #+END_SRC
  552. Customize the org agenda
  553. #+BEGIN_SRC emacs-lisp
  554. (defun me--org-skip-subtree-if-priority (priority)
  555. "Skip an agenda subtree if it has a priority of PRIORITY.
  556. PRIORITY may be one of the characters ?A, ?B, or ?C."
  557. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  558. (pri-value (* 1000 (- org-lowest-priority priority)))
  559. (pri-current (org-get-priority (thing-at-point 'line t))))
  560. (if (= pri-value pri-current)
  561. subtree-end
  562. nil)))
  563. (setq org-agenda-custom-commands
  564. '(("c" "Simple agenda view"
  565. ((tags "PRIORITY=\"A\""
  566. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  567. (org-agenda-overriding-header "Hohe Priorität:")))
  568. (agenda ""
  569. ((org-agenda-span 7)
  570. (org-agenda-start-on-weekday nil)
  571. (org-agenda-overriding-header "Nächste 7 Tage:")))
  572. (alltodo ""
  573. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  574. (org-agenda-skip-if nil '(scheduled deadline))))
  575. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  576. #+END_SRC
  577. ** *TODO*
  578. org-super-agenda
  579. ** org-caldav
  580. :PROPERTIES:
  581. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  582. :END:
  583. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  584. #+BEGIN_SRC emacs-lisp
  585. ;;(use-package org-caldav
  586. ;; :ensure t
  587. ;; :config
  588. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  589. ;; org-caldav-calendar-id "orgmode"
  590. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  591. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  592. #+END_SRC
  593. ** journal
  594. :PROPERTIES:
  595. :ID: a1951e18-d862-4198-9652-016e979053c8
  596. :END:
  597. [[https://github.com/bastibe/org-journal][Source]]
  598. #+BEGIN_SRC emacs-lisp
  599. (use-package org-journal
  600. :if *sys/linux*
  601. :ensure t
  602. :defer t
  603. :config
  604. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  605. (when (and (boundp 'org-journal-dir)
  606. (boundp 'org-journal-enable-agenda-integration))
  607. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  608. org-journal-enable-agenda-integration t)))
  609. #+END_SRC
  610. * Programming
  611. ** Magit / Git
  612. :PROPERTIES:
  613. :ID: d3589460-317f-40f6-9056-053be9ba3217
  614. :END:
  615. Little crash course in magit:
  616. - magit-init to init a git project
  617. - magit-status (C-x g) to call the status window
  618. In status buffer:
  619. - s stage files
  620. - u unstage files
  621. - U unstage all files
  622. - a apply changes to staging
  623. - c c commit (type commit message, then C-c C-c to commit)
  624. - b b switch to another branch
  625. - P u git push
  626. - F u git pull
  627. #+BEGIN_SRC emacs-lisp
  628. (use-package magit
  629. :ensure t
  630. :defer t
  631. :init
  632. ; set git-path in work environment
  633. (if (string-equal user-login-name "POH")
  634. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  635. )
  636. :bind (("C-x g" . magit-status)))
  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. :hook (projectile-after-switch-project . (lambda () (set-workon_home)))
  751. :bind
  752. (("C-c p p" . projectile-switch-project)
  753. ("C-c p c" . projectile-command-map)
  754. ("C-c p s s" . projectile-ag))
  755. :preface
  756. (defun set-workon_home()
  757. (setenv "WORKON_HOME" (projectile-project-root)))
  758. :init
  759. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL ".projectile-cache")
  760. projectile-known-projects-file (concat MY--PATH_USER_LOCAL ".projectile-bookmarks"))
  761. :config
  762. (projectile-mode t)
  763. (setq-default projectile-completion-system 'ivy
  764. projectile-enable-caching t
  765. projectile-mode-line '(:eval (projectile-project-name))))
  766. #+END_SRC
  767. ** smartparens
  768. :PROPERTIES:
  769. :ID: 997ec416-33e6-41ed-8c7c-75a7bc47d285
  770. :END:
  771. #+BEGIN_SRC emacs-lisp
  772. (use-package smartparens
  773. :ensure t
  774. :diminish smartparens-mode
  775. :bind
  776. (:map smartparens-mode-map
  777. ("C-M-f" . sp-forward-sexp)
  778. ("C-M-b" . sp-backward-sexp)
  779. ("C-M-a" . sp-backward-down-sexp)
  780. ("C-M-e" . sp-up-sexp)
  781. ("C-M-w" . sp-copy-sexp)
  782. ("M-k" . sp-kill-sexp)
  783. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  784. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  785. ("C-]" . sp-select-next-thing-exchange))
  786. :config
  787. (setq sp-show-pair-from-inside nil
  788. sp-escape-quotes-after-insert nil)
  789. (require 'smartparens-config))
  790. #+END_SRC
  791. ** lisp
  792. :PROPERTIES:
  793. :ID: a2bc3e08-b203-49d3-b337-fb186a14eecb
  794. :END:
  795. #+BEGIN_SRC emacs-lisp
  796. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  797. #+END_SRC
  798. ** web
  799. :PROPERTIES:
  800. :ID: c0b0b4e4-2162-429f-b80d-6e5334b1290e
  801. :END:
  802. apt install npm
  803. sudo npm install -g vscode-html-languageserver-bin
  804. evtl alternativ typescript-language-server?
  805. Unter Windows:
  806. Hier runterladen: https://nodejs.org/dist/latest/
  807. und in ein Verzeichnis entpacken.
  808. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  809. PATH=P:\path\to\node;%path%
  810. #+BEGIN_SRC emacs-lisp
  811. (use-package web-mode
  812. :ensure t
  813. :defer t
  814. :mode
  815. ("\\.phtml\\'"
  816. "\\.tpl\\.php\\'"
  817. "\\.djhtml\\'"
  818. "\\.[t]?html?\\'")
  819. :init
  820. (if *work_remote*
  821. (setq exec-path (append exec-path '("P:/Tools/node"))))
  822. :config
  823. (setq web-mode-enable-auto-closing t
  824. web-mode-enable-auto-pairing t)
  825. (add-hook 'web-mode-hook 'smartparens-mode))
  826. #+END_SRC
  827. Emmet offers snippets, similar to yasnippet.
  828. Default completion is C-j
  829. [[https://github.com/smihica/emmet-mode#usage][Github]]
  830. #+begin_src emacs-lisp
  831. (use-package emmet-mode
  832. :ensure t
  833. :defer t
  834. :hook
  835. ((web-mode . emmet-mode)
  836. (css-mode . emmet-mode))
  837. :config
  838. (unbind-key "C-<return>" emmet-mode-keymap))
  839. #+end_src
  840. ** YAML
  841. :PROPERTIES:
  842. :ID: 95413247-04d5-4e02-8431-06c162ec8f3b
  843. :END:
  844. #+begin_src emacs-lisp
  845. (use-package yaml-mode
  846. :if *sys/linux*
  847. :ensure t
  848. :mode ("\\.yml$" . yaml-mode))
  849. #+end_src
  850. ** R
  851. #+BEGIN_SRC emacs-lisp
  852. (use-package ess
  853. :ensure t
  854. :init
  855. (if *work_remote*
  856. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  857. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  858. #+END_SRC
  859. ** Python
  860. :PROPERTIES:
  861. :ID: 8c76fcd1-c57c-48ab-8af0-aa782de6337f
  862. :END:
  863. Systemseitig muss python-language-server installiert sein:
  864. apt install python3-pip python3-setuptools python3-wheel
  865. apt install build-essential python3-dev
  866. pip3 install 'python-language-server[all]'
  867. für andere language servers
  868. https://github.com/emacs-lsp/lsp-mode#install-language-server
  869. #+BEGIN_SRC emacs-lisp
  870. (use-package lsp-python-ms
  871. :if *sys/linux*
  872. :ensure t
  873. :defer 0.3
  874. :custom (lsp-python-ms-auto-install-server t))
  875. (use-package python
  876. :if *sys/linux*
  877. :delight "π "
  878. :bind (("M-[" . python-nav-backward-block)
  879. ("M-]" . python-nav-forward-block)))
  880. (use-package pyvenv
  881. :if *sys/linux*
  882. :ensure t
  883. :after python
  884. :hook ((python-mode . pyvenv-mode)
  885. (python-mode . (lambda ()
  886. (if-let ((pyvenv-directory (find-pyvenv-directory (buffer-file-name))))
  887. (pyvenv-activate pyvenv-directory))
  888. (lsp))))
  889. :custom
  890. (pyvenv-default-virtual-env-name "env")
  891. (pyvenv-mode-line-indicator '(pyvenv-virtual-env-name ("[venv:" pyvenv-virtual-env-name "]")))
  892. :preface
  893. (defun find-pyvenv-directory (path)
  894. "Check if a pyvenv directory exists."
  895. (cond
  896. ((not path) nil)
  897. ((file-regular-p path) (find-pyvenv-directory (file-name-directory path)))
  898. ((file-directory-p path)
  899. (or
  900. (seq-find
  901. (lambda (path) (file-regular-p (expand-file-name "pyvenv.cfg" path)))
  902. (directory-files path t))
  903. (let ((parent (file-name-directory (directory-file-name path))))
  904. (unless (equal parent path) (find-pyvenv-directory parent))))))))
  905. ;; manage multiple python version
  906. ;; needs to be installed on system
  907. ; (use-package pyenv-mode
  908. ; :ensure t
  909. ; :after python
  910. ; :hook ((python-mode . pyenv-mode)
  911. ; (projectile-switch-project . projectile-pyenv-mode-set))
  912. ; :custom (pyenv-mode-set "3.8.5")
  913. ; :preface
  914. ; (defun projectile-pyenv-mode-set ()
  915. ; "Set pyenv version matching project name."
  916. ; (let ((project (projectile-project-name)))
  917. ; (if (member project (pyenv-mode-versions))
  918. ; (pyenv-mode-set project)
  919. ; (pyenv-mode-unset)))))
  920. ;)
  921. #+END_SRC
  922. * beancount
  923. ** Installation
  924. :PROPERTIES:
  925. :ID: 2c329043-b7a9-437d-a5cf-f2ad6514be91
  926. :END:
  927. #+BEGIN_SRC shell
  928. sudo su
  929. cd /opt
  930. python3 -m venv beancount
  931. source ./beancount/bin/activate
  932. pip3 install wheel
  933. pip3 install beancount
  934. sleep 100
  935. echo "shell running!"
  936. deactivate
  937. #+END_SRC
  938. #+BEGIN_SRC emacs-lisp
  939. (use-package beancount
  940. :if *sys/linux*
  941. :load-path "user-global/elisp"
  942. ; :ensure t
  943. :defer t
  944. :mode
  945. ("\\.beancount$" . beancount-mode)
  946. :init
  947. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  948. ; (add-hook 'beancount-mode-hook (pyvenv-activate "/opt/beancount"))
  949. ; (setenv "PATH"
  950. ; (concat "/opt/beancount/bin:"
  951. ; (getenv "PATH")))
  952. :config
  953. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  954. #+END_SRC
  955. To support org-babel, check if it can find the symlink to ob-beancount.el
  956. #+BEGIN_SRC shell
  957. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  958. beansym="$orgpath/ob-beancount.el
  959. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  960. if [ -h "$beansym" ]
  961. then
  962. echo "$beansym found"
  963. elif [ -e "$bean" ]
  964. then
  965. echo "creating symlink"
  966. ln -s "$bean" "$beansym"
  967. else
  968. echo "$bean not found, symlink creation aborted"
  969. fi
  970. #+END_SRC
  971. Fava is strongly recommended.
  972. #+BEGIN_SRC shell
  973. cd /opt
  974. python3 -m venv fava
  975. source ./fava/bin/activate
  976. pip3 install wheel
  977. pip3 install fava
  978. deactivate
  979. #+END_SRC
  980. Start fava with fava my_file.beancount
  981. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  982. Beancount-mode can start fava and open the URL right away.