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.

539 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
  1. (defun me/tangle-init ()
  2. "If the current buffer is 'init.org',
  3. the code blocks are tangled, and the tangled file is compiled."
  4. (when (equal (buffer-file-name)
  5. (expand-file-name (concat user-emacs-directory "init.org")))
  6. ;; avoid running hooks
  7. (let ((prog-mode-hook nil))
  8. (org-babel-tangle)
  9. (byte-compile-file (concat user-emacs-directory "init.el"))
  10. (load-file user-init-file))))
  11. (add-hook 'after-save-hook 'me/tangle-init)
  12. (require 'package)
  13. ;; bug before emacs 26.3
  14. (when (version< emacs-version "26.3")
  15. (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
  16. (add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/") t)
  17. (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  18. (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  19. (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
  20. (package-initialize)
  21. (unless (package-installed-p 'use-package)
  22. (package-refresh-contents)
  23. (package-install 'use-package))
  24. (setq use-package-verbose nil)
  25. (eval-when-compile
  26. (require 'use-package))
  27. (require 'bind-key)
  28. (use-package diminish
  29. :ensure t)
  30. (defvar me/whoami
  31. (if (string-equal (system-name) "PMTS01")
  32. "work_remote"
  33. (if (string-equal (system-name) "laptop")
  34. "home_laptop"
  35. (if (string-equal (system-name) "PMPCNEU08")
  36. "work_local"
  37. "home_desktop"))))
  38. (defvar MY--PATH_USER_LOCAL (expand-file-name "~/.emacs.d/user-local/"))
  39. (defvar MY--PATH_USER_GLOBAL (expand-file-name "~/.emacs.d/user-global/"))
  40. (pcase me/whoami
  41. ("home"
  42. (progn
  43. (defvar MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/"))
  44. (defvar MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/"))
  45. (defvar MY--PATH_ORG_JOURNAl (expand-file-name "~/Archiv/Organisieren/Journal/"))))
  46. ("home_laptop"
  47. (progn
  48. (defvar MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/"))
  49. (defvar MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/"))
  50. (defvar MY--PATH_ORG_JOURNAL (expand-file-name "~/Archiv/Organisieren/Journal/"))))
  51. ("work_remote"
  52. (progn
  53. (defvar MY--PATH_ORG_FILES "p:/Eigene Dateien/Notizen/")
  54. (defvar MY--PATH-ORG-JOURNAL "p:/Eigene Dateien/Notizen/Journal/")
  55. (defvar MY--PATH_START "p:/Eigene Dateien/Notizen/"))))
  56. (setq bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks"))
  57. (setq recentf-save-file (concat MY--PATH_USER_LOCAL "recentf"))
  58. (setq custom-file (concat MY--PATH_USER_LOCAL "custom.el")) ;; don't spam init.e with saved customization settings
  59. (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_defs"))
  60. (setq backup-directory-alist `((".*" . ,temporary-file-directory)))
  61. (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory)))
  62. (setq save-abbrevs 'silently) ;; don't bother me with asking for abbrev saving
  63. (setq-default create-lockfiles nil) ;; disable lock files, can cause trouble in e.g. lsp-mode
  64. (defalias 'yes-or-no-p 'y-or-n-p) ;; answer with y and n
  65. (setq custom-safe-themes t) ;; don't ask me if I want to load a theme
  66. (setq sentence-end-double-space nil) ;; don't coun two spaces after a period as the end of a sentence.
  67. (delete-selection-mode t) ;; delete selected region when typing
  68. (save-place-mode 1) ;; saves position in file when it's closed
  69. (setq save-place-forget-unreadable-files nil) ;; checks if file is readable before saving position
  70. (setq locale-coding-system 'utf-8)
  71. (set-terminal-coding-system 'utf-8)
  72. (set-keyboard-coding-system 'utf-8)
  73. (set-selection-coding-system 'utf-8)
  74. (if (eq system-type 'windows-nt)
  75. (prefer-coding-system 'utf-8-dos)
  76. (prefer-coding-system 'utf-8))
  77. (blink-cursor-mode -1) ;; turn off blinking cursor
  78. (show-paren-mode t) ;; show other part of brackets
  79. (column-number-mode t)
  80. (setq uniquify-buffer-name-style 'forward)
  81. (setq-default indent-tabs-mode nil) ;; avoid tabs in place of multiple spaces (they look bad in tex)
  82. (setq-default indicate-empty-lines t) ;; show empty lines
  83. (setq scroll-margin 5 ;; smooth scrolling
  84. scroll-conservatively 10000
  85. scroll-preserve-screen-position 1
  86. scroll-step 1)
  87. (global-hl-line-mode t) ;; highlight current line
  88. (menu-bar-mode 0) ;; disable menu bar
  89. (tool-bar-mode 0) ;; disable tool bar
  90. (scroll-bar-mode 0) ;; disable scroll bar
  91. (when (eq system-type 'windows-nt)
  92. (remove-hook 'find-file-hooks 'vc-refresh-state)
  93. (progn
  94. (setq gc-cons-threshold (* 511 1024 1024)
  95. gc-cons-percentage 0.5
  96. garbage-collection-messages t
  97. w32-pipe-read-delay 0
  98. w32-get-true-file-attributes nil)
  99. (run-with-idle-timer 5 t #'garbage-collect)))
  100. (if (string-equal system-type "gnu/linux")
  101. (set-face-font 'default "Hack-10"))
  102. (global-visual-line-mode)
  103. (diminish 'visual-line-mode)
  104. (use-package adaptive-wrap
  105. :ensure t
  106. :config
  107. (add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode))
  108. ; :init
  109. ; (when (fboundp 'adaptive-wrap-prefix-mode)
  110. ; (defun my/activate-adaptive-wrap-prefix-mode ()
  111. ; "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
  112. ; (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
  113. ; (add-hook 'visual-line-mode-hook 'my/activate-adaptive-wrap-prefix-mode)))
  114. (use-package display-line-numbers
  115. :init
  116. (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  117. (add-hook 'org-src-mode-hook 'display-line-numbers-mode)
  118. :config
  119. (setq-default display-line-numbers-type 'visual
  120. display-line-numbers-current-absolute t
  121. display-line-numbers-with 4
  122. display-line-numbers-widen t))
  123. ; (add-hook 'emacs-lisp-mode-hook 'display-line-numbers-mode)
  124. (use-package rainbow-mode
  125. :ensure t
  126. :diminish
  127. :hook ((org-mode
  128. emacs-lisp-mode) . rainbow-mode))
  129. (use-package undo-tree
  130. :ensure t
  131. :diminish undo-tree-mode
  132. :init
  133. (global-undo-tree-mode 1))
  134. (use-package imenu-list
  135. :ensure t
  136. :config
  137. (setq imenu-list-focus-after-activation t
  138. imenu-list-auto-resize t
  139. imenu-list-position 'right)
  140. :bind
  141. (:map global-map
  142. ([f9] . imenu-list-smart-toggle))
  143. )
  144. (use-package which-key
  145. :ensure t
  146. :diminish which-key-mode
  147. :config
  148. (which-key-mode)
  149. (which-key-setup-side-window-right-bottom)
  150. (which-key-setup-minibuffer)
  151. (setq which-key-idle-delay 0.5))
  152. (use-package evil
  153. :ensure t
  154. :defer .1 ;; don't block emacs when starting, load evil immediately after startup
  155. :config
  156. (evil-mode 1))
  157. (use-package general
  158. :ensure t)
  159. (general-define-key
  160. :states 'normal
  161. :keymaps 'imenu-list-major-mode-map
  162. (kbd "RET") '(imenu-list-goto-entry :which-key "goto")
  163. (kbd "TAB") '(hs-toggle-hiding :which-key "collapse")
  164. "d" '(imenu-list-display-entry :which-key "show")
  165. "q" '(imenu-list-quit-window :which-key "quit"))
  166. (use-package org
  167. :ensure org-plus-contrib
  168. :mode (("\.org$" . org-mode))
  169. :init
  170. (add-hook 'org-mode-hook 'company/org-mode-hook)
  171. (add-hook 'org-src-mode-hook 'smartparens-mode)
  172. :config
  173. (setq org-modules (quote (org-id
  174. org-habit
  175. )))
  176. (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org")
  177. org-agenda-files (list MY--PATH_ORG_FILES
  178. MY--PATH_ORG_FILES_MOBILE)
  179. org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations")
  180. org-log-into-drawer "LOGBOOK")
  181. ;; some display customizations
  182. (setq org-pretty-entities t
  183. org-startup-truncated t
  184. org-startup-align-all-tables t)
  185. ;; some source code blocks customizations
  186. (setq org-src-window-setup 'current-window ;; C-c ' opens in current window
  187. org-src-fontify-natively t ;; use syntax highlighting in code blocks
  188. org-src-preserve-indentation t ;; no extra indentation
  189. org-src-tab-acts-natively t))
  190. (org-babel-do-load-languages
  191. 'org-babel-load-languages
  192. '((emacs-lisp . t)
  193. (gnuplot . t)
  194. (js . t)
  195. (latex . t)
  196. (lisp . t)
  197. (python . t)
  198. (shell . t)
  199. (sqlite . t)
  200. (org . t)
  201. (R . t)
  202. (scheme . t)
  203. ))
  204. (defun me--org-confirm-babel-evaluate (lang body)
  205. "Do not confirm evaluation for these languages."
  206. (not (or (string= lang "python")
  207. (string= lang "ipython")
  208. (string= lang "emacs-lisp")
  209. (string= lang "R")
  210. (string= lang "latex")
  211. (string= lang "sqlite"))))
  212. (setq org-confirm-babel-evaluate 'me--org-confirm-babel-evaluate)
  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. (use-package org-id
  220. :config
  221. (setq org-id-link-to-org-use-id t)
  222. (org-id-update-id-locations)) ;; update id file .org-id-locations on startup
  223. (pcase me/whoami
  224. ("work_remote")
  225. (setq org-todo-keywords
  226. '((sequence "OPEN" "TODO" "UNCLEAR" "|" "DONE" "IMPOSSIBLE"))))
  227. (bind-key "C-c l" 'org-store-link)
  228. (bind-key "C-c c" 'org-capture)
  229. (bind-key "C-c a" 'org-agenda)
  230. (setq org-agenda-sorting-strategy
  231. (quote
  232. ((agenda deadline-up priority-down)
  233. (todo priority-down category-keep)
  234. (tags priority-down category-keep)
  235. (search category-keep))))
  236. (defun me--org-skip-subtree-if-priority (priority)
  237. "Skip an agenda subtree if it has a priority of PRIORITY.
  238. PRIORITY may be one of the characters ?A, ?B, or ?C."
  239. (let ((subtree-end (save-excursion (org-end-of-subtree t)))
  240. (pri-value (* 1000 (- org-lowest-priority priority)))
  241. (pri-current (org-get-priority (thing-at-point 'line t))))
  242. (if (= pri-value pri-current)
  243. subtree-end
  244. nil)))
  245. (setq org-agenda-custom-commands
  246. '(("c" "Simple agenda view"
  247. ((tags "PRIORITY=\"A\""
  248. ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
  249. (org-agenda-overriding-header "Hohe Priorität:")))
  250. (agenda ""
  251. ((org-agenda-span 7)
  252. (org-agenda-start-on-weekday nil)
  253. (org-agenda-overriding-header "Nächste 7 Tage:")))
  254. (alltodo ""
  255. ((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
  256. (org-agenda-skip-if nil '(scheduled deadline))))
  257. (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
  258. ;;(use-package org-caldav
  259. ;; :ensure t
  260. ;; :config
  261. ;; (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc"
  262. ;; org-caldav-calendar-id "orgmode"
  263. ;; org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox")
  264. ;; org-caldav-files (concat MY--PATH_ORG_FILES "tasks")))
  265. (use-package org-journal
  266. :ensure t
  267. :defer t
  268. :custom
  269. (org-journal-dir MY--PATH_ORG_JOURNAl)
  270. (org-journal-enable-agenda-integration t))
  271. ; (require 'ivy)
  272. (use-package ivy
  273. :ensure t
  274. :diminish
  275. (ivy-mode . "")
  276. :init
  277. (ivy-mode 1)
  278. :bind
  279. ("C-r" . ivy-resume) ;; overrides isearch-backwards binding
  280. :config
  281. (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer
  282. ivy-height 20 ;; height of ivy window
  283. ivy-count-format "%d/%d" ;; current and total number
  284. ivy-re-builders-alist ;; regex replaces spaces with *
  285. '((t . ivy--regex-plus))))
  286. (use-package counsel
  287. :ensure t
  288. :bind*
  289. (("M-x" . counsel-M-x)
  290. ("C-x C-f" . counsel-find-file)
  291. ("C-x C-r" . counsel-recentf)
  292. ("C-c C-f" . counsel-git)
  293. ("C-c h f" . counsel-describe-function)
  294. ("C-c h v" . counsel-describe-variable)
  295. ("M-i" . counsel-imenu)))
  296. (use-package swiper
  297. :ensure t
  298. :bind
  299. ("C-s" . swiper))
  300. (use-package ivy-hydra
  301. :ensure t)
  302. ; (require 'company)
  303. (use-package company
  304. :defer 1
  305. :bind
  306. (:map company-active-map
  307. ("RET" . nil)
  308. ([return] . nil)
  309. ("TAB" . company-complete-selection)
  310. ([tab] . company-complete-selection)
  311. ("<right>" . company-complete-common))
  312. :config
  313. (global-company-mode 1)
  314. (setq-default
  315. company-idle-delay .2
  316. company-minimum-prefix-length 1
  317. company-require-match nil
  318. company-show-numbers t
  319. company-tooltip-align-annotations t))
  320. ; (require 'company-statistics)
  321. (use-package company-statistics
  322. :ensure t
  323. :after company
  324. :init
  325. (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el")
  326. :config
  327. (company-statistics-mode 1))
  328. (use-package company-dabbrev
  329. :ensure nil
  330. :after company
  331. :config
  332. (setq-default company-dabbrev-downcase nil))
  333. (use-package company-box
  334. :ensure t
  335. :init
  336. (add-hook 'company-mode-hook 'company-box-mode))
  337. (defun company/org-mode-hook()
  338. (set (make-local-variable 'company-backends)
  339. '(company-capf company-files))
  340. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
  341. (message "company/org-mode-hook"))
  342. (defun company/elisp-mode-hook()
  343. (set (make-local-variable 'company-backends)
  344. '((company-elisp company-dabbrev) company-capf company-files))
  345. (message "company/elisp-mode-hook"))
  346. (defun company/beancount-mode-hook()
  347. (set (make-local-variable 'company-backends)
  348. '(company-beancount)))
  349. (use-package magit
  350. :ensure t
  351. :defer t
  352. :init
  353. ; set git-path in work environment
  354. (if (string-equal user-login-name "POH")
  355. (setq magit-git-executable "P:/Eigene Dateien/Tools/Git/bin/git.exe")
  356. )
  357. :bind (("C-x g" . magit-status))
  358. )
  359. (use-package lsp-mode
  360. :defer t
  361. :commands lsp
  362. :custom
  363. (lsp-auto-guess-root nil)
  364. (lsp-prefer-flymake nil) ; use flycheck instead
  365. (lsp-file-watch-threshold 2000)
  366. :bind (:map lsp-mode-map ("C-c C-f" . lsp-format-buffer))
  367. :hook ((python-mode
  368. js-mode
  369. js2-mode
  370. typescript-mode
  371. web-mode) . lsp))
  372. (use-package lsp-ui
  373. :after lsp-mode
  374. :ensure t
  375. :diminish
  376. :commands lsp-ui-mode
  377. :config
  378. (setq lsp-ui-doc-enable t
  379. lsp-ui-doc-header t
  380. lsp-ui-doc-include-signature t
  381. lsp-ui-doc-position 'top
  382. lsp-ui-doc-border (face-foreground 'default)
  383. lsp-ui-sideline-enable nil
  384. lsp-ui-sideline-ignore-duplicate t
  385. lsp-ui-sideline-show-code-actions nil)
  386. (when (display-graphic-p)
  387. (setq lsp-ui-doc-use-webkit t))
  388. ;; workaround hide mode-line of lsp-ui-imenu buffer
  389. (defadvice lsp-ui-imenu (after hide-lsp-ui-imenu-mode-line activate)
  390. (setq mode-line-format nil)))
  391. (use-package company-lsp
  392. :requires company
  393. :defer t
  394. :ensure t
  395. :config
  396. ;;disable client-side cache because lsp server does a better job
  397. (setq company-transformers nil
  398. company-lsp-async t
  399. company-lsp-cache-candidates nil))
  400. (use-package flycheck
  401. :ensure t
  402. :hook
  403. ((css-mode . flycheck-mode)
  404. (emacs-lisp-mode . flycheck-mode)
  405. (python-mode . flycheck-mode))
  406. :init
  407. (setq flycheck-emacs-lisp-load-path 'inherit)
  408. :config
  409. (setq-default
  410. flycheck-check-synta-automatically '(save mode-enabled)
  411. flycheck-disable-checkers '(emacs-lisp-checkdoc)
  412. eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck
  413. flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages
  414. (use-package projectile
  415. :ensure t
  416. :defer t
  417. :bind
  418. (("C-c p p" . projectile-switch-project)
  419. ("C-c p c" . projectile-command-map)
  420. ("C-c p s s" . projectile-ag))
  421. :init
  422. (setq-default projectile-cache-file (concat MY--PATH_USER_LOCAL ".projectile-cache")
  423. projectile-known-projects-file (concat MY--PATH_USER_LOCAL ".projectile-bookmarks"))
  424. :config
  425. (projectile-mode t)
  426. (setq-default projectile-completion-system 'ivy
  427. projectile-enable-caching t
  428. projectile-mode-line '(:eval (projectile-project-name))))
  429. (use-package smartparens
  430. :ensure t
  431. :diminish smartparens-mode
  432. :config
  433. (setq sp-show-pair-from-inside nil)
  434. (require 'smartparens-config))
  435. (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook)
  436. (use-package web-mode
  437. :ensure t
  438. :defer t
  439. :mode
  440. ("\\.phtml\\'"
  441. "\\.tpl\\.php\\'"
  442. "\\.djhtml\\'"
  443. "\\.[t]?html?\\'")
  444. :config
  445. (setq web-mode-enable-auto-closing t
  446. web-mode-enable-auto-pairing t)
  447. (add-hook 'web-mode-hook 'smartparens-mode))
  448. (if (string-equal system-type "gnu/linux")
  449. (use-package pyvenv
  450. :ensure t
  451. :config
  452. (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))
  453. (add-hook 'pyvenv-post-activate-hooks #'my/postactivatehook))
  454. (defun my/postactivatehook ()
  455. (setq lsp-python-ms-extra-paths pyvenv-virtual-env))
  456. (use-package virtualenvwrapper
  457. :ensure t
  458. :hook (venv-postmkvirtualenv . (lambda() (shell-command "pip3 install importmagic epc")))
  459. :config
  460. (setq venv-location (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")))
  461. (use-package lsp-python-ms
  462. :ensure t
  463. :after lsp-mode python))
  464. ; :custom (lsp-python-executable-cmd "python3"))
  465. (if (string-equal system-type "gnu/linux")
  466. (use-package beancount
  467. :load-path "user-local/elisp"
  468. ; :ensure t
  469. :defer t
  470. :mode
  471. ("\\.beancount$" . beancount-mode)
  472. :init
  473. (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
  474. ; (add-hook 'beancount-mode-hook (pyvenv-activate "/opt/beancount"))
  475. ; (setenv "PATH"
  476. ; (concat "/opt/beancount/bin:"
  477. ; (getenv "PATH")))
  478. :config
  479. (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount")))