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.

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