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.

1037 lines
30 KiB

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