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.

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