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.

1039 lines
30 KiB

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