My literate Emacs config
Clone or download
Latest commit e98e20a Jan 17, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore +:tracking generated file init.el Sep 13, 2017
LICENSE Initial commit Jun 27, 2015
init.el init.el:~:new gen Jan 16, 2019 org:+:new pretty symbol Jan 16, 2019

toc toc



this is the source for my Emacs config file.

this is an Org mode file. recommendation is to read this file in Emacs which has support for Org mode.

feel free to look around. hopefully you find something that is interesting for you.



Copyright (c) 2015-2018 Marco Wahl <>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

compile the config file

This is a literate program. The respective emacs lisp file has to be created by a compilation the so called tangling.

Call org-babel-tangle on this Org file to get file init.el.

It’s possible to activate the link (org-babel-tangle) to initiate the tangle or use key sequence C-cv t.

first line of the tangle

;;; init.el --- personal emacs config file marco wahl -*- lexical-binding: t ; eval: (view-mode 1)-*-

Set to read-only to make edits harder. Recall that the tangled file is not supposed to be edited.

conform to el-tradition

The following lines are traditionally in every elisp file. These lines also please checkdoc, the elisp documentation checker.

;;; Commentary:


;;; Code:


Switch on debugging, in case.

(setq debug-on-error t)




(load-file "/home/b/p/elisp/external/emacspeak/lisp/emacspeak-setup.el")

try out emacspeak

don’t load outdated byte code

(setq load-prefer-newer t)

note: this is for the case when an emacs lisp el file lies around with a corresponding compiled elc file. when the el file gets changed still the code of the elc file is taken unless load-prefer-newer.


org from source

Load early the local git version to avoid some other org version gets loaded.

(defvar mw-org-source-directory "~/p/org/org-mode")

(let ((orgmodelocation (expand-file-name mw-org-source-directory)))
  (push (concat orgmodelocation "/lisp") load-path)
  (push (concat orgmodelocation "/contrib/lisp") load-path)
  (eval-after-load "org"
       (defconst org-time-stamp-formats '("<%Y-%m-%d>" . "<%Y-%m-%d %H:%M>")
         "Formats for `format-time-string' which are used for time stamps.")))
  (eval-after-load "org-agenda"
       (org-defkey org-agenda-mode-map (kbd "Y") #'org-agenda)))
  (eval-after-load 'info
    '(progn (info-initialize)
             (concat (expand-file-name mw-org-source-directory)
  (eval-after-load 'eww
    '(progn (org-link-set-parameters "eww" :follow #'eww :store #'org-eww-store-link))))

(require 'org)

quickly jump to org source

(defun mw-find-org-source-directory ()
  (find-file mw-org-source-directory))

unbind some default keys of org

Want C-, for more generic commands. Both bound in Org to org-cycle-agenda-files.

(eval-after-load "org-keys"
     (org-defkey org-mode-map (kbd "C-,") nil)
     (org-defkey org-mode-map (kbd "C-'") nil)))

agenda files

;; (setq org-agenda-files '("/home/b/private/zen/projects/ango2018/"))
;; (setq org-agenda-files
;;       '("~/busi/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/org/"
;;         "~/tmp/"
;;         "~/p/org/worg/"))

speed keys for org files

(eval-after-load 'org
  (lambda ()
    (setq org-speed-commands-user
          '(("c" . (lambda ()
                     (org-clone-subtree-with-time-shift 1 "")))
            ("_" . (lambda () (org-cycle-hide-drawers 'subtree)))
            ("K" . org-cut-subtree)
            ("-" . mw-org-hide-meta-info-lines) ;; outline-hide-more
            ("+" . (lambda (arg) (interactive "P")
                     "Show metainfo lines like org properties.  With prefix arg close drawers."
                     (if (not arg)
                     (org-cycle-hide-drawers 'all))) ;; outline-show-more
            ("*" . (lambda (&optional arg)
                     (interactive "P")
                     (avy-goto-char-2 ?* 32 arg)))
            ;; ("." . mw-avy-goto-char) ; somehow this conflicts with auctex
            ("." . (lambda () (interactive)
                     (let ((avy-all-windows nil)) (call-interactively #'avy-goto-char))))
            ("9" . org-decrypt-entry)
            ("6" . org-count-sub-orgees)
            (";" . org-timer-set-timer)
            ("G" . ace-link)
            ("H" . org-rise)
            ("J" . org-clock-goto)
            ("N" org-speed-move-safe 'outline-next-visible-heading)
            ("P" org-speed-move-safe 'outline-previous-visible-heading)
            ("4" . mw-org-property-show-properties-in-clone)
            ("7" . mw-org-log-show-in-clone)
            ("T" . org-tree-to-indirect-buffer)
            ("W" . mw-org-subtree-as-top-level-tree-toggle)
            ("Y" . org-agenda)
            ("d" . org-attach)
            ("k" . org-capture)
            ("m" . org-teleport)
            ("q" . org-columns-quit)
            ("s" . foldout-zoom-subtree)
            ("S" . foldout-exit-fold)
            ("x" . (lambda (arg) "Org export of orgee." (interactive "P")
                     (let ((org-export-initial-scope 'subtree))
            ("y" . org-property-action)
            ("z" . org-add-note)
            ("h" . org-refile-dwim)
            ("A" . (lambda () (interactive) (recenter 0)))))
    ;; (add-to-list 'org-speed-commands-user (cons ","  #'avy-goto-line))
    ;; (add-to-list 'org-speed-commands-user (cons "S" #'mw-org-narrow-to-one-level-above))

promote/demote highest level

(defun org-demote-level-1 ()
  "Demote all level 1 subtrees."
  (goto-char (point-min))
  (while (progn
           (org-next-visible-heading 1)
    (when (= 1 (plist-get (cadr (org-element-at-point)) :level))

I think the next one is implied with org-shift-meta-left (also on “L” speed key afaict).

(defun org-promote-level-2 ()
  "Promote all level 2 subtrees."
  (goto-char (point-min))
  (while (progn
           (org-next-visible-heading 1)
    (when (= 2 (plist-get (cadr (org-element-at-point)) :level))

keys for org-attach-dired…

idea: use a submap to bind c-c c-x like:

(let ((map (make-sparse-keymap))) (define-key map “a” #’…) ) bind the map to c-c c-x.

 (lambda ()
   (define-key dired-mode-map (kbd "C-c C-x a") #'org-attach-dired-to-subtree)
   (define-key dired-mode-map (kbd "C-c C-x c")
     (lambda () (interactive)
       (let ((org-attach-method 'cp))
         (call-interactively #'org-attach-dired-to-subtree))))
   (define-key dired-mode-map (kbd "C-c C-x r")
     (lambda () (interactive)
       (let ((org-attach-method 'mv))
         (call-interactively #'org-attach-dired-to-subtree))))
   (define-key dired-mode-map (kbd "C-c C-x h")
     (lambda () (interactive)
       (let ((org-attach-method 'ln))
         (call-interactively #'org-attach-dired-to-subtree))))
   (define-key dired-mode-map (kbd "C-c C-x s")
     (lambda () (interactive)
       (let ((org-attach-method 'lns))
         (call-interactively #'org-attach-dired-to-subtree))))))

org todo dependencies

Activate dependency checks.

(setq org-enforce-todo-dependencies t)

personal org indentation

(setq org-adapt-indentation nil       ;; no artificial space at the
      ;; left side.  I don't have
      ;; space for this. ;)

to org attachments

No auto git commit for the attachment directory.

(setq org-attach-commit nil)

No duplication of attachments as org properties.

(setq org-attach-file-list-property nil)

org agenda include inactive timestamps

(setq org-agenda-include-inactive-timestamps t) ;;
;; (setq org-agenda-include-inactive-timestamps nil) ;; for not seeing them.

org column settings

 org-columns-ellipses ""
 org-columns-default-format "%ITEM %TODO %PRIORITY %TAGS")

org babel

jump to org block bound

The following bindings allow to find the next occurance of string ‘#+’ which typically indicate an org-block meta thing.

 (lambda ()
    (kbd "C-c M-n")
    (lambda ()
      (re-search-forward "#\\+")

 (lambda ()
    (kbd "C-c M-p")
    (lambda ()
      (re-search-backward "#\\+")))))

There are useful bindings in connection with org-blocks already built in, e.g. org-next-block which sets point to the beginning of the next block.

tab jump from code-block ‘end’ to ‘begin’
;; Experimentation for more convenient block handling.
(defun mw-org-jump-to-beginning-of-block-maybe ()
  "When on a closing line of a block jump to the opening line of the block."
  (let ((case-fold-search t)
        (org-block-end-line-regexp "^[ \t]*#\\+end_")
        (org-block-begin-line-regexp  "^[ \t]*#\\+begin_"))
    (when (save-excursion
            (beginning-of-line 1)
            (looking-at org-block-end-line-regexp))
        (search-backward-regexp org-block-begin-line-regexp)
        t ;; signal that action has been taken
;; Use tab-key for trigger the action.  This is done via hooking.
(eval-after-load 'org
  (lambda ()
    (add-to-list 'org-tab-first-hook 'mw-org-jump-to-beginning-of-block-maybe)))
convenient go up to the beginning of a block
;; Experimentation for more convenient block handling.
(defun mw-org-search-backward-beginning-of-block ()
  "When on a closing line of a block jump to the opening line of the block."
  (let ((case-fold-search t)
        (org-block-begin-line-regexp  "^[ \t]*#\\+begin_"))
    (search-backward-regexp org-block-begin-line-regexp)))
more key bindings for babeling
(require 'ob-keys)

   (cons "m" #'org-babel-mark-block)
   (cons "N" #'org-narrow-to-block)
   (cons "'" #'org-edit-special)
   (cons ">" ; jump to the end.
         (lambda () (let ((case-fold-search t)) ; don't care about case.
                      (search-forward-regexp "#\\+end_src")

org velocity

org velocity is a org-mode contrib extension.

(setq org-velocity-bucket (expand-file-name "" org-directory))

First i hung the C-c v in on org-mode-hook [2014-10-22 Wed 10:25] like

(add-hook 'org-mode-hook (lambda () (local-set-key (kbd "C-c v") 'org-velocity)))

which is nice but actually org-velocity is also capable of a global capturing into the org-velocity-bucket. This is a further possibility to capture something.

I use the global key setting C-c v for org-velocity.

org-protocol for receiving from the outside

(require 'org-protocol)

The org-protocol is useful for actions which come from the outside. E.g. capturing from conkeror into org.

highlight current line in agenda

From Email from Marcin Borkowski: Hl-line mode in agenda:

(add-hook 'org-agenda-finalize-hook (lambda () (hl-line-mode 1)))

save the o-press when opening the agenda

                                        ;(add-hook 'org-agenda-finalize-hook (lambda () (delete-other-windows)))
;; (setq org-agenda-window-setup 'only-window)

delete other windows after jump from agenda

;; (eval-after-load "org-agenda"
;;   '(push #'delete-other-windows org-agenda-after-show-hook))


using org-screenshot as a package now.

;; (push "~/p/elisp/external/org-attach-screenshot" load-path)
;; (require 'org-attach-screenshot)

screenshots for orgees. in particular during capturing.

(defun mw-org-attach-screenshot-as-standard-attachment ()
  "Trigger ‘org-attach-screenshot’ with target as Org standard attachment.
Create the attachment dir if not exists.

The enhancement compared with pure org-attach-screenshot is that
no decision about how to store the image has to be made.
  (require 'org-attach)
  (org-attach-dir t)

watch out for a shortcut key to this command.

jump from the agenda to the stars

In the agenda ‘tab’ per default jumps to the beginning of the headline text. For me it’s a bit more convenient to jump to the beginning of the stars. Fortunately there is org-agenda-after-show-hook.

(eval-after-load "org-agenda"
  '(push #'beginning-of-line org-agenda-after-show-hook))

speed commands also at beginning of buffer

(setq org-use-speed-commands
      (lambda ()
        (or (= (point-min) (point))
            (and (looking-at org-outline-regexp)))))

Taken the looking around code from the documentation of org-use-speed-commands.

refile targets config

(setq org-refile-targets
       ((nil :maxlevel . 7)
        ;; (org-agenda-files :maxlevel . 1)
        (org-agenda-files :level . 0))))

(setq org-refile-use-outline-path (quote file))


(setq org-image-actual-width nil)

play with the subtree bullets

put some info from tags into the bullet
 (lambda ()
    '(("^\\**\\(\\*\\) "
       (1 (compose-region (- (match-end 1) 1)
                          (match-end 1)
                          " ")
      ("^\\**\\(\\*\\) .*:idea:"
       (1 (compose-region (- (match-end 1) 1)
                          (match-end 1)
      ("^\\**\\(\\*\\) .*:imp:"
       (1 (compose-region (- (match-end 1) 1)
                          (match-end 1)
                          "" ; "☀"
org-bullets-mode for org files
(add-hook 'org-mode-hook #'org-bullets-mode)

consider to customize org-bullets-bullet-list.

from agenda open narrowed view of subtree at point

(eval-after-load "org-agenda"
     (org-defkey org-agenda-mode-map "s"
                 (lambda ()
                   "Foldout zoom into the subtree at point in same window.
With prefix argument window fills the frame."
                   (call-interactively #'org-agenda-switch-to)

     (org-defkey org-agenda-mode-map "S"
                 (lambda (arg)
                   "Narrow to the subtree for the item at point in other window.
With prefix argument ARG switch to that window."
                   (interactive "P")
                   (let ((win (selected-window)))
                     (unless arg
                       (select-window win)))))))

hide up to first heading

(defun mw-org-hide-above-first-heading ()
  "Hide from beginning of buffer up to first heading."
  (let ((first-heading-or-end
           (goto-char 1)
           (unless (org-at-heading-p)
    (unless (= 1 first-heading-or-end)
      (org-flag-region 1 first-heading-or-end t 'outline))))

beginning/end -of-defun.

 (lambda ()
   (setq beginning-of-defun-function #'org-back-to-heading)
   (setq end-of-defun-function #'org-end-of-subtree)))


(eval-after-load "org" '(require 'org-num))


package managers


Straight is a package manager that looks nice to me.

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
         'silent 'inhibit-cookies)
      (goto-char (point-max))
  (load bootstrap-file nil 'nomessage))

package.el resources

The gnu package repo is not included from the start.

;; (setf package-archives nil)
;; (add-to-list 'package-archives '("mw" . "/home/b/p/elisp/mw/packs/") t)
;; (add-to-list 'package-archives '("gnu" . "") t)
(add-to-list 'package-archives '("melpa" . "") t)
;; (add-to-list 'package-archives '("RSW-Packages" . "") t)

[2016-02-08 Mon 12:57] Possibly drop usage of the custom file entirely for more clarity in the init process.




create slides from org.

  • [2018-05-17 Thu 11:44] leaving the (require 'ox-reveal) in the config leads to some file related error which starts with “File mode specification error:”. (Seen in messages buffer.) This is relevant because I e.g. can’t org-capture anymore.
    • workaround: load the package when needed.
    • try understand or report.
 (add-to-list 'load-path "~/p/elisp/external/org-reveal")
; (require 'ox-reveal)

this mode folds regions delimitted by {{{ and }}}.

(add-to-list 'load-path "~/p/elisp/external/project-emacs--folding-mode")
(require 'folding)

Try reactivate hyperbole some day.

  • [2018-04-05 Thu 12:35] deactivated. because it interferes and brings me stress.
(straight-use-package 'hyperbole)
 (require 'package)
 (setq package-enable-at-startup nil) ;; Prevent double loading of libraries
 (unless (package-installed-p 'hyperbole)
   (package-install 'hyperbole))

(require 'hyperbole)
;; (org-defkey org-mode-map (kbd "<C-M-return>") #'hkey-either)

(global-set-key (kbd "C-M-7") #'hkey-either)
(global-set-key (kbd "C-M-8") #'assist-key)

(add-hook 'org-mode-hook
          (lambda () (local-set-key [f10] #'org-time-stamp)))
(add-hook 'org-mode-hook
          (lambda () (local-set-key (kbd "C-c .") ; no success to override of the hyperbole 'C-c .' like so.
(eval-after-load "org"
     (org-defkey org-mode-map (kbd "C-c r") #'org-reveal)))
;; override a binding of hyperbole for org-mode


AUR access

aurel helps with the management of the AUR-packages of the Arch-Linux system.

(straight-use-package 'aurel)
(autoload 'aurel-package-info "aurel" nil t)
(autoload 'aurel-package-search "aurel" nil t)
(autoload 'aurel-maintainer-search "aurel" nil t)
(autoload 'aurel-installed-packages "aurel" nil t)
(setq aurel-download-directory "~/AUR")
  • [2014-04-07 Mon 22:26] Just installed a package that might help with


  • start a http server with {{{ M-x httpd-start }}}.
  • start impatient-mode in the buffer you want to see via server.
  • browse to http://localhost:8080/imp/.
  • find the page.
  • it’s all in the docu section of impatient-mode.
enable impatient mode
(straight-use-package 'impatient-mode)

Quickly add to integers in buffer with prefix-arguments for adding/subtracting that value. Default is 1.

(straight-use-package 'evil-numbers)

(global-set-key (kbd "M-+") #'evil-numbers/inc-at-pt)
(global-set-key (kbd "M--") #'evil-numbers/dec-at-pt)
check similar packages

There are more packages in this field.


support for writing haskell programs.

(straight-use-package 'haskell-mode)

Move cursor onto a visible character.

avy is similar to ace-jump-mode. I read that avy is the variant that gets maintained.

(straight-use-package 'avy)

(defun mw-avy-goto-line-below (&optional arg)
"Index lines below (above with ARG) for jump there quickly."
  (interactive "P")
  (if arg (avy-goto-line-above)

(global-set-key (kbd "C-.") #'avy-goto-char)
(global-set-key (kbd "C->") #'avy-goto-char-in-line)
(global-set-key (kbd "C-,") #'mw-avy-goto-line-below)
(global-set-key (kbd "C-'") #'avy-goto-line)

(setq avy-keys
        '(?e ?t ?h ?u ?n ?o ?s ?a ?d ?i ?-
             ?. ?c ?, ?r ?l ?' ?p ?y ?f ?g
             ?m ?j ?b ?k ?w ?q ?v ?x ?z))

(setf avy-all-windows-alt t) ; hint: behavior prefix arg

  ;; [2016-05-03 Tue 15:56]: was
  ;;(eval-after-load "isearch" '(define-key isearch-mode-map (kbd "C-'") 'avy-isearch))
(straight-use-package 'dictionary)

this theme the author likes to use when it’s dark outside.

(straight-use-package 'reverse-theme)
(straight-use-package 'ledger-mode)

expand-region helps to expand the region.

(straight-use-package 'expand-region)
(global-set-key (kbd "C-=") #'er/expand-region)

this program realizes input of passwords via emacs, i think.

(straight-use-package 'pinentry)
key chord
(straight-use-package 'key-chord)

(key-chord-mode 1) ;; recall: e.g. (key-chord-unset-global "bb") for undef a key-chord.
(key-chord-define-global "xx" #'execute-extended-command)
(key-chord-define-global "w5" #'winner-undo)
(key-chord-define-global "u7" #'global-undo-tree-mode)
(key-chord-define-global "x5" #'mw-command-execute-at-point)
(key-chord-define-global "7g" #'mw-split-window-horizontally-at-point)
(key-chord-define-global "4p" #'mw-split-window-vertically-at-point)
(key-chord-define-global "x7" #'eval-defun)
(key-chord-define-global "r7" #'mw-org-refile-set-direct-target-bm)
(key-chord-define-global "r8" #'mw-org-refile-refile-to-direct-target)
(key-chord-define-global "r1" #'mw-carry-region-toggle)
(key-chord-define-global "l1" #'mw-mark-line)
(key-chord-define-global "o6" #'org-open-at-point-global)
(key-chord-define-global "c4" #'recompile)
(key-chord-define-global "o8" #'ace-link)
(key-chord-define-global "s-" #'mw-thread-mousedance-at-cursor)
(key-chord-define-global "ao" #'other-window)
(key-chord-define-global ";q" #'other-frame)
(key-chord-define-global "qj" #'mw-exchange-to-buddy)
(key-chord-define-global ".," #'next-buffer)
(key-chord-define-global "><"       ; this is "S-.," on dovorak layout
(key-chord-define-global "r9" #'rope-read-mode)
(key-chord-define-global "yy" #'mw-duplicate-line)
(key-chord-define-global "''" #'mw-umlautify-before-point)
(key-chord-define-global "uu" (lambda (&optional in-place)
				(interactive "P")
				(if in-place (mw-translate-in-place-eng+deu)
(key-chord-define-global "hh" (lambda () (interactive) (recenter 0))) ; #'recenter-top-bottom; afair H is a respecive vim binding?
(key-chord-define-global "``" #'go-up)
(key-chord-define-global "~~" #'dired-jump)
(key-chord-define-global "^^" #'dired-jump)
(key-chord-define-global ",," #'lentic-mode-move-lentic-window)
(key-chord-define-global "3." #'delete-other-windows)
(key-chord-define-global "c8" #'delete-window) ; for kinesis keyboard
(key-chord-define-global "g8" #'delete-window) ; for cherry keyboard
(key-chord-define-global "m1" #'magit-status)
(key-chord-define-global "m2" #'mw-region-include-top-exclude-bottom-empty-lines)
(key-chord-define-global "yi" (lambda ()
				"Switch to org agenda."
				(if (get-buffer "*Org Agenda*")
				    (switch-to-buffer (get-buffer "*Org Agenda*"))
(key-chord-define-global "kx" (lambda () (interactive)
				(if (eq major-mode 'org-mode)
(key-chord-define-global "1'" #'org-previous-visible-heading)
(key-chord-define-global "jk" (lambda () (interactive)
				 ((eq major-mode 'Buffer-menu-mode) (ibuffer))
				 (t (list-buffers)))))
(key-chord-define-global "n1" #'sp-narrow-to-sexp)
(key-chord-define-global "n2" #'mw-narrow-to-up-sexp)
(key-chord-define-global "n5" #'narrow-to-region)
(key-chord-define-global "a6" #'ariadne-marks-goto-end)
(key-chord-define-global "a7" #'ariadne-marks-backward)
(key-chord-define-global "a8" #'ariadne-marks-set-mark)
(key-chord-define-global "a9" (lambda (&optional arg)
				(interactive "P")
				(when arg (ariadne-marks-unset-all))))
(key-chord-define-global "a0" #'abbrev-mode)
(key-chord-define-global "c1" #'chronos-add-timer)
(key-chord-define-global "d1" #'mw-org-link-strip-decoration)
(key-chord-define-global "s1" #'slime-repl)
(key-chord-define-global "y5" #'kmacro-start-macro-or-insert-counter)
(key-chord-define-global "f6" #'kmacro-call-macro) ; need
                                        ; non-key-chord
                                        ; to end macro
                                        ; AFAICS.
(key-chord-define-global "ii" (lambda (arg)
				(interactive "P")
				(if arg
				    (capitalize-word -1)
				  (downcase-word -1))))
(key-chord-define-global "II" (lambda ()
				(upcase-word -1)))
(key-chord-define-global "`;" #'ido-hacks-mode)
(key-chord-define-global "h1" #'hide-parts-restore)
(key-chord-define-global "h2" #'hide-parts-one-char-indicator)
(key-chord-define-global "h4" #'hide-parts-dwim)
(key-chord-define-global "f1" #'foldout-exit-fold)
(key-chord-define-global "f4" #'foldout-zoom-subtree)
(key-chord-define-global "v1" #'evil-mode)
(key-chord-define-global "e7" #'recursive-edit)
(key-chord-define-global "e8" #'exit-recursive-edit)
(key-chord-define-global "q6" #'auto-fill-mode)
(key-chord-define-global "m5" #'mw-calc-embedded-narrow-toggle)

Hydra provides some convenient key maps organization.

(straight-use-package 'hydra)
package provision

“emacs and scheme talk to each other”

(straight-use-package 'geiser)
;(straight-use-package '(geiser :type git :host gitlab :repo "jaor/geiser"))
load file geiser.elM-x geiser.hack on

ido-hacks sits on top of ido and makes ido even cooler. When ido-hacks-mode comes into the way then just switch it off.

  • [2017-11-05 Sun 17:15] ido-hacks fails often. it scrambles the characters often.
  • [2017-11-05 Sun 17:18] disabling ido-hacks.
  • [2017-12-19 Tue 14:19] reenabling. is this adiction?
  • [2018-07-08 Sun 14:31] LTM like the regexp variant is broken.
(straight-use-package 'ido-hacks)
(require 'ido-hacks)
(when ido-enable-regexp

claims to do the right fill in some cases iirc.

(straight-use-package 'filladapt)
todo deal with inconveniences
  • up to now must evaluate file by hand.
  • is there an old style (i.e. “` “) quote in there?

At very first invocation do M-x dired-narrow in a dired buffer. After that the key binding is active.

Recall g for getting rid of all filtering.

(straight-use-package 'dired-narrow)
(straight-use-package 'auto-correct)
(straight-use-package 'quarter-plane)

get into the mode with

M-x gited-list-branches

(straight-use-package 'gited)
(add-hook 'dired-mode-hook
          (lambda ()
             (define-key dired-mode-map "\C-x\C-g" 'gited-list-branches)))
(straight-use-package 'lua-mode)


(straight-use-package 'mastodon)
(straight-use-package 'racket-mode)

access passwords via emacs.

(straight-use-package 'password-store)

display mode-line in minibuffer.

(straight-use-package '(herald-the-mode-line
           :type git
           :host github
           :repo "marcowahl/herald-the-mode-line"))
rope read

Most important package! Saves eye movements!

(straight-use-package 'rope-read-mode)
reactivate key d
(define-key rope-read-mode-map "d" #'rope-read-next-paragraph)
(straight-use-package 'async)
(eval-after-load "dired-async"
  '(dired-async-mode 1))
the package slime
(straight-use-package 'slime)
(eval-after-load "slime"
     (setq inferior-lisp-program "sbcl")
     (setq slime-contribs '(slime-fancy))
     (setq common-lisp-hyperspec-root
the local-git slime

attempt to use slime from a local repo.

;; (add-to-list 'load-path "~/p/elisp/external/slime")
;; (require 'slime-autoloads)
;; (setq inferior-lisp-program "/usr/bin/sbcl")
;; (setq slime-contribs '(slime-fancy))
;; (eval-after-load 'info
;;   '(progn (info-initialize)
;;           (add-to-list 'Info-directory-list
;;                        "~/p/elisp/external/slime/doc")))

****** - the quicklisp slime

CL-USER> (ql:quickload “quicklisp-slime-helper”) To use, add this to your ~/.emacs:

(load (expand-file-name "~/p/quicklisp/slime-helper.el"))
(setq inferior-lisp-program "sbcl")

****** - hyperspec access

common-lisp-hyperspec-root is a variable defined in ‘hyperspec.el’. Its value is “

Documentation: The root of the Common Lisp HyperSpec URL. If you copy the HyperSpec to your local system, set this variable to something like ”usr/local/doc/HyperSpec”.

;; (add-hook
;;  'slime-mode-hook
;;  (lambda ()
;;    (setq common-lisp-hyperspec-root "file:///home/b/media/texts/it/languages/lisp/HyperSpec/")))

(setq common-lisp-hyperspec-root "file:///home/b/media/texts/it/languages/lisp/HyperSpec/")

***** - go-up

   :type git
   :host gitlab
   :repo "marcowahl/go-up"))

Very helpful mode for editing elisp.

(straight-use-package 'paredit)

(global-set-key (kbd "C-M-<down>") #'paredit-splice-sexp)
(global-set-key (kbd "C-M-<up>") #'mw-paredit-elevate)
disable some paredit key settings
(eval-after-load 'paredit
     (define-key paredit-mode-map (kbd "M-s") nil) ; want this as search key
     (define-key paredit-mode-map (kbd "M-r") nil) ; want this as move-to-window-line-top-bottom
elevate a sexp

an addition for lisp editing. elevate a sexp to a level above.

(ert-deftest 9e04e044f2113716a37aeba7a26e7529a434a467 ()
     (insert "a")
     (goto-char 2)
     (call-interactively #'mw-paredit-elevate)

(ert-deftest 6adde106c7c56a979ceeda1c77158035444edc30 ()
     (insert "(a)")
     (goto-char 2)
     (call-interactively #'mw-paredit-elevate)

(ert-deftest 111c383248a7dfebb5c9d42bf685ec7e869de7fc ()
     (insert "((haha foo) (bar))")
     (goto-char 2)
     (call-interactively #'mw-paredit-elevate)
   "(haha foo)

(defun mw-paredit-elevate ()
  "Move sexp at point at backward up location."
  (catch 'top-paren-level
    (paredit-handle-sexp-errors (paredit-enclosing-list-start)
      (throw 'top-paren-level nil))
enable paredit in some cases
 (lambda (x) (add-hook x #'paredit-mode))
(straight-use-package 'underline-with-char)

press a key to wrap region in a certain way.

(straight-use-package 'wrap-region)

set some region wrappers.

(wrap-region-global-mode t)
(wrap-region-add-wrapper "`" "'")
(wrap-region-add-wrapper "~" "~" nil 'org-mode)
(wrap-region-add-wrapper "*" "*" nil 'org-mode)
(wrap-region-add-wrapper "_" "_" nil 'org-mode)
(wrap-region-add-wrapper "=" "=" nil 'org-mode)
(wrap-region-add-wrapper ":" ":" nil 'org-mode)
(wrap-region-add-wrapper "#+begin_quote\n" "\n#+end_quote" "q" 'org-mode)
(wrap-region-add-wrapper "#+begin_example\n" "\n#+end_example" "e" 'org-mode)
(wrap-region-add-wrapper "#+begin_verse\n" "\n#+end_verse" "v" 'org-mode)
(wrap-region-add-wrapper "#+begin_verbatim\n" "\n#+end_verbatim" "V" 'org-mode)
(wrap-region-add-wrapper "#+begin_src \n" "\n#+end_src" "s" 'org-mode)

display page breaks nicely.

(straight-use-package 'form-feed)

note: page-break-lines is a similar package.

(straight-use-package 'ztree)
ztree “supports showing the difference between two directories”.
example call: {{M-x ztree-diff}}
company mode

company supports completion.

(straight-use-package 'company)


magit is an interface to git.

(straight-use-package 'magit)
(eval-after-load "magit-diff"
  '(define-key magit-file-section-map "C"

a test framework for elisp.

exceptionally installed buttercup via classical package manager. reason: could not easily get buttercup to run via the straight install.

(straight-use-package 'deft)
(straight-use-package 'evil)
(straight-use-package 'hack-time-mode)
(straight-use-package 'shadow)

from source


(push "~/p/elisp/external/org-bullets" load-path)
(require 'org-bullets)

lentic ;;; From: Source:

(add-to-list 'load-path "~/p/elisp/external/lentic")
(add-to-list 'load-path "~/p/elisp/external/m-buffer-el")
(require 'lentic-mode)


redefine M-< and M-> which originally was jump to the beginning and jump to the end.

(add-to-list 'load-path "~/p/elisp/external/beginend")
(require 'beginend)


Big Brother DB. Well integrated storage for data around institutions and persons e.g. addresses.

(push (expand-file-name "~/p/elisp/external/bbdb/lisp") load-path)
(require 'bbdb-loaddefs (expand-file-name "~/p/elisp/external/bbdb/lisp/bbdb-loaddefs.el"))
(bbdb-initialize 'gnus 'message 'anniv)
(bbdb-mua-auto-update-init 'gnus 'message)
(setq bbdb-mua-pop-up nil
      ;; bbdb-mua-pop-up-window-size 0.1
      bbdb-mua-update-interactive-p '(query . create)
      bbdb-mua-auto-update-p 'create ; st annoying.  disable with (setf bbdb-mua-auto-update-p nil)
      bbdb-update-records-p 'query
      ;; bbdb-ignore-message-alist
      ;;    '(("From" . "bugzilla-daemon"))
(add-hook 'message-setup-hook 'bbdb-mail-aliases)
;; [2016-02-05 Fri 13:15] this is a try...
(add-hook 'bbdb-after-change-hook (lambda (arg) (bbdb-save)))
;; Source [[][Email from Alan Schmitt: Re: can I auto save the bbdb f]]
;; ...[2016-02-05 Fri 13:15]

(setq bbdb-snarf-rule-default 'eu)


date at point

(push "~/p/elisp/mw/date-at-point" load-path)
(require 'date-at-point)

functions to prepare u/mount

(defun mw-mount-typical ()
  "Prepare mount the typical drive via eshell."
  (let ((shell (eshell)))
    (set-buffer shell)
    (insert "sudo mount /dev/sdb1 /mnt")
    (switch-to-buffer shell)
(defun mw-umount-typical ()
  "Prepare umount the typical drive via eshell."
  (let ((shell (eshell)))
    (set-buffer shell)
    (insert "sudo umount /mnt")
    (switch-to-buffer shell)

just one space line

(defun mw-just-one-blank-line ()
  "Leave a blank line at cursor."
  (interactive "*")
     (if (not (re-search-backward "[^ \t\n]" nil t))
     (if (not (re-search-forward "[^ \t\n]" nil t))
  (open-line 2)

additions around eww

clean up

remove duplication of firefox browsing functionality

duplicate eww buffer

(defun mw-eww-fork ()
  "Create a further eww buffer for current url."
  (when (eq major-mode 'eww-mode)
    (eww-browse-url (plist-get eww-data :url) t)))

additions to eww keymap

This is for somehow saving the page to not loosing it at the next eww call.

(defun mw-eww-browse-with-firefox ()
  "Browse the current eww url with firefox."
  (cl-assert (eq major-mode 'eww-mode))
  (browse-url-firefox (plist-get eww-data :url)))

(require 'eww)
(eval-after-load "eww"
      (define-key eww-mode-map "x" #'mw-eww-duplicate-buffer) ;'rename-uniquely
      (message "Added 'x' in eww-mode-map -- mw-eww-duplicate-buffer")
      (define-key eww-mode-map "o" #'mw-eww-browse-with-firefox)
      (message "Added 'o' in eww-mode-map -- mw-eww-browse-with-firefox")
      (define-key eww-mode-map "f" #'eww-lnum-follow)
      (message "Added 'f' in eww-mode-map -- eww-lnum-follow")))

eww on region


(defun mw-eww-trigger-with-region-text ()
  "Trigger eww with current region as input."
  (eww (buffer-substring
(defalias 'mw-eww-on-region 'mw-eww-trigger-with-region-text
  "Shorter name.")

open page with firefox

help:eww-browse-with-external-browser has

(eww-browse-with-external-browser &optional URL)

Browse the current URL with an external browser. The browser to used is specified by the ‘shr-external-browser’ variable.

    (define-key eww-mode-map "&"
      (lambda (arg)
        "Open url with external browser.  With prefix ARG use firefox."
        (interactive "P")
        (let ((shr-external-browser
               (if arg 'browse-url-firefox
      (message "& in eww with prefix arg means open with firefox.")))

switch from w3m to eww and vice versa

(defun mw-w3m-switch-to-eww ()
  "Switch to eww from w3m."
  (eww w3m-current-url))
(defun mw-eww-switch-to-w3m ()
  "Switch to w3m from eww."
  (w3m (eww-current-url)))

extend rectangle to longest line

(defun mw-longest-line-length-in-rectangle (start end)
  "Return max col of lines in rectangle."
  (let ((pt (point))
        (maxi 0))
    (when (< end start)
        (let ((aux end))
          (setq end start start aux)))
    (goto-char start)
    (while (<= (point) end)
     (setq maxi (max maxi (current-column)))
     (forward-line 1))
    (goto-char pt)

(defun mw-rectangle-mark-mode-forward-to-max-col (start end)
  "Forward to longest line's max column of region.
Precondition: rectangle-mark-mode is on."
  (interactive "r")
  (cl-assert rectangle-mark-mode)
   (- (mw-longest-line-length-in-rectangle start end)

convert table to tsv

(defun mw-org-table-convert-to-tsv ()
  "Convert table to tab separated values."
  (let ((table (org-table-to-lisp
	         (org-table-begin) (org-table-end)))))
    (delete-region (org-table-begin) (org-table-end))
    (insert (orgtbl-to-tsv table nil) "\n")))

use org-num-mode per default


insert calendar date at point in calendar

(defun mw-insert-date-from-calendar ()
  "Insert the date from the calendar.
Started with `org-date-from-calendar'."
  (let ((cal-date (with-current-buffer "*Calendar*"
        (separator "/"))
    (insert (format-time-string
             (mapconcat #'identity '("%Y" "%m" "%d") separator)
             (encode-time 0 0 0
                          (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))

clone indirect buffer and narrow to region

(defun mw-region-clone-indirect-buffer-narrowed-to-region (start end)
  "Show just region in a narrowed clone in other window.
Only do something when region is active."
  (interactive "r")
  (when (region-active-p)
      (clone-indirect-buffer-other-window nil t)
      (narrow-to-region start end)

delete empty lines in region

(defun mw-region-delete-empty-lines (start end)
"Delete all empty lines in region."
  (interactive "r")
  (flush-lines "^$" start end))

eww on file in dired

Setting key e for opening the file at point in eww.

Note there is already key W for opening the file at point in some browser.

(add-hook 'dired-mode-hook
          (lambda ()
            ;; Set dired-x buffer-local variables here.  For example:
            ;; (dired-omit-mode 1)
            ;; lab: "e" for open the file in eww.  Note: I never used
            ;; "e" to start edit a file of a dired (which is the
            ;; default behavior. [2016-07-21 Thu 17:11])
            (define-key dired-mode-map "e"
              (lambda () (interactive)
                (eww-open-file (dired-get-file-for-visit))))))

;; (setf dired-mode-hook nil)

more fun with pages

;; activate some page-related extensions
(require 'page-ext)
(define-key pages-directory-mode-map "q" 'quit-window) ; fixes hyperbole
;; (define-key pages-directory-mode-map "q" 'ignore)
(let ((map pages-directory-mode-map))
  (define-key map (kbd "TAB") #'pages-directory-goto)
  (define-key map "n" #'next-line)
  (define-key map "p" #'previous-line))

Diary entries in agenda on top

this can be done with a user defined compare function for the org-agenda-sorting-strategy. this means to enable user-defined-up in the strategy for ‘agenda’.

fill user-defined-up with life by setting org-agenda-cmp-user-defined to the following function:

(defun org-cmp-diary (a b)
  "Compare the diary entry of strings A and B."
  (let ((a-is-diary-type (string-equal (get-text-property (1- (length a)) 'type a) "diary"))
        (b-is-diary-type (string-equal (get-text-property (1- (length b)) 'type b) "diary")))
    (cond (a-is-diary-type -1)
          (b-is-diary-type +1)
          (t -1))))

concretely I had set:

org-agenda-sorting-strategy: ‘((agenda time-up ts-up user-defined-up) (todo priority-down category-keep) (tags priority-down category-keep) (search category-keep))

M-RET insert item with date if above is like so

(defun mw-org-insert-item-with-ina-ts-when-on-such-item ()
  "When on org timestamp item insert org timestamp item with current time.
This holds only for inactive timestamps."
  (when (save-excursion
          (let ((item-pos (org-in-item-p)))
            (when item-pos
              (goto-char item-pos)
              (org-list-at-regexp-after-bullet-p org-ts-regexp-inactive))))
    (let ((item-pos (org-in-item-p))
          (pos (point)))
      (assert item-pos)
      (goto-char item-pos)
      (let* ((struct (org-list-struct))
	     (prevs (org-list-prevs-alist struct))
	     (s (concat (with-temp-buffer
                          (org-insert-time-stamp nil t t)
                          (buffer-string)) " ")))
        (setq struct (org-list-insert-item pos struct prevs nil s))
        (org-list-write-struct struct (org-list-parents-alist struct))
        (looking-at org-list-full-item-re)
	(goto-char (match-end 0))
 'org-metareturn-hook 'mw-org-insert-item-with-ina-ts-when-on-such-item)


replace certain tags in Org with symbols or images.

(push "~/p/elisp/mw/org-pretty-tags" load-path)
(require 'org-pretty-tags)
(add-hook 'org-mode-hook #'org-pretty-tags-mode)

find init source

(defun mw-find-emacs-init ()
  (find-file "~/p/elisp/mw/.emacs.d/"))

espeak region

(defun mw-espeak-en-region (start end)
  (interactive "r")
  (let ((fn (make-temp-file "espeak-buffer")))
    (write-region start end fn)
    (async-shell-command (format "espeak -v en -s 110 -f %s" fn))))

(defun mw-espeak-de-region (start end)
  (interactive "r")
  (let ((fn (make-temp-file "espeak-buffer")))
    (write-region start end fn)
    (async-shell-command (format "espeak -v de -s 110 -f %s" fn))))

espeak string

(defun mw-espeak-en-string (string)
    (insert string)
    (mw-espeak-en-region (point-min) (point-max))))

(defun mw-espeak-de-string (string)
    (insert string)
    (mw-espeak-de-region (point-min) (point-max))))

narrow to region with calc

use like so:

  • set region to some math of interest.
    • e.g. “1+1”.
  • {{{ M-x mw-calc-embedded-narrow-toggle }}}
  • use calc-embedded on the narrowed region.
  • {{{ M-x mw-calc-embedded-narrow-toggle }}} to leave calc-embedded and widen.
(defun mw-calc-embedded-narrow-toggle (start end)
  "Narrow to region and enter calc embedded or widen and leave calc
  (interactive "r")
  (if calc-embedded-info
    (narrow-to-region start end))
  (calc-embedded nil))

diff dwim with two dired buffers

(defun mw-dired-diff-to-file-in-other-dired ()
  "Compare file at point with file at point in other dired.
Select the window containing the diff."
  (let* ((current-win (selected-window))
	   (lambda (window)
             (and (not (eq current-win window))
	          (with-current-buffer (window-buffer window)
	            (eq major-mode 'dired-mode))))))
          (and other-win
               (let ((point-in-other
                      (window-point other-win)))
                 (with-current-buffer (window-buffer other-win)
                     (goto-char point-in-other)
                     (dired-get-filename nil t)))))))
    (when filename
      (select-window (dired-diff filename)))))

fira code

fira code setup

[2016-08-24 Wed 09:02]

This works when using emacs –daemon + emacsclient

(add-hook 'after-make-frame-functions
          (lambda (frame)
            (set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")))

This works when using emacs without server/client

(set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol")

I haven’t found one statement that makes both of the above situations work. I used both simultaneously.

(defconst fira-code-font-lock-keywords-alist
  (mapcar (lambda (regex-char-pair)
            `(,(car regex-char-pair)
              (0 (prog1 ()
                    (match-beginning 1)
                    (match-end 1)
                    ,(concat (char-to-string ?\t)
                              (decode-char 'ucs (cadr regex-char-pair)))))))))
          '(("\\(www\\)"                   #Xe100) ;;;    ;; 
            ("[^/]\\(\\*\\*\\)[^/]"        #Xe101) ;
            ("\\(\\*\\*\\*\\)"             #Xe102) ;
            ("\\(\\*\\*/\\)"               #Xe103) ;
            ("\\(\\*>\\)"                  #Xe104) ;
            ("[^*]\\(\\*/\\)"              #Xe105) ;
            ("\\(\\\\\\\\\\)"              #Xe106) ;
            ("\\(\\\\\\\\\\\\\\)"          #Xe107) ;
            ("\\({-\\)"                    #Xe108) ;
            ("\\(\\[\\]\\)"                #Xe109) ;
            ("\\(::\\)"                    #Xe10a) ;
            ("\\(:::\\)"                   #Xe10b) ;
            ("[^=]\\(:=\\)"                #Xe10c) ;
            ("\\(!!\\)"                    #Xe10d) ;
            ("\\(!=\\)"                    #Xe10e) ;
            ("\\(!==\\)"                   #Xe10f) ;
            ("\\(-}\\)"                    #Xe110) ;
            ("\\(--\\)"                    #Xe111) ;
            ("\\(---\\)"                   #Xe112) ;
            ("\\(-->\\)"                   #Xe113) ;
            ("[^-]\\(->\\)"                #Xe114) ;
            ("\\(->>\\)"                   #Xe115) ;
            ("\\(-<\\)"                    #Xe116) ;
            ("\\(-<<\\)"                   #Xe117) ;
            ("\\(-~\\)"                    #Xe118) ;
            ("\\(#{\\)"                    #Xe119) ;
            ("\\(#\\[\\)"                  #Xe11a) ;
            ("\\(##\\)"                    #Xe11b) ;
            ("\\(###\\)"                   #Xe11c) ;
            ("\\(####\\)"                  #Xe11d) ;
            ("\\(#(\\)"                    #Xe11e) ;
            ("\\(#\\?\\)"                  #Xe11f) ;
            ("\\(#_\\)"                    #Xe120) ;
            ("\\(#_(\\)"                   #Xe121) ;
            ("\\(\\.-\\)"                  #Xe122) ;
            ("\\(\\.=\\)"                  #Xe123) ;
            ("\\(\\.\\.\\)"                #Xe124) ;
            ("\\(\\.\\.<\\)"               #Xe125) ;
            ("\\(\\.\\.\\.\\)"             #Xe126) ;
            ("\\(\\?=\\)"                  #Xe127) ;
            ("\\(\\?\\?\\)"                #Xe128) ;
            ("\\(;;\\)"                    #Xe129) ;
            ("\\(/\\*\\)"                  #Xe12a) ;
            ("\\(/\\*\\*\\)"               #Xe12b) ;
            ("\\(/=\\)"                    #Xe12c) ;
            ("\\(/==\\)"                   #Xe12d) ;
            ("\\(/>\\)"                    #Xe12e) ;
            ("\\(//\\)"                    #Xe12f) ;
            ("\\(///\\)"                   #Xe130) ;
            ("\\(&&\\)"                    #Xe131) ;
            ("\\(||\\)"                    #Xe132) ;
            ("\\(||=\\)"                   #Xe133) ;
            ("[^|]\\(|=\\)"                #Xe134) ;
            ("\\(|>\\)"                    #Xe135) ;
            ("\\(\\^=\\)"                  #Xe136) ;
            ("\\(\\$>\\)"                  #Xe137) ;
            ("\\(\\+\\+\\)"                #Xe138) ;
            ("\\(\\+\\+\\+\\)"             #Xe139) ;
            ("\\(\\+>\\)"                  #Xe13a) ;
            ("\\(=:=\\)"                   #Xe13b) ;
            ("[^!/]\\(==\\)[^>]"           #Xe13c) ;
            ("\\(===\\)"                   #Xe13d) ;
            ("\\(==>\\)"                   #Xe13e) ;
            ("[^=]\\(=>\\)"                #Xe13f) ;
            ("\\(=>>\\)"                   #Xe140) ;
            ("\\(<=\\)"                    #Xe141) ;
            ("\\(=<<\\)"                   #Xe142) ;
            ("\\(=/=\\)"                   #Xe143) ;
            ("\\(>-\\)"                    #Xe144) ;
            ("\\(>=\\)"                    #Xe145) ;
            ("\\(>=>\\)"                   #Xe146) ;
            ("[^-=]\\(>>\\)"               #Xe147) ;
            ("\\(>>-\\)"                   #Xe148) ;
            ("\\(>>=\\)"                   #Xe149) ;
            ("\\(>>>\\)"                   #Xe14a) ;
            ("\\(<\\*\\)"                  #Xe14b) ;
            ("\\(<\\*>\\)"                 #Xe14c) ;
            ("\\(<|\\)"                    #Xe14d) ;
            ("\\(<|>\\)"                   #Xe14e) ;
            ("\\(<\\$\\)"                  #Xe14f) ;
            ("\\(<\\$>\\)"                 #Xe150) ;
            ("\\(<!--\\)"                  #Xe151) ;
            ("\\(<-\\)"                    #Xe152) ;
            ("\\(<--\\)"                   #Xe153) ;
            ("\\(<->\\)"                   #Xe154) ;
            ("\\(<\\+\\)"                  #Xe155) ;
            ("\\(<\\+>\\)"                 #Xe156) ;
            ("\\(<=\\)"                    #Xe157) ;
            ("\\(<==\\)"                   #Xe158) ;
            ("\\(<=>\\)"                   #Xe159) ;
            ("\\(<=<\\)"                   #Xe15a) ;
            ("\\(<>\\)"                    #Xe15b) ;
            ("[^-=]\\(<<\\)"               #Xe15c) ;
            ("\\(<<-\\)"                   #Xe15d) ;
            ("\\(<<=\\)"                   #Xe15e) ;
            ("\\(<<<\\)"                   #Xe15f) ;
            ("\\(<~\\)"                    #Xe160) ;
            ("\\(<~~\\)"                   #Xe161) ;
            ("\\(</\\)"                    #Xe162) ;
            ("\\(</>\\)"                   #Xe163) ;
            ("\\(~@\\)"                    #Xe164) ;
            ("\\(~-\\)"                    #Xe165) ;
            ("\\(~=\\)"                    #Xe166) ;
            ("\\(~>\\)"                    #Xe167) ;
            ("[^<]\\(~~\\)"                #Xe168) ;
            ("\\(~~>\\)"                   #Xe169) ;
            ("\\(%%\\)"                    #Xe16a) ;
            ("\\(x\\)"                     #Xe16b) ;   This ended up
                                                   ;  being hard to do
                                                   ;  properly so i'm
                                                   ;  leaving it out.
            ("[^:=]\\(:\\)[^:=]"           #Xe16c) ;
            ("[^\\+<>]\\(\\+\\)[^\\+<>]"   #Xe16d) ;
            ("[^\\*/<>]\\(\\*\\)[^\\*/<>]" #Xe16f) ;

bring the fira code font to buffers with the function.

(defun add-fira-code-symbol-keywords ()
  (font-lock-add-keywords nil fira-code-font-lock-keywords-alist))

hook the function e.g. to prog mode.

(add-hook 'prog-mode-hook #'add-fira-code-symbol-keywords)

recall the remove.

(remove-hook 'prog-mode-hook #'add-fira-code-symbol-keywords)
  • [2016-11-13 Sun 14:47] disabled because sometimes these characters come out not so nicely.

failed attempt to activate fira code

  • [2017-11-30 Thu 15:14] kept this item to warn and possibly revisit.
  • [2016-07-18] The following was disappointing.


;;(when (window-system)
;; (set-frame-font "Fira Code"))
;;(let ((alist '((33 . ".\\(?:\\(?:==\\|!!\\)\\|[!=]\\)")
;;              (35 . ".\\(?:###\\|##\\|_(\\|[#(?[_{]\\)")
;;              (36 . ".\\(?:>\\)")
;;              (37 . ".\\(?:\\(?:%%\\)\\|%\\)")
;;              (38 . ".\\(?:\\(?:&&\\)\\|&\\)")
;;              (42 . ".\\(?:\\(?:\\*\\*/\\)\\|\\(?:\\*[*/]\\)\\|[*/>]\\)")
;;              (43 . ".\\(?:\\(?:\\+\\+\\)\\|[+>]\\)")
;;              (45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)")
;;              (46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=-]\\)")
;;              (47 . ".\\(?:\\(?:\\*\\*\\|//\\|==\\)\\|[*/=>]\\)")
;;              (48 . ".\\(?:x[a-zA-Z]\\)")
;;              (58 . ".\\(?:::\\|[:=]\\)")
;;              (59 . ".\\(?:;;\\|;\\)")
;;              (60 . ".\\(?:\\(?:!--\\)\\|\\(?:~~\\|->\\|\\$>\\|\\*>\\|\\+>\\|--\\|<[<=-]\\|=[<=>]\\||>\\)\\|[*$+~/<=>|-]\\)")
;;              (61 . ".\\(?:\\(?:/=\\|:=\\|<<\\|=[=>]\\|>>\\)\\|[<=>~]\\)")
;;              (62 . ".\\(?:\\(?:=>\\|>[=>-]\\)\\|[=>-]\\)")
;;              (63 . ".\\(?:\\(\\?\\?\\)\\|[:=?]\\)")
;;              (91 . ".\\(?:]\\)")
;;              (92 . ".\\(?:\\(?:\\\\\\\\\\)\\|\\\\\\)")
;;              (94 . ".\\(?:=\\)")
;;              (119 . ".\\(?:ww\\)")
;;              (123 . ".\\(?:-\\)")
;;              (124 . ".\\(?:\\(?:|[=|]\\)\\|[=>|]\\)")
;;              (126 . ".\\(?:~>\\|~~\\|[>=@~-]\\)"))))
;; (dolist (char-regexp alist)
;;   (set-char-table-range composition-function-table (car char-regexp)
;;                         `([,(cdr char-regexp) 0 font-shape-gstring]))))

enable more mouse-wheel

firefox inspired usage of the mouse wheel.

shift+wheel for scrolling horizontally.

(global-set-key [mouse-4] #'scroll-down)
(global-set-key [mouse-5] #'scroll-up)
(global-set-key [S-mouse-4] #'scroll-right)
(global-set-key [S-mouse-5] #'scroll-left)

control+wheel for zooming the text.

(global-set-key [(control mouse-4)] (lambda () (interactive) (text-scale-increase 1)))
(global-set-key [(control mouse-5)] (lambda () (interactive) (text-scale-decrease 1)))

mouse wheel for pdf-view-mode

 (lambda ()
   (local-set-key [mouse-4] #'pdf-view-previous-line-or-previous-page)
   (local-set-key [mouse-5] #'pdf-view-next-line-or-next-page)
   (local-set-key [(control mouse-4)] (lambda () (interactive) (pdf-view-enlarge 1.25)))
   (local-set-key [(control mouse-5)] (lambda () (interactive) (pdf-view-enlarge 0.8)))))

mouse wheel for image-mode

 (lambda ()
   (local-set-key [mouse-4] (lambda () (interactive) (image-previous-line 1)))
   (local-set-key [mouse-5] (lambda () (interactive) (image-next-line 1)))
   (local-set-key [(control mouse-4)] (lambda () (interactive) (image-increase-size 1)))
   (local-set-key [(control mouse-5)] (lambda () (interactive) (image-decrease-size 1)))))

control sound

[2017-03-22 Wed 13:00] When calling the sound goes to 0%!

(defun mw-sound-master-pecentage (percent)
  "Set Master via amixer to PERCENT."
   "" "*mw-amixer*" "amixer" "set" "Master"
   (format "%d%%" (max 0 (min 100 percent)))))

(defun mw-sound-100% ()
  "100% sound."
  (mw-sound-master-pecentage 100)
  (message "sound set to 100%%"))

(defun mw-sound-set-enjoyable-volume ()
  "Enjoyable volume for listening with headphones.

  The effect of this function is somewhat subjective."
  (mw-sound-master-pecentage 30)
  (message "personal sound level set"))

(defun mw-sound-0% ()
  "0% sound."
  (mw-sound-master-pecentage 0)
  (message "sound set to 0%%"))

keys-chords for org-mode

 (lambda ()

attach screenshot as standard attachment

 "t1" #'mw-org-attach-screenshot-as-standard-attachment)

key chord for org outline path

 "o7" (lambda () (interactive) (org-display-outline-path nil t)))


Emms is for playing sound. I use emms mostly for playing internet radio.

BTW emms-streams has configured some nice stations AFAICT.

(push "~/p/elisp/external/emms/lisp" load-path)
(require 'emms-setup)
(emms-devel)				; adds +/- in emms-buffer.
(eval-after-load 'info
  '(progn (info-initialize)
          (add-to-list 'Info-directory-list "~/p/elisp/external/emms/doc")))


Diary entries are useful sometimes. E.g. it’s possible to import ics files into a diary.

Recall that in the org agenda the d key switches diary inclusion on or off.

;; for diary to include other diaries
(add-hook 'diary-list-entries-hook #'diary-include-other-diary-files)
(add-hook 'diary-mark-entries-hook #'diary-mark-included-diary-files)
(add-hook 'diary-list-entries-hook #'diary-sort-entries t)

convert region to timestamp

(defun mw-region-convert-to-org-time-stamp (start end)
  "Parse region and replace by respective timestamp in Org format.

Example(-!- is point, -m- is mark):

    -!- 11:33 2017/10/07-m-


    -!-[2017-10-07 Sat 11:33]-m-
  (interactive "r")
  (let* ((string (if (string-match-p "[[:digit:]]\\{8\\}" (buffer-substring start end))
                    (concat (buffer-substring start (+ 4 start)) "-"
                            (buffer-substring  (+ 4 start)  (+ 6 start)) "-"
                            (buffer-substring  (+ 6 start)  (+ 8 start)) )
                  (buffer-substring start end)))
         (apply #'encode-time
                   (append timelist
                           (make-list (- 6 (length timelist)) 0))))))
        (with-hm t)
        (inactive t))
    (delete-region start end)

(make-obsolete 'org-convert-region-to-org-time-stamp 'mw-region-convert-to-org-time-stamp "now")
(make-obsolete 'mw-convert-region-to-org-time-stamp 'mw-region-convert-to-org-time-stamp "now")

convenient snapshot of emacs from within

(push "~/p/elisp/mw/emacsshot" load-path)
(require 'emacsshot)
 [print] ; (kbd "<print>")
 (lambda (&optional prefix)
   (interactive "p")
   (case prefix
     (1 (emacsshot-snap-window))
     (4 (emacsshot-snap-frame))
     (16 (emacsshot-snap-window-include-modeline)))))

compare windows

Set compare-windows to ignore whitespace by default. Further treat - and + at the beginning of a line as whitespace.

(setq compare-ignore-whitespace t)
(setq compare-windows-whitespace "\\(\\s-\\|

Treating + and - as whitespace eases to compare diffs. Just open the diff buffer in two windows and place the cursors at the beginning of the regions to compare followed by M-x compare-windows .



emr is a refactoring tool.

(straight-use-package 'emr)
(eval-after-load "emr" '(emr-initialize))
(eval-after-load "emr"
  '(define-key emacs-lisp-mode-map (kbd "M-RET")

idea: bind M-RET to emr-show-refactor-menu.

Show the emr menu with M-RET

seclusion mode

Window mode to hide all the clutter and help you focus.

note seclusion-mode is not implemented as mode but just a function.

the package

(straight-use-package 'seclusion-mode)

turn on seclusion-mode

{{{ M-x seclusion-mode RET }}}

opens a copy of the current buffer in a further frame with seclusion on.


there are several customizable variables.

turn off seclusion-mode

  • kill the buffer in the seclusion-mode frame.
  • and kill the frame.
  • that’s it.

see also hidden-mode-line-mode.


Another collection of Emacs stuff.

(push "~/p/elisp/mw/auxies" load-path)
(require 'auxies-rest)

mark a line

(require 'mw-mark)

check the source

  • Does auxies look good?
    • The name is not so promising AFAICS.
  • Can auxies be restructured.


(push "~/p/elisp/mw/auxies" load-path)
(require 'auxies-eww)

pick entry ‘user’ from password-store

for some accounts in some situations it’s handy to have the ‘user’ accessible. user means the value of the user field in the respective password record. note that the user field is optional with the pass system so the functionality of mw-password-store-pick-user depends on the maintainer of the pass file to place the user attribute e.g. user: marcowahl.

(defun mw-password-store-pick-user (entry)
  "Add value of 'user:' in ENTRY to kill ring."
  (interactive (list (password-store--completing-read)))
  (let ((user-text
         (let ((case-fold-search t))
            (lambda (x) (string-match-p "^user:" x))
            (s-lines (password-store--run-show entry))
    (if (not user-text)
        (error "no entry 'user' set for this account.")
      (message "%s copied to kill-ring (from entry %s.)" user-text entry)
      (kill-new (s-trim-left (nth 1 (s-split ":" user-text)))))))

eval region as shell command

use case:

  • user sees a region you want evaluate as shell code.
  • mark that region.
  • evaluate with `mw-region-eval-as-shell-command’.
(defun mw-region-eval-as-async-shell-command (start end)
"Evaluate region as shell command."
  (interactive "r")
    start end)))


(straight-use-package 'pdf-tools)

delete trailing ws on save

the idea is that delete trailing ws on save keeps the files somewhat clean.

 (lambda ()

set/unset a night theme

this setting relies on the availability of theme ‘reverse.

(defun mw-set-night-theme ()
  "Set a theme that I like for nighttime."
  (load-theme 'reverse)
  (set-face-background 'region "darkmagenta")
  (set-face-background 'secondary-selection "darkgreen"))

(defun mw-unset-night-theme ()
  "Unset the night theme.
With my usual setting this unset should yield my typical theme for daylight."
  (disable-theme 'reverse)
  (set-face-background 'region "cyan")
  (set-face-background 'secondary-selection "chartreuse"))

kill emacs

(global-set-key (kbd "C-x C-c") #'save-buffers-kill-emacs) ; also kill a possible daemon.

yes/no -> y/n

type y instead of yes and n for no at several occations.

(defalias 'yes-or-no-p 'y-or-n-p)

find file

find file at point.

 (lambda(&optional prefix)
   (interactive "P")
    (if prefix

tools to work with the agenda

Be able to hide a line of the org agenda.

This is functionality that affects only the representation in an agenda buffer.

This function can be used to scan an agenda with the “scan to nothing” technique. Which is start at the top and hide each line you have thought of.

hide some of agenda

(defun mw-org-agenda-hide-line-or-region ()
  "Hide the line containing point or lines in the region from the agenda.
This action is just cosmetics in the agenda buffer and does not
affect the sources.  I.e. the lines appear again at the next
refresh for an agenda.

Note: This function has been derived from

Note: Of course you can make the agenda buffer writable and use
some standard deletion functionality.  But you need to take the
action of making the agenda buffer writable.  And also take care
about some commands which might have a special meaning in the
agenda buffer e.g. C-k."
  (let ((inhibit-read-only t))
    (if (region-active-p)
           (goto-char (region-beginning))
           (goto-char (region-end))
           (when (or (not (= (region-end)
                               (goto-char (region-end))
                     (= (point) (mark)))
      (move-beginning-of-line 1)
       (save-excursion (move-beginning-of-line 2) (point))))
    ;; (org-agenda-reapply-filters)
    ;; (org-agenda-mark-clocking-task)

keybinding org-agenda

Using the key ‘h’ which reminds of hide. ‘h’ is the standard binding to popup holidays, but they are still accessable on key ‘H’.

(eval-after-load "org-agenda"
     (org-defkey org-agenda-mode-map (kbd "h") #'mw-org-agenda-hide-line-or-region)
     (org-defkey org-agenda-mode-map (kbd "N") (lambda () (interactive) (scroll-up 1)))
     (org-defkey org-agenda-mode-map (kbd "M-n")
                 (lambda () (interactive)
                 "Narrow to line below.  Widen when on bottom."
                   (when (= 0 (forward-line))
     (org-defkey org-agenda-mode-map (kbd "M-p")
                 (lambda ()
                 "Narrow to line above.  Widen when on top."
                   (when (= 0 (forward-line -1))
     (org-defkey org-agenda-mode-map (kbd "P") (lambda () (interactive) (scroll-down 1)))
     (org-defkey org-agenda-mode-map (kbd "-") (lambda () (interactive) (org-agenda-todo "x")))))


this timeclock keymap is the suggested from the timeclock source.

(define-key ctl-x-map "ti" #'timeclock-in)
(define-key ctl-x-map "to" #'timeclock-out)
(define-key ctl-x-map "tc" #'timeclock-change)
(define-key ctl-x-map "tr" #'timeclock-reread-log)
(define-key ctl-x-map "tu" #'timeclock-update-mode-line)
(define-key ctl-x-map "tv" #'timeclock-visit-timelog)
(define-key ctl-x-map "tw" #'timeclock-when-to-leave-string)
(define-key ctl-x-map "tt" #'timeclock-mode-line-display)
(setq timeclock-file "/home/b/busi/archiv/timelogs/timelog")

little helpers

little-helpers is a collection of Emacs stuff.

(push  (expand-file-name "~/p/elisp/mw/little-helpers") load-path)
(require 'little-helpers)
(defalias 'mw-region-ephemeral-enumerate-visual-lines


My little collection of Emacs stuff.

   (lambda (not-found b)
     (if not-found
         (not (string= b (expand-file-name "~/p/elisp/mw/little-helpers")))))
   load-path :initial-value t)))
(require 'org-supplements)
(global-set-key (kbd "C-<") #'mw-recenter-jump-to-top)

prettify symbols in org files

print some text using a glyph or something else.

activate with M-x prettify-symbols-mode.

 (lambda ()
   (setq prettify-symbols-alist
         (append prettify-symbols-alist
                 '(("see" . ?👁)
                   ("siehe" . ?👁)
                   ("note" . ?✎)
                   ("exists" . ?∃))))))

enable global-prettify-symbols-mode



Foldout is a companion for outline mode and org mode. Foldout realizes fold (in the sense of narrow) to a subtree.

One can fold into further subtrees and later exit each fold.

(require 'foldout)

tweaking for org

The standard foldout-zoom-subtree reveals drawers which annoys me.

(defun foldout-zoom-org-subtree (&optional exposure)
  "Same as `foldout-zoom-subtree' with often nicer zoom in Org mode."
  (interactive "P")
      (((symbol-function #'outline-show-entry) (lambda () (org-show-entry))))
    (foldout-zoom-subtree exposure)
[2019-01-02] I’m not perfectly satisfied with the functionality.
[2019-01-02] switch to plain foldout-zoom-subtree.
[2019-01-02] hoping to get a feeling for what I want.

async tangle

(defun mw-org-babel-tangle-buffer-asynchronously ()
  "Tangle current buffer asynchronously."
     `(lambda ()
        (require 'org)
        (org-babel-tangle-file ,buffer-file-name))))


Support of the famous tomato-technique. The idea is to work concentrated for a while (a tomato) and then take a break. This shall be repeated some times a day.

The functions here support pomodoro based on org.

The code is derived from: Source: Author there: Frédéric Couchet le mercredi, août 4 2010, 22:53

(require 'org-timer)

(defvar *mw-pomodoros-completed-in-session* 0
  "Number of pomodoros in the current emacs-session.")

(defvar *mw-pomodoros-before-longer-break* 3
  "Number of pomodoros to reach for a longer break.")

(defcustom *mw-pomodoro-pause-duration* 5
  "Duration in minutes of standard pauses between pomodoros.")

(defcustom *mw-pomodoro-longer-pause-duration* 15
  "Duration in minutes of standard pauses between pomodoros.")

(setq org-timer-default-timer "25")

(add-hook 'org-clock-in-hook
          '(lambda ()
             (if (not ;org-timer-timer-is-countdown ; 201501151654 maint
                   (message "Start a fresh timer.")
                   (org-timer-set-timer '(64))))))

(add-hook 'org-clock-out-hook
          '(lambda ()
             (setq org-mode-line-string nil)))

;; disable org's standard notification [2016-03-17 Thu 10:32] TODO
;; improve and go into the details...
(setf org-show-notification-handler #'ignore)

(defvar mw-pause-state nil "is mw in pause?")

(defun mw-pause-state ()
  (message "%s" mw-pause-state)

(defvar mw-background-color-before-tomato-pause nil)

 '(lambda ()
    (if mw-pause-state
          (setq mw-pause-state nil)
          (message "Pause over at %s.  What about another tomato?"
                   (format-time-string "%T"))
          (set-background-color mw-background-color-before-tomato-pause)
          (start-process "play-a-sound" "*play-a-sound-output*"
                         "mplayer" (expand-file-name
                                        ;(play-sound '(sound :file
                                        ;".../aoogah.wav")) ;
                                        ;[2014-06-02 Mon 15:14] this
                                        ;line played the sound also.
                                        ;But sychronously.
          ;; (zone)

      (setq *mw-pomodoros-completed-in-session*
            (1+ *mw-pomodoros-completed-in-session*))
      ;; going to an org buffer is necessary for starting
      ;; an org timer, I guess [201710301217].
         (if (= 0 (% *mw-pomodoros-completed-in-session*
      (setq mw-background-color-before-tomato-pause
            (frame-parameter (selected-frame) 'background-color))
      (set-background-color (frame-parameter (selected-frame) 'foreground-color))
       "Tomato done at %s.  Il est vraiment temps de prendre une pause."
       (format-time-string "%T"))
      ;; (start-process "play-a-sound" "*play-a-sound-output*"
      ;;                "mplayer" (expand-file-name "~/media/sound/human/shutdown.wav"))
      (start-process "play-a-sound" "*play-a-sound-output*"
                     ;; "en-swedish"
                     "125" ;; word speed
                     "The tomato rings.  Take a rest, now, please."))))

(defun mw-org-trigger-timer-for-pause (&optional duration)
  "Start a timer for a pause of `DURATION' minutes.

   `DURATION' defaults to 5.  See hook `org-timer-done-hook' for
   actions at timers end.

     It looks to me that the org-timer thing is broken.  I can't set
   a new timer with org-timer-set-timer from an org-buffer any
   more except with the triple universal prefix AKA '(64).

   [2014-06-27 Fri 11:12] Good news: I could use M-x
   org-timer-set-timer today and it did the expected thing."
  (if (derived-mode-p 'org-mode)
      (let ((saved-org-timer-default-timer org-timer-default-timer)
            (duration (if (not duration) *mw-pomodoro-pause-duration*
                        (number-to-string duration))))
        (setq org-timer-default-timer duration)
        (org-timer-set-timer '(64))
        (setq org-timer-default-timer saved-org-timer-default-timer)
        (setq mw-pause-state t))
    (error "mw-org-trigger-timer-for-pause: Not in an Org buffer")))

a key for Info-search-next

X wants to find “mysearchstring” muliple times. It’s possible already by typing

s mysearchstring

With the key setting below (a for again) the sequence above simplifies to

s mysearchstring
(eval-after-load 'info
  '(progn (define-key Info-mode-map (kbd "a") #'Info-search-next)))

mark inner of certain blocks

(defun mw-org-mark-block-content ()
  "Mark block without the delimitter lines."
  (let ((element (org-element-at-point)))
    (catch 'found
      (while  element
        (when (member (car element) '(src-block verse-block))
             (goto-char (org-element-property :end element))
             (skip-chars-backward "\n\t ")
             (forward-line 0)
           t t)
	  (goto-char (org-element-property :begin element))
          (forward-line 1))
        (setq element (plist-get (cadr element) :parent))))))

mark inner of source block

use case: mark code for evaluation.

function to determine if point is inside a src-block?

(defun mw-org-at-src-block-at-point ()
  "Return src block at point.  nil if there is none."
    (let ((element (org-element-at-point)))
      (while (and element (not (member (car element) '(src-block))))
        (setq element (plist-get (cadr element) :parent)))
(defun mw-org-mark-src-block-content ()
  "Mark source block without the delimitter lines."
  (let ((element (mw-org-at-src-block-at-point)))
    (when element
         (goto-char (org-element-property :end element))
         (skip-chars-backward "\n\t ")
         (forward-line 0)
       t t)
      (goto-char (org-element-property :begin element))
      (forward-line 1))))

directly evaluate elisp of a src block

(defun mw-org-babel-direct-eval-src-block-as-elisp ()
  "Mark and eval src block as direct elisp."
  (exchange-point-and-mark) ; point at the end.
  (eval-region (region-beginning) (region-end)))
(defun mw-org-babel-direct-eval-next-src-block-as-elisp ()
  "Mark and eval src block as direct elisp."

style for Org files

functionality to bring consistency to org files.

(defun mw-org-style ()
  "Rewrite the subtree or the file according personal style.
- Unify the number of blank lines around headlines.
- Align tags.
IDEA set case of begin_ end_ blocks.  I prefer lower case.
IDEA use org-indent-region for some areas.
IDEA sort the tags in each headline."
  (unless (eq major-mode 'org-mode)
    (user-error "No styling for this buffer.  Buffer is not in Org-mode"))
  (goto-char (point-min))
  (replace-regexp "\n\n+\\([]\n\\|\n\\)\\(\\*+ \\)" "\n\\1\\2")
  (goto-char (point-min))
  (replace-regexp "\\(.\n\\)\\([]\n\\|\\)\\(\\*+ \\)" "\\1\n\\2\\3")
  (goto-char (point-min))
  (when (org-at-heading-p)
    (org-end-of-meta-data t)
  (while (outline-next-heading)
    (org-end-of-meta-data t)

This function could be used at each save.

(add-hook 'after-save-hook #'mw-org-style nil t)


Want abbrevs everywhere.

Started with the suggestion about abbreviations on

(setq-default abbrev-mode t)     ;; enable abbreviations
;(setq save-abbrevs t)            ;; save abbreviations upon exiting
;; abbrev-file-name ; using the default setting.
(quietly-read-abbrev-file)       ;; reads the abbreviations file on startup

fit text scale

(add-to-list 'load-path "~/p/elisp/mw/fit-text-scale")
(require 'fit-text-scale)
 (kbd "C-x C-&")
 (lambda (&optional arg)
   (interactive "P")
    (if arg
 (kbd "C-x C-*")
 (lambda (&optional arg)
   (interactive "P")

rotate windows

(defun mw-rotate-split ()
  "Somehow rotate buffers in the emacs-window.

Originates from group 2006."
  (let ((root (car (window-tree))))
    (if (listp root)
	(let* ((w1 (nth 2 root))
	       (w2 (nth 3 root))
	       (b1 (window-buffer w1))
	       (b2 (window-buffer w2)))
	  (cond ((car root)
		 (delete-window w2)
		 (set-window-buffer (split-window-horizontally) b2))
		 (delete-window w1)
		 (set-window-buffer (split-window-vertically) b1))))
      (message "Root window not split"))))


deadgrep is an interface to ripgrep.

(straight-use-package 'deadgrep)
(defalias 'rg #'deadgrep)


(add-to-list 'load-path "~/p/elisp/mw/ariadne-marks")
(require 'ariadne-marks)

animate to find cursor easily

use animate-string

this is a start. somewhat similar to the beacon mode.

(defun mw-dance-around-the-cursor-a ()
        ((poi (point))
         (start (progn
                  (move-to-window-line 0)
         (end (progn
                (move-to-window-line -1)
      (mw-create-sha1-hash-named-copy-of-region start end)
      (goto-char (1+ (- poi start)))
      (setq buffer-read-only nil)
      (let ((animate-n-steps 10))
         "E m a c s" (line-number-at-pos)
      (sit-for 0.1))

move point some

(defun mw-dance-around-the-cursor-b ()
  (cl-loop for ii from 1 to 20 do
           (sit-for 0.01))
    (cl-loop for ii from 1 to 20 do
           (sit-for 0.01))))

mouse dance via thread

(defun mw-mouse-spiral-at-cursor ()
  (let ((pos (cdr (mouse-avoidance-point-position)))
        (stretch-start 15.0)
        (stretch-growth 0.99)
        (delta 0.1)
        (rotations 5.0))
    (cl-do ((alpha 0.0 (+ delta alpha))
            (stretch stretch-start (* stretch stretch-growth)))
        ((< (* rotations 2 3.141) alpha))
       (+ (car pos) (floor (* stretch (cos alpha))))
       (+ 1 (cdr pos) (floor (* 0.5 stretch (sin alpha)))))
      (sit-for 0.01))))

(defun mw-thread-mousedance-at-cursor ()
  (make-thread #'mw-mouse-spiral-at-cursor))

goto end-of-subtree

provide functionality goto end-of-subtree as command.

(defun mw-org-end-of-subtree ()
  (if (org-before-first-heading-p)
      (goto-char (point-max))


     (org-defkey org-mode-map (kbd "C-)") #'mw-org-end-of-subtree)))

hidden mode line

Found the following mode line hiding function at (Bastien)

(defvar-local hidden-mode-line-mode nil)

(define-minor-mode hidden-mode-line-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global t
  :variable hidden-mode-line-mode
  :group 'editing-basics
  (if hidden-mode-line-mode
      (setq hide-mode-line mode-line-format
            mode-line-format nil)
    (setq mode-line-format hide-mode-line
          hide-mode-line nil))
  ;; Apparently force-mode-line-update is not always enough to
  ;; redisplay the mode-line
  (when (and (called-interactively-p 'interactive)
     0 nil 'message
     (concat "Hidden Mode Line Mode enabled.  "
             "Use M-x hidden-mode-line-mode to make the mode-line appear."))))

;; If you want to hide the mode-line in every buffer by default
;; (add-hook 'after-change-major-mode-hook 'hidden-mode-line-mode)

(defun mw-hidden-mode-line-for-all ()
  (dolist (buffer (buffer-list))
    (set-buffer buffer)
    (unless hidden-mode-line-mode

(defun mw-hidden-mode-line-deactivate-for-all ()
  (dolist (buffer (buffer-list))
    (set-buffer buffer)
    (when hidden-mode-line-mode

hide fringe

(let ((fringe-width 0))
  (fringe-mode fringe-width))

hide scroll bar

(scroll-bar-mode -1)

org attach embedded images

can be useful after paste from eww to org to persist images.

(require 'org-attach-embedded-images)

key to switch from fancy diary to calendar

from fancy diary display use c to open the calendar.

(eval-after-load 'diary-lib
'(define-key diary-fancy-overriding-map "c" #'calendar))

help transform bank data to ledger transactions

(push "~/p/elisp/mw/postbank-to-ledger/" load-path)
(require 'postbank-to-ledger)

reverse a line char wise

(defun mw-reverse-line ()
  "Reverse the letters of the line containing point.
Cursor ends somewhere in that line."
  (let* ((pt (point))
         (bol (progn (beginning-of-line) (point)))
         (offset (- pt bol))
         (eol (progn (end-of-line) (point)))
         (reversel (nreverse (buffer-substring bol eol))))
    (delete-region bol eol)
    (insert reversel)
    (goto-char (- eol offset))))

(ert-deftest test-1-mw-reverse-line ()
  (should (string= "zab rab oof"
             (insert "foo bar baz
             (goto-char 1)
             (buffer-substring 1 12)))))

(ert-deftest test-2-mw-reverse-line ()
  (should (= 9
               (insert "foo bar baz
               (goto-char 4)

M-RET insert heading with date if above is like so

(push "~/p/elisp/mw/org-insert-context-dependent/" load-path)
(require 'org-insert-context-dependent)

(add-hook 'org-metareturn-hook #'org-icd-insert-heading-with-i-ts)

move sibling to top or end

**** - subtrees

(defalias 'mw-org-move-subtree-to-bottom #'mw-org-subtree-make-last-sibling)
(defun mw-org-subtree-make-last-sibling ()
  "Move sibling so it gets last sibling."
  (org-back-to-heading t)
  (org-back-to-heading t))
(defalias 'mw-org-move-subtree-to-top #'mw-org-subtree-make-first-sibling)
(defun mw-org-subtree-make-first-sibling ()
 "Move sibling so it gets first sibling.."
 (org-back-to-heading t)
 (unless (org-first-sibling-p)
  (let (up-pos )
      (setq up-pos (point)))
    (goto-char up-pos)

plain lists

(defun mw-org-move-item-to-bottom ()
  "Move plain list item so it gets last sibling."
  (flet ((user-error (format &rest args) (throw 'end-reached nil)))
    (catch 'end-reached
      (while t
(defun mw-org-move-item-to-top ()
  "Move plain list item so it gets first sibling."
  (flet ((user-error (format &rest args) (throw 'at-border nil)))
    (catch 'at-border
      (while t


move to the moved item
(defun mw-org-move-subtree-or-item-to-bottom ()
  "Position subtree or item at point at the end of the list."
   ((org-at-item-p) (mw-org-move-item-to-bottom))
   (t (mw-org-move-subtree-to-bottom))))
(defun mw-org-move-subtree-or-item-to-top ()
  "Position subtree or item at point at the top of the list."
   ((org-at-item-p) (mw-org-move-item-to-top))
   (t (mw-org-move-subtree-to-top))))
don’t move to the moved item
(defun mw-org-move-subtree-or-item-to-bottom-keep-point ()
  "Position subtree or item at point at the end of the list."
(defun mw-org-move-subtree-or-item-to-top-keep-point ()
  "Position subtree or item at point at the top of the list."

first child to end

(defun mw-org-move-first-child-subtree-to-end ()
  "Move first child to end."
  (org-next-visible-heading 1)
  (backward-char) ; back to parent.  todo: corner case.
  (skip-chars-forward " \n")


keep some data hidden in an extra location.

(let ((private-code-file "~/private/p/mw-private.el"))
  (unless (and
           (file-exists-p private-code-file)
           (load private-code-file))
    (warn "load of file %s with private data failed.  recommendation: check the file" private-code-file)))


mark clones

A hook allows marking the clones easily.

(setq clone-indirect-buffer-hook
      (lambda ()
        (make-local-variable 'is-indirect-clone-p)
        (setq is-indirect-clone-p t)))


(add-hook 'dired-mode-hook 'dired-hide-details-mode)


create appts from the agenda

(add-hook 'org-finalize-agenda-hook 'org-agenda-to-appt)

goto clock in agenda

(defun org-agenda-list--clock-goto (&optional arg start-day span with-hour)
  "Goto the current clock in agenda.
This function is thought as advice function for org-agenda-list."

(advice-add 'org-agenda-list :after #'org-agenda-list--clock-goto)

agenda gets only window

(add-hook 'org-agenda-finalize-hook #'delete-other-windows)



org agenda

(eval-after-load "org-agenda"
     (org-defkey org-agenda-mode-map (kbd "C-o") #'org-agenda-show)))

help about local char

Put describe-char into the C-h section. The command is already on C-u C-x =. Somehow I think the binding in the help section is natural.

(define-key help-map "=" (lambda () (interactive) (describe-char (point))))


(global-set-key (kbd "C-x C-k E") #'edit-last-kbd-macro)


change window layout with prominent keys.

(global-set-key (kbd "C-<left>") #'winner-undo)
(global-set-key (kbd "C-<right>") #'winner-redo)


Find occurrences in several buffers.

(global-set-key (kbd "M-s O") #'multi-occur-in-matching-buffers)


imenu provides a mechanism to jump to locations of interest for several file types, e.g. Org.

(global-set-key (kbd "C-*") 'imenu)


can help to edit all occurances of a variable.

(global-set-key (kbd "C-;") 'iedit-mode)
use case example
  • narrow to a part of interest.
  • have point on the word of interest.
  • activate imenu-mode (C-;).
  • edit the word.
  • leave the mode with C-cc (or C-;).


(global-set-key (kbd "C-x r u") #'clear-register)


global keys
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-switchb)
(global-set-key (kbd "C-c v") 'org-velocity)
keys for org
goto end of subtree on c-)
     (org-defkey org-mode-map (kbd "C-)") #'org-end-of-subtree)))
org-up-element on c-^

Currently disabled by not tangling. See the other setting for C-^ at Alternate up.

     (org-defkey org-mode-map (kbd "C-^") #'go-up)))

following org-mode links given in other modes

To be able to follow an org-mode link in an arbitrary file can be nice, e.g. to get to the original from within a tangled file.

(global-set-key (kbd "C-c o") #'org-open-at-point-global)

exit org src edit with c-cc

(define-key org-src-mode-map "\C-c\C-c" 'org-edit-src-exit)

individual keymap

(defvar mw-individual-keymap
  (let ((map (make-sparse-keymap)))
    (define-key map "0" (lambda () (interactive) (find-file "~/0_in")))
    (define-key map "1" (lambda () (interactive) (find-file "~/1_out")))
    (define-key map "/" #'rg)
    (define-key map "f" #'mw-kill-buffer-filename)
    (define-key map "G" #'git-auto-commit-mode)
    (define-key map "g" #'gnus)
    (define-key map "l" #'clone-indirect-buffer)
    (define-key map "A" #'mw-append-to-scratch)
    (define-key map "r" #'mw-auxies-toggle-default-frame-reverse-state)
    (define-key map "d" #'herald-the-mode-line)
    (define-key map "h" #'mw-strip)
    (define-key map "F" #'fringe-mode)
    (define-key map "&" #'emacspeak-wizards-execute-asynchronously)
    ;; the above binding could get C-x &.  remember Michaels talk on threads.
    (define-key map "b"
      (lambda ()
        (if emms-player-playing-p
            (emms-play-url "")))))
    (define-key map "B" ; background
      (let ((map (make-sparse-keymap)))
        (define-key map "b" (lambda () (interactive) (set-background-color "black")))
        (define-key map "d" ; dark.
          (lambda () (interactive) (set-background-color "#021")))
        (define-key map "w" (lambda () (interactive) (set-background-color "white")))
        (define-key map "c" (lambda () (interactive) (set-background-color "lightcyan")))
    (define-key map "p" #'password-store-copy)
    (define-key map "P" #'mw-password-store-pick-user)
    (define-key map (kbd "C-j") #'org-clock-goto)
    (define-key map "z" #'mw-auxies-delete-to-direction)
    (define-key map "k" #'key-chord-mode) ; sometimes i need turning it off and on again.
    (define-key map "c" (lambda () (interactive)
                          (if (get-buffer "*Calendar*")
                              (switch-to-buffer "*Calendar*")
    (define-key map "q" (lambda (arg)
                          (interactive "P")
                          (if (equal arg '(4))
    (define-key map "u" #'unexpand-abbrev)
    (define-key map "i" #'ido-hacks-mode)
    (define-key map "w" #'org-refile-goto-last-stored)
                                        ; recall: from org-files there is already C-u C-u C-c C-w.
    (define-key map "<" #'mw-screen-exchange-slurp-insert)
    (define-key map ">" #'mw-screen-exchange-write-region)
    (define-key map "e" #'evil-mode)
    (define-key map "E" (lambda () "Erase org-stored-links" (interactive) (setq org-stored-links nil)))
    (define-key map "(" #'paredit-mode)
    (define-key map ")" #'lispy-mode)
    (define-key map "W" #'calc-embedded-word) ; recall 'q' to leave the mode.
    (define-key map "s" (lambda () (interactive) (switch-to-buffer "*scratch*")))
    (define-key map "o" ; org...
      (let ((map (make-sparse-keymap)))
        (define-key map "a" #'org-agenda-list)
    (define-key map "O" #'mw-org-kill-new-outline-path) ; Has been useful for refile.
    (define-key map "m" #'mw-region-teleport-to-other-window)
    (define-key map "a" #'mw-region-append-to-other-window)
    (define-key map "=" #'mw-duplicate-term)
    (define-key map "t" #'org-todo-current-clock-entry)
    ;;     (define-key map "t" (lambda ()
    ;;                           "Switch the minibuffer externalization for new frames.
    ;; And delete all frames.
    ;; This works good when an Emacs daemon runs and thus allows
    ;; easily create a new frame."
    ;;                           (interactive)
    ;;                           (if (cdr (assoc 'minibuffer default-frame-alist))
    ;;                               (mw-unset-minibuffer-in-default-frame)
    ;;                             (mw-set-minibuffer-in-default-frame))
    ;;                           (mapc #'delete-frame (frame-list))
    ;;                           ))
  "Personal convenience keymap.")
(global-set-key (kbd "\C-z") mw-individual-keymap)



the following hydra is thought to supplement C-c right and C-c left.

(defhydra hydra-winner
  (global-map "C-x <left>")
  "Go back window layouts with 'winner'."
  ("<left>" winner-undo)
  ("<right>" winner-redo "Go back to layout from where winner started.":exit t)
  ("q" ignore "Quit hydra and stay with this layout for now."
  :exit t))
window size
(defhydra hydra-winsize (global-map "C-c ^")
  "Shrink window."
  ("6" shrink-window)
  ("^" enlarge-window)
  ("<" shrink-window-horizontally)
  (">" enlarge-window-horizontally))
(defun mw-face-set-default-relatively-big (&optional val)
  "Set the default face height to VAL.
Default is 255 which stands typically for a relatively big font."
  (setq val (or val 255))
          'default nil
          :height val))
(defun mw-increase-face-height ()
  (let ((before-height (face-attribute 'default :height)))
    (cl-loop while (and (< change 42)
                        (= before-height (face-attribute 'default :height)))
             with change = 1
             do (progn
                   'default nil
                   :height (max 1 (+ before-height change)))
                  (sit-for 0))
             (cl-incf change))
    (message "face height: %d" (face-attribute 'default :height))))

(defun mw-decrease-face-height ()
  (let ((before-height (face-attribute 'default :height)))
    (cl-loop while (and (< change 42) (= before-height (face-attribute 'default :height)))
             with change = 1
             do (progn
                   'default nil
                   :height (max 1 (- before-height change)))
                  (sit-for 0))
             (cl-incf change)))
  (message "face height: %d" (face-attribute 'default :height)))

(defhydra hydra-font-control (global-map "C-c C-S-f")
  "Control the font."
  ("-" (mw-decrease-face-height))
  ("+" (mw-increase-face-height))
  ("=" (mw-increase-face-height))
  ("b" (set-face-attribute
        'default nil
        :weight 'bold))
  ("n" (set-face-attribute
        'default nil
        :weight 'normal))
  ("f" (set-face-attribute
        'default nil
        :family "firacode") "firacode")
  ("a" (add-fira-code-symbol-keywords)
   "add some cool fira code symbols. e.g. ~~>")
  ("p" (set-face-attribute
        'default nil
        :family "profont") "profont")
  ("s" (set-face-attribute
        'default nil
        :family "sourcecodepro") "sourcecodepro")
  ("c" (set-face-attribute
        'default nil
        :family "courier") "courier")
  ("d" (set-face-attribute
        'default nil
        :family "deja vu sans mono") "deja vu sans mono")
  ("i" (message "family: %s, weight: %s, height: %s"
                (face-attribute 'default :family)
                (face-attribute 'default :weight)
                (face-attribute 'default :height))
  ("q" (ignore) "ok, quit" :exit t))

alternate up

(global-set-key (kbd "C-^") #'go-up)

dired extra keys

key for alternate up

Expand dired-mode-map with a key for opening parent directory as alternate dired.

 (lambda ()
   (define-key dired-mode-map "`" #'go-up)))
key for narrow

Expand dired-mode-map with a key for filtering the list of files.

 (lambda () (define-key dired-mode-map "/" #'dired-narrow-regexp)))
hide dot files
 (lambda () (define-key dired-mode-map "," #'mw-dired-hide-dot-files)))
compare files in different dired windows
 (lambda () (define-key dired-mode-map "@" #'mw-dired-diff-to-file-in-other-dired)))

enhance keys for buffer list

switch to ibuffer.
scroll-up 1.
go to the last line.
  • With M-> point goes to the last char (and not one before that.)
 (lambda ()
    ">" (lambda () (interactive)
    "N" (lambda () (interactive)
          (scroll-up 1)))
    "P" (lambda () (interactive)
          (scroll-down 1)))
    "i" (lambda () (interactive)

enhance keys for ibuffer

switch to buffer-list.
(add-hook 'ibuffer-mode-hook
          (lambda ()
             "i" (lambda () (interactive)
                   (if (bufferp (get-buffer "*Buffer List*"))
                       (display-buffer "*Buffer List*" '(display-buffer-same-window . ()))

various keysettings

(global-set-key (kbd "<f1>") #'ignore) ;; e.g. for leaving the zone.
(global-set-key (kbd "<f6>") #'flyspell-mode)
(global-set-key (kbd "M-<f6>") #'mw-cycle-ispell-language-and-input-method)
(global-set-key (kbd "M-<f7>") #'mw-cycle-ispell-completion-dict)
(global-set-key (kbd "C-$") #'ispell-complete-word)
(global-set-key (kbd "S-<f11>") #'mw-rotate-split)
(global-set-key (kbd "C-<f11>") (lambda () "'Rotate' windows two times." (interactive) (mw-rotate-split) (mw-rotate-split)))
(global-set-key (kbd "<f12>") #'org-insert-heading-starting-with-inactive-ts)
(global-set-key (kbd "S-<f12>") #'org-list-insert-inactive-ts-item)
(global-set-key (kbd "S-<f8>") #'mw-ephemeral-enumerate-visual-lines-down-from-point)

;; the following collides with parmode:
;; (global-set-key (kbd "C-M-<right>") #'next-buffer)
;; (global-set-key (kbd "C-M-<left>") #'previous-buffer)
;; [2015-10-12 Mon 15:03] trying key chords.

(global-set-key (kbd "<XF86AudioLowerVolume>") #'emms-volume-lower)
(global-set-key (kbd "<XF86AudioRaiseVolume>") #'emms-volume-raise)

(defhydra hydra-volume-control (global-map "C-c 1")
  "Volume control."
  ("1" (dotimes (_ 50) (emms-volume-lower)) "silence")
  ("2" (emms-volume-lower) "lower")
  ("3" (progn (emms-volume-amixer-change -100)
              (emms-volume-amixer-change 50)
              ) "half")
  ("4" (emms-volume-raise) "raise")
  ("5" (dotimes (_ 50) (emms-volume-raise)) "full")
  ("q" (ignore) "quit" :exit t))

(global-set-key (kbd "<XF86AudioMute>") #'mw-sound-0%)
(global-set-key (kbd "<XF86AudioNext>") #'mw-sound-100%)
(global-set-key (kbd "<XF86AudioPlay>") #'mw-sound-set-enjoyable-volume)

;(global-set-key (kbd "C-x o") 'ace-window)

;; cycle through amounts of spacing
(global-set-key (kbd "M-SPC") #'cycle-spacing)

(global-set-key (kbd "C-5") #'repeat)

(defun mw-direct-command-repeat (&optional arg)
  "Direct command Repeat.  With prefix arg show the candidate."
  (interactive "P")
   (if arg
       (function mw-message-last-command)
     (function mw-repeat-last-command))))

 (kbd "C-6")

(define-key global-map (kbd "<f9>")
  (lambda (&optional prefix)
    "Try insert org-inactive-timestamp.  With prefix argument
  try insert yyyymmddhhmm.  Special in org-agenda: toggle
    (interactive "P")
     ((eq major-mode 'org-agenda-mode)
      (setq org-agenda-include-inactive-timestamps (eq nil org-agenda-include-inactive-timestamps))
       ((equal '(16) prefix)
        (insert (format-time-string "%Y%m%d%H%M")))
       ((equal '(4) prefix)
        (org-insert-time-stamp nil t t))
       (t (org-insert-time-stamp nil nil t)))
      (insert " ")))))

shortcuts to info

use M-x emacs-info and M-x elisp-info. the idea comes from org-info.

(defmacro shortcut-to-info-topic (info-topic)
  `(defun ,(intern (concat info-topic "-info")) (&optional node)
,(concat "Open info browser for topic '" info-topic "'.")
     (info (format ,(concat "(" info-topic ")%s" ) (or node "")))))

(shortcut-to-info-topic "emacs")
(shortcut-to-info-topic "elisp")

enable more emacs features

Enable features that are disabled by default.

Emacs writes these lines if the user decides to enable these features.

(put 'dired-find-alternate-file 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'erase-buffer 'disabled nil)
(put 'list-threads 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'scroll-left 'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'upcase-region 'disabled nil)

Emacs’ customize

Emacs allows to specify the storage-location of customization done via the emacs-customize interface. The default is to keep the customization in the init-file.

Take care about overrides due to customizations.


(setq custom-file "~/.emacs.d/init/.emacs-custom.el")
(load custom-file)

customize remember some possibilities

this section is to remember several customizations easily.

no menu bar


use dired targets in other buffers

Typical scenario: have two dired buffers open.

  • one containing the file you want to copy with point on it.
  • the other showing the target directory.

then use key C to copy the file into the target directory.


dired listing switches

Often I don’t want to see the . and .. pseudo directories in dired.

Setting dired-listing-switches to “-lA” does the trick.

“A” stands for “almost all”. I chose the “l” before the “A” option because I can then remove the “A” with a simple backspace without first moving the cursor.

Hint: change the value of dired-listing-switches dynamically from within a dired by C-u s.

various after Emacs’ customize

separate sunrise/sunset for calendar

variables calendar-latitude, calendar-longitude can be configured via customize.

diary uses the functions here like


provide a string with the sunset

Function: solar-sunrise-sunset-string
(defun solar-sunrise-string (date &optional nolocation)
  "String of *local* times of sunrise and daylight on Gregorian DATE.
Optional NOLOCATION non-nil means do not print the location."
  (let ((l (solar-sunrise-sunset date)))
     "%s%s (%s hrs daylight)"
     (if (car l)
         (concat "Sunrise " (apply 'solar-time-string (car l)))
       "No sunrise")
     (if nolocation ""
       (format " at %s" (eval calendar-location-name)))
     (nth 2 l))))

(defun solar-sunset-string (date &optional nolocation)
  "String of *local* times of sunset, and daylight on Gregorian DATE.
Optional NOLOCATION non-nil means do not print the location."
  (let ((l (solar-sunrise-sunset date)))
     "%s%s (%s hrs daylight)"
     (if (cadr l)
         (concat "Sunset " (apply 'solar-time-string (cadr l)))
       "no sunset")
     (if nolocation ""
       (format " at %s" (eval calendar-location-name)))
     (nth 2 l))))

create a calendar function

this section originated from

Function: diary-sunrise-sunset
(require 'solar)

(defun diary-sunrise ()
  "Local time of sunset as a diary entry.
Accurate to a few seconds.

Depends on variable `date'."
  (or (and calendar-latitude calendar-longitude calendar-time-zone)
  (solar-sunrise-string date))

(defun diary-sunset ()
  "Local time of sunset as a diary entry.
Accurate to a few seconds.

Depends on variable `date'."
  (or (and calendar-latitude calendar-longitude calendar-time-zone)
  (solar-sunset-string date))

Direct call like so:

(let ((date (calendar-current-date)))


This is the location for patches.

Remove the patches when the issue has gone.

C-c C-k before first heading

add: behave like the whole file is one subtree.


(defun org-kill-note-or-show-branches ()
  "Abort storing current note, or show just branches."
  (if org-finish-function
      (let ((org-note-abort t))
        (funcall org-finish-function))
      (if (org-before-first-heading-p)
            (unless (save-excursion
                      (goto-char (point-max))
              (while (outline-get-next-sibling)

C-c tab more predictable

want C-c tab to show just headlines in any case.

in particular

when invoked on a subtree that shows something that is not headline.

when before the first headline.

behave like the whole file is one subtree


(eval-after-load "org"
  '(defun org-ctrl-c-tab (&optional arg)
     "Toggle columns width in a table, or show direct children.
Call `org-table-toggle-column-width' if point is in a table.
Otherwise, call `org-show-children'.  ARG is the level to hide."
     (interactive "p")
     (if (org-at-table-p)
         (call-interactively #'org-table-toggle-column-width)
       (if (org-before-first-heading-p)
             (when (save-excursion (outline-next-heading))
               (outline-hide-sublevels (or arg 1))))
         (call-interactively #'org-show-children)))))

calendar goto date alternative

type month numerically.

(defun mw-calendar-goto-date (date &optional noecho)
  "Move cursor to Julian DATE; echo Julian date unless NOECHO is non-nil."
   (let* ((today (calendar-current-date))
          (year (calendar-read
                 "Julian calendar year (>0): "
                 (lambda (x) (> x 0))
          (month (calendar-read
                 "Julian calendar month: "
                 (lambda (x) (and (<= 1 x) (<= x 12)))
           (if (and (zerop (% year 4)) (= month 2))
             (aref [31 28 31 30 31 30 31 31 30 31 30 31] (1- month))))
          (day (calendar-read
                (format "Julian calendar day (%d-%d): "
                        (if (and (= year 1) (= month 1)) 3 1) last)
                (lambda (x)
                  (and (< (if (and (= year 1) (= month 1)) 2 0) x)
                       (<= x last))))))
     (list (list month day year))))
  (calendar-goto-date date)
  (or noecho (calendar-julian-print-date)))

switch to included diaries

The switch from org-agenda to an entry of an included diary file fails if the respective diary buffer is not available. BTW fancy diary does not have this problem since it uses a button for the switch. The agenda just keeps a marker.

Fix by loading all included diary files.

(defun mw-find-included-diary-files ()
  (mapc (lambda (x) (find-file-noselect x t))
(add-hook 'org-agenda-cleanup-fancy-diary-hook #'mw-find-included-diary-files)

use older org-auto-repeat-maybe

use the older due to low performance of the new version for several tasks. I guess long logbooks are an issue.

(defun org-auto-repeat-maybe (done-word)
  "Check if the current headline contains a repeated time-stamp.

If yes, set TODO state back to what it was and change the base date
of repeating deadline/scheduled time stamps to new date.

This function is run automatically after each state change to a DONE state."
  (let* ((repeat (org-get-repeat))
	 (aa (assoc org-last-state org-todo-kwd-alist))
	 (interpret (nth 1 aa))
	 (head (nth 2 aa))
	 (whata '(("h" . hour) ("d" . day) ("m" . month) ("y" . year)))
	 (msg "Entry repeats: ")
	 (org-log-done nil)
	 (org-todo-log-states nil)
	 (end (copy-marker (org-entry-end-position))))
	(when (and repeat (not (zerop (string-to-number (substring repeat 1)))))
	  (when (eq org-log-repeat t) (setq org-log-repeat 'state))
	  (let ((to-state (or (org-entry-get nil "REPEAT_TO_STATE" 'selective)
			      (and (stringp org-todo-repeat-to-state)
			      (and org-todo-repeat-to-state org-last-state))))
	    (org-todo (cond
		       ((and to-state (member to-state org-todo-keywords-1))
		       ((eq interpret 'type) org-last-state)
		       (t 'none))))
	  (org-back-to-heading t)
	  (org-add-planning-info nil nil 'closed)
	  ;; When `org-log-repeat' is non-nil or entry contains
	  ;; a clock, set LAST_REPEAT property.
	  (when (or org-log-repeat
		    (catch :clock
			(while (re-search-forward org-clock-line-re end t)
			  (when (org-at-clock-log-p) (throw :clock t))))))
	    (org-entry-put nil "LAST_REPEAT" (format-time-string
					      (org-time-stamp-format t t)
	  (when org-log-repeat
	    (if (or (memq 'org-add-log-note (default-value 'post-command-hook))
		    (memq 'org-add-log-note post-command-hook))
		;; We are already setup for some record.
		(when (eq org-log-repeat 'note)
		  ;; Make sure we take a note, not only a time stamp.
		  (setq org-log-note-how 'note))
	      ;; Set up for taking a record.
	      (org-add-log-setup 'state
				 (or done-word (car org-done-keywords))
	  (let ((planning-re (regexp-opt
			      (list org-scheduled-string org-deadline-string))))
	    (while (re-search-forward org-ts-regexp end t)
	      (let* ((ts (match-string 0))
		     (planning? (org-at-planning-p))
		     (type (if (not planning?) "Plain:"
				planning-re (line-beginning-position) t)
			       (match-string 0)))))
		 ;; Ignore fake time-stamps (e.g., within comments).
		 ((not (org-at-timestamp-p 'agenda)))
		 ;; Time-stamps without a repeater are usually
		 ;; skipped.  However, a SCHEDULED time-stamp without
		 ;; one is removed, as they are no longer relevant.
		 ((not (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)"
		  (when (equal type org-scheduled-string)
		    (org-remove-timestamp-with-keyword type)))
		  (let ((n (string-to-number (match-string 2 ts)))
			(what (match-string 3 ts)))
		    (when (equal what "w") (setq n (* n 7) what "d"))
		    (when (and (equal what "h")
			       (not (string-match-p "[0-9]\\{1,2\\}:[0-9]\\{2\\}"
		       "Cannot repeat in Repeat in %d hour(s) because no hour \
has been set"
		    ;; Preparation, see if we need to modify the start
		    ;; date for the change.
		    (when (match-end 1)
		      (let ((time (save-match-data
				    (org-time-string-to-time ts))))
			 ((equal (match-string 1 ts) ".")
			  ;; Shift starting date to today
			   (- (org-today) (time-to-days time))
			 ((equal (match-string 1 ts) "+")
			  (let ((nshiftmax 10)
				(nshift 0))
			    (while (or (= nshift 0)
				       (not (time-less-p (current-time) time)))
			      (when (= (cl-incf nshift) nshiftmax)
				(or (y-or-n-p
				     (format "%d repeater intervals were not \
enough to shift date past today.  Continue? "
				    (user-error "Abort")))
			      (org-timestamp-change n (cdr (assoc what whata)))
			      (org-in-regexp org-ts-regexp3)
			      (setq ts (match-string 1))
			      (setq time
				      (org-time-string-to-time ts)))))
			  (org-timestamp-change (- n) (cdr (assoc what whata)))
			  ;; Rematch, so that we have everything in place
			  ;; for the real shift.
			  (org-in-regexp org-ts-regexp3)
			  (setq ts (match-string 1))
			  (string-match "\\([.+]\\)?\\(\\+[0-9]+\\)\\([hdwmy]\\)"
		      (org-timestamp-change n (cdr (assoc what whata)) nil t))
		    (setq msg
			   msg type " " org-last-changed-timestamp " "))))))))
	  (setq org-log-post-message msg)
	  (message "%s" msg))
      (set-marker end nil))))

zone for all windows

Slight change to zone to let all windows display buffer zone.

(eval-after-load "zone"
  '(defun zone ()
    "Zone out, completely.
All windows show *zone*."
      (let ((f (selected-frame))
            (outbuf (get-buffer-create "*zone*"))
            (text (buffer-substring (window-start) (window-end)))
            (wp (1+ (- (window-point)
        (let ((win-0 (selected-window)))
          (while (not (equal win-0 (progn
                                     (other-window 1 t)
            (switch-to-buffer "*zone*" )))
        (put 'zone 'orig-buffer (current-buffer))
        (switch-to-buffer outbuf)
        (setq mode-name "Zone")
        (setq buffer-undo-list t
              truncate-lines t
              tab-width (zone-orig tab-width)
              line-spacing (zone-orig line-spacing))
        (insert text)
        (untabify (point-min) (point-max))
        (set-window-start (selected-window) (point-min))
        (set-window-point (selected-window) wp)
        (sit-for 0 500)
        (let ((pgm (elt zone-programs (random (length zone-programs))))
              (ct (and f (frame-parameter f 'cursor-type)))
              (show-trailing-whitespace nil)
              (restore (list '(kill-buffer outbuf))))
          (when ct
            (modify-frame-parameters f '((cursor-type . (bar . 0))))
            (setq restore (cons '(modify-frame-parameters
                                  f (list (cons 'cursor-type ct)))
          ;; Make `restore' a self-disabling one-shot thunk.
          (setq restore `(lambda () ,@restore (setq restore nil)))
          (condition-case nil
                (message "Zoning... (%s)" pgm)
                ;; If some input is pending, zone says "sorry", which
                ;; isn't nice; this might happen e.g. when they invoke the
                ;; game by clicking the menu bar.  So discard any pending
                ;; input before zoning out.
                (if (input-pending-p)
                (zone-call pgm)
                (message "Zoning...sorry"))
             (funcall restore)
             (while (not (input-pending-p))
               (message "We were zoning when we wrote %s..." pgm)
               (sit-for 3)
               (message "'s hoping we didn't hose your buffer!")
               (sit-for 3)))
             (funcall restore)
             (message "Zoning...sorry")))
          (when restore (funcall restore)))))))



display time

(add-hook 'emacs-startup-hook #'display-time)

activate appointments


(appt-activate 1)

appointments can trigger something in emacs.

  • see also org-agenda-to-appt.
  • see also Personalize the sound of the bell for the configuration of the respective audio signal.



accoustic signal

Let Emacs say something at start.

;; (org-agenda-list)
;; (switch-to-buffer "*Org Agenda*")

;; Vision: Extend the following code to be like the computer in the
;; Heart of Gold.  E.g. be able to start a conversation like "Hey
;; Emacs, please make some tee!"
(start-process "play-a-sound" "*play-a-sound-output*"
               ;; "en-swedish"
               "155" ;; word speed
               "Hi guys! This is a fantastic day! Let's do something!")



Can never remember the original name of this fun. The alias is supposed to help me finding the command.

the command switches the representation of a message. there is the usual nice representation and also a raw representation.

(defalias 'mw-gnus-article-toggle-view #'gnus-summary-toggle-header)

check (edit-abbrevs) for abbrevs.

disabled stuff

resurrect any of these as needed.

disabled packages


chronos allows to conveniently set timers and say a text when the timer is done.

(defvar *mw-timer* nil "For recall a timer for later kill.")
(use-package chronos
  :ensure t
  :config (setf chronos-text-to-speech-program "espeak"
                ;; chronos-text-to-speech-program-parameters
                chronos-text-to-speech-program-parameters  '("-v" "de" "-s" "110")
                  (lambda (c)
                    ;; (browse-url-firefox
                    ;; ""
                    ;;  )
                    (unless *mw-timer*
                      (setq *mw-timer*
                        3 3
                        (lambda () (mw-espeak-de-string "aufwachen, bitte!"))))
                      (run-at-time 10 nil (lambda ()
                                            (cancel-timer *mw-timer*)
                                            (setq *mw-timer* nil))))))))


use-package allows convenient emacs package configuration.

(straight-use-package 'use-package)

i guess use-package now uses straight.

TODO check use-package effect

does `use-package’ use straight rather than `package’ now?

there seems to be “[`straight.el`’s `use-package` integration][use-package-integration].” see documentation of straight.


experimenting with multiple major modes (mmm) for literate programming.

(use-package mmm-mode
  :ensure t
    (setq mmm-global-mode 'maybe)
        :submode emacs-lisp-mode
        :face mmm-declaration-submode-face
        :front "#\\+begin_src emacs-lisp.*"
        :front-offset (end-of-line 1)
        :back "#\\+end_src")))))
  • [2018-03-15 Thu 09:49] try use it for literate elisp programming with Org mode.
  • [2018-03-15 Thu 10:25] activate mmm-mode to edit emacs-lisp snippets conveniently:
    • in org file M-x mmm-mode-on.
    • C-c % C-c emacs-lisp-mode


(straight-use-package 'camcorder)
(setf camcorder-output-directory "~/0_in/camcorder/")


(use-package hungry-delete
  :ensure t)


(use-package slime-company
 :ensure t)


(use-package elm-mode :ensure t)
elm-mode from local clone
;; (add-to-list 'load-path "~/p/elisp/external/elm-mode")
;; (require 'elm-mode)


(use-package interleave
  :ensure t)
From the doc
  • Create a Org file that will keep your notes. In the Org headers section, add
    “#+INTERLEAVE_PDF: /the/path/to/your/pdf.pdf”
  • Start `interleave’ with `M-x interleave’.
  • To insert a note for a page, type `i’.
  • Navigation is the same as in `doc-view-mode’/`pdf-view-mode’.”


Quickly follow links in certain modes e.g. info-mode.

(use-package ace-link
  :ensure t
  :config (ace-link-setup-default))
check for integration with ert and more

[2016-05-03 Tue 09:01] Read about this on the project page.


(use-package swiper
  :ensure t
  :bind ("C-S-s" . swiper))


From the documentation at

…use keyfreq-show to see how many times you used a command.

(straight-use-package 'keyfreq)
(keyfreq-mode 1)
(keyfreq-autosave-mode 1)


[2016-11-03 Thu 10:50] i suspect this to interfer with the gnus-gmail connection.

auth-stuff -> pass(word-store)

;; (use-package auth-password-store
;;   :ensure t
;;   :config (auth-pass-enable))


A replacement of zap-to-char.

(use-package avy-zap
  :ensure t
  :bind (("M-z" . avy-zap-to-char-dwim)
         ("M-Z" . avy-zap-up-to-char-dwim)))


Adds a visual symbol about the previous page after scrolling a page. This might help sometimes. Try together with rope-read.

(use-package on-screen
  :ensure t
  :config (global-on-screen-mode))


Activate any time with M-x browse-kill-ring or with M-y but the latter only if not immediately after yank.

(use-package browse-kill-ring
  :ensure t
  :config (browse-kill-ring-default-keybindings)) ; M-y


(use-package lispy
  :ensure t
  ;; :config
  ;; (define-key lispy-mode-map-lispy (kbd "]") nil)
  ;; (define-key lispy-mode-map-lispy (kbd "[") nil)

 (lambda ()
   (key-chord-define-local "[0" (lambda () (interactive) (insert "[")))
   (key-chord-define-local "]1" (lambda () (interactive) (insert "]")))))


[2016-01-08 Fri 14:49] At first I thought smartparens-mode will replace paredit for me. But somehow I always come back to paredit.

(use-package smartparens
  :ensure t
  :config (turn-on-smartparens-mode))


gnorb is integration of gnus and org and bbdb .

(use-package gnorb
  :ensure t)

(require 'gnorb)
(require 'gnorb-org)
(require 'gnorb-gnus)

(eval-after-load "gnorb-bbdb"
     (define-key bbdb-mode-map (kbd "O") 'gnorb-bbdb-tag-agenda)
     (define-key bbdb-mode-map (kbd "S") 'gnorb-bbdb-mail-search)
     (define-key bbdb-mode-map [remap bbdb-mail] 'gnorb-bbdb-mail)
     (define-key bbdb-mode-map (kbd "l") 'gnorb-bbdb-open-link)
     (global-set-key (kbd "C-c C") 'gnorb-bbdb-cite-contact)))

(eval-after-load ;; "gnorb-org"
     (org-defkey org-mode-map (kbd "C-c C") 'gnorb-org-contact-link)
     (org-defkey org-mode-map (kbd "C-c m") 'gnorb-org-handle-mail)
     (org-defkey org-mode-map (kbd "C-c e") 'gnorb-org-view)
     (org-defkey org-mode-map (kbd "C-c E") 'gnorb-org-email-subtree)
     (org-defkey org-mode-map (kbd "C-c V") 'gnorb-org-popup-bbdb)
     (setq gnorb-org-agenda-popup-bbdb t)
     (eval-after-load "org-agenda"
       '(progn ;; (org-defkey org-agenda-mode-map (kbd "C-c t") 'gnorb-org-handle-mail)
          (org-defkey org-agenda-mode-map (kbd "C-c v") 'gnorb-org-popup-bbdb)
          (org-defkey org-agenda-mode-map (kbd "V") 'gnorb-org-view)))))

(eval-after-load "gnorb-gnus"
     (define-key gnus-summary-mime-map "a" 'gnorb-gnus-article-org-attach)
     (define-key gnus-summary-mode-map (kbd "C-c t") 'gnorb-gnus-incoming-do-todo)
     (define-key gnus-summary-mode-map (kbd "C-c e") 'gnorb-gnus-view)
                                        ; this is 'e' because of the
                                        ; respective binding for
                                        ; org-view suggested in the
                                        ; docu [2015-05-28 Thu 08:54].
     (push '("attach to org heading" . gnorb-gnus-mime-org-attach)
     ;; The only way to add mime button command keys is by redefining
     ;; gnus-mime-button-map, possibly not ideal. Ideal would be a
     ;; setter function in gnus itself.
     (push '(gnorb-gnus-mime-org-attach "a" "Attach to Org heading")
     (setq gnus-mime-button-map
           (let ((map (make-sparse-keymap)))
             ;; (define-key map gnus-mouse-2 'gnus-article-push-button)
             ;; (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
             (dolist (c gnus-mime-button-commands)
               (define-key map (cadr c) (car c)))

(eval-after-load "message"
     (define-key message-mode-map (kbd "C-c t") 'gnorb-gnus-outgoing-do-todo)))


rase is for triggering actions at sunrise and sunset.

Reversing the colors of Emacs at sunrise and at sunset.

(defun hook-for-rase-sun-event-theme-switch (sun-event &optional first-run)
   (first-run (let ((solar-rise-set  (solar-sunrise-sunset (calendar-current-date)))
                    (time-of-day (mw-current-time-of-day-decimal)))
                ;; ((7.749999999068677 "CET") (17.5166666675359 "CET") "9:46")
                (if (or (< time-of-day (caar solar-rise-set))
                        (<= (caadr solar-rise-set) time-of-day))
   ((eq sun-event 'sunrise) (mw-unset-night-theme))
   ((eq sun-event 'sunset) (mw-set-night-theme))))

(use-package rase
  :ensure t
  (run-at-time "20 sec" nil (lambda () (rase-start t))) ;; Pragmatic, not nice.
  ;; (rase-start t) ;; This line is not enough to change the theme.


Actually i don’t use helm consciously. [2015-06-27 Sat 10:57]

(use-package helm
  :ensure t)

[2016-04-29 Fri 14:31] I do use helm-emms to switch on bassdrive.


The following lines go back to a recommendation of an arch linux install.

(use-package gnuplot
  :ensure t
  :config (progn
            (autoload 'gnuplot-mode "gnuplot" "gnuplot major mode" t)
            (autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot mode" t)
            (setq auto-mode-alist (append '(("\\.gp$" . gnuplot-mode)) auto-mode-alist))))


Helpful for jumping around!

(use-package sotlisp
  :ensure t)


(use-package nyan-mode
  :ensure t
  :config (nyan-mode))


(use-package git-auto-commit-mode
  :ensure t
  :config (git-auto-commit-mode t))


(require 'epa
         :ensure t)
(define-key epa-key-list-mode-map "N" #'mw-epa-mark-next-key)


(use-package beacon
  :ensure t
  :defer 1 ; else can't start as daemon like /home/b/p/emacs-build/lib-src/emacsclient -c -n -a \"\"
  :config (beacon-mode 1))


I can only remember that I liked the name and the idea of this package.

(use-package elmacro
  :ensure t)
what is elmacro?


(use-package git-timemachine
  :ensure t)

Start git-timemachine on a file to travel time on it.


Package for editing lists.

(add-to-list 'load-path "~/p/elisp/external/refine")
(require 'refine)


use a fork which does not redefine if-let. I observed the issue when tried the auto-correct package.

 '(j-mode :type git :host github :repo "zlrth/j-mode"
            :upstream (:host github
                       :repo "zellio/j-mode")))


check out wcheck! ([2018-07-13])

(use-package wcheck-mode)

rest packages

(use-package ace-flyspell
  :ensure t)
(use-package ace-isearch
  :ensure t)
(use-package ace-jump-buffer
  :ensure t)
(use-package ace-jump-mode
  :ensure t)
(use-package all
  :ensure t)
(use-package anaconda-mode
  :ensure t)
(use-package ansi
  :ensure t)
(use-package apu
  :ensure t)
(use-package arduino-mode
  :ensure t)
(use-package ascii-art-to-unicode
  :ensure t)
(use-package auto-complete
  :ensure t)
(use-package babel
  :ensure t)
(use-package biblio
  :ensure t)
(use-package biblio-core
  :ensure t)
(use-package boxquote
  :ensure t)
(use-package calfw
  :ensure t)
(use-package caps-lock
  :ensure t)
(use-package cask-mode
  :ensure t)
(use-package cider
  :ensure t)
(use-package cl-generic
  :ensure t)
(use-package clojure-mode
  :ensure t)
(use-package closql
  :ensure t)
(use-package command-log-mode
  :ensure t)
(use-package commander
  :ensure t)
(use-package company-anaconda
  :ensure t)
(use-package company-emoji
  :ensure t)
(use-package company-web
  :ensure t)
(use-package concurrent
  :ensure t)
(use-package conkeror-minor-mode
  :ensure t)
(use-package connection
  :ensure t)
(use-package counsel
  :ensure t)
(use-package counsel-projectile
  :ensure t)
(use-package csv-mode
  :ensure t)
(use-package darkroom
  :ensure t)
(use-package dash-functional
  :ensure t)
(use-package deferred
  :ensure t)
(use-package dired-collapse
  :ensure t)
(use-package dired-filter
  :ensure t)
(use-package dired-quick-sort
  :ensure t)
(use-package discover
  :ensure t)
(use-package downplay-mode
  :ensure t)
(use-package ebib
  :ensure t)
(use-package ecukes
  :ensure t)
(use-package eimp
  :ensure t)
(use-package ein
  :ensure t)
(use-package el-mock
  :ensure t)
(use-package el-search
  :ensure t
  :config ; (el-search-install-bindings-under-prefix [(meta ?s) ?e])
(use-package elisp-refs
  :ensure t)
(use-package emacsql
  :ensure t)
(use-package emacsql-sqlite
  :ensure t)
(use-package epkg
  :ensure t)
(use-package epoch-view
  :ensure t)
(use-package espuds
  :ensure t)
(use-package esxml
  :ensure t)
(use-package eww-lnum
  :ensure t)
(use-package exwm
  :ensure t)
(use-package fabric
  :ensure t)
(use-package fliptext
  :ensure t)
(use-package flycheck
  :ensure t)
(use-package flycheck-elm
  :ensure t)
(use-package flycheck-package
  :ensure t)
(use-package flylisp
  :ensure t)
(use-package flyspell-lazy
  :ensure t)
(use-package focus
  :ensure t)
(use-package fsm
  :ensure t)
(use-package ggtags
  :ensure t)
(use-package git-auto-commit-mode
  :ensure t)
(use-package git-messenger
  :ensure t)
(use-package gnu-apl-mode
  :ensure t)
(use-package goto-chg
  :ensure t)
(use-package goto-last-change
  :ensure t)
(use-package gscholar-bibtex
  :ensure t)
(use-package haskell-emacs
  :ensure t)
(use-package helm-unicode
  :ensure t)
(use-package helpful
  :ensure t)
(use-package hide-region
  :ensure t)
(use-package hledger-mode
  :ensure t)
(use-package html5-schema
  :ensure t)
(use-package htmlize
  :ensure t)
(use-package indium
  :ensure t)
(use-package io-mode
  :ensure t)
(use-package io-mode-inf
  :ensure t)
(use-package ivy-hydra
  :ensure t)
(use-package js2-mode
  :ensure t)
(use-package js2-refactor
  :ensure t)
(use-package julia-mode
  :ensure t)
(use-package julia-shell
  :ensure t)
(use-package let-alist
  :ensure t)
(use-package lfe-mode
  :ensure t)
(use-package lib-requires
  :ensure t)
(use-package link
  :ensure t)
(use-package linum-relative
  :ensure t)
(use-package loop
  :ensure t)
(use-package lyrics
  :ensure t)
(use-package makey
  :ensure t)
(use-package markdown-mode
  :ensure t)
(use-package message-x
  :ensure t)
(use-package mmt
  :ensure t)
(use-package mode-line-in-header
  :ensure t)
(use-package move-text
  :ensure t)
(use-package multiple-cursors
  :ensure t)
(use-package multishell
  :ensure t)
(use-package names
  :ensure t)
(use-package navi-mode
  :ensure t)
(use-package nginx-mode
  :ensure t)
(use-package noccur
  :ensure t)
(use-package org-attach-screenshot
  :ensure t)
(use-package org-board
  :ensure t)
(use-package outorg
  :ensure t)
(use-package outshine
  :ensure t)
(use-package ov
  :ensure t)
(use-package package-build
  :ensure t)
(use-package package-lint
  :ensure t)
(use-package parsebib
  :ensure t)
(use-package pass
  :ensure t)
(use-package password-store-otp
  :ensure t)
(use-package pcre2el
  :ensure t)
(use-package php-mode
  :ensure t)
(use-package pomodoro
  :ensure t)
(use-package ponylang-mode
  :ensure t)
(use-package pretty-mode
  :ensure t)
(use-package psgml
  :ensure t)
(use-package pt
  :ensure t)
(use-package pythonic
  :ensure t)
(use-package quack
  :ensure t)
(use-package queue
  :ensure t)
(use-package rainbow-delimiters
  :ensure t)
(use-package rectangle-utils
  :ensure t)
(use-package request
  :ensure t)
(use-package request-deferred
  :ensure t)
(use-package restclient
  :ensure t)
(use-package rudel
  :ensure t)
(use-package rust-mode
  :ensure t)
(use-package screenshot
  :ensure t)
(use-package showkey
  :ensure t)
(use-package shut-up
  :ensure t)
(use-package sibilant-mode
  :ensure t)
(use-package sicp
  :ensure t)
(use-package simple-httpd
  :ensure t)
(use-package skewer-mode
  :ensure t)
(use-package soap-client
  :ensure t)
(use-package speed-type
  :ensure t)
(use-package spinner
  :ensure t)
(use-package ssh-tunnels
  :ensure t)
(use-package stream
  :ensure t)
(use-package suggest
  :ensure t)
(use-package sx
  :ensure t)
(use-package tablist
  :ensure t)
(use-package tldr
  :ensure t)
(use-package transmission
  :ensure t)
(use-package trr
  :ensure t)
(use-package twittering-mode
  :ensure t)
(use-package typing
  :ensure t)
(use-package typit
  :ensure t)
(use-package vdiff
  :ensure t)
(use-package visual-regexp
  :ensure t)
(use-package vlf
  :ensure t)
(use-package volume
  :ensure t)
(use-package web
  :ensure t)
(use-package web-completion-data
  :ensure t)
(use-package websocket
  :ensure t)
(use-package wgrep
  :ensure t)
(use-package xelb
  :ensure t)
(use-package xref-js2
  :ensure t)
(use-package yalinum
  :ensure t)
(use-package yaml-mode
  :ensure t)
(use-package zone-nyan
  :ensure t)


i had problems with straight and this package.

(use-package ert-runner
  :ensure t)


  • is a tracker for file access.
  • never was sure if this is something of value for me.
  • disabled because it consumes annoyingly much time afaict.
  • a zeitgeist demon needs to be up for zeitgeist to work.
(use-package zeitgeist
  :ensure t)


fancy-narrow is a mode worth looking into afaicsn. fancy-narrow came in unexpectedly in an error message at an ert test.

=> disabled.

(use-package fancy-narrow
  :ensure t)

x out text to obfuscate

the code is from rot13.


(defvar mw-allX-display-table
  (let ((table (make-display-table))
	(i 0))
    (while (< i 26)
      (aset table (+ i ?a) (vector ?x))
      (aset table (+ i ?A) (vector ?X))
      (setq i (1+ i)))
  "Char table to display chars as x and X.")

(defun mw-toggle-allX-mode ()
  "Toggle the use of x for all letters for the current window."
  (if (eq (window-display-table) mw-allX-display-table)
      (set-window-display-table (selected-window) nil)
    (if (null (window-display-table))
	(set-window-display-table (selected-window) mw-allX-display-table))))

company for noweb references

trying a suggestion from Nik.

From: Nik Clayton <> Subject: company-mode completions for noweb references Newsgroups: gmane.emacs.orgmode To: emacs-orgmode <> Date: Tue, 6 Nov 2018 19:32:20 +0100 Archived-At:

[1. text/plain] Hoi,

I’ve been writing a few things using Org where I’m making frequent use of noweb references in SRC blocks, and decided that completion would be handy for them.

This function will complete “^<<” with a list of the defined named blocks in the current file, if you’re in a SRC block.

It could be made smarter (e.g., only offer the completion if “:noweb yes” is set, only offer to complete from named blocks with the same language as the current block), but I thought I’d throw it out here in case anyone else finds it useful.

Best, N


(defun my/org-src-block-name-backend (command &optional arg &rest ignored)
  "Complete `<<' with the names of defined SRC blocks."
  (interactive (list 'interactive))
  (cl-case command
    (interactive (company-begin-backend 'my/org-src-block-name-backend))
    (init (require 'org-element))
    (prefix (and (eq major-mode 'org-mode)
                 (eq 'src-block (car (org-element-at-point)))
                 (cons (company-grab-line "^<<\\(\\w*\\)" 1) t)))
     (org-element-map (org-element-parse-buffer) 'src-block
       (lambda (src-block)
         (let ((name (org-element-property :name src-block)))
           (when name
              :value (org-element-property :value src-block)
              :annotation (org-element-property :raw-value (org-element-lineage
                                                            src-block '(headline)))))))))
    (sorted t)            ; Show candidates in same order as doc
    (ignore-case t)
    (duplicates nil)               ; No need to remove duplicates
    (post-completion               ; Close the reference with ">>"
     (insert ">>"))
    ;; Show the contents of the block in a doc-buffer. If you have
    ;; company-quickhelp-mode enabled it will show in a popup
    (doc-buffer (company-doc-buffer (get-text-property 0 :value arg)))
    (annotation (format " [%s]" (get-text-property 0 :annotation arg)))))
restore this
;(add-to-list 'company-backends 'my/org-src-block-name-backend)


a project from Emacs berlin.

(push "~/p/elisp/external/syntactic-close" load-path)

skip over whitespace

keys to skip over whitespace.

 (kbd "C-S-f")
 (lambda ()
   (if (looking-at "[
       (skip-chars-forward "
     ;; using execute-kbd-macro because I can.
     (execute-kbd-macro (kbd "C-f")))))

 (kbd "C-S-b")
 (lambda ()
   (if (looking-back "[
 	]" (1- (point)))
       (skip-chars-backward "
     ;; using execute-kbd-macro because I can.
     (execute-kbd-macro (kbd "C-b")))))

enter edit timestamp

(defun mw-org-edit-timestamp ()
  "Edit the timestamp at point."
    (assert (org-at-timestamp-p 'lax) t "Not at a timestamp.")
      (let ((beg (match-beginning 0)))
        (goto-char beg)
        (if (looking-at-p org-ts-regexp-inactive)
          (org-time-stamp nil))))))

kill fap

(defun mw-filename-at-point-kill ()
  (if-let (fn (thing-at-point 'filename))
      (kill-new fn)))

joy with emacs

(push "~/p/elisp/mw/joy" load-path)
(require 'joy)

org agenda files stack

(defvar org-agenda-files-stack nil
  "Stack for agenda file sets.")

(defun org-agenda-files-set-and-push-recent (agenda-files)
  "Replace agenda-files and push recent for potential reset."
  (push org-agenda-files org-agenda-files-stack)
  (setq org-agenda-files agenda-files))

(defun org-agenda-files-pop-and-set ()
  "Pop item from stack and set as agenda-files else nop."
  (when org-agenda-files-stack
    (setq org-agenda-files (pop org-agenda-files-stack))))

org link edit

(require 'org-link-edit)

marked files to kill ring

(defun mw-dired-marked-paths-to-kill-ring ()
  "Marked files to kill-ring."
  (kill-new (mapconcat #'identity

execute key-sequence asynchronously

from T.V.Raman.

(defun emacspeak-wizards-execute-asynchronously (key)
  "Read key-sequence, then execute its command on a new thread."
  (interactive (list (read-key-sequence "Key Sequence: ")))
  (let ((l (local-key-binding key))
        (g (global-key-binding key)))
     ((commandp l)
      (make-thread l)
      (message "Running %s on a new thread." l))
     ((commandp g)
      (make-thread g)
      (message "Running %s on a new thread." g))
     (t (error "%s is not bound to a command." key)))))

display a calendar for a certain diary file

display a calendar for a certain diary file. this is meant for seeing the marks just for that diary file in the calendar.

diary-view-other-diary-entries is the basis for the following function.

(defun mw-diary-view-other-calendar (arg dfile)
  "Open calendar for another diary file.
DFILE specifies the file to use as the diary file."
   (list (prefix-numeric-value current-prefix-arg)
         (read-file-name "Enter diary file name: " default-directory nil t)))
  (let ((diary-file dfile))

insert a zero width space

this can be used to trick parsers sometimes.

in org you can place a zero width space between two brackets to prevent something be interpreted as link.


[[foo]] vs. [​[foo]].
(defun mw-insert-zero-width-space ()
  "Insert a space with zero width."
  (insert ?\x200B))


parse csv.

(push "~/p/elisp/external/el-csv" load-path)
(require 'parse-csv)

try table.el

(add-hook 'text-mode-hook 'table-recognize)

e.g. create tables like

|two fotos with mobile cam:                                             |
|tiff                                                                   |
|66939 |8cfc744faf258563fc685744a6abce75006035a5.201806171401-scan.TIF  |
|pdf                                                                    |
|71937 |c1ddb87abcb798ed7675243302b83da389b817de.201806171401-scan.PDF  |

switch diary

switch diary file. this can be useful for display the right ammount of entries marked.

(defun mw-diary-switch (file)
     "choose diary-file: "
  (setq diary-file file))

make personal diary entry

(defun mw-diary-make-personal-entry-for-today (&optional nonmarking)
  "Insert entry in personal diary file."
   (format-time-string "%Y-%m-%d")
   nonmarking "~/org/diary.d/diary-personal"))

text search via org also in archive

(setq org-agenda-text-search-extra-files '(agenda-archives))

start gnus in thread

When starting gnus in a thread emacs remains responsive.

(defun thread-call-gnus ()
"Call gnus in a thread.
This keeps emacs responsive."
  (make-thread #'gnus))

magit open diff in other window

(defun mw-magit-diff-visit-file-other-window ()
"`magit-diff-visit-file' but keep cursor in magit window."
  (let ((buffer (current-buffer)))
   (let ((current-prefix-arg '(4)))
     (call-interactively #'magit-diff-visit-file))
   (switch-to-buffer-other-window buffer)))

(define-key magit-file-section-map (kbd "C-o") #'mw-magit-diff-visit-file-other-window)

auto-hscroll-mode current-line

saw this option btw comming with emacs 26.1.

(setq  auto-hscroll-mode 'current-line)


mark inner of drawer

(defun mw-org-inside-drawer-p ()
  "Answer if point is inside an org drawer."
  (let ((element (org-element-at-point)))
  (catch 'found
      (while  element
        (when (and (eq 'drawer (car element))
                   (throw 'found 'found)))
        (setq element (plist-get (cadr element) :parent))))))

(defun mw-org-mark-drawer-content ()
  "Mark drawer without the delimitter lines."
  (let ((element (org-element-at-point)))
    (unless (catch 'found
       (while  element
         (when (member (car element) '(drawer property-drawer))
           (push-mark (org-element-property :contents-end element) t t)
	   (goto-char (org-element-property :contents-begin element))
           (throw 'found 'found))
         (setq element (plist-get (cadr element) :parent))))
      (message "Not in a drawer"))))

(defalias 'mw-org-drawer-mark-content 'mw-org-mark-drawer-content)

delete inner of drawers

(defun mw-org-drawer-delete-content ()
  "Delete the content of a drawer."
  (let ((element (org-element-at-point)))
    (unless (catch 'found
              (while  element
                (when (member (car element) '(drawer property-drawer))
                  (when-let ((start (org-element-property :contents-begin element))
                             (end (org-element-property :contents-end element)))
                    (delete-region start end))
                  (throw 'found 'found))
                (setq element (plist-get (cadr element) :parent))))
      (message "Not in a drawer"))))

count visual lines in region

(defun mw-count-visual-lines-in-region (start end)
  "Count visual lines in region.
  Recommendation: Put START and END to beginning of line each."
  (interactive "r")
  (when (region-active-p)
      (let ((stopper (min
                        (move-to-window-line -1)
            (ctr 0))
        (goto-char start)
        (while (< (point) stopper)
          (end-of-visual-line 2)
          (incf ctr))
        (message "%d" ctr)
(defalias 'mw-region-count-visual-lines #'mw-count-visual-lines-in-region)


(defun mw-narrow-to-line ()
"Narrow to line containing point."
   (progn (beginning-of-line) (point))
   (progn (end-of-line) (point)))))
(define-key narrow-map "l" #'mw-narrow-to-line)

*** - narrow-to-below

(defun mw-narrow-to-below (arg)
  "Narrow to half below or before (with ARG) the cursor."
  (interactive "P")
  (narrow-to-region (point) (if arg (point-min) (point-max))))
(define-key narrow-map "l" #'mw-narrow-to-line)

*** - agenda blocks as pages

see (info “(org) Block agenda”) for “agenda blocks”.

(setq org-agenda-block-separator "")

block indent org blocks

(defun mw-org-whitespace-prefix-blocks ()
  (let ((data (org-element-parse-buffer)))
    (org-element-map data '(src-block example-block verbatim-block verse-block)
      (lambda (ele)
           (goto-char (org-element-property :begin ele))
           (beginning-of-line 2)
           (goto-char (org-element-property :end ele))
           (end-of-line -1)
         'line-prefix "\t")))))
(defun mw-org-whitespace-unprefix-blocks ()
  (let ((data (org-element-parse-buffer)))
    (org-element-map data '(src-block example-block verbatim-block verse-block)
      (lambda (ele)
           (goto-char (org-element-property :begin ele))
           (beginning-of-line 2)
           (goto-char (org-element-property :end ele))
           (end-of-line -1)

reverse org subtrees

(push "~/p/elisp/mw/org-reverse-subtrees" load-path)
(require 'org-reverse-subtrees)


(push "~/p/elisp/mw/--rest/little-code-things/" load-path)
(require 'little-code-things)

hide all drawers per command

the functionality is already there but not the command.

(defun mw-org-hide-drawers () (interactive)
(org-cycle-hide-drawers 'all))

(defalias 'mw-org-drawers-hide #'mw-org-hide-drawers)

M-x on symbol at point

(defun mw-command-execute-at-point ()
  "M-x the symbol at point."
  (if-let ((text (thing-at-point 'symbol)))
      (command-execute (intern text))))

try develop execution with arguments

  • idea:

(execute-kbd-macro (vconcat [?\M-x] “replace-regexp” [return] “fa3d101c53b5fb94-uniquefoo” [return] “65df5e087813de63”))


(execute-kbd-macro [ ?\M-x ?d ?e ?b ?b ?u ?g ?s ?- ?g ?n ?u ?- ?s ?e ?a ?r ?c ?h return ?b ?u ?g ?# ?2 ?8 ?9 ?0 ?9 ])


(push "~/p/elisp/mw/quit-emacs" load-path)
(require 'quit-emacs)

timezone conversion to current tz

(push "~/p/elisp/mw/tz-conversion/" load-path)
(require 'tz-conversion)


(tzc-convert-utc-to-current-tz "16:00")


play with this. unclear if this is something.

use also indent-region.

(push "~/p/elisp/mw/hide-common-indent/" load-path)
(require 'hide-common-indent)

insert random hex

(defun convert-0-15-to-hex (in)
  (let ((table
         '(0 ?0 1 ?1 2 ?2 3 ?3 4 ?4 5 ?5 6 ?6 7 ?7 8 ?8 9 ?9
             10 ?a 11 ?b 12 ?c 13 ?d 14 ?e 15 ?f)))
    (plist-get table in)))

(defun mw-insert-random-hex (&optional length)
  (interactive "P")
  (unless length
    (setq length 16))
  (cl-do ((spot 0 (incf spot))) ((= length spot))
    (insert (convert-0-15-to-hex (random 16)))))

display live keystrokes in emacs

(add-to-list 'load-path "~/p/elisp/mw/keystrokes/")
(require 'keystrokes)

make xref-find-references act more locally

Cyclopedia Square: Fixing xref-find-references


(define-key global-map [remap xref-find-references] 'ag-project)

And actually, to work completely like xref-find-references I added one option to the ag command, --word-regexp, like so (oh, I also removed --stats which is there by default in ag.el):

(setq ag-arguments (list "--word-regexp" "--smart-case"))

prefix filename with hash in dired

  • hint: better write a shell script to do the job?
(defun mw-dired-prefix-file-with-its-sha1 ()
  "Prefix file with sha1 sum."
  (let* ((filename (dired-get-filename))
             (file-name-nondirectory filename))
            (sit-for 0.01) ; wait for the buffer to be filled with the
                           ; result.
            (goto-char (point-min))
            (delete-region (point) (point-max))
            (goto-char (point-min))
            (replace-regexp " " "-")
     (concat (file-name-directory filename) new-name) nil))


tool to stack major modes.

(add-to-list 'load-path "~/p/elisp/mw/major-mode-stack")
(require 'major-mode-stack)

org file to subtree

(defun mw-org-copy-buffer-as-subtree ()
  "Copy buffer as subtree."
  (let ((current-buf (current-buffer)))
      (insert-buffer-substring current-buf)
      (goto-char (point-min))
      (unless (outline-on-heading-p)
      (goto-char (point-min))
      (org-insert-heading nil nil t)
      (insert "BUFFERASORGSUBTREE\n")
      (beginning-of-line 0)
      (if (< (point-min) (point))
          (delete-region (point-min) (point)))
      (while (outline-get-next-sibling)
        (goto-char (point-min)))
      (goto-char (point-min))

koma letter

(eval-after-load 'ox-koma-letter
     (add-to-list 'org-latex-classes
     (setq org-koma-letter-default-class "mw-letter-private")))

calc-eval for region

(defun mw-region-replace-with-calc-eval (start end)
  "Apply `calc-eval' to region and replace with result."
  (interactive "r")
   (let ((result (calc-eval (buffer-substring start end))))
     (delete-region start end)

remove logbook drawer

(defun mw-org-log-delete ()
  "Delete logbook drawer of subtree."
    (goto-char (org-log-beginning))
    (when (save-excursion
              (beginning-of-line 0)
              (search-forward-regexp org-drawer-regexp)
              (goto-char (match-beginning 1))
              (looking-at "LOGBOOK")))
      (delete-region (region-beginning) (region-end))
      (org-remove-empty-drawer-at (point)))))

goto outermost list

(defun mw-backward-up-list-as-far-as-possible ()
  "Place point on the outermost list at its beginning."
  (condition-case nil
      (while t
    (error nil)))

(defun mw-forward-up-list-as-far-as-possible ()
  "Place point on the outermost list at its end."

(defun mw-eval-outermost-sexp ()
  "Evaluate the outermost sexp starting from point."
  (call-interactively #'eval-last-sexp))

emms toggle on/off

(defun emms-on-or-off ()
  "Toggle start/stop emms."
  (if emms-player-playing-p
      (emms-stop) (emms-start)))

expand <n to “name”

;; (require 'org-tempo)
;; (eval-after-load "org-tempo"
;; (progn
;; (setq org-tempo-keywords-alist '((110 . "name") (76 . "latex") (72 . "html") (65 . "ascii") (105 . "index")))
;  (push '(?n . "name") org-tempo-keywords-alist)
;  (org-tempo-add-templates)))
(eval-after-load 'org-tempo
     (push (cons "n" "name") org-tempo-keywords-alist)))

hide dot files in dired

(defun mw-dired-hide-dot-files ()
  "Hide the files starting with a dot in dired."
  (unless (eq 'dired-mode major-mode)
      "Buffer is not in dired-mode.  "
      "Command applies only in dired-mode")))
    (dired-mark-files-regexp "^\\.")

copy just headlines

little lib to copy just the headlines of a subtree.

(add-to-list 'load-path "~/p/elisp/mw/lab/org-copy-headlines-only")
(require 'org-copy-headlines-only)

open org-links in region

DO improve the arrangement of the windows.

(defun mw-org-open-links-in-region ()
  (when (region-active-p)
    (if (< (mark) (point))
    (let ((link-found-in-range
           (and (not org-link-search-failed)
                (< (point) (mark)))))
      (while (and (not org-link-search-failed)
                  (< (point) (mark)))
        (call-interactively #'other-window)
      (if link-found-in-range

(defalias 'mw-org-region-open-links 'mw-org-open-links-in-region)

espeak with typing

espeak the words when typing.

this is highly experimental.

(defun mw-espeak-previous-word ()
  (let ((async-shell-command-buffer 'new-buffer))
     (format "espeak -v de -s 110 \"%s\""

(defun mw-espeak-previous-word-at-certain-input ()
  "Speak word before point.
Consider setting async-shell-command-buffer to 'new-buffer."
  (let* ((key (this-single-command-keys)))
    (unless (equal [] key)
      (let* ((event (if (and (symbolp (aref key 0))
                             (> (length key) 1)
                             (consp (aref key 1)))
                        (aref key 1)
                      (aref key 0)))))
      (when (equal [32] key)
;(add-hook 'pre-command-hook 'mw-espeak-previous-word-at-certain-input)
;(remove-hook 'pre-command-hook 'mw-espeak-previous-word-at-certain-input)

list subset of other list

(defun list-as-set-subset-p (set_s set_t)
  "Return if SET_S is a subset of SET_T."
   (lambda (x y) (and x y))
   (mapcar (lambda (x) (if x t nil))
           (mapcar (lambda (x) (member x set_t))
   :initial-value t))

pause indication in mode line

immediate indication in the mode-line if i’m in pause or not.

(define-minor-mode pause-indication-mode
  "Toggle mode.
     Interactively with no argument, this command toggles the mode.
     A positive prefix argument enables the mode, any other prefix
     argument disables it.  From Lisp, argument omitted or nil enables
     the mode, `toggle' toggles the state."
      ;; The initial value.
      :global t
      :lighter (:eval (if mw-pause-state
                          (propertize " [pause]" 'face '(:foreground "red"))
                        " []"))
      :group 'pause-indication)

adjust region to in/exclude empty lines around

(defun mw-region-exclude-bottom-empty-lines (start end)
  (interactive "r")
  (when (= (point) start)
  (assert (<= (mark) (point)))
  (skip-chars-backward " \t\n")
  (when (< (point) (mark))
    (goto-char (mark)))
  (unless (= (point) (point-max))

(defun mw-region-include-top-empty-lines (start end)
  (interactive "r")
  (unless (= (point) start)
  ; assert: point is at the start of the region.
  (while (progn (backward-char)
                (looking-at-p "^[ \t]*$"))

(defun mw-region-exclude-top-empty-lines (start end)
  (interactive "r")
  (unless (= (point) start)
  ; assert: point is at the start of the region.
  (while (looking-at-p "[ \t]*$")
    (beginning-of-line 2)))
(defun mw-region-include-top-exclude-bottom-empty-lines ()
  "Let region include empty lines at top and exclude those at
  (when (region-active-p)
    (mw-region-exclude-bottom-empty-lines (region-beginning) (region-end))
    (mw-region-include-top-empty-lines (region-beginning) (region-end))))
(defun mw-region-prepare-for-rectangle-prefix ()
  "Let region exclude empty lines at top and bottom."
  (when (region-active-p)
    (mw-region-exclude-bottom-empty-lines (region-beginning) (region-end))
    (mw-region-exclude-top-empty-lines (region-beginning) (region-end)))
  (unless (= (point) (region-end))

change ws treatment for org-mark-element

want include whitespace at top and exclude whitespace at bottom.

(defadvice org-mark-element (after incude-top-exclude-bot-ws activate)
  "Include ws before element, exclude at bottom of element."


image cache can irritate sometimes.

(setq image-cache-eviction-delay 1)

see is also clear-image-cache.

frame config

[2016-02-05 Fri 22:53] Try out minibuffer in extra frame.

I like to have the minibuffer somewhere else! Unfortunately I’m not 100% content. Maybe I need to exercise more.

;; (setq initial-frame-alist '((minibuffer . nil)))
;; (setq default-frame-alist '((minibuffer . nil)))


  • [2018-03-29 Thu 13:45] some settings are deactivated.
;; (push (expand-file-name "~/p/elisp/external/gnus/lisp") load-path)
;; (require 'gnus-load)
;; (require 'info)
;; (add-to-list 'Info-default-directory-list "~/p/elisp/external/gnus/texi/")
(setq gnus-registry-max-entries 500000)
(gnus-registry-initialize) ; gnorb wants that, see (info "(gnorb)Setup").

to html mail in gnus

The following helps with html-mail in some cases.

Source: Email from Tassilo Horn: Re: a dark theme?

;; I don't think that has anything to do with themes, but SHR which renders
;; HTML mail in Gnus just picks bad colors to confirm with what's declared
;; in the HTML text.  But you can force it to require more contrast like
;; so:
(setq shr-color-visible-distance-min 10
      shr-color-visible-luminance-min 60)



  • [2018-06-19 Tue 18:17] switching to ledger again. ∃ arch package. I don’t need to compile.
  • [2018-06-19 Tue 18:16] (<– some time before that) switched from ledger to hledger. Reason: Classical ledger needs ages in my setting (Arch) to rebuild and the rebuild becomes necessary when a new boost version comes out AFAICS. hledger OTOH is a precompiled package in Arch.
;; from
;; Required to use hledger instead of ledger itself.
;; (setq ledger-mode-should-check-version nil
;;       ledger-report-links-in-register nil
;;       ledger-binary-path "hledger")

;; (push  (expand-file-name "~/p/ledger/lisp") load-path)
;; (autoload 'ledger-mode "ledger-mode" "ledger major mode")

;; (eval-after-load 'info
;;   '(progn (info-initialize)
;;           (add-to-list
;;            'Info-directory-list
;;            (expand-file-name "~/p/ledger/doc"))))

keep ledger files styled

M-q aligns all postings in region.

(defun mw-ledger-style-ledger ()
  "Style the ledger.
- Have one empty line in front of every transaction.
- Apply ledger-mode's align function."
    (goto-char (point-min))
      (ledger-post-align-postings (point-min) (point-max)))))

copy ledger transaction at point

(defun mw-ledger-copy-transaction-at-point ()
  "Copy the transaction under point.  Leave point at beginning of the copy.
This is very much like `ledger-copy-transaction-at-point' but
without the prompting the user."
  (let* ((extents (ledger-navigate-find-xact-extents (point)))
         (transaction (buffer-substring-no-properties (car extents) (cadr extents))))
    (insert "\n\n" transaction)

zen reward mode

Get points for task-status-changes in org. But where is the zen here?

(push (expand-file-name "~/p/elisp/external/zen-reward-mode/") load-path)
(load-library "zen-reward-mode")


Found this in a newsgroup. See the source for more info.


(add-to-list 'load-path "~/p/elisp/mw/hide-parts")
(require 'hide-parts)

org capture using functions

I think the functions must exist for “function-customized” capture templates to work.

(defun org-mw-capture-target-location () "~/tmp/")
(defun org-mw-capture-template-function () "* haha 2\n")

skeletons for inserting org source blocks

general src block

(define-skeleton org-skeleton-src-block ""
  "#+begin_src "  _ \n

This definition goes together with an abbrevs section


"bs"           0    ""  org-src-block

Typing ‘bs’ space inserts the org-src-block then.

elisp src block

(define-skeleton org-skeleton-src-block-emacs-lisp ""
  "#+begin_src emacs-lisp" \n  _ \n

insert last kills

(defun mw-insert-last-kills (&optional arg)
  "Insert last ARG items of kill-ring.
ARG defaults to 2.  Negative values of ARG are an error."
  (assert (or (not arg) (<= 0 arg)))
  (if (not arg) (setq arg 2))
  (mapc (lambda (x)
          (insert (substring-no-properties x) "\n"))
        (seq-take kill-ring arg)))

keys for fit image to width or height

  • W on an image to fit its width to the window width.
  • H for the height respectively.
     (define-key image-mode-map "W" #'image-transform-fit-to-width)
     (define-key image-mode-map "H" #'image-transform-fit-to-height)))

convert region to slashed date representation

this uses date parsing of calc afair.

(defun mw-region-convert-to-slashed-yyyymmdd (start end)
  "Parse region and replace as slashed yyyymmdd.

Example(-!- is point, -m- is mark):


    -!- 11:33 2017-10-07-m-


  (interactive "r")
  (let ((time
         (apply #'encode-time
                         (buffer-substring start end)))))
                   (append timelist
                           (make-list (- 6 (length timelist)) 0))))))
        (with-hm t)
        (inactive t))
    (delete-region start end)
    (insert (format-time-string "%Y/%m/%d" time))))

org completion


(defun org-completion-symbols ()
  (when (looking-back "=[a-zA-Z]+")
    (let (cands)
          (goto-char (point-min))
          (while (re-search-forward "=\\([a-zA-Z]+\\)=" nil t)
             (match-string-no-properties 0) cands :test 'equal))
      (when cands
        (list (match-beginning 0) (match-end 0) cands)))))

(defun ora-cap-filesystem ()
  (let (path)
    (when (setq path (ffap-string-at-point))
      (let ((compl
             (all-completions path #'read-file-name-internal)))
        (when compl
          (let ((offset (ivy-completion-common-length (car compl))))
            (list (- (point) offset) (point) compl)))))))

(add-hook 'org-mode-hook (lambda ()
                           (setq-local completion-at-point-functions


(defun table-lamp ()
  (other-frame 1)
  (switch-to-buffer (get-buffer-create "*white"))
  (set-background-color "white"))

narrow to logbook drawer

(defun mw-org-log-narrow ()
  "Narrow to logbook drawer if exists."
  (let ((pos
                (search-forward-regexp org-drawer-regexp nil nil)
                (not (string= "logbook" (downcase (match-string 1))))))
           (when (string= "logbook" (downcase (match-string 1)))
    (when pos
      (goto-char pos)

stretch the cursor

Make cursor the width of the character it is under e.g. indicate the width of a TAB.

(setq x-stretch-cursor t)


Subject: Pragmatic Emacs: Adaptive cursor width Newsgroups: feedbase.planet.emacsen Date: Mon, 02 Oct 2017 01:36:00 +0000

org-todo current clocked item

(defun org-todo-current-clock-entry ()
  "Change the TODO state of the currently clocked item."

filler text

German “Blindtext”.

(defmacro make-times (arg &rest body)
  "Repeat BODY ARG times. "
  `(dotimes (_ ,arg)
(defun mw-insert-filler-text (&optional arg)
  "Insert filler-text.  With number ARG make that much copies."
  (interactive "p")
  (let ((text "Lorem ipsum dolor sit amet,
consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum."))
    (insert text)
     (1- arg)
     (insert text))))

keymaps for org babel blocks


(require 'lispy)

(setq scimax-src-block-keymaps
      `(("emacs-lisp" . ,(let ((map (make-composed-keymap `( ; ,lispy-mode-map
                           (define-key map (kbd "C-c C-c") 'org-ctrl-c-ctrl-c)
(defun scimax-add-keymap-to-src-blocks (limit)
  "Add keymaps to src-blocks defined in `scimax-src-block-keymaps'."
  (let ((case-fold-search t)
    (while (re-search-forward org-babel-src-block-regexp limit t)
      (let ((lang (match-string 2))
            (beg (match-beginning 0))
            (end (match-end 0)))
        (if (assoc (org-no-properties lang) scimax-src-block-keymaps)
               beg end `(local-map ,(cdr (assoc
                                          (org-no-properties lang)
              (require 'org-mouse)
               beg end `(cursor-sensor-functions
                         ((lambda (win prev-pos sym)
                            ;; This simulates a mouse click and makes a menu change
                            (org-mouse-down-mouse nil)))))))))))
(defun scimax-spoof-mode (orig-func &rest args)
  "Advice function to spoof commands in org-mode src blocks.
It is for commands that depend on the major mode. One example is
  (if (org-in-src-block-p)
      (let ((major-mode (intern (format "%s-mode" (first (org-babel-get-src-block-info))))))
        (apply orig-func args))
    (apply orig-func args)))
(define-minor-mode scimax-src-keymap-mode
  "Minor mode to add mode keymaps to src-blocks."
  :init-value nil
  (if scimax-src-keymap-mode
        (add-hook 'org-font-lock-hook #'scimax-add-keymap-to-src-blocks t)
        (add-to-list 'font-lock-extra-managed-props 'local-map)
        (add-to-list 'font-lock-extra-managed-props 'cursor-sensor-functions)
        (advice-add 'lispy--eval :around 'scimax-spoof-mode)
        (cursor-sensor-mode +1))
    (remove-hook 'org-font-lock-hook #'scimax-add-keymap-to-src-blocks)
    (advice-remove 'lispy--eval 'scimax-spoof-mode)
    (cursor-sensor-mode -1))
(add-hook 'org-mode-hook (lambda ()
                           (scimax-src-keymap-mode +1)))
(defun mw-scimax-add-keymap-to-next-src-block ()
  "Add keymaps to next src-block defined in `scimax-src-block-keymaps'."
  (let ((case-fold-search t)
    (when (re-search-forward org-babel-src-block-regexp (point-max) t)
      (let ((lang (match-string 2))
            (beg (match-beginning 0))
            (end (match-end 0)))
        (if (assoc (org-no-properties lang) scimax-src-block-keymaps)
               beg end `(local-map ,(cdr (assoc
                                          (org-no-properties lang)
              (require 'org-mouse)
               beg end `(cursor-sensor-functions
                         ((lambda (win prev-pos sym)
                            ;; This simulates a mouse click and makes a menu change
                            (org-mouse-down-mouse nil)))))))))))

towards a slide show thing

Starting somewhere

(start-process "bg-setting" nil "xsetbg" "/home/b/media/images/b/20170531231556.png")

(seq-filter (lambda (name) (and (not (string= name "."))
                                (not (string= name ".."))))
            (directory-files "/home/b/media/images/b"))

(setq lexical-binding t)
(let ((myring (make-ring 3))
  (mapc (lambda (element) (ring-insert myring element))
  (setq item (car (ring-elements myring)))
  (defun next-background ()
    (setq item (ring-next myring item))
    (start-process "bg-setting" nil "xsetbg" (ring-next myring item))))

duplicate a term for continue work on it

continue as equation by copying the current line.

(defun mw-insert-copy-line-and-insert-equal-sign ()
  "Copy line and insert equal sign.
Thought to duplicate a term as preparation for further
transformation.  Example:

1+1 =
  (let ((text (buffer-substring
               (progn (beginning-of-line) (point))
               (progn (end-of-line) (point)))))
    (insert " = \n" text)))


(push "~/p/elisp/mw/logbook-sorter" load-path)
(require 'logbook-sorter)


(push "~/p/elisp/mw/reverse-words/dist" load-path)
(require 'reverse-words "reverse-words-0.0.0.el")

display org properties narrowed in clone

(defun mw-org-property-show-properties-in-clone ()
  "Display Org properties in a narrowed clone."
  (assert (eq 'org-mode major-mode))
  (let ((range-property-block (org-get-property-block)))
    (when range-property-block
      (clone-indirect-buffer-other-window nil t)
       (car range-property-block) (cdr range-property-block))

display org notes narrowed in clone

See Display Org properties in other buffer for a way to do it.

Recall defun org-log-beginning.

(defun mw-org-get-log-block ()
  "Return the (beg . end) range of the body of the logbook drawer or nil."
   (unless (org-before-first-heading-p)
     (let ((log-beginning (org-log-beginning)))
       (if log-beginning
             (goto-char log-beginning)
             (let ((element (org-element-at-point)))
               (catch 'found
                 (while element
                   (when (eq 'drawer (car element))
                     (throw 'found (cons log-beginning (org-element-property :contents-end element))))
                   (setq element (plist-get (cadr element) :parent)))))))))))

(defun mw-org-show-log-in-clone ()
  "Display Org notes in a narrowed clone."
  (assert (eq 'org-mode major-mode))
  (let ((range-block (mw-org-get-log-block)))
    (when range-block
      (clone-indirect-buffer-other-window nil t)
       (car range-block) (cdr range-block))
(defalias 'mw-org-log-show-in-clone 'mw-org-show-log-in-clone)

widen to show the sexp up

(defun mw-narrow-to-up-sexp ()
  "Go one level up in sexps and narrow to it."
  (sp-narrow-to-sexp 1)

override special scroll-lock-mode behavior

I prefer to have scroll lock style all the time.

(defun scroll-lock-next-line (&optional arg)
  "Scroll up ARG lines keeping point fixed."
  (interactive "p")
  (or arg (setq arg 1))
  ;; (if (pos-visible-in-window-p (point-max))
  ;;     (forward-line arg)
  (scroll-up arg)
  ;; )
  (scroll-lock-move-to-column scroll-lock-temporary-goal-column))


(push "~/p/elisp/external/txr-mode" load-path)
(require 'txr-mode)

move or copy region

(defun mw-region-teleport-to-other-window (start end)
  "Move region to position in other window."
  (interactive "r")
  (let ((buf (save-excursion
               (other-window 1)
    (when buf
      (with-current-buffer buf
      (append-to-buffer buf start end)
      (delete-region start end)
      (switch-to-buffer buf))))

(defun mw-region-append-to-other-window (start end)
  "Move region to position in other window."
  (interactive "r")
  (let ((buf (save-excursion
               (other-window 1)
    (when buf
      (with-current-buffer buf
      (append-to-buffer buf start end)
      (switch-to-buffer buf))))


control of `repeat’

Linked to the binding of `repeat’.

;; (global-set-key (kbd "C-M-5") #'repeat-message-last-command)

(defun repeat-message-last-command ()
  "Haha.  This function is not so helpful because it pollutes `last-repeatable-command'.
 Maybe fix somehow if time."
   "%s <- last repeatable command. %s <- before last"


(push "~/p/elisp/mw/cursor-color-mode" load-path)
(require 'cursor-color-mode)


;; (push "~/p/elisp/mw/hack-time-mode" load-path)
;; (require 'hack-time-mode)


(push "~/p/elisp/mw/carry-region" load-path)
(require 'carry-region)

(defalias 'mw-region-carry-toggle 'mw-carry-region-toggle "Alternative reliable name.")


(local-set-key (kbd "C-c r") #'mw-carry-region-toggle)
(global-set-key (kbd "C-c r") #'mw-carry-region-toggle)

more avy-goto via one command

BEGIN_SR emacs-lisp (defun mw-avy-goto-char (arg) “Call avy-goto-char variant dependend of universal-argument. Double C-u for `avy-goto-char-in-line’ else call `avy-goto-char’. ” (interactive “P”) (cond ((equal ‘(16) arg) (call-interactively #’avy-goto-char-in-line)) ((call-interactively #’avy-goto-char)))) END_SRCTEXTIFY org-link

textifylink part

(defun mw-org-link-textify ()
  "Replace the link at point with its description."
  (when (org-in-regexp org-bracket-link-regexp 1)
    (let ((remove (list (match-beginning 0) (match-end 0)))
          (link (match-string-no-properties 1))
          (desc (match-string-no-properties 3)))
      (replace-match (or desc link)))))

pick often used pw from authinfo

(defun ()
  "Kill passwort for user out of my authinfo."
  (let* ((delay-to-callback 42)
           (car (aref (aref (plist-get
                              (auth-source-search :user  ""))
     delay-to-callback nil
     (lambda ()
       (setf kill-ring  (delete target kill-ring))))))



(push "~/p/elisp/mw/lab/org-structure-as-dirs-and-files" load-path)
(require 'org-structure-as-dirs-and-files)


I really like this.


(defun org-teleport (&optional arg)
  "Teleport the current heading to after a headline selected with avy.
With a prefix ARG move the headline to before the selected
headline.  With a numeric prefix, set the headline level.  If ARG
is positive, move after, and if negative, move before."
  (interactive "P")
  ;; Kill current headline
  (kill-region (region-beginning) (region-end))
  ;; Jump to a visible headline
  (let ((avy-all-windows t))
    (avy-with avy-goto-line (avy--generic-jump "^\\*+" nil avy-style)))
   ;; Move before  and change headline level
   ((and (numberp arg) (> 0 arg))
    ;; arg is what we want, second is what we have
    ;; if n is positive, we need to demote (increase level)
    (let ((n (- (abs arg) (car (org-heading-components)))))
      (cl-loop for i from 1 to (abs n)
               (if (> 0 n)
   ;; Move after and change level
   ((and (numberp arg) (< 0 arg))
    (goto-char (region-end))
    (when (eobp) (insert "\n"))
    ;; n is what we want and second is what we have
    ;; if n is positive, we need to demote
    (let ((n (- (abs arg) (car (org-heading-components)))))
      (cl-loop for i from 1 to (abs n)
               (if (> 0 n) (org-promote-subtree)

   ;; move to before selection
   ((equal arg '(4))
   ;; move to after selection
    (goto-char (region-end))
    (when (eobp) (insert "\n"))


(defun mw-mistyrose ()
"Set background color to mistyrose."
  (set-background-color "mistyrose"))


(require 'org-mime)

Use e.g. org-mime-subtree to mail a tree.


(push "~/p/elisp/mw/org-section-numbers" load-path)
(require 'org-section-numbers)


(defun tweet-this (b e)
  (interactive "r")
  (twittering-update-status (buffer-substring b e)))


(defun mw-bbdb-this (b e)
  "Ask bbdb about the region."
  (interactive "r")
  (bbdb (buffer-substring b e)))

(defun mw-bbdb-word-at-point ()
  "Ask bbdb about word at point."
  (bbdb (thing-at-point 'word t)))

drop the leading stars from items in column view

(defun mw-org-columns-modify-value-for-display (column-title value)
  (if (string= "ITEM" (upcase column-title))

(setq org-columns-modify-value-for-display-function

repeat per hydra

(defhydra hydra-repeat (global-map "C-c C-6")
  "Command repeat."
  ("6" (mw-direct-command-repeat)))

capitalize word

Slight change to capitalize. Capitalize the word backwards when on end of it.

(defun mw-capitalize-word (arg)
  "At end of word capitalize it.  Else do `capitalize-word'.
Argument ARG see `capitalize-word'."
  (interactive "P")
  (unless arg
    (when (looking-at-p  "\\>")
    (setf arg 1))
  (capitalize-word arg)
  ;; (forward-char)

[2016-09-06 Tue 11:31] not so happy with this command because point gets stuck at the end of a word when repeating the command. Just discovered capitalize-dwim. What is capitalize-dwim?

;; (global-set-key "\M-c" #'mw-capitalize-word)
(global-set-key "\M-c" #'capitalize-dwim)

See also `toggle-letter-case’. I possibly reinvented the wheel some AFAICS. [2016-06-23 Thu 11:07]

Interesting how many little details one finds when realizing such easy looking feature.

handle bottommost-tagged after sorting

This was an attempt to keep an orgee at the bottom. Switched to define stuff in .dir-locals.el.

;; (setf org-after-sorting-entries-or-items-hook
;;       (lambda ()
;;         (search-forward  ":bottommost:")
;;         (org-cut-subtree)
;;         (goto-char (point-max))
;;         (org-paste-subtree 1)))

double space at end of sentences

Function to convert single space sentence endings to double space.

(defun if-sentence-end-space-make-it-space
    () (interactive)
    (let ((sentence-end-double-space nil))
      (when (looking-at " +") (replace-match "  "))))


(push "~/p/elisp/external/maxima" load-path)
(require 'maxima)

pick current agenda filter

[2016-05-25 Wed 19:26] I wanted this. Practise shall show if this helps some.

(defun mw-org-agenda-store-current-filters-as-custom-agenda ()
  "Make current setting of agenda a custom agenda \"x\" ."
   `("x" "Custom agenda possibly stored by `mw-org-agenda-store-current-filters-as-custom-agenda'" agenda ""
       "Custom agenda")


(eval-after-load 'org-crypt '(org-crypt-use-before-save-magic))


Don’t forget the crypto.

(push "~/p/elisp/external/jl-encrypt" load-path)
(require 'jl-encrypt)
;; (add-hook 'gnus-message-setup-hook #'mml-secure-encrypt-if-possible)
;; (add-hook 'message-send-hook #'mml-secure-check-encryption-p)


;; (require 'exwm)
;; (require 'exwm-config)
;; (exwm-config-default)

multiple screens

;; (require 'exwm-randr)

;; (setq exwm-randr-workspace-output-plist '(0 "LVDS" 1 "HDMI-0"))
;; (add-hook 'exwm-randr-screen-change-hook
;;           (lambda ()
;;             (start-process-shell-command
;;              "xrandr" nil "xrandr --output LVDS --left-of HDMI-0 --auto")))
;; (exwm-randr-enable)


;; (require 'exwm-systemtray)
;; (exwm-systemtray-enable)

jump to other drawers

(defun mw-org-next-drawer (count)
"Go forward to next drawer.
Do this COUNT times."
  (interactive "p")
  (let ((case-fold-search t))
    (search-forward-regexp org-drawer-regexp nil nil count)
    (when (looking-back ":end:" (- (point) (length ":end:")))
    ( mw-org-next-drawer 1))))

(defun mw-org-previous-drawer (count)
  (interactive "p")
  (let ((case-fold-search t))
    (search-backward-regexp org-drawer-regexp nil nil count)
    (when (looking-at ":end:")
      (search-backward-regexp org-drawer-regexp))))
(defhydra hydra-org-drawers (global-map "C-c n")
  "Move to next drawer."
  ("n" mw-org-next-drawer)
  ("p" mw-org-previous-drawer))

org labs

go directly to diary file from agenda

(defun mw-org-agenda-open-diary (&optional arg)
  "Open diary with date from agenda.  Prefix ARG to see that many days."
  (interactive "P")
   (if (and arg (not (equal '(4) arg)))
       (prefix-numeric-value arg))))
(eval-after-load "org-agenda"
    org-agenda-mode-map "D"
    (lambda (&optional arg)
      (interactive "P")
      (if arg
          (mw-org-agenda-open-diary arg)

property-action from agenda

(eval-after-load "org-agenda"
'(org-defkey org-agenda-mode-map "\C-c\C-xy" #'org-agenda-property-action))

list items with a date

(defun org-list-insert-inactive-ts-item ()
  "Insert a list item starting with an inactive timestamp."
  (let ((item-pos (org-in-item-p))
        (pos (point)))
    (if item-pos
          (goto-char item-pos)
          (let* ((struct (org-list-struct))
	         (prevs (org-list-prevs-alist struct))
	         (s (concat (with-temp-buffer
                              (org-insert-time-stamp nil t t)
                              (buffer-string)) " ")))
            (setq struct (org-list-insert-item pos struct prevs nil s))
            (org-list-write-struct struct (org-list-parents-alist struct))
            (looking-at org-list-full-item-re)
	    (goto-char (match-end 0))
      (insert "- ")
      (org-insert-time-stamp nil t t)
      (insert " "))))

headlines with a date

(defun org-insert-heading-starting-with-inactive-ts ()
  "Insert a heading containing an inactive timestamp."
  (org-insert-time-stamp nil t t)
  (insert " "))

org hide above first heading

(defun org-first-heading ()
  (goto-char (point-min))
  (if (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t)
      (goto-char (match-beginning 0))))

(defun org-flag-region-before-first-heading (&optional show)
  (interactive "P")
  (goto-char (point-min))
   (progn (org-first-heading) (point))
   (not show)))


(setq org-show-context-detail
      '((isearch . lineage)
        (bookmark-jump . lineage)
        (occur-tree . minimal)
        (default . ancestors)))

Agenda for deadlines only

(eval-after-load "org-agenda"
  '(add-to-list 'org-agenda-custom-commands
                '("A" "Agenda; only deadlines"
                  agenda ""
                  ((org-agenda-entry-types '(:deadline))))))

Source: ;;

Agenda Block Agenda

See the N (NEXT) tasks.

(eval-after-load "org-agenda"
  '(add-to-list 'org-agenda-custom-commands
                '("n" "Agenda; only NEXT tasks"
                  ((agenda "")
                   (todo "N")))))

Timetravel Org

When you want to see or change something in the agenda at a different day the following functions might be helpful.

This fun allows (afaict) the view on an Org agenda when setting an other date as current.

(defun mw-org-timemachine-set-other-today ()
  "Choose a day from the calendar as today for Org."
  (setq org-extend-today-until
        (truncate (- (/ (org-time-stamp-to-now (org-read-date) t) 60 60)))))

(defun mw-org-timemachine-reset-today ()
  "Reset timetravel to zero."
  ;; For me it's okay, but maybe better reset to the original
  ;; value which might have been something.different from zero.
  (setq org-extend-today-until 0))

org-todo with certain date

recall: there is already org-todo-yesterday.

(defun mw-org-todo-with-other-date (date &optional arg)
  "Like `org-todo' but ask for an other DATE.
Optional argument ARG prefix arg."
  (interactive (list (org-read-date) current-prefix-arg))
  (let* ((org-use-effective-time t)
           (- (/ (org-time-stamp-to-now date t)
                 60 60))))
         (org-extend-today-until (1+ hour)))
    (org-todo arg)))

unset a register

I think this functionality is not in Emacs core yet.

(defun clear-register (register)
  "Unset contents of Emacs register named REGISTER."
  (interactive (list (register-read-with-preview "Clear register: ")))
  (setf register-alist (assq-delete-all register register-alist)))

controlled garbage collection

This is from

(defun my-minibuffer-setup-hook ()
  (setq gc-cons-threshold most-positive-fixnum))

(defun my-minibuffer-exit-hook ()
  (setq gc-cons-threshold 800000))

(add-hook 'minibuffer-setup-hook #'my-minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook #'my-minibuffer-exit-hook)


Library of Babel is a collection of Org source blocks. This code is for adding my additions to the lob.

(org-babel-lob-ingest "~/org/")

switch buffers between frames

Found at EmacsWiki: Switching Buffers provided by YoniRabkinKatzenell AFAICS. I think this can be useful for me.

(defun yrk-switch-buffers-between-frames ()
  "Switch the buffers between the two last frames."
  (let ((this-frame-buffer nil)
        (other-frame-buffer nil))
    (setq this-frame-buffer (car (frame-parameter nil 'buffer-list)))
    (other-frame 1)
    (setq other-frame-buffer (car (frame-parameter nil 'buffer-list)))
    (switch-to-buffer this-frame-buffer)
    (other-frame 1)
    (switch-to-buffer other-frame-buffer)))


this is a typical procedere with commit message for the author

Automate the typical thing and get happy. ^_^

(defun mw-dtrt-commit-msg-prepare()
  "This function applied to a commit-msg buffer shall dtrt."
  (let ((beg (point)))
    (search-forward-regexp "modified: *")
    (delete-region beg (point)))
  (let ((end (point)))
    (search-backward-regexp "\\.")
    (delete-region (point) end))
  (insert ":\n")
(add-hook 'git-commit-mode-hook
          (lambda () (key-chord-define-local "p8" #'mw-dtrt-commit-msg-prepare)))

linum experiments

(defun delta (line pointline)
  "LINE is the processed line.
POINTLINE is the line containing point."
  (format "%d" (- line pointline)))

(defun delta5 (line pointline)
  "LINE is the processed line.
POINTLINE is the line containing point."
  (format "%5d" (- line pointline)))

(defun the-line (line)
  "LINE is the processed line.
pointline is the line containing point."
  (format "%4d" line))

;; (setq linum-format 'the-line)
;; (setq linum-format 'delta5)



;; change case of letters                                                 ;;
(defun toggle-letter-case ()
  "Toggle the letter case of current word or text selection.
Toggles between: “all lower”, “Init Caps”, “ALL CAPS”."
  (let (p1 p2 (deactivate-mark nil) (case-fold-search nil))
    (if (region-active-p)
        (setq p1 (region-beginning) p2 (region-end))
      (let ((bds (or (bounds-of-thing-at-point 'word)
                     (progn (forward-whitespace 1)
                            (bounds-of-thing-at-point 'word)))))
        (setq p1 (car bds) p2 (cdr bds))))
    (when (not (eq last-command this-command))
        (goto-char p1)
         ((looking-at "[[:lower:]][[:lower:]]") (put this-command 'state "all lower"))
         ((looking-at "[[:upper:]][[:upper:]]") (put this-command 'state "all caps"))
         ((looking-at "[[:upper:]][[:lower:]]") (put this-command 'state "init caps"))
         ((looking-at "[[:lower:]]") (put this-command 'state "all lower"))
         ((looking-at "[[:upper:]]") (put this-command 'state "all caps"))
         (t (put this-command 'state "all lower")))))
     ((string= "all lower" (get this-command 'state))
      (upcase-initials-region p1 p2) (put this-command 'state "init caps"))
     ((string= "init caps" (get this-command 'state))
      (upcase-region p1 p2) (put this-command 'state "all caps"))
     ((string= "all caps" (get this-command 'state))
      (downcase-region p1 p2) (put this-command 'state "all lower")))))

;;set this to M-c
(global-set-key "\M-C" #'toggle-letter-case)

ispell and org

Email from Artur Malabarba: Endless Parentheses: Making Is

Subject: Endless Parentheses: Making Ispell work with org-mode Newsgroups: Date: Mon, 24 Aug 2015 02:00:00 +0200 (15 hours, 49 minutes, 21 seconds ago) Archived-at:

[1. text/html]

If you’ve every tried to do some spell-checking in org-mode you know how finicky that can be. Ispell is happy to

check absolutely anything, even code blocks and property drawers! When you’re blogging about code-snippets from an org file this annoyance quickly turns into irritation. Here’s how you fix it.

(defun endless/org-ispell ()
  "Configure `ispell-skip-region-alist' for `org-mode'."
  (make-local-variable 'ispell-skip-region-alist)
  (add-to-list 'ispell-skip-region-alist '(org-property-drawer-re))
  (add-to-list 'ispell-skip-region-alist '("~" "~"))
  (add-to-list 'ispell-skip-region-alist '("=" "="))
  (add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_SRC" . "^#\\+END_SRC")))
(add-hook 'org-mode-hook #'endless/org-ispell)


(add-hook 'ediff-keymap-setup-hook
          (lambda ()
              ediff-mode-map "8"

drag windows

Found [2015-03-03 Tue 17:18] Link:

When using Emacs on a larger screen where Emacs’ frame is split into multiple windows, you sometimes wish there was some simple way to rearrange which buffer is shown in which window. Of course, you can do that by moving through your windows and using switch-to-buffer and friends but that’s not really convenient.

So here’s a command which lets you use drag one buffer from one window to the other. The effect is that the buffers of the start and target window are swapped.

(defun th/swap-window-buffers-by-dnd (drag-event)
  "Swaps the buffers displayed in the DRAG-EVENT's start and end window."

  (interactive "e")
  (let ((start-win (cl-caadr drag-event))
        (end-win   (cl-caaddr drag-event)))
    (when (and (windowp start-win)
               (windowp end-win)
               (not (eq start-win end-win))
               (not (memq (minibuffer-window)
                          (list start-win end-win))))
      (let ((bs (window-buffer start-win))
            (be (window-buffer end-win)))
        (unless (eq bs be)
          (set-window-buffer start-win be)
          (set-window-buffer end-win bs))))))

Bind it to some mouse drag event and have fun. For example, I use

(global-set-key (kbd "<C-S-drag-mouse-1>") #'th/swap-window-buffers-by-dnd)

So that drag’n’drop with the left mouse button and control and shift pressed is bound to the command above.


Recall function navi-search-and-switch to activate a navi-buffer.

;(require 'navi-mode)

quickly access

(defun mw-ask-leo-about-word-at-point ()
  "Call the leo translation page for the word at point."
  (mw-ask-leo (word-at-point)))

(defun mw-search-leo-relevant-section ()
  (search-forward-regexp "# +suchwort")
  (remove-hook 'eww-after-render-hook 'mw-search-leo-relevant-section))

(defun mw-ask-leo (arg)
  "Call the leo translation page for a string.
Use region as default string."
   (let ((text-region
          (when (region-active-p)
            (buffer-substring (region-beginning) (region-end)))))
     (list (read-from-minibuffer
       "word: " text-region))))
  (add-hook 'eww-after-render-hook 'mw-search-leo-relevant-section)
  (eww (format "" arg)))

hippie expand

Hippie expand is using various sources as potential for expansion.

(global-set-key (kbd "M-/") 'hippie-expand)

special holidays

Special Holidays can be defined in a function. Hooking can be done via variable `holiday-other-holidays’.

Note: The code here looks not so good. Improvement would be good.

(defun mw-further-holidays-of-interest ()
  "For specifying further holidays.
This function can be stored in variable `holiday-other-holidays'
for an effect."
  (if (= 2014 displayed-year)
      (if (or (= 4 displayed-month) (= 5 displayed-month) (= 6 displayed-month))
          '(((5 29 2014) "Christi Himmelfahrt"))
        (if (or (= 7 displayed-month) (= 8 displayed-month) (= 9 displayed-month))
            '(((8 15 2014) "Mariä Himmelfahrt"))))
    (if (= 2016 displayed-year)
        (if (or (= 4 displayed-month) (= 5 displayed-month) (= 6 displayed-month))
            '(((5 5 2016) "Christi Himmelfahrt"))
          (if (or (= 7 displayed-month) (= 8 displayed-month) (= 9 displayed-month))
              '(((8 15 2016) "Mariä Himmelfahrt")))))))

personalize the bell

Bird sound is awesome. In particular when the sound plays concurrently.

(defun mw-play-little-bird-sound ()
  "Play a little bird sound."
   "play-a-sound" "*play-a-sound-output*"
   "mplayer" "-af" "volume=-15"
   (expand-file-name "~/media/sound/birds/Tufted-Tit-Mouse-web-II.wav")))
;;(setq ring-bell-function 'mw-play-little-bird-sound)
;; turn off with: (setq ring-bell-function 'ignore)
;; turn off with: (setq ring-bell-function nil) ; which gives a "visual bell".
;; (setq ring-bell-function ' mw-set-and-reset-bg-color) ; speed totally matters here!
(setq ring-bell-function nil) ; speed totally matters here!
(defun mw-set-and-reset-bg-color ()
"Little dance to give a visual signal."
  (let ((before-color (frame-parameter (selected-frame) 'background-color)))
    (set-background-color "red")
    (sit-for 0)
    (set-background-color before-color)))

kill an url at point

(defun mw-kill-url-at-point ()
  "Try to interpret the thing at point as url and if so put to kill ring."
  (kill-new (thing-at-point 'url)))
(global-set-key (kbd "C-c M-w") 'mw-kill-url-at-point)

duplicate a w3m-session

  • [2014-07-18 Fri 17:14] It looks like the defun below is already there in w3m: “M-n runs the command w3m-copy-buffer.”
(defun mw-w3m-duplicate-session (&optional reload)
  "Duplicate the w3m-session.
Optional argument RELOAD for w3m-view-this-url-1."
  (interactive "P")
  (if (not (eq major-mode 'w3m-mode))
      (message "This command applies resonably to w3m mode only")
    (if w3m-current-url
        (w3m-view-this-url-1 w3m-current-url reload 'new-session)
      (message "No current URL"))))


wcheck is a mode for checking things in a buffer. Might be worth to invest some energy into its configuration for spell checking.

There is documentation on

I found out about wcheck’s existance when reading an emacs group.

The following example shows that wcheck can be used for indication of trailing whitespace.

;; source:
(setq wcheck-language-data
      '(("Trailing whitespace"
	 (program . identity)
	 (action-program . (lambda (marked-text)
			     (list (cons "Remove whitespace" ""))))
	 (face . highlight)
	 (regexp-start . "")
	 (regexp-body . "[ \t]+")
	 (regexp-end . "$")
	 (regexp-discard . "")

open url at point in firefox

#BEGIN_SRC emacs-lisp (defun mw-browse-url-at-point-firefox () (interactive) (let ((browse-url-browser-function #’browse-url-firefox)) (browse-url-at-point)))

Also consider to call `browse-url-firefox’ directly.

key sequences to open browser

(global-set-key (kbd "\C-cg") 'eww)
(global-set-key (kbd "\C-cG") 'browse-url)
(global-set-key (kbd "\C-cF") 'browse-url-firefox)


Using a local branch and not the package to test a version with encryption.

(push  "~/p/elisp/mw/mpages" load-path)
(autoload 'mpages "mpages" "For writing morning pages." t nil)

(defadvice mpages (after ctrlc-ctrlc-to-finish activate)
  "Set C-c C-c to close the mpage writing.
Set the key for encrytion, then save and kill the buffer.
This binding shall make the close more convenient."
  (local-set-key [?\C-c ?\C-c] (lambda ()
                                 (setq epa-file-encrypt-to '("49010A040A3AE6F2"))


(add-hook 'dired-load-hook
          (lambda ()
            (load "dired-x")
            ;; Set dired-x global variables here.  For example:
            ;; (setq dired-guess-shell-gnutar "gtar")
            ;; (setq dired-x-hands-off-my-keys nil)

from dired to ediff

(add-hook 'dired-mode-hook
          (lambda ()
            (define-key dired-mode-map "E" #'dired-ediff)))

(defun dired-ediff ()
  "Run ediff on the files at point and mark from dired."
      ((file (dired-get-filename t))
       (other (if (and transient-mark-mode mark-active)
                  (save-excursion (goto-char (mark t))
                                  (dired-get-filename t t)))))
    (when (and file other (not (equal file other)))
      (ediff file other))))

from diff to ediff

(add-hook 'diff-mode-hook (lambda () (define-key diff-mode-map "E" #'mw-diff-ediff)))

(defun mw-diff-ediff ()
  "Run ediff for the diff at point."
   (diff-find-file-name nil nil)
   (diff-find-file-name t nil)))

delete blank lines also above

(global-set-key  (kbd "C-x C-o") #'delete-blank-lines)

[2015-07-13 Mon 11:54] Activation. Let’s see if the removal of the blank lines above proves useful.

disable query about active processes at quit

(require 'cl)
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
  (cl-flet ((process-list ())) ad-do-it))

Source: Programming: Seven specialty Emacs settings with big payoffs.

open line below

(global-set-key (kbd "C-S-o") #'mw-open-line-below)

real delete

Real delete of region, not this ‘play it save and put the delete into kill-ring’ stuff.

(global-set-key (kbd "\C-cw") #'delete-region)

check this functionality

[2018-12-17 11:35] looks like the deleted goes into kill-ring.

mouse avoidance

Documentation says

Should be one of the symbols ‘banish’, ‘exile’, ‘jump’, ‘animate’, ‘cat-and-mouse’, ‘proteus’, or ‘none’.

(mouse-avoidance-mode 'proteus)





;; (add-hook 'emacs-lisp-mode-hook
;;           (lambda ()
;;             (setq-local prettify-symbols-alist
;;                         '(("lambda" . ?λ)))
;;             (push '("(" . ?⎛ ) prettify-symbols-alist)
;;             (push '(")" . ?⎞ ) prettify-symbols-alist)
;;             (prettify-symbols-mode 1)))


Email from Stefan Monnier: Re: can emacs do this

(add-hook 'python-mode-hook
          (lambda ()
            (setq-local prettify-symbols-alist
                        '(("lambda" . )
                          ("math.sqrt" . ?√)
                          ("math.pi" . )
                          ("sum" . )))
            (prettify-symbols-mode 1)))

natural language environment

Convenient switching of the input-method and the spell-checking.

This code is derived from

(defvar mw-lang-inputmethod-ring)

(let ((langs-inputmethods '(("deutsch" "german-prefix") ("american" nil))))
  (setq mw-lang-inputmethod-ring (make-ring (length langs-inputmethods)))
  (dolist (elem langs-inputmethods)
    (ring-insert mw-lang-inputmethod-ring elem)))

(defun mw-cycle-ispell-language-and-input-method ()
  "Use the next language setting from mw-langs-inputmethod-ring."
  (let ((lang-inputmethod (ring-ref mw-lang-inputmethod-ring -1)))
    (ring-insert mw-lang-inputmethod-ring lang-inputmethod)
    (ispell-change-dictionary (car lang-inputmethod))
    (set-input-method (cadr lang-inputmethod))))
;; [2014-07-08 Tue 11:34] Idea: one could also switch the completer
;; dictionary on M-tab.  (setq ispell-complete-word-dict
;; "/usr/share/dict/ngerman")

(let ((the-dicts '("/usr/share/dict/ngerman"
  (setq mw-dict-ring (make-ring (length the-dicts)))
  (dolist (elem the-dicts) (ring-insert mw-dict-ring elem)))

(defun mw-cycle-ispell-completion-dict ()
  (let ((dict (ring-ref mw-dict-ring -1)))
    (ring-insert mw-dict-ring dict)
    (setq ispell-alternate-dictionary  ;; ISSUE: which of these variables
          ;; ispell-complete-word-dict ;; should be taken here?
    (message (concat dict " set for ispell completion."))))


Scroll lock mode gives another buffer movement feeling.

(global-set-key (kbd "<Scroll_Lock>") 'scroll-lock-mode)


Seamless exchange with screen.

(defvar mw-screen-exchange-filename
  "Name of the file used by screen copy and paste.")

screen like commands for slurp and write

(defun mw-screen-exchange-slurp-insert ()
  (insert-file-contents mw-screen-exchange-filename))

(defun mw-screen-exchange-write-region (start end)
  (interactive "r")
  (write-region start end mw-screen-exchange-filename))

editing the screen-exchange file

(defun mw-screen-exchange-open-buffer ()
  "Open the screen exchange file in auto revert mode."
  (set-buffer (find-file mw-screen-exchange-filename))


Direct client-to-client support for erc.

(eval-after-load "erc" '(require 'erc-dcc))


zone is builtin. I use zone as signal.

Set zone-timeout to a number to have zone stop after zone-timeout seconds.

(setq  zone-timeout 300)

emacs lisp hook

(add-hook 'emacs-lisp-mode-hook #'eldoc-mode)
(add-hook 'emacs-lisp-mode-hook #'imenu-add-menubar-index)
(add-hook 'emacs-lisp-mode-hook #'checkdoc-minor-mode)

last line

;;; init.el ends here