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.

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