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.

1029 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
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
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
  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 "~/.emacs.d/user-local/"))
  113. (defvar MY--PATH_USER_GLOBAL (expand-file-name "~/.emacs.d/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-hooks '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. * imenu-list
  279. :PROPERTIES:
  280. :ID: 0ae27ec9-5d77-43cf-ac76-5e12cc959046
  281. :END:
  282. A minor mode to show imenu in a sidebar.
  283. Call imenu-list-smart-toggle.
  284. [[https://github.com/bmag/imenu-list][Source]]
  285. #+BEGIN_SRC emacs-lisp
  286. (use-package imenu-list
  287. :ensure t
  288. :config
  289. (setq imenu-list-focus-after-activation t
  290. imenu-list-auto-resize t
  291. imenu-list-position 'right)
  292. :bind
  293. (:map global-map
  294. ([f9] . imenu-list-smart-toggle))
  295. )
  296. #+END_SRC
  297. * which-key
  298. :PROPERTIES:
  299. :ID: a880f079-b3a3-4706-bf1e-5f6c680101f1
  300. :END:
  301. #+BEGIN_SRC emacs-lisp
  302. (use-package which-key
  303. :ensure t
  304. :diminish which-key-mode
  305. :config
  306. (which-key-mode)
  307. (which-key-setup-side-window-right-bottom)
  308. (which-key-setup-minibuffer)
  309. (setq which-key-idle-delay 0.5))
  310. #+END_SRC
  311. * Evil
  312. :PROPERTIES:
  313. :ID: 80ca70e2-a146-46db-b581-418d655dc1fc
  314. :END:
  315. #+BEGIN_SRC emacs-lisp
  316. (use-package evil
  317. :ensure t
  318. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  319. :config
  320. (evil-mode 1))
  321. #+END_SRC
  322. * General (key mapper)
  323. :PROPERTIES:
  324. :ID: a20f183f-d41a-4dff-bc37-3bc4e25c8036
  325. :END:
  326. #+BEGIN_SRC emacs-lisp
  327. (use-package general
  328. :ensure t)
  329. (general-define-key
  330. :states 'normal
  331. :keymaps 'imenu-list-major-mode-map
  332. (kbd "RET") '(imenu-list-goto-entry :which-key "goto")
  333. (kbd "TAB") '(hs-toggle-hiding :which-key "collapse")
  334. "d" '(imenu-list-display-entry :which-key "show")
  335. "q" '(imenu-list-quit-window :which-key "quit"))
  336. #+END_SRC
  337. * ivy / counsel / swiper
  338. :PROPERTIES:
  339. :ID: 55c74ba9-7761-4545-8ddd-087d6ee33e4b
  340. :END:
  341. #+BEGIN_SRC emacs-lisp
  342. ; (require 'ivy)
  343. (use-package ivy
  344. :ensure t
  345. :diminish
  346. (ivy-mode . "")
  347. :init
  348. (ivy-mode 1)
  349. :bind
  350. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  351. :config
  352. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  353. ivy-height 20 ;; height of ivy window
  354. ivy-count-format "%d/%d" ;; current and total number
  355. ivy-re-builders-alist ;; regex replaces spaces with *
  356. '((t . ivy--regex-plus))))
  357. (use-package counsel
  358. :ensure t
  359. :bind*
  360. (("M-x" . counsel-M-x)
  361. ("C-x C-f" . counsel-find-file)
  362. ("C-x C-r" . counsel-recentf)
  363. ("C-c C-f" . counsel-git)
  364. ("C-c h f" . counsel-describe-function)
  365. ("C-c h v" . counsel-describe-variable)
  366. ("M-i" . counsel-imenu)))
  367. (use-package swiper
  368. :ensure t
  369. :bind
  370. ("C-s" . swiper))
  371. (use-package ivy-hydra
  372. :ensure t)
  373. #+END_SRC
  374. * company
  375. :PROPERTIES:
  376. :ID: 944563b6-b04a-44f2-9b21-a6a3e200867c
  377. :END:
  378. #+BEGIN_SRC emacs-lisp
  379. (use-package company
  380. :defer 1
  381. :bind
  382. (("C-<tab>" . company-complete)
  383. :map company-active-map
  384. ("RET" . nil)
  385. ([return] . nil)
  386. ("TAB" . company-complete-selection)
  387. ([tab] . company-complete-selection)
  388. ("<right>" . company-complete-common))
  389. :hook
  390. (after-init . global-company-mode)
  391. :config
  392. (setq company-idle-delay .2
  393. company-minimum-prefix-length 1
  394. company-require-match nil
  395. company-show-numbers t
  396. company-tooltip-align-annotations t))
  397. (use-package company-statistics
  398. :ensure t
  399. :after company
  400. :init
  401. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  402. :config
  403. (company-statistics-mode 1))
  404. (use-package company-dabbrev
  405. :ensure nil
  406. :after company
  407. :config
  408. (setq-default company-dabbrev-downcase nil))
  409. (use-package company-box
  410. :ensure t
  411. :init
  412. (add-hook 'company-mode-hook 'company-box-mode))
  413. #+END_SRC
  414. ** company backends
  415. :PROPERTIES:
  416. :ID: 4ce2e728-276d-41f9-9538-84e6e08afd8d
  417. :END:
  418. #+BEGIN_SRC emacs-lisp
  419. (defun company/org-mode-hook()
  420. (set (make-local-variable 'company-backends)
  421. '(company-capf company-files))
  422. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  423. (message "company/org-mode-hook"))
  424. (defun company/elisp-mode-hook()
  425. (set (make-local-variable 'company-backends)
  426. '(company-capf company-files))
  427. (message "company/elisp-mode-hook"))
  428. (defun company/beancount-mode-hook()
  429. (set (make-local-variable 'company-backends)
  430. '(company-beancount)))
  431. #+END_SRC
  432. * orgmode
  433. ** org
  434. :PROPERTIES:
  435. :ID: b89d7639-080c-4168-8884-bd5d8965f466
  436. :END:
  437. #+BEGIN_SRC emacs-lisp
  438. (use-package org
  439. :ensure org-plus-contrib
  440. :mode (("\.org$" . org-mode))
  441. :init
  442. (add-hook 'org-mode-hook 'company/org-mode-hook)
  443. (add-hook 'org-src-mode-hook 'smartparens-mode)
  444. (add-hook 'org-mode-hook 'org-indent-mode)
  445. :config
  446. (setq org-modules (quote (org-id
  447. org-habit
  448. org-tempo ;; easy templates
  449. )))
  450. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  451. org-agenda-files (list (concat MY--PATH_ORG_FILES "notes.org")
  452. (concat MY--PATH_ORG_FILES "projects.org")
  453. (concat MY--PATH_ORG_FILES "todo.org")))
  454. (when *sys/linux*
  455. (setq org-agenda-files (list org-agenda-files
  456. MY--PATH_ORG_FILES_MOBILE)))
  457. (setq org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  458. org-log-into-drawer "LOGBOOK")
  459. ;; some display customizations
  460. (setq org-pretty-entities t
  461. org-startup-truncated t
  462. org-startup-align-all-tables t)
  463. ;; some source code blocks customizations
  464. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  465. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  466. org-src-preserve-indentation t ;; no extra indentation
  467. org-src-tab-acts-natively t)
  468. (setq org-log-done 'time)) ;; create timestamp when task is done
  469. #+END_SRC
  470. ** languages
  471. :PROPERTIES:
  472. :ID: ad3af718-d0db-448c-9f75-eb9e250c2862
  473. :END:
  474. Set some languages and disable confirmation for evaluating code blocks C-c C-c
  475. #+BEGIN_SRC emacs-lisp
  476. (org-babel-do-load-languages
  477. 'org-babel-load-languages
  478. '((emacs-lisp . t)
  479. (gnuplot . t)
  480. (js . t)
  481. (latex . t)
  482. (lisp . t)
  483. (python . t)
  484. (shell . t)
  485. (sqlite . t)
  486. (org . t)
  487. (R . t)
  488. (scheme . t)))
  489. (setq org-confirm-babel-evaluate nil)
  490. #+END_SRC
  491. ** habits
  492. :PROPERTIES:
  493. :ID: fcc91d0a-d040-4910-b2cf-3221496a3842
  494. :END:
  495. #+BEGIN_SRC emacs-lisp
  496. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  497. ;; (add-to-list 'org-modules "org-habit")
  498. (setq org-habit-graph-column 80
  499. org-habit-preceding-days 30
  500. org-habit-following-days 7
  501. org-habit-show-habits-only-for-today nil)
  502. #+END_SRC
  503. ** org-id
  504. :PROPERTIES:
  505. :ID: c4017c45-d650-410c-8bd4-bc3cf42bbbb9
  506. :END:
  507. Currently it causes some debugger errors "not a standard org time string", so it's disabled
  508. #+BEGIN_SRC emacs-lisp
  509. ;; (use-package org-id
  510. ;; :config
  511. ;; (setq org-id-link-to-org-use-id t)
  512. ;; (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  513. #+END_SRC
  514. ** org-agenda
  515. :PROPERTIES:
  516. :ID: 03b67efb-4179-41e5-bc2e-c472b13f8be6
  517. :END:
  518. Custom keywords, depending on environment
  519. #+BEGIN_SRC emacs-lisp
  520. (when *work_remote*
  521. (setq org-todo-keywords
  522. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE" "CANCELLED"))))
  523. #+END_SRC
  524. Add some key bindings
  525. #+BEGIN_SRC emacs-lisp
  526. (bind-key "C-c l" 'org-store-link)
  527. (bind-key "C-c c" 'org-capture)
  528. (bind-key "C-c a" 'org-agenda)
  529. #+END_SRC
  530. Sort agenda by deadline and priority
  531. #+BEGIN_SRC emacs-lisp
  532. (setq org-agenda-sorting-strategy
  533. (quote
  534. ((agenda deadline-up priority-down)
  535. (todo priority-down category-keep)
  536. (tags priority-down category-keep)
  537. (search category-keep))))
  538. #+END_SRC
  539. Customize the org agenda
  540. #+BEGIN_SRC emacs-lisp
  541. (defun me--org-skip-subtree-if-priority (priority)
  542. "Skip an agenda subtree if it has a priority of PRIORITY.
  543. PRIORITY may be one of the characters ?A, ?B, or ?C."
  544. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  545. (pri-value (* 1000 (- org-lowest-priority priority)))
  546. (pri-current (org-get-priority (thing-at-point 'line t))))
  547. (if (= pri-value pri-current)
  548. subtree-end
  549. nil)))
  550. (setq org-agenda-custom-commands
  551. '(("c" "Simple agenda view"
  552. ((tags "PRIORITY=\"A\""
  553. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  554. (org-agenda-overriding-header "Hohe Priorität:")))
  555. (agenda ""
  556. ((org-agenda-span 7)
  557. (org-agenda-start-on-weekday nil)
  558. (org-agenda-overriding-header "Nächste 7 Tage:")))
  559. (alltodo ""
  560. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  561. (org-agenda-skip-if nil '(scheduled deadline))))
  562. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  563. #+END_SRC
  564. ** *TODO*
  565. org-super-agenda
  566. ** org-caldav
  567. :PROPERTIES:
  568. :ID: 6bd24369-0d04-452f-85a0-99914dfb74ff
  569. :END:
  570. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  571. #+BEGIN_SRC emacs-lisp
  572. ;;(use-package org-caldav
  573. ;; :ensure t
  574. ;; :config
  575. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  576. ;; org-caldav-calendar-id "orgmode"
  577. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  578. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  579. #+END_SRC
  580. ** journal
  581. :PROPERTIES:
  582. :ID: a1951e18-d862-4198-9652-016e979053c8
  583. :END:
  584. [[https://github.com/bastibe/org-journal][Source]]
  585. #+BEGIN_SRC emacs-lisp
  586. (use-package org-journal
  587. :if *sys/linux*
  588. :ensure t
  589. :defer t
  590. :config
  591. ;; feels hacky, but this way compiler error "assignment to free variable" disappears
  592. (when (and (boundp 'org-journal-dir)
  593. (boundp 'org-journal-enable-agenda-integration))
  594. (setq org-journal-dir MY--PATH_ORG_JOURNAl
  595. org-journal-enable-agenda-integration t)))
  596. #+END_SRC
  597. * Programming
  598. ** Magit / Git
  599. :PROPERTIES:
  600. :ID: d3589460-317f-40f6-9056-053be9ba3217
  601. :END:
  602. Little crash course in magit:
  603. - magit-init to init a git project
  604. - magit-status (C-x g) to call the status window
  605. In status buffer:
  606. - s stage files
  607. - u unstage files
  608. - U unstage all files
  609. - a apply changes to staging
  610. - c c commit (type commit message, then C-c C-c to commit)
  611. - b b switch to another branch
  612. - P u git push
  613. - F u git pull
  614. #+BEGIN_SRC emacs-lisp
  615. (use-package magit
  616. :ensure t
  617. :defer t
  618. :init
  619. ; set git-path in work environment
  620. (if (string-equal user-login-name "POH")
  621. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  622. )
  623. :bind (("C-x g" . magit-status))
  624. )
  625. #+END_SRC
  626. ** LSP
  627. :PROPERTIES:
  628. :ID: 06ad00e0-44a6-4bfb-ba6f-b1672811e053
  629. :END:
  630. Configuration for the language server protocol
  631. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  632. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  633. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  634. TODO Unterverzeichnisse wurden noch nicht getestet
  635. #+BEGIN_SRC emacs-lisp
  636. (use-package lsp-mode
  637. :defer t
  638. :commands lsp
  639. :custom
  640. (lsp-auto-guess-root nil)
  641. (lsp-prefer-flymake nil) ; use flycheck instead
  642. (lsp-file-watch-threshold 2000)
  643. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  644. :hook ((python-mode
  645. js-mode
  646. js2-mode
  647. typescript-mode
  648. web-mode) . lsp))
  649. (use-package lsp-ui
  650. :after lsp-mode
  651. :ensure t
  652. :diminish
  653. :commands lsp-ui-mode
  654. :config
  655. (setq lsp-ui-doc-enable t
  656. lsp-ui-doc-header t
  657. lsp-ui-doc-include-signature t
  658. lsp-ui-doc-position 'top
  659. lsp-ui-doc-border (face-foreground 'default)
  660. lsp-ui-sideline-enable nil
  661. lsp-ui-sideline-ignore-duplicate t
  662. lsp-ui-sideline-show-code-actions nil)
  663. (when *sys/gui*
  664. (setq lsp-ui-doc-use-webkit t))
  665. ;; workaround hide mode-line of lsp-ui-imenu buffer
  666. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  667. (setq mode-line-format nil)))
  668. (use-package company-lsp
  669. :requires company
  670. :defer t
  671. :ensure t
  672. :config
  673. ;;disable client-side cache because lsp server does a better job
  674. (setq company-transformers nil
  675. company-lsp-async t
  676. company-lsp-cache-candidates nil))
  677. #+END_SRC
  678. ** yasnippet
  679. :PROPERTIES:
  680. :ID: 935d89ef-645e-4e92-966f-2fe3bebb2880
  681. :END:
  682. For useful snippet either install yasnippet-snippets or get them from here
  683. [[https://github.com/AndreaCrotti/yasnippet-snippets][Github]]
  684. #+begin_src emacs-lisp
  685. (use-package yasnippet
  686. :ensure t
  687. :diminish yas-minor-mode
  688. :config
  689. (setq yas-snippet-dirs (list (concat MY--PATH_USER_GLOBAL "snippets")))
  690. (yas-global-mode t)
  691. (yas-reload-all)
  692. (unbind-key "TAB" yas-minor-mode-map)
  693. (unbind-key "<tab>" yas-minor-mode-map))
  694. #+end_src
  695. ** hippie expand
  696. :PROPERTIES:
  697. :ID: c55245bc-813d-4816-a0ca-b4e2e793e28b
  698. :END:
  699. With hippie expand I am able to use yasnippet and emmet at the same time with the same key.
  700. #+begin_src emacs-lisp
  701. (use-package hippie-exp
  702. :defer t
  703. :bind
  704. ("C-<return>" . hippie-expand)
  705. :config
  706. (setq hippie-expand-try-functions-list
  707. '(yas-hippie-try-expand emmet-expand-line)))
  708. #+end_src
  709. ** flycheck
  710. :PROPERTIES:
  711. :ID: 3d8f2547-c5b3-46d0-91b0-9667f9ee5c47
  712. :END:
  713. #+BEGIN_SRC emacs-lisp
  714. (use-package flycheck
  715. :ensure t
  716. :hook
  717. ((css-mode . flycheck-mode)
  718. (emacs-lisp-mode . flycheck-mode)
  719. (python-mode . flycheck-mode))
  720. :init
  721. (setq flycheck-emacs-lisp-load-path 'inherit)
  722. :config
  723. (setq-default
  724. flycheck-check-synta-automatically '(save mode-enabled)
  725. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  726. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  727. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  728. #+END_SRC
  729. ** Projectile
  730. :PROPERTIES:
  731. :ID: a90329fd-4d36-435f-8308-a2771ac4c320
  732. :END:
  733. Manage projects and jump quickly between its files
  734. #+BEGIN_SRC emacs-lisp
  735. (use-package projectile
  736. :ensure t
  737. :defer t
  738. :bind
  739. (("C-c p p" . projectile-switch-project)
  740. ("C-c p c" . projectile-command-map)
  741. ("C-c p s s" . projectile-ag))
  742. :init
  743. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL ".projectile-cache")
  744. projectile-known-projects-file (concat MY--PATH_USER_LOCAL ".projectile-bookmarks"))
  745. :config
  746. (projectile-mode t)
  747. (setq-default projectile-completion-system 'ivy
  748. projectile-enable-caching t
  749. projectile-mode-line '(:eval (projectile-project-name))))
  750. #+END_SRC
  751. ** smartparens
  752. :PROPERTIES:
  753. :ID: 997ec416-33e6-41ed-8c7c-75a7bc47d285
  754. :END:
  755. #+BEGIN_SRC emacs-lisp
  756. (use-package smartparens
  757. :ensure t
  758. :diminish smartparens-mode
  759. :bind
  760. (:map smartparens-mode-map
  761. ("C-M-f" . sp-forward-sexp)
  762. ("C-M-b" . sp-backward-sexp)
  763. ("C-M-a" . sp-backward-down-sexp)
  764. ("C-M-e" . sp-up-sexp)
  765. ("C-M-w" . sp-copy-sexp)
  766. ("M-k" . sp-kill-sexp)
  767. ("C-M-<backspace>" . sp-slice-sexp-killing-backward)
  768. ("C-S-<backspace>" . sp-slice-sexp-killing-around)
  769. ("C-]" . sp-select-next-thing-exchange))
  770. :config
  771. (setq sp-show-pair-from-inside nil
  772. sp-escape-quotes-after-insert nil)
  773. (require 'smartparens-config))
  774. #+END_SRC
  775. ** lisp
  776. :PROPERTIES:
  777. :ID: a2bc3e08-b203-49d3-b337-fb186a14eecb
  778. :END:
  779. #+BEGIN_SRC emacs-lisp
  780. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  781. #+END_SRC
  782. ** web
  783. :PROPERTIES:
  784. :ID: c0b0b4e4-2162-429f-b80d-6e5334b1290e
  785. :END:
  786. apt install npm
  787. sudo npm install -g vscode-html-languageserver-bin
  788. evtl alternativ typescript-language-server?
  789. Unter Windows:
  790. Hier runterladen: https://nodejs.org/dist/latest/
  791. und in ein Verzeichnis entpacken.
  792. Optional: PATH erweitern unter Windows (so kann exec-path-from-shell den Pfad ermitteln):
  793. PATH=P:\path\to\node;%path%
  794. #+BEGIN_SRC emacs-lisp
  795. (use-package web-mode
  796. :ensure t
  797. :defer t
  798. :mode
  799. ("\\.phtml\\'"
  800. "\\.tpl\\.php\\'"
  801. "\\.djhtml\\'"
  802. "\\.[t]?html?\\'")
  803. :init
  804. (if *work_remote*
  805. (setq exec-path (append exec-path '("P:/Tools/node"))))
  806. :config
  807. (setq web-mode-enable-auto-closing t
  808. web-mode-enable-auto-pairing t)
  809. (add-hook 'web-mode-hook 'smartparens-mode))
  810. #+END_SRC
  811. Emmet offers snippets, similar to yasnippet.
  812. Default completion is C-j
  813. [[https://github.com/smihica/emmet-mode#usage][Github]]
  814. #+begin_src emacs-lisp
  815. (use-package emmet-mode
  816. :ensure t
  817. :defer t
  818. :hook
  819. ((web-mode . emmet-mode)
  820. (css-mode . emmet-mode))
  821. :config
  822. (unbind-key "C-<return>" emmet-mode-keymap))
  823. #+end_src
  824. ** YAML
  825. :PROPERTIES:
  826. :ID: 95413247-04d5-4e02-8431-06c162ec8f3b
  827. :END:
  828. #+begin_src emacs-lisp
  829. (use-package yaml-mode
  830. :if *sys/linux*
  831. :ensure t
  832. :mode ("\\.yml$" . yaml-mode))
  833. #+end_src
  834. ** R
  835. #+BEGIN_SRC emacs-lisp
  836. (use-package ess
  837. :ensure t
  838. :init
  839. (if *work_remote*
  840. (setq exec-path (append exec-path '("P:/Tools/R/bin/x64"))
  841. org-babel-R-command "P:/Tools/R/bin/x64/R --slave --no-save")))
  842. #+END_SRC
  843. ** Python
  844. :PROPERTIES:
  845. :ID: 8c76fcd1-c57c-48ab-8af0-aa782de6337f
  846. :END:
  847. Systemseitig muss python-language-server installiert sein:
  848. pip3 install 'python-language-server[all]'
  849. für andere language servers
  850. https://github.com/emacs-lsp/lsp-mode#install-language-server
  851. #+BEGIN_SRC emacs-lisp
  852. (if *sys/linux*
  853. (defun my/postactivatehook ()
  854. (setq lsp-python-ms-extra-paths pyvenv-virtual-env))
  855. (use-package pyvenv
  856. :ensure t
  857. :config
  858. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  859. (add-hook 'pyvenv-post-activate-hooks 'my/postactivatehook))
  860. (use-package virtualenvwrapper
  861. :ensure t
  862. :hook (venv-postmkvirtualenv . (lambda() (shell-command "pip3 install importmagic epc")))
  863. :config
  864. (setq venv-location (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  865. (use-package lsp-python-ms
  866. :ensure t
  867. ;:after lsp-mode python
  868. :hook (python-mode . (lambda()
  869. (require 'lsp-python-ms)
  870. (lsp)))
  871. :init
  872. (setq lsp-python-ms-executable
  873. "~/.emacs.d/mspyls/Microsoft.Python.LanguageServer")
  874. :custom (lsp-python-executable-cmd "python3")))
  875. #+END_SRC
  876. * beancount
  877. ** Installation
  878. :PROPERTIES:
  879. :ID: 2c329043-b7a9-437d-a5cf-f2ad6514be91
  880. :END:
  881. #+BEGIN_SRC shell
  882. sudo su
  883. cd /opt
  884. python3 -m venv beancount
  885. source ./beancount/bin/activate
  886. pip3 install wheel
  887. pip3 install beancount
  888. sleep 100
  889. echo "shell running!"
  890. deactivate
  891. #+END_SRC
  892. #+BEGIN_SRC emacs-lisp
  893. (use-package beancount
  894. :if *sys/linux*
  895. :load-path "user-global/elisp"
  896. ; :ensure t
  897. :defer t
  898. :mode
  899. ("\\.beancount$" . beancount-mode)
  900. :init
  901. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  902. ; (add-hook 'beancount-mode-hook (pyvenv-activate "/opt/beancount"))
  903. ; (setenv "PATH"
  904. ; (concat "/opt/beancount/bin:"
  905. ; (getenv "PATH")))
  906. :config
  907. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  908. #+END_SRC
  909. To support org-babel, check if it can find the symlink to ob-beancount.el
  910. #+BEGIN_SRC shell
  911. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  912. beansym="$orgpath/ob-beancount.el
  913. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  914. if [ -h "$beansym" ]
  915. then
  916. echo "$beansym found"
  917. elif [ -e "$bean" ]
  918. then
  919. echo "creating symlink"
  920. ln -s "$bean" "$beansym"
  921. else
  922. echo "$bean not found, symlink creation aborted"
  923. fi
  924. #+END_SRC
  925. Fava is strongly recommended.
  926. #+BEGIN_SRC shell
  927. cd /opt
  928. python3 -m venv fava
  929. source ./fava/bin/activate
  930. pip3 install wheel
  931. pip3 install fava
  932. deactivate
  933. #+END_SRC
  934. Start fava with fava my_file.beancount
  935. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  936. Beancount-mode can start fava and open the URL right away.