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.

561 lines
16 KiB

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