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.

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