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.

544 lines
16 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
  1. #+TITLE: Emacs configuration file
  2. #+BABEL: :cache yes
  3. #+PROPERTY: header-args :tangle yes
  4. * TODOS
  5. - Paket exec-path-from-shell, um PATH aus Linux auch in emacs zu haben
  6. * First start
  7. 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
  8. #+NAME: init.el
  9. #+BEGIN_SRC emacs-lisp :tangle no
  10. (require 'org')
  11. (find-file (concat user-emacs-directory "init.org"))
  12. (org-babel-tangle)
  13. (load-file (concat user-emacs-directory "init.el"))
  14. (byte-compile-file (concat user-emacs-directory "init.el"))
  15. #+END_SRC
  16. This function updates init.el whenever changes in init.org are made. The update will be active after saving.
  17. #+BEGIN_SRC emacs-lisp
  18. (defun me/tangle-init ()
  19. "If the current buffer is 'init.org',
  20. the code blocks are tangled, and the tangled file is compiled."
  21. (when (equal (buffer-file-name)
  22. (expand-file-name (concat user-emacs-directory "init.org")))
  23. ;; avoid running hooks
  24. (let ((prog-mode-hook nil))
  25. (org-babel-tangle)
  26. (byte-compile-file (concat user-emacs-directory "init.el"))
  27. (load-file user-init-file))))
  28. (add-hook 'after-save-hook 'me/tangle-init)
  29. #+END_SRC
  30. #+BEGIN_SRC emacs-lisp
  31. (require 'package)
  32. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  33. (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  34. (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
  35. (package-initialize)
  36. #+END_SRC
  37. #+BEGIN_SRC emacs-lisp
  38. (unless (package-installed-p 'use-package)
  39. (package-refresh-contents)
  40. (package-install 'use-package))
  41. (setq use-package-verbose nil)
  42. ;(eval-when-compile
  43. (require 'use-package);)
  44. #+END_SRC
  45. * Default settings
  46. #+BEGIN_SRC emacs-lisp
  47. (defvar MY--PATH_USER_LOCAL (expand-file-name "~/.emacs.d/user-local/"))
  48. (defvar MY--PATH_USER_GLOBAL (expand-file-name "~/.emacs.d/user-global/"))
  49. (defvar MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/"))
  50. (defvar MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/"))
  51. (defvar MY--PATH_ORG_JOURNAl (expand-file-name "~/Archiv/Organisieren/Journal/"))
  52. (setq bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks"))
  53. (setq recentf-save-file (concat MY--PATH_USER_LOCAL "recentf"))
  54. (setq custom-file (concat MY--PATH_USER_LOCAL "custom.el")) ;; don't spam init.e with saved customization settings
  55. (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_defs"))
  56. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  57. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  58. (setq save-abbrevs 'silently) ;; don't bother me with asking for abbrev saving
  59. (setq-default create-lockfiles nil) ;; disable lock files, can cause trouble in e.g. lsp-mode
  60. (defalias 'yes-or-no-p 'y-or-n-p) ;; answer with y and n
  61. (setq custom-safe-themes t) ;; don't ask me if I want to load a theme
  62. (setq sentence-end-double-space nil) ;; don't coun two spaces after a period as the end of a sentence.
  63. (delete-selection-mode t) ;; delete selected region when typing
  64. (setq locale-coding-system 'utf-8)
  65. (set-terminal-coding-system 'utf-8)
  66. (set-keyboard-coding-system 'utf-8)
  67. (set-selection-coding-system 'utf-8)
  68. (if (eq system-type 'windows-nt)
  69. (prefer-coding-system 'utf-8dos)
  70. (prefer-coding-system 'utf-8))
  71. (blink-cursor-mode -1) ;; turn off blinking cursor
  72. (show-paren-mode t) ;; show other part of brackets
  73. (column-number-mode t)
  74. (setq uniquify-buffer-name-style 'forward)
  75. (setq-default indent-tabs-mode nil) ;; avoid tabs in place of multiple spaces (they look bad in tex)
  76. (setq-default indicate-empty-lines t) ;; show empty lines
  77. (setq scroll-margin 5 ;; smooth scrolling
  78. scroll-conservatively 10000
  79. scroll-preserve-screen-position 1
  80. scroll-step 1)
  81. (global-hl-line-mode t) ;; highlight current line
  82. (menu-bar-mode 0) ;; disable menu bar
  83. (tool-bar-mode 0) ;; disable tool bar
  84. (scroll-bar-mode 0) ;; disable scroll bar
  85. #+END_SRC
  86. * visuals
  87. ** Font
  88. #+BEGIN_SRC emacs-lisp
  89. (set-face-font 'default "Hack Nerd Font Mono-10")
  90. #+END_SRC
  91. ** line wrappings
  92. #+BEGIN_SRC emacs-lisp
  93. (global-visual-line-mode)
  94. (diminish 'visual-line-mode)
  95. (use-package adaptive-wrap
  96. :ensure t
  97. :init
  98. (when (fboundp 'adaptive-wrap-prefix-mode)
  99. (defun my/activate-adaptive-wrap-prefix-mode ()
  100. "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  101. (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  102. (add-hook 'visual-line-mode-hook 'my/activate-adaptive-wrap-prefix-mode)))
  103. #+END_SRC
  104. ** line numbers
  105. #+BEGIN_SRC emacs-lisp
  106. (use-package display-line-numbers
  107. :init
  108. (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  109. (add-hook 'org-src-mode-hook 'display-line-numbers-mode)
  110. :config
  111. (setq-default display-line-numbers-type 'visual
  112. display-line-numbers-current-absolute t
  113. display-line-numbers-with 4
  114. display-line-numbers-widen t))
  115. ; (add-hook 'emacs-lisp-mode-hook 'display-line-numbers-mode)
  116. #+END_SRC
  117. ** misc
  118. #+BEGIN_SRC emacs-lisp
  119. (use-package rainbow-mode
  120. :diminish
  121. :hook ((org-mode
  122. emacs-lisp-mode) . rainbow-mode))
  123. #+END_SRC
  124. * undo
  125. #+BEGIN_SRC emacs-lisp
  126. (require 'undo-tree)
  127. (use-package undo-tree
  128. :ensure t
  129. :diminish undo-tree-mode
  130. :init
  131. (global-undo-tree-mode 1))
  132. #+END_SRC
  133. * imenu-list
  134. A minor mode to show imenu in a sidebar.
  135. Call imenu-list-smart-toggle.
  136. [[https://github.com/bmag/imenu-list][Source]]
  137. #+BEGIN_SRC emacs-lisp
  138. (use-package imenu-list
  139. :ensure t
  140. :config
  141. (setq imenu-list-focus-after-activation t
  142. imenu-list-auto-resize t
  143. imenu-list-position 'right)
  144. :bind
  145. (:map global-map
  146. ([f9] . imenu-list-smart-toggle))
  147. )
  148. #+END_SRC
  149. * which-key
  150. #+BEGIN_SRC emacs-lisp
  151. (require 'which-key)
  152. (use-package which-key
  153. :ensure t
  154. :diminish which-key-mode
  155. :config
  156. (which-key-mode)
  157. (which-key-setup-side-window-right-bottom)
  158. (which-key-setup-minibuffer)
  159. (setq which-key-idle-delay 0.5))
  160. #+END_SRC
  161. * orgmode
  162. ** org
  163. #+BEGIN_SRC emacs-lisp
  164. (use-package org
  165. :ensure org-plus-contrib
  166. :init
  167. (add-hook 'org-mode-hook 'company/org-mode-hook)
  168. :config
  169. ;; (require 'org-id)
  170. (add-to-list 'org-modules "org-id")
  171. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  172. org-agenda-files (list MY--PATH_ORG_FILES
  173. MY--PATH_ORG_FILES_MOBILE)
  174. org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  175. org-log-into-drawer "LOGBOOK"))
  176. (org-id-update-id-locations)
  177. #+END_SRC
  178. ** habits
  179. #+BEGIN_SRC emacs-lisp
  180. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  181. ;; (add-to-list 'org-modules "org-habit")
  182. (setq org-habit-graph-column 80
  183. org-habit-preceding-days 30
  184. org-habit-following-days 7
  185. org-habit-show-habits-only-for-today nil)
  186. #+END_SRC
  187. ** *TODO*
  188. org-super-agenda
  189. ** org-caldav
  190. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  191. BEGIN_SRC emacs-lisp
  192. (use-package org-caldav
  193. :ensure t
  194. :config
  195. (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  196. org-caldav-calendar-id "orgmode"
  197. org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  198. org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  199. END_SRC
  200. ** journal
  201. [[https://github.com/bastibe/org-journal][Source]]
  202. #+BEGIN_SRC emacs-lisp
  203. (use-package org-journal
  204. :ensure t
  205. :defer t
  206. :custom
  207. (org-journal-dir MY--PATH_ORG_JOURNAl)
  208. (org-journal-enable-agenda-integration t))
  209. #+END_SRC
  210. * ivy / counsel / swiper
  211. #+BEGIN_SRC emacs-lisp
  212. (require 'ivy)
  213. (use-package ivy
  214. :ensure t
  215. :diminish
  216. (ivy-mode . "")
  217. :init
  218. (ivy-mode 1)
  219. :bind
  220. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  221. :config
  222. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  223. ivy-height 20 ;; height of ivy window
  224. ivy-count-format "%d/%d" ;; current and total number
  225. ivy-re-builders-alist ;; regex replaces spaces with *
  226. '((t . ivy--regex-plus))))
  227. (use-package counsel
  228. :ensure t
  229. :bind*
  230. (("M-x" . counsel-M-x)
  231. ("C-x C-f" . counsel-find-file)
  232. ("C-x C-r" . counsel-recentf)
  233. ("C-c C-f" . counsel-git)
  234. ("C-c h f" . counsel-describe-function)
  235. ("C-c h v" . counsel-describe-variable)
  236. ("M-i" . counsel-imenu)))
  237. (use-package swiper
  238. :ensure t
  239. :bind
  240. ("C-s" . swiper))
  241. (use-package ivy-hydra
  242. :ensure t)
  243. #+END_SRC
  244. * company
  245. #+BEGIN_SRC emacs-lisp
  246. (require 'company)
  247. (use-package company
  248. :defer 1
  249. :bind
  250. (:map company-active-map
  251. ("RET" . nil)
  252. ([return] . nil)
  253. ("TAB" . company-complete-selection)
  254. ([tab] . company-complete-selection)
  255. ("<right>" . company-complete-common))
  256. :config
  257. (global-company-mode 1)
  258. (setq-default
  259. company-idle-delay .2
  260. company-minimum-prefix-length 1
  261. company-require-match nil
  262. company-show-numbers t
  263. company-tooltip-align-annotations t))
  264. (require 'company-statistics)
  265. (use-package company-statistics
  266. :ensure t
  267. :after company
  268. :init
  269. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  270. :config
  271. (company-statistics-mode 1))
  272. (use-package company-dabbrev
  273. :ensure nil
  274. :after company
  275. :config
  276. (setq-default company-dabbrev-downcase nil))
  277. (use-package company-box
  278. :ensure nil
  279. :init
  280. (add-hook 'company-mode-hook 'company-box-mode))
  281. #+END_SRC
  282. ** company backends
  283. #+BEGIN_SRC emacs-lisp
  284. (defun company/org-mode-hook()
  285. (set (make-local-variable 'company-backends)
  286. '(company-capf company-files))
  287. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  288. (message "company/org-mode-hook"))
  289. (defun company/elisp-mode-hook()
  290. (set (make-local-variable 'company-backends)
  291. '((company-elisp company-dabbrev) company-capf company-files))
  292. (message "company/elisp-mode-hook"))
  293. (defun company/beancount-mode-hook()
  294. (set (make-local-variable 'company-backends)
  295. '(company-beancount)))
  296. #+END_SRC
  297. * Programming
  298. ** Magit / Git
  299. Little crash course in magit:
  300. - magit-init to init a git project
  301. - magit-status (C-x g) to call the status window
  302. In status buffer:
  303. - s stage files
  304. - u unstage files
  305. - U unstage all files
  306. - a apply changes to staging
  307. - c c commit (type commit message, then C-c C-c to commit)
  308. - b b switch to another branch
  309. - P u git push
  310. - F u git pull
  311. #+BEGIN_SRC emacs-lisp
  312. (use-package magit
  313. :ensure t
  314. :defer t
  315. :init
  316. ; set git-path in work environment
  317. (if (string-equal user-login-name "POH")
  318. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  319. )
  320. :bind (("C-x g" . magit-status))
  321. )
  322. #+END_SRC
  323. ** LSP
  324. Configuration for the language server protocol
  325. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  326. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  327. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  328. TODO Unterverzeichnisse wurden noch nicht getestet
  329. #+BEGIN_SRC emacs-lisp
  330. (use-package lsp-mode
  331. :defer t
  332. :commands lsp
  333. :custom
  334. (lsp-auto-guess-root nil)
  335. (lsp-prefer-flymake nil) ; use flycheck instead
  336. (lsp-file-watch-threshold 2000)
  337. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  338. :hook ((python-mode
  339. js-mode
  340. js2-mode
  341. typescript-mode
  342. web-mode) . lsp))
  343. (use-package lsp-ui
  344. :after lsp-mode
  345. :diminish
  346. :commands lsp-ui-mode
  347. :config
  348. (setq lsp-ui-doc-enable t
  349. lsp-ui-doc-header t
  350. lsp-ui-doc-include-signature t
  351. lsp-ui-doc-position 'top
  352. lsp-ui-doc-border (face-foreground 'default)
  353. lsp-ui-sideline-enable nil
  354. lsp-ui-sideline-ignore-duplicate t
  355. lsp-ui-sideline-show-code-actions nil)
  356. (when (display-graphic-p)
  357. (setq lsp-ui-doc-use-webkit t))
  358. ;; workaround hide mode-line of lsp-ui-imenu buffer
  359. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  360. (setq mode-line-format nil)))
  361. (use-package company-lsp
  362. :requires company
  363. :defer t
  364. :ensure t
  365. :config
  366. ;;disable client-side cache because lsp server does a better job
  367. (setq company-transformers nil
  368. company-lsp-async t
  369. company-lsp-cache-candidates nil))
  370. #+END_SRC
  371. ** flycheck
  372. #+BEGIN_SRC emacs-lisp
  373. (use-package flycheck
  374. ;;:ensure t
  375. :hook
  376. ((css-mode . flycheck-mode)
  377. (emacs-lisp-mode . flycheck-mode)
  378. (python-mode . flycheck-mode))
  379. :init
  380. (setq flycheck-emacs-lisp-load-path 'inherit)
  381. :config
  382. (setq-default
  383. flycheck-check-synta-automatically '(save mode-enabled)
  384. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  385. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  386. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  387. #+END_SRC
  388. ** lisp
  389. #+BEGIN_SRC emacs-lisp
  390. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  391. #+END_SRC
  392. ** web
  393. apt install npm
  394. sudo npm install -g vscode-html-languageserver-bin
  395. evtl alternativ typescript-language-server?
  396. #+BEGIN_SRC emacs-lisp
  397. (use-package web-mode
  398. :ensure t
  399. :defer t
  400. :mode
  401. ("\\.phtml\\'"
  402. "\\.tpl\\.php\\'"
  403. "\\.djhtml\\'"
  404. "\\.[t]?html?\\'"))
  405. #+END_SRC
  406. ** Python
  407. Systemseitig muss python-language-server installiert sein:
  408. pip3 install 'python-language-server[all]'
  409. für andere language servers
  410. https://github.com/emacs-lsp/lsp-mode#install-language-server
  411. #+BEGIN_SRC emacs-lisp
  412. (use-package pyvenv
  413. :ensure t
  414. :config
  415. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  416. (add-hook 'pyvenv-post-activate-hooks #'my/postactivatehook))
  417. (defun my/postactivatehook ()
  418. (setq lsp-python-ms-extra-paths pyvenv-virtual-env))
  419. (use-package virtualenvwrapper
  420. :ensure t
  421. :hook (venv-postmkvirtualenv . (lambda() (shell-command "pip3 install importmagic epc")))
  422. :config
  423. (setq venv-location (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  424. (use-package lsp-python-ms
  425. :ensure t
  426. :after lsp-mode python)
  427. ; :custom (lsp-python-executable-cmd "python3"))
  428. #+END_SRC
  429. * beancount
  430. ** Installation
  431. #+BEGIN_SRC shell
  432. sudo su
  433. cd /opt
  434. python3 -m venv beancount
  435. source ./beancount/bin/activate
  436. pip3 install wheel
  437. pip3 install beancount
  438. sleep 100
  439. echo "shell running!"
  440. deactivate
  441. #+END_SRC
  442. #+BEGIN_SRC emacs-lisp
  443. (use-package beancount
  444. :load-path "user-local/elisp"
  445. :defer t
  446. :mode
  447. ("\\.beancount$" . beancount-mode)
  448. :init
  449. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  450. ; (add-hook 'beancount-mode-hook (pyvenv-activate "/opt/beancount"))
  451. ; (setenv "PATH"
  452. ; (concat "/opt/beancount/bin:"
  453. ; (getenv "PATH")))
  454. :config
  455. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))
  456. #+END_SRC
  457. To support org-babel, check if it can find the symlink to ob-beancount.el
  458. #+BEGIN_SRC shell
  459. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  460. beansym="$orgpath/ob-beancount.el
  461. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  462. if [ -h "$beansym" ]
  463. then
  464. echo "$beansym found"
  465. elif [ -e "$bean" ]
  466. then
  467. echo "creating symlink"
  468. ln -s "$bean" "$beansym"
  469. else
  470. echo "$bean not found, symlink creation aborted"
  471. fi
  472. #+END_SRC
  473. Fava is strongly recommended.
  474. #+BEGIN_SRC shell
  475. cd /opt
  476. python3 -m venv fava
  477. source ./fava/bin/activate
  478. pip3 install wheel
  479. pip3 install fava
  480. deactivate
  481. #+END_SRC
  482. Start fava with fava my_file.beancount
  483. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  484. Beancount-mode can start fava and open the URL right away.