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.

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