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.

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