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.

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