From 3a7fee948871f3b9128a63354b38c81b2e9e3d1a Mon Sep 17 00:00:00 2001 From: marc Date: Thu, 5 Sep 2019 19:54:23 +0200 Subject: [PATCH] added init.org --- init.org | 446 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 446 insertions(+) create mode 100644 init.org diff --git a/init.org b/init.org new file mode 100644 index 0000000..f4798e2 --- /dev/null +++ b/init.org @@ -0,0 +1,446 @@ +#+TITLE: Emacs configuration file +#+BABEL: :cache yes +#+PROPERTY: header-args :tangle yes + +* TODOS +- Paket exec-path-from-shell, um PATH aus Linux auch in emacs zu haben + +* First start +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 + +#+NAME: init.el +#+BEGIN_SRC emacs-lisp :tangle no +(require 'org') +(find-file (concat user-emacs-directory "init.org")) +(org-babel-tangle) +(load-file (concat user-emacs-directory "init.el")) +(byte-compile-file (concat user-emacs-directory "init.el")) +#+END_SRC + +This function updates init.el whenever changes in init.org are made. The update will be active after saving. +#+BEGIN_SRC emacs-lisp + (defun me/tangle-init () + "If the current buffer is 'init.org', + the code blocks are tangled, and the tangled file is compiled." + (when (equal (buffer-file-name) + (expand-file-name (concat user-emacs-directory "init.org"))) + ;; avoid running hooks + (let ((prog-mode-hook nil)) + (org-babel-tangle) + (byte-compile-file (concat user-emacs-directory "init.el")) + (load-file user-init-file)))) + (add-hook 'after-save-hook 'me/tangle-init) +#+END_SRC + +#+BEGIN_SRC emacs-lisp +(require 'package) + +(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) +(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) +(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t) + +(package-initialize) +#+END_SRC + +#+BEGIN_SRC emacs-lisp + (unless (package-installed-p 'use-package) + (package-refresh-contents) + (package-install 'use-package)) + + (setq use-package-verbose nil) + + ;(eval-when-compile + (require 'use-package);) +#+END_SRC + +* Default settings +#+BEGIN_SRC emacs-lisp + (defvar MY--PATH_USER_LOCAL (expand-file-name "~/.emacs.d/user-local/")) + (defvar MY--PATH_USER_GLOBAL (expand-file-name "~/.emacs.d/user-global/")) + + (defvar MY--PATH_ORG_FILES (expand-file-name "~/Archiv/Organisieren/")) + (defvar MY--PATH_ORG_FILES_MOBILE (expand-file-name "~/Archiv/Organisieren/mobile/")) + (defvar MY--PATH_ORG_JOURNAl (expand-file-name "~/Archiv/Organisieren/Journal/")) + (setq bookmark-default-file (concat MY--PATH_USER_LOCAL "bookmarks")) + (setq recentf-save-file (concat MY--PATH_USER_LOCAL "recentf")) + (setq custom-file (concat MY--PATH_USER_LOCAL "custom.el")) ;; don't spam init.e with saved customization settings + (setq abbrev-file-name (concat MY--PATH_USER_GLOBAL "abbrev_defs")) + (setq backup-directory-alist `((".*" . ,temporary-file-directory))) + (setq auto-save-file-name-transforms `((".*" ,temporary-file-directory))) + (setq save-abbrevs 'silently) ;; don't bother me with asking for abbrev saving + (setq-default create-lockfiles nil) ;; disable lock files, can cause trouble in e.g. lsp-mode + (defalias 'yes-or-no-p 'y-or-n-p) ;; answer with y and n + (setq custom-safe-themes t) ;; don't ask me if I want to load a theme + (setq sentence-end-double-space nil) ;; don't coun two spaces after a period as the end of a sentence. + (delete-selection-mode t) ;; delete selected region when typing + + (setq locale-coding-system 'utf-8) + (set-terminal-coding-system 'utf-8) + (set-keyboard-coding-system 'utf-8) + (set-selection-coding-system 'utf-8) + (if (eq system-type 'windows-nt) + (prefer-coding-system 'utf-8dos) + (prefer-coding-system 'utf-8)) + (blink-cursor-mode -1) ;; turn off blinking cursor + (show-paren-mode t) ;; show other part of brackets + (column-number-mode t) + (setq uniquify-buffer-name-style 'forward) + (setq-default indent-tabs-mode nil) ;; avoid tabs in place of multiple spaces (they look bad in tex) + (setq-default indicate-empty-lines t) ;; show empty lines + (setq scroll-margin 5 ;; smooth scrolling + scroll-conservatively 10000 + scroll-preserve-screen-position 1 + scroll-step 1) + (global-hl-line-mode t) ;; highlight current line +(menu-bar-mode 0) ;; disable menu bar +(tool-bar-mode 0) ;; disable tool bar +(scroll-bar-mode 0) ;; disable scroll bar +#+END_SRC +* visuals +** Font +#+BEGIN_SRC emacs-lisp +(set-face-font 'default "Hack Nerd Font Mono-10") +#+END_SRC + +** line wrappings +#+BEGIN_SRC emacs-lisp + (global-visual-line-mode) + (diminish 'visual-line-mode) + (use-package adaptive-wrap + :ensure t + :init + (when (fboundp 'adaptive-wrap-prefix-mode) + (defun my/activate-adaptive-wrap-prefix-mode () + "Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously." + (adaptive-wrap-prefix-mode (if visual-line-mode 1 -1))) + (add-hook 'visual-line-mode-hook 'my/activate-adaptive-wrap-prefix-mode))) +#+END_SRC +** line numbers +#+BEGIN_SRC emacs-lisp + (use-package display-line-numbers + :init + (add-hook 'prog-mode-hook 'display-line-numbers-mode) + (add-hook 'org-src-mode-hook 'display-line-numbers-mode) + :config + (setq-default display-line-numbers-type 'visual + display-line-numbers-current-absolute t + display-line-numbers-with 4 + display-line-numbers-widen t)) + ; (add-hook 'emacs-lisp-mode-hook 'display-line-numbers-mode) +#+END_SRC +* undo +#+BEGIN_SRC emacs-lisp +(require 'undo-tree) +(use-package undo-tree +:ensure t +:diminish undo-tree-mode +:init +(global-undo-tree-mode 1)) +#+END_SRC +* imenu-list + A minor mode to show imenu in a sidebar. + Call imenu-list-smart-toggle. + [[https://github.com/bmag/imenu-list][Source]] + +#+BEGIN_SRC emacs-lisp +(use-package imenu-list + :ensure t + :config + (setq imenu-list-focus-after-activation t + imenu-list-auto-resize t + imenu-list-position 'right) + :bind + (:map global-map + ([f9] . imenu-list-smart-toggle)) + ) +#+END_SRC +* which-key +#+BEGIN_SRC emacs-lisp + (require 'which-key) + (use-package which-key + :ensure t + :diminish which-key-mode + :config + (which-key-mode) + (which-key-setup-side-window-right-bottom) + (which-key-setup-minibuffer) + (setq which-key-idle-delay 0.5)) +#+END_SRC + +* lisp +#+BEGIN_SRC emacs-lisp + (add-hook 'emacs-lisp-mode-hook 'company/elisp-mode-hook) +#+END_SRC +* flycheck +#+BEGIN_SRC emacs-lisp + (use-package flycheck + ;;:ensure t + :hook + ((css-mode . flycheck-mode) + (emacs-lisp-mode . flycheck-mode) + (python-mode . flycheck-mode)) + :init + (setq flycheck-emacs-lisp-load-path 'inherit) + :config + (setq-default + flycheck-check-synta-automatically '(save mode-enabled) + flycheck-disable-checkers '(emacs-lisp-checkdoc) + eldoc-idle-delay .1 ;; let eldoc echo faster than flycheck + flycheck-display-errors-delay .3)) ;; this way any errors will override eldoc messages +#+END_SRC + +* org +#+BEGIN_SRC emacs-lisp + (use-package org + :ensure org-plus-contrib + :init + (add-hook 'org-mode-hook 'company/org-mode-hook) + :config +;; (require 'org-id) + (add-to-list 'org-modules "org-id") + (setq org-default-notes-file (concat MY--PATH_ORG_FILES "notes.org") + org-agenda-files (list MY--PATH_ORG_FILES + MY--PATH_ORG_FILES_MOBILE) + org-id-locations-file (concat MY--PATH_USER_LOCAL ".org-id-locations") + org-log-into-drawer "LOGBOOK")) + (org-id-update-id-locations) +#+END_SRC +* habits +#+BEGIN_SRC emacs-lisp + (require 'org-habit) ;;TODO Lösung ohne require finden, scheint mir nicht ideal zu sein, nur um ein org-modul zu aktivieren +;; (add-to-list 'org-modules "org-habit") + (setq org-habit-graph-column 80 + org-habit-preceding-days 30 + org-habit-following-days 7 + org-habit-show-habits-only-for-today nil) +#+END_SRC +* *TODO* +org-super-agenda + +* org-caldav +Vorerst deaktiviert, Nutzen evtl. nicht vorhanden +BEGIN_SRC emacs-lisp + (use-package org-caldav + :ensure t + :config + (setq org-caldav-url "https://nextcloud.cloudsphere.duckdns.org/remote.php/dav/calendars/marc" + org-caldav-calendar-id "orgmode" + org-caldav-inbox (expand-file-name "~/Archiv/Organisieren/caldav-inbox") + org-caldav-files (concat MY--PATH_ORG_FILES "tasks"))) +END_SRC +* journal +[[https://github.com/bastibe/org-journal][Source]] + +#+BEGIN_SRC emacs-lisp + (use-package org-journal + :ensure t + :defer t + :custom + (org-journal-dir MY--PATH_ORG_JOURNAl) + (org-journal-enable-agenda-integration t)) +#+END_SRC +* ivy / counsel / swiper + +#+BEGIN_SRC emacs-lisp + (require 'ivy) + (use-package ivy + :ensure t + :diminish + (ivy-mode . "") + :init + (ivy-mode 1) + :bind + ("C-r" . ivy-resume) ;; overrides isearch-backwards binding + :config + (setq ivy-use-virtual-buffers t ;; recent files and bookmarks in ivy-switch-buffer + ivy-height 20 ;; height of ivy window + ivy-count-format "%d/%d" ;; current and total number + ivy-re-builders-alist ;; regex replaces spaces with * + '((t . ivy--regex-plus)))) + + (use-package counsel + :ensure t + :bind* + (("M-x" . counsel-M-x) + ("C-x C-f" . counsel-find-file) + ("C-x C-r" . counsel-recentf) + ("C-c C-f" . counsel-git) + ("C-c h f" . counsel-describe-function) + ("C-c h v" . counsel-describe-variable) + ("M-i" . counsel-imenu))) + + (use-package swiper + :ensure t + :bind + ("C-s" . swiper)) + +(use-package ivy-hydra +:ensure t) +#+END_SRC + +* company + +#+BEGIN_SRC emacs-lisp + (require 'company) + (use-package company + :defer 1 + :bind + (:map company-active-map + ("RET" . nil) + ([return] . nil) + ("TAB" . company-complete-selection) + ([tab] . company-complete-selection) + ("" . company-complete-common)) + :config + (global-company-mode 1) + (setq-default + company-idle-delay .2 + company-minimum-prefix-length 1 + company-require-match nil + company-show-numbers t + company-tooltip-align-annotations t)) + + (require 'company-statistics) + (use-package company-statistics + :ensure t + :after company + :init + (setq company-statistics-file (concat MY--PATH_USER_LOCAL "company-statistics-cache.el"));~/.emacs.d/user-dir/company-statistics-cache.el") + :config + (company-statistics-mode 1)) + + (use-package company-dabbrev + :ensure nil + :after company + :config + (setq-default company-dabbrev-downcase nil)) + + (use-package company-box + :ensure nil + :init + (add-hook 'company-mode-hook 'company-box-mode)) +#+END_SRC + +** company backends + +#+BEGIN_SRC emacs-lisp + (defun company/org-mode-hook() + (set (make-local-variable 'company-backends) + '(company-capf company-files)) + (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) + (message "company/org-mode-hook")) + + (defun company/elisp-mode-hook() + (set (make-local-variable 'company-backends) + '((company-elisp company-dabbrev) company-capf company-files)) + (message "company/elisp-mode-hook")) + + (defun company/beancount-mode-hook() + (set (make-local-variable 'company-backends) + '(company-beancount))) +#+END_SRC + +* beancount +** Installation +#+BEGIN_SRC shell +sudo su +cd /opt +python3 -m venv beancount +source ./beancount/bin/activate +pip3 install wheel +pip3 install beancount +sleep 100 +echo "shell running!" +deactivate +#+END_SRC + +#+BEGIN_SRC emacs-lisp + (use-package beancount + :load-path "user-local/elisp" + :defer t + :mode + ("\\.beancount$" . beancount-mode) + :init + (add-hook 'beancount-mode-hook 'company/beancount-mode-hook) + (setenv "PATH" + (concat "/opt/beancount/bin:" + (getenv "PATH"))) + :config + (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount")) +#+END_SRC + +To support org-babel, check if it can find the symlink to ob-beancount.el + +#+BEGIN_SRC shell + orgpath=`find /home/marc/.emacs.d/elpa/ -type d -name "org-plus*" -print` + beansym="$orgpath/ob-beancount.el + bean="/home/marc/Archiv/Programmierprojekte/Lisp/beancount-mode/ob-beancount.el" + + if [ -h "$beansym" ] + then + echo "$beansym found" + elif [ -e "$bean" ] + then + echo "creating symlink" + ln -s "$bean" "$beansym" + else + echo "$bean not found, symlink creation aborted" + fi +#+END_SRC + +Fava is strongly recommended. + +#+BEGIN_SRC shell +cd /opt +python3 -m venv fava +source ./fava/bin/activate +pip3 install wheel +pip3 install fava +deactivate +#+END_SRC + +Start fava with fava my_file.beancount + +It is accessable on this URL: [[http://127.0.0.1:5000][Fava]] +Beancount-mode can start fava and open the URL right away. +* Python +Systemseitig muss python-language-server installiert sein: +pip3 install 'python-language-server[all]' + +#+BEGIN_SRC emacs-lisp + (use-package lsp-mode + :ensure t + :init + (add-to-list 'exec-path "/home/marc/.local/bin") + :config + (setq lsp-prefer-flymake nil) ;; prefer lsp-ui (flycheck) over flymake + (add-hook 'python-mode-hook #'lsp)) + + (use-package lsp-ui + :requires lsp-mode flycheck + :ensure t + :config + (setq lsp-ui-doc-enable t + lsp-ui-doc-use-childframe t + lsp-ui-doc-position 'top + lsp-ui-doc-include-signature t + lsp-ui-sideline-enable nil + lsp-ui-flycheck-enable t + lsp-ui-flycheck-list-position 'right + lsp-ui-flycheck-live-reporting t + lsp-ui-peek-enable t + lsp-ui-peek-list-width 60 + lsp-ui-peek-list-height 25) + (add-hook 'lsp-mode-hook 'lsp-ui-mode)) + + (use-package company-lsp + :requires company + :ensure t + :config + (push 'company-lsp company-backends) + + ;;disable client-side cache because lsp server does a better job + (setq company-transformers nil + company-lsp-async t + company-lsp-cache-candidates nil)) +#+END_SRC