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.

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