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.

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