My personal configuration for Emacs, 2021-07-05T11:00:00+02:00

Irgendein Abschnitt


(require 'package)
(require 'json)

(add-to-list 'package-archives '("melpa" . "") t)
(add-to-list 'package-archives '("elpy" . ""))
(add-to-list 'package-archives '("org" . "") t)


(load (concat user-emacs-directory "reveal.el"))

(add-to-list 'auto-mode-alist '("\\.org.txt\\'" . org-mode))
(add-to-list 'auto-mode-alist '("\\.ino\\'" . c-mode))
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")

;;; yasnippet
;;; should be loaded before auto complete so that they can work together
(require 'yasnippet)
(yas-global-mode 1)

Deciding on which system we work

Emacs config switch depending on hostname or operating system: Idea found here: Single dot emacs file and per-computer configuration | SIGQUIT

This is so cool: with those functions, I am able to maintain one single Emacs configuration for all of my hosts. If there is something I want to do or do not on a specific platform or host, those functions allow me to express my restrictions easily:

Usage: (when (my-system-type-is-windows) (do-something) )

;; Check if system is Microsoft Windows
(defun my-system-type-is-windows ()
  "Return true if system is Windows-based (at least up to Win7)"
  (string-equal system-type "windows-nt")

;; Check if system is GNU/Linux
(defun my-system-type-is-linux ()
  "Return true if system is GNU/Linux-based"
  (string-equal system-type "gnu/linux")

Window splitting

The existing split-window-sensibly function always prefers to end up with a horizontal stack of windows (which, rather confusingly, it calls a vertical "split", though the split is horizontal …) over a side-by-side arrangement. It's easy enough to create a function which has the opposite preference, which is essentially just a copy of split-window-sensibly with the preferences reversed:

(defun split-window-really-sensibly (&optional window)
  (let ((window (or window (selected-window))))
    (or (and (window-splittable-p window t)
             ;; Split window vertically.
             (with-selected-window window
        (and (window-splittable-p window)
             ;; Split window horizontally.
             (with-selected-window window
        (and (eq window (frame-root-window (window-frame window)))
             (not (window-minibuffer-p window))
             ;; If WINDOW is the only window on its frame and is not the
             ;; minibuffer window, try to split it vertically disregarding
             ;; the value of `split-height-threshold'.
             (let ((split-height-threshold 0))
               (when (window-splittable-p window)
                 (with-selected-window window
(setq split-window-preferred-function 'split-window-really-sensibly)


(require 'recentf)
(recentf-mode 1)
(setq recentf-max-saved-items 25)
(setq recentf-max-menu-items 40)
(setq recentf-menu-append-commands-flag t)
(setq recentf-menu-filter 'recentf-arrange-by-dir)


Corral is a lightweight package that lets you quickly wrap parentheses and other delimiters around text, intuitively surrounding what you want it to using just two commands.


Corral can be found on melpa, and should be installed from there. To install it manually instead, save corral.el to your computer and add this to your init file:

(require 'corral)


Call a command once to wrap delimiters around the sexp at point. Repeated calls of the same command, backward or forward, will shift the delimiters in the respective direction, corralling more text.

To use these commands, just bind them to keys of your choosing. Here are some example keybindings:

 (global-set-key (kbd "M-(") 'corral-parentheses-backward)
 (global-set-key (kbd "M-)") 'corral-parentheses-forward)
 (global-set-key (kbd "M-[") 'corral-brackets-backward)
 (global-set-key (kbd "M-]") 'corral-brackets-forward)
 (global-set-key (kbd "M-{") 'corral-braces-backward)
 (global-set-key (kbd "M-}") 'corral-braces-forward)
 (global-set-key (kbd "M-\"") 'corral-double-quotes-backward)


Keep point position instead of following delimiters

This is controlled by the variable corral-preserve-point, which can be set manually or through customize.

 (setq corral-preserve-point t)


(setq org-agenda-category-icon-alist '(("todo" "org/icons/todo16.png" nil nil :ascent\ center)))
(setq org-agenda-custom-commands
   '(("n" "Agenda and all TODOs"
          ((tags "GTD=\"t\"+TODO=\"NEXT\""
                         ((org-agenda-overriding-header "Next Actions")))
           (stuck "" nil)
           (tags-todo "GTD<>\"t\"+CATEGORY<>\"Haushalt\""
                                  ((org-agenda-overriding-header "Sonstige ToDo")))
           (tags-todo "CATEGORY=\"Haushalt\"+SCHEDULED<=\"<+2d>\""
                                  ((org-agenda-overriding-header "Haushalt")))
           (agenda "" nil))
          ("~/cloud/agenda.html" "~/cloud/agenda.txt"))))
(setq org-agenda-files
   '("~/org/" "~/org/" "~/org/" "~/org/"))
(setq org-agenda-include-diary t)
(setq org-agenda-skip-deadline-prewarning-if-scheduled 1)
(setq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-skip-timestamp-if-deadline-is-shown t)
(setq org-agenda-skip-timestamp-if-done t)
(setq org-agenda-span 'fortnight)
(setq org-agenda-time-grid
   '((daily today)
         (800 1000 1200 1400 1600 1800 2000)
         "......" "----------------"))
(setq org-agenda-time-leading-zero t)
(setq org-agenda-window-setup 'reorganize-frame)
 '((R . t)
   (emacs-lisp . t)
   (gnuplot . t)
   (ledger . t)         ;this is the important one for this tutorial
   (python . t)
(setq org-babel-load-languages '((emacs-lisp . t) (ledger . t) (plantuml . t)))
(setq org-babel-python-command "python3")
(setq org-caldav-calendar-id "personal")
(setq org-caldav-calendars '((:calendar-id "personal" :inbox "~/org/")))
(setq org-caldav-files '("~/org/" "~/org/"))
(setq org-caldav-inbox "~/org/")
(setq org-caldav-show-sync-results nil)
(setq org-caldav-sync-changes-to-org 'all)
(setq org-caldav-sync-direction 'twoway)
(setq org-caldav-url
(setq org-capture-after-finalize-hook '(yankpad--remove-id-from-yankpad-capture))
(setq org-capture-templates
   '(("g" "Gutschein" table-line
          (file+headline "~/org/" "Gutscheine")
          "| %? | Thema | Nummer | 10\342\202\254 | Mindestbestellwert | 2020-12-31 |")
         ("Q" "Quotelink" entry
          (file+headline "~/org/" "Inbox")
          "* %:description
Source: [[%:link]]

         ("B" "Biblink" entry
          (file "~/bib/")
          "* %:description
   :TITLE: %:description:
   :URL: %:link
   :SAVED: %<%Y-%m-%d>

%" :immediate-finish t)
         ("L" "Weblink" entry
          (file+headline "~/org/" "Inbox")
          "* [[%:link][%:description]]
   :Bookmarked: %<%Y-%m>
   :END: " :immediate-finish t)
         ("jj" "Dayly Log" plain
          (file+olp+datetree "~/org/odo/jrn/log/" "Log")
          "     %?" :empty-lines 1 :time-prompt t)
         ("jp" "Period Log" entry
          (file "~/org/odo/jrn/log/")
          "* ")
         ("f" "Finanzen in Ledger" plain
          (file "~/org/finanzen.ledger")
          "%(shell-command-to-string (format \"ledger xact %s %s\" (substring \"%:date\" 1 11) \"%:description\"))                                    " :immediate-finish t :empty-lines 1)
         ("p" "Project" entry
          (file+headline "~/org/" "Projects")
          "* [/] %?%:description :project:")
         ("t" "ToDo" entry
          (file+headline "~/org/" "--- ToDo's ---")
          "* %?" :empty-lines 1)
         ("j" "Journal")
         ("" "" entry
          (file "~/org/")
         ("js" "Stepping Stones" entry
          (file "~/org/odo/jrn/log/")
         ("ji" "Intersections" entry
          (file "~/org/odo/jrn/log/")
         ("jn" "Now: The Open " entry
          (file "~/org/odo/jrn/log/")
         ("jd" "Dreams Log" entry
          (file+olp+datetree "~/org/odo/jrn/depth/" "Log")
         ("jt" "Twilight Imagery" entry
          (file+olp+datetree "~/org/odo/jrn/depth/" "Log")
         ("jD" "Dreams extension" entry
          (file "~/org/odo/jrn/depth/")
          "* ")
         ("jT" "Twighlight enhancements" entry
          (file "~/org/odo/jrn/depth/")
          "* ")))
(setq org-closed-keep-when-no-todo t)
(setq org-crypt-disable-auto-save t)
(setq org-deadline-past-days 21)
(setq org-deadline-warning-days 1)
(setq org-directory "~/org")
(setq org-download-screenshot-method "scrot -s %s")
(setq org-edna-mode t)
(setq org-edna-use-inheritance t)
(setq org-ellipsis nil)
(setq org-enforce-todo-dependencies t)
(setq org-export-use-babel nil)
(setq org-hide-block-startup t)
(setq org-hide-emphasis-markers t)
(setq org-hide-leading-stars t)
(setq org-html-html5-fancy t)
(setq org-html-toplevel-hlevel 3)
(setq org-icalendar-combined-agenda-file "/tmp/org-caldav-GvSoW8")
(setq org-icalendar-include-todo 'all)
(setq org-icalendar-store-UID t)
(setq org-icalendar-timezone "Europe/Berlin")
(setq org-icalendar-use-deadline '(todo-due))
(setq org-icalendar-use-scheduled '(event-if-not-todo todo-start))
(setq org-image-actual-width 640)
(setq org-journal-date-format "%Y-%m-%d (%A)")
(setq org-journal-dir "~/org/journal/")
(setq org-journal-file-format "Journal-%Y")
(setq org-link-frame-setup
   '((vm . vm-visit-folder-other-frame)
         (vm-imap . vm-visit-imap-folder-other-frame)
         (gnus . org-gnus-no-new-news)
         (file . find-file)
         (wl . wl-other-frame)))
(setq org-link-from-user-regexp "\\<andy\\>")
(setq org-log-done 'time)
(setq org-modules
   '(org-bbdb org-bibtex org-docview org-gnus org-habit org-info org-irc org-mhe org-w3m))
(setq org-plantuml-jar-path "/usr/share/plantuml/plantuml.jar")
(setq org-refile-allow-creating-parent-nodes 'confirm)
(setq org-refile-targets '(("" :maxlevel . 3)))
(setq org-refile-use-outline-path nil)
(setq org-reveal-root "file://~/bin/reveal.js")
(setq org-reveal-theme "solarized")
(setq org-roam-completion-system 'helm)
(setq org-roam-directory "")
(setq org-src-block-faces '(("*" fixed-pitch)))
(setq org-startup-align-all-tables t)
(setq org-startup-folded 'content)
(setq org-startup-with-inline-images t)
(setq org-stuck-projects '("Project=\"t\"" ("NEXT") nil ""))
(setq org-super-agenda-fontify-whole-header-line t)
(setq org-super-agenda-groups
   '((:name "Mit Deadline" :deadline t)
         (:name "Wichtig" :priority "A")))
(setq org-super-agenda-mode t)
(setq org-super-agenda-unmatched-name "Sonstiges")
(setq org-support-shift-select t)
(setq org-tags-column -64)
(setq org-tags-exclude-from-inheritance '("crypt"))
(setq org-todo-keywords   '((sequence "proj(p)" "TODO(t)" "wait(w)" "NEXT(n)" "|" "DONE(d)" "stop(s)" "forw(f)")))
(setq org-todo-repeat-to-state "NEXT")
(setq org-use-property-inheritance '("GTD"))


;; load gnuplot mode
(require 'gnuplot)
(require 'ob-gnuplot)


Out of the box, org-mode doesn't know about pdf-tools. However, you can add support for opening org links to pdf files with org-pdfview, which is available as a package on MELPA. Once it's installed, you can activate it with the following code in your .emacs:

 (eval-after-load 'org '(require 'org-pdfview))

 (add-to-list 'org-file-apps 
              '("\\.pdf\\'" . (lambda (file link)
                                      (org-pdfview-open link))))

Doing this will provide a new completion target for adding links via C-c C-l, pdfview:, with support for jumping to specific pages. Full links use the format:


If you just want to encrypt the text of an entry, but not the headline, or properties you can use org-crypt. In order to use org-crypt you need to add something like the following to your .emacs:

 (require 'org-crypt)
 (setq org-tags-exclude-from-inheritance (quote ("crypt")))
 ;; GPG key to use for encryption
 ;; Either the Key ID or set to nil to use symmetric encryption.
 (setq org-crypt-key "CABFD3324FD3279F63070228F58A421AE336FFBD")

Now any text below a headline that has a :crypt: tag will be automatically be encrypted when the file is saved. If you want to use a different tag just customize the org-crypt-tag-matcher setting.

Preventing tag inheritance stops you having encrypted text inside encrypted text.

To decrypt the text just call M-x org-decrypt-entry and the encrypted text where the point is will be replaced with the plain text. If you use this feature a lot, you will probably want to bind M-x org-decrypt-entry to a key.

Entries with a :crypt: tag will be automatically be encrypted when you save the file. Emacs Backup Files - a Warning.

With org-crypt, if you have autosave turned on and decrypt the entries, the autosave file will contain the entries in plain text. For this reason your should disable autosave for encrypted files.


 (load (concat user-emacs-directory "lisp/org-super-links.el"))
 (load (concat user-emacs-directory "lisp/org-super-links-org-rifle.el"))
 (load (concat user-emacs-directory "lisp/org-super-links-org-ql.el"))
 (require 'helm-org-rifle)
 (require 'org-super-links)
 (setq sl-search-function 'helm-org-rifle)


Youtube links in org-mode, see

After installing and loading this library in emacs you can use links with the format




in your org-mode document. If you display inline-images in org-mode the link is replaced by the image for the video downloaded from youtube. When you click on the link or on the image the video-url is opened in the browser.

 (load (concat user-emacs-directory "lisp/org-yt.el"))
 (require 'org-yt)


Corral is a lightweight package that lets you quickly wrap parentheses and other delimiters around text, intuitively surrounding what you want it to using just two commands.


Corral can be found on melpa, and should be installed from there. To install it manually instead, save corral.el to your computer and add this to your init file:

 (require 'org-special-block-extras)


 (require 'org-protocol)

org download

 (require 'org-download)

 ;; Drag-and-drop to `dired`
 (add-hook 'dired-mode-hook 'org-download-enable)

elFeed Feed Reader

;; elfeed feed reader                                                     ;;
;;shortcut functions
(defun bjm/elfeed-show-all ()
  (bookmark-jump "elfeed-all"))
(defun bjm/elfeed-show-emacs ()
  (bookmark-jump "elfeed-emacs"))
(defun bjm/elfeed-show-daily ()
  (bookmark-jump "elfeed-daily"))


(require 'projectile)

(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(projectile-mode +1)

(setq projectile-project-search-path '("~/prj/"))

(projectile-register-project-type 'nikola '("")
                  :compile "nikola build"
                  :test "nikola auto"
                  :run "nikola deploy"
                  :test-suffix ".spec")


(require 'emms-setup)
(setq emms-source-file-default-directory "~/data/aud/Musik/")


(require 'helm-config)
(helm-mode t)
(setq helm-split-window-default-side (quote right))

CUA Mode

Cua-mode is part of GnuEmacs versions 22.1.1 and later (at least).

Cua-mode allows one to use ‘C-v’, ‘C-c’, and ‘C-x’ to paste, copy, and cut the region. Since this conflicts with very important keybindings in Emacs, these CUA bindings are only active when the mark is active. The package does a whole lot more, too: ‘C-z’ to undo, Shift-movement to select, and it includes support for rectangular regions (‘C-RET’ and arrow keys instead of using the `C-x r …’ keys) and registers (instead of using the register commands), and it uses `<tab>’ and `S-<tab>’ to indent and outdent the region. As you can see, it is very powerful!

Note: If region is not active – no visible selection – then ‘C-x’ works as it as it does normally in Emacs (without cua-mode).

On the other hand if the region is active you can use C-S-x (or two rapid C-x C-x) instead C-x to do what C-x normally does in Emacs. The same goes for the other CUA keys.

(cua-mode t)
(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy nil) ;; Standard Windows behaviour


(setq centaur-tabs-style "wave"
          centaur-tabs-height 32
          centaur-tabs-set-icons t
          centaur-tabs-set-bar 'under
          x-underline-at-descent-line t)
   ;; (setq centaur-tabs-gray-out-icons 'buffer)
   ;; (centaur-tabs-enable-buffer-reordering)
   ;; (setq centaur-tabs-adjust-buffer-order t)
   (centaur-tabs-mode t)
   (setq uniquify-separator "/")
   (setq uniquify-buffer-name-style 'forward)

   (defun centaur-tabs-buffer-groups ()
     "`centaur-tabs-buffer-groups' control buffers' group rules.

 Group centaur-tabs with mode if buffer is derived from `eshell-mode' `emacs-lisp-mode' `dired-mode' `org-mode' `magit-mode'.
 All buffer name start with * will group to \"Emacs\".
 Other buffer group by `centaur-tabs-get-group-name' with project name."
        ;; ((not (eq (file-remote-p (buffer-file-name)) nil))
        ;; "Remote")
        ((or (string-equal "*" (substring (buffer-name) 0 1))
             (memq major-mode '(magit-process-mode
        ((derived-mode-p 'prog-mode)
        ((derived-mode-p 'dired-mode)
        ((memq major-mode '(helpful-mode
        ((memq major-mode '(org-mode
         (centaur-tabs-get-group-name (current-buffer))))))


(require 'ledger-mode)
(setq ledger-default-date-format "%Y-%m-%d")
(setq ledger-accounts-file "~/fin/accounts.ledger")
(setq ledger-clear-whole-transactions t)
(setq ledger-post-account-alignment-column 2)
(setq ledger-post-amount-alignment-at :decimal)
(setq ledger-post-amount-alignment-column 58)
(setq ledger-reconcile-default-date-format "%Y-%m-%d")
(setq ledger-report-auto-width t)
(setq ledger-report-use-strict t)
(setq ledger-reports
   '(("bal-giro" "ledger bal giro")
         ("regBarclay" "ledger reg Barclay")
         ("bal Giro" "ledger bal giro")
         ("bal Bargeld" "ledger bal Bargeld")
         ("Verlauf-Bargeld" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg Bargeld")
         ("Freies Gehalt" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg Liquid and @HELLMANN")
         ("Verlauf-Barclaycard" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg Liability:Barclay")
         ("Verf\303\274gbarkeit" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg Liquid")
         ("Bestand" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger bal Asset Liability")
         ("Verlauf Darlehen M08" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger --end 2020-01-01 reg \"Darlehen M08\"")
         ("Verlauf Darlehen M09" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger --end 2020-01-01 reg \"Darlehen M09\"")
         ("Verlauf Darlehen M07" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger --end 2020-01-01 reg \"Darlehen M07\"")
         ("Bausparvertr\303\244ge" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger --begin 2019-01-01  --end 2020-01-01 bal \"Bausparvertr\" ")
         ("Verlauf Bausparvertr\303\244ge" "ledger reg M0")
         ("Verlauf Leben M07" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg \"Budget:A:Leben M07\"")
         ("bal Leben" "ledger bal A:Leben")
         ("Verlauf Taschengeld" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg Taschengeld")
         ("bal giro" "ledger bal Giro")
         ("Bestand Bausparvertr\303\244ge" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger bal Bausparvertr\303\244ge \"Passiva:Kredite:Bausparvertrag\"")
         ("Darlehen M07" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger bal \"Aktiva:Bausparvertrage\" \"Passiva:Kredite:Bausparvertrag\"")
         ("Verlauf Bausparvertr\303\244ge" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg \"Bausparvertrag\"")
         ("Verlauf M07" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg \"Bausparvertrag M07\"")
         ("Verlauf M08" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg \"Bausparvertrag M08\"")
         ("Verlauf M09" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg \"Bausparvertrag M09\"")
         ("bal Bausparvertrag M07" "ledger ")
         ("Budget-Einnahmen" "ledger [[ledger-mode-flags]] budget -f ~/fin/drops.ledger Einnahmen")
         ("Budget-Ausgaben" "ledger [[ledger-mode-flags]] budget -f ~/fin/drops.ledger Ausgaben")
         ("Verlauf-Girokonto" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg Giro")
         ("Ausgaben-Gesamt" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger bal Ausgaben")
         ("bal" "%(binary) -f %(ledger-file) bal")
         ("reg" "%(binary) -f %(ledger-file) reg")
         ("payee" "%(binary) -f %(ledger-file) reg @%(payee)")
         ("account" "%(binary) -f %(ledger-file) reg %(account)")
         ("budget" "%(binary) budget -f %(ledger-file) ")))
(setq ledger-schedule-file "~/fin/schedule.ledger")
(setq ledger-schedule-look-forward 7)
(setq ledger-schedule-week-days
   '(("Mo" 1)
         ("Di" 2)
         ("Mi" 3)
         ("Do" 4)
         ("Fr" 5)
         ("Sa" 6)
         ("So" 0)))


(defun gtd/planning-trigger ()
  "Automatically insert chain-find-next trigger when entry becomes NEXT"
  (when (equal org-state "NEXT")
  (message "das war next")
  (setq planned (car (org-map-entries (lambda () (org-entry-get nil  "PLANNED")) "PLANNED<>\"\"" 'tree)))
  (if planned (
  (message "Geplant ist %s" planned)
  (org-entry-put nil "SCHEDULED" planned)
  (org-entry-delete nil "PLANNED")
  ) nil) ))

(add-hook 'org-after-todo-state-change-hook 'gtd/planning-trigger)

(defun drops-mark-as-project ()
"This function makes sure that the current heading has
(1) the tag :project:
(2) has property COOKIE_DATA set to \"todo recursive\"
(3) has any TODO keyword and
(4) a leading progress indicator"
    (org-toggle-tag "project" 'on)
    (org-set-property "COOKIE_DATA" "todo recursive")
    (org-back-to-heading t)
    (let* ((title (nth 4 (org-heading-components)))
           (keyword (nth 2 (org-heading-components))))
       (when (and (bound-and-true-p keyword) (string-prefix-p "[" title))
           (message "TODO keyword and progress indicator found")
       (when (and (not (bound-and-true-p keyword)) (string-prefix-p "[" title))
           (message "no TODO keyword but progress indicator found")
           (forward-whitespace 1)
           (insert "NEXT ")
       (when (and (not (bound-and-true-p keyword)) (not (string-prefix-p "[" title)))
           (message "no TODO keyword and no progress indicator found")
           (forward-whitespace 1)
           (insert "NEXT [/] ")
       (when (and (bound-and-true-p keyword) (not (string-prefix-p "[" title)))
           (message "TODO keyword but no progress indicator found")
           (forward-whitespace 2)
           (insert "[/] ")

(defun drops-id-get-or-generate()
"Returns the ID property if set or generates and returns a new one if not set.
 The generated ID is stripped off potential progress indicator cookies and
 sanitized to get a slug. Furthermore, it is prepended with an ISO date-stamp
 if none was found before."
        (when (not (org-id-get))
               (let* (
                      (my-heading-text (nth 4 (org-heading-components)));; retrieve heading string
                      (my-heading-text (replace-regexp-in-string "[[][0-9%/]+[]] " "" my-heading-text));; remove progress indicators like "[2/7]" or "[25%]"
                      (new-id (my-generate-sanitized-alnum-dash-string my-heading-text));; get slug from heading text
                   ;;(message (concat "HEADING: " my-heading-text))
                   (when (not (string-match "[12][0-9][0-9][0-9]-[01][0-9]-[0123][0-9]-.+" new-id))
                           ;; only if no ISO date-stamp is found at the beginning of the new id:
                           (setq new-id (concat (format-time-string "%Y-%m-%d-") new-id)))
                   (org-set-property "ID" new-id)
        (kill-new (concat "id:" (org-id-get)));; put ID in kill-ring
        (org-id-get);; retrieve the current ID in any case as return value

(defun my-generate-sanitized-alnum-dash-string(str)
"Returns a string which contains only a-zA-Z0-9 with single dashes
 replacing all other characters in-between them.

 Some parts were copied and adapted from org-hugo-slug
 from (GPLv3)."
(let* (;; Remove "<FOO>..</FOO>" HTML tags if present.
       (str (replace-regexp-in-string "<\\(?1:[a-z]+\\)[^>]*>.*</\\1>" "" str))
       ;; Remove URLs if present in the string.  The ")" in the
       ;; below regexp is the closing parenthesis of a Markdown
       ;; link: [Desc](Link).
       (str (replace-regexp-in-string (concat "\\](" "[^)]+)") "]" str))
       ;; Replace "&" with " and ", "." with " dot ", "+" with
       ;; " plus ".
       (str (replace-regexp-in-string
             "&" " and "
              "\\." " dot "
               "\\+" " plus " str))))
       ;; Replace German Umlauts with 7-bit ASCII.
       (str (replace-regexp-in-string "[Ä]" "Ae" str t))
       (str (replace-regexp-in-string "[Ü]" "Ue" str t))
       (str (replace-regexp-in-string "[Ö]" "Oe" str t))
       (str (replace-regexp-in-string "[ä]" "ae" str t))
       (str (replace-regexp-in-string "[ü]" "ue" str t))
       (str (replace-regexp-in-string "[ö]" "oe" str t))
       (str (replace-regexp-in-string "[ß]" "ss" str t))
       ;; Replace all characters except alphabets, numbers and
       ;; parentheses with spaces.
       (str (replace-regexp-in-string "[^[:alnum:]()]" " " str))
       ;; On emacs 24.5, multibyte punctuation characters like ":"
       ;; are considered as alphanumeric characters! Below evals to
       ;; non-nil on emacs 24.5:
       ;;   (string-match-p "[[:alnum:]]+" ":")
       ;; So replace them with space manually..
       (str (if (version< emacs-version "25.0")
                (let ((multibyte-punctuations-str ":")) ;String of multibyte punctuation chars
                  (replace-regexp-in-string (format "[%s]" multibyte-punctuations-str) " " str))
       ;; Remove leading and trailing whitespace.
       (str (replace-regexp-in-string "\\(^[[:space:]]*\\|[[:space:]]*$\\)" "" str))
       ;; Replace 2 or more spaces with a single space.
       (str (replace-regexp-in-string "[[:space:]]\\{2,\\}" " " str))
       ;; Replace parentheses with double-hyphens.
       (str (replace-regexp-in-string "\\s-*([[:space:]]*\\([^)]+?\\)[[:space:]]*)\\s-*" " -\\1- " str))
       ;; Remove any remaining parentheses character.
       (str (replace-regexp-in-string "[()]" "" str))
       ;; Replace spaces with hyphens.
       (str (replace-regexp-in-string " " "-" str))
       ;; Remove leading and trailing hyphens.
       (str (replace-regexp-in-string "\\(^[-]*\\|[-]*$\\)" "" str)))
(defun my-cliplink-format-and-trim-title (title)
  (let (;; Table of replacements which make this title usable for
        ;; org-link. Can be extended.
        (replace-table '(("\\[" . "{")
                         ("\\]" . "}")
                         ("&#8217;" . "’")
                         ("&" . "&") ("&#039;" . "'") ("&#8211;" . "–") ("&#8212;" . "—")
                         (" •     " . "")  ("  | heise online • " . " - heise online") (" | heise online • " . " - heise online")
                               ("&nbsp;" . " ") ("&ensp;" . " ") ("&emsp;" . " ") ("&thinsp;" . " ")
                               ("&rlm;" . "‏") ("&lrm;" . "‎") ("&zwj;" . "‍") ("&zwnj;" . "‌")
                               ("&iexcl;" . "¡") ("&cent;" . "¢") ("&pound;" . "£") ("&curren;" . "¤") ("&yen;" . "¥") ("&brvbar;" . "¦") ("&sect;" . "§")
                               ("&uml;" . "¨") ("&copy;" . "©") ("&ordf;" . "ª") ("&laquo;" . "«") ("&not;" . "¬") ("&shy;" . "­") ("&reg;" . "®")
                               ("&macr;" . "¯") ("&deg;" . "°") ("&plusmn;" . "±") ("&sup2;" . "²") ("&sup3;" . "³") ("&acute;" . "´") ("&micro;" . "µ")
                               ("&para;" . "¶") ("&middot;" . "·") ("&cedil;" . "¸") ("&sup1;" . "¹") ("&ordm;" . "º") ("&raquo;" . "»") ("&frac14;" . "¼")
                               ("&frac12;" . "½") ("&frac34;" . "¾") ("&iquest;" . "¿") ("&Agrave;" . "À") ("&Aacute;" . "Á") ("&Acirc;" . "Â")
                               ("&Atilde;" . "Ã") ("&Auml;" . "Ä") ("&Aring;" . "Å") ("&AElig;" . "Æ") ("&Ccedil;" . "Ç") ("&Egrave;" . "È") ("&Eacute;" . "É")
                               ("&Ecirc;" . "Ê") ("&Euml;" . "Ë") ("&Igrave;" . "Ì") ("&Iacute;" . "Í") ("&Icirc;" . "Î") ("&Iuml;" . "Ï") ("&ETH;" . "Ð")
                               ("&Ntilde;" . "Ñ") ("&Ograve;" . "Ò") ("&Oacute;" . "Ó") ("&Ocirc;" . "Ô") ("&Otilde;" . "Õ") ("&Ouml;" . "Ö") ("&times;" . "×")
                               ("&Oslash;" . "Ø") ("&Ugrave;" . "Ù") ("&Uacute;" . "Ú") ("&Ucirc;" . "Û") ("&Uuml;" . "Ü") ("&Yacute;" . "Ý") ("&THORN;" . "Þ")
                               ("&szlig;" . "ß") ("&agrave;" . "à") ("&aacute;" . "á") ("&acirc;" . "â") ("&atilde;" . "ã") ("&auml;" . "ä") ("&aring;" . "å")
                               ("&aelig;" . "æ") ("&ccedil;" . "ç") ("&egrave;" . "è") ("&eacute;" . "é") ("&ecirc;" . "ê") ("&euml;" . "ë") ("&igrave;" . "ì")
                               ("&iacute;" . "í") ("&icirc;" . "î") ("&iuml;" . "ï") ("&eth;" . "ð") ("&ntilde;" . "ñ") ("&ograve;" . "ò") ("&oacute;" . "ó")
                               ("&ocirc;" . "ô") ("&otilde;" . "õ") ("&ouml;" . "ö") ("&divide;" . "÷") ("&oslash;" . "ø") ("&ugrave;" . "ù") ("&uacute;" . "ú")
                               ("&ucirc;" . "û") ("&uuml;" . "ü") ("&yacute;" . "ý") ("&thorn;" . "þ") ("&yuml;" . "ÿ") ("&fnof;" . "ƒ") ("&Alpha;" . "Α")
                               ("&Beta;" . "Β") ("&Gamma;" . "Γ") ("&Delta;" . "Δ") ("&Epsilon;" . "Ε") ("&Zeta;" . "Ζ") ("&Eta;" . "Η") ("&Theta;" . "Θ")
                               ("&Iota;" . "Ι") ("&Kappa;" . "Κ") ("&Lambda;" . "Λ") ("&Mu;" . "Μ") ("&Nu;" . "Ν") ("&Xi;" . "Ξ") ("&Omicron;" . "Ο") ("&Pi;" . "Π")
                               ("&Rho;" . "Ρ") ("&Sigma;" . "Σ") ("&Tau;" . "Τ") ("&Upsilon;" . "Υ") ("&Phi;" . "Φ") ("&Chi;" . "Χ") ("&Psi;" . "Ψ")
                               ("&Omega;" . "Ω") ("&alpha;" . "α") ("&beta;" . "β") ("&gamma;" . "γ") ("&delta;" . "δ") ("&epsilon;" . "ε") ("&zeta;" . "ζ")
                               ("&eta;" . "η") ("&theta;" . "θ") ("&iota;" . "ι") ("&kappa;" . "κ") ("&lambda;" . "λ") ("&mu;" . "μ") ("&nu;" . "ν") ("&xi;" . "ξ")
                               ("&omicron;" . "ο") ("&pi;" . "π") ("&rho;" . "ρ") ("&sigmaf;" . "ς") ("&sigma;" . "σ") ("&tau;" . "τ") ("&upsilon;" . "υ")
                               ("&phi;" . "φ") ("&chi;" . "χ") ("&psi;" . "ψ") ("&omega;" . "ω") ("&thetasym;" . "ϑ") ("&upsih;" . "ϒ") ("&piv;" . "ϖ")
                               ("&bull;" . "•") ("&hellip;" . "…") ("&prime;" . "′") ("&Prime;" . "″") ("&oline;" . "‾") ("&frasl;" . "⁄") ("&weierp;" . "℘")
                               ("&image;" . "ℑ") ("&real;" . "ℜ") ("&trade;" . "™") ("&alefsym;" . "ℵ") ("&larr;" . "←") ("&uarr;" . "↑") ("&rarr;" . "→")
                               ("&darr;" . "↓") ("&harr;" . "↔") ("&crarr;" . "↵") ("&lArr;" . "⇐") ("&uArr;" . "⇑") ("&rArr;" . "⇒") ("&dArr;" . "⇓") ("&hArr;" . "⇔")
                               ("&forall;" . "∀") ("&part;" . "∂") ("&exist;" . "∃") ("&empty;" . "∅") ("&nabla;" . "∇") ("&isin;" . "∈") ("&notin;" . "∉")
                               ("&ni;" . "∋") ("&prod;" . "∏") ("&sum;" . "∑") ("&minus;" . "−") ("&lowast;" . "∗") ("&radic;" . "√") ("&prop;" . "∝")
                               ("&infin;" . "∞") ("&ang;" . "∠") ("&and;" . "∧") ("&or;" . "∨") ("&cap;" . "∩") ("&cup;" . "∪") ("&int;" . "∫") ("&there4;" . "∴")
                               ("&sim;" . "∼") ("&cong;" . "≅") ("&asymp;" . "≈") ("&ne;" . "≠") ("&equiv;" . "≡") ("&le;" . "≤") ("&ge;" . "≥") ("&sub;" . "⊂")
                               ("&sup;" . "⊃") ("&nsub;" . "⊄") ("&sube;" . "⊆") ("&supe;" . "⊇") ("&oplus;" . "⊕") ("&otimes;" . "⊗") ("&perp;" . "⊥")
                               ("&sdot;" . "⋅") ("&lceil;" . "⌈") ("&rceil;" . "⌉") ("&lfloor;" . "⌊") ("&rfloor;" . "⌋") ("&lang;" . "〈") ("&rang;" . "〉")
                               ("&loz;" . "◊") ("&spades;" . "♠") ("&clubs;" . "♣") ("&hearts;" . "♥") ("&diams;" . "♦") ("&quot;" . "\"") ("&OElig;" . "Œ")
                               ("&oelig;" . "œ") ("&Scaron;" . "Š") ("&scaron;" . "š") ("&Yuml;" . "Ÿ") ("&circ;" . "ˆ") ("&tilde;" . "˜") ("&ndash;" . "–")
                               ("&mdash;" . "—") ("&lsquo;" . "‘") ("&rsquo;" . "’") ("&sbquo;" . "‚") ("&ldquo;" . "“") ("&rdquo;" . "”") ("&bdquo;" . "„")
                               ("&dagger;" . "†") ("&Dagger;" . "‡") ("&permil;" . "‰") ("&lsaquo;" . "‹") ("&rsaquo;" . "›") ("&euro;" . "€")
        ;; Maximum length of the title.
        (max-length 100)
        ;; Removing redundant whitespaces from the title.
        (result (straight-string title)))
    ;; Applying every element of the replace-table.
    (dolist (x replace-table)
      (setq result (replace-regexp-in-string (car x) (cdr x) result t t)))
    ;; Cutting off the title according to its maximum length.
    (when (> (length result) max-length)
      (setq result (concat (substring result 0 max-length) "…")))
    ;; Returning result.

(defun string-replace (this withthat in)
  "replace THIS with WITHTHAT' in the string IN"
    (insert in)
    (goto-char (point-min))
    (replace-string this withthat)
    (buffer-substring (point-min) (point-max))))
(defun straight-string (s)
  "Spliting the string and then concatenating it back."
  (mapconcat #'(lambda (x) x) (split-string s) " "))
(defun my-www-get-page-title (url)
    "retrieve title of web page.
    (let ((title))
      (with-current-buffer (url-retrieve-synchronously url)
        (goto-char (point-min))
        (re-search-forward "<title>\\([^<]*\\)</title>" nil t 1)
        (setq title (match-string 1))
        (goto-char (point-min))
        (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1)
        (string-replace "&nbsp;" " "
                        ;;(decode-coding-string title (intern (match-string 1)))
                        ;; following line fixes charset issues from
                        ;; previous line:
                        (decode-coding-string title 'utf-8)
  (defun my-url-linkify ()
    "Make URL at cursor point into an Org-mode link.
If there's a text selection, use the text selection as input.


Adapted code from:"
    (let (resultLinkStr bds p1 p2 domainName)
      ;; get the boundary of URL or text selection
      (if (region-active-p)
          (setq bds (cons (region-beginning) (region-end)) )
        (setq bds (bounds-of-thing-at-point 'url))
      ;; set URL
      (setq p1 (car bds))
      (setq p2 (cdr bds))
      (let (
            (url (buffer-substring-no-properties p1 p2))
        ;; retrieve title
        (let ((title (my-cliplink-format-and-trim-title (replace-regexp-in-string "\n" " • " (my-www-get-page-title url)))))
          ;;(message (concat "title is: " title))
          ;;(setq url (replace-regexp-in-string "&" "&" url))
          (let ((resultLinkStr (concat "[[" url "][" title "]]")))
            ;; delete url and insert the link
            (delete-region p1 p2)
            (insert resultLinkStr)


(load (concat user-emacs-directory "lisp/dame.el"))
(load (concat user-emacs-directory "lisp/dame-org-rifle.el"))
(load (concat user-emacs-directory "lisp/dame-org-ql.el"))
(setq sl-search-function 'helm-org-rifle)


(require 'org-edna)
(setq orgstuck-keywords '("project" ("NEXT") nil ""))

(setq Org-todo-repeat-to-state "NEXT")



(add-hook 'text-mode-hook #'abbrev-mode)


(defun ekz (&optional b e) 
  (interactive "r")
  (append-to-file b e "~/cloud/Notes/Einkaufszettel.txt"))


(when (my-system-type-is-linux)
  (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu4e")
  (require 'mu4e)
  (require 'org-mu4e)
  ;; default
  (setq mu4e-maildir (expand-file-name "~/.mail"))

  (setq mu4e-drafts-folder "/mailbox/Drafts")
  (setq mu4e-sent-folder   "/mailbox/Sent")
  (setq mu4e-trash-folder  "/mailbox/Trash")

  ;; setup some handy shortcuts
  (setq mu4e-maildir-shortcuts
                '(("/remline/INBOX"             . ?i)
          ("/Ablage/Warpzone"  . ?w)
          ("/remline/Junk"  . ?j)
          ("/Ablage/amazon"  . ?a)
          ("/Ablage/aqbanking"  . ?q)
          ("/remline/Ablage/fritzbox"  . ?f)
                  ("/remline/Ablage/Mailinglisten/WZ-Intern"     . ?z)))

  ;; Multiple accounts from

  (defvar my-mu4e-account-alist
           (user-mail-address  "")
           (mu4e-reply-to-address "")
           (user-full-name     "Andy Drop")
           (mu4e-sent-folder   "/mailbox/Sent")
           (mu4e-drafts-folder "/mailbox/Drafts")
           (mu4e-trash-folder  "/mailbox/Trash")
           (mu4e-refile-folder "/Ablage"))
           (user-mail-address  "")
           (mu4e-reply-to-address "")
           (user-full-name     "Andy Drop")
           (mu4e-sent-folder   "/plaindrops/Sent")
           (mu4e-drafts-folder "/plaindrops/Drafts")
           (mu4e-trash-folder  "/plaindrops/Trash")
           (mu4e-refile-folder "/Ablage"))))

  (setq mu4e-user-mail-address-list
                (mapcar (lambda (account) (cadr (assq 'user-mail-address account)))

  (defun my-mu4e-set-account ()
        "Set the account for composing a message."
        (let* ((account
                        (if mu4e-compose-parent-message
                                (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
                                  (string-match "/\\(.*?\\)/" maildir)
                                  (match-string 1 maildir))
                          (completing-read (format "Compose with account: (%s) "
                                                                           (mapconcat #'(lambda (var) (car var))
                                                                                                  my-mu4e-account-alist "/"))
                                                           (mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
                                                           nil t nil nil (caar my-mu4e-account-alist))))
                   (account-vars (cdr (assoc account my-mu4e-account-alist))))
          (if account-vars
                  (mapc #'(lambda (var)
                                        (set (car var) (cadr var)))
                (error "No email account found"))))

  ;; ask for account when composing mail
  (add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)

  ;; --- End of Multiple Accounts ---

  ;; allow for updating mail using 'U' in the main view:
  (setq mu4e-get-mail-command "offlineimap")

  ;; something about ourselves
  ;; I don't use a signature...
   user-mail-address ""
   user-full-name  "Andreas Drop"
   ;; message-signature
   ;;  (concat
   ;;    "Foo X. Bar\n"
   ;;    "\n")

  (setq mu4e-html2text-command "w3m -T text/html")

  ;; enable inline images
  (setq mu4e-view-show-images t)
  ;; use imagemagick, if available
  (when (fboundp 'imagemagick-register-types)

  ;; sending mail -- replace USERNAME with your gmail username
  ;; also, make sure the gnutls command line utils are installed
  ;; package 'gnutls-bin' in Debian/Ubuntu, 'gnutls' in Archlinux.

  (require 'smtpmail)

  ;;(setq message-send-mail-function 'smtpmail-send-it
  ;;      smtpmail-default-smtp-server ""
  ;;      smtpmail-smtp-server ""
  ;;      smtpmail-smtp-service 25
  ;;      smtpmail-debug-info t)

  (setq mu4e-bookmarks
         '(("flag:unread AND NOT flag:trashed" "Unread messages" 117)
           ("" "Today's messages" 116)
           ("" "Last 7 days" 119)
           ("mime:image/*" "Messages with images" 112)
           ("maildir:\"/remline/INBOX\" or maildir:\"/mailbox/INBOX\" or maildir:\"/plaindrops/INBOX\"" "Common Inbox" 105)))
  (setq mu4e-drafts-folder "/Drafts")
  (setq mu4e-get-mail-command "offlineimap")
  (setq mu4e-headers-results-limit 5000)
  (setq mu4e-html2text-command "pandoc -f html -t markdown --reference-links")
  (setq mu4e-maildir "~/mail")
  (setq mu4e-sent-folder "/Sent")
  (setq mu4e-trash-folder "/Trash")
  (setq mu4e-view-show-images t)

  (add-to-list 'mu4e-view-actions
           '("ViewInBrowser" . mu4e-action-view-in-browser) t)


;; use an org file to organise feeds
(require 'elfeed)
(require 'elfeed-org)
(setq rmh-elfeed-org-files (list "~/org/"))

(global-set-key (kbd "C-0") 'kill-this-buffer)
(global-set-key (kbd "C-.") 'split-window-horizontally)

(global-set-key (kbd "C-M-f") 'elfeed)
(global-set-key (kbd "C-M-m") 'mu4e)

(require 'openwith)
(openwith-mode t)
(add-to-list  'mm-inhibit-file-name-handlers 'openwith-file-handler)
(setq openwith-associations
      (list (list (openwith-make-extension-regexp '("pdf"))
                  "evince" '(file))
            (list (openwith-make-extension-regexp '("maff" "mht" "mhtml"))
                  "firefox" '(file))
            (list (openwith-make-extension-regexp '("m4a" "flac" "mp3" "wav"))
                  "vlc" '(file))
            (list (openwith-make-extension-regexp '("avi" "flv" "mov" "mp4"
                                                    "mpeg" "mpg" "ogg" "wmv"))
                  "vlc" '(file))
            (list (openwith-make-extension-regexp '("doc" "docx" "odt"))
                  "libreoffice" '("--writer" file))
            (list (openwith-make-extension-regexp '("ods" "xls" "xlsx"))
                  "libreoffice" '("--calc" file))
            (list (openwith-make-extension-regexp '("odp" "pps" "ppt" "pptx"))
                  "libreoffice" '("--impress" file))


(setq nikola-build-before-hook '(ignore))
(setq nikola-deploy-before-hook nil)
(setq nikola-new-page-extension "org")
(setq nikola-new-post-extension "org")
(setq nikola-output-root-directory '\"output\")
(setq nikola-verbose t)
(setq nikola-webserver-auto t)
(setq nikola-webserver-open-browser-p t)

Lade Server

(set-face-attribute 'default nil :height 130)
(when (my-system-type-is-linux)
        (find-file "~/org/") 

(when (my-system-type-is-windows)
        (find-file "c:/Users/adrop/cloud/org/")
        (setq my-timer (run-with-idle-timer 300 t 'org-store-agenda-views))


(require 'german-holidays)
(setq calendar-holidays holiday-german-NI-holidays)

(setq calendar-date-style 'iso)
(setq calendar-day-abbrev-array ["So" "Mo" "Di" "Mi" "Do" "Fr" "Sa"])
(setq calendar-day-header-array ["So" "Mo" "Di" "Mi" "Do" "Fr" "Sa"])
(setq calendar-day-name-array
       ["Sonntag" "Montag" "Dienstag" "Mittwoch" "Donnerstag" "Freitag" "Samstag"])
(setq calendar-iso-date-display-form
       '((format "%s-%.2d-%.2d" year
                         (string-to-number month)
                         (string-to-number day))))
(setq calendar-iso-month-header
         (format "%d-%s" year
                         (calendar-month-name month))
         'font-lock-face 'calendar-month-header))
(setq calendar-mark-diary-entries-flag t)
(setq calendar-month-name-array
       ["Januar" "Februar" "M\303\244rz" "April" "Mai" "Juni" "Juli" "August" "September" "Oktober" "November" "Dezember"])
(setq calendar-standard-time-zone-name "CEST")
(setq calendar-time-display-form
       '(24-hours ":" minutes
                              (if time-zone " (")
                              (if time-zone ")")))
(setq calendar-view-diary-initially-flag t)
(setq calendar-week-start-day 1)
(setq plstore-cache-passphrase-for-symmetric-encrytion t)


(add-hook 'diary-list-entries-hook 'diary-sort-entries t)
(add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
(add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)


(require 'eww)
(setq eww-search-prefix "")
(defun browse-youtube-url (url &optional new-window)
    (start-process "vlc" " *vlc*" "vlc" url))

(setq browse-url-browser-function '(("youtu" . browse-youtube-url)
                                    ("." . browse-url-epiphany)))


(setq smtpmail-debug-info t)
(setq smtpmail-default-smtp-server "")
(setq smtpmail-queue-dir "~/mail/queued-mail/")
(setq smtpmail-smtp-server "")
(setq smtpmail-smtp-service 465)
(setq smtpmail-stream-type 'ssl)


(setq dired-listing-switches "-hl --group-directories-first")
(setq dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$\\|^\\..*$")
(setq dired-use-ls-dired t)