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.

562 lines
17 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
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. * 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-8-dos)
  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. (if (string-equal system-type "gnu/linux")
  106. (set-face-font 'default "Hack-10"))
  107. #+END_SRC
  108. ** line wrappings
  109. #+BEGIN_SRC emacs-lisp
  110. (global-visual-line-mode)
  111. (diminish 'visual-line-mode)
  112. (use-package adaptive-wrap
  113. :ensure t
  114. :init
  115. (when (fboundp 'adaptive-wrap-prefix-mode)
  116. (defun my/activate-adaptive-wrap-prefix-mode ()
  117. "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  118. (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  119. (add-hook 'visual-line-mode-hook 'my/activate-adaptive-wrap-prefix-mode)))
  120. #+END_SRC
  121. ** line numbers
  122. #+BEGIN_SRC emacs-lisp
  123. (use-package display-line-numbers
  124. :init
  125. (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  126. (add-hook 'org-src-mode-hook 'display-line-numbers-mode)
  127. :config
  128. (setq-default display-line-numbers-type 'visual
  129. display-line-numbers-current-absolute t
  130. display-line-numbers-with 4
  131. display-line-numbers-widen t))
  132. ; (add-hook 'emacs-lisp-mode-hook 'display-line-numbers-mode)
  133. #+END_SRC
  134. ** misc
  135. #+BEGIN_SRC emacs-lisp
  136. (use-package rainbow-mode
  137. :ensure t
  138. :diminish
  139. :hook ((org-mode
  140. emacs-lisp-mode) . rainbow-mode))
  141. #+END_SRC
  142. * undo
  143. #+BEGIN_SRC emacs-lisp
  144. (use-package undo-tree
  145. :ensure t
  146. :diminish undo-tree-mode
  147. :init
  148. (global-undo-tree-mode 1))
  149. #+END_SRC
  150. * imenu-list
  151. A minor mode to show imenu in a sidebar.
  152. Call imenu-list-smart-toggle.
  153. [[https://github.com/bmag/imenu-list][Source]]
  154. #+BEGIN_SRC emacs-lisp
  155. (use-package imenu-list
  156. :ensure t
  157. :config
  158. (setq imenu-list-focus-after-activation t
  159. imenu-list-auto-resize t
  160. imenu-list-position 'right)
  161. :bind
  162. (:map global-map
  163. ([f9] . imenu-list-smart-toggle))
  164. )
  165. #+END_SRC
  166. * which-key
  167. #+BEGIN_SRC emacs-lisp
  168. (use-package which-key
  169. :ensure t
  170. :diminish which-key-mode
  171. :config
  172. (which-key-mode)
  173. (which-key-setup-side-window-right-bottom)
  174. (which-key-setup-minibuffer)
  175. (setq which-key-idle-delay 0.5))
  176. #+END_SRC
  177. * orgmode
  178. ** org
  179. #+BEGIN_SRC emacs-lisp
  180. (use-package org
  181. :ensure org-plus-contrib
  182. :init
  183. (add-hook 'org-mode-hook 'company/org-mode-hook)
  184. :config
  185. ;; (require 'org-id)
  186. (add-to-list 'org-modules "org-id")
  187. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  188. org-agenda-files (list MY--PATH_ORG_FILES
  189. MY--PATH_ORG_FILES_MOBILE)
  190. org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  191. org-log-into-drawer "LOGBOOK"))
  192. (org-id-update-id-locations)
  193. #+END_SRC
  194. ** habits
  195. #+BEGIN_SRC emacs-lisp
  196. (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren
  197. ;; (add-to-list 'org-modules "org-habit")
  198. (setq org-habit-graph-column 80
  199. org-habit-preceding-days 30
  200. org-habit-following-days 7
  201. org-habit-show-habits-only-for-today nil)
  202. #+END_SRC
  203. ** *TODO*
  204. org-super-agenda
  205. ** org-caldav
  206. Vorerst deaktiviert, Nutzen evtl. nicht vorhanden
  207. BEGIN_SRC emacs-lisp
  208. (use-package org-caldav
  209. :ensure t
  210. :config
  211. (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  212. org-caldav-calendar-id "orgmode"
  213. org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  214. org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  215. END_SRC
  216. ** journal
  217. [[https://github.com/bastibe/org-journal][Source]]
  218. #+BEGIN_SRC emacs-lisp
  219. (use-package org-journal
  220. :ensure t
  221. :defer t
  222. :custom
  223. (org-journal-dir MY--PATH_ORG_JOURNAl)
  224. (org-journal-enable-agenda-integration t))
  225. #+END_SRC
  226. * ivy / counsel / swiper
  227. #+BEGIN_SRC emacs-lisp
  228. ; (require 'ivy)
  229. (use-package ivy
  230. :ensure t
  231. :diminish
  232. (ivy-mode . "")
  233. :init
  234. (ivy-mode 1)
  235. :bind
  236. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  237. :config
  238. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  239. ivy-height 20 ;; height of ivy window
  240. ivy-count-format "%d/%d" ;; current and total number
  241. ivy-re-builders-alist ;; regex replaces spaces with *
  242. '((t . ivy--regex-plus))))
  243. (use-package counsel
  244. :ensure t
  245. :bind*
  246. (("M-x" . counsel-M-x)
  247. ("C-x C-f" . counsel-find-file)
  248. ("C-x C-r" . counsel-recentf)
  249. ("C-c C-f" . counsel-git)
  250. ("C-c h f" . counsel-describe-function)
  251. ("C-c h v" . counsel-describe-variable)
  252. ("M-i" . counsel-imenu)))
  253. (use-package swiper
  254. :ensure t
  255. :bind
  256. ("C-s" . swiper))
  257. (use-package ivy-hydra
  258. :ensure t)
  259. #+END_SRC
  260. * company
  261. #+BEGIN_SRC emacs-lisp
  262. ; (require 'company)
  263. (use-package company
  264. :defer 1
  265. :bind
  266. (:map company-active-map
  267. ("RET" . nil)
  268. ([return] . nil)
  269. ("TAB" . company-complete-selection)
  270. ([tab] . company-complete-selection)
  271. ("<right>" . company-complete-common))
  272. :config
  273. (global-company-mode 1)
  274. (setq-default
  275. company-idle-delay .2
  276. company-minimum-prefix-length 1
  277. company-require-match nil
  278. company-show-numbers t
  279. company-tooltip-align-annotations t))
  280. ; (require 'company-statistics)
  281. (use-package company-statistics
  282. :ensure t
  283. :after company
  284. :init
  285. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  286. :config
  287. (company-statistics-mode 1))
  288. (use-package company-dabbrev
  289. :ensure nil
  290. :after company
  291. :config
  292. (setq-default company-dabbrev-downcase nil))
  293. (use-package company-box
  294. :ensure t
  295. :init
  296. (add-hook 'company-mode-hook 'company-box-mode))
  297. #+END_SRC
  298. ** company backends
  299. #+BEGIN_SRC emacs-lisp
  300. (defun company/org-mode-hook()
  301. (set (make-local-variable 'company-backends)
  302. '(company-capf company-files))
  303. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  304. (message "company/org-mode-hook"))
  305. (defun company/elisp-mode-hook()
  306. (set (make-local-variable 'company-backends)
  307. '((company-elisp company-dabbrev) company-capf company-files))
  308. (message "company/elisp-mode-hook"))
  309. (defun company/beancount-mode-hook()
  310. (set (make-local-variable 'company-backends)
  311. '(company-beancount)))
  312. #+END_SRC
  313. * Programming
  314. ** Magit / Git
  315. Little crash course in magit:
  316. - magit-init to init a git project
  317. - magit-status (C-x g) to call the status window
  318. In status buffer:
  319. - s stage files
  320. - u unstage files
  321. - U unstage all files
  322. - a apply changes to staging
  323. - c c commit (type commit message, then C-c C-c to commit)
  324. - b b switch to another branch
  325. - P u git push
  326. - F u git pull
  327. #+BEGIN_SRC emacs-lisp
  328. (use-package magit
  329. :ensure t
  330. :defer t
  331. :init
  332. ; set git-path in work environment
  333. (if (string-equal user-login-name "POH")
  334. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  335. )
  336. :bind (("C-x g" . magit-status))
  337. )
  338. #+END_SRC
  339. ** LSP
  340. Configuration for the language server protocol
  341. *ACHTUNG* Dateipfad muss absolut sein, symlink im Pfad führt zumindest beim ersten Start zu Fehlern beim lsp
  342. Sobald der lsp einmal lief, kann zukünftig der symlink-Pfad genommen werden.
  343. Getestet wurde die funktionierende Datei selbst und neu erstellte Dateien im selben Pfad.
  344. TODO Unterverzeichnisse wurden noch nicht getestet
  345. #+BEGIN_SRC emacs-lisp
  346. (use-package lsp-mode
  347. :defer t
  348. :commands lsp
  349. :custom
  350. (lsp-auto-guess-root nil)
  351. (lsp-prefer-flymake nil) ; use flycheck instead
  352. (lsp-file-watch-threshold 2000)
  353. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  354. :hook ((python-mode
  355. js-mode
  356. js2-mode
  357. typescript-mode
  358. web-mode) . lsp))
  359. (use-package lsp-ui
  360. :after lsp-mode
  361. :ensure t
  362. :diminish
  363. :commands lsp-ui-mode
  364. :config
  365. (setq lsp-ui-doc-enable t
  366. lsp-ui-doc-header t
  367. lsp-ui-doc-include-signature t
  368. lsp-ui-doc-position 'top
  369. lsp-ui-doc-border (face-foreground 'default)
  370. lsp-ui-sideline-enable nil
  371. lsp-ui-sideline-ignore-duplicate t
  372. lsp-ui-sideline-show-code-actions nil)
  373. (when (display-graphic-p)
  374. (setq lsp-ui-doc-use-webkit t))
  375. ;; workaround hide mode-line of lsp-ui-imenu buffer
  376. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  377. (setq mode-line-format nil)))
  378. (use-package company-lsp
  379. :requires company
  380. :defer t
  381. :ensure t
  382. :config
  383. ;;disable client-side cache because lsp server does a better job
  384. (setq company-transformers nil
  385. company-lsp-async t
  386. company-lsp-cache-candidates nil))
  387. #+END_SRC
  388. ** flycheck
  389. #+BEGIN_SRC emacs-lisp
  390. (use-package flycheck
  391. :ensure t
  392. :hook
  393. ((css-mode . flycheck-mode)
  394. (emacs-lisp-mode . flycheck-mode)
  395. (python-mode . flycheck-mode))
  396. :init
  397. (setq flycheck-emacs-lisp-load-path 'inherit)
  398. :config
  399. (setq-default
  400. flycheck-check-synta-automatically '(save mode-enabled)
  401. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  402. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  403. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  404. #+END_SRC
  405. ** lisp
  406. #+BEGIN_SRC emacs-lisp
  407. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  408. #+END_SRC
  409. ** web
  410. apt install npm
  411. sudo npm install -g vscode-html-languageserver-bin
  412. evtl alternativ typescript-language-server?
  413. #+BEGIN_SRC emacs-lisp
  414. (use-package web-mode
  415. :ensure t
  416. :defer t
  417. :mode
  418. ("\\.phtml\\'"
  419. "\\.tpl\\.php\\'"
  420. "\\.djhtml\\'"
  421. "\\.[t]?html?\\'"))
  422. #+END_SRC
  423. ** Python
  424. Systemseitig muss python-language-server installiert sein:
  425. pip3 install 'python-language-server[all]'
  426. für andere language servers
  427. https://github.com/emacs-lsp/lsp-mode#install-language-server
  428. #+BEGIN_SRC emacs-lisp
  429. (if (string-equal system-type "gnu/linux")
  430. (use-package pyvenv
  431. :ensure t
  432. :config
  433. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  434. (add-hook 'pyvenv-post-activate-hooks #'my/postactivatehook))
  435. (defun my/postactivatehook ()
  436. (setq lsp-python-ms-extra-paths pyvenv-virtual-env))
  437. (use-package virtualenvwrapper
  438. :ensure t
  439. :hook (venv-postmkvirtualenv . (lambda() (shell-command "pip3 install importmagic epc")))
  440. :config
  441. (setq venv-location (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  442. (use-package lsp-python-ms
  443. :ensure t
  444. :after lsp-mode python))
  445. ; :custom (lsp-python-executable-cmd "python3"))
  446. #+END_SRC
  447. * beancount
  448. ** Installation
  449. #+BEGIN_SRC shell
  450. sudo su
  451. cd /opt
  452. python3 -m venv beancount
  453. source ./beancount/bin/activate
  454. pip3 install wheel
  455. pip3 install beancount
  456. sleep 100
  457. echo "shell running!"
  458. deactivate
  459. #+END_SRC
  460. #+BEGIN_SRC emacs-lisp
  461. (if (string-equal system-type "gnu/linux")
  462. (use-package beancount
  463. :load-path "user-local/elisp"
  464. :ensure t
  465. :defer t
  466. :mode
  467. ("\\.beancount$" . beancount-mode)
  468. :init
  469. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  470. ; (add-hook 'beancount-mode-hook (pyvenv-activate "/opt/beancount"))
  471. ; (setenv "PATH"
  472. ; (concat "/opt/beancount/bin:"
  473. ; (getenv "PATH")))
  474. :config
  475. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount")))
  476. #+END_SRC
  477. To support org-babel, check if it can find the symlink to ob-beancount.el
  478. #+BEGIN_SRC shell
  479. orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print`
  480. beansym="$orgpath/ob-beancount.el
  481. bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el"
  482. if [ -h "$beansym" ]
  483. then
  484. echo "$beansym found"
  485. elif [ -e "$bean" ]
  486. then
  487. echo "creating symlink"
  488. ln -s "$bean" "$beansym"
  489. else
  490. echo "$bean not found, symlink creation aborted"
  491. fi
  492. #+END_SRC
  493. Fava is strongly recommended.
  494. #+BEGIN_SRC shell
  495. cd /opt
  496. python3 -m venv fava
  497. source ./fava/bin/activate
  498. pip3 install wheel
  499. pip3 install fava
  500. deactivate
  501. #+END_SRC
  502. Start fava with fava my_file.beancount
  503. It is accessable on this URL: [[http://127.0.0.1:5000][Fava]]
  504. Beancount-mode can start fava and open the URL right away.