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.

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