My literate Emacs config
Clone or download
Latest commit e98e20a Jan 17, 2019
Permalink
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
readme.org org:+:new pretty symbol Jan 16, 2019

readme.org

toc toc

prologue

about

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.

enjoy!

copyright

Copyright (c) 2015-2018 Marco Wahl <marcowahlsoft@gmail.com>

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 http://www.gnu.org/licenses/.

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:

;; THIS FILE HAS BEEN GENERATED.


;;; Code:

debugging

Switch on debugging, in case.

(setq debug-on-error t)

config

specials

emacspeak

(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

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"
    '(progn
       (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"
    '(progn
       (org-defkey org-agenda-mode-map (kbd "Y") #'org-agenda)))
  (eval-after-load 'info
    '(progn (info-initialize)
            (add-to-list
             'Info-directory-list
             (concat (expand-file-name mw-org-source-directory)
                     "/doc"))))
  (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 ()
  (interactive)
  (push-mark)
  (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"
  '(progn
     (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/ango2018.org"))
;; (setq org-agenda-files
;;       '("~/busi/org/busi-todo.org"
;;         "~/org/incidents.org"
;;         "~/org/doc-tl.org"
;;         "~/org/dates.org"
;;         "~/org/inbox.org"
;;         "~/org/gtd.org"
;;         "~/org/someday.org"
;;         "~/org/tickler.org"
;;         "~/org/recur.org"
;;         "~/org/notes.org"
;;         "~/org/bucket.org"
;;         "~/tmp/tmp.org"
;;         "~/p/org/worg/library-of-babel.org"))

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)
                         (mw-org-show-meta-info-lines))
                     (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)
                     (org-narrow-to-subtree)
                     (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))
                       (org-export-dispatch))))
            ("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."
  (interactive)
  (goto-char (point-min))
  (while (progn
           (org-next-visible-heading 1)
           (org-at-heading-p))
    (when (= 1 (plist-get (cadr (org-element-at-point)) :level))
      (org-demote-subtree))))

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."
  (interactive)
  (goto-char (point-min))
  (while (progn
           (org-next-visible-heading 1)
           (org-at-heading-p))
    (when (= 2 (plist-get (cadr (org-element-at-point)) :level))
      (org-promote-subtree))))

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.

(add-hook
 'dired-mode-hook
 (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

(setq
 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.

(add-hook
 'org-mode-hook
 (lambda ()
   (local-set-key
    (kbd "C-c M-n")
    (lambda ()
      (interactive)
      (end-of-line)
      (re-search-forward "#\\+")
      (beginning-of-line)))))

(add-hook
 'org-mode-hook
 (lambda ()
   (local-set-key
    (kbd "C-c M-p")
    (lambda ()
      (interactive)
      (beginning-of-line)
      (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."
  (interactive)
  (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))
      (progn
        (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."
  (interactive)
  (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)

(setq
 org-babel-key-bindings
 (append
  org-babel-key-bindings
  (list
   (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")
                      (beginning-of-line)))))))

org velocity

org velocity is a org-mode contrib extension.

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

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)
source

http://mbork.pl/2015-09-26_A_few_org-agenda_hacks

delete other windows after jump from agenda

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

org-screenshot

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.
"
  (interactive)
  (require 'org-attach)
  (org-attach-dir t)
  (org-attach-screenshot
   nil
   (format-time-string
    "screenshot-%Y%m%d-%H%M%S.png"))
  (org-attach-sync))

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
      (quote
       ((nil :maxlevel . 7)
        ;; (org-agenda-files :maxlevel . 1)
        (org-agenda-files :level . 0))))

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

org-image-actual-width

(setq org-image-actual-width nil)

play with the subtree bullets

put some info from tags into the bullet
(add-hook
 'org-mode-hook
 (lambda ()
   (font-lock-add-keywords
    nil
    '(("^\\**\\(\\*\\) "
       (1 (compose-region (- (match-end 1) 1)
                          (match-end 1)
                          " ")
          nil))
      ("^\\**\\(\\*\\) .*:idea:"
       (1 (compose-region (- (match-end 1) 1)
                          (match-end 1)
                          "💡")
          nil))
      ("^\\**\\(\\*\\) .*:imp:"
       (1 (compose-region (- (match-end 1) 1)
                          (match-end 1)
                          "" ; "☀"
                          )
          nil))))))
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"
  '(progn
     (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."
                   (interactive)
                   (call-interactively #'org-agenda-switch-to)
                   (foldout-zoom-subtree)
                   (org-back-to-heading)))

     (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)))
                     (org-agenda-goto)
                     (org-narrow-to-subtree)
                     (org-back-to-heading)
                     (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."
  (interactive)
  (let ((first-heading-or-end
         (save-excursion
           (goto-char 1)
           (unless (org-at-heading-p)
             (outline-next-heading))
           (point))))
    (unless (= 1 first-heading-or-end)
      (org-flag-region 1 first-heading-or-end t 'outline))))

beginning/end -of-defun.

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

org-num-mode

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

packages

package managers

straight

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)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (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" . "http://elpa.gnu.org/packages/") t)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
;; (add-to-list 'package-archives '("RSW-Packages" . "http://www.plasmas.biz/rswe/") t)

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

packages

non-straight

org-reveal

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)
folding.el

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

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

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
 (package-initialize)
 (unless (package-installed-p 'hyperbole)
   (package-refresh-contents)
   (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.
                                    'org-time-stamp)))
(eval-after-load "org"
  '(progn
     (org-defkey org-mode-map (kbd "C-c r") #'org-reveal)))
;; override a binding of hyperbole for org-mode

straight

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")
history
  • [2014-04-07 Mon 22:26] Just installed a package that might help with

AUR-packages.

impatient-mode
what
  • 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)
evil-numbers

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.

haskell-mode

support for writing haskell programs.

(straight-use-package 'haskell-mode)
avy

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)
    (avy-goto-line-below)))

(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

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

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

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

expand-region helps to expand the region.

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

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
			 #'previous-buffer)
(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)
				  (mw-translate-as-message-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."
				(interactive)
				(if (get-buffer "*Org Agenda*")
				    (switch-to-buffer (get-buffer "*Org Agenda*"))
				  (org-agenda-list))))
(key-chord-define-global "kx" (lambda () (interactive)
				(if (eq major-mode 'org-mode)
				    (org-edit-special)
				  (org-edit-src-exit))))
(key-chord-define-global "1'" #'org-previous-visible-heading)
(key-chord-define-global "jk" (lambda () (interactive)
				(cond
				 ((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")
				(ariadne-marks-unset)
				(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 ()
				(interactive)
				(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

Hydra provides some convenient key maps organization.

(straight-use-package 'hydra)
geiser
package provision

“emacs and scheme talk to each other”

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

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)
(ido-mode)
(when ido-enable-regexp
  (ido-toggle-regexp))
(ido-hacks-mode)
filladapt

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?
dired-narrow

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)
auto-correct
(straight-use-package 'auto-correct)
quarter-plane
(straight-use-package 'quarter-plane)
gited

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)))
lua-mode
(straight-use-package 'lua-mode)

lua-mode

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

access passwords via emacs.

(straight-use-package 'password-store)
herald-the-mode-line

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)
async
(straight-use-package 'async)
(eval-after-load "dired-async"
  '(dired-async-mode 1))
slime
the package slime
(straight-use-package 'slime)
(eval-after-load "slime"
  '(progn
     (setq inferior-lisp-program "sbcl")
     (setq slime-contribs '(slime-fancy))
     (setq common-lisp-hyperspec-root
	     "file:///home/b/media/texts/it/languages/lisp/HyperSpec/")))
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 “http://www.lispworks.com/reference/HyperSpec/

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

(straight-use-package
 '(go-up
   :type git
   :host gitlab
   :repo "marcowahl/go-up"))
paredit

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
  '(progn
     (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 ()
  (string=
   (with-temp-buffer
     (insert "a")
     (goto-char 2)
     (call-interactively #'mw-paredit-elevate)
     (buffer-string))
   "a"))

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

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


(defun mw-paredit-elevate ()
  "Move sexp at point at backward up location."
  (interactive)
  (catch 'top-paren-level
    (paredit-handle-sexp-errors (paredit-enclosing-list-start)
      (throw 'top-paren-level nil))
    (kill-sexp)
    (paredit-backward-up)
    (yank)))
enable paredit in some cases
(mapc
 (lambda (x) (add-hook x #'paredit-mode))
 '(lisp-mode
   lisp-interaction-mode-hook
   emacs-lisp-mode-hook
   slime-repl-mode-hook
   eval-expression-minibuffer-setup-hook))
underline-with-char
(straight-use-package 'underline-with-char)
wrap-region

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)
form-feed-mode

display page breaks nicely.

(straight-use-package 'form-feed)

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

ztree
(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)

(global-company-mode)
magit

magit is an interface to git.

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

a test framework for elisp.

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

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

from source

org-bullets

(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)
(global-lentic-mode)

beginend

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)

bbdb

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 [[gnus:nntp+news.gmane.org:gmane.emacs.bbdb.user#m28u2z8m57.fsf@charm-ecran.irisa.fr][Email from Alan Schmitt: Re: can I auto save the bbdb f]]
;; ...[2016-02-05 Fri 13:15]


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

various

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."
  (interactive)
  (let ((shell (eshell)))
    (set-buffer shell)
    (end-of-buffer)
    (insert "sudo mount /dev/sdb1 /mnt")
    (switch-to-buffer shell)
    (eshell-send-input)))
(defun mw-umount-typical ()
  "Prepare umount the typical drive via eshell."
  (interactive)
  (let ((shell (eshell)))
    (set-buffer shell)
    (end-of-buffer)
    (insert "sudo umount /mnt")
    (switch-to-buffer shell)
    (eshell-send-input)))

just one space line

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

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."
  (interactive)
  (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."
  (interactive)
  (cl-assert (eq major-mode 'eww-mode))
  (browse-url-firefox (plist-get eww-data :url)))

(require 'eww)
(eval-after-load "eww"
    '(progn
      (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

eww

(defun mw-eww-trigger-with-region-text ()
  "Trigger eww with current region as input."
  (interactive)
  (eww (buffer-substring
        (region-beginning)
        (region-end))))
(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.

(eval-after-load
 "eww"
 '(progn
    (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
                 shr-external-browser)))
          (eww-browse-with-external-browser))))
      (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."
  (interactive)
  (eww w3m-current-url))
(defun mw-eww-switch-to-w3m ()
  "Switch to w3m from eww."
  (interactive)
  (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)
     (end-of-line)
     (setq maxi (max maxi (current-column)))
     (forward-line 1))
    (goto-char pt)
    maxi))

(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)
  (rectangle-forward-char
   (- (mw-longest-line-length-in-rectangle start end)
      (current-column))))

convert table to tsv

(defun mw-org-table-convert-to-tsv ()
  "Convert table to tab separated values."
  (interactive)
  (let ((table (org-table-to-lisp
	        (buffer-substring-no-properties
	         (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

(add-hook
 'org-mode-hook
#'org-num-mode)

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'."
  (interactive)
  (let ((cal-date (with-current-buffer "*Calendar*"
                    (save-match-data
                      (calendar-cursor-to-date))))
        (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)
      (deactivate-mark)))

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))
        (end-of-line)))
    t))
(add-hook
 'org-metareturn-hook 'mw-org-insert-item-with-ina-ts-when-on-such-item)

org-pretty-tags

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 ()
  (interactive)
  (push-mark)
  (find-file "~/p/elisp/mw/.emacs.d/readme.org"))

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)
  (with-temp-buffer
    (insert string)
    (mw-espeak-en-region (point-min) (point-max))))

(defun mw-espeak-de-string (string)
  (with-temp-buffer
    (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
embedded."
  (interactive "r")
  (if calc-embedded-info
      (widen)
    (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."
  (interactive)
  (let* ((current-win (selected-window))
         (other-win
          (get-window-with-predicate
	   (lambda (window)
             (and (not (eq current-win window))
	          (with-current-buffer (window-buffer window)
	            (eq major-mode 'dired-mode))))))
         (filename
          (and other-win
               (let ((point-in-other
                      (window-point other-win)))
                 (with-current-buffer (window-buffer other-win)
                   (save-excursion
                     (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]

https://github.com/tonsky/FiraCode/wiki/Setting-up-Emacs https://gist.github.com/mordocai/50783defab3c3d1650e068b4d1c91495

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 ()
                   (compose-region
                    (match-beginning 1)
                    (match-end 1)
                    ,(concat (char-to-string ?\t)
                             (list
                              (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.

source: https://github.com/tonsky/FiraCode/wiki/Setting-up-Emacs

;;(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

(add-hook
 'pdf-view-mode-hook
 (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

(add-hook
 'image-mode-hook
 (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."
  (start-process
   "" "*mw-amixer*" "amixer" "set" "Master"
   (format "%d%%" (max 0 (min 100 percent)))))

(defun mw-sound-100% ()
  "100% sound."
  (interactive)
  (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."
  (interactive)
  (mw-sound-master-pecentage 30)
  (message "personal sound level set"))

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

keys-chords for org-mode

(add-hook
 'org-mode-hook
 (lambda ()
   <<55d1db28e5099601def016f605ce12af1f8ddc48-sha1-of-code>>
   <<8b0de79c259534f4efdd1dfbada8eecd77991e45-sha1-of-code>>))

attach screenshot as standard attachment

(key-chord-define-local
 "t1" #'mw-org-attach-screenshot-as-standard-attachment)

key chord for org outline path

(key-chord-define-local
 "o7" (lambda () (interactive) (org-display-outline-path nil t)))

emms

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.
(emms-default-players)
(eval-after-load 'info
  '(progn (info-initialize)
          (add-to-list 'Info-directory-list "~/p/elisp/external/emms/doc")))

diary

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-

call.

    -!-[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)))
        (time
         (apply #'encode-time
                (reverse
                 (let
                     ((timelist
                       (math-date-to-dt
                        (math-parse-date
                         string))))
                   (append timelist
                           (make-list (- 6 (length timelist)) 0))))))
        (with-hm t)
        (inactive t))
    (delete-region start end)
    (org-insert-time-stamp
     time
     with-hm
     inactive)))

(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)
(global-set-key
 [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-\\|
\\|\240\\|\\(^[+-]\\)\\)+")

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 .

toot

https://mastodon.sdf.org/@marcowahl/100151693344816513

emr

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")
    #'emr-show-refactor-menu))

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.

config

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.

auxies

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.

auxies-eww

(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))
           (seq-find
            (lambda (x) (string-match-p "^user:" x))
            (s-lines (password-store--run-show entry))
            nil))))
    (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")
  (async-shell-command
   (buffer-substring-no-properties
    start end)))

pdf-tools

(straight-use-package 'pdf-tools)

delete trailing ws on save

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

(push
 (lambda ()
   (delete-trailing-whitespace))
 before-save-hook)

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."
  (interactive)
  (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."
  (interactive)
  (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.

(ffap-bindings)
(global-set-key
 "��"
 (lambda(&optional prefix)
   (interactive "P")
   (call-interactively
    (if prefix
        #'ido-find-file
      #'find-file-at-point))))

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
`org-agenda-drag-line-forward'.

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."
  (interactive)
  (let ((inhibit-read-only t))
    (if (region-active-p)
        (delete-region
         (save-excursion
           (goto-char (region-beginning))
           (beginning-of-line)
           (point))
         (progn
           (goto-char (region-end))
           (when (or (not (= (region-end)
                             (save-excursion
                               (goto-char (region-end))
                               (beginning-of-line)
                               (point))))
                     (= (point) (mark)))
             (forward-line))
           (point)))
      (move-beginning-of-line 1)
      (delete-region
       (point)
       (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"
  '(progn
     (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."
                   (widen)
                   (when (= 0 (forward-line))
                     (mw-narrow-to-line))))
     (org-defkey org-agenda-mode-map (kbd "M-p")
                 (lambda ()
                 "Narrow to line above.  Widen when on top."
                 (interactive)
                   (widen)
                   (when (= 0 (forward-line -1))
                     (mw-narrow-to-line))))
     (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")))))

timeclock

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
'mw-ephemeral-enumerate-visual-lines-in-region)

org-supplements

My little collection of Emacs stuff.

(assert
 (not
  (reduce
   (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.

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

enable global-prettify-symbols-mode

(global-prettify-symbols-mode)

foldout

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")
  (cl-letf
      (((symbol-function #'outline-show-entry) (lambda () (org-show-entry))))
    (foldout-zoom-subtree exposure)
    (org-cycle)))
[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."
  (interactive)
  (async-start
     `(lambda ()
        (require 'org)
        (org-babel-tangle-file ,buffer-file-name))))

pomodoro

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: http://www.couchet.org/blog/index.php?post/2010/08/04/Pomodoro-et-org-mode 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
                  org-timer-countdown-timer)
                 (progn
                   (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 ()
  (interactive)
  (message "%s" mw-pause-state)
  mw-pause-state)

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

(add-hook
 'org-timer-done-hook
 '(lambda ()
    (if mw-pause-state
        (progn
          (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
                                    "~/media/sound/birds/Canary-animals065.wav"
                                    ))
                                        ;(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].
      (with-temp-buffer
        (org-mode)
        (mw-org-trigger-timer-for-pause
         (if (= 0 (% *mw-pomodoros-completed-in-session*
                     *mw-pomodoros-before-longer-break*))
             *mw-pomodoro-longer-pause-duration*
           *mw-pomodoro-pause-duration*)))
      (setq mw-background-color-before-tomato-pause
            (frame-parameter (selected-frame) 'background-color))
      (set-background-color (frame-parameter (selected-frame) 'foreground-color))
      (message
       "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*"
                     "espeak"
                     "-v"
                     ;; "en-swedish"
                     "en"
                     "-s"
                     "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."
  (interactive)
  (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
s RET
s RET

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

s mysearchstring
a
a
(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."
  (interactive)
  (let ((element (org-element-at-point)))
    (catch 'found
      (while  element
        (when (member (car element) '(src-block verse-block))
          (push-mark
           (save-excursion
             (goto-char (org-element-property :end element))
             (skip-chars-backward "\n\t ")
             (forward-line 0)
             (point))
           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."
  (save-excursion
    (let ((element (org-element-at-point)))
      (while (and element (not (member (car element) '(src-block))))
        (setq element (plist-get (cadr element) :parent)))
      element)))
(defun mw-org-mark-src-block-content ()
  "Mark source block without the delimitter lines."
  (interactive)
  (deactivate-mark)
  (let ((element (mw-org-at-src-block-at-point)))
    (when element
      (push-mark
       (save-excursion
         (goto-char (org-element-property :end element))
         (skip-chars-backward "\n\t ")
         (forward-line 0)
         (point))
       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."
  (interactive)
  (mw-org-mark-src-block-content)
  (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."
  (interactive)
  (org-babel-next-src-block)
  (mw-org-babel-direct-eval-src-block-as-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."
  (interactive)
  (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)
    (mw-just-one-blank-line))
  (while (outline-next-heading)
    (org-end-of-meta-data t)
    (mw-just-one-blank-line)))

This function could be used at each save.

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

abbrevs

Want abbrevs everywhere.

Started with the suggestion about abbreviations on http://www.star.bris.ac.uk/bjm/emacs-tips.html#sec-1-19.

(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)
(global-set-key
 (kbd "C-x C-&")
 (lambda (&optional arg)
   (interactive "P")
   (apply
    (if arg
        #'fts-max-font-size-see-line
      #'fts-max-font-size-see-lines)
    nil)))
(global-set-key
 (kbd "C-x C-*")
 (lambda (&optional arg)
   (interactive "P")
   (fts-max-font-size-see-buffer)))

rotate windows

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

Originates from gnu.emacs.help group 2006."
  (interactive)
  (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))
		(t
		 (delete-window w1)
		 (set-window-buffer (split-window-vertically) b1))))
      (message "Root window not split"))))

deadgrep

deadgrep is an interface to ripgrep.

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

ariadne

(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 ()
  (interactive)
  (save-excursion
    (let
        ((poi (point))
         (start (progn
                  (move-to-window-line 0)
                  (point)))
         (end (progn
                (move-to-window-line -1)
                (point))))
      (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))
        (animate-string
         "E m a c s" (line-number-at-pos)
         (current-column)))
      (sit-for 0.1))
    (kill-buffer)))

move point some

(defun mw-dance-around-the-cursor-b ()
(interactive)
(save-excursion
  (cl-loop for ii from 1 to 20 do
           (backward-char)
           (sit-for 0.01))
    (cl-loop for ii from 1 to 20 do
           (forward-char)
           (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))
      (set-mouse-position
       (selected-frame)
       (+ (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 ()
  (interactive)
  (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 ()
  (interactive)
  (if (org-before-first-heading-p)
      (goto-char (point-max))
    (outline-end-of-subtree)))

key

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

hidden mode line

Found the following mode line hiding function at http://bzg.fr/emacs-hide-mode-line.html. (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))
  (force-mode-line-update)
  ;; Apparently force-mode-line-update is not always enough to
  ;; redisplay the mode-line
  (redraw-display)
  (when (and (called-interactively-p 'interactive)
             hidden-mode-line-mode)
    (run-with-idle-timer
     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 ()
  (interactive)
  (dolist (buffer (buffer-list))
    (set-buffer buffer)
    (unless hidden-mode-line-mode
      (hidden-mode-line-mode))))

(defun mw-hidden-mode-line-deactivate-for-all ()
  (interactive)
  (dolist (buffer (buffer-list))
    (set-buffer buffer)
    (when hidden-mode-line-mode
      (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."
  (interactive)
  (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"
                   (with-temp-buffer
             (insert "foo bar baz
")
             (goto-char 1)
             (mw-reverse-line)
             (buffer-substring 1 12)))))

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

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."
  (interactive)
  (org-back-to-heading t)
  (org-cut-special)
  (go-up)
  (mw-org-end-of-subtree)
  (org-yank)
  (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.."
 (interactive)
 (org-back-to-heading t)
 (unless (org-first-sibling-p)
  (let (up-pos )
    (save-excursion
      (go-up)
      (setq up-pos (point)))
    (org-cut-special)
    (goto-char up-pos)
    (outline-next-heading)
    (org-yank))))

plain lists

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

both

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."
  (interactive)
  (cond
   ((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."
  (interactive)
  (cond
   ((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."
  (interactive)
  (save-excursion
    (mw-org-move-subtree-or-item-to-bottom)))
(defun mw-org-move-subtree-or-item-to-top-keep-point ()
  "Position subtree or item at point at the top of the list."
  (interactive)
  (save-excursion
    (mw-org-move-subtree-or-item-to-top)))

first child to end

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

private

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)))

hooks

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)))

dired

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

agenda

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."
  (org-agenda-clock-goto))

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

agenda gets only window

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

shortcuts

keysettings

org agenda

(eval-after-load "org-agenda"
  '(progn
     (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))))

edit-last-kbd-macro

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

winner

change window layout with prominent keys.

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

multi-occur

Find occurrences in several buffers.

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

imenu

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

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

iedit

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-;).

rectangle

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

org

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-)
(eval-after-load
    "org"
  '(progn
     (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.

(eval-after-load
    "org"
  '(progn
     (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 ()
        (interactive)
        (if emms-player-playing-p
            (emms-player-pause)
          (progn
            (mw-sound-set-enjoyable-volume)
            (emms-play-url "http://www.bassdrive.com/BassDrive.m3u")))))
    (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")))
        map))
    (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*")
                            (calendar))))
    (define-key map "q" (lambda (arg)
                          (interactive "P")
                          (if (equal arg '(4))
                              (unbury-buffer)
                            (bury-buffer))))
    (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)
        map))
    (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))
    ;;                           ))
    map)
  "Personal convenience keymap.")
(global-set-key (kbd "\C-z") mw-individual-keymap)

hydras

winner

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))
faces
(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."
(interactive)
  (setq val (or val 255))
  (set-face-attribute
          'default nil
          :height val))
(defun mw-increase-face-height ()
  (interactive)
  (let ((before-height (face-attribute 'default :height)))
    (cl-loop while (and (< change 42)
                        (= before-height (face-attribute 'default :height)))
             with change = 1
             do (progn
                  (set-face-attribute
                   '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 ()
  (interactive)
  (let ((before-height (face-attribute 'default :height)))
    (cl-loop while (and (< change 42) (= before-height (face-attribute 'default :height)))
             with change = 1
             do (progn
                  (set-face-attribute
                   '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))
   "info")
  ("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.

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

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

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

enhance keys for buffer list

i
switch to ibuffer.
N
scroll-up 1.
>
go to the last line.
  • With M-> point goes to the last char (and not one before that.)
(add-hook
 'Buffer-menu-mode-hook
 (lambda ()
   (local-set-key
    ">" (lambda () (interactive)
          (end-of-buffer)
          (backward-char)))
   (local-set-key
    "N" (lambda () (interactive)
          (scroll-up 1)))
   (local-set-key
    "P" (lambda () (interactive)
          (scroll-down 1)))
   (local-set-key
    "i" (lambda () (interactive)
          (ibuffer)))))

enhance keys for ibuffer

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

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")
  (funcall
   (if arg
       (function mw-message-last-command)
     (function mw-repeat-last-command))))

(global-set-key
 (kbd "C-6")
 #'mw-direct-command-repeat)

(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
  inactive-timestamps-display."
    (interactive "P")
    (cond
     ((eq major-mode 'org-agenda-mode)
      (setq org-agenda-include-inactive-timestamps (eq nil org-agenda-include-inactive-timestamps))
      (org-agenda-redo))
     (t
      (cond
       ((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 "'.")
     (interactive)
     (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.

code


(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

menu-bar-mode

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.

help:dired-dwim-target

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

&%%(diary-sunrise)
&%%(diary-sunset)

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)))
    (format
     "%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)))
    (format
     "%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-setup))
  (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-setup))
  (solar-sunset-string date))

Direct call like so:

(let ((date (calendar-current-date)))
 (diary-sunrise-sunset))

patches

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.

code

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

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

code

(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)
           (progn
             (org-show-all)
             (mw-org-hide-above-first-heading)
             (when (save-excursion (outline-next-heading))
               (outline-hide-sublevels (or arg 1))))
         (outline-hide-subtree)
         (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."
  (interactive
   (let* ((today (calendar-current-date))
          (year (calendar-read
                 "Julian calendar year (>0): "
                 (lambda (x) (> x 0))
                 (number-to-string
                  (calendar-extract-year
                   (calendar-julian-from-absolute
                    (calendar-absolute-from-gregorian
                     today))))))
          (month (calendar-read
                 "Julian calendar month: "
                 (lambda (x) (and (<= 1 x) (<= x 12)))
                 (number-to-string
                  (calendar-extract-month
                   (calendar-julian-from-absolute
                    (calendar-absolute-from-gregorian
                     today))))))
          (last
           (if (and (zerop (% year 4)) (= month 2))
               29
             (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))
        diary-included-files))
(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))))
    (unwind-protect
	(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)
				   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))
			to-state)
		       ((eq interpret 'type) org-last-state)
		       (head)
		       (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
		      (save-excursion
			(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)
					      (current-time))))
	  (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))
				 org-last-state
				 org-log-repeat)))
	  (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:"
			     (save-excursion
			       (re-search-backward
				planning-re (line-beginning-position) t)
			       (match-string 0)))))
		(cond
		 ;; 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]\\)"
				     ts))
		  (when (equal type org-scheduled-string)
		    (org-remove-timestamp-with-keyword type)))
		 (t
		  (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\\}"
						    ts)))
		      (user-error
		       "Cannot repeat in Repeat in %d hour(s) because no hour \
has been set"
		       n))
		    ;; 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))))
			(cond
			 ((equal (match-string 1 ts) ".")
			  ;; Shift starting date to today
			  (org-timestamp-change
			   (- (org-today) (time-to-days time))
			   'day))
			 ((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? "
					     nshift))
				    (user-error "Abort")))
			      (org-timestamp-change n (cdr (assoc what whata)))
			      (org-in-regexp org-ts-regexp3)
			      (setq ts (match-string 1))
			      (setq time
				    (save-match-data
				      (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]\\)"
					ts)))))
		    (save-excursion
		      (org-timestamp-change n (cdr (assoc what whata)) nil t))
		    (setq msg
			  (concat
			   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*."
    (interactive)
    (save-window-excursion
      (let ((f (selected-frame))
            (outbuf (get-buffer-create "*zone*"))
            (text (buffer-substring (window-start) (window-end)))
            (wp (1+ (- (window-point)
                       (window-start)))))
        (let ((win-0 (selected-window)))
          (while (not (equal win-0 (progn
                                     (other-window 1 t)
                                     (selected-window))))
            (switch-to-buffer "*zone*" )))
        (put 'zone 'orig-buffer (current-buffer))
        (switch-to-buffer outbuf)
        (setq mode-name "Zone")
        (erase-buffer)
        (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)))
                                restore)))
          ;; Make `restore' a self-disabling one-shot thunk.
          (setq restore `(lambda () ,@restore (setq restore nil)))
          (condition-case nil
              (progn
                (message "Zoning... (%s)" pgm)
                (garbage-collect)
                ;; 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)
                    (discard-input))
                (zone-call pgm)
                (message "Zoning...sorry"))
            (error
             (funcall restore)
             (while (not (input-pending-p))
               (message "We were zoning when we wrote %s..." pgm)
               (sit-for 3)
               (message "...here's hoping we didn't hose your buffer!")
               (sit-for 3)))
            (quit
             (funcall restore)
             (ding)
             (message "Zoning...sorry")))
          (when restore (funcall restore)))))))

epilogue

actions

display time

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

activate appointments

with

(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.

pinentry

(pinentry-start)

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*"
               "espeak"
               "-v"
               ;; "en-swedish"
               "en"
               "-s"
               "155" ;; word speed
               "Hi guys! This is a fantastic day! Let's do something!")

hints

gnus-summary-toggle-header

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

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")
                chronos-expiry-functions
                '(chronos-buffer-notify
                  chronos-text-to-speech-notify
                  (lambda (c)
                    ;; (browse-url-firefox
                    ;; "https://www.vevo.com/watch/amy-winehouse/in-my-bed/GB0700400018"
                    ;;  )
                    (unless *mw-timer*
                      (setq *mw-timer*
                       (run-at-time
                        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

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.

mmm-mode

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

(use-package mmm-mode
  :ensure t
  :config
  (progn
    (setq mmm-global-mode 'maybe)
    (mmm-add-classes
     '((embedded-org-elisp
        :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

camcorder

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

hungry-delete

(use-package hungry-delete
  :ensure t)

slime-company

(use-package slime-company
 :ensure t)

elm-mode

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

interleave

package
(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’.”

ace-link

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.

swiper

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

keyfreq

From the documentation at https://github.com/dacap/keyfreq:

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

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

auth-password-store

[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))

avy-zap

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)))

on-screen

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))

browse-kill-ring

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

lispy

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

(setf
 lispy-mode-hook
 (lambda ()
   (key-chord-define-local "[0" (lambda () (interactive) (insert "[")))
   (key-chord-define-local "]1" (lambda () (interactive) (insert "]")))))

smartparens

[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

gnorb is integration of gnus and org and bbdb .

(use-package gnorb
  :ensure t)

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

(eval-after-load "gnorb-bbdb"
  '(progn
     (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"
  '(progn
     (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"
  '(progn
     (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)
           gnus-mime-action-alist)
     ;; 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")
           gnus-mime-button-commands)
     (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)))
             map))))

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

rase

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)
  (cond
   (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))
                    (mw-set-night-theme)
                  (mw-unset-night-theme))))
   ((eq sun-event 'sunrise) (mw-unset-night-theme))
   ((eq sun-event 'sunset) (mw-set-night-theme))))

(use-package rase
  :ensure t
  :config
  (add-hook
   'rase-functions
   #'hook-for-rase-sun-event-theme-switch)
  (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.
  )

helm

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.

gnuplot

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))))

sotlisp

Helpful for jumping around!

(use-package sotlisp
  :ensure t)

nyan-mode

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

git-auto-commit-mode

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

epa

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

beacon

(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))

elmacro

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

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

git-timemachine

(use-package git-timemachine
  :ensure t)

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

refine

Package for editing lists.

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

j-mode

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

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

wcheck-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])
  (el-search-install-shift-bindings))
(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)

ert-runner

i had problems with straight and this package.

(use-package ert-runner
  :ensure t)

zeitgeist

  • 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

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.

code

(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)))
    table)
  "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."
  (interactive)
  (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 <nik@ngo.org.uk> Subject: company-mode completions for noweb references Newsgroups: gmane.emacs.orgmode To: emacs-orgmode <emacs-orgmode@gnu.org> Date: Tue, 6 Nov 2018 19:32:20 +0100 Archived-At: http://permalink.gmane.org/gmane.emacs.orgmode/122299

[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

code

(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)))
    (candidates
     (org-element-map (org-element-parse-buffer) 'src-block
       (lambda (src-block)
         (let ((name (org-element-property :name src-block)))
           (when name
             (propertize
              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)

syntactic-close

a project from Emacs berlin.

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

skip over whitespace

keys to skip over whitespace.

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

(global-set-key
 (kbd "C-S-b")
 (lambda ()
   (interactive)
   (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."
  (interactive)
  (save-match-data
    (assert (org-at-timestamp-p 'lax) t "Not at a timestamp.")
    (save-excursion
      (let ((beg (match-beginning 0)))
        (goto-char beg)
        (if (looking-at-p org-ts-regexp-inactive)
            (org-time-stamp-inactive)
          (org-time-stamp nil))))))

kill fap

(defun mw-filename-at-point-kill ()
  (interactive)
  (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."
  (interactive)
  (kill-new (mapconcat #'identity
                       (dired-get-marked-files)
                       "
")))

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)))
    (cond
     ((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."
  (interactive
   (list (prefix-numeric-value current-prefix-arg)
         (read-file-name "Enter diary file name: " default-directory nil t)))
  (let ((diary-file dfile))
    (calendar)))

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.

e.g.

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

el-csv

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:                                             |
+------+----------------------------------------------------------------+
|657649|5339dc78461f0abaf12ac2facc98be33cdb2ec41.IMG_20180617_143738.jpg|
+------+----------------------------------------------------------------+
|521702|86f8d165cf726b172ac3a1882f94bd8d4fc22a27.IMG_20180617_143750.jpg|
+------+----------------------------------------------------------------+
|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)
  (interactive
   (list
    (completing-read
     "choose diary-file: "
     '("~/org/diary"
       "~/org/diary.d/diary-2014"
       "~/org/diary.d/diary-2015"
       "~/org/diary.d/diary-2016"
       "~/org/diary.d/diary-2018"
       "~/org/diary.d/diary-environmental"
       "~/org/diary.d/diary-personal"
       "~/org/diary.d/diary-personal-repeating"
       "~/org/diary.d/ib-1516"
       "~/org/diary.d/ib-1617"
       "~/org/diary.d/ib-1718"))))
  (setq diary-file file))

make personal diary entry

(defun mw-diary-make-personal-entry-for-today (&optional nonmarking)
  "Insert entry in personal diary file."
  (interactive)
  (diary-make-entry
   (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."
  (interactive)
  (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."
  (interactive)
  (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)

drawers

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."
  (interactive)
  (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."
  (interactive)
  (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)
    (save-excursion
      (let ((stopper (min
                      (save-excursion
                        (move-to-window-line -1)
                        (point))
                      end))
            (ctr 0))
        (goto-char start)
        (end-of-visual-line)
        (while (< (point) stopper)
          (end-of-visual-line 2)
          (incf ctr))
        (message "%d" ctr)
        ctr))))
(defalias 'mw-region-count-visual-lines #'mw-count-visual-lines-in-region)

narrow-to-line

(defun mw-narrow-to-line ()
"Narrow to line containing point."
(interactive)
(save-excursion
  (narrow-to-region
   (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 ()
  (interactive)
  (let ((data (org-element-parse-buffer)))
    (org-element-map data '(src-block example-block verbatim-block verse-block)
      (lambda (ele)
        (put-text-property
         (save-excursion
           (goto-char (org-element-property :begin ele))
           (beginning-of-line 2)
           (point))
         (save-excursion
           (goto-char (org-element-property :end ele))
           (end-of-line -1)
           (point))
         'line-prefix "\t")))))
(defun mw-org-whitespace-unprefix-blocks ()
  (interactive)
  (let ((data (org-element-parse-buffer)))
    (org-element-map data '(src-block example-block verbatim-block verse-block)
      (lambda (ele)
        (set-text-properties
         (save-excursion
           (goto-char (org-element-property :begin ele))
           (beginning-of-line 2)
           (point))
         (save-excursion
           (goto-char (org-element-property :end ele))
           (end-of-line -1)
           (point))
         nil)))))

reverse org subtrees

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

little-code-things

(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."
  (interactive)
  (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”))

fa3d101c53b5fb94-uniquefoo

(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 ])

quit-emacs

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

timezone conversion to current tz

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

e.g.

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

hide-common-indent

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

M-?

(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."
  (interactive)
  (let* ((filename (dired-get-filename))
         (new-name
          (with-temp-buffer
            (start-process
             "<sha1sum>"
             (current-buffer)
             "sha1sum"
             (file-name-nondirectory filename))
            (sit-for 0.01) ; wait for the buffer to be filled with the
                           ; result.
            (goto-char (point-min))
            (end-of-line)
            (delete-region (point) (point-max))
            (goto-char (point-min))
            (replace-regexp " " "-")
            (buffer-string))))
    (rename-file
     filename
     (concat (file-name-directory filename) new-name) nil))
  (revert-buffer))

major-mode-stack

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."
  (interactive)
  (let ((current-buf (current-buffer)))
    (with-temp-buffer
      (org-mode)
      (insert-buffer-substring current-buf)
      (goto-char (point-min))
      (unless (outline-on-heading-p)
          (outline-next-heading))
      (org-demote-subtree)
      (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)
        (org-demote-subtree)
        (goto-char (point-min)))
      (goto-char (point-min))
      (org-cut-subtree))))

koma letter

(eval-after-load 'ox-koma-letter
  '(progn
     (add-to-list 'org-latex-classes
                  '("mw-letter-private"
                    "\\documentclass\{scrlttr2\}
          \\usepackage[german]{babel}
          \\setkomavar{frombank}{DE35\\,7001\\,0080\\,0667\\,9338\\,02}"))
     (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")
  (insert
   (let ((result (calc-eval (buffer-substring start end))))
     (delete-region start end)
     result)))

remove logbook drawer

(defun mw-org-log-delete ()
  "Delete logbook drawer of subtree."
  (interactive)
  (save-excursion
    (goto-char (org-log-beginning))
    (when (save-excursion
            (save-match-data
              (beginning-of-line 0)
              (search-forward-regexp org-drawer-regexp)
              (goto-char (match-beginning 1))
              (looking-at "LOGBOOK")))
      (org-mark-element)
      (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."
  (interactive)
  (condition-case nil
      (while t
        (backward-up-list))
    (error nil)))

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

(defun mw-eval-outermost-sexp ()
  "Evaluate the outermost sexp starting from point."
  (interactive)
  (mw-forward-up-list-as-far-as-possible)
  (call-interactively #'eval-last-sexp))

emms toggle on/off

(defun emms-on-or-off ()
  "Toggle start/stop emms."
  (interactive)
  (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
  '(progn
     (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."
  (interactive)
  (unless (eq 'dired-mode major-mode)
    (user-error
     (concat
      "Buffer is not in dired-mode.  "
      "Command applies only in dired-mode")))
  (save-excursion
    (dired-mark-files-regexp "^\\.")
    (dired-do-kill-lines)))

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 ()
  (interactive)
  (when (region-active-p)
    (if (< (mark) (point))
        (exchange-point-and-mark))
    (org-next-link)
    (let ((link-found-in-range
           (and (not org-link-search-failed)
                (< (point) (mark)))))
      (while (and (not org-link-search-failed)
                  (< (point) (mark)))
        (split-window)
        (org-open-at-point)
        (call-interactively #'other-window)
        (org-next-link))
      (if link-found-in-range
          (delete-window)))))

(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))
    (async-shell-command
     (format "espeak -v de -s 110 \"%s\""
             (buffer-substring
              (save-excursion
                (backward-word)
                (point))
              (point))))))

(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)
        (mw-espeak-previous-word)))))
;(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."
  (reduce
   (lambda (x y) (and x y))
   (mapcar (lambda (x) (if x t nil))
           (mapcar (lambda (x) (member x set_t))
                   set_s))
   :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.
      nil
      :global t
      :lighter (:eval (if mw-pause-state
                          (propertize " [pause]" 'face '(:foreground "red"))
                        " [no.right.now]"))
      :group 'pause-indication)
(pause-indication-mode)

adjust region to in/exclude empty lines around

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

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

(defun mw-region-exclude-top-empty-lines (start end)
  (interactive "r")
  (unless (= (point) start)
    (exchange-point-and-mark))
  ; 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
bottom."
  (interactive)
  (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."
  (interactive)
  (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))
    (exchange-point-and-mark))
  (beginning-of-line))

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."
  (mw-region-include-top-exclude-bottom-empty-lines))

image-cache

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)))

gnus

  • [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)

ledger

source

  • [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 http://unconj.ca/blog/using-hledger-with-ledger-mode.html
;; 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."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (replace-regexp
     "^
*\\([[:digit:]]\\{4\\}/[[:digit:]]\\{2\\}/[[:digit:]]\\{2\\}\\)"
     "
\\1")
    (save-restriction
      (widen)
      (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."
  (interactive)
  (let* ((extents (ledger-navigate-find-xact-extents (point)))
         (transaction (buffer-substring-no-properties (car extents) (cadr extents))))
    (ledger-navigate-end-of-xact)
    (insert "\n\n" transaction)
    (ledger-navigate-beginning-of-xact)))

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")

history

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

hide-parts

(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/tmp.org")
(defun org-mw-capture-template-function () "* haha 2\n")

skeletons for inserting org source blocks

general src block

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

This definition goes together with an abbrevs section

(org-mode-abbrev-table)

"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 ""
  \n
  "#+begin_src emacs-lisp" \n  _ \n
  "#+end_src")

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."
  (interactive)
  (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.
(eval-after-load
    'image-mode
  '(progn
     (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):

Before

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

After

    -!-2017/10/07-m-
"
  (interactive "r")
  (let ((time
         (apply #'encode-time
                (reverse
                 (let
                     ((timelist
                       (math-date-to-dt
                        (math-parse-date
                         (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

following https://oremacs.com/2017/10/04/completion-at-point/

(defun org-completion-symbols ()
  (when (looking-back "=[a-zA-Z]+")
    (let (cands)
      (save-match-data
        (save-excursion
          (goto-char (point-min))
          (while (re-search-forward "=\\([a-zA-Z]+\\)=" nil t)
            (cl-pushnew
             (match-string-no-properties 0) cands :test 'equal))
          cands))
      (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
                                       '(org-completion-symbols
                                         ora-cap-filesystem))))

table-lamp

(defun table-lamp ()
  (interactive)
  (make-frame-command)
  (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."
  (interactive)
  (narrow-to-region
   (point)
   (save-excursion
     (outline-next-heading)
     (point)))
  (let ((pos
         (save-excursion
           (while
               (and
                (search-forward-regexp org-drawer-regexp nil nil)
                (not (string= "logbook" (downcase (match-string 1))))))
           (when (string= "logbook" (downcase (match-string 1)))
             (point)))))
    (when pos
      (goto-char pos)
      (org-narrow-to-drawer)
      (org-reveal))))

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)

source

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."
  (interactive)
  (org-clock-goto)
  (org-todo))

filler text

German “Blindtext”.

(defmacro make-times (arg &rest body)
  "Repeat BODY ARG times. "
  `(dotimes (_ ,arg)
     ,@body))
(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)
    (make-times
     (1- arg)
     (newline)
     (newline)
     (insert text))))

keymaps for org babel blocks

see http://kitchingroup.cheme.cmu.edu/blog/2017/06/10/Adding-keymaps-to-src-blocks-via-org-font-lock-hook/

(require 'lispy)

(setq scimax-src-block-keymaps
      `(("emacs-lisp" . ,(let ((map (make-composed-keymap `( ; ,lispy-mode-map
                                                            ,emacs-lisp-mode-map
                                                            ,outline-minor-mode-map)
                                                          org-mode-map)))
                           (define-key map (kbd "C-c C-c") 'org-ctrl-c-ctrl-c)
                           map))))
(defun scimax-add-keymap-to-src-blocks (limit)
  "Add keymaps to src-blocks defined in `scimax-src-block-keymaps'."
  (let ((case-fold-search t)
        lang)
    (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)
            (progn
              (add-text-properties
               beg end `(local-map ,(cdr (assoc
                                          (org-no-properties lang)
                                          scimax-src-block-keymaps))))
              (require 'org-mouse)
              (add-text-properties
               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
`lispy--eval'."
  (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
      (progn
        (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))
  (font-lock-fontify-buffer))
(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'."
  (interactive)
  (let ((case-fold-search t)
        lang)
    (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)
            (progn
              (add-text-properties
               beg end `(local-map ,(cdr (assoc
                                          (org-no-properties lang)
                                          scimax-src-block-keymaps))))
              (require 'org-mouse)
              (add-text-properties
               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))
      item)
  (mapc (lambda (element) (ring-insert myring element))
        '("/home/b/media/images/b/20170531231556.png"
          "/home/b/media/images/b/20170531231616.png"
          "/home/b/media/images/b/20170531231716.png"))
  (setq item (car (ring-elements myring)))
  (defun next-background ()
    (interactive)
    (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 =
1+1"
  (interactive)
  (let ((text (buffer-substring
               (progn (beginning-of-line) (point))
               (progn (end-of-line) (point)))))
    (end-of-line)
    (insert " = \n" text)))

org-logbook-sorter

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

reverse-words

(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."
  (interactive)
  (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)
      (delete-all-overlays)
      (narrow-to-region
       (car range-property-block) (cdr range-property-block))
      (org-reveal))))

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."
  (org-with-wide-buffer
   (unless (org-before-first-heading-p)
     (let ((log-beginning (org-log-beginning)))
       (if log-beginning
           (save-excursion
             (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."
  (interactive)
  (assert (eq 'org-mode major-mode))
  (let ((range-block (mw-org-get-log-block)))
    (when range-block
      (clone-indirect-buffer-other-window nil t)
      (narrow-to-region
       (car range-block) (cdr range-block))
      (org-reveal))))
(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."
  (interactive)
  (widen)
  (sp-narrow-to-sexp 1)
  (sp-backward-up-sexp))

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))
  (scroll-lock-update-goal-column)
  ;; (if (pos-visible-in-window-p (point-max))
  ;;     (forward-line arg)
  (scroll-up arg)
  ;; )
  (scroll-lock-move-to-column scroll-lock-temporary-goal-column))

txr-mode

(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)
               (current-buffer))))
    (when buf
      (with-current-buffer buf
        (push-mark))
      (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)
               (current-buffer))))
    (when buf
      (with-current-buffer buf
        (push-mark))
      (append-to-buffer buf start end)
      (switch-to-buffer buf))))

repeat

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."
  (interactive)
  (message
   "%s <- last repeatable command. %s <- before last"
   last-repeatable-command
   repeat-previous-repeated-command))

cursor-color-mode

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

hack-time

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

carry-region

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

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

keybinding

(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."
  (interactive)
  (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 mw-password-for-marco.wahl@gmail.com ()
  "Kill passwort for user marco.wahl@gmail.com out of my authinfo."
  (interactive)
  (let* ((delay-to-callback 42)
         (target
          (kill-new
           (car (aref (aref (plist-get
                             (car
                              (auth-source-search :user  "marco.wahl@gmail.com"))
                             :secret)
                            2)
                      0)))))
    (run-with-timer
     delay-to-callback nil
     (lambda ()
       (setf kill-ring  (delete target kill-ring))))))

org-structure-as-dirs-and-files

org-structure-as-dirs-and-files.el

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

org-teleport

I really like this.

source http://kitchingroup.cheme.cmu.edu/blog/2016/03/18/Org-teleport-headlines/

(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
  (org-mark-subtree)
  (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)))
  (cond
   ;; Move before  and change headline level
   ((and (numberp arg) (> 0 arg))
    (save-excursion
      (yank))
    ;; 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)
               do
               (if (> 0 n)
                   (org-promote-subtree)
                 (org-demote-subtree)))))
   ;; Move after and change level
   ((and (numberp arg) (< 0 arg))
    (org-mark-subtree)
    (goto-char (region-end))
    (when (eobp) (insert "\n"))
    (save-excursion
      (yank))
    ;; 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)
               do
               (if (> 0 n) (org-promote-subtree)
                 (org-demote-subtree)))))

   ;; move to before selection
   ((equal arg '(4))
    (save-excursion
      (yank)))
   ;; move to after selection
   (t
    (org-mark-subtree)
    (goto-char (region-end))
    (when (eobp) (insert "\n"))
    (save-excursion
      (yank))))
  (outline-hide-leaves))

misty-rose

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

org-mime

(require 'org-mime)

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

org-section-numbers

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

tweet-this

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

bbdb-this

(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."
  (interactive)
  (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))
      value))

(setq org-columns-modify-value-for-display-function
      'mw-org-columns-modify-value-for-display)

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  "\\>")
      (backward-word))
    (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))
      (forward-sentence)
      (when (looking-at " +") (replace-match "  "))))

maxima

(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\" ."
  (interactive)
  (org-add-agenda-custom-command
   `("x" "Custom agenda possibly stored by `mw-org-agenda-store-current-filters-as-custom-agenda'" agenda ""
     ((org-agenda-overriding-header
       "Custom agenda")
      (org-agenda-tag-filter-preset
       ',org-agenda-tag-filter)
      (org-agenda-regexp-filter-preset
       ',org-agenda-regexp-filter)
      (org-agenda-category-filter-preset
       ',org-agenda-category-filter)))))

org-crypt

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

jl-encrypt

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)

exwm

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

multiple screens

xrandr
;; (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)

systemtray

;; (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")
  (diary-check-diary-file)
  (diary-list-entries
   org-agenda-current-date
   (if (and arg (not (equal '(4) arg)))
       (prefix-numeric-value arg))))
(eval-after-load "org-agenda"
  '(org-defkey
    org-agenda-mode-map "D"
    (lambda (&optional arg)
      (interactive "P")
      (if arg
          (mw-org-agenda-open-diary arg)
        (org-agenda-toggle-diary)))))

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."
  (interactive)
  (let ((item-pos (org-in-item-p))
        (pos (point)))
    (if item-pos
        (progn
          (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))
            (end-of-line)))
      (beginning-of-line)
      (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."
  (interactive)
  (org-insert-heading)
  (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))
  (outline-flag-region
   (point)
   (progn (org-first-heading) (point))
   (not show)))

org-show-context-detail

(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: http://emacs.stackexchange.com/questions/12930/display-org-todo-list-of-entries-with-deadlines ;;

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."
  (interactive)
  (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.
  (interactive)
  (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)
         (hour
          (truncate
           (- (/ (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 http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/.

(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)

lob

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/mw-lob.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."
  (interactive)
  (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)))

VCS

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."
  (interactive)
  (let ((beg (point)))
    (search-forward-regexp "modified: *")
    (delete-region beg (point)))
  (end-of-line)
  (let ((end (point)))
    (search-backward-regexp "\\.")
    (delete-region (point) end))
  (insert ":\n")
  (backward-char))
(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)

toggle-letter-case

;; http://www.star.bris.ac.uk/bjm/emacs-tips.html#sec-1-14

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; change case of letters                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://ergoemacs.org/emacs/modernization_upcase-word.html
(defun toggle-letter-case ()
  "Toggle the letter case of current word or text selection.
Toggles between: “all lower”, “Init Caps”, “ALL CAPS”."
  (interactive)
  (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))
      (save-excursion
        (goto-char p1)
        (cond
         ((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")))))
    (cond
     ((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: gwene.org.emacsen.planet Date: Mon, 24 Aug 2015 02:00:00 +0200 (15 hours, 49 minutes, 21 seconds ago) Archived-at: http://endlessparentheses.com/ispell-and-org-mode.html?source=rss

[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)

ediff

(add-hook 'ediff-keymap-setup-hook
          (lambda ()
            (define-key
              ediff-mode-map "8"
              #'mw-ediff-set-visible-mode-in-ediff-buffers)))

drag windows

Found [2015-03-03 Tue 17:18] Link: https://tsdh.wordpress.com/2015/03/03/swapping-emacs-windows-using-dragndrop/

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.

navi-mode

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

;(require 'navi-mode)

quickly access dict.leo.org

(defun mw-ask-leo-about-word-at-point ()
  "Call the leo translation page for the word at point."
  (interactive)
  (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."
  (interactive
   (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 "https://pda.leo.org/englisch-deutsch/%s" 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."
  (interactive)
  (start-process
   "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."
  (interactive)
  (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

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 https://github.com/tlikonen/wcheck-mode.

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: https://github.com/tlikonen/wcheck-mode
(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 . "")
	 (read-or-skip-faces
	  (nil)))))

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)

mpages

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 ()
                                 (interactive)
                                 (setq epa-file-encrypt-to '("49010A040A3AE6F2"))
                                 (save-buffer)
                                 (kill-buffer))))

dired-x

(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."
  (interactive)
  (let
      ((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."
  (interactive)
  (ediff
   (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)

battery

(display-battery-mode)

beautification

elisp

;; (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)))

python

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 http://www.emacswiki.org/emacs/FlySpell

(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."
  (interactive)
  (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"
                   "/usr/share/dict/french"
                   "/usr/share/dict/words")))
  (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 ()
  (interactive)
  (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?
          dict)
    (message (concat dict " set for ispell completion."))))

scroll-lock-mode

Scroll lock mode gives another buffer movement feeling.

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

screen

Seamless exchange with screen.

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

screen like commands for slurp and write

(defun mw-screen-exchange-slurp-insert ()
  (interactive)
  (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."
  (interactive)
  (set-buffer (find-file mw-screen-exchange-filename))
  (auto-revert-mode))

erc

Direct client-to-client support for erc.

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

zone

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