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.

551 lines
16 KiB

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