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.

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