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.

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