Permalink
Switch branches/tags
Nothing to show
Find file
89b4c8b Oct 28, 2017
9135 lines (7653 sloc) 329 KB

This is the GNU/Emacs config file of Karl Voit.

This file is named config.org. My init.el got some nifty Elisp code that converts/tangles (only) the Elisp blocks into the config.el. This generated file is interpreted by my GNU/Emacs on startup.

Note that all Elisp blocks part of a DISABLED heading or which are marked with :tangle no won’t be tangled to the config.el file. Unfortunately, within the Org-mode rendering of GitHub, you won’t see the DISABLED keyword nor the :tangle no parameter of the babel blocks. Please get the Org-mode file and open it in your Emacs directly.

Originally, I found this process on http://www.holgerschurig.de/en/emacs-init-tangle/ However, I adapted its code and write additional features.

Links that start with id: won’t work for you because they link to my personal Org-mode files.


Some minor tasks I plan to do with my config.org:

  • flyspell bindkeys:
    • [ ] create a hydra some day
  • [ ] FIXXME: check why Python “auto-complete mode” is disabled in my config
  • [ ] FIXXME: check why Python > Ropemacs (for refactoring) is disabled in my config

General settings

Here, I do set some very general settings for my GNU/Emacs.

profiling:

(defvar my-config-el-start-time (current-time) "Time when config.el was started")
;(profiler-start 'cpu);; test startup performance - create report with M-x profiler-report

2011-04-20: turn off backup files

(setq backup-inhibited t)

set start of week to Monday (not sunday) http://sunsite.univie.ac.at/textbooks/emacs/emacs_33.html

(setq calendar-week-start-day 1)

omit usage of TAB for C-x r o: indent-tabs-mode

(setq-default indent-tabs-mode t)

append and update time-stamps for Time-stamp: <> in headers:

(add-hook 'write-file-hooks 'time-stamp)

set warning of opening large files to 100MB

(setq large-file-warning-threshold 100000000)

do not add double space after periods Real sentence in Emacs : emacs

(setq sentence-end-double-space nil)

https://www.emacswiki.org/emacs/TruncateLines M-x toggle-truncate-lines

(setq truncate-lines t)

elisp - Emacs truncate lines in all buffers - Stack Overflow

(setq-default global-visual-line-mode t)

inhibit the startup screen

(setq inhibit-startup-screen t)

English time-stamps in Org-mode (instead of localized German ones):

(setq system-time-locale "C")

Adaptive cursor width | Pragmatic Emacs: make cursor the width of the character it is under; i.e. full width of a TAB:

(setq x-stretch-cursor t)

Guru mode

(defun disable-guru-mode ()
  (guru-mode -1)
  )
(add-hook 'prelude-prog-mode-hook 'disable-guru-mode t)

Package

Configure the package manager of my GNU/Emacs.

http://www.reddit.com/r/emacs/comments/2u1bml/gnu_or_melpa_version_of_yasnippet_both_in_mx/

MELPA packages are usually built automatically from a project’s repository; the GNU repository has stable releases that are explicitly submitted to it.

package-user-dir holds the directory where Emacs package manager installs its local copies of the packages:

(setq package-user-dir (concat my-user-emacs-directory "elpa"))
(package-initialize)
;;(add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/"))
;;OLD:(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"));; moved to stable.melpa.org https://www.reddit.com/r/emacs/comments/4zqbz0/whats_up_with_melpa_stable/
(add-to-list 'package-archives '("melpa" . "http://stable.melpa.org/packages/"))
;;unstable;; (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))

;; 2017-03-26: from https://www.reddit.com/r/emacs/comments/61jsvy/melpa_stopped_working_over_https_for_me_any_ideas/
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))

Add elpy repository:

(add-to-list 'package-archives '("elpy" . "https://jorgenschaefer.github.io/packages/"))

Bugfixing: 2016-01-26: fix certificate issue: “gnutls.c: [0] (Emacs) fatal error: The TLS connection was non-properly terminated.”

(if (fboundp 'gnutls-available-p)
    (fmakunbound 'gnutls-available-p))
(setq tls-program '("gnutls-cli --tofu -p %p %h")
      imap-ssl-program '("gnutls-cli --tofu -p %p %s")
      smtpmail-stream-type 'starttls
      starttls-extra-arguments '("--tofu")
      )

Initialize packages:

;; 2015-11-25: https://github.com/jwiegley/use-package
(eval-when-compile (require 'use-package))
(require 'diminish)
(require 'bind-key)

;; http://www.lunaryorn.com/2015/01/06/my-emacs-configuration-with-use-package.html
(setq package-enable-at-startup nil)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

Upper/lower-case

Many times, I do need to uppercase or lowercase a word. Those commands offer me quick shortcuts to do so.

See: id:2014-03-04-M-l-subword

(global-set-key [M-l] 'downcase-word)
(global-set-key [M-u] 'upcase-word)
(global-set-key [M-c] 'capitalize-word)

yes-or-no-p: prefer y/n

«True #Emacs Knights are lazy and hate typing yes/no - they prefer y/n instead. Use this (fset ‘yes-or-no-p ‘y-or-n-p) in your config.» … from: http://twitter.com/emacs_knight/status/128339316417101825

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

Deletes duplicate entries of the history of the minibuffer

«If the value of this variable is t, that means when adding a new history element, all previous identical elements are deleted.» from: http://www.gnu.org/software/emacs/manual/html_node/elisp/Minibuffer-History.html

(setq history-delete-duplicates t)

Pasting with the mouse without moving the point

«middle-clicking pastes at the current location instead of moving it» from: http://sachachua.com/blog/2017/04/emacs-pasting-with-the-mouse-without-moving-the-point-mouse-yank-at-point/

(setq mouse-yank-at-point t)

Un-setting some keys

Here, I do unset some keys I don’t use so that they are not in my way when I accidentially use them:

;;   \C-v   scroll up
;;   \C-t   transpose-chars
(dolist (key '("\C-v" "\C-t"))
    (global-unset-key key))

delete-trailing-whitespace before saving

I don’t see any use of trailing whitespace. Previously, I had a function to remove them mapped to my-map SPC but then I found out that adding this as a general before-save-hook does the job automatically:

;;(bind-key (kbd "SPC") #'delete-trailing-whitespace my-map)
;  (define-key org-mode-map (kbd "C-c C-, SPC") #'delete-trailing-whitespace);; workaround since line above doesn't work

;; 2016-02-06: https://www.reddit.com/r/emacs/comments/445w6s/whats_some_small_thing_in_your_dotemacs_that_you/
(add-hook 'before-save-hook 'delete-trailing-whitespace)

Maximize frame window

Details: id:2016-03-27-maximize-window-init.el

(toggle-frame-maximized)

my-load-local-el()

Using this function, I am able to easily load lisp files within my Emacs config hierarchy. It contains minimal error handling for a missing file.

from: http://www.zonix.de/html40/linux/emacsgnus.html

(defun my-load-local-el (part)
  "load lisp file and warn if not found"
  (let ((fullname (concat my-user-emacs-directory part)))
    (if (file-exists-p fullname)
	(load fullname)
      (message (format "Loading %s (source)...failed" fullname)))))

no-littering

From:

It sets some default paths in order to separate automatically created files and directories.

(use-package no-littering
   :load-path "~/.emacs.d/contrib/no-littering/"
   )
(require 'no-littering)

Server mode

Start Emacs as a server process: new files can be visited via emacsclient (instead of parallel emacs instances). Therefore, I don’t have to run multiple instances (which occupies RAM storage) and I am able to open new files instantly.

(server-start)

my-system-is-FOOBAR

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

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

;; Get current system's name
(defun my-insert-system-name()
  (interactive)
  "Get current system's name"
  (insert (format "%s" system-name))
  )

;; Get current system type
(defun my-insert-system-type()
  (interactive)
  "Get current system type"
  (insert (format "%s" system-type))
  )

;; Check if system is Darwin/Mac OS X
(defun my-system-type-is-darwin ()
  "Return true if system is darwin-based (Mac OS X)"
  (string-equal system-type "darwin")
  )

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

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

Here are host-specific functions which I should not use if possible because with them, I lose some generic approach:

(defun my-system-is-floyd-or-sherri ()
  "Return true if the system we are running on is floyd or sherri"
  (or
    (string-equal system-name "floyd")
    (string-equal system-name "floyd.lan")
    (string-equal system-name "sherri")
    (string-equal system-name "sherri.lan")
    )
  )

(defun my-system-is-sherri ()
  "Return true if the system we are running on is sherri"
  (or
    (string-equal system-name "sherri")
    (string-equal system-name "sherri.lan")
    )
  )

(defun my-system-is-floyd ()
  "Return true if the system we are running on is floyd"
  (or
    (string-equal system-name "floyd")
    (string-equal system-name "floyd.lan")
    )
  )

(defun my-system-is-blanche ()
  "Return true if the system we are running on is blanche"
  (or (string-equal system-name "blanche") (string-equal system-name "blanche.lan"))
  )

(defun my-system-is-karl-voit-at ()
  "Return true if the system we are running on is karl-voit.at"
  (string-equal system-name "friends.grml.info")
  )

(defun my-system-is-powerplantlinux ()
  "Return true if the system we are running on is powerplant"
  (or
   (string-equal system-name "powerplant")
   (string-equal system-name "powerplant.lan")
   )
  )

System-specific paths

The system PATH variable provides access to executables. However, I do tend to use programs which are not part of the PATH variable of the operating system as well. Therefore, I do extend the Emacs variable exec-path (further down and following headings).

http://www.emacswiki.org/emacs/MacOSTweaks#toc13

;; setting path so that Emacs finds aspell and such
(when (my-system-type-is-darwin)
  (setenv "PATH"
	  (concat (getenv "PATH")
		  ":/Users/vk/bin:/usr/local/texlive/2010/bin/x86_64-darwin:/opt/local/bin:/opt/local/sbin"))
  (setq exec-path (append exec-path
			  '("/opt/local/bin"
			    "/usr/local/texlive/2010/bin/x86_64-darwin"
			    "/usr/local/teTeX/bin/powerpc-apple-darwin-current"
			    )))
  (add-to-list 'load-path "/opt/local/share/emacs/site-lisp")

  ;; 2011-04-20: allow typing of german umlauts in OS X by Alt-u followed by u,o,a,...
  (setq mac-option-modifier nil)

  (setq org-ditaa-jar-path "~/data/hosts/blanche/config/ditaa.jar")

  ;; setting path to color-theme-mode.el from MacPorts
  (add-to-list 'load-path "/opt/local/share/emacs/site-lisp/color-theme-6.6.0")
  )

ditaa

(when (my-system-type-is-gnu)
  (setq org-ditaa-jar-path "/usr/share/ditaa/ditaa.jar")
  )

setting path so that Emacs finds aspell and such:

(if (my-system-type-is-windows)

    ;;disabled;(setenv "PATH"
    ;;disabled;               (concat (getenv "PATH")
    ;;disabled;		  ":/Users/vk/bin:/usr/local/texlive/2010/bin/x86_64-darwin:/opt/local/bin:/opt/local/sbin"))
    (setq exec-path (append exec-path
     			     '("C:/Program Files (x86)/Aspell/bin"
     			       ;;disabled; "/usr/local/texlive/2010/bin/x86_64-darwin"
     			       ;;disabled; "/usr/local/teTeX/bin/powerpc-apple-darwin-current"
     			       )))
    ;;disabled;(add-to-list 'load-path "/opt/local/share/emacs/site-lisp")

 (
  ;; on all other systems:
  )
 )

Cygwin Paths (Windows)

As mentioned in the chapter of system-specific paths, I do use programs which are not part of the PATH variable of the operating system. Cygwin executables (in form of babun) are one example of this kind of programs.

Links:

(when (my-system-type-is-windows)

Hard-coding the cygwin install path (for babun):

  • id:2016-04-22-magit-not-working-on-windows
(setq cygwin-root-directory "c:/Users/karl.voit/.babun/cygwin/")

Check if Cygwin/babun inst found on the install path given:

(if (file-directory-p cygwin-root-directory)
    (progn

OLD method of extending the path:

(setenv "PATH"
        (concat
         ;;"c:\\cygwin64\\usr\\local\\bin" ";"  ;; Cygwin
         ;;"c:\\cygwin64\\bin" ";"  ;; Cygwin
         "C:\\Users\\karl.voit\\.babun\\cygwin\\bin" ";"
         "C:\\Users\\karl.voit\\.babun\\cygwin\\usr\\local\\bin" ";"
         "C:\\Program\ Files\ \(x86\)\\Java\\jre1.8.0_144\\bin" ";"
         (getenv "PATH")))

Extending the path:

(setq exec-path (cons (concat cygwin-root-directory "bin/") exec-path)) ;; Babun
(setq exec-path (cons (concat cygwin-root-directory "usr/local/bin/") exec-path)) ;; Babun
(setq exec-path (cons "C:/Program Files (x86)/Java/jre1.8.0_144/bin" exec-path)) ;; Babun

Adding cygwin mounts:

(use-package cygwin-mount)
(cygwin-mount-activate)

Adding cygwin bash shell

;;(setq shell-file-name "c:/cygwin64/bin/bash") ;; Cygwin
(setq shell-file-name (concat cygwin-root-directory "bin/zsh")) ;; Babun
;;(setq shell-file-name (concat cygwin-root-directory "bin/bash")) ;; Babun
(setenv "SHELL" shell-file-name)
(setq explicit-shell-file-name shell-file-name)
(setq ediff-shell shell-file-name)
(setq explicit-shell-args '("--login" "-i"))
(setq w32-quote-process-args ?\")

id:2015-11-02-tramp-windows-babel and Docu: help:tramp-methods

(setq tramp-default-method "plink")

requires: setup-cygwin.el and cygwin-mount.el in the contrib dir:

(add-to-list 'load-path (concat my-user-emacs-directory "contrib/"))
(require 'setup-cygwin)

END of Cygwin/babun configuration

    )
(message "»»» I could not locate the cygwin path")
)

end of Cygwin config

);; end of if-windows

Starting GNU/Emacs on Windows

First, I create a batch file which starts the emacs.exe with optional Org-mode files as parameters:

C:\Users\Karl.Voit\bin\windows-start-orgmode.bat

REM Here, invoke some syncronization mechanism like Unison:
REM "C:\Program Files\bin\unison-2.40.102-gtk.exe" grmlvrs

REM As of 2017, I switched from Unison to Syncthing

"C:\Program Files\emacs-24.5-bin-i686-mingw32\bin\emacs.exe"

REM Re-syncing after leaving Emacs:
REM "C:\Program Files\bin\unison-2.40.102-gtk.exe" grmlvrs

REM End

This batch file is included in a Visual Basic file. This way, I am able to start my GNU/Emacs using misc app-launcher solutions: batch files are not listed in typical app-launchers whereas VBS files work at least with my Hotstrings:

C:\Users\Karl.Voit\bin\orgmode.vbs or in Cygwin /home/karl.voit/bin/orgmode.vbs

'HideBat.vbs
CreateObject("Wscript.Shell").Run "C:\Users\Karl.Voit\bin\windows-start-orgmode.bat", 0, True

Looking for binaries

Some Emacs configuration snippets relate to external programs such as LaTeX. Instead of (a) blindly evaluating those snippets or (b) using per-host-configuration for them, I do prefer to check whether or not those programs are installed on the local host instead. This is just the sane way of doing those things.

In detail, it gets a bit dirty for Windows, since there are some tools that are installed but not listed in the PATH environment exec-path. See below for some workarounds for that.

my-binary-found(binaryname)

my-binary-found(binaryname) returns the path where a binary executable can be found within the exec-path.

It also checks certain operating system/binary combinations which aren’t likely in the exec-path.

  (defun my-binary-found(binaryname)
    "Returns the path where a binary executable can be found.

It also checks certain operating system/binary combinations which aren't likely in the exec path."
    (cond
     ((and (my-system-type-is-windows) (string= binaryname "firefox"))
      (when (file-exists-p "C:/Program Files/Mozilla Firefox/firefox.exe")
        (concat "C:/Program Files/Mozilla Firefox/firefox.exe")
        )
      )
     ((and (my-system-type-is-windows) (string= binaryname "python"))
      (when (file-exists-p "C:/Python27/python.exe")
        (concat "C:/Python27/python.exe")
        )
      )
     ((and (my-system-type-is-windows) (string= binaryname "outlook"))
      (when (file-exists-p "C:/Program Files (x86)/Microsoft Office/Office16/OUTLOOK.EXE")
        (concat "C:/Program Files (x86)/Microsoft Office/Office16/OUTLOOK.EXE")
        )
      )
     ;; this is the default check for all binaries which got no special handling above:
     (t
      (locate-file binaryname exec-path exec-suffixes 1))
     ))

Examples:

(message (concat "pdflatex found on: " (my-binary-found "pdflatex")))

(if (my-binary-found "pdflatex")
  (message "LaTeX found")
  (message "LaTeX not found")
)

my-binary-not-found-list and my-eval-if-binary-or-warn()

my-eval-if-binary-or-warn (binaryname &optional warningtext) checks if a binary can be found in the path via my-binary-found().

If not found, a warning message is printed which can be defined as an optional parameter as well. Additionally, the not found binaries are collected in the variable my-binary-not-found-list.

(defvar my-binary-not-found-list nil
  "Holds a list of binaries which could not be found via my-eval-if-binary-or-warn()"
  )

(defun my-eval-if-binary-or-warn (binaryname &optional warningtext)
  "Checks if a binary can be found in the path via my-binary-found().

If not found, a warning message is printed which can be defined as an optional parameter as well.
Additionally, the not found binaries are collected in the variable my-binary-not-found-list."
  (or warningtext (setq warningtext (concat "»»» I could not locate the PATH-binary for: " binaryname)))
  (let* ((binarypath (my-binary-found binaryname)))
    (if binarypath
       ;; binary was found in exec-path
       (concat binarypath)
      (progn
        ;; binary NOT found in exec-path:
        (message warningtext)
        (if my-binary-not-found-list
            (add-to-list 'my-binary-not-found-list binaryname)
          (setq my-binary-not-found-list (list binaryname))
          )
        ))))

Example usages:

(my-eval-if-binary-or-warn "yyy" "This is a warning text for yyy")
(my-eval-if-binary-or-warn "xxx")
(my-eval-if-binary-or-warn "xxx" "This is a warning text for xxx")
(my-eval-if-binary-or-warn "zzz" "This is a warning text for xxx")

(message "Binaries not found: %s" my-binary-not-found-list)

Example output for different hosts

This heading ist just for collecting example outputs:

sherri output:

pdflatexTeX binary: /usr/bin/pdflatex
python binary: /usr/bin/python
firefox binary: /usr/bin/firefox
chrome binary:
aspell binary: /usr/bin/aspell
ispell binary:
pandoc binary: /usr/bin/pandoc
ditaa binary: /usr/bin/ditaa
gnuplot binary: /usr/bin/gnuplot
git binary: /usr/bin/git
Outlook binary:
grep binary: /bin/grep
scss binary: /usr/bin/scss
ag binary: /usr/bin/ag
biber binary: /usr/bin/biber

Windows output:

pdflatex binary: c:/Program Files/MiKTeX_2.9/miktex/bin/pdflatex.exe
python binary:
ipython binary:
firefox binary:
chrome binary:
aspell binary:
ispell binary:
pandoc binary: c:/Users/karl.voit/AppData/Local/Pandoc/pandoc.exe
ditaa binary:
gnuplot binary:
git binary:
Outlook binary:
grep binary:
scss binary:
ag binary:
biber binary: c:/Program Files/MiKTeX_2.9/miktex/bin/biber.exe
Binaries not found in checks above: (ag scss grep Outlook git gnuplot ditaa ispell aspell chrome firefox ipython python)

After moving system-specific paths above this checks: only aspell was found:

Binaries not found in checks above: (ag scss grep Outlook git gnuplot ditaa ispell chrome firefox ipython python)

but on Windows, there are following things installed:

  • [ ] python
  • [ ] ipython
  • [ ] firefox
  • [ ] chrome
  • [ ] (a/i?)spell
  • [ ] Outlook
    • real path: “C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE”
    • also holds for OUTLOOK.EXE and OUTLOOK
    • where outlook is also unsuccessful :-(
(message "★★★★★★★★★★")
(message (concat "pdflatex binary: " (my-binary-found "pdflatex")))
(message (concat "python binary: " (my-binary-found "python")))
(message (concat "ipython binary: " (my-binary-found "ipython")))
(message (concat "firefox binary: " (my-binary-found "firefox")))
(message (concat "chrome binary: " (my-binary-found "chrome")))
(message (concat "aspell binary: " (my-binary-found "aspell")))
(message (concat "ispell binary: " (my-binary-found "ispell")))
(message (concat "pandoc binary: " (my-binary-found "pandoc")))
(message (concat "ditaa binary: " (my-binary-found "ditaa")))
(message (concat "gnuplot binary: " (my-binary-found "gnuplot")))
(message (concat "git binary: " (my-binary-found "git")))
(message (concat "Outlook binary: " (my-binary-found "Outlook")))
(message (concat "grep binary: " (my-binary-found "grep")))
(message (concat "scss binary: " (my-binary-found "scss")))
(message (concat "ag binary: " (my-binary-found "ag")))
(message (concat "biber binary: " (my-binary-found "biber")))
(message "★★★★★★★★★★")

Test queries

Here, I do probe for some tools mostly because I want to test my code above.

When I am using tool-specific settings below, I do add comment characters to disable the check at this stage:

;;(my-eval-if-binary-or-warn "pdflatex")
;;(my-eval-if-binary-or-warn "python")
(my-eval-if-binary-or-warn "ipython")
;;(my-eval-if-binary-or-warn "firefox")
(my-eval-if-binary-or-warn "chrome")
;;(my-eval-if-binary-or-warn "aspell")
;;(my-eval-if-binary-or-warn "pandoc")
(my-eval-if-binary-or-warn "ditaa")
;;(my-eval-if-binary-or-warn "gnuplot")
;;(my-eval-if-binary-or-warn "git")
;;(my-eval-if-binary-or-warn "outlook")
(my-eval-if-binary-or-warn "grep")
;;(my-eval-if-binary-or-warn "scss")
(my-eval-if-binary-or-warn "ag")
(my-eval-if-binary-or-warn "biber")

System-specific browse-url-browser

Here, I do hard-code my preferred browser that is used when I open URLs within Emacs:

http://stackoverflow.com/questions/4506249/how-to-make-emacs-org-mode-open-links-to-sites-in-google-chrome

(setq firefox-path (my-eval-if-binary-or-warn "firefox"))
(setq chrome-path (my-eval-if-binary-or-warn "google-chrome"))

(cond
 ((my-system-type-is-darwin)
  (setq browse-url-browser-function 'browse-url-default-macosx-browser)
  )
 (firefox-path
  (setq browse-url-browser-function 'browse-url-generic
	browse-url-generic-program firefox-path)
  )
 (chrome-path
  (setq browse-url-browser-function 'browse-url-generic
	browse-url-generic-program chrome-path)
  )
 )

http://stackoverflow.com/questions/4506249/how-to-make-emacs-org-mode-open-links-to-sites-in-google-chrome

(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "chromium-browser")

https://chrome.google.com/webstore/detail/ljobjlafonikaiipfkggjbhkghgicgoh?hl=de

  • Edit-server for Chrome
;(use-package edit-server)
(my-load-local-el "contrib/edit-server.el")
;won't work; (use-package edit-server
;won't work;    :load-path "~/.emacs.d/contrib/"
;won't work;    :config
;won't work;    (edit-server-start)
;won't work;    )

(if (locate-library "edit-server")
    (progn
      (use-package edit-server)
      (setq edit-server-new-frame nil)
      (edit-server-start)))

2017-06-20: A little trick with EWW : emacs - presents code to interactively select your browser of choice.

Styling

The (sub-)headings here deal with the visual appeal of my GNU/Emacs. I like dark themes and minimized interfaces. Therefore, I hide everyting I do not use.

Interesting read: http://www.tbray.org/ongoing/When/201x/2012/09/24/Typographic-notes

Show current column:

(setq column-number-mode t)

Cursor settings:

;; Prevent the cursor from blinking
;(blink-cursor-mode 0)
(set-cursor-color "IndianRed")

Flat mode-line styling: 2014-05-24: from http://www.reddit.com/r/emacs/comments/23l9oi/flat_modeline/

(set-face-attribute 'mode-line nil :box nil)
(set-face-attribute 'mode-line-inactive nil :box nil)

Themes

Since a couple of major versions, GNU/Emacs has a built-in theme manager. This is for dealing with the themes:

(setq calendar-location-name "Graz, AT")
(setq calendar-latitude 47.07)
(setq calendar-longitude 15.43)
(use-package theme-changer)
(change-theme 'whiteboard 'misterioso)  ;; day and night theme

My favorite dark themes: wombat, misterioso, zenburn, material

(load-theme 'wombat t) ;; dark theme
;;   (load-theme 'misterioso t)
;;   (load-theme 'zenburn t)
;;   (load-theme 'material t) ;; from http://www.reddit.com/r/emacs/comments/39dk64/escaping_from_org_mode/
;;              issues with *bold* stuff in org-mode :-(

My favorite light themes: leuven, whiteboard, solarized-light,

;;   (load-theme 'leuven t) ;; from http://www.reddit.com/r/emacs/comments/39dk64/escaping_from_org_mode/
;;   (load-theme 'whiteboard t)
;;   (load-theme 'solarized-light t)
;  (face-spec-set 'org-block-begin-line
;    '((t (:underline "#FFFFFF" :foreground "#404040" :background "#b3b3b3")))
;    "Face used for the line delimiting the begin of source blocks.")

  ;(defface org-block-begin-line
  ;  '((t (:underline "#FFFFFF" :foreground "#cccccc" :background "#4d4d4d")))
  ;  "Face used for the line delimiting the begin of source blocks.")

  (defface org-block
    ;; defface org-block-background was removed from org:
    ;; http://emacs.stackexchange.com/questions/14824/org-block-background-font-not-having-effect
    ;; read also: https://www.reddit.com/r/emacs/comments/415imd/prettier_orgmode_source_code_blocks/
    '((t (:background "#1a1a1a")))
    "Face used for the source block background.")

  ;(defface org-block-end-line
  ;  '((t (:overline "#FFFFFF" :foreground "#cccccc" :background "#4d4d4d")))
  ;  "Face used for the line delimiting the end of source blocks.")

  ;;test: (set-face-background 'org-block-background "#1a1a1a")
;;    (defadvice load-theme (before theme-dont-propagate activate) (mapcar #'disable-theme custom-enabled-themes))

Only one window on startup

«Make [current] WINDOW fill its frame.»

(add-hook 'emacs-startup-hook 'delete-other-windows t)

Font

(add-to-list 'default-frame-alist
                       '(font . "DejaVu Sans Mono-12"))

Font sizes

(defun my-increase-fontsize ()
  (interactive)
  "Sets the font to bigger size"
  (set-face-attribute 'default (selected-frame) :height 130)
  )
(defun my-normal-fontsize ()
  (interactive)
  "Sets the font to normal size"
  (set-face-attribute 'default (selected-frame) :height 100)
  )

Host-specific font size:

(when (my-system-type-is-gnu)
  (my-increase-fontsize);; increase fonts on some hosts by default
  )
(when (my-system-type-is-darwin)
  (set-face-attribute 'default (selected-frame) :height 170);; 2011-04-20: increase/set font size http://www.emacswiki.org/emacs/SetFonts
  )
(when (my-system-type-is-windows)
  ;;(set-face-attribute 'default (selected-frame) :height 150)
  ;;(set-face-attribute 'default (selected-frame) :height 130);; 2016-08-19 let's test 130 after 150 seems too big
  (set-face-attribute 'default (selected-frame) :height 110);; 2017-09-06 detego
  )
(when (my-system-is-floyd)
  (set-face-attribute 'default (selected-frame) :height 105)
  )
(when (my-system-is-sherri)
  (set-face-attribute 'default (selected-frame) :height 110)
  )

UTF-8 and codings

Activate UTF-8 mode:

(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

When I paste from the Windows clipboard, I tend to get messed up Umlauts and special characters. This ought to fix it but I think that this does not work either:

(cond ((my-system-type-is-windows)
       ;; on Windows, 'utf-8 does not work properly when system
       ;; clipboard gets yanked
       (setq selection-coding-system 'utf-16le-dos)

       ;; For example: =\344= instead of =ä= on Windows 7:
       ;;(set-selection-coding-system 'iso-latin-1-dos)
       )

      ((my-system-type-is-gnu)
       (set-selection-coding-system 'utf-8)
       )
      (t
       (set-selection-coding-system 'utf-8)
       )
      )

;; 2013-12-10 IRC #Emacs
(set-clipboard-coding-system 'utf-8)

;; http://www.masteringemacs.org/articles/2012/08/09/working-coding-systems-unicode-emacs/
;; in addition to the lines above:

(set-default-coding-systems 'utf-8)
;; backwards compatibility as default-buffer-file-coding-system
;; is deprecated in 23.2.
(if (boundp 'buffer-file-coding-system)
    ;; NOTE: default-buffer-file-coding-system is obsolete; use
    ;;       buffer-file-coding-system if found
    (setq-default buffer-file-coding-system 'utf-8)
  (setq default-buffer-file-coding-system 'utf-8))
;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))

From: https://www.masteringemacs.org/article/working-coding-systems-unicode-emacs

[…] One problem with the universal coding system argument is that it only cares about Emacs’s settings, not those of your shell or system. That’s a problem, because tools like Python use the environment variable PYTHONIOENCODING to set the coding system for the Python interpreter.

I have written the following code that advises the universal-coding-system-argument function so it also, temporarily for just that command, sets a user-supplied list of environment variables to the coding system. […]

(defvar universal-coding-system-env-list '("PYTHONIOENCODING")
  "List of environment variables \\[universal-coding-system-argument] should set")

(defadvice universal-coding-system-argument (around provide-env-handler activate)
  "Augments \\[universal-coding-system-argument] so it also sets environment variables

Naively sets all environment variables specified in
`universal-coding-system-env-list' to the literal string
representation of the argument `coding-system'.

No guarantees are made that the environment variables set by this advice support
the same coding systems as Emacs."
  (let ((process-environment (copy-alist process-environment)))
    (dolist (extra-env universal-coding-system-env-list)
      (setenv extra-env (symbol-name (ad-get-arg 0))))
    ad-do-it))

my-map: my own keyboard shortcut prefix

About defining keys: Emacs: How to Define Keys

If you are not satisfied with the default setup of Emacs keyboard shortcuts, you start with defining your own keyboard shortcuts (bindings).

To avoid binding conflicts with libraries/packages, it is a good habit of using a keyboard shortcut prefix no-one else is using. So if you stick to this prefix, you’ve got your own «name-space» where you are able to define your bindings freely.

My approach is to use my-map as a mapping which is bound to C-c C-,= . So my personal bindings start with =C-c C-,= such as =C-c C-, - for decreasing the font size of GNU/Emacs.

2015-11-10: Following code was replaced by bind-key below:

;; 2011-04-20, 2013-04-08: defining «C-c C-,» as my own prefix:
;; http://stackoverflow.com/questions/1024374/how-can-i-make-c-p-an-emacs-prefix-key-for-develperlysense
;; http://stackoverflow.com/questions/5682631/what-are-good-custom-keybindings-in-emacs
;; NOTE: (info "(elisp) Key Binding Conventions") warns about user prefixes other than C-c
(global-unset-key (kbd "C-c C-,")); causes error: "Invalid modifier in string"
;; same as: (global-unset-key (kbd "C-c C-,"))
(define-prefix-command 'my-map)

Using the bind-key package:

(require 'bind-key);; https://github.com/emacsattic/bind-key

(bind-keys
 :prefix-map my-map
 :prefix-docstring "My own keyboard map"
 :prefix "C-c C-,"
 ;; 2013-03-31: http://stackoverflow.com/questions/3124844/what-are-your-favorite-global-key-bindings-in-emacs
 ("-" . text-scale-decrease)
 ("+" . text-scale-increase)
 ("=" . text-scale-increase);; because "+" needs "S-=" and I might forget shift
 )

Usage example:

(bind-key "m w" #'mark-word my-map)

or:

(bind-keys
 :map my-map
 ("f" . forward-char)
 ("b" . backward-char))

or for use-package():

:bind (:map my-map ("8" . bm-toggle))

Alternative tipp: in case you run out of keybinding spaces, you can take a look at hydra and the “defhydra hydra-k” method. Hydra lists a menu of options and the hydra-k offers a prefix for it.

See 33min30s of the video linked in: Irreal: Hydra Video

My helper functions (part I)

Here I defined some functions I am using in the configuration below.

measure-time()

From time to time, I want to measure, how long an Elisp snippet ran. This can be done with following code.

from: http://stackoverflow.com/questions/23622296/emacs-timing-execution-of-function-calls-in-emacs-lisp

(defmacro measure-time (&rest body)
  "Measure the time it takes to evaluate BODY."
  `(let ((time (current-time)))
     ,@body
     (message " Execution time: %.06f" (float-time (time-since time)))))

my-title-capitalization(): Proper English Title Capitalization of a Marked Region → my-map C

Read http://www.karl-voit.at/2015/05/25/elisp-title-capitalization/ where I wrote a verbose description of the topic and my solution.

;; additionally to the list defined in title-capitalization:
(defvar my-do-not-capitalize-words '("lazyblorg" "mutt")
  "My personal list of words that doesn't get capitalized in titles.")


(defun title-capitalization (beg end)
  "Proper English title capitalization of a marked region"
  ;; - before: the presentation of this heading of my own from my keyboard and yet
  ;; - after:  The Presentation of This Heading of My Own from My Keyboard and Yet
  ;; - before: a a a a a a a a
  ;; - after:  A a a a a a a A
  (interactive "r")
  (save-excursion
    (let* (
	   ;; basic list of words which don't get capitalized according to simplified rules:
	   ;; http://karl-voit.at/2015/05/25/elisp-title-capitalization/
           (do-not-capitalize-basic-words '("a" "ago" "an" "and" "as" "at" "but" "by" "for"
                                            "from" "in" "into" "it" "next" "nor" "of" "off"
                                            "on" "onto" "or" "over" "past" "so" "the" "till"
                                            "to" "up" "yet"
                                            "n" "t" "es" "s"))
	   ;; if user has defined 'my-do-not-capitalize-words, append to basic list:
           (do-not-capitalize-words (if (boundp 'my-do-not-capitalize-words)
                                        (append do-not-capitalize-basic-words my-do-not-capitalize-words )
                                      do-not-capitalize-basic-words
                                      )
                                    )
           )
      ;; go to begin of first word:
      (goto-char beg)
      (capitalize-word 1)
      ;; go through the region, word by word:
      (while (< (point) end)
        (skip-syntax-forward "^w" end)
        (let ((word (thing-at-point 'word)))
          (if (stringp word)
              ;; capitalize current word except it is list member:
              (if (member (downcase word) do-not-capitalize-words)
                  (downcase-word 1)
                (capitalize-word 1)))))
      ;; capitalize last word in any case:
      (backward-word 1)
      (if (and (>= (point) beg)
               (not (member (or (thing-at-point 'word) "s")
                            '("n" "t" "es" "s"))))
          (capitalize-word 1))))
)

(ert-deftest my-title-capitalization ()
  "Tests proper English title capitalization"
  (should (string= (with-temp-buffer
		     (insert "the presentation of this heading of my own from my keyboard and yet\n")
		     (goto-char (point-min))
		     (set-mark-command nil)
		     (goto-char (point-max))
		     ;(transient-mark-mode 1)
		     (title-capitalization)
		     (buffer-string))
		   "The Presentation of This Heading of My Own from My Keyboard and Yet\n"
		   )))
(bind-key "c" #'title-capitalization my-map)

my-toggle-windows-split() → my-map |

Toggle the windows split between horizontally and vertically. I usually don’t use it though.

From: http://www.emacswiki.org/emacs/ToggleWindowSplit

(defun my-toggle-windows-split ()
  "Switch window split from horizontally to vertically, or vice versa.

i.e. change right window to bottom, or change bottom window to right."
  (interactive)
  (require 'windmove)
  (let ((done))
    (dolist (dirs '((right . down) (down . right)))
      (unless done
        (let* ((win (selected-window))
               (nextdir (car dirs))
               (neighbour-dir (cdr dirs))
               (next-win (windmove-find-other-window nextdir win))
               (neighbour1 (windmove-find-other-window neighbour-dir win))
               (neighbour2 (if next-win (with-selected-window next-win
                                          (windmove-find-other-window neighbour-dir next-win)))))
          ;;(message "win: %s\nnext-win: %s\nneighbour1: %s\nneighbour2:%s" win next-win neighbour1 neighbour2)
          (setq done (and (eq neighbour1 neighbour2)
                          (not (eq (minibuffer-window) next-win))))
          (if done
              (let* ((other-buf (window-buffer next-win)))
                (delete-window next-win)
                (if (eq nextdir 'right)
                    (split-window-vertically)
                  (split-window-horizontally))
                (set-window-buffer (windmove-find-other-window neighbour-dir) other-buf))))))))

(bind-key "|" 'my-toggle-windows-split my-map)

my-yank-windows → my-map y

Yanking from the windows clipboard results in messed up lists. When using this special yank function, common list formatting is fixed for Org-mode syntax.

  • id:2016-05-22-my-yank-windows
(when (my-system-type-is-windows)

  (defun my-yank-windows ()
    "yanks from clipboard and replaces typical (list) markup"
    (interactive)
    (let ((mybegin (point)))              ;; mark beginning of line as start point
      (clipboard-yank)
      (save-restriction
        (narrow-to-region mybegin (point))  ;; ignore everything outside of region
        (goto-char (point-min))
        (while (search-forward "\"	" nil t)
          (replace-match "- " nil t))
        (while (search-forward "o	" nil t)
          (replace-match "  - " nil t))
        ;;(while (search-forward "1.	" nil t) ;; FIXXME: replace with regex-methods for numbers in general
        ;; (replace-match "1. " nil t))
        (recode-region (point-min) (point-max) 'latin-1 'windows-1252); fix char encoding, e.g.: \366 -> ö
        ))
    )

  (bind-key "y" 'my-yank-windows my-map)

)

my-fill-or-unfill() paragraph

M-q does fix paragraph formatting and is one of my most favorite commands in GNU/Emacs. If you need to go back to «one line per paragraph», this function offers a toggle function for M-q. Applied twice, it re-formats the current paragraph to one line. Very handy for copy/paste to web forms or such where you need one paragraph per line.

(defun my-fill-or-unfill ()
  "Like `fill-paragraph', but unfill if used twice."
  (interactive)
  (let ((fill-column
         (if (eq last-command 'my-fill-or-unfill)
             (progn (setq this-command nil)
                    (point-max))
           fill-column)))
    (call-interactively 'fill-paragraph)))

(global-set-key [remap fill-paragraph]
                'my-fill-or-unfill)

my-open-in-external-app()

Some times, I want to use an external application for opening a certain file instead of opening it in Emacs. This can be done using following function:

(defun my-open-in-external-app (&optional file)
  "Open the current FILE or dired marked files in external app.
   The app is chosen from your OS's preference."
  (interactive)
  (message "%s" (concat "my-open-in-external-app called with \"" file "\" as argument"))
  ;; FIXXME: add check if FILE is an existing file; show error message if not
  (let ( doIt
         (myFileList
          (cond
           ((string-equal major-mode "dired-mode") (dired-get-marked-files))
           ((not file) (list (buffer-file-name)))
           (file (list file)))))

    (setq doIt (if (<= (length myFileList) 5)
                   t
                 (y-or-n-p "Open more than 5 files? ") ) )

    (when doIt
      (cond
       ((string-equal system-type "windows-nt")
        (mapc (lambda (fPath) (w32-shell-execute "open" (replace-regexp-in-string "/" "\\" fPath t t)) ) myFileList))
       ((string-equal system-type "darwin")
        (mapc (lambda (fPath) (shell-command (format "open \"%s\"" fPath)) )  myFileList) )
       ((string-equal system-type "gnu/linux")
        (mapc (lambda (fPath) (let ((process-connection-type nil)) (start-process "" nil "xdg-open" fPath)) ) myFileList)
) ) ) ) )

my-buffer-exists(bufname)

my-buffer-exists(bufname)

(defun my-buffer-exists (bufname)
  (not (eq nil (get-buffer bufname)))
  )

Spell checking

«Flyspell enables on-the-fly spell checking in Emacs by the means of a minor mode.»

Please do evaluate this only if “aspell” is found on the system:

(when (my-eval-if-binary-or-warn "aspell")

General settings

setting path to flyspell-mode.el from MacPorts:

(when (my-system-type-is-darwin)
  (add-to-list 'load-path "/opt/local/share/emacs/lisp/textmodes")
  )

save to user dictionary without asking:

(setq ispell-silently-savep t)

flyspell

flyspell.el http://kaolin.unice.fr/~serrano/

(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checking" t)

Dictionary Settings

;(set-default 'ispell-local-dictionary my-german-ispell-dictionary)

;;(autoload 'flyspell-mode "flyspell" "On-the-fly ispell." t)
(setq flyspell-issue-welcome-flag nil)

(when (my-system-type-is-windows)
  (setq flyspell-default-dictionary "german8")
)
(when (my-system-type-is-gnu)
  (setq flyspell-default-dictionary "de_AT")
)

from here to my-toggle-ispell-english-deutsch: see id:2014-01-06-aspell-issue

(eval-after-load "ispell"
  '(add-to-list 'ispell-dictionary-alist
                '("german8"
                   "[a-zA-ZäöüßÄÖÜ]" "[^a-zA-ZäöüßÄÖÜ]" "[']" t
                  ("-C" "-d" "de_DE-neu.multi")
                  "~latin1" iso-8859-1)))

(if (my-system-type-is-windows)
    ;; use british english on powerplantwin:
    (let ((langs '("german8" "british")))
      (setq lang-ring (make-ring (length langs)))
      (dolist (elem langs) (ring-insert lang-ring elem)))
  )
(if (my-system-type-is-gnu)
    ;; use US english on powerplantwin:
    (let ((langs '("de_AT" "en_US")))
      (setq lang-ring (make-ring (length langs)))
      (dolist (elem langs) (ring-insert lang-ring elem)))
  ;; use american english on all other systems:
  (let ((langs '("german8" "british")))
    (setq lang-ring (make-ring (length langs)))
    (dolist (elem langs) (ring-insert lang-ring elem)))
  )

my-toggle-ispell-language() → S-F5

my-toggle-ispell-language() because I use two languages and switch between them:

(defun my-toggle-ispell-language ()
  (interactive)
  (let ((lang (ring-ref lang-ring -1)))
    (ring-insert lang-ring lang)
    (ispell-change-dictionary lang)))

auto-dictionary-mode

This mode determines the dictionary language for the current buffer according to the text found. It switches language automatically when you switch the language you’re typing.

What a relief for bilingual people like me (German/English).

(use-package auto-dictionary
   :load-path "~/.emacs.d/contrib/auto-dictionary-mode/"
)

(require 'auto-dictionary)
(add-hook 'flyspell-mode-hook (lambda () (auto-dictionary-mode 1)))

Spellchecking Source Code

Modes for programming languages; check spelling only in comments/strings

(add-hook          'c-mode-hook 'flyspell-prog-mode)
(add-hook         'sh-mode-hook 'flyspell-prog-mode)
(add-hook        'c++-mode-hook 'flyspell-prog-mode)
(add-hook       'ruby-mode-hook 'flyspell-prog-mode)
(add-hook      'cperl-mode-hook 'flyspell-prog-mode)
(add-hook     'python-mode-hook 'flyspell-prog-mode)
(add-hook   'autoconf-mode-hook 'flyspell-prog-mode)
(add-hook   'autotest-mode-hook 'flyspell-prog-mode)
(add-hook   'makefile-mode-hook 'flyspell-prog-mode)
(add-hook 'emacs-lisp-mode-hook 'flyspell-prog-mode)

Keybindings

bind-keys:

(define-key global-map [(f5)] 'flyspell-mode)
(bind-key "fm" 'flyspell-mode my-map);; also mapped to F5
(bind-key "fr" 'flyspell-region my-map)
(bind-key "fl" 'my-toggle-ispell-language my-map);; also mapped to Shift-F5
(define-key global-map [(shift f5)] 'my-toggle-ispell-language)
(bind-key "ft" 'my-toggle-ispell-language my-map);; can't remember if l(anguage) or t(oggle)
(bind-key "fn" 'flyspell-goto-next-error my-map)
(define-key global-map [(f6)] 'flyspell-goto-next-error)
(bind-key "ff" 'flyspell-correct-word-before-point my-map)
(define-key global-map [(f7)] 'flyspell-correct-word-before-point)

End of aspell

);; when aspell found

flycheck

«Flycheck is a modern on-the-fly syntax checking extension for GNU Emacs, intended as replacement for the older Flymake extension which is part of GNU Emacs.»

(use-package flycheck
  :ensure t
  :init
  (global-flycheck-mode)
  :config
  (setq flycheck-flake8-maximum-line-length 200); http://www.flycheck.org/manual/latest/Configuring-checkers.html#Configuring-checkers
  )

Snippets

German blog article on snippet systems: http://www.karl-voit.at/Textbausteine/

I do recommend to use snippet systems for quickly inserting static (words/numbers, sentences, paragraphs, …) or dynamic (current date/time) text.

Most snippets, I do define in a system-wide tool so that I am able to use them in every program. Some snippets I do define and use only within Emacs. Yasnippet and yankpad offers me very advanced functionality to define and use most elaborate snippets. Those snippets vary from simple ones (e.g., check-lists for packing for vacations) to rather advanced ones (e.g., a complete lecture organization with many tasks and their dependencies).

yasnippet

Yasnippet is the snippet tool to use within Emacs:

(use-package yasnippet
  :demand t
  :mode ("/\\.emacs\\.d/etc/yasnippet/snippets/" . snippet-mode)
  :diminish yas-minor-mode
  :defer 15
  :config
  (yas-load-directory (concat my-user-emacs-directory "etc/yasnippet/snippets/"))
  (yas-global-mode 1)

  ;; http://yasnippet.googlecode.com/svn/trunk/doc/index.html
  ;;disabled;(my-load-local-el "contrib/yasnippet/yasnippet.el")
  ;;(autoload 'yas-minor-mode "yasnippet")

  ;;disabled 2015-04-01 - issues did not vanish;; ;; https://capitaomorte.github.io/yasnippet/faq.html#sec-4
  ;;disabled 2015-04-01 - issues did not vanish;; ;; How to I use alternative keys, i.e. not TAB?
  ;;disabled 2015-04-01 - issues did not vanish;; ;; see id:2015-02-01-yas-expand-not-TAB
  ;;disabled 2015-04-01 - issues did not vanish;; (define-key yas-minor-mode-map (kbd "<tab>") nil)
  ;;disabled 2015-04-01 - issues did not vanish;; (define-key yas-minor-mode-map (kbd "TAB") nil)
  ;;disabled 2015-04-01 - issues did not vanish;; (define-key yas-minor-mode-map (kbd "<f4>") 'yas-expand)

)

yankpad

yankpad is an add-on that enables easy management of yasnippet snippets within an Org-mode file. I do define Org-mode-independent snippets with the basic yasnippet methods. Any snippet that is used within Org-mode only is defined in my yankpad file.

  • see also: id:2016-08-08-yankpad-test
(use-package yankpad
  :ensure t
  :defer 10
  :init
  (setq yankpad-file "~/org/yankpad.org")
  :bind (:map my-map ("SPC" . yankpad-insert))
  :config
  ;; (bind-key "<f6>" 'yankpad-map))
)

Elisp

This heading contains configurations for editing Elisp code.

separate color for highlightning () brackets: http://compgroups.net/comp.emacs/to-use-special-color-for-brackets-in-emacs-lisp-mo/222015

;; ######################################################
(defface paren-face
  '((((class color) (background dark))
     (:foreground "grey30"))
    (((class color) (background light))
     (:foreground "grey60")))
  "Face used to dim parentheses.")
(defun egoge-dim-parens ()
  (font-lock-add-keywords nil
			  '(("(\\|)" . 'paren-face))))
(add-hook 'emacs-lisp-mode-hook 'egoge-dim-parens)

Do not use Auto Fill Mode for Lisp mode:

(add-hook 'emacs-lisp-mode-hook 'turn-off-auto-fill)

When editing code that uses parenthesis, enabling this does highlight the matching parenthesis:

(show-paren-mode t)

ert

for using unit tests of yasnippet (see id:2013-02-07yasnippetdebuggen and yasnippet-tests.el)

(my-load-local-el "contrib/cl-lib.el")
(my-load-local-el "contrib/ert.el")
(my-load-local-el "contrib/ert-x.el")

buttercup - Elisp test suite

Buttercup is a behavior-driven development framework for testing Emacs Lisp code. It allows to group related tests so they can share common set-up and tear-down code, and allows the programmer to “spy” on functions to ensure they are called with the right arguments during testing.

The framework is heavily inspired by Jasmine.

Disabled for now because I do not use it at the moment.

(use-package buttercup
  :ensure t
;  :if (my-system-is-floyd)
  :defer 10
  :config
)

smartparens - highlight corresponding parens

(use-package smartparens
  :init
  (smartparens-global-mode 1)
  (show-smartparens-global-mode +1)

  :bind (;; ("M-n" . sp-next-sexp)
         ;; ("M-p" . sp-previous-sexp)
         ("M-f" . sp-forward-sexp)
         ("M-b" . sp-backward-sexp)
         )

  :config
  ;; Enable smartparens everywhere
  (use-package smartparens-config)

  ;; ;; Require and disable paredit because some packages rely on it.
  ;; (use-package paredit)
  ;; (disable-paredit-mode)

  (setq
   smartparens-strict-mode t
   sp-autoinsert-if-followed-by-word t
   sp-autoskip-closing-pair 'always
   ;;sp-base-key-bindings 'paredit
   sp-hybrid-kill-entire-symbol nil)

  ;; (sp-use-paredit-bindings)

  ;; (sp-with-modes '(markdown-mode gfm-mode rst-mode)
  ;;   (sp-local-pair "*" "*" :bind "C-*")
  ;;   (sp-local-tag "2" "**" "**")
  ;;   (sp-local-tag "s" "```scheme" "```")
  ;;   (sp-local-tag "<"  "<_>" "</_>" :transform 'sp-match-sgml-tags))

  ;; ;; Close a backtick with another backtick in clojure-mode
  ;; (sp-local-pair 'clojure-mode "`" "`" :when '(sp-in-string-p))

  (sp-local-pair 'emacs-lisp-mode "`" nil :when '(sp-in-string-p))
  )

s - «The long lost Emacs string manipulation library.»

https://github.com/magnars/s.el

(use-package s
  :ensure t
  :defer 10
  :config
)

Elisp: → my-map er|el|ef

Misc bindings for Elisp:

(bind-key "er" #'eval-region my-map)
(bind-key "el" #'find-library my-map)
(bind-key "ef" #'find-function-at-point my-map)

macrostep

I found the macrostep package through the Irreal article John Wiegley and Sacha Chua on use-package which links 2015-04-01 Emacs package highlight: use-package from YouTube.

(use-package macrostep
  ;;:ensure t
  :defer 15
  :load-path "~/.emacs.d/contrib/macrostep/" ;; relative to emacs dir
  :config ;; executed after loading package
  (define-key emacs-lisp-mode-map (kbd "C-c e") 'macrostep-expand)
)

From the README:

The standard keybindings in macrostep-mode are the following:

e, =, RET
expand the macro form following point one step
c, u, DEL
collapse the form following point
q, C-c C-c
collapse all expanded forms and exit macrostep-mode
n, TAB
jump to the next macro form in the expansion
p, M-TAB
jump to the previous macro form in the expansion

It’s not very useful to enable and disable macrostep-mode directly. Instead, bind macrostep-expand to a key in emacs-lisp-mode-map, for example C-c e:

 (define-key emacs-lisp-mode-map (kbd "C-c e") 'macrostep-expand)
  

You can then enter macrostep-mode and expand a macro form completely by typing C-c e e e ... as many times as necessary.

Exit macrostep-mode by typing q or C-c C-c, or by successively typing c to collapse all surrounding expansions.

Python

This heading contains configurations for editing Python code. Python is the programming language I prefer for my private projects. I do like its easy-to-read syntax, providing a high level of maintainability. It also ships with a large set of libraries.

Misc stuff is taken from: https://github.com/jorgenschaefer/elpy/wiki/

Some keyboard commands (summary):

KeyCommand
F5flymake-goto-prev-error
F6flymake-goto-next-error
my-map Ppylookup

BEGIN of Python-related stuff

The code blocks here are only executed when python is found on the current system:

(when (my-eval-if-binary-or-warn "python")

BEGIN of Elpy

Elpy provides a very cool programming experience for Python code.

BEGIN of elpy package

(use-package elpy
  :ensure t
  ;;:if (or (my-system-type-is-gnu) (my-system-type-is-windows))
  :mode ("\\.py\\'" . elpy-mode)
  :config ;; executed after loading package

enable elpy and use ipython:

(elpy-enable)
(elpy-use-ipython)

Switch for ipython (NOT YET TESTED)

From this reddit and this solution: NOT TESTED YET! (2017-10-02)

(when (my-eval-if-binary-or-warn "ipython")
    (setq python-shell-interpreter "ipython"
        python-shell-interpreter-args "--simple-prompt -i")
)

auto-mode-list for Python files

(add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
(add-to-list 'auto-mode-alist '("\\.py$" . company-mode))

ropemacs

ropemacs is an evironment that provides advanced things such as refactoring:

http://www.saltycrane.com/blog/2010/05/my-emacs-python-environment/ Ropemacs:

(add-to-list 'load-path (concat my-user-emacs-directory "vendor/pymacs-0.24-beta2"))
(use-package pymacs)
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-enable-autoimport t)

auto-completion

(use-package auto-complete
  :ensure t
)
(add-to-list 'load-path (concat my-user-emacs-directory "vendor/auto-complete-1.2"))
(use-package auto-complete-config)
(add-to-list 'ac-dictionary-directories (concat my-user-emacs-directory "vendor/auto-complete-1.2/dict"))
(ac-config-default)

pyflakes

Pyflakes is a simple program which checks Python source files for errors:

(setq python-check-command "pyflakes")

flymake, flycheck

FlyMake performs on-the-fly syntax checks on the files being edited using the external syntax check tool (usually the compiler). Highlights erroneous lines and displays associated error messages.

Unfortunately, this project is outdated and last change was 3 years ago.

For a modern alternative, check out Flycheck.

(when (load "flymake" t)
  (defun flymake-pyflakes-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-inplace))
           (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name))))
      (list "~/bin/pycheckers"  (list local-file))))
  (add-to-list 'flymake-allowed-file-name-masks
               '("\\.py\\'" flymake-pyflakes-init)))

better than flymake (and maintained): http://stackoverflow.com/a/1621489 Flycheck

(add-hook 'python-mode-hook
    (lambda ()
      (unless (eq buffer-file-name nil) (flymake-mode 1)) ;dont invoke flymake on temporary buffers for the interpreter
      (local-set-key [f5] 'flymake-goto-prev-error)
      (local-set-key [f6] 'flymake-goto-next-error)
      ))

pylookup

pylookup: Emacs mode for searching python documents with convenience

  ;; add pylookup to your loadpath, ex) ~/.emacs.d/pylookup
  (setq pylookup-dir (concat my-user-emacs-directory "contrib/pylookup"))
  (add-to-list 'load-path pylookup-dir)
  ;; load pylookup when compile time
;  (eval-when-compile (require 'pylookup))
  ;; set executable file and db file
  (setq pylookup-program (concat pylookup-dir "/pylookup.py"))
  (setq pylookup-db-file (concat pylookup-dir "/pylookup.db"))
  ;; set search option if you want
  ;; (setq pylookup-search-options '("--insensitive" "0" "--desc" "0"))

  ;; to speedup, just load it on demand
  (autoload 'pylookup-lookup "pylookup"
    "Lookup SEARCH-TERM in the Python HTML indexes." t)

  ;; MANUALLY run the DB update on LOCAL resources:
  ;; 1) install Debian package "python-doc"
  ;; 2) run: ~/.emacs.d/contrib/pylookup/pylookup.py -u ~doc/python2.7/html
  (autoload 'pylookup-update "pylookup"
    "Run pylookup-update and create the database at `pylookup-db-file'." t)

  (define-key my-map "P" 'pylookup-lookup)

hideshow-orgmode (NOT WORKING YET)

I found hideshow-orgmode via this reddit thread. It provides (Python) code outlining similar to Org-mode TAB visibility cycling. This is a very nice thing to have. So far, I used yafolding-mode for it.

Set-up on 2017-10-28 but did not work out of the box (nothing changes when I do hs-cycle(-all)). I have to invest this issue when I’ve got more time.

(use-package hideshow-orgmode
  :load-path  (lambda () (expand-file-name (concat my-user-emacs-directory "contrib/hideshow-orgmode")))
  :config
  (global-set-key (kbd "M-h") 'hs-cycle)
  (global-set-key (kbd "M-H") 'hs-cycle-all)
)

END of Python-related stuff + Elpy

);; use-package
);; if python binary found

dired

Usually, I do file management in tmux and zsh. There are my aliases, my functions, the features I like.

Having a file manager in Emacs does have some advantages, I guess. Maybe I’ll try it some day.

Here are some minor tweaks related to file management in Emacs with dired.

From Emacsrocks #16: two window file management. From the documentation:

If non-nil, Dired tries to guess a default target directory. This means: if there is a Dired buffer displayed in the next window, use its current directory, instead of this Dired buffer’s current directory.

(setq dired-dwim-target t)

Also from Emacsrocks #16: hide and show file details with ( and ):

(use-package dired-details
  :load-path  (lambda () (expand-file-name (concat my-user-emacs-directory "contrib/")))
  :config
  (setq-default dired-details-hidden-string "")
  )

LaTeX

LaTeX is a powerful text setting system I use for creating letters, books, presentations, and so forth.

AucTeX is an awesome handy mode for working with TeX code.

BEGIN of LaTeX settings (only if “pdflatex” is found on the system):

(when (my-eval-if-binary-or-warn "pdflatex")

General LaTeX settings:

(autoload 'tex-site "tex-site.el")  ;; acticate AucTeX and set general preferences

(setq TeX-PDF-mode t)  ;; compile to PDF using pdflatex (instead to DVI)

(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill) ;; word-wrap in TeX files

(setq TeX-auto-save t)
(setq TeX-parse-self t)

;(setq-default TeX-master nil);; 2015-03-22 deactivated because it doesn't seem to have any influence: id:2013-12-31-org-master-file
(make-variable-buffer-local 'TeX-master) ;; I think this is need because the variable is not buffer local until Auctex is active

Synctex is a nice add-on that synchronizes the editing tool (Emacs/AucTeX) with a PDF viewing tool (e.g., Okular): http://www.bleedingmind.com/index.php/2010/06/17/synctex-on-linux-and-mac-os-x-with-emacs/

(when (my-eval-if-binary-or-warn "synctex")
  (add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
  (setq TeX-source-correlate-method 'synctex)
)

Define system-specific PDF viewers and further Synctex settings:

(defun okular-make-url () (concat
      		     "file://"
      		     (expand-file-name (funcall file (TeX-output-extension) t)
      				       (file-name-directory (TeX-master-file)))
      		     "#src:"
      		     (TeX-current-line)
      		     (TeX-current-file-name-master-relative))
       "./"
       (TeX-current-file-name-master-relative)
       )

(defun skim-make-url () (
      		   concat
      		   (TeX-current-line)
      		   " "
      		   (expand-file-name (funcall file (TeX-output-extension) t)
      				     (file-name-directory (TeX-master-file)))
      		   " "
      		   (buffer-file-name))
       )

(setq TeX-view-program-list '(
      			("Okular" "okular --unique %u")
      			("Skim" "/Applications/Skim.app/Contents/SharedSupport/displayline %q")
      			)
      )

(when (my-system-type-is-gnu)
  (setq TeX-view-program-selection '((output-pdf "Okular") (output-dvi "Okular")))
  (eval-after-load "tex"
    '(add-to-list 'TeX-expand-list '("%u" okular-make-url))
    )
  )

(when (my-system-type-is-darwin)
  (setq TeX-view-program-selection '((output-pdf "Skim")))
  (eval-after-load "tex"
    '(add-to-list 'TeX-expand-list '("%q" skim-make-url))
    )
  )

https://tex.stackexchange.com/questions/60170/how-to-set-up-okular-for-forward-backward-search-with-tex-live-2011-not-trivia

(add-hook ‘LaTeX-mode-hook
(lambda ()
  (add-to-list ‘TeX-expand-list
  ‘(“%u” okular-make-url))))

CDLaTeX is a minor mode for Emacs supporting fast insertion of environment templates and math stuff in LaTeX.

I tried it once but do not use it any more.

(when (or (my-system-type-is-gnu) (my-system-is-powerplantlinux))
  (my-load-local-el "contrib/cdlatex.el")
  )

RefTeX is the package for LaTeX that does manage references.

http://www.tug.org/pipermail/macostex-archives/2005-November/018997.html

  • reftex
  • TeX-fold-mode
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
(add-hook 'LaTeX-mode-hook '(lambda () (TeX-fold-mode 1)))

BibLaTeX provides bibliographic facilities. Biber is a moder implementation of it. I prefer it for generating references and its indexes.

http://www.mail-archive.com/auctex@gnu.org/msg04137.html

(eval-after-load "tex"
  '(add-to-list 'TeX-command-list
      	  '("Biber" "biber %s" TeX-run-Biber nil t :help "Run Biber") t))

(defun TeX-run-Biber (name command file)
  "Create a process for NAME using COMMAND to format FILE with Biber."
  (let ((process (TeX-run-command name command file)))
    (setq TeX-sentinel-function 'TeX-Biber-sentinel)
    (if TeX-process-asynchronous
        process
      (TeX-synchronous-sentinel name file process))))

(defun TeX-Biber-sentinel (process name)
  "Cleanup TeX output buffer after running Biber."
  (goto-char (point-max))
  (cond
   ;; Check whether Biber reports any warnings or errors.
   ((re-search-backward (concat
      		   "^(There \\(?:was\\|were\\) \\([0-9]+\\) "
      		   "\\(warnings?\\|error messages?\\))") nil t)
    ;; Tell the user their number so that she sees whether the
    ;; situation is getting better or worse.
    (message (concat "Biber finished with %s %s. "
      	       "Type `%s' to display output.")
             (match-string 1) (match-string 2)
             (substitute-command-keys
      	"\\\\[TeX-recenter-output-buffer]")))
   (t
    (message (concat "Biber finished successfully. "
      	       "Run LaTeX again to get citations right."))))
  (setq TeX-command-next TeX-command-default))
(setq reftex-bibpath-environment-variables
      '("~/archive/library/"))
(defun guess-TeX-master (filename)
    "Guess the master file for FILENAME from currently open files according to their extension."
    (let ((candidate nil)
          (filename (file-name-nondirectory filename)))
      (save-excursion
        (dolist (buffer (buffer-list))
          (with-current-buffer buffer
            (let ((name (buffer-name))
                  (file buffer-file-name))
              ;(if (and file (string-match "\\.\(org\|tex\)$" file))
              (if (and file (string-match "\\.org$" file))
                  (progn
                    (goto-char (point-min))
                    (if (re-search-forward (concat "\\\\input{" filename "}") nil t)
                        (setq candidate file))
                    (if (re-search-forward (concat "\\\\include{" (file-name-sans-extension filename) "}") nil t)
                        (setq candidate file))))))))
      (if candidate
          (message "TeX master document: %s" (file-name-nondirectory candidate)))
      candidate))

;; ONLY for special file modes with a recognized extension!
;; Causes Lisp error (that's a afact) when used with buffers like *scratch* (that's my guess)
;;(setq TeX-master (guess-TeX-master (buffer-file-name)))

END of LaTeX settings

)

GnuPlot

«Gnuplot is a portable command-line driven graphing utility for Linux, OS/2, MS Windows, OSX, VMS, and many other platforms.»

Also very handy when visualizing table data within Org-mode! (see Org-mode/babel configuration)

Example: place the cursor within the table and evaluate org-plot/gnuplot or use the keyboard shortcut C-c " g

WhenHow many
[2016-11-17 Thu]3
[2016-11-23 Wed]4
[2016-12-10 Sat]1
;; gnuplot
(when (my-eval-if-binary-or-warn "gnuplot")
  (use-package gnuplot
    :ensure t
    :defer 10
    :if (my-system-type-is-gnu)
  )
)

Org-mode

Org-mode is my digital life. I do almost anything within Org-mode: http://karl-voit.at/tags/emacs/

I am doing Personal Information Management (PIM) for decades, tried many different methods and tools. With Org-mode my quest for the best PIM-tool out there finally came to an end. It’s an endless pile of Lego-bricks from where I can draw some bricks and assemble it to meet my requirements. Therefore, Org-mode is something different for everybody. It depends, what Lego bricks you took and how you combined them. Org-mode scales well from a simple outliner or todo-list up to something very, very big.

Almost half of my Emacs configuration deals with Org-mode. Fasten your seat belt and dive into my rabbit hole of Org …

Profiling Org-mode config loading time:

(defvar my-org-config-start-time (current-time) "Time when my org-mode config was started")
(message "★→ Org-mode")

Load Org and misc contrib packages

Since a couple of major releases GNU/Emacs comes with an Org-mode version built in. However, I do prefer the “maint” branch of the Org-mode Git repository instead. See also Installation - The Org Manual.

Note that the Org-mode paths to my manually installed Org-mode are set within init.el already.

assign file extensions to Org-mode:

(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))

2014-10-29 test

(setq org-babel-safe-header-args nil)

Loading contributed packages:

(use-package org-checklist
 :load-path "~/.emacs.d/contrib/org-mode/contrib/lisp/"
)
(use-package org-depend
 :load-path "~/.emacs.d/contrib/org-mode/contrib/lisp/"
)
(use-package org-expiry
 :load-path "~/.emacs.d/contrib/org-mode/contrib/lisp/"
)
(use-package ob-restclient
 :load-path "~/.emacs.d/contrib/ob-restclient.el/"
)

  ;;disabled;; (my-load-local-el "contrib/org-mode/contrib/lisp/ox-confluence.el")
  ;;disabled;; (my-load-local-el "contrib/org-mode/contrib/lisp/ox-freemind.el")
  (autoload 'org-checklist "org-checklist.el")

  ;; http://repo.or.cz/w/org-mode.git?a=blob_plain;f=contrib/lisp/org-expiry.el;hb=HEAD
  ;; Expiry dates handling
  (autoload 'org-expiry "org-expiry.el")

  ;; managing bookmarks with Org-mode
  ;; http://orgmode.org/worg/org-contrib/org-protocol.html
  (autoload 'org-protocol "org-protocol")

Enable misc org modules:

(setq org-modules (quote
                   (org-bbdb
        	        org-bibtex
                    org-crypt
                    org-gnus
                    org-id
                    org-info
                    org-habit
                    org-inlinetask
                    org-irc
                    org-mew
                    org-mhe
                    org-protocol
                    org-rmail
                    org-vm
                    org-wl
                    org-w3m
                    )
                   )
      )

org-favtable: I was not able to find the advantage of favtables in comparison to search or id-links:

(require 'org-favtable)
(setq org-favtable-id "my-favtable")
(global-set-key (kbd "C-+") 'org-favtable)

General Org-mode settings

http://www.reddit.com/r/emacs/comments/2m4b7j/help_setting_orgmode_as_the_default_major_mode/ - «This will make it that any file without an auto-mode alist entry gets associated with org-mode by default.»

(add-to-list 'auto-mode-alist '("'" . org-mode) t)

Might cause performance issues; http://orgmode.org/manual/Clean-view.html

(setq org-startup-indented t)
(setq org-enforce-todo-dependencies t)
(setq org-insert-heading-respect-content nil)
(setq org-reverse-note-order nil)
(setq org-show-following-heading t)
(setq org-show-hierarchy-above t)
(setq org-show-siblings nil)
(setq org-deadline-warning-days 1)
(setq org-blank-before-new-entry (quote ((heading . t)
					   (plain-list-item . nil))))

Logging into drawers:

(setq org-log-done (quote time))
(setq org-log-into-drawer t)
(setq org-log-redeadline (quote note));; record when the deadline date of a tasks is modified
(setq org-log-reschedule (quote time))
(setq org-return-follows-link t)
(setq org-remove-highlights-with-change nil)
(setq org-read-date-prefer-future nil)
(setq org-list-demote-modify-bullet (quote (("+" . "-")
					      ("*" . "-")
					      ("1." . "-")
					      ("1)" . "-"))))
(setq split-width-threshold 9999);; Minimum width for splitting windows sensibly.
(setq global-auto-revert-mode t)
(setq require-final-newline nil)
(setq org-adapt-indentation nil);; do not indent drawers/body according to heading level

Default state for repeating/recurring events

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

Smart navigation: begin/end of line is different for headings, list items, …

(setq org-special-ctrl-a/e t)
(setq org-special-ctrl-k t)

Smart yanking: https://www.gnu.org/software/emacs/manual/html_node/org/Structure-editing.html

(setq org-yank-adjusted-subtrees t)
  • until 2016-11-10, the defaults were OK to me
    • with update to Org 9, jumping from agenda to hidden heading reveales only heading but not ancestors as before
(setq org-show-context-detail
      '((agenda . lineage) ;; instead of "local"
        (bookmark-jump . lineage)
        (isearch . lineage)
        (default . ancestors))
      )

Set the timestamps of expiry.el to inactive ones: http://comments.gmane.org/gmane.emacs.orgmode/20934

(setq org-expiry-inactive-timestamps t)

Prevent accidental deleting of hole subtrees or similar

(setq org-catch-invisible-edits "smart")

Use IDO for target completion:

(setq org-completion-use-ido t)

Disable property inheritance (in order to seed up)

(setq org-use-property-inheritance nil)

https://www.gnu.org/software/emacs/manual/html_node/org/Matching-tags-and-properties.html

(setq org-tags-match-list-sublevels nil)

Prevent auto-filling for source code:

;(setq org-src-prevent-auto-filling t)

From: Release Notes v8.1: http://orgmode.org/worg/agenda-optimization.html

(setq org-agenda-ignore-drawer-properties '(effort appt stats));; agenda performance

Automatically write CREATED properties in the PROPERTIES drawer:

(org-expiry-insinuate)
;; not checked yet: (setq org-expiry-handler-function 'org-expiry-archive-subtree)

Checking org-mode syntax:

(require 'org-lint)

Open corresponding .org_archive file with ff-find-other-file

https://twitter.com/_wilfredh/status/708046038200950787 « M-x describe-function shows the docstring, which mentions ff-other-file-alist.»

;;
(defvar my-cpp-other-file-alist
'(("\\.org\\'" (".org_archive"))
  ;;("\\.ipp\\'" (".hpp" ".cpp"))
  ;;("\\.hpp\\'" (".ipp" ".cpp"))
  ;;("\\.cxx\\'" (".hxx" ".ixx"))
  ;;("\\.ixx\\'" (".cxx" ".hxx"))
  ;;("\\.hxx\\'" (".ixx" ".cxx"))
  ;;("\\.c\\'" (".h"))
  ;;("\\.h\\'" (".c"))
  ))
(setq-default ff-other-file-alist 'my-cpp-other-file-alist)

Yasnippet settings: http://yasnippet.googlecode.com/svn/trunk/doc/index.html

;;disabled;(my-load-local-el "contrib/yasnippet/yasnippet.el")
(add-hook 'org-mode-hook 'yas-minor-mode-on)
(setq yas-indent-line 'fixed) ;; fixes Org-mode issue with yasnippets: https://github.com/capitaomorte/yasnippet/issues/362
From: Bastien <bzg@altern.org>
Newsgroups: gmane.emacs.orgmode
Subject: Re: scale inline images in orgmode
Date: Thu, 30 Aug 2012 15:52:59 +0200
Message-ID: <87a9xcsczo.fsf@altern.org>

:

You can now (from git master) use `org-image-actual-width'.
(setq org-image-actual-width 300)
  => always resize inline images to 300 pixels
(setq org-image-actual-width '(400))
  => if there is a #+ATTR.*: width="200", resize to 200,
     otherwise resize to 400
(setq org-image-actual-width nil)
  => if there is a #+ATTR.*: width="200", resize to 200,
     otherwise don't resize
(setq org-image-actual-width t)
  => Never resize and use original width (the default)

scimax/org-return

Smart return does add new list item, … if appropriate

(require 'org-inlinetask)

(defun scimax/org-return (&optional ignore)
  "Add new list item, heading or table row with RET.
A double return on an empty element deletes it.
Use a prefix arg to get regular RET. "
  (interactive "P")
  (if ignore
      (org-return)
    (cond
     ((eq 'line-break (car (org-element-context)))
      (org-return-indent))
     ;; Open links like usual
     ((eq 'link (car (org-element-context)))
      (org-open-at-point-global))
     ;; It doesn't make sense to add headings in inline tasks. Thanks Anders
     ;; Johansson!
     ((org-inlinetask-in-task-p)
      (org-return))
     ;; add checkboxes
     ((org-at-item-checkbox-p)
      (org-insert-todo-heading nil))
     ;; lists end with two blank lines, so we need to make sure we are also not
     ;; at the beginning of a line to avoid a loop where a new entry gets
     ;; created with only one blank line.
     ((and (org-in-item-p) (not (bolp)))
      (if (org-element-property :contents-begin (org-element-context))
          (org-insert-heading)
        (beginning-of-line)
        (setf (buffer-substring
               (line-beginning-position) (line-end-position)) "")
        (org-return)))
     ;;disabled;; ((org-at-heading-p)
     ;;disabled;;  (if (not (string= "" (org-element-property :title (org-element-context))))
     ;;disabled;;      (progn (org-end-of-meta-data)
     ;;disabled;;             (org-insert-heading))
     ;;disabled;;    (beginning-of-line)
     ;;disabled;;    (setf (buffer-substring
     ;;disabled;;           (line-beginning-position) (line-end-position)) "")))
     ((org-at-table-p)
      (if (-any?
           (lambda (x) (not (string= "" x)))
           (nth
            (- (org-table-current-dline) 1)
            (org-table-to-lisp)))
          (org-return)
        ;; empty row
        (beginning-of-line)
        (setf (buffer-substring
               (line-beginning-position) (line-end-position)) "")
        (org-return)))
     (t
      (org-return)))))


(define-key org-mode-map (kbd "RET")
  'scimax/org-return)

org-file-apps -> open files in external apps

Here is a list of file extensions that should be openend outside of Emacs:

;;(add-to-list 'org-file-apps '("\\.odp" . system))
;;(add-to-list 'org-file-apps '("\\.odp" . mailcap))
(add-to-list 'org-file-apps '("\\.odp" . "open %s"))
;;(add-to-list 'org-file-apps '("\\.odp" . "/usr/bin/xdg-open %s"))

Styling

Omit the headline-asterisks except the last one:

(setq org-hide-leading-stars t)

http://orgmode.org/org.html - show blocked tasks in agenda in gray color

;;disabled;(setq org-agenda-dim-blocked-tasks t)
(setq org-agenda-dim-blocked-tasks 'invisible)

syntax highlighting in source code:

from Eric Schulte <eric.schulte@gmx.com>
     Newsgroups: gmane.emacs.orgmode
     Subject: Re: org mode in press
     Date: Sat, 28 Jan 2012 10:06:08 -0700
     Message-ID: <87ipjv92pr.fsf@gmx.com>
  • 2014-04-04: set to nil in order to avoid performance issues!
  • 2015-12-26: set to t to test again these days
    • seems to be OK now
(setq org-src-fontify-natively t)

automatically change status of a heading to DONE when all children are done:

(defun org-summary-todo (n-done n-not-done)
  "Switch entry to DONE when all subentries are done, to TODO otherwise."
  (let (org-log-done org-log-states)   ; turn off logging
    (org-todo (if (= n-not-done 0) "DONE" "TODO"))))
(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)

Statistic cookies count ALL subtasks not only direkt ones

(setq org-hierarchical-todo-statistics t)

Stop the mouse cursor from highlighting lines in the agenda: http://orgmode.org/worg/org-faq.html

(add-hook 'org-finalize-agenda-hook
          (lambda () (remove-text-properties
                      (point-min) (point-max) '(mouse-face t))))

Changing the default ellipsis to something that can’t be mixed up with normal characters: http://endlessparentheses.com/changing-the-org-mode-ellipsis.html

Note: on some computers, this results in higher line height as described on http://emacs.stackexchange.com/questions/251/line-height-with-unicode-characters See: id:2016-08-19-unicode-enlarges-line-height

(setq org-ellipsis "")

Set the width of inline images:

(setq org-image-actual-width '(400))

Nice looking bullets for headings:

(use-package org-bullets
  :ensure t
  :config ;; executed after loading package
  (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
)

General key bindings

Standard key bindings:

  (global-set-key "\C-cl" 'org-store-link)
  (global-set-key "\C-ca" 'org-agenda)
;;obsolete:  (global-set-key "\C-cb" 'org-iswitchb)

unset C-c , (org-priority) because I get confused when I mistype C-c C-,

;;(global-unset-key (kbd "C-c ,"))
(global-set-key (kbd "C-c ,") 'my-map)

Remembering positions:

(global-set-key (kbd "C-c %") 'org-mark-ring-push)
(global-set-key (kbd "C-c <left>") 'org-mark-ring-goto)
(global-set-key (kbd "C-c <down>") 'org-mark-ring-push)

MISC Apple bindings

(setq mac-command-modifier 'apple)
(global-set-key [(<apple> <up>)] 'org-move-subtree-up)
(global-set-key "\S-<down>" 'org-move-subtree-down)
(global-set-key "\S-<left>" 'org-do-promote)
(global-set-key "\S-<right>" 'org-do-demote)

Org-mode keys for Mac

  • I wanted to map Alt-left|right|… but Alt has to be used by the system in order to type umlauts :-(
(setq mac-command-modifier 'apple)
(global-set-key [(<apple> <up>)] 'org-move-subtree-up)
(global-set-key "\S-<down>" 'org-move-subtree-down)
(global-set-key "\S-<left>" 'org-do-promote)
(global-set-key "\S-<right>" 'org-do-demote)

fix broken mapping (because of prelude and so on).

  • disabled 2014-01-19
(defun my-org-mode-hook ()
  (define-key prelude-mode-map (kbd "C-c +") nil)
  (define-key prelude-mode-map (kbd "C-c -") nil)
  )
(add-hook 'org-mode-hook 'my-org-mode-hook)

My general Org helper functions

my-url-linkify() → my-map u

Replaces URL with Org-mode link including description

  (defun my-www-get-page-title (url)
    "retrieve title of web page.
from: http://www.opensubscriber.com/message/help-gnu-emacs@gnu.org/14332449.html"
    (let ((title))
      (with-current-buffer (url-retrieve-synchronously url)
	(goto-char (point-min))
	(re-search-forward "<title>\\([^<]*\\)</title>" nil t 1)
	(setq title (match-string 1))
	(goto-char (point-min))
	(re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1)
        (string-replace "&nbsp;" " "
                        ;;(decode-coding-string title (intern (match-string 1)))
                        ;; following line fixes charset issues from
                        ;; previous line:
                        (decode-coding-string title 'utf-8)
                        ))
      )
    )
  (defun my-url-linkify ()
    "Make URL at cursor point into an Org-mode link.
If there's a text selection, use the text selection as input.

Example: http://example.com/xyz.htm
becomes
\[\[http://example.com/xyz.htm\]\[Source example.com\]\]

Adapted code from: http://ergoemacs.org/emacs/elisp_html-linkify.html"
    (interactive)
    (let (resultLinkStr bds p1 p2 domainName)
      ;; get the boundary of URL or text selection
      (if (region-active-p)
	  (setq bds (cons (region-beginning) (region-end)) )
	(setq bds (bounds-of-thing-at-point 'url))
	)
      ;; set URL
      (setq p1 (car bds))
      (setq p2 (cdr bds))
      (let (
	    (url (buffer-substring-no-properties p1 p2))
	    )
	;; retrieve title
	(let ((title (my-www-get-page-title url)))
	  (message (concat "title is: " title))
	  ;;(setq url (replace-regexp-in-string "&" "&amp;" url))
	  (let ((resultLinkStr (concat "[[" url "][" title "]]")))
	    ;; delete url and insert the link
	    (delete-region p1 p2)
	    (insert resultLinkStr)
	    )
	  )
	)
      )
    )

Bind the key:

(bind-key "u" 'my-url-linkify my-map)

my-org-startup-visibility()

Sometimes, I get a mess with all kinds of sub-hierarchies openend in my most important Org-mode buffers. When I want to get the startup visibility, I invoke this function to get a fresh environment again.

Take a look at my-reset-org() as well.

(defun my-org-startup-visibility (&optional ignore)
  "Sets the startup visibility in my most important buffers"
  (interactive "P")
  (save-window-excursion ;; Why save-excursion is not sufficient here: https://emacs.stackexchange.com/questions/24133/save-excursion-doesnt-restore-the-currently-visible-buffer
    (when (my-buffer-exists "misc.org")
      (switch-to-buffer "misc.org")
      (org-set-startup-visibility)
      )
    (when (my-buffer-exists "projects.org")
      (switch-to-buffer "projects.org")
      (org-set-startup-visibility)
      )
    (when (my-buffer-exists "issues.org")
      (switch-to-buffer "issues.org")
      (org-set-startup-visibility)
      )
    (when (my-buffer-exists "contacts.org")
      (switch-to-buffer "contacts.org")
      (org-set-startup-visibility)
      )
    (when (my-buffer-exists "notes.org")
      (switch-to-buffer "notes.org")
      (org-set-startup-visibility)
      )
    (when (my-buffer-exists "hardware.org")
      (switch-to-buffer "hardware.org")
      (org-set-startup-visibility)
      )
    (when (my-buffer-exists "public_voit.org")
      (switch-to-buffer "public_voit.org")
      (org-set-startup-visibility)
      )
    (when (my-system-type-is-windows)
      (when (my-buffer-exists "detego.org")
        (switch-to-buffer "detego.org")
        (org-set-startup-visibility)
        )
      (when (my-buffer-exists "ciso.org")
        (switch-to-buffer "ciso.org")
        (org-set-startup-visibility)
        )
      )
    )
  )

my-reset-org() - reset some Org-mode stuff

This function summarizes some other functions that clear up the current Org-mode, re-building some caches and so fort.

Take a look at my-org-startup-visibility() as well.

(defun my-reset-org ()
  "Clears all kinds of Org-mode caches and re-builds them if possible"
  (interactive)
  (measure-time
   (org-element-cache-reset)
   (org-refile-cache-clear)
   (org-refile-get-targets)
   (setq org-agenda-tags-column (- (- (window-total-width) 3))) ;; total width minus 3
   (when (my-buffer-exists "*Org Agenda*")
     (kill-buffer "*Org Agenda*")
     (org-agenda-list)
     )
   )
  )

when being idle for 15 minutes, run my-reset-org()

  • See id:2016-06-05-reset-things-after-15-min-idle

current-idle-time example: (0 420 1000 0)

Disabled because it doesn’t work:

(setq my-reset-org-previous-idle-time-invocation (current-time))
(run-with-idle-timer (* 60 15) t (lambda ()
                                   (if (< 2 (float-time (time-since my-reset-org-previous-idle-time-invocation)))
                                       (sit-for 2)
                                     (when (< (nth 1 (current-idle-time)) (* 60 16));; run only once per idle period
                                       (message "Idle for 15 minutes, invoking my-reset-org in 10 seconds ...")
                                       (sit-for 10);; give user 10s to press a button to prevent this
                                       (when (< (nth 1 (current-idle-time)) (* 60 16));; run only once per idle period
                                         (my-reset-org)
                                         (setq my-reset-org-previous-idle-time-invocation (current-time))
                                         (message (concat "my-reset-org finished at " (current-time-string)))
                                         )
                                       )
                                     )
                                   ))

;;(defun mytest ()
;;     (when (< (nth 1 (or (current-idle-time) (list 0 0 0 0)))) (* 60 16));; run only once per idle period
;;       (message "yes")
;;       )
;;     )
;;
;;(sit-for 3)
;;(message (or (current-idle-time) (number-to-string 0)))

Functions for Working Hour Calculation

I used this code to derive working hours until the company switched to a stupid new tool everybody hates. Yes, even worse than SAP.

This is just for the record because it contains much Elisp sweat from my side:

(defun my-extract-minutes-of-hm-string(hm-string)
  "returns the minutes of a string like 9:42 -> 42 (and 0 if there are no minutes)"
  (let (
	;; minutes is the second element after splitting with ":"
	(minutes (nth 1 (split-string hm-string ":")))
	)
    ;; if there is no second element, return "0" (instead of nil)
    (if (eq minutes 'nil)
	0
      (string-to-number minutes)
      )
    )
  )

(defun my-extract-hours-of-hm-string(hm-string)
  "returns the hours of a string like 9:42 -> 9"
  (string-to-number
   (car
    (split-string hm-string ":")
    )
   )
)

(defun my-hm-string-to-minutes(hm-string)
  "returns the minutes of a string like 2:42 -> 162"
  (let (
	;; minutes is the second element after splitting with ":"
	(minutes (my-extract-minutes-of-hm-string hm-string))
	(hours (my-extract-hours-of-hm-string hm-string))
	)
    (+ minutes (* hours 60))
    )
  )


;; EXAMPLE USAGE:
;; | [2015-01-13 Di] | Tue | 08:53-17:23 |   |   | 8:30 | 8:30 | 100 | Product Development |       |
;; |                 |     |             |   |   |      | korr |   % | Was                 | Notiz |
;; #+TBLFM: $7=$6::$9=Product Development::$8 = '(my-percentage-of-hm-string-with-day $7 $2)

(defun my-percentage-of-hm-string-with-day(hm-string day)
  "percentage of HH:MM when 8h30min (Mon-Thu) or 4h30min (Fri) are 100 percent"
  (let (
	(hours (my-extract-hours-of-hm-string hm-string));; integer of hours from hm-string
	(minutes (my-extract-minutes-of-hm-string hm-string));; integer of minutes from hm-string
        (norm-hour-minutes (cond
                            ((string= day "Mon") 8.5)
                            ((string= day "Mo")  8.5)
                            ((string= day "Tue") 8.5)
                            ((string= day "Di")  8.5)
                            ((string= day "Wed") 8.5)
                            ((string= day "Mi")  8.5)
                            ((string= day "Thu") 8.5)
                            ((string= day "Do")  8.5)
                            ((string= day "Fri") 4.5)
                            ((string= day "Fr")  4.5)
                            )
                           )
	)
    ;;debug;;(message (concat "norm-hour-minutes for " day " is " (number-to-string norm-hour-minutes)))
    (let (
	  (hoursminutes (+ hours (/ minutes 60.00))) ;; 8h30min -> 8.5h
	  )
      (round (* 100 (/ hoursminutes norm-hour-minutes)));; hoursminutes in relation to norm-hoursminutes
      )
    )
  )

(defun my-calculate-office-hour-total(officestart officeend lunchstart lunchend)
  "calculates the total hours:minutes of a work-day depending on time of arrival/leave and lunch break in HH:MM"
  (let (
	(officestartminutes (my-hm-string-to-minutes officestart));; integer of minutes
	(officeendminutes (my-hm-string-to-minutes officeend));; integer of minutes
	(lunchstartminutes (my-hm-string-to-minutes lunchstart));; integer of minutes
	(lunchendminutes (my-hm-string-to-minutes lunchend));; integer of minutes
	)
    (let* (
          (officeminutes (- (- officeendminutes officestartminutes) (- lunchendminutes lunchstartminutes)))
          (officeminutesstring (format-time-string "%H:%M" (seconds-to-time (* 60 officeminutes)) t))
          )
      ;;(message (concat "Minutes epoch: " (number-to-string officeminutes)))
      ;;(message (concat "Minutes string: " officeminutesstring))
      (symbol-value 'officeminutesstring)
      )
    )
  )
;; (my-calculate-office-hour-total "09:57" "17:22" "11:35" "12:08") -> Minutes epoch: 412 | Minutes string: 06:52


;; #############################################################################

my-insert-orgmode-url-from-clipboard() → my-map U

Inserts URL from clipboard and retrieves title as Org-mode link

straight-string()

(defun straight-string (s)
  "Spliting the string and then concatenating it back."
  (mapconcat #'(lambda (x) x) (split-string s) " "))

my-cliplink-format-and-trim-title(title) does replace HTML entities with their Unicode characters and trims the title to 100 characters.

The replacement table is taken from this ErgoEmacs page.

(defun my-cliplink-format-and-trim-title (title)
  (let (;; Table of replacements which make this title usable for
        ;; org-link. Can be extended.
        (replace-table '(("\\[" . "{")
                         ("\\]" . "}")
                         ("&amp;" . "&") ("&#039;" . "'") ("&#8211;" . "")
			         ("&nbsp;" . " ") ("&ensp;" . "") ("&emsp;" . "") ("&thinsp;" . "")
			         ("&rlm;" . "") ("&lrm;" . "") ("&zwj;" . "") ("&zwnj;" . "")
			         ("&iexcl;" . "¡") ("&cent;" . "¢") ("&pound;" . "£") ("&curren;" . "¤") ("&yen;" . "¥") ("&brvbar;" . "¦") ("&sect;" . "§")
			         ("&uml;" . "¨") ("&copy;" . "©") ("&ordf;" . "ª") ("&laquo;" . "«") ("&not;" . "¬") ("&shy;" . "­") ("&reg;" . "®")
			         ("&macr;" . "¯") ("&deg;" . "°") ("&plusmn;" . "±") ("&sup2;" . "²") ("&sup3;" . "³") ("&acute;" . "´") ("&micro;" . "µ")
			         ("&para;" . "") ("&middot;" . "·") ("&cedil;" . "¸") ("&sup1;" . "¹") ("&ordm;" . "º") ("&raquo;" . "»") ("&frac14;" . "¼")
			         ("&frac12;" . "½") ("&frac34;" . "¾") ("&iquest;" . "¿") ("&Agrave;" . "À") ("&Aacute;" . "Á") ("&Acirc;" . "Â")
			         ("&Atilde;" . "Ã") ("&Auml;" . "Ä") ("&Aring;" . "Å") ("&AElig;" . "Æ") ("&Ccedil;" . "Ç") ("&Egrave;" . "È") ("&Eacute;" . "É")
			         ("&Ecirc;" . "Ê") ("&Euml;" . "Ë") ("&Igrave;" . "Ì") ("&Iacute;" . "Í") ("&Icirc;" . "Î") ("&Iuml;" . "Ï") ("&ETH;" . "Ð")
			         ("&Ntilde;" . "Ñ") ("&Ograve;" . "Ò") ("&Oacute;" . "Ó") ("&Ocirc;" . "Ô") ("&Otilde;" . "Õ") ("&Ouml;" . "Ö") ("&times;" . "×")
			         ("&Oslash;" . "Ø") ("&Ugrave;" . "Ù") ("&Uacute;" . "Ú") ("&Ucirc;" . "Û") ("&Uuml;" . "Ü") ("&Yacute;" . "Ý") ("&THORN;" . "Þ")
			         ("&szlig;" . "ß") ("&agrave;" . "à") ("&aacute;" . "á") ("&acirc;" . "â") ("&atilde;" . "ã") ("&auml;" . "ä") ("&aring;" . "å")
			         ("&aelig;" . "æ") ("&ccedil;" . "ç") ("&egrave;" . "è") ("&eacute;" . "é") ("&ecirc;" . "ê") ("&euml;" . "ë") ("&igrave;" . "ì")
			         ("&iacute;" . "í") ("&icirc;" . "î") ("&iuml;" . "ï") ("&eth;" . "ð") ("&ntilde;" . "ñ") ("&ograve;" . "ò") ("&oacute;" . "ó")
			         ("&ocirc;" . "ô") ("&otilde;" . "õ") ("&ouml;" . "ö") ("&divide;" . "÷") ("&oslash;" . "ø") ("&ugrave;" . "ù") ("&uacute;" . "ú")
			         ("&ucirc;" . "û") ("&uuml;" . "ü") ("&yacute;" . "ý") ("&thorn;" . "þ") ("&yuml;" . "ÿ") ("&fnof;" . "ƒ") ("&Alpha;" . "Α")
			         ("&Beta;" . "Β") ("&Gamma;" . "Γ") ("&Delta;" . "Δ") ("&Epsilon;" . "Ε") ("&Zeta;" . "Ζ") ("&Eta;" . "Η") ("&Theta;" . "Θ")
			         ("&Iota;" . "Ι") ("&Kappa;" . "Κ") ("&Lambda;" . "Λ") ("&Mu;" . "Μ") ("&Nu;" . "Ν") ("&Xi;" . "Ξ") ("&Omicron;" . "Ο") ("&Pi;" . "Π")
			         ("&Rho;" . "Ρ") ("&Sigma;" . "Σ") ("&Tau;" . "Τ") ("&Upsilon;" . "Υ") ("&Phi;" . "Φ") ("&Chi;" . "Χ") ("&Psi;" . "Ψ")
			         ("&Omega;" . "Ω") ("&alpha;" . "α") ("&beta;" . "β") ("&gamma;" . "γ") ("&delta;" . "δ") ("&epsilon;" . "ε") ("&zeta;" . "ζ")
			         ("&eta;" . "η") ("&theta;" . "θ") ("&iota;" . "ι") ("&kappa;" . "κ") ("&lambda;" . "λ") ("&mu;" . "μ") ("&nu;" . "ν") ("&xi;" . "ξ")
			         ("&omicron;" . "ο") ("&pi;" . "π") ("&rho;" . "ρ") ("&sigmaf;" . "ς") ("&sigma;" . "σ") ("&tau;" . "τ") ("&upsilon;" . "υ")
			         ("&phi;" . "φ") ("&chi;" . "χ") ("&psi;" . "ψ") ("&omega;" . "ω") ("&thetasym;" . "ϑ") ("&upsih;" . "ϒ") ("&piv;" . "ϖ")
			         ("&bull;" . "") ("&hellip;" . "") ("&prime;" . "") ("&Prime;" . "") ("&oline;" . "") ("&frasl;" . "") ("&weierp;" . "")
			         ("&image;" . "") ("&real;" . "") ("&trade;" . "") ("&alefsym;" . "") ("&larr;" . "") ("&uarr;" . "") ("&rarr;" . "")
			         ("&darr;" . "") ("&harr;" . "") ("&crarr;" . "") ("&lArr;" . "") ("&uArr;" . "") ("&rArr;" . "") ("&dArr;" . "") ("&hArr;" . "")
			         ("&forall;" . "") ("&part;" . "") ("&exist;" . "") ("&empty;" . "") ("&nabla;" . "") ("&isin;" . "") ("&notin;" . "")
			         ("&ni;" . "") ("&prod;" . "") ("&sum;" . "") ("&minus;" . "") ("&lowast;" . "") ("&radic;" . "") ("&prop;" . "")
			         ("&infin;" . "") ("&ang;" . "") ("&and;" . "") ("&or;" . "") ("&cap;" . "") ("&cup;" . "") ("&int;" . "") ("&there4;" . "")
			         ("&sim;" . "") ("&cong;" . "") ("&asymp;" . "") ("&ne;" . "") ("&equiv;" . "") ("&le;" . "") ("&ge;" . "") ("&sub;" . "")
			         ("&sup;" . "") ("&nsub;" . "") ("&sube;" . "") ("&supe;" . "") ("&oplus;" . "") ("&otimes;" . "") ("&perp;" . "")
			         ("&sdot;" . "") ("&lceil;" . "") ("&rceil;" . "") ("&lfloor;" . "") ("&rfloor;" . "") ("&lang;" . "") ("&rang;" . "")
			         ("&loz;" . "") ("&spades;" . "") ("&clubs;" . "") ("&hearts;" . "") ("&diams;" . "") ("&quot;" . "\"") ("&OElig;" . "Œ")
			         ("&oelig;" . "œ") ("&Scaron;" . "Š") ("&scaron;" . "š") ("&Yuml;" . "Ÿ") ("&circ;" . "ˆ") ("&tilde;" . "˜") ("&ndash;" . "")
			         ("&mdash;" . "") ("&lsquo;" . "") ("&rsquo;" . "") ("&sbquo;" . "") ("&ldquo;" . "") ("&rdquo;" . "") ("&bdquo;" . "")
			         ("&dagger;" . "") ("&Dagger;" . "") ("&permil;" . "") ("&lsaquo;" . "") ("&rsaquo;" . "") ("&euro;" . "")
                         ))
        ;; Maximum length of the title.
        (max-length 100)
        ;; Removing redundant whitespaces from the title.
        (result (straight-string title)))
    ;; Applying every element of the replace-table.
    (dolist (x replace-table)
      (setq result (replace-regexp-in-string (car x) (cdr x) result)))
    ;; Cutting off the title according to its maximum length.
    (when (> (length result) max-length)
      (setq result (concat (substring result 0 max-length) "")))
    ;; Returning result.
    result))

extract-title-from-html(html)

(defun extract-title-from-html (html)
  (let (;; Start index of the title.
        (start (string-match "<title>" html))
        ;; End index of the title.
        (end (string-match "</title>" html))
        ;; Amount of characters to skip the openning title tag.
        (chars-to-skip (length "<title>")))
    ;; If title is found ...
    (if (and start end (< start end))
        ;; ... extract it and return.
        (substring html (+ start chars-to-skip) end)
      nil)))

cliplink-decode-content-and-return-orgmode-link-of-title (buffer url content)

(defun cliplink-decode-content-and-return-orgmode-link-of-title (buffer url content)
  (let* (;; Decoding the content from UTF-8.
         (decoded-content (decode-coding-string content 'utf-8))
         ;; Extrating and preparing the title.
         (title (my-cliplink-format-and-trim-title
                 (extract-title-from-html decoded-content))))
    ;; Inserting org-link.
    (with-current-buffer buffer
      (insert (format "[[%s][%s]]" url title)))))

my-insert-orgmode-url-from-clipboard ()

(defun my-insert-orgmode-url-from-clipboard ()
  "It inserts the URL which is taken from the system clipboard in Org-mode"
  ;; Of course, this function is interactive. :)
  (interactive)
  (let (;; Remembering the current buffer, 'cause it is a destination
        ;; buffer we are inserting the org-link to.
        (dest-buffer (current-buffer))
        ;; Getting URL from the clipboard. Since it may contain
        ;; some text properties we are using substring-no-properties
        ;; function.
        (url (substring-no-properties (current-kill 0))))
    ;; Retrieving content by URL.
    (url-retrieve
     url
     ;; Performing an action on the retrieved content.
     `(lambda (s)
        (cliplink-decode-content-and-return-orgmode-link-of-title ,dest-buffer ,url
                          (buffer-string))))))

bind to my-map U

(bind-key "U" 'my-insert-orgmode-url-from-clipboard my-map)

my-org-region-to-property() → my-map p

This is ultra-handy for writing properties. For example for my contact management contacts.org I maintain properties such as phone numbers. When I mark a (changed) phone number within the body of a heading and invoke this function, I get asked for an existing property and the marked region gets the new value for this property.

Please do read my blog article on this topic for all the details. You’re gonna like it.

See: id:2015-05-28-ask-for-properties

Version that tries to read only properties of current entry:

(defun org-read-entry-property-name ()
  "Read a property name from the current entry."
  (let ((completion-ignore-case t)
        (default-prop (or (and (org-at-property-p)
                               (org-match-string-no-properties 2))
                          org-last-set-property)))
    (org-completing-read
     (format "Property [%s]: " (if default-prop default-prop ""))
     (org-entry-properties nil nil)
     nil nil nil nil default-prop)))

(defun my-org-region-to-property (&optional property)
  "Copies the region as value to an Org-mode property"
  (interactive)
  ;; if no region is defined, do nothing
  (if (use-region-p)
      ;; if a region string is found, ask for a property and set property to
      ;; the string in the region
      (let ((val (replace-regexp-in-string
                  "\\`[ \t\n]*" ""
                  (replace-regexp-in-string "[ \t\n]*\\'" ""
                                            (substring (buffer-string)
                                                       (- (region-beginning) 1)
                                                       (region-end))))
                 )
            ;; if none was stated by user, read property from user
            (prop (or property
                      (org-read-entry-property-name))))
        ;; set property
        (org-set-property prop val))))

(bind-key (kbd "p") #'my-org-region-to-property my-map)

my-0d() - add a 0 day deadline to a headline

On an agenda entry: add “-0d” to deadline

 (fset 'my-0d
	[return ?\C-s ?> left ?  ?- ?0 ?d ?\C-x ?b return down])

my-agenda-cancel-event-and-set-to-inactive() - Change active timestamp to inactive and cancel event in the agenda

(fset 'my-agenda-cancel-event-and-set-to-inactive
	(lambda (&optional arg) "Keyboard macro."
	  (interactive "p")
	  (kmacro-exec-ring-item (quote ([return S-up 3 20 99] 0 "%d")) arg)
	  )
	)

my-cancel-event-and-set-to-inactive() - Change active timestamp to inactive and cancel event outside of the agenda

(fset 'my-cancel-event-and-set-to-inactive
	(lambda (&optional arg) "Keyboard macro."
	  (interactive "p")
	  (kmacro-exec-ring-item (quote ([5 18 62 13 S-up 3 20 99] 0 "%d")) arg)
	  )
	)

my-org-time-string-to-seconds(s)

 (defun my-org-time-string-to-seconds (s)
   "Convert a string HH:MM:SS to a number of seconds.
    Omitted third element will be interpreted as MM:SS with missing hours."
   ;; test with:
   ;; (message (concat "result is: " (number-to-string (my-org-time-string-to-seconds "57:45:03"))))
   ;; (message (concat "result is: " (number-to-string (my-org-time-string-to-seconds "57:45"))))
   (cond
    ((and (stringp s)
	   (string-match "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)" s))
     (let ((hour (string-to-number (match-string 1 s)))
	    (min (string-to-number (match-string 2 s)))
	    (sec (string-to-number (match-string 3 s))))
	(+ (* hour 3600) (* min 60) sec)))
    ((and (stringp s)
	   (string-match "\\([0-9]+\\):\\([0-9]+\\)" s))
     (let ((min (string-to-number (match-string 1 s)))
	    (sec (string-to-number (match-string 2 s))))
	(+ (* min 60) sec)))
    ;;((stringp s) (string-to-number s))
    ;;(t s)
    )
   )

my-org-time-string-to-hours(s)

(defun my-org-time-string-to-hours (s)
  "Convert a string HH:MM:SS to hours (float).
   When only two values given, they will be interpreted as MM:SS with missing hours."
  ;; test via:
  ;; (message (concat "result is: " (number-to-string (my-org-time-string-to-hours "57:45:03"))))
  ;; (message (concat "result is: " (number-to-string (my-org-time-string-to-hours "57:45"))))
  (/ (my-org-time-string-to-seconds s) 3600.0)
  )

my-org-time-seconds-to-string(secs)

(defun my-org-time-seconds-to-string (secs)
  "Convert a number of seconds to a time string."
  (cond ((>= secs 3600) (format-seconds "%h:%.2m:%.2s" secs))
	  ((>= secs 60) (format-seconds "%m:%.2s" secs))
	  (t (format-seconds "%s" secs))))

with-time() - evaluate formula and return time

  (defmacro with-time (time-output-p &rest exprs)
    "Evaluate an org-table formula, converting all fields that look
like time data to integer seconds.  If TIME-OUTPUT-P then return
the result as a time value."
    (list
     (if time-output-p 'my-org-time-seconds-to-string 'identity)
     (cons 'progn
	   (mapcar
	    (lambda (expr)
	      `,(cons (car expr)
		      (mapcar
		       (lambda (el)
			 (if (listp el)
			     (list 'with-time nil el)
			   (my-org-time-string-to-seconds el)))
		       (cdr expr))))
	    `,@exprs))))

org-mode-hook

Set some modes when openening a file in Org-mode:

(add-hook 'org-mode-hook
          (lambda ()
            ;; yasnippet
            ;;disabled;            (make-variable-buffer-local 'yas/trigger-key)
            ;;disabled;            (org-set-local 'yas/trigger-key [tab])
            ;;disabled;            (define-key yas/keymap [tab] 'yas/next-field-group)
            ;; flyspell mode for spell checking everywhere
            ;;disabled; (flyspell-mode 1)
            ;; auto-fill mode on
            (auto-fill-mode 1)))

Make TAB the yas trigger key in the org-mode-hook and enable flyspell mode and autofill:

(add-hook 'org-mode-hook
	    (lambda ()
	      ;; flyspell mode for spell checking everywhere
	      ;;disabled; (flyspell-mode 1)
	      ;; Undefine C-c [ and C-c ] since this breaks my org-agenda files when directories are include
	      ;; It expands the files in the directories individually
	      (org-defkey org-mode-map "\C-c["    'undefined)
	      (org-defkey org-mode-map "\C-c]"    'undefined)
	      ;;            (local-set-key (kbd "C-c M-o") 'bh/mail-subtree)
	      )
	    )

Opening image files with external viewer:

(add-hook 'org-mode-hook
	    '(lambda ()
	       (setq org-file-apps
		     (append '(
			       ("\\.png\\'" . default)
			       ("\\.jpg\\'" . default)
			       ("\\.jpeg\\'" . default)
			       ("\\.tiff\\'" . default)
			       ) org-file-apps ))))

TODO keywords and faces

Define my default keywords:

(setq org-todo-keywords (quote
                         (
                          (sequence "TODO(t)" "NEXT(n)" "STARTED(s)" "WAITING(w@/!)" "SOMEDAY(S!)" "|" "DONE(d!/!)" "CANCELLED(c@/!)")
                          )
                         )
      )

Define the style of the keywords:

 (setq org-todo-keyword-faces
	(quote (("TODO"      :foreground "lightblue"    :weight bold)
		("NEXT"      :foreground "red"          :weight bold)
		("STARTED"   :foreground "red"          :weight bold)
		("DONE"      :foreground "forest green" :weight bold)
		("WAITING"   :foreground "orange"       :weight bold)
		("TEAM"      :foreground "orange"       :weight bold)
		("SOMEDAY"   :foreground "magenta"      :weight bold)
		("CANCELLED" :foreground "forest green" :weight bold)
		("QUOTE"     :foreground "red"          :weight bold)
		("QUOTED"    :foreground "magenta"      :weight bold)
		("APPROVED"  :foreground "forest green" :weight bold)
		("EXPIRED"   :foreground "forest green" :weight bold)
		("REJECTED"  :foreground "forest green" :weight bold)
		("OPEN"      :foreground "blue"         :weight bold)
		("CLOSED"    :foreground "forest green" :weight bold)
		("PHONE"     :foreground "forest green" :weight bold))))

«Non-nil means use the fast todo selection scheme with ‘C-c C-t’. This variable describes if and under what circumstances the cycling mechanism for TODO keywords will be replaced by a single-key, direct selection scheme.» https://www.gnu.org/software/emacs/manual/html_node/org/TODO-basics.html

(setq org-use-fast-todo-selection t)

«Non-nil means switching TODO states with S-cursor counts as state change. This is the default behavior. However, setting this to nil allows a convenient way to select a TODO state and bypass any logging associated with that.» https://www.gnu.org/software/emacs/manual/html_node/org/TODO-basics.html

(setq org-treat-S-cursor-todo-selection-as-state-change nil)

CANCELED -> add ARCHIVE-tag: http://article.gmane.org/gmane.emacs.orgmode/64852

  • disabled 2015-12-07
(setq org-todo-state-tags-triggers
      (quote (("CANCELLED"
      	 ("ARCHIVE" . t))
      	("WAITING"
      	 ("WAITING" . t))
      	(done
      	 ("WAITING"))
      	("TODO"
      	 ("WAITING")
      	 ("CANCELLED"))
      	("NEXT"
      	 ("WAITING"))
      	("STARTED"
      	 ("WAITING"))
      	("DONE"
      	 ("WAITING")
      	 ("CANCELLED")))))

Change font for DONE tasks

(setq org-fontify-done-headline t)
(custom-set-faces
 '(org-done ((t (:foreground "PaleGreen"
                 :weight normal
                 :strike-through t))))
 '(org-headline-done
            ((((class color) (min-colors 16) (background dark))
               (:foreground "LightSalmon" :strike-through t)))))

Tagging

Tags with fast selection keys http://orgmode.org/org.html#Setting-tags

(setq org-tag-alist (quote (
			      ;;("Kommunikation" . ?k)
			      ("Besorgung" . ?B)
			      ("nonComputer" . ?n)
			      ("fitness" . ?f)
			      (:startgroup)
			      ("@BWG" . ?b)
			      ;;("@Infonova" . ?i)
			      ;;("@out_of_town" . ?o)
			      ;;("@FHStP" . ?F)
                            ;;("@Ebreichsdorf" . ?e)
                            ;;("@TUG" . ?t)
			      (:endgroup)
			      (:startgroup)
			      ("private" . ?p)
			      ("public" . ?P)
			      (:endgroup)
			      (:startgroup)
			      ;;("bigRock" . ?b)
			      ("MIT" . ?m)
			      ("lp" . ?l)
			      ("reward" . ?r)
			      (:endgroup)
			      )))

Allow setting single tags without the menu http://orgmode.org/org.html#Setting-tags

(setq org-fast-tag-selection-single-key (quote expert))

Capture

http://orgmode.org/manual/Capture.html «Capture lets you quickly store notes with little interruption of your work flow.»

One of my most used Org-mode features - a simple must-have.

My general inbox for Org-mode is my inbox.org file. It mostly gets new headings from MobileOrg but I also fill it from other sources: emails, manual editing in vim, …

Setting it up: http://orgmode.org/org.html#Setting-up-capture

(setq org-default-notes-file "~/org/inbox.org")
(define-key global-map "\C-cc" 'org-capture)

Capture tricks

http://storax.github.io/blog/2016/05/02/org-capture-tricks/

  • See id:2016-05-05-yasnippet-like-capture-templates
 * JIRA Ticket %(my-capture-promt "JIRA Project" 'jr-prj)-%(my-capture-promt "JIRA Ticket No." 'jr-no)
 For project %(my-capture-insert 'jr-prj) I have to do the following stuff:
 %(my-capture-optional "triage" (format
  "** Triage %s-%s
 Do the triage."
  jr-prj jr-no))
 %(my-capture-optional "implementation" (format
  "** Implement %s-%s
 Implement stuff
 - [ ] Tests pass?"
  jr-prj jr-no))

my-capture-* - Functions for prompting for different things

(defvar my-capture-promt-history nil
  "History of prompt answers for org capture.")

(defun my-capture-prompt (prompt variable)
  "PROMPT for string, save it to VARIABLE and insert it."
  (make-local-variable variable)
  (set variable (read-string (concat prompt ": ") nil my-capture-promt-history)))

(defun my-capture-prompt-date (prompt variable)
  "PROMPT for a date, save it to VARIABLE and insert it."
  (make-local-variable variable)
  (set variable
       (format-time-string
        (org-time-stamp-format nil nil)
        (org-read-date nil t nil prompt))
       ))

(defun my-capture-insert (variable)
  "Insert content of VARIABLE."
  (symbol-value variable))

(defun my-capture-optional (what text)
  "Ask user to include WHAT.  If user agrees return TEXT."
  (when (y-or-n-p (concat "Include " what "?"))
    text))

(defun my-capture-selection (list variable)
  "Let the user choose between a pre-defined set of strings"
  (make-local-variable variable)
  (let ((selected-value (ido-completing-read "Select from list: " list)))
    (set variable selected-value)
    selected-value)
  )

org-capture-templates - Prelude

A shortcut for a simple heading with keyword NEXT which will be used multiple times below:

(setq my-capture-template-next "* NEXT %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n")

A test capture template:

  (setq my-capture-template-test "** Capture test

- Entering values: %(my-capture-prompt \"Please enter FOO\" 'my-foo) %(my-capture-prompt \"Please enter BAR\" 'my-bar)
- Entering a date: %(my-capture-prompt-date \"Enter a date\" 'my-date)
- Selection: %(my-capture-selection '(\"one\" \"two\" \"three\") 'my-number)
- Optional: %(my-capture-optional \"an optional snippet\" \"The content for the optional thing\")

Re-using:
- Here comes %(my-capture-insert 'my-foo) and %(my-capture-insert 'my-bar)
- The date: %(my-capture-insert 'my-date)
- Your number choice: %(my-capture-insert 'my-number)

\n\n")

Using test org-capture-templates:

(setq org-capture-templates
`(
  ("1" "first version with string" entry (file+headline "~/org/misc.org" "shorts")
   "* NEXT %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)
  ("2" "second version with variable" entry (file+headline "~/org/misc.org" "shorts")
   ,my-capture-template-next :empty-lines 1)
        ))

org-capture-templates

BEGIN of the templates:

 (setq org-capture-templates
	`(

My general templates:

	  ("s" "shorts-todo" entry (file+headline "~/org/misc.org" "shorts")
	   ,my-capture-template-next :empty-lines 1)
	  ("e" "Event" entry (file+headline "~/org/misc.org" "Events")
	   "* %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)
	  ("b" "Bookmark" entry (file+headline "~/org/notes.org" "Bookmarks")
	   "* %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)
	  ("p" "public voit" entry (file+headline "~/org/public_voit.org" "Blogbeiträge")
	   "* NEXT %?        :blog:%^g\n:PROPERTIES:\n:CREATED: %U\n:ID: %^{prompt}\n:END:\n\n" :empty-lines 1)
	  ("a" "anzuschauen" entry (file+headline "~/org/misc.org" "Anzuschauen")
	   "* NEXT %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n%x\n\n" :empty-lines 1)
	  ("B" "Besorgung" entry (file+headline "~/org/hardware.org" "Besorgungen")
	   ,my-capture-template-next :empty-lines 1)

Hardware templates:

	  ("h" "hardware")
	  ("hs" "sherri" entry (file+olp "~/org/hardware.org" "Inventar" "intel NUC (<2015-07-25 Sat>, € 486.84, e-tec)" "shorts")
	   ,my-capture-template-next :empty-lines 1)
	  ("hf" "floyd" entry (file+olp "~/org/hardware.org" "Inventar" "lenovo Thinkpad X260 (<2016-03-22 Tue>, 899€, u:book)" "shorts")
	   ,my-capture-template-next :empty-lines 1)
	  ("hc" "Chromebook" entry (file+olp "~/org/hardware.org" "Inventar" "Toshiba Chromebook 2 (<2016-03-14 Mon>, 334,02€, Amazon)" "shorts")
	   ,my-capture-template-next :empty-lines 1)
	  ("hp" "RasPlay" entry (file+olp "~/org/hardware.org" "Inventar" "Raspberry Pi 2 Model B (<2015-06-29 Mon>, 38€, Pollin.de)")
	   ,my-capture-template-next :empty-lines 1)
	  ;;old;;("hb" "blanche" entry (file+olp "~/org/hardware.org" "Inventar" "Mac Mini mit OS X 10.5 (2009-0?0??)" "shorts")
	  ;;old;; "* NEXT %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)
	  ("hw" "Winora T3" entry (file+olp "~/org/hardware.org" "Inventar" "Fahrrad: Winora T3 ([[contact:Kotnik][Kotnik]], 2464€, <2013-08-02 Fri>)")
	   ,my-capture-template-next :empty-lines 1)

Templates for my home:

	  ("w" "Breitenweg")
	  ("ws" "Breitenweg shorts" entry (file+headline "~/org/bwg.org" "shorts")
	   ,my-capture-template-next :empty-lines 1)
	  ("we" "Breitenweg event" entry (file+headline "~/org/bwg.org" "Events")
	   "* %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)
	  ;;old;;("wa" "Breitenweg Ausgaben" table-line (file+headline "~/org/bwg.org" "getätigte Ausgaben") "| %t | %? ||||")

Company templates:

	  ("d" "detego")
 ("ds" "shorts" entry (file+headline "~/org/detego.org" "shorts")
	   ,my-capture-template-next :empty-lines 1)
	  ("de" "event" entry (file+headline "~/org/detego.org" "Events")
	   "* %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)
	  ("dc" "CISO")
	  ("dcs" "shorts" entry (file+headline "~/org/ciso.org" "shorts")
	   ,my-capture-template-next :empty-lines 1)
	  ("dce" "event" entry (file+headline "~/org/ciso.org" "Events")
	   "* %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)

Template for my lecture:

	  ("f" "FH St. Pölten shorts" entry (file+headline "~/org/fhsp.org" "shorts")
	   ,my-capture-template-next :empty-lines 1)

Put it in the inbox, refile it later:

	  ("I" "inbox, refile later" entry (file "~/org/inbox.org")
	   "\n* %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)

Old templates for the records:

("x" "xlog")
("xf" "xlog FNS" table-line (id "xlog-fns-id") "| %T |")
("xz" "xlog ZNS" table-line (id "xlog-zns-id") "| %T |")
("xh" "xlog hometrainer" table-line (id "xlog-hometrainer") "| %T |  |  |  |")
("xb" "xlog Bettwäsche" table-line (id "xlog-bettwaesche-id") "| %T |  |  |  |  |")
("xg" "xlog Gewicht" table-line (id "xlog-gewicht") "| %T |  |")
("xr" "Reinigung Geschirrspüler" table-line (id "xlog-Geschirrspuelerreinigung") "| %T |")
("xp" "Pollenallergie Symptome" table-line (id "ad5f7363-e280-4566-912d-1fb5699725da") "| %T |")
("xt" "Pollenallergie Tabletteneinnahme" table-line (id "b718be27a93a35207bac9b18ec390cc3") "| %T |")
("xG" "elmex grün" table-line (id "d705cdf9-40e5-4677-9662-e0e17d05798f") "| %T |")
("xR" "elmex rot" table-line (id "fbd9be0e-5077-4ba9-89eb-6041f945991a") "| %T |")
("xD" "dentalux Complex 3" table-line (id "2013-08-06-detalux3") "| %T |")
("xk" "Keyboard Akkus leer" table-line (id "3407c9b7-1b41-443b-9254-32c4af3a54e8") "| %T |")
("xx" "xlogtest" table-line (file+headline "~/org/misc.org" "xlogtest2012-06-17") "| %T |")

Test template:

	  ("X" "test" entry (file+headline "~/org/misc.org" "Tests")
	   ,my-capture-template-test :empty-lines 1)

END of the templates:

	  )
	)

Moving web bookmarks from inbox.org to notes.org → my-map b

Smart moving bookmark headings from inbox.org to notes.org

  (defun my-save-bookmark()
    "removes NEXT/Bookmark, (NOT YET: FIXXME: retrieves title),
move time-stamp to CREATED, re-file to bookmarks, invoke Org-mode tagging process"
    (interactive)
    (save-excursion
      ;; get myself to the beginning of the current heading:
      ;;(outline-previous-visible-heading 1)  ;; jump to previous heading
      ;;(outline-next-visible-heading 1)      ;; jumps to beginning of the current (interesting) heading
      (beginning-of-line)                   ;; jump to beginning of line
      (let ((mybegin (point)))              ;; mark beginning of line as start point
	(outline-next-visible-heading 1)    ;; jumps to EOF if it is the last entry
	(save-restriction
	  (narrow-to-region mybegin (point))  ;; ignore everything outside of region
	  ;; search/replace unwanted keywords at the beginning:
	  (goto-char (point-min))
	  (while (search-forward "* NEXT Bookmark " nil t) (replace-match "* " nil t))
	  (goto-char (point-min))
	  (while (search-forward "* NEXT " nil t) (replace-match "* " nil t))
	  (goto-char (point-min))
	  (while (search-forward "* Bookmark " nil t) (replace-match "* " nil t))
	  (goto-char (point-min))
	  (while (search-forward "//m.heise.de" nil t) (replace-match "//heise.de" nil t));; remove mobile heise URL
	  (goto-char (point-min))
	  (while (search-forward "/from/atom10?wt_mc=rss.ho.beitrag.atom" nil t);; remove heise RSS tags
	    (replace-match "" nil t)
	    )
	  (goto-char (point-min))
	  (while (search-forward "?wt_mc=rss.ho.beitrag.atom" nil t);; remove heise RSS tags
	    (replace-match "" nil t)
	    )
	  (goto-char (point-min))
	  ;; insert second asterisk (modify to second level heading)
	  (insert "*")
	  ;; move time-stamp to properties-drawer:
	  (search-forward-regexp "^\\[20")  ;; jump to second line (with time-stamp) via search
	  (beginning-of-line)
	  (insert ":PROPERTIES:\n:CREATED:  ")
	  (end-of-line)
	  (newline)
	  (insert ":END:\n")
	  ;; move region to end of notes.org
	  (kill-region mybegin (point)) ;; kill region to kill-ring
	  (switch-to-buffer "notes.org")
	  (end-of-buffer)
	  (newline)
	  (yank)
	  ;; add tags
	  (outline-previous-visible-heading 1)  ;; jump to heading
	  (org-set-tags-command)
	  )
	)
      )
    )

  (bind-key "b" 'my-save-bookmark my-map)

Refiling

Targets include this file and any file contributing to the agenda - up to 5 levels deep

(setq org-refile-targets (quote (
                                 ;; ignore my-org-memacs-files here
                                 (my-work-agenda-files :maxlevel . 4)
                                 (my-nonwork-agenda-files :maxlevel . 4)
                                 ;;OLD: (nil :maxlevel . 3)
                                 ;;OLD: ("contacts.org" :maxlevel . 6)
                                 )))

Targets start with the file name - allows creating level 1 tasks

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

Activate caching of targets: (a must-have)

(setq org-refile-use-cache t)

Targets complete directly with IDO: so much better!

(setq org-outline-path-complete-in-steps nil)

Allow refile to create parent tasks with confirmation:

(setq org-refile-allow-creating-parent-nodes (quote confirm))

Archiving - preserve top level node and tags when archiving

When I archive a heading (and its sub-headings), it gets moved from foo.org to foo.org_archive. Following code does preserve at least the top level node so that the archive file gets the rough structure of the non-archive file.

http://orgmode.org/worg/org-hacks.html#sec-1-7-1

(defun my-org-inherited-no-file-tags ()
  (let ((tags (org-entry-get nil "ALLTAGS" 'selective))
        (ltags (org-entry-get nil "TAGS")))
    (mapc (lambda (tag)
            (setq tags
                  (replace-regexp-in-string (concat tag ":") "" tags)))
          (append org-file-tags (when ltags (split-string ltags ":" t))))
    (if (string= ":" tags) nil tags)))
(defadvice org-archive-subtree (around my-org-archive-subtree-low-level activate)
    (let ((tags (my-org-inherited-no-file-tags))
          (org-archive-location
           (if (save-excursion (org-back-to-heading)
                               (> (org-outline-level) 1))
               (concat (car (split-string org-archive-location "::"))
                       "::* "
                       (car (org-get-outline-path)))
             org-archive-location)))
      ad-do-it
      (with-current-buffer (find-file-noselect (org-extract-archive-file))
        (save-excursion
          (while (org-up-heading-safe))
          (org-set-tags-to tags)))))

Links

I love customized links. I created a bunch of them in order to link certain kind of data.

  (setq org-link-abbrev-alist
	'(
	  ("bib" . "~/archive/library/%s.bib")
	  ("cite" . "file:~/org/references.org::/%s/")
					;	("mynotes" . "file:~/org/references.org::%s")
					;	("papers" . "~/archive/library/%s.pdf")
	  ("photo" . "file:~/people/all_photographs/%s")
	  ("pdf" . "~/archive/library/%s.pdf")
	  ("notes" . "~/archive/library/%s-notes.pdf")
	  ("contact" . "~/org/contacts.org::/\*.*%s/")
;	  ("tsfile" . "~/org/memacs/files.org_archive::/\*.*%s/") replaced by org-link-set-parameters() + my-handle-tsfile-link()
	  ("ifile" . "~/org/memacs/ifiles.org::/\*.*%s/")
	  ;;("mbox2001" . "file:~/archive/events_memories/backup_2002-06-23/2002-06-23/home/vk/Emails_from_approx_2000-07-01_to_2002-06-24.mbox::/\%s/")
	  ("postings2002" . "file:~/archive/usenet/memacs-archive/2002-03-13_to_2002-06-23_postings_Karl_Voit_usenet::%s")
	  ("postings2001" . "file:~/archive/usenet/memacs-archive/2000-07-06_to_2002-01-28_postings_Karl_Voit_usenet::%s")
	  ;;("bank" . "file:~/institutions/easybank/Memacs-easybank-summary.csv::%s")
	  ;;("ipd" . "https://r6portal-defects.infonova.com/browse/IPD-%s")
	  ;;("IPD" . "https://r6portal-defects.infonova.com/browse/IPD-%s")
	  ("tfs" . "http://grzd-tfs02:8080/tfs/DefaultCollection/Detego/_workitems?id=%s")
	  ("TFS" . "http://grzd-tfs02:8080/tfs/DefaultCollection/Detego/_workitems?id=%s")
	  ))

Custom Link Completion

(defun org-make-link (&rest strings)
  "Concatenate STRINGS."
  (apply 'concat strings))

You might as well be interested in Pragmatic Emacs: Insert internal org-mode links the ivy way

Links to Outlook entities

(when (my-eval-if-binary-or-warn "outlook")

  (org-add-link-type "outlook" 'org-outlook-open)

  (defun org-outlook-open (id)
    "Open the Outlook item identified by ID.  ID should be an Outlook GUID."
    ;; 2017-03-02: following line stopped working with "org-outlook-open: ShellExecute failed: Access is denied."
    ;;(w32-shell-execute "open" (concat "outlook:" id))
    ;; fix:
    (w32-shell-execute "open"
                       "C:/Program Files (x86)/Microsoft Office/Office16/OUTLOOK.EXE"
                       (concat "/select " "outlook:" id))
    )
)

Reference management: link handling functions

Helper function string-replace (this withthat in)

(defun string-replace (this withthat in)
  "replace THIS with WITHTHAT' in the string IN"
  (with-temp-buffer
    (insert in)
    (goto-char (point-min))
    (replace-string this withthat)
    (buffer-substring (point-min) (point-max))))

org-pdf-complete-link ()

 (defun org-pdf-complete-link (&optional arg)
   "Create a papers link using completion."
   (let (file link)
     (setq file (read-file-name "pdf: " "~/archive/library/"))
     (let ((pwd (file-name-as-directory (expand-file-name ".")))
	    (pwd1 (file-name-as-directory (abbreviate-file-name
					   (expand-file-name ".")))))
	(setq file (string-replace "~/archive/library/" "" file))
	(setq file (string-replace pwd "" (string-replace pwd1 "" file)))
	(setq file (string-replace ".bib" "" file))
	(setq file (string-replace ".pdf" "" file))
	(setq link (concat "pdf:" file)))
     link))
 (defun org-ref-complete-link (&optional arg)
   "Create a reference link using completion."
   (let (file link)
     (setq file (read-file-name "ref: " "~/archive/library/"))
     (let ((pwd (file-name-as-directory (expand-file-name ".")))
	    (pwd1 (file-name-as-directory (abbreviate-file-name
					   (expand-file-name ".")))))
	(setq file (string-replace "~/archive/library/" "" file))
	(setq file (string-replace pwd "" (string-replace pwd1 "" file)))
	(setq file (string-replace ".bib" "" file))
	(setq file (string-replace ".pdf" "" file))
	(setq link (concat "ref:" file)))
     link))
 (defun org-photo-complete-link (&optional arg)
   "Create a reference link using completion."
   (let (file link)
     (setq file (read-file-name "photo: " "~/people/all_photographs/"))
     (let ((pwd (file-name-as-directory (expand-file-name ".")))
	    (pwd1 (file-name-as-directory (abbreviate-file-name
					   (expand-file-name ".")))))
	(setq file (string-replace "~/people/all_photographs/" "" file))
	(setq file (string-replace pwd "" (string-replace pwd1 "" file)))
					;(setq file (string-replace ".jpg" "" file))
					;(setq file (string-replace ".jpeg" "" file))
					;(setq file (string-replace ".tiff" "" file))
	(setq link (concat "photo:" file)))
     link))
(my-load-local-el "contrib/format-bib.el")

handling tsfile links (Memacs)

Defining memacs variables:

(defvar memacs-root "~/org/memacs/")
(defvar memacs-file-pattern "files.org_archive") ;; also possible: "*.org"

my-handle-tsfile-link (querystring)

  • 2016-12-31 by John Kitchin
(defun my-handle-tsfile-link (querystring)
  (message (concat "DEBUG1: querystring: " querystring))
  (message (concat "DEBUG2: "
                          "grep \""
                          querystring
                          "\" "
                          (concat memacs-root memacs-file-pattern)))
  ;; get a list of hits
  (let ((queryresults (split-string
                       (s-trim
                        (shell-command-to-string
                         (concat
                          "grep \""
                          querystring
                          "\" "
                          (concat memacs-root memacs-file-pattern))))
                       "\n" t)))
    (message (concat "DEBUG3: queryresults: " (car queryresults)))
    ;; check length of list (number of lines)
    (cond
     ((= 0 (length queryresults))
      ;; edge case: empty query result
      (message "Sorry, no results found for query: %s" querystring))
     (t
      (with-temp-buffer
        (insert (if (= 1 (length queryresults))
                    (car queryresults)
                  (completing-read "Choose: " queryresults)))
        (org-mode)
        (goto-char (point-min))
        (org-next-link)
        (org-open-at-point))))))

Setting link parameters:

(org-link-set-parameters
 "tsfile"
 :follow (lambda (path) (my-handle-tsfile-link path))
 :help-echo "Opens the linked file with your default application")

OLD code:

  (defun my-handle-tsfile-link (querystring)
    ;; get a list of hits
    (let ((queryresults (split-string (replace-regexp-in-string
                                       "\r?\n$" ""
                                       (shell-command-to-string
					(concat "grep "
						querystring
						(concat memacs-root memacs-file-pattern))))
                                      "\n")))

      ;; doesn't work because queryresults is not a string:
      ;; (message "%s" (concat "DEBUG: queryresults: " queryresults))

      ;; check length of list (number of lines)
      (cond
       ((= 0 (length queryresults))
	;; edge case: empty query result
	(message "Sorry, empty querystring."))

;; I get «split-string: Wrong type argument: stringp, ("")»
       ((= 1 (length (split-string queryresults "\n")))
	;; queryresults is unique
	(with-temp-buffer
	  (insert queryresults)
	  (org-mode)
	  (org-element-map (org-element-parse-buffer) 'link
	    (lambda (ln)
	      (when (string= (org-element-property :type ln) "file")
		(org-element-property :path ln)
		(message "%s" (concat "DEBUG: file -> " ln))
		)))))

;; I get the «File: » prompt but no completion:
       (t
	;; querystring results multiple matches
	(org-open-file (completing-read
			"File: "
			(remove-if-not    ;remove nils from list
			 'identity
			 (loop for queryresult in queryresults
                               collect
                               ;; get the filename the match is in. assumes no : in the file name
                               (let* ((f (car (split-string queryresult ":")))
                                      (basedir (file-name-directory f)))
				 (with-temp-buffer
                                   (insert queryresult)
                                   (org-mode)
                                   (org-element-map (org-element-parse-buffer) 'link
                                     (lambda (ln)
                                       (when (string= (org-element-property :type ln) "file")
					 (expand-file-name  (org-element-property :path ln) basedir))))))))))))))

color links

Don’t know why I disabled this:

(require 's)

(defun color-comp (&optional arg)
  "Completion function for color links."
  (let ((color-data (prog2
                        (save-selected-window
                          (list-colors-display))
                        (with-current-buffer (get-buffer "*Colors*")
                          (mapcar (lambda (line)
                                    (append (list line)
                                            (s-split " " line t)))
                                  (s-split "\n" (buffer-string))))
                      (kill-buffer "*Colors*"))))
    (format "color:%s"
            (s-trim (cadr (assoc (completing-read "Color: " color-data) color-data))))))


(defun color-link-face (path)
  "Face function for color links."
  (or (cdr (assoc path org-link-colors))
      `(:foreground ,path)))


(defun color-link-export (path description backend)
  "Export function for color links."
  (cond
   ((eq backend 'html)
    (let ((rgb (assoc (downcase path) color-name-rgb-alist))
          r g b)
      (setq r (* 255 (/ (nth 1 rgb) 65535.0))
            g (* 255 (/ (nth 2 rgb) 65535.0))
            b (* 255 (/ (nth 3 rgb) 65535.0)))
      (format "<span style=\"color: rgb(%s,%s,%s)\">%s</span>"
              (truncate r) (truncate g) (truncate b)
              (or description path))))))

(org-link-set-parameters "color"
                         :face 'color-link-face
                         :complete 'color-comp
                         :export 'color-link-export)

Open in external app

Found via reddit thread:

Add a type of link so that the emacs will open the linked file with the default external application (useful for media such as movies, pdfs, etc.)

  • 2017-09-14: FIXXME: does not work on Windows: Unable to start '~\path\to\2017-09-12 a file.pdf': The specified file was not found.
    • I guess that the backslashes have to be replaced by forward slashes for Windows/Cygwin

Alternative approach for Windows:

(w32-shell-execute "open"
			 "C:/Program Files (x86)/.../cygstart"
			 (concat " \"" path-to-media "\""))
(defun my-open-ext (path-to-media)
  (if (my-system-type-is-windows)
      (shell-command (concat "cygstart \"" path-to-media "\""))
    (shell-command (concat "open " \"" path-to-media \""))
    )
)
(org-add-link-type "open" 'my-open-ext)

Agenda

Org-mode is my digital everything. And therefore, Org is also my calendar which is called “agenda” in Org-mode speak. I see my todos (scheduled), my appointments and all date- & time-stamps on it.

But it gets even more crazy with Memacs: https://github.com/novoid/Memacs/ With Memacs, I get email, text messages, phone calls, downloaded files, visited web pages, Git commits, photos, and so forth on my agenda. This is really cool.

Agenda files

I maintain two categories of agenda files: work and non-work files which are defined for Windows and non-windows separately (path format differs).

Using my-toggle-agenda-files() I can toggle between host-specific default agenda and all agenda files.

Definition of work files:

(if (my-system-type-is-windows)
    (setq my-work-agenda-files (append (quote (
                                               "c:/Users/karl.voit/org/detego.org"
                                               "c:/Users/karl.voit/org/ciso.org"
                                               "c:/Users/karl.voit/org/exported-detego-calendar.org"
                                               ;;"c:/Users/karl.voit/org/r6-stories.org"
                                               ;;"c:/Users/karl.voit/org/infonova.org"
                                               ))))
  (setq my-work-agenda-files (append (quote (
                                             "~/org/detego.org"
                                             "~/org/ciso.org"
                                             "~/org/exported-detego-calendar.org"
                                             ;;"~/org/infonova.org"
                                             ;;"~/org/r6-stories.org"
                                             ;;"~/org/infonova.org"
                                             ;;"~/org/tagstore.org";;moved to archive
                                             ;;"~/org/ist.org";;moved to archive
                                             ;;"~/org/test-phd.org"
                                             ;;"~/org/postdoc.org";;moved to archive
                                             ))))
  )

Definitions of non-work files:

(if (my-system-type-is-windows)
   (setq my-nonwork-agenda-files (append (quote (
                                           "c:/Users/karl.voit/org/misc.org"
					            "c:/Users/karl.voit/org/issues.org"
					            "c:/Users/karl.voit/org/projects.org"
					            "c:/Users/karl.voit/org/finanzen_behoerden_versicherungen.org"
					            "c:/Users/karl.voit/org/bwg.org"
					            "c:/Users/karl.voit/org/contacts.org"
					            ;;"c:/Users/karl.voit/org/foodandbeverages.org"
					            "c:/Users/karl.voit/org/hardware.org"
					            "c:/Users/karl.voit/org/fhsp.org"
					            "c:/Users/karl.voit/org/notes.org"
					            "c:/Users/karl.voit/org/public_voit.org"
					            "c:/Users/karl.voit/org/errors_public_voit.org"
					            "c:/Users/karl.voit/org/errors_orgmode_commits.org"
					            ;;"c:/Users/karl.voit/org/movies.org"
					            ;;"c:/Users/karl.voit/org/references.org"
					            ;;"c:/Users/karl.voit/src/lazyblorg/lazyblorg.org"
					            ;;"c:/Users/karl.voit/org/memacs/error.org"
					            ;;"c:/Users/karl.voit/org/memacs/git.org"
					            ;;"c:/Users/karl.voit/org/memacs/ifiles.org"
					            ;;"c:/Users/karl.voit/org/memacs/phonecalls.org"
					            ;;"c:/Users/karl.voit/org/memacs/roylog.org"
					            ;;"c:/Users/karl.voit/org/memacs/SMS.org"
                                              ))))
 (setq my-nonwork-agenda-files (append (quote (
                                         ;;"~/org/archive.org"
					          "~/org/misc.org"
					          "~/org/issues.org"
					          "~/org/projects.org"
					          "~/org/finanzen_behoerden_versicherungen.org"
					          "~/org/bwg.org"
					          "~/org/contacts.org"
					          "~/org/foodandbeverages.org"
					          "~/org/hardware.org"
					          "~/org/notes.org"
					          "~/org/movies.org"
					          "~/org/references.org"
					          "~/org/public_voit.org"
					          "~/org/errors_public_voit.org"
					          "~/org/errors_orgmode_commits.org"
					          "~/org/fhsp.org"
					          "~/src/lazyblorg/wiki/Roadmap.org"
					          "~/org/memacs/error.org"
					          ;;"~/org/memacs/roylog.org"
					          ;;"~/org/memacs/archive.org"
					          ;;"~/org/memacs/bank.org"
					          ;;"~/org/memacs/datebk6.org"
					          ;;"~/org/memacs/delicious.org"
					          ;;"~/org/memacs/files.org"
					          ;;"~/org/memacs/GCal.org"
					          ;;"~/org/memacs/git.org"
					          ;;"~/org/memacs/ifiles.org"
					          ;;"~/org/memacs/mbox.org"
					          ;;"~/org/memacs/news.org"
					          ;;"~/org/memacs/phonecalls.org"
					          ;;"~/org/memacs/SMS.org"
					          ;;"~/org/memacs/tweets.org"
					          ;;"~/org/memacs/www.org"
					          ;;"~/org/memacs/movies.org"
					          ;;"~/org/memacs/Filmliste.org"
                                            ))))
 )

my-toggle-agenda-files() toggles between work/everything and nonwork/everything:

Default agenda files: on my business host, start with the work-related files; on my other machines, start with my non-work-related files.

(defun my-toggle-agenda-files ()
  "Toggle my agenda files between work/everything and nonwork/everything
depending on the current system.
Source for the toggle code: `http://ergoemacs.org/emacs/elisp_toggle_command.html'"
  (interactive)
  ;; use a property “state”. Value is t or nil
  (if (get 'my-toggle-agenda-files 'state)
      (progn
        (message "Agenda files: host-specific")
        (if (my-system-type-is-windows)
            (setq org-agenda-files (append my-work-agenda-files ))
          (setq org-agenda-files (append my-nonwork-agenda-files ))
          )
        (put 'my-toggle-agenda-files 'state nil))
    (progn
      (message "Agenda files: all")
      (setq org-agenda-files (append my-work-agenda-files my-nonwork-agenda-files))
      (put 'my-toggle-agenda-files 'state t))))


(bind-key "A" 'my-toggle-agenda-files my-map)

 (if (my-system-type-is-windows)
     (setq org-agenda-files (append my-work-agenda-files my-nonwork-agenda-files))
     (setq org-agenda-files (append my-nonwork-agenda-files ))
     )

Misc agenda helper functions

my-skip-tag(tag)

From: Memnon Anon <gegendosenfleisch@googlemail.com>
Newsgroups: gmane.emacs.orgmode
Subject: Re: Exclude tag from custom agenda
Date: Sun, 9 Dec 2012 15:59:48 +0000 (UTC)
Message-ID: <871uezql9d.fsf@mean.albasani.net>
Based on http://article.gmane.org/gmane.emacs.orgmode/41427
 (defun my-skip-tag(tag)
   "Skip entries that are tagged TAG"
   (let* ((entry-tags (org-get-tags-at (point))))
     (if (member tag entry-tags)
	  (progn (outline-next-heading) (point))
	nil)))

tag-without-done-or-canceled()

2012-12-09 From: Memnon Anon <gegendosenfleisch@googlemail.com>
To: news1142@Karl-Voit.at
Subject: Re: Custom agenda: search by tag and exclude DONE items
 (defun tag-without-done-or-canceled ()
   "Show items with tag \"borrowed\" that are neither in \"DONE\" or \"CANCELED \" state."
   (let ((state (org-entry-get (point) "TODO")))
     (if (and (member "borrowed" (org-get-tags-at (point)))
	       (not (string= state "DONE"))
	       (not (string= state "CANCELED")))
	  nil ; do not skip
	(line-end-position)))) ; skip

MISC functions from Bernt Hansen’s famous http://doc.norang.ca/org-mode.html

  (defun bh/is-project-p ()
    "Any task with a todo keyword subtask"
    (let ((has-subtask)
	  (subtree-end (save-excursion (org-end-of-subtree t))))
      (save-excursion
	(forward-line 1)
	(while (and (not has-subtask)
		    (< (point) subtree-end)
		    (re-search-forward "^\*+ " subtree-end t))
	  (when (member (org-get-todo-state) org-todo-keywords-1)
	    (setq has-subtask t))))
      has-subtask))

  (defun bh/skip-non-stuck-projects ()
    "Skip trees that are not stuck projects"
    (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
	   (has-next (save-excursion
		       (forward-line 1)
		       (and (< (point) subtree-end)
			    (re-search-forward "^\\*+ \\(NEXT\\|STARTED\\) " subtree-end t)))))
      (if (and (bh/is-project-p) (not has-next))
	  nil ; a stuck project, has subtasks but no next task
	subtree-end)))

  (defun bh/skip-non-projects ()
    "Skip trees that are not projects"
    (let* ((subtree-end (save-excursion (org-end-of-subtree t))))
      (if (bh/is-project-p)
	  nil
	subtree-end)))

  (defun bh/skip-projects ()
    "Skip trees that are projects"
    (let* ((subtree-end (save-excursion (org-end-of-subtree t))))
      (if (bh/is-project-p)
	  subtree-end
	nil)))

  (defun bh/skip-non-archivable-tasks ()
    "Skip trees that are not available for archiving"
    (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
	   (daynr (string-to-int (format-time-string "%d" (current-time))))
	   (a-month-ago (* 60 60 24 (+ daynr 1)))
	   (last-month (format-time-string "%Y-%m-" (time-subtract (current-time) (seconds-to-time a-month-ago))))
	   (this-month (format-time-string "%Y-%m-" (current-time)))
	   (subtree-is-current (save-excursion
				 (forward-line 1)
				 (and (< (point) subtree-end)
				      (re-search-forward (concat last-month "\\|" this-month) subtree-end t)))))
      (if subtree-is-current
	  subtree-end ; Has a date in this month or last month, skip it
	;; Make sure the ARCHIVE property is set for this task
	;; Create one at the parent task if necessary
	(save-excursion
	  (save-restriction
	    (widen)
	    (let ((archive-prop (org-entry-get nil "ARCHIVE" 'inherit))
		  (parent-task))
	      (org-up-heading-safe)
	      (setq parent-task (nth 4 (org-heading-components)))
	      (unless archive-prop
		(setq archive-prop (org-entry-put nil "ARCHIVE" (concat "%s_archive::* " parent-task)))))))
	nil)))

  (defmacro bh/agenda-sort-test (fn a b)
    "Test for agenda sort"
    `(cond
      ;; if both match leave them unsorted
      ((and (apply ,fn (list ,a))
	    (apply ,fn (list ,b)))
       (setq result nil))
      ;; if a matches put a first
      ((apply ,fn (list ,a))
       ;; if b also matches leave unsorted
       (if (apply ,fn (list ,b))
	   (setq result nil)
	 (setq result -1)))
      ;; otherwise if b matches put b first
      ((apply ,fn (list ,b))
       (setq result 1))
      ;; if none match leave them unsorted
      (t nil)))

  (defmacro bh/agenda-sort-test-num (fn compfn a b)
    `(cond
      ((apply ,fn (list ,a))
       (setq num-a (string-to-number (match-string 1 ,a)))
       (if (apply ,fn (list ,b))
	   (progn
	     (setq num-b (string-to-number (match-string 1 ,b)))
	     (setq result (if (apply ,compfn (list num-a num-b))
			      -1
			    1)))
	 (setq result -1)))
      ((apply ,fn (list ,b))
       (setq result 1))
      (t nil)))

  (defun bh/is-not-scheduled-or-deadline (date-str)
    (and (not (bh/is-deadline date-str))
	 (not (bh/is-scheduled date-str))))

  (defun bh/is-due-deadline (date-str)
    (string-match "Deadline:" date-str))

  (defun bh/is-late-deadline (date-str)
    (string-match "In *\\(-.*\\)d\.:" date-str))

  (defun bh/is-pending-deadline (date-str)
    (string-match "In \\([^-]*\\)d\.:" date-str))

  (defun bh/is-deadline (date-str)
    (or (bh/is-due-deadline date-str)
	(bh/is-late-deadline date-str)
	(bh/is-pending-deadline date-str)))

  (defun bh/is-scheduled (date-str)
    (or (bh/is-scheduled-today date-str)
	(bh/is-scheduled-late date-str)))

  (defun bh/is-scheduled-today (date-str)
    (string-match "Scheduled:" date-str))

  (defun bh/is-scheduled-late (date-str)
    (string-match "Sched\.\\(.*\\)x:" date-str))

  (defun bh/agenda-sort (a b)
    "Sorting strategy for agenda items.
Late deadlines first, then scheduled, then non-late deadlines"
    (let (result num-a num-b)
      (cond
       ;; time specific items are already sorted first by org-agenda-sorting-strategy

       ;; non-deadline and non-scheduled items next
       ((bh/agenda-sort-test 'bh/is-not-scheduled-or-deadline a b))

       ;; late deadlines next
       ((bh/agenda-sort-test-num 'bh/is-late-deadline '< a b))

       ;; late scheduled items next
       ;;   ((bh/agenda-sort-test-num 'bh/is-scheduled-late '> a b))

       ;; deadlines for today next
       ((bh/agenda-sort-test 'bh/is-due-deadline a b))

       ;; scheduled items for today next
       ((bh/agenda-sort-test 'bh/is-scheduled-today a b))

       ;; late deadlines next
       ;;   ((bh/agenda-sort-test-num 'bh/is-late-deadline '< a b))

       ;; late scheduled items next
       ((bh/agenda-sort-test-num 'bh/is-scheduled-late '> a b))

       ;; pending deadlines last
       ((bh/agenda-sort-test-num 'bh/is-pending-deadline '< a b))

       ;; finally default to unsorted
       (t (setq result nil)))
      result))

Removes things tagged with “lp” or “reward” when typing “/ RET” in agenda

From: http://doc.norang.ca/org-mode.html#CustomAgendaViewFilteringContext
Also: http://orgmode.org/manual/Filtering_002flimiting-agenda-items.html
(defun bh/org-auto-exclude-function-private (tag)
  "Automatic task exclusion in the agenda with / RET"
  (and (cond
	  ((string= tag "lp") t)
	  ((string= tag "reward") t)
	  ((string= tag "test") t)
	  ((string= tag "2read") t)
	  )
	 (concat "-" tag)))

For business, I use a different setup:

(defun bh/org-auto-exclude-function-infonova (tag)
  "Automatic task exclusion in the agenda with / RET"
  (and (cond
	  ((string= tag "lp") t)
	  ((string= tag "reward") t)
	  ((string= tag "test") t)
	  ((string= tag "@BWG") t)
	  ((string= tag "blog") t)
	  ((string= tag "2read") t)
	  )
	 (concat "-" tag)))

(if (my-system-type-is-windows)
    (setq org-agenda-auto-exclude-function 'bh/org-auto-exclude-function-infonova)
  (setq org-agenda-auto-exclude-function 'bh/org-auto-exclude-function-private)
  )

my-narrow-agenda()

(defun my-narrow-agenda ()
  (interactive "P")
;  (org-agenda-filter-apply "-\(WAITING\|:reward:\|:lp:\)" 'regexp)

  (org-agenda-filter-apply "-NEXT.*:\\(@BWG\\|reward\\):" 'regexp)
;; returns: wrong number of arguments

;  (setq current-prefix-arg '(4)) ; C-u
;  (org-agenda-filter-by-regexp "\(WAITING\|:reward:\|:lp:\)")

;;  (org-agenda-filter-by-regexp '(4) "WAITING")
;; NEXT.*:\(@BWG\|reward\):   -> keyword "NEXT" with either tag "@BWG" OR "reward"
  )

my-super-agenda

Supercharge your Org daily/weekly agenda by grouping items

See also: id:2017-08-12-org-super-agenda

Loading the code:

(use-package org-super-agenda
 :load-path "~/.emacs.d/contrib/org-super-agenda/"
)

Definition of my-super-agenda-groups, my central configuration of super-agenda:

(setq my-super-agenda-groups
      '(;; Each group has an implicit boolean OR operator between its selectors.
        (:name "Today"  ; Optionally specify section name
               :time-grid t  ; Items that appear on the time grid
               )
        (:name "Important" :priority "A")
        (:priority<= "B"
                     ;; Show this section after "Today" and "Important", because
                     ;; their order is unspecified, defaulting to 0. Sections
                     ;; are displayed lowest-number-first.
                     :order 1)
        (:name "Habits" :habit t :order 2)
        (:name "Shopping" :tag "Besorgung" :order 3)
               ;; Boolean AND group matches items that match all subgroups
               ;;  :and (:tag "shopping" :tag "@town")
               ;; Multiple args given in list with implicit OR
               ;;  :tag ("food" "dinner"))
               ;;  :habit t
               ;;  :tag "personal")
        (:name "Started" :todo "STARTED" :order 5)
        ;;(:name "Space-related (non-moon-or-planet-related)"
        ;;       ;; Regexps match case-insensitively on the entire entry
        ;;       :and (:regexp ("space" "NASA")
        ;;                     ;; Boolean NOT also has implicit OR between selectors
        ;;                     :not (:regexp "moon" :tag "planet")))
        (:name "BWG" :tag "@BWG" :order 7)
        (:todo "WAITING" :order 9)  ; Set order of this section
        (:name "read" :tag "2read" :order 15)
        ;; Groups supply their own section names when none are given
        (:todo ("SOMEDAY" "WATCHING")
               ;; Show this group at the end of the agenda (since it has the
               ;; highest number). If you specified this group last, items
               ;; with these todo keywords that e.g. have priority A would be
               ;; displayed in that group instead, because items are grouped
               ;; out in the order the groups are listed.
               :order 25)
        (:name "reward"
               :tag ("reward" "lp")
               :order 100
               )

        ;; After the last group, the agenda will display items that didn't
        ;; match any of these groups, with the default order position of 99
        )
      )

my-super-agenda() is a function so that I am able to call the agenda interactively or within my-org-agenda() which is defined further down below.

(defun my-super-agenda()
  "generates my super-agenda"
  (interactive)
  (org-super-agenda-mode)
  (let
      ((org-super-agenda-groups my-super-agenda-groups))
    (org-agenda nil "a")
    )
  )

org-agenda-custom-commands → long list of agenda definitions

(setq org-agenda-custom-commands
      (quote (

              ("a" "Super Agenda" agenda ""
               (org-super-agenda-mode)
               ((org-super-agenda-groups my-super-agenda-groups))
               (org-agenda nil "a"))

              ("A" "Agenda" agenda ""
               (org-agenda nil "a"))

              ;; disabled 2014-08-17 ;;          ;; https://lists.gnu.org/archive/html/emacs-orgmode/2011-07/msg01374.html
              ;; disabled 2014-08-17 ;;          ("E" "events only" agenda ""
              ;; disabled 2014-08-17 ;;           (
              ;; disabled 2014-08-17 ;;            (org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'todo))
              ;; disabled 2014-08-17 ;;            ))
              ("n" "no TODO events +180d"
               ((agenda "no TODO events +180d"
                        ((org-agenda-span 180)
                         (org-agenda-time-grid nil)
                         (org-agenda-entry-types '(:timestamp :sexp))
                         (org-agenda-skip-function
                          '(or
                            (org-agenda-skip-entry-if 'todo 'any);; skip if any TODO state is found
                            (org-agenda-skip-entry-if 'category "infonova");; skip if any TODO state is found
                            (my-skip-tag "lp")
                            )
                          )
                         ;;(org-agenda-skip-function '(my-skip-tag "lp"))
                        )))
               nil ("~/org/agenda_180d_filtered.html"))

              ("D" "detail agenda"
               ((agenda "detail agenda"
                        ((org-agenda-span 31)
                         (org-agenda-time-grid nil)
                        )))
               nil ("~/org/agenda_details.html"))

              ;; disabled 2015-02-15 - replaced by no TODO events ;; ("p" "events Prio [#A]"
              ;; disabled 2015-02-15 - replaced by no TODO events ;;  ((agenda "+PRIORITY=\"A\""
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	  ((org-agenda-ndays 31)
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	   (org-agenda-time-grid nil)
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	   (org-agenda-entry-types '(:timestamp :sexp))
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	   (org-agenda-skip-function
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	    '(org-agenda-skip-entry-if 'notregexp "\\=.*\\[#A\\]")))
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	  ;; (
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	  ;;  (org-agenda-skip-function 'tag-without-done-or-canceled)
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	  ;;  )
              ;; disabled 2015-02-15 - replaced by no TODO events ;; 	  )))

              ;; disabled 2015-02-15 - replaced by no TODO + normal agenda ;; ("1" "1 month"
              ;; disabled 2015-02-15 - replaced by no TODO + normal agenda ;;  ((agenda "1 month"
              ;; disabled 2015-02-15 - replaced by no TODO + normal agenda ;; 	  ((org-agenda-ndays 31)
              ;; disabled 2015-02-15 - replaced by no TODO + normal agenda ;; 	   (org-agenda-time-grid nil)
              ;; disabled 2015-02-15 - replaced by no TODO + normal agenda ;; 	   (org-agenda-entry-types '(:timestamp :sexp))
              ;; disabled 2015-02-15 - replaced by no TODO + normal agenda ;; 	   )
              ;; disabled 2015-02-15 - replaced by no TODO + normal agenda ;; 	  )))

              ("r" "reward tasks" (
                                   (tags-todo "reward/!STARTED"
                                              (
                                               (org-agenda-overriding-header "rewards: STARTED")
                                               ))
                                   (tags-todo "reward/!NEXT"
                                              (
                                               (org-agenda-overriding-header "rewards: NEXT")
                                               ))
                                   (tags-todo "reward/!TODO"
                                              (
                                               (org-agenda-overriding-header "rewards: TODO")
                                               ))
                                   (tags-todo "reward/!SOMEDAY"
                                              (
                                               (org-agenda-overriding-header "rewards: SOMEDAY")
                                               ))
                                   ))
              ("i" "issues" (
                                   (tags-todo "issue/!STARTED"
                                              (
                                               (org-agenda-overriding-header "issues: STARTED")
                                               ))
                                   (tags-todo "issue/!NEXT"
                                              (
                                               (org-agenda-overriding-header "issues: NEXT")
                                               ))
                                   (tags-todo "issue/!TODO"
                                              (
                                               (org-agenda-overriding-header "issues: TODO")
                                               ))
                                   (tags-todo "issue/!SOMEDAY"
                                              (
                                               (org-agenda-overriding-header "issues: SOMEDAY")
                                               ))
                                   ))

              ;;disabled;              ("R" "grab reward" tags-todo "reward/!TODO|SOMEDAY"
              ;;disabled;	       (
              ;;disabled;		(org-agenda-overriding-header "rewards: TODO or SOMEDAY")
              ;;disabled;		))

              ("B" "borrowed" tags "+borrowed"
               (
                (org-agenda-overriding-header "borrowed or lend")
                (org-agenda-skip-function 'tag-without-done-or-canceled)
                ))

              ("$" "Besorgungen" tags "+Besorgung"
               (
                (org-agenda-overriding-header "Besorgungen")
                (org-agenda-skip-function 'tag-without-done-or-canceled)
                ))

              ;; disabled 2015-02-15 - can filter by tag ;; ("O" "SOMEDAY" tags-todo "+TODO=\"SOMEDAY\""
              ;; disabled 2015-02-15 - can filter by tag ;;  (
              ;; disabled 2015-02-15 - can filter by tag ;;   (org-agenda-overriding-header "SOMEDAY is today! :-)")
              ;; disabled 2015-02-15 - can filter by tag ;;   ))
              ;; disabled 2015-02-15 - can filter by tag ;;
              ;; disabled 2015-02-15 - can filter by tag ;; ("h" "home @ALW" tags-todo "+@ALW"
              ;; disabled 2015-02-15 - can filter by tag ;;  (
              ;; disabled 2015-02-15 - can filter by tag ;;   (org-agenda-overriding-header "home tasks")
              ;; disabled 2015-02-15 - can filter by tag ;;   ))
              ;; disabled 2015-02-15 - can filter by tag ;;
              ;; disabled 2015-02-15 - can filter by tag ;; ("b" "Breitenweg @BWG" tags-todo "+@BWG"
              ;; disabled 2015-02-15 - can filter by tag ;;  (
              ;; disabled 2015-02-15 - can filter by tag ;;   (org-agenda-overriding-header "home tasks")
              ;; disabled 2015-02-15 - can filter by tag ;;   ))

              ;; disabled 2014-08-17 because of error ;;;; 2014-02-18: from Org-mode ML Subject: Re: Get a list of tasks completed today
              ;; disabled 2014-08-17 because of error ;;("." "Completed today"
              ;; disabled 2014-08-17 because of error ;; ((todo "TODO|DONE|CANCELED"
              ;; disabled 2014-08-17 because of error ;;        ((org-agenda-skip-function
              ;; disabled 2014-08-17 because of error ;;          '(org-agenda-skip-entry-if 'notregexp (format-time-string "CLOSED: \\[%Y-%m-%d")))))
              ;; disabled 2014-08-17 because of error ;;  (org-agenda-sorting-strategy '(priority-down)))
              ;; disabled 2014-08-17 because of error ;; )

              ;; disabled 2015-02-15 - don't use it any more ;; ;; 2014-02-18: from Org-mode ML Subject: Re: Get a list of tasks completed today
              ;; disabled 2015-02-15 - don't use it any more ;; ("W" "Closed within a week."
              ;; disabled 2015-02-15 - don't use it any more ;;  tags "CLOSED>\"<-1w>\""
              ;; disabled 2015-02-15 - don't use it any more ;;  ((org-agenda-sorting-strategy '(priority-down))))

              ;; disabled 2015-02-15 - don't know what's for ;; ("o" "overview Agenda" (
              ;; disabled 2015-02-15 - don't know what's for ;; 			(agenda ""
              ;; disabled 2015-02-15 - don't know what's for ;; 				nil )
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled by nil above;			((org-agenda-skip-function '(my-skip-tag "reward"))
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled by nil above;			 (org-agenda-overriding-header "Agenda without rewards: ")))
              ;; disabled 2015-02-15 - don't know what's for ;; 			(tags "+TODO=\"DONE\"+CLOSED>=\"<today>\""
              ;; disabled 2015-02-15 - don't know what's for ;; 			      (
              ;; disabled 2015-02-15 - don't know what's for ;; 			       (org-agenda-overriding-header "DONE today")
              ;; disabled 2015-02-15 - don't know what's for ;; 			       ))
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled;                (tags "+reward"
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled;                           (
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled;			    (org-agenda-overriding-header "Rewards")
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled;                            ;(org-agenda-skip-function 'bh/skip-non-stuck-projects))
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled;                            ;(org-agenda-todo-ignore-scheduled 'future)
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled;                            ;(org-agenda-todo-ignore-deadlines 'future)
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled;			   )
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;diabled;			   )
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;too slow - dont need;                (tags-todo "-CANCELLED/!"
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;too slow - dont need;                           ((org-agenda-overriding-header "Stuck Projects")
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;too slow - dont need;                            (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;slow;                (tags-todo "-CANCELLED+WAITING/!"
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;slow;                           ((org-agenda-overriding-header "Waiting and Postponed Tasks")
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;slow;                            (org-agenda-skip-function 'bh/skip-stuck-projects)
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;slow;                            (org-tags-match-list-sublevels nil)
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;slow;                            (org-agenda-todo-ignore-scheduled 'future)
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;slow;                            (org-agenda-todo-ignore-deadlines 'future)
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;slow;			    ))
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                (tags "REFILE"
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                      ((org-agenda-overriding-header "Tasks to Refile")
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                       (org-tags-match-list-sublevels nil)))
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                (tags "-REFILE/"
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                      ((org-agenda-overriding-header "Tasks to Archive")
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                       (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                       (org-tags-match-list-sublevels nil)))
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                (tags-todo "-HOLD-CANCELLED/!"
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                           ((org-agenda-overriding-header "Projects")
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                            (org-agenda-skip-function 'bh/skip-non-projects)
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                            (org-agenda-sorting-strategy
              ;; disabled 2015-02-15 - don't know what's for ;; 			;;                             '(category-keep))))
              ;; disabled 2015-02-15 - don't know what's for ;; 			)
              ;; disabled 2015-02-15 - don't know what's for ;;  nil)

              ;;disabled;;	      ("x" "Borrowed"
              ;;disabled;;	       ((agenda ""
              ;;disabled;;			((org-agenda-skip-function 'tag-without-done-or-canceled)
              ;;disabled;;			 (org-agenda-overriding-header "Fun: ")))))

              ;;disabled 2014-08-17;; ("X" "calfw" open-calfw-agenda-org)

              ;;2012-12-10 deactivated;	      ("c" . "custom searches") ; description for "c" prefix
              ;;2012-12-10 deactivated;              ("cr" "rewards" agenda "+reward"
              ;;2012-12-10 deactivated;	       (
              ;;2012-12-10 deactivated;		(org-agenda-overriding-header "rewards")
              ;;2012-12-10 deactivated;		(org-agenda-time-grid nil)
              ;;2012-12-10 deactivated;		(org-agenda-entry-types '(:deadline))
              ;;2012-12-10 deactivated;	       ))
              ;;2012-12-10 deactivated;              ("cr" "rewards" agenda "+reward"
              ;;2012-12-10 deactivated;	       (
              ;;2012-12-10 deactivated;		(org-agenda-overriding-header "rewards")
              ;;2012-12-10 deactivated;		(org-agenda-time-grid nil)
              ;;2012-12-10 deactivated;		(org-agenda-entry-types '(:deadline))
              ;;2012-12-10 deactivated;	       ))
              ;;2012-12-10 deactivated;              ("ct" "@TUG" tags-todo "+@TUG"
              ;;2012-12-10 deactivated;               ((org-agenda-overriding-header "TUG Tasks")))
              ;;2012-12-10 deactivated;              ("ca" "@ALW" tags-todo "+@ALW"
              ;;2012-12-10 deactivated;               ((org-agenda-overriding-header "ALW Tasks")))
              ;;2012-12-10 deactivated;              ("cb" "Besorgungen" tags-todo "+Besorgung"
              ;;2012-12-10 deactivated;               ((org-agenda-overriding-header "Besorgungen")))
              ;;2012-12-10 deactivated;              ("cs" "Started tasks" tags-todo "/!STARTED"
              ;;2012-12-10 deactivated;               ((org-agenda-overriding-header "Started Tasks")))
              ;;2012-12-10 deactivated;              ("n" "Next and Started tasks" tags-todo "-WAITING-CANCELLED/!NEXT|STARTED"
              ;;2012-12-10 deactivated;               ((org-agenda-overriding-header "Next Tasks")))
              ;;2012-12-10 deactivated;              ("p" "Projects" tags-todo "LEVEL=2-REFILE|LEVEL=1+REFILE/!-DONE-CANCELLED-WAITING-SOMEDAY"
              ;;2012-12-10 deactivated;               ((org-agenda-skip-function 'bh/skip-non-projects)
              ;;2012-12-10 deactivated;                (org-agenda-overriding-header "Projects")))
              ;; ("o" "Other (Non-Project) tasks" tags-todo "LEVEL=2-REFILE|LEVEL=1+REFILE/!-DONE-CANCELLED-WAITING-SOMEDAY"
              ;;  ((org-agenda-skip-function 'bh/skip-projects)
              ;;   (org-agenda-overriding-header "Other Non-Project Tasks")))
              ;; ("A" "Tasks to be Archived" tags "LEVEL=2-REFILE/DONE|CANCELLED"
              ;;  ((org-agenda-overriding-header "Tasks to Archive")
              ;;   (org-agenda-skip-function 'bh/skip-non-archivable-tasks)))
                                      ;2012-12-10 deactivated;              ("h" "Habits" tags-todo "STYLE=\"habit\""
                                      ;2012-12-10 deactivated;               ((org-agenda-todo-ignore-with-date nil)
                                      ;2012-12-10 deactivated;                (org-agenda-todo-ignore-scheduled nil)
                                      ;2012-12-10 deactivated;                (org-agenda-todo-ignore-deadlines nil)
                                      ;2012-12-10 deactivated;                (org-agenda-overriding-header "Habits")))
              ;;              ("#" "Stuck Projects" tags-todo "LEVEL=2-REFILE|LEVEL=1+REFILE/!-DONE-CANCELLED"
              ;;               ((org-agenda-skip-function 'bh/skip-non-stuck-projects)
              ;;                (org-agenda-overriding-header "Stuck Projects")))
              ;;               ("*" "All open TODO tasks" tags-todo "-CANCELLED"
              ;;               ((org-agenda-overriding-header "All Open TODO tasks")
              ;;                (org-agenda-todo-ignore-with-date nil)
              ;;                (org-agenda-todo-ignore-scheduled nil)
              ;;                (org-agenda-todo-ignore-deadlines nil)
              ;;                (org-agenda-todo-ignore-timestamp nil)
              ;;                (org-agenda-todo-list-sublevels t)
              ;;                (org-tags-match-list-sublevels 'indented)))
              )))

Agenda settings

start Agenda in follow-mode:

;(setq org-agenda-start-with-follow-mode t)
;;(setq org-agenda-inhibit-startup nil);; slower but visibility of buffers is correctly shown
(setq org-agenda-inhibit-startup t);; faster with no hidden headings (agenda performance)

Compact the block agenda view

(setq org-agenda-compact-blocks t)
(setq org-agenda-use-tag-inheritance (quote (agenda)));; agenda performance

http://orgmode.org/org.html#Weekly_002fdaily-agenda

(setq org-agenda-span 1)

For tag searches ignore tasks with scheduled and deadline dates

(setq org-agenda-tags-todo-honor-ignore-options t)

Always hilight the current agenda line

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

The following custom-set-faces create the highlights

(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(highlight ((t (:background "cyan"))))
 '(hl-line ((t (:inherit highlight :background "darkseagreen2"))))
 '(org-mode-line-clock ((t (:background "grey75" :foreground "red" :box (:line-width -1 :style released-button)))) t))

Keep tasks with dates off the global todo lists:

(setq org-agenda-todo-ignore-with-date nil)

Allow deadlines which are due soon to appear on the global todo lists:

(setq org-agenda-todo-ignore-deadlines (quote far))

Keep tasks scheduled in the future off the global todo lists

(setq org-agenda-todo-ignore-scheduled (quote future))

Remove completed deadline tasks from the agenda view

(setq org-agenda-skip-deadline-if-done t)

Remove completed scheduled tasks from the agenda view

(setq org-agenda-skip-scheduled-if-done t)

Remove completed items from search results

(setq org-agenda-skip-timestamp-if-done t)

Include agenda archive files when searching for things

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

show state changes in log-mode of agenda

(setq org-agenda-log-mode-items (quote (state)))

http://orgmode.org/worg/org-faq.html

;(setq org-agenda-skip-additional-timestamps-same-entry t)
(setq org-agenda-skip-additional-timestamps-same-entry nil)

do not search for time in heading when displaying a date-stamp

(setq org-agenda-search-headline-for-time nil)

open agenda in same buffer, full size

(setq org-agenda-window-setup 'current-window)

add diary entries in agenda view http://orgmode.org/org.html#Weekly_002fdaily-agenda

(setq org-agenda-include-diary t)

Show all future entries for repeating tasks

(setq org-agenda-repeating-timestamp-show-all t)

Show all agenda dates - even if they are empty

(setq org-agenda-show-all-dates t)

Sorting order for tasks on the agenda

 (setq org-agenda-sorting-strategy
	(quote ((agenda habit-down time-up user-defined-up priority-down category-keep)
		(todo priority-down category-keep)
		(tags priority-down category-keep)
		(search category-keep))))

Start the weekly agenda today

(setq org-agenda-start-on-weekday nil)

Non-nil means skip timestamp line if same entry shows because of deadline.

(setq org-agenda-skip-timestamp-if-deadline-is-shown t)

Agenda sorting functions

(setq org-agenda-cmp-user-defined 'bh/agenda-sort)

Enable display of the time grid so we can see the marker for the current time

(setq org-agenda-time-grid
      ((daily today remove-match)
       #("----------------" 0 16
         (org-heading t))
       (800 1000 1200 1400 1600 1800 2000)))

Display tags farther right

;;(setq org-agenda-tags-column -102)
(setq org-tags-column -101); for powerplantwin 23" TFT turned 90
					; degrees; should *not* differ between
					; systems! Otherwise Org-files gets
					; re-formatted after switching
                                      ; system
;;(when (my-system-type-is-windows)
;;    ;;(setq org-agenda-tags-column -103);; for 23" TFT turned 90 degrees
;;      (setq org-agenda-tags-column -117);; for 24" TFT turned 90 degrees
;;      )
;;(when (my-system-is-sherri)
;;    (setq org-agenda-tags-column -117);; -117 for 23" TFT sherri, rotated 90°
;;    )
(setq org-agenda-tags-column (- (- (window-total-width) 3))) ;; total width minus 3

Sticky agendas remain opened in the background so that you don’t need to regenerate them each time you hit the corresponding keystroke. This is a big time saver.

(setq org-agenda-sticky t)

Agenda category icons

There is the possibility of adding icons to categories: http://julien.danjou.info/blog/2010/icon-category-support-in-org-mode

This is a neat way of beautifying the agenda.

Unfortunately, the clean way of defining the data directory relatively to the path stored in my-user-emacs-directory does not work:

(concat my-user-emacs-directory "bin/R6-logo_18x12.jpg") nil nil :ascent center)

I don’t know how to fix this and so I stick with the hard coded path and with a bleeding heart.

  (setq org-agenda-category-icon-alist nil)
  ;(when (my-system-type-is-windows)
    (add-to-list 'org-agenda-category-icon-alist
		 '(".*" '(space . (:width (16))))
		 )
;;    (add-to-list 'org-agenda-category-icon-alist
;;		  '("r6" "~/.emacs.d/bin/R6-logo_18x12.jpg" nil nil :ascent center)
;;		  )
;;    (add-to-list 'org-agenda-category-icon-alist
;;		  '("infonova" "~/.emacs.d/bin/R6-logo_18x12.jpg" nil nil :ascent center)
;;		  )
    (add-to-list 'org-agenda-category-icon-alist
		  '("detego" "~/.emacs.d/bin/detego-inwarehouse-logo-D_only_16x16.png" nil nil :ascent center)
		  )
    (add-to-list 'org-agenda-category-icon-alist
		  '("outlook" "~/.emacs.d/bin/detego-inwarehouse-logo-D_only_16x16.png" nil nil :ascent center)
		  )
    ;;(add-to-list 'org-agenda-category-icon-alist
    ;;		 '("misc" '(space . (:width (18))))
    ;;		 )
  ;  )

  (when (and (not (my-system-type-is-windows)) (not (my-system-is-karl-voit-at)))
    (add-to-list 'org-agenda-category-icon-alist
		 '(".*" '(space . (:width (16))))
		 )
    (add-to-list 'org-agenda-category-icon-alist
		 '("contacts" "~/.emacs.d/bin/user-identity.png" nil nil :ascent center)
		     ;; /usr/share/icons/gnome/16x16/emotes/face-smile.png
		  )
    (add-to-list 'org-agenda-category-icon-alist
		 '("public_voit" "~/.emacs.d/bin/application-rss+xml.png" nil nil :ascent center)
                 ;; /usr/share/icons/oxygen/16x16/mimetypes/application-rss+xml.png
		  )
;;    (add-to-list 'org-agenda-category-icon-alist
;;		 '("misc" "~/.emacs.d/bin/emblem-new.png" nil nil :ascent center)
;;                 ;; /usr/share/icons/oxygen/16x16/emblems/emblem-new.png
;;		  )
    (add-to-list 'org-agenda-category-icon-alist
		 '("hardware" "~/.emacs.d/bin/camera-photo.png" nil nil :ascent center)
                 ;; /usr/share/icons/oxygen/16x16/devices/camera-photo.png
		  )
    (add-to-list 'org-agenda-category-icon-alist
		 '("bwg" "~/.emacs.d/bin/go-home.png" nil nil :ascent center)
                 ;; /usr/share/icons/oxygen/16x16/actions/go-home.png
		  )
   )

my-org-agenda() → my-map a

switch to open Agenda or open new one:

(defun my-org-agenda ()
  "Opens the already opened agenda or opens new one instead"
  (interactive)

  (setq my-org-agenda-tags-column (- (- (window-total-width) 3)))
  (setq org-agenda-tags-column my-org-agenda-tags-column) ;; total width minus 3

  (if (my-buffer-exists "*Org Agenda*")
      (switch-to-buffer "*Org Agenda*")
    (my-super-agenda)
    )
  )
(bind-key "a" 'my-org-agenda my-map)

my-memacs-org-agenda() → my-map m C-cm

Memacs org-agenda shortcut

(defun my-memacs-org-agenda ()
  "Opens an org-agenda with activated archive"
  (interactive)
  ;;(setq org-agenda-files (append (quote ("~/org/issues.org"))));; for testing purposes
  (org-agenda-list)
  ;;(call-interactively 'org-agenda-log-mode)
  (org-agenda-log-mode '(4))
  (call-interactively 'org-agenda-archives-mode)
  (org-agenda-archives-mode 'files)
  )
;;disabled because I needed "m";; (bind-key "m" 'my-memacs-org-agenda my-map)
(global-set-key "\C-cm" 'my-memacs-org-agenda)

Or within a shell as separate Emacs instance:

/usr/bin/emacs --load /home/vk/.emacs.d/init.el --eval '(progn (my-memacs-org-agenda))'

I aliased it within ~/.zshrc.local to memacs

my-export-agenda()

 (defun my-export-agenda()
   "Exports monthly Org-mode agenda to agenda.ics file"
   (interactive)
   (save-some-buffers)
   (org-agenda-list nil nil 60)
   (message "after org-agenda-list")
   ;;test;  (org-agenda-list nil nil 15)
   (org-agenda-write "~/org/agenda-export-raw.ics")
   (message "after org-agenda-write")
   (setq scriptpath "~/src/postprocess_Org-mode_iCal_export/")
   (setq icspath "~/org/")
   (shell-command-to-string (concat
			      scriptpath "postprocess_Org-mode_iCal_export.py "
			      "-i " icspath "agenda-export-raw.ics "
			      "-o " icspath "agenda-export-postprocessed.ics "
			      "--overwrite "
			      "--remove-summary-timestamp"
			      )
			     )
   (shell-command-to-string (concat
			      scriptpath "postprocess_Org-mode_iCal_export.py "
			      "-i " icspath "agenda-export-raw.ics "
			      "-o " icspath "agenda-export-freebusy.ics "
			      "--overwrite "
			      "--obfuscate"
			      )
			     )
   (message "after shell-command-to-string")
   (if (my-system-type-is-gnu)
	(shell-command-to-string "/home/vk/bin/vk-cronjob-gary-do-unison-sync-unattended-share-all_if_host_is_reachable.sh")
     (message "Please do sync using unison!")
     )
   )

my-org-agenda-to-appt

For org appointment reminders http://orgmode.org/worg/org-hacks.html#sec-3_1 Get appointments for today

(when (or (my-system-type-is-gnu) (my-system-is-powerplantlinux))
  (defun my-org-agenda-to-appt ()
    (interactive)
    (setq appt-time-msg-list nil)
    (let ((org-deadline-warning-days 0))    ;; will be automatic in org 5.23
	(org-agenda-to-appt)))
  ;; Run once, activate and schedule refresh
  (my-org-agenda-to-appt)
  (appt-activate t)
  (run-at-time "24:01" nil 'org-agenda-to-appt)
  ;; 5 minute warnings
  (setq appt-message-warning-time 15)
  (setq appt-display-interval 15)
  ;; Update appt each time agenda opened.
  (add-hook 'org-finalize-agenda-hook 'org-agenda-to-appt)
  ;; Setup zenify, we tell appt to use window, and replace default function
  (setq appt-display-format 'window)
  (setq appt-disp-window-function (function appt-disp-window))
  (defun appt-disp-window (min-to-app new-time msg)
    (save-window-excursion
	(shell-command
	 (concat "/usr/bin/zenity --info --title='Appointment' --text='" msg "' &") nil nil)
	)
    )
  )

my-export-month-agenda-to-png-via-screenshot()

Generates my agenda and creates a screenshot with it. I used this as a workaround before I customized my agenda export to HTML.

  • id:2016-04-12-my-export-month-agenda-to-png-via-screenshot
(defun my-export-month-agenda-to-png-via-screenshot()
  (interactive)
  (when (my-system-is-sherri)
    (message "Generating agenda ...")
    (org-agenda nil "n") ; generates agenda "n" (one month without todos)
    (if (my-buffer-exists "*Org Agenda*")
	(switch-to-buffer "*Org Agenda*")
      (org-agenda-list)
      )
    (message "Waiting for Screenshot ...")
    (sit-for 1) ; (sleep 1) ... doesn't re-display and thus screenshot
                ; showed buffer before switching to agenda
    (message "Say cheese ...")

    (setq myoutput
          (shell-command-to-string "/usr/bin/import -window root /home/vk/share/roy/from_sherri/agenda.png"))
    (message (concat "Screenshot done (" myoutput ")"))
    )
  )

*

calfw - A calendar framework for Emacs

https://github.com/kiwanami/emacs-calfw

I am not using it because of a missing visualization option I described on https://github.com/kiwanami/emacs-calfw/issues/22

Open calendar using: M-x cfw:open-org-calendar

(add-to-list 'load-path "~/.emacs.d/contrib/calfw/")
(use-package calfw-org)

Provide a command to use calfw in org-agenda-custom-commands

(defun open-calfw-agenda-org(&rest args)
  (let
      (
       ;; do not duplicate deadlines
       (org-deadline-warning-days 0)
       )
    (cfw:open-org-calendar)
    )
  )

habits

«Org has the ability to track the consistency of a special category of TODOs, called “habits”.»

(setq org-global-properties (quote (("STYLE_ALL" . "habit"))))
  • position the habit graph on the agenda to the right of the default
(setq org-habit-graph-column 50)

my-reset-org-with-visibility-and-super-agenda() - reset some Org-mode stuff and reset startup visibility

This function is a combination of my-reset-org() and my-org-startup-visibility() from above.

(defun my-reset-org-with-visibility-and-super-agenda ()
  "Clears all kinds of Org-mode caches and re-builds them if possible and resets the most important buffers to their startup visibility"
  (interactive)
  (my-reset-org)
  (my-org-startup-visibility)
  )

org-agenda-exporter-settings

I export my agendas defined in org-agenda-custom-commands that have an export file associated (as of 2017-06-03: agenda_180d_filtered.html and agenda_details.html) using a daily cronjob that looks like:

0 4 * * * /usr/bin/emacs --batch --load /home/vk/.emacs.d/init.el --eval '(progn (setq org-agenda-files (append my-work-agenda-files my-nonwork-agenda-files)) (org-store-agenda-views))' >/dev/null 2>&1

As you can see, I override org-agenda-files with both, my work and my non-work agenda files. Otherwise, I’d get the host-specific non-work-only agenda which I don’t want to see in my exported agenda HTML files.

The generated HTML files are placed in a directory that gets automatically synced via Syncthing to my Android phone. The phone has browser bookmarks set for the agenda files and my desktop has icons for those bookmarks. This is how I access my agenda files on my phone.

customizing the agenda export of C-x C-w

 (setq org-agenda-exporter-settings
	'((ps-number-of-columns 2)
	  (ps-landscape-mode t)
	  ;;disabled;                  (org-agenda-add-entry-text-maxlines 5)
	  (htmlize-output-type 'css)))

iCal

iCal -> Org

Import iCal to Org-mode

(my-load-local-el "contrib/org-import-calendar.el")
;won't work; (use-package org-import-calendar
;won't work;  :load-path "~/.emacs.d/contrib/"
;won't work; )

(use-package org-import-icalendar)

Austrian Holidays

(require 'holidays)
(setq holiday-austria-holidays '((holiday-fixed  1  1 "Neujahr (frei)")
                                   (holiday-fixed  1  6 "Heilige Drei Könige (frei)")
                                   (holiday-easter-etc 1 "Ostermontag (frei)")
				     (holiday-easter-etc -46 "Aschermittwoch")
				     (holiday-easter-etc -2 "Karfreitag")
				     (holiday-fixed  5  1 "Österreichischer Staatsfeiertag (frei)")
				     (holiday-easter-etc 39 "Christi Himmelfahrt (frei)")
				     (holiday-easter-etc 50 "Pfingstmontag (frei)")
				     (holiday-easter-etc 60 "Fronleichnam (frei)")
				     (holiday-float 5 0 2 "Muttertag")
				     (holiday-float 6 0 2 "Vatertag")
				     (holiday-fixed  8 15 "Mariä Himmelfahrt (frei)")
				     (holiday-fixed 10 26 "Nationalfeiertag (frei)")
				     (holiday-fixed 11  1 "Allerheiligen (frei)")
				     (holiday-fixed 12  8 "Maria Empfängnis (frei)")
				     (holiday-fixed 12 24 "Heiliger Abend (nicht frei)")
				     (holiday-fixed 12 25 "Erster Weihnachtstag (frei)")
				     (holiday-fixed 12 26 "Zweiter Weihnachtstag (frei)")))
  ;;(setq holiday-other-holidays '((holiday-fixed 10  3 "Tag der Deutschen Einheit")))
  (setq holiday-local-holidays holiday-austria-holidays)
  (setq calendar-holidays (append holiday-local-holidays holiday-other-holidays))
  ;; and add (load "~/Notes/holidays" t) to your .emacs and add
  ;; #+CATEGORY: Feiertag
  ;; %%(org-calendar-holiday)
  ;; to an agenda file
  ;; ######################################################
  ;; Muttertag... from http://debianforum.de/forum/viewtopic.php?f=29&t=67024

time-zone for iCal

(setq org-icalendar-timezone "Europe/Vienna")

setting destination file for iCal export

(setq org-combined-agenda-icalendar-file "~/public_html/orgmodevk478.ics")

org-mycal-export-limit()

define filter. The filter is called on each entry in the agenda. It defines a regexp to search for two timestamps, gets the start and end point of the entry and does a regexp search. It also checks if the category of the entry is in an exclude list and returns either t or nil to skip or include the entry.

(defun org-mycal-export-limit ()
  "Limit the export to items that have a date, time and a range. Also exclude certain categories."
  (setq org-tst-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ... [0-9]\\{2\\}:[0-9]\\{2\\}[^\r\n>]*?\\)>")
  (setq org-tstr-regexp (concat org-tst-regexp "--?-?" org-tst-regexp))
  (save-excursion
    ;; get categories
    (setq mycategory (org-get-category))
    ;; get start and end of tree
    (org-back-to-heading t)
    (setq mystart    (point))
    (org-end-of-subtree)
    (setq myend      (point))
    (goto-char mystart)
    ;; search for timerange
    (setq myresult (re-search-forward org-tstr-regexp myend t))
    ;; search for categories to exclude
    (setq mycatp (member mycategory org-export-exclude-category))
    ;; return t if ok, nil when not ok
    (if (and myresult (not mycatp)) t nil)))

;; activate filter and call export function
(defun org-mycal-export ()
  (let ((org-icalendar-verify-function 'org-mycal-export-limit))
    (org-export-icalendar-combine-agenda-files)))

org-mode export of calendar events to Google

http://orgmode.org/worg/org-tutorials/org-google-sync.html

Categories that should be excluded

(setq org-export-exclude-category (list "google" "private"))

Ignore :noexport: entries in iCal-export

http://comments.gmane.org/gmane.emacs.orgmode/36415

(setq org-icalendar-honor-noexport-tag t)

Add tags to iCal-export

http://comments.gmane.org/gmane.emacs.orgmode/19148

(setq org-icalendar-categories (quote (all-tags category)))
'(org-icalendar-include-body 1000)
'(org-icalendar-include-sexps nil)
'(org-icalendar-include-todo nil)
'(org-icalendar-store-UID t)
'(org-icalendar-timezone "Europe/Berlin")
'(org-icalendar-use-deadline (quote (event-if-not-todo event-if-todo)))
'(org-icalendar-use-plain-timestamp nil)
'(org-icalendar-use-scheduled (quote (event-if-not-todo event-if-todo)))

Tables

(setq org-table-export-default-format "orgtbl-to-csv")

orgaggregate - Aggregate Values in a Table

https://github.com/tbanel/orgaggregate «Aggregating a table is creating a new table by computing sums, averages, and so on, out of material from the first table.»

(use-package orgtbl-aggregate
   :load-path "~/.emacs.d/contrib/orgaggregate/"
)

;won't work; (use-package org-insert-dblock
;won't work;    :load-path "~/.emacs.d/contrib/orgaggregate/"
;won't work; )
(my-load-local-el "contrib/orgaggregate/org-insert-dblock.el")

org-table-sticky-header-mode

A minor mode to show the sticky header for org-mode tables.

(use-package org-table-sticky-header
  :ensure t
  :config
  (add-hook 'org-mode-hook 'org-table-sticky-header-mode)
  )

Exporting

Not necessary any more:

;;(require 'ox-beamer)
;;(require 'ox-odt)
;;(require 'ox-freemind)
;;(require 'ox-taskjuggler)

Add bibtex to pdf export method:

(when (my-eval-if-binary-or-warn "pdflatex")
   (setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -output-directory %o %f"
        "bibtex %b"
        "pdflatex -interaction nonstopmode -output-directory %o %f"
        "pdflatex -interaction nonstopmode -output-directory %o %f"))
)

Guess the master file for FILENAME from currently open files according to their extension

  • disabled 2015-03-22 because it did not help
(add-hook 'org-mode-hook
	    (lambda ()
            (setq TeX-master (guess-TeX-master (buffer-file-name)))
	      (message (concat "set master file to: " buffer-file-name))
	      )
	    )

Export subtree (by default) instead of whole buffer: http://orgmode.org/manual/The-Export-Dispatcher.html

(setq org-export-initial-scope 'subtree)

using alternative LaTeX exporter

For the records:

invoke: M-x org-export-dispatch

(require 'org-export)
(require 'org-e-latex)
(require 'ox-latex)
(add-to-list 'org-latex-classes
             '("beamer"
               "\\documentclass\[presentation\]\{beamer\}"
               ("\\section\{%s\}" . "\\section*\{%s\}")
               ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
               ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))
(unless (boundp 'org-export-latex-classes)
  (setq org-export-latex-classes nil))
(add-to-list 'org-export-latex-classes
             '("article"
               "\\documentclass{article}"
               ("\\section{%s}" . "\\section*{%s}")))

org-export-latex-classes → koma-article

(add-to-list 'org-export-latex-classes
          '("koma-article"
             "\\documentclass{scrartcl}
             [NO-DEFAULT-PACKAGES]
             [EXTRA]"
             ("\\section{%s}" . "\\section*{%s}")
             ("\\subsection{%s}" . "\\subsection*{%s}")
             ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
             ("\\paragraph{%s}" . "\\paragraph*{%s}")
             ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

org-export-latex-classes → ACM

(add-to-list 'org-export-latex-classes
          '("ACM"
             "\\documentclass{acm_proc_article-sp}
             [NO-DEFAULT-PACKAGES]
             [EXTRA]"
             ("\\section{%s}" . "\\section*{%s}")
             ("\\subsection{%s}" . "\\subsection*{%s}")
             ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
             ("\\paragraph{%s}" . "\\paragraph*{%s}")
             ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

LaTeX classes

http://orgmode.org/org.html#Header-and-sectioning

BEGIN of LaTeX class definitions

(when (my-eval-if-binary-or-warn "pdflatex")
  (with-eval-after-load 'ox-latex
  ;;(message (concat "################################################\norg-latex-classes = [" org-latex-classes "]"))

Customized «scrartcl»

(add-to-list 'org-latex-classes
             '("scrartcl"
               "\\documentclass\[a4paper,parskip=half\]\{scrartcl\}"
               ("\\section\{%s\}" . "\\section*\{%s\}")
               ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
               ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))

«scrartclsmall»

  • 2014-10-16: does NOT work yet. Most probably because savetrees does not work well with inputenc
(add-to-list 'org-latex-classes
             '("scrartclsmall"
               "\\documentclass\[a4paper,parskip=half\]\{scrartcl\}\\usepackage\{savetrees\}"
               ("\\section\{%s\}" . "\\section*\{%s\}")
               ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
               ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))

«detego»

  • 2017-09-13: must be tested
(add-to-list 'org-latex-classes
             '("detego"
               "\\documentclass\[a4paper,parskip=half,11pt\]\{scrartcl\}
                \\usepackage\[ngerman,american\]\{babel\}\\usepackage\{eurosym\}\\usepackage\{xspace\}\\usepackage\[usenames,dvipsnames\]\{xcolor\}
                \\usepackage\[protrusion=true,factor=900\]\{microtype\}\\usepackage\{enumitem\}
                \\definecolor\{DispositionColor\}\{RGB\}\{0,54,90\}
                \\usepackage\{helvet\}
                \\renewcommand\{\\familydefault\}\{\\sfdefault\}
                \\DeclareRobustCommand\{\\myacro\}\[1\]\{\\textsc\{\\lowercase\{#1\}\}\} %%  abbrevations using small caps
                %% colorful headings:
                %\\setheadsepline\{.4pt\}\[\\color\{DispositionColor\}\]
                \\renewcommand\{\\headfont\}\{\\normalfont\\sffamily\\color\{DispositionColor\}\}
                \\renewcommand\{\\pnumfont\}\{\\normalfont\\sffamily\\color\{DispositionColor\}\}
                \\addtokomafont\{disposition\}\{\\color\{DispositionColor\}\}
                \\addtokomafont\{caption\}\{\\color\{DispositionColor\}\\footnotesize\}
                \\addtokomafont\{captionlabel\}\{\\color\{DispositionColor\}\}

                \\usepackage\{enumitem\}
                \\setlist\{noitemsep\} %% kills the space between items

               "
               ("\\section\{%s\}" . "\\section*\{%s\}")
               ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
               ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))

«lyrics»

  • 2017-03-23: 2-column layout sans-serif for lyrics
(add-to-list 'org-latex-classes
             '("lyrics"
               "\\documentclass\[a4paper,parskip=half\]\{scrartcl\}\\usepackage\{savetrees\}
                \\usepackage\{lmodern\} \\renewcommand*\\sfdefault\{lcmss\} \\renewcommand*\\familydefault\{\\sfdefault\}"
               ("\\section\{%s\}" . "\\section*\{%s\}")
               ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
               ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))

«lyrics2» 2 column version of «lyrics»

(add-to-list 'org-latex-classes
             '("lyrics2"
               "\\documentclass\[a4paper,parskip=half,twocolumn\]\{scrartcl\}\\usepackage\{savetrees\}
                \\usepackage\{lmodern\} \\renewcommand*\\sfdefault\{lcmss\} \\renewcommand*\\familydefault\{\\sfdefault\}"
               ("\\section\{%s\}" . "\\section*\{%s\}")
               ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
               ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))

Adding TUGRAZ letter export class format

(add-to-list 'org-export-latex-classes
             '("TUGRAZletter"
               "\\documentclass{scrlttr2}
                \\usepackage{tugrazletter}
                [NO-DEFAULT-PACKAGES]
                [EXTRA]"
               ("\\section{%s}" . "\\section*{%s}")))

END of LaTeX class definitions

   );; with-eval-after-load
);; if pdflatex is found

ox-pandoc - Export via Pandoc

https://github.com/kawabata/ox-pandoc - «This is another exporter that translates Org-mode file to various other formats via Pandoc.»

(when (my-eval-if-binary-or-warn "pandoc")
  (use-package ox-pandoc
    :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
    :defer 10
    ;; :if (or (my-system-type-is-gnu) (my-system-type-is-windows))
  )
)

ox-asciidoc - Export to AsciiDoc

https://github.com/yashi/org-asciidoc - «An Org Mode Exporter Backend For AsciiDoc»

(use-package ox-asciidoc
  ;;:ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
  :defer 10
)

Org-Reveal - generate nice presentations out of Org-mode

https://github.com/yjwen/org-reveal

  • Reveal.js is a tool for creating good-looking HTML presentations, authored by Hakim El Hattab.
  • For an example of a reveal.js presentation, see here.
  • Org-Reveal exports your Org documents to reveal.js presentations.
  • With Org-reveal, you can create beautiful presentations with 3D effects from simple but powerful Org contents.
(use-package ox-reveal
  :ensure t
  ;;:if (my-system-type-is-windows)
  :defer 10
  :config

  ;;(setq org-reveal-root "file:///d:/reveal.js")
  (cond ((my-system-type-is-gnu)
         (setq org-reveal-root "http://cdn.jsdelivr.net/reveal.js/3.0.0/")
         (setq org-reveal-extra-css "file:///home/vk/.emacs.d/bin/reveal_theme_night_local.css"))
        ((my-system-type-is-windows)
         (setq org-reveal-root "file:///C:/Users/karl.voit/.emacs.d/bin/reveal.js/")
         (setq org-reveal-extra-css "file:///C:/Users/karl.voit/.emacs.d/bin/reveal_theme_night_local.css"))
        (t
         (setq org-reveal-root "http://cdn.jsdelivr.net/reveal.js/3.0.0/"))
    )

  ;; my preferred defaults:
  (setq org-reveal-hlevel 2)
  (setq org-reveal-postamble "<p> Created by Karl. </p>")
  (setq org-reveal-center nil)
  (setq org-reveal-progress t)
  (setq org-reveal-history nil)
  (setq org-reveal-control t)
  (setq org-reveal-keyboard t)
  (setq org-reveal-overview nil)
  (setq org-reveal-transition "default")
  ;; - transitions:
  ;;   - default
  ;;   - cube
  ;;   - page
  ;;   - concave
  ;;   - zoom
  ;;   - linear
  ;;   - fade
  ;;   - none
  (setq org-reveal-theme "night")
  ;; - Styles:
  ;;   - black (default)
  ;;   - white
  ;;   - league
  ;;     - gray one
  ;;   - sky
  ;;     - nice bright one
  ;;   - beige
  ;;     - nice bright one
  ;;   - simple
  ;;     - bright
  ;;   - serif
  ;;     - old school
  ;;   - blood
  ;;     - cool!
  ;;   - *night*
  ;;     - very nice
  ;;   - moon
  ;;   - solarized
)

ox-clip - formatted copy from Org-mode to system clipboard

This module copies selected regions in org-mode as formatted text on the clipboard that can be pasted into other applications. When not in org-mode, the htmlize library is used instead.

For Windows the html-clip-w32.py script will be installed. It works pretty well, but I noticed that the hyperlinks in the TOC to headings don’t work, and strike-through doesn’t seem to work. I have no idea how to fix either issue.

Mac OSX needs textutils and pbcopy, which should be part of the base install.

Linux needs a relatively modern xclip. https://github.com/astrand/xclip

There is one command: `ox-clip-formatted-copy’ that should work across Windows, Mac and Linux.

(require ‘htmlize)

(when (or
       (and (my-system-type-is-gnu) (my-eval-if-binary-or-warn "xclip") (not (my-system-is-karl-voit-at)))
       (and (my-system-type-is-darwin) (my-eval-if-binary-or-warn "textutils") (my-eval-if-binary-or-warn "pbcopy"))
       (my-system-type-is-windows);; For Windows the html-clip-w32.py script will be installed.
       )
  (use-package ox-clip
      ;;:if
    :ensure t
    :defer 10
    )
  )

lazyblorg

I wrote my own blogging system named lazyblorg and generate my own blog with it.

my-lazyblorg-test() - blog article preview

When writing a blog article, this function generates a local version of the blog article and shows it in the browser.

 (if (my-system-type-is-gnu)
     (defun my-lazyblorg-test()
	"Saves current blog entry to file and invoke lazyblorg process with it"
	(interactive)
	(save-excursion
	  (search-backward ":blog:");; search begin of current (previous) blog entry
	  (beginning-of-line nil)
	  (set-mark-command nil);; set mark
	  (org-cycle);; close org-mode heading and sub-headings
	  (next-line);; goto next org-mode heading (this should be next line after blog entry)
	  (beginning-of-line nil)
	  (let ((p (point));; copy region
		(m (mark)))
	    (if (< p m)
		(kill-ring-save p m)
	      (kill-ring-save m p)))
	  (find-file "/tmp/lazyblorg-preview.org");; fixed temporary file (will be overwritten)
	  (erase-buffer);; I told you!
	  (yank);; paste region from above
	  (save-buffer);; save to disk
	  (kill-buffer "lazyblorg-preview.org");; destroy last evidence
	  (previous-line);;
	  (org-cycle);; close org-mode heading and sub-headings
	  ;; invoke lazyblorg:
	  (shell-command-to-string "/home/vk/src/lazyblorg/preview_blogentry.sh");; invoke shell script
	  )
	)
   )

my-jump-to-lazyblorg-heading-according-to-URL-in-clipboard() → my-map l

One of the advantages of lazyblorg is, that a blog entry can be written anywhere in my Org-mode files. This is great for composing blog articles but not so great for locating it in my Org-mode files when I need to access the source of an article.

Therefore, I wrote the following function. The process is now very easy: I locate the article (using my blog search?) in the web browser. Then I copy the URL to the system clipboard. I switch to Emacs and call the function below to jump to the article. Easy as that. :-)

Gets “public voit”-URL from clipboard and jumps to its Org-mode heading:

(defun my-jump-to-lazyblorg-heading-according-to-URL-in-clipboard ()
  "Retrieves an URL from the clipboard, gets its Org-mode source,
   extracts the ID of the article and jumps to its Org-mode heading"
  (interactive)
  (let (
        ;; Getting URL from the clipboard. Since it may contain
        ;; some text properties we are using substring-no-properties
        ;; function
        (url (substring-no-properties (current-kill 0)))
        ;; This is a check string: if the URL in the clipboard
        ;; doesn't start with this, an error message is shown
        (domain "karl-voit.at")
	)
    ;; Check if URL string is from my domain (all other strings do
    ;; not make any sense here)
    (if (string-match (upcase domain) (upcase url))
	  ;; Retrieving content by URL into new buffer asynchronously
	  (url-retrieve url
                      ;; call this lambda function when URL content is retrieved
			(lambda (status)
			   ;; Extrating and preparing the ID
			   (let* (
                                ;; Limit the ID search to the top 1000 characters of the buffer
				  (pageheader (buffer-substring 1 1000))
				  ;; Start index of the id
                                (start (string-match "<meta name=\"orgmode-id\" content=\"" pageheader))
                                ;; End index of the id
                                (end (string-match "\" />" pageheader start))
                                ;; Amount of characters to skip for the openning tag
                                (chars-to-skip (length "<meta name=\"orgmode-id\" content=\""))
                                ;; Extract ID
                                (lazyblorg-id (if (and start end (< start end))
                                                  ;; ... extract it and return.
                                                  (substring pageheader (+ start chars-to-skip) end)
                                                nil))
                                )
			     (message (concat "Looking for id:" lazyblorg-id " ..."))
			     (org-open-link-from-string (concat "id:" lazyblorg-id))
			     )
			   )
			)
	(message (concat "Sorry: the URL \"" (substring url 0 (length domain)) "...\" doesn't contain \"" domain "\". Aborting."))
      ;;(message (concat "domain: " domain))
      ;;(message (concat "url:    " url))
	)
    )
  )

binding the function:

(bind-key "l" #'my-jump-to-lazyblorg-heading-according-to-URL-in-clipboard my-map)

helm-org-agenda-files-headings: grep within headings → my-map H

This is a neat and fast way of looking for string only within heading lines:

(bind-key "H" #'helm-org-agenda-files-headings my-map)

Contact management

Yes, of course I do manage contact data about people within Org-mode.

See http://julien.danjou.info/org-contacts.html

These are rather simple settings for it:

Set org-contacts defaults that differ from standard

(setq org-contacts-address-property "CITY")
(setq org-contacts-birthday-property "BORN")
(setq org-contacts-files "~/org/contacts.org")
(setq org-contacts-icon-property "PHOTOGRAPH")
(custom-set-variables
 '(org-contacts-files "~/org/contacts.org")
 '(org-contacts-address-property "CITY")
 '(org-contacts-birthday-property "BORN")
 '(org-contacts-icon-property "PHOTOGRAPH")
 )

Take a look at my-org-region-to-property() as well.

babel - working with source code

Activate Babel languages:

(when (my-system-type-is-windows)
  (org-babel-do-load-languages
   'org-babel-load-languages
   '(
     (python . t)
     (shell . t)
     (org . t)
     (emacs-lisp . t)
     (sql . t)
     (restclient . t)
     (plantuml . t)
     ))
  )

(when (my-system-type-is-gnu)
  (org-babel-do-load-languages
   'org-babel-load-languages
   '(
;     (ipython . t)
     (python . t)
     (ruby . t)
     (gnuplot . t)
     (shell . t)
     (org . t)
     (R . t)
     (emacs-lisp . t)
     (ditaa . t)
     (dot . t)
     (plantuml . t)
     ))
  )

Inhibit evaluation of code blocks during export http://orgmode.org/manual/Exporting-code-blocks.html

(setq org-export-babel-evaluate nil)

Do not prompt to confirm evaluation: This may be dangerous - make sure you understand the consequences of setting this – see the docstring for details

(setq org-confirm-babel-evaluate nil)

When some code generates an image file, display it in the results:

(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)

http://orgmode.org/manual/Sparse-trees.html#index-org_002dshow_002dentry_002dbelow-179

(setq org-show-entry-below (quote ((default))))

see id:2014-12-21-org-screen

(require 'org-screen)

(require 'ob-screen)
(defvar org-babel-default-header-args:screen
  '(
    (:results . "silent")
    (:session . "default")
    (:cmd . "/bin/zsh")
    (:terminal . "/usr/bin/gnome-terminal"))
  "Default arguments to use when running screen source blocks.")

http://kitchingroup.cheme.cmu.edu/blog/2014/12/21/Capturing-stderr-from-Python-in-org-mode-take-2/

  • 2016-04-08: doesn’t work
(if (my-system-type-is-gnu)
    ;; does not seem to work with Windows:
    (setq org-babel-python-command "python -i -c \"import sys; sys.stderr = sys.stdout\"")
    (setq org-babel-python-command "python")
    )

Redirect stderr to stdout in order to see it in the results: id:2015-01-11-redirect-org-babel-sh-stderr-to-stdout

(if (my-system-type-is-gnu)
  ;outdated: org-babel-sh-command was removed with org-mode v8.3:
  ;outdated;  (setq org-babel-sh-command
  ;outdated;        "~/bin/zsh_stderr_redirected_to_stdout.sh")
  ;(setq shell-file-name "~/.emacs.d/bin/zsh_stderr_redirected_to_stdout.sh");; id:2015-01-11-redirect-org-babel-sh-stderr-to-stdout
  )

re-direct stderr to stdout and add an additional line:

From: Ken Mankoff <mankoff@gmail.com>
Newsgroups: gmane.emacs.orgmode
Subject: Re: No output from babel shell src block
Date: Thu, 12 May 2016 15:36:03 -0400
Message-ID: <m237pn83x8.fsf@gmail.com>
(setq org-babel-default-header-args:sh
      '((:prologue . "exec 2>&1") (:epilogue . ":"))
      '((:epilogue . ":"))
      )

ob-async: asynchronous babel execution

https://github.com/astahlman/ob-async

  • not yet available as a package
  • [ ] re-check availability
(use-package ob-async
  :ensure t
  :config
  (add-to-list 'org-ctrl-c-ctrl-c-hook 'ob-async-org-babel-execute-src-block)
  )

PlantUML

Forget dot. :-)

PlantUML is a handy tool for drawing simple diagrams. It is part of Org-mode since 2010.

As an example, the following block gets exported as a cool diagram:

Alice -> Bob: synchronous call
Alice ->> Bob: asynchronous call
(require 'ob-plantuml)
(setq org-plantuml-jar-path (concat my-user-emacs-directory "bin/plantuml.jar")) ;; I keep the jar file in my ".emacs.d/bin"

For a maximum of editing experience and a very cool preview, you also want to install plantuml-mode:

(use-package plantuml-mode
  :load-path  (lambda () (expand-file-name (concat my-user-emacs-directory "contrib/plantuml-mode")))
  :config
  (add-to-list 'auto-mode-alist '("\\.plantuml\\'" . plantuml-mode)) ;; Enable plantuml-mode for PlantUML files
  (add-to-list
   'org-src-lang-modes '("plantuml" . plantuml))
  )
M-x plantuml-previeworder of preference: SVG, PNG, ASCII
C-c C-cpreview: renders a PlantUML diagram from the current buffer in the best supported format
C-u C-c C-cpreview in other window
C-u C-u C-c C-cpreview in other frame

org-crypt

Activate org-crypt if gpg is installed:

(when (my-eval-if-binary-or-warn "gpg")
    (require 'org-crypt)

Encrypt all entries before saving

(org-crypt-use-before-save-magic)
(setq org-tags-exclude-from-inheritance (quote ("crypt")))

GPG key to use for encryption

(setq org-crypt-key "8A614641")

encrypting whole files: http://orgmode.org/worg/org-tutorials/encrypting-files.html

(require 'epa-file)

disabling auto-save for sensitive files http://anirudhs.chaosnet.org/blog/2005.01.21.html

    (define-minor-mode sensitive-mode
      "For sensitive files like password lists.
It disables backup creation and auto saving.

With no argument, this command toggles the mode.
Non-null prefix argument turns on the mode.
Null prefix argument turns off the mode."
      ;; The initial value.
      nil
      ;; The indicator for the mode line.
      " Sensitive"
      ;; The minor mode bindings.
      nil
      (if (symbol-value sensitive-mode)
          (progn
            ;; disable backups
            (set (make-local-variable 'backup-inhibited) t)
            ;; disable auto-save
            (if auto-save-default
                (auto-save-mode -1)))
        ;;resort to default value of backup-inhibited
        (kill-local-variable 'backup-inhibited)
        ;;resort to default auto save setting
        (if auto-save-default
            (auto-save-mode 1))))
    ;; disabling auto-save for gpg file extension
    (setq auto-mode-alist
          (append '(("\\.gpg$" . sensitive-mode))
                  auto-mode-alist)
          )

Do not ask for disabling auto-save

(setq org-crypt-disable-auto-save nil)

END of org-crypt setup

)

Org-Mobile

http://orgmode.org/org.html#MobileOrg

General OrgMobile setup:

(cond ((my-system-type-is-windows)
       (setq org-directory "~/org")
       (setq org-mobile-directory "~/org/mobile-org/")
       (setq org-mobile-inbox-for-pull "~/org/inbox.org")
       )
      (t
       (setq org-directory "~/org")
       (setq org-mobile-directory "~/org/mobile-org/")
       (setq org-mobile-inbox-for-pull "~/org/inbox.org")
       )
      )

Do not generate IDs for all headings: http://orgmode.org/manual/Pushing-to-MobileOrg.html

(setq org-mobile-force-id-on-agenda-items nil)

my-mobile-org-import() → my-map i

On my Android phone, I use MobileOrg to capture stuff. Following binding brings me the most current captured items into my inbox.org:

(defun my-mobile-org-import ()
  "Imports mobile-org-data from mobile-org to inbox.org and openes inbox.org"
  (interactive "P")
  (org-mobile-pull)
  (find-file "~/org/inbox.org")
  )
(bind-key "i" (lambda ()
                         """foobar"""
                         (interactive) (my-mobile-org-import)) my-map )

Note that even though I use Orgzly to view Org-mode data on my Android phone, I use MobileOrg to capture. This might change in future, when I am able to choose whether or not single SyncThing folders gets synced on WiFi or on 4G networks (instead of all or nothing). Take a look at my feature wish report and the other issue it was referred to.

my-org-mobile-push() - pushing to org-mobile

The function generates misc files for MobileOrg.

(defun my-org-mobile-push (&optional arg)
  (interactive)
  ;; when called with universal argument (C-u), Emacs will be closed
  ;;      after pushing to files
  ;; save original agenda in temporary variable
  (setq ORIGSAVED-org-agenda-custom-commands org-agenda-custom-commands)
  ;; set agenda for MobileOrg (omit some agenda
  ;; views I do not need on my phone):
  (setq org-agenda-custom-commands
        (quote (

                ("1" "1 month"
                 ((agenda "1 month"
                          ((org-agenda-ndays 31)
                           (org-agenda-time-grid nil)
                           (org-agenda-entry-types '(:timestamp :sexp))
                           )
                          )))

                ("B" "borrowed" tags "+borrowed"
                 (
                  (org-agenda-overriding-header "borrowed or lend")
                  (org-agenda-skip-function 'tag-without-done-or-canceled)
                  ))

                ("$" "Besorgungen" tags "+Besorgung"
                 (
                  (org-agenda-overriding-header "Besorgungen")
                  (org-agenda-skip-function 'tag-without-done-or-canceled)
                  ))

                )))
  ;; generate MobileOrg export:
  (org-mobile-push)
  ;; restore previously saved agenda:
  (setq org-agenda-custom-commands
        ORIGSAVED-org-agenda-custom-commands)
  (if (equal arg '(4))
      ;; save buffers and exit emacs;; FIXXME: not working yet
      (save-buffers-kill-terminal 't)
    )
  )

MobileOrg push → my-map I

As of 2017-04, I moved from MobileOrg to Orgzly for mobile viewing data within my Org-mode data. Therefore, this function is not of any use any more:

(bind-key "I" #'my-org-mobile-push my-map)

Reference management → my-map (|)

Do read http://karl-voit.at/2015/12/26/reference-management-with-orgmode/

I do manage references to white papers and books using a self-made concept based on RefTeX and Org-mode.

If I’d start all over again, I’d take a look at org-ref which was not around yet back then.

Set my default bibliography file:

(setq reftex-default-bibliography '("~/archive/library/references.bib"))

Set citation format (no clue what I did here)

(defadvice reftex-format-citation (before eval-citation-format)
  (setq format (eval format)))

Inserting citations when using and when defining them:

(defun org-mode-reftex-setup ()
  (load-library "reftex")
  (and (buffer-file-name) (file-exists-p (buffer-file-name))
	 (progn
         ;;enable auto-revert-mode to update reftex when bibtex file changes on disk
	   (global-auto-revert-mode t)
	   (reftex-parse-all)
         ;;add a custom reftex cite format to insert links
	   (reftex-set-cite-format
	    '((?b . "[[bib:%l][%l.bib]]")
	      (?c . "[[cite:%l][%l]]")
	      (?p . "[[pdf:%l][%l.pdf]]")
	      (?a . "[[notes:%l][%l-notes.pdf]]")
	      (?s . "[[pdf:%l-self][%l-self.pdf]]")
	      (?t . "%t")
	      (?h . (concat "** %l - %t\n:PROPERTIES:\n:CREATED: "
			    "<" (substring (format-time-string (org-time-stamp-format t t)) 1 -1) ">"
			    "\n:ID: %l\n:END:\n[[bib:%l][%l.bib]]\n[[pdf:%l][%l.pdf]]\n\n*** Abstract\n\n#+BEGIN_QUOTE\n#+END_QUOTE\n\n"))
	      (?n . (concat "*** PDF Annotations: [[notes:%l][%l-notes.pdf]]\n:PROPERTIES:\n:CREATED: "
			    "<" (substring (format-time-string (org-time-stamp-format t t)) 1 -1) ">"
			    "\n:ID: %l-notes\n:END:\n\n"
			    "\#+begin_src sh :results output :eval no-export\n"
			    "${HOME}/bin/vkextract_annotations_to_orgmode_snippet.sh %l\n"
			    "#+end_src"))
	      ))))

Binding the keyboard shortcuts:

(define-key org-mode-map (kbd "C-c )") 'reftex-citation)
(define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search))
  • disabled 2015-05-14 - double code from above?
;; http://orgmode.org/worg/org-faq.html#using-reftex-in-org-mode
(defun org-mode-reftex-setup ()
  (load-library "reftex")
  (and (buffer-file-name)
       (file-exists-p (buffer-file-name))
       (reftex-parse-all))
  (define-key org-mode-map (kbd "C-c )") 'reftex-citation))

disabled 2015-05-14: see id:2015-05-14-disable-orgmode-reftex-autoload

(add-hook 'org-mode-hook 'org-mode-reftex-setup)
  • disabled 2015-05-14 - I don’t use “CHECK_NEEDED” any more
(add-hook 'org-mode-hook
          (lambda ()
            (if (member "CHECK_NEEDED" org-todo-keywords-1)
		  (org-mode-reftex-setup))))

org-mode-reftex-search ()

(defun org-mode-reftex-search ()
  ;;jump to the notes for the paper pointed to at from reftex search
  (interactive)
  (org-open-link-from-string (format "[[cite:%s]]" (reftex-citation t))))

Setup my own org-mode-reftex-setup:

  • See also: id:2015-05-14-disable-orgmode-reftex-autoload
(defun org-mode-reftex-setup ()
  (setq TeX-master t)
  (load-library "reftex")
  (and (buffer-file-name)
     (file-exists-p (buffer-file-name))
     (progn
       (reftex-parse-all)
       (reftex-set-cite-format "[[cite:%l][%l]]")))
  (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
  (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search))
(add-hook 'org-mode-hook 'org-mode-reftex-setup)

(bind-key (kbd "R") #'org-mode-reftex-setup my-map)
;; 2015-05-14: does NOT work (yet). See id:2015-05-14-disable-orgmode-reftex-autoload

Org-mode docu → my-map o

One of the benefits of Emacs is, that it comes with its complete manual. Same holds for the Org-mode. With this shortcut, I am able to navigate through the org manual instantly:

Append the Org-mode documentation from the git repository to the info-paths:

(autoload 'info "info.el")
(eval-after-load 'info
  ;;(add-to-list 'Info-additional-directory-list (concat my-user-emacs-directory "contrib/org-mode/doc/")) ;; causes "void-variable" error
  (setq Info-additional-directory-list (concat my-user-emacs-directory "contrib/org-mode/doc/"))
  )

Bind a keyboard shortcut to open the Org manual:

(bind-key (kbd "o") (lambda()
			       (interactive)
                               (info "(org)")
			       )
  my-map
  )

Reading RSS feeds

I did test importing some RSS feeds into Orgmode but the decided to stay with my usual Android RSS reader.

org-feed - aggregating RSS feeds in news.org file:

(setq org-feed-alist
      '(
  ("heise"
         "http://www.heise.de/newsticker/heise.rdf"
         "~/org/news.org" "heise")
  ("Dilbert"
         "http://feeds.feedburner.com/DilbertDailyStrip"
         "~/org/news.org" "Dilbert")
  )
      )

org-protocol-capture-html - turn HTML into Org-mode

https://github.com/alphapapa/org-protocol-capture-html

org-protocol is awesome, but browsers do a pretty poor job of turning a page’s HTML content into plain-text. However, Pandoc supports converting from HTML to org-mode, so we can use it to turn HTML into Org-mode content! It can even turn HTML tables into Org tables!

  • see: id:2016-07-10-inst-org-protocol-capture
  • I disabled the package because I do have to play around with it to make it work on my hosts.
(when (my-eval-if-binary-or-warn "pandoc")
  (use-package org-protocol-capture-html
     :load-path "~/.emacs.d/contrib/org-protocol-capture-html/"
  )
  (require 'org-protocol-capture-html)
)

org-mind-map

I found org-mind-map via an article on irreal.

At the moment, I am not planning on using it intensively. It is maybe a cool method to visualize the structure of some Org-mode files of mine for demonstration purposes for novice or non-Org-users.

(use-package org-mind-map
  ;;:ensure t
  :defer 15
  :load-path "~/.emacs.d/contrib/org-mind-map/"
  :config ;; executed after loading package
)

2017-10-14: Unfortunately, I do have issues with this tool so that I had to disable it. Maybe I’d give it another try in a couple of months or so.

debug message: config orgmode finished.

(message "→★ orgmode finished in %.2fs" (float-time (time-subtract (current-time) my-org-config-start-time)))

Misc modes/packages

Misc sources for packages:

tabbar

«Tabbar is an emacs minor mode that displays a tab bar at the top, similar to the idea of web browser’s tabs.»

I just did not think that the screen space was used wisely for the minor advantage.

(when (my-system-type-is-gnu)
    (use-package tabbar
       :load-path "~/.emacs.d/contrib/"
    )
  )

post-mode

post-mode was used for composing Usenet postings which I do in slrn since decades and not within Emacs as before.

(setq post-variable-signature-source "~/daten/nobackup/funnies/good_sigs/allsigs.txt")
(setq post-signature-directory "~/daten/nobackup/funnies/good_sigs/")

MiniMap

«Minimap is a feature provided by the Sublime editor. It shows a smaller, “minibar”, display of the current buffer alongside the main editing window.»

(use-package minimap
  :if (my-system-type-is-gnu)
  :ensure t
  :diminish minimap-mode
  :defer 10
  :config ;; executed after loading package
  (setq minimap-window-location 'right)
  ;;deactivated;; (setq minimap-window-location 'right)
  (global-set-key [f8] 'minimap-mode)
)

TWiki

TWiki syntax highlighting

;(use-package erin))
(my-load-local-el "contrib/erin.el")

Twitter

I shortly tested Emacs as a Twitter client but did not find advantages enough to use it instead of the Twitter webpage.

(add-to-list 'load-path (expand-file-name (concat my-user-emacs-directory "contrib/twittering-mode/")))
(use-package twittering-mode)
(setq twittering-timer-interval 300)  ; Update your timeline each 300 seconds (5 minutes)
(setq twittering-url-show-status nil) ; Keeps the echo area from showing all the http processes
(setq twittering-icon-mode t)         ; Show icons
(setq twittering-use-show-minibuffer-length t) ; Show character count in compose buffer
;; I added is.gd support myself, pull request sent.
;; standard options are tinyurl and toly
;(setq twittering-tinyurl-service 'is.gd)
;; See http://www.reverttoconsole.com/blog/nix/twitter-mode-for-emacs-with-oauth/
(setq twittering-use-master-password t)
;; This tells twittering-mode which time line buffers
;; to open when starting
(setq twittering-initial-timeline-spec-string
      '(":friends"
        ":replies"
        ":direct_messages"
        ":search/tugraz/"
        ":search/tagstore/"
	))
;; some key bindings
(add-hook 'twittering-mode-hook
          (lambda ()
            (mapc (lambda (pair)
                    (let ((key (car pair))
                          (func (cdr pair)))
                      (define-key twittering-mode-map
                        (read-kbd-macro key) func)))
                  '(("R" . twittering-native-retweet)
                    ("l" . twittering-goto-next-thing)))))
;; enable spell check
(add-hook 'twittering-edit-mode-hook (lambda () (ispell-minor-mode) (flyspell-mode)))
;; filter by regex  http://www.emacswiki.org/emacs/TwitteringMode -> "10 May 2011"
(setq twittering-tweet-filters '("foobar42" "foobar 23"))
(defun twittering-filter-tweets ()
  (setq non-matching-statuses '())
  (dolist (status twittering-new-tweets-statuses)
    (setq matched-tweets 0)
    (dolist (pat twittering-tweet-filters)
      (if (string-match pat (cdr (assoc 'text status)))
          (setq matched-tweets (+ 1 matched-tweets))))
    (if (= 0 matched-tweets)
        (setq non-matching-statuses (append non-matching-statuses `(,status)))))
  (setq new-statuses non-matching-statuses))
(add-hook 'twittering-new-tweets-hook 'twittering-filter-tweets)

UndoTree

Some people prefer the undo-tree visualization and method for undoing things in Emacs.

(use-package undo-tree
  :ensure t
  :diminish undo-tree-mode
  :config ;; executed after loading package
  (autoload 'undo-tree "undo-tree.el")
)

open-resource

http://code.google.com/p/emacs-open-resource/ «It uses recentf’s files buffer to provide a nice interface for selecting found files. Files are searched using the “find” utility in Unix. The results are filtered with grep for unwanted patterns and with awk to return relative paths (relative paths are shorter and thus more readable).»

(add-to-list 'load-path (expand-file-name (concat my-user-emacs-directory "contrib/emacs-open-resource-read-only")))
(use-package open-resource)
(global-set-key "\C-cr" 'open-resource)

whitespace-mode + style

https://www.emacswiki.org/emacs/WhiteSpace

«This package is a minor mode to visualize blanks (TAB, (HARD) SPACE and NEWLINE).»

  • from Twitter 2012-05-22: @emacs_knight
;;(when (or (my-system-type-is-gnu) (my-system-is-blanche))
(whitespace-mode)
(setq whitespace-style '(trailing space-before-tab indentation empty space-after-tab)) ;; only show bad whitespace
  ;;(face trailing lines-tail) whitespace-line-column 80) ;; highlight long lines tails (setq whitespace-style
;;  )

(e)diff

Visualizing differences of files.

ediff from command line usage: emacs -diff file1 file2

(when (my-eval-if-binary-or-warn "diff")
  (defun command-line-diff (switch)
    (let ((file1 (pop command-line-args-left))
  	(file2 (pop command-line-args-left)))
      ;;    (ediff file1 file2)))
      (ediff-merge-files file1 file2)))

  (add-to-list 'command-switch-alist '("diff" . command-line-diff))
)

Counting words → M-=

Counting lines, words, characters.

(use-package wc
   :load-path "~/.emacs.d/contrib/"
)

magit → my-map g + smeargle (highlighting)

«Magit is an interface to the version control system Git, implemented as an Emacs package. Magit aspires to be a complete Git porcelain. While we cannot (yet) claim that Magit wraps and improves upon each and every Git command, it is complete enough to allow even experienced Git users to perform almost all of their daily version control tasks directly from within Emacs. While many fine Git clients exist, only Magit and Git itself deserve to be called porcelains.»

Some people start using Emacs just to be able to use this nifty Git interface of Magit.

(when (my-eval-if-binary-or-warn "git")

(use-package magit
  :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
  ;;:if (or (my-system-type-is-gnu) (my-system-is-powerplantlinux))
  ;;  :bind (:map magit-status-mode-map ("q" magit-quit-session))
  :config ;; executed after loading package

  ;; full screen magit-status
  ;; http://whattheemacsd.com//setup-magit.el-01.html
  (defadvice magit-status (around magit-fullscreen activate)
    (window-configuration-to-register :magit-fullscreen)
    ad-do-it
    (delete-other-windows))

  (defun magit-quit-session ()
    "Restores the previous window configuration and kills the magit buffer"
    (interactive)
    (kill-buffer)
    (jump-to-register :magit-fullscreen))
(bind-key "g" #'magit-status my-map)
  • smeargle - Highlighting Regions by Last Updated Time (my-map c)
    • https://github.com/syohex/emacs-smeargle/
    • M-x smeargle - Highlight regions by last updated time.
    • M-x smeargle-age - Highlight regions by age of changes.
    • M-x smeargle-clear - Clear overlays in current buffer
(use-package smeargle
  :ensure t
  :defer 10
  :config ;; executed after loading package
  ;;:bind (:map my-map ("c" . smeargle)) ;; CONFLICTS with my title capitalization
)

End of use-package of magit:

)
) ;; if magit is found

Recent files

«Recentf is a minor mode that builds a list of recently opened files. This list is is automatically saved across sessions on exiting Emacs - you can then access this list through a command or the menu.»

(autoload 'recentf "recentf.el")
(recentf-mode 1)
(setq recentf-max-menu-items 50)

Confluence: vk-open-as-confluence-page() → my-map C

Editing Confluence wiki pages (up to Confluence 3.x)

Unfortunately, Altlassian moved away from a Wiki style editing mode to a WYSIWYG editor. This killed my beautiful “edit in Emacs” method:

(when (my-system-type-is-windows)

 ;(add-to-list 'load-path (expand-file-name "~/.emacs.d/contrib/confluence-el-1.5/"))
 (use-package confluence)
 (setq confluence-url "http://product.infonova.at/confluence/rpc/xmlrpc")
 (add-to-list 'auto-mode-alist '("\\.\\(confluence\\)$" . confluence-mode))

 (dolist (hook '(confluence-mode-hook))
   (add-hook hook (lambda ()
       	     (flyspell-mode 1)
       	     (ispell-change-dictionary "british")
       	     (flyspell-buffer)
       	     ))
   )

 (defun vk-open-as-confluence-page ()
   "Takes current line (delimited by brackets, two spaces or pipe) and opens it as Confluence page in IR6 space"
   (interactive)
   (save-excursion
     (re-search-backward "\\(\\] \\|  \\|\* \\|| \\)")  ;; search for "] " or "  " or "| "
     (forward-char)
     (forward-char)
     (setq start-pos (point))
     (re-search-forward "\\( \\[\\|  \\| |\\)")  ;; search for " [" or "  " or " |"
     (backward-char)
     (backward-char)
     (setq end-pos (point))
     (setq myname (buffer-substring start-pos end-pos))
       				;(message "Confluence page name: [%s]" myname)
     (confluence-get-page myname "IR6")
       				;(confluence-get-page myname)
     )
   )

  (bind-key "C" #'vk-open-as-confluence-page my-map)

)

message-outlook.el - sending mail with Outlook

(when (my-eval-if-binary-or-warn "outlook")
  (use-package message-outlook
     :load-path "~/.emacs.d/contrib/"
  )
)

Editing Outlook emails in Emacs

when (or (my-system-is-powerplantlinux) (my-system-type-is-windows))

  (use-package outlookedit
     :load-path "~/.emacs.d/contrib/"
  )
  ;;(use-package outlookedit)

(defvar mno-get-outlook-body
  "cscript //B //Job:getMessage c:/Users/karl.voit/bin/outlook_emacs.wsf")
(defvar mno-put-outlook-body
  "cscript //B //Job:putMessage c:/Users/karl.voit/bin/outlook_emacs.wsf")

;; ######################################################
;; use mail-mode for email or usenet postings:
(add-to-list 'auto-mode-alist '("\\.\\(mail\\|email\\|posting\\)$" . mail-mode))
(dolist (hook '(mail-mode-hook))
  (add-hook hook (lambda ()
            (mail-mode-auto-fill)
            (auto-fill-mode 1)
            (flyspell-mode 1)
            (ispell-change-dictionary "german8")
            (flyspell-buffer)
            ))
  )

;; http://www.emacswiki.org/emacs/MailMode
(add-hook 'mail-mode-hook
   (lambda ()
     (font-lock-add-keywords nil
       		      '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
       			 (0 'mail-multiply-quoted-text-face))
       			("^[ \t]*>[ \t]*>.*$"
       			 (0 'mail-double-quoted-text-face))))))

)

Periodically auto-save buffers

Automatically save buffers more often within certain modes:

(use-package real-auto-save)
(add-hook 'org-mode-hook 'turn-on-real-auto-save)
;; Auto save interval is 10 seconds by default. You can change it:
(when (my-system-type-is-windows)
  (setq real-auto-save-interval 10)
)
(when (my-system-type-is-gnu)
  (setq real-auto-save-interval 30)
)

spray (speed-reading region) → my-map s

A speed reading mode for Emacs.

(use-package spray
  :ensure t
  :defer 10
  :config ;; executed after loading package
  :bind (:map my-map ("s" . spray-mode))
)

yafolding - Folding based on identation → M-RET C-TAB

I do use this folding method for Python source code. It is not perfect but most of the time, it’s a good companion to me.

(use-package yafolding
  :ensure t
  :defer 10
  :mode ("\\.xml\\'" . yafolding-mode)

  :config ;; executed after loading package

  (add-to-list 'auto-mode-alist '("\\.xml$" . nxml-mode))
  ;;(add-to-list 'auto-mode-alist '("\\.xml$" . yafolding-mode))
  ;;(global-set-key (kbd "<C-S-return>") 'yafolding-toggle-all)
  ;;(global-set-key (kbd "<C-return>") 'yafolding-toggle-element)
  :bind (("<M-S-return>" . yafolding-toggle-all)
         ("<M-return>" . yafolding-toggle-element)
         ("<C-Tab>" . yafolding-toggle-element))
)

Naked full screen Emacs → my-map F12

I love to work in full-screen mode where nothing is distracting me from the information I am working with: the content of Emacs.

There are some packages out there that provide this functionality such as writeroom-mode or darkroom-mode (see discussion of them here).

The code below was written by Bastien Guerry and adopted by me to meet my requirements: https://gist.github.com/bzg/8578998

Conditions when loading:

(when (my-system-type-is-gnu)
 (defvar my-toggle-naked-emacs-status nil
   "state of fullscreen/naked Emacs mode. t means fullscreen, nil means normal")
 (make-variable-buffer-local 'my-toggle-naked-emacs-status)

 ;; See http://bzg.fr/emacs-hide-mode-line.html
 (defvar-local hidden-mode-line-mode nil)
 (defvar-local hide-mode-line nil)

 (define-minor-mode hidden-mode-line-mode
   "Minor mode to hide the mode-line in the current buffer."
   :init-value nil
   :global nil
   :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."))))

 ;; A small minor mode to use a big fringe
 (defvar bzg-big-fringe-mode nil)
 (define-minor-mode bzg-big-fringe-mode
   "Minor mode to hide the mode-line in the current buffer."
   :init-value nil
   :global t
   :variable bzg-big-fringe-mode
   :group 'editing-basics
   (if (not bzg-big-fringe-mode)
	(set-fringe-style nil)
     (set-fringe-mode
      (/ (- (frame-pixel-width)
	     (* 100 (frame-char-width)))
	  3)
      )
     ))

 ;; Command to toggle the display of the mode-line as a header
 (defvar-local header-line-format nil)
 (defun mode-line-in-header ()
   (interactive)
   (if (not header-line-format)
	(setq header-line-format mode-line-format
	      mode-line-format nil)
     (setq mode-line-format header-line-format
	    header-line-format nil))
   (set-window-buffer nil (current-buffer)))

 (defun my-toggle-naked-emacs ()
   "Toggle fullscreen/naked Emacs and normal Emacs"
   (interactive)
   (cond (my-toggle-naked-emacs-status
	   ;; make it naked!

	   (setq my-toggle-naked-emacs-status nil)
	   ;; Prevent the cursor from blinking
	   (blink-cursor-mode 0)
	   ;; Don't let Emacs hurt your ears
	   (setq visible-bell t)

	   ;; This is bound to f11 in Emacs 24.4
	   (toggle-frame-fullscreen)
	   ;; ;; Who use the bar to scroll?
	   ;; (scroll-bar-mode 0)

	   (menu-bar-mode 0)

	   ;; You can also set the initial frame parameters
	   ;; (setq initial-frame-alist
	   ;;       '((menu-bar-lines . 0)
	   ;;         (tool-bar-lines . 0)))

	   ;; Activate hidden-mode-line-mode
	   (hidden-mode-line-mode 1)

	   ;; If you want to hide the mode-line in all new buffers
	   ;; (add-hook 'after-change-major-mode-hook 'hidden-mode-line-mode)

	   ;; Alternatively, you can paint your mode-line in White but then
	   ;; you'll have to manually paint it in black again
	   ;; (custom-set-faces
	   ;;  '(mode-line-highlight ((t nil)))
	   ;;  '(mode-line ((t (:foreground "white" :background "white"))))
	   ;;  '(mode-line-inactive ((t (:background "white" :foreground "white")))))

	   ;; reset fringe with:
	   ;; (set-fringe-mode nil)

	   ;; Now activate this global minor mode
	   (bzg-big-fringe-mode 1)

	   ;; To activate the fringe by default and deactivate it when windows
	   ;; are split vertically, uncomment this:
	   ;; (add-hook 'window-configuration-change-hook
	   ;;           (lambda ()
	   ;;             (if (delq nil
	   ;;                       (let ((fw (frame-width)))
	   ;;                         (mapcar (lambda(w) (< (window-width w) fw))
	   ;;                                 (window-list))))
	   ;;                 (bzg-big-fringe-mode 0)
	   ;;               (bzg-big-fringe-mode 1))))

	   ;; Use a minimal cursor
	   ;; (setq cursor-type 'hbar)

	   ;; ;; Get rid of the indicators in the fringe
	   ;; (mapcar (lambda(fb) (set-fringe-bitmap-face fb 'org-hide))
	   ;;         fringe-bitmaps)
	   ;;
	   ;; ;; Set the color of the fringe
	   ;; (custom-set-faces
	   ;;  '(fringe ((t (:background "white")))))
	   ;;
	   ;; (custom-set-faces
	   ;;   '(default ((t (:background "black" :foreground "grey"))))
	   ;;   '(fringe ((t (:background "black")))))

	   ;;(global-set-key (kbd "C-s-SPC") 'mode-line-in-header)
	   (bind-key "h" 'mode-line-in-header my-map)

	   (message "Enjoy your concentration!")

	   )
	  (t
	   ;; normal mode
	   (setq my-toggle-naked-emacs-status t)

	   (blink-cursor-mode t)
	   (setq visible-bell nil)
	   (toggle-frame-fullscreen)
	   ;(scroll-bar-mode 1)
	   ;;(menu-bar-mode 1)
	   (hidden-mode-line-mode nil)

	   ;; If you want to hide the mode-line in all new buffers
	   ;; (add-hook 'after-change-major-mode-hook 'hidden-mode-line-mode)

	   (bzg-big-fringe-mode nil)
	   (set-fringe-mode nil)

	   (message "See everything.")
	   )
	  )
   )

map it to F12 and end condition of loading:

  (global-set-key [f12] 'my-toggle-naked-emacs)
)

browse-kill-ring → M-y

https://github.com/browse-kill-ring/browse-kill-ring

«Are you tired of using the endless keystrokes of C-y M-y M-y M-y … to get at that bit of text you killed thirty-seven kills ago? Ever wish you could just look through everything you’ve killed recently to find out if you killed that piece of text that you think you killed, but you’re not quite sure? If so, then browse-kill-ring is the Emacs extension for you.»

(use-package browse-kill-ring
   :load-path  (lambda () (expand-file-name (concat my-user-emacs-directory "contrib/")))
   ;:load-path (concat my-user-emacs-directory "contrib/")
   :config
   (browse-kill-ring-default-keybindings); map M-y to browse-kill-ring
)

;; 2017-09-05: to delete when above is working:
;;(require 'browse-kill-ring)
;;(browse-kill-ring-default-keybindings); map M-y to browse-kill-ring

pdf-mode - Edit raw PDF files in Emacs

«pdf-mode is a major mode for editing PDF files in Emacs. It’s not perfect, but it should be a good starting point. It might be useful for the poor souls who are working on generating PDF; definitely useful to me.»

2014-11-16 works at a quick test but I disable it for now since I don’t need it for now.

(use-package pdf-mode
   :load-path "~/.emacs.d/contrib/pdf-mode/"
)

guide-key - displays the available key bindings automatically

«guide-key.el displays the available key bindings automatically and dynamically. guide-key aims to be an alternative of one-key.el.»

This is great: when I do press my prefix for my-map and wait a bit, I get a popup buffer that tells me what bindings I am able to use.

(use-package guide-key
  :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
  :config ;; executed after loading package
  (setq guide-key/guide-key-sequence '("C-c C-,"))
  (guide-key-mode 1)  ; Enable guide-key-mode
)

vcard-mode

https://github.com/dochang/vcard-mode

«This package provides a major mode to edit vCard files in Emacs.»

(use-package vcard-mode
  :ensure nil ;; install package if not found OR: (setq use-package-always-ensure t)
  :load-path "contrib/vcard-mode/" ;; relative to emacs dir
  :pin manual
  :mode ("\\.vc\\(f\\|ard\\)\\'" . vcard-mode)
)

sunrise-mode - file management like midnight commander or FreeCommander

via http://www.emacswiki.org/emacs/Sunrise_Commander and GitHub

disabled 2015-08-31 since I don’t use it for now.

(use-package sunrise-commander
  :ensure nil ;; install package if not found OR: (setq use-package-always-ensure t)
  :mode ("\\.py\\'" . elpy-mode)
  ;; 3) Choose some unused extension for files to be opened in Sunrise VIRTUAL
  ;; mode and add it to `auto-mode-alist', e.g. if you want to name your virtual
  ;; directories like *.svrm just add to your .emacs file a line like the
  ;; following:
  :mode ("\\.srvm\\'" . sr-virtual-mode)
)

RAML-mode

(use-package raml-mode
   :if (my-system-type-is-windows)
   :load-path "~/.emacs.d/contrib/raml-mode/"
)

Synonyms → my-map S

(if (file-exists-p (concat my-user-emacs-directory "bin/mthes10/mthesaur.txt"))
  (use-package synonyms
    :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
    :init ;; executed before loading package
    (setq synonyms-file        (concat my-user-emacs-directory "bin/mthes10/mthesaur.txt"))
    (setq synonyms-cache-file  (concat my-user-emacs-directory "bin/vkcachefile"))
    :config
    (defun my-synonym-current-word ()
      "Lookup synonyms for current word."
      (interactive)
      (synonyms-lookup (thing-at-point 'word) nil nil))
    :bind (:map my-map ("S" . my-synonym-current-word))
  )
(message (concat "»»» I could not locate \"" my-user-emacs-directory "bin/mthes10/mthesaur.txt\""))
)

nyan-mode - Nyan Cat instead of scroll bar

«Nyan Mode is an analog indicator of your position in the buffer. The Cat should go from left to right in your mode-line, as you move your point from 0% to 100%.»

via https://www.reddit.com/r/emacs/comments/3xoins/totally_useless_and_utterly_awesome_packages/

This seems to be a bit silly but it is actually quite useful for me. I usually do work with a ninety degree tilted monitor where horizontal space is limited but vertical space not. By disabling the scroll bar for Emacs (see further above) and using the Nyan cat as a replacement for it, I can save precious horizontal space.

(use-package nyan-mode
  :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
  :config
  (nyan-mode t)
)

highlight-tail

https://melpa.org/#/highlight-tail

This minor-mode draws a tail in real time, when you write. It changes the background color of some last typed characters and smoothly fade them out to the background color.

So from now on, your Emacs will be even more sexy! ;o )

If you do not understand what I mean, check the animation: http://nic-nac-project.net/~necui/img/htshow.gif

(use-package highlight-tail
  :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
  :init
  (setq highlight-tail-colors '(("#1c1c1c" . 0)
                                ;;("#bc2525" . 25)
                                ;;("black" . 66)
                                ))
  :config
  (highlight-tail-mode)
)

anzu-mode - showing number of matches when searching

«anzu.el is an Emacs port of anzu.vim. anzu.el provides a minor mode which displays current match and total matches information in the mode-line in various search modes.»

I love this visualization.

(use-package anzu
  :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
  :diminish anzu-mode
  :config
  (global-anzu-mode +1)
)

smart-mode-line - abbreviating paths, …

«Smart Mode Line is a sexy mode-line for Emacs. It aims to be easy to read from small to large monitors by using colors, a prefix feature, and smart truncation.»

(use-package smart-mode-line
  :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
  :config
  (setq sml/no-confirm-load-theme t)
  (setq sml/theme 'respectful) ;; select theme: light, dark, respectful
  ;; hiding minor modes from mode line (don't forget the leading space)
  (setq rm-blacklist '(" Fill" " Ind" " MRev" " hl-p" " Guide" " OrgStruct" " ,"))
  ;; replacing path names with abbrevations:
  (add-to-list 'sml/replacer-regexp-list '("^~/hosts/all/config/emacs.d" ":EMACS:") t)
  (add-to-list 'sml/replacer-regexp-list '("^~/org" ":ORG:") t)
  (add-to-list 'sml/replacer-regexp-list '("^~/frankie/src/lazyblorg" ":LB:") t)
  (add-to-list 'sml/replacer-regexp-list '("^C:/Users/karl.voit/org" ":ORG:") t)
  (add-to-list 'sml/replacer-regexp-list '("^~/frankie/" "~/") t)
  (smart-mode-line-enable)
)

display-time-mode - Enable the display of time in the modeline

http://www.emacswiki.org/emacs/DisplayTime

(setq display-time-string-forms
      '((propertize (format-time-string "%A %F %R" now) 'face 'bold)))
(display-time-mode t)

dash

https://github.com/magnars/dash.el «A modern list api for Emacs. No ‘cl required.»

  • required by eno (and most probably others in future)
  • disabled because I do not use eno for now
(use-package dash
  :ensure t
  :defer 10
  )

edit-at-point

  • required by eno (and most probably others in future)
  • disabled because I do not use eno for now
(use-package edit-at-point
  :ensure t
  :defer 10
  )

eno-mode: ace-jump/easymotion provides: goto certain char in view

https://github.com/enoson/eno.el

ace-jump/easymotion provides “goto certain char in view”, which let us moving without mouse, but it’s still not efficient or intuitive enough, so I create this package to not just goto but also edit(copy,cut..) any word/symbol/string/paren/line in view by directly selecting hints, similar to ace-jump/easymotion but don’t need to enter the leading char.

(use-package eno
  :ensure t
  ;;  :diminish eno
  :defer 11
  ;;  :config ;; executed after loading package
  :bind (:map my-map ("RET" . eno-word-goto))
)

markdown-mode

via: http://ikiwiki.info/tips/Emacs_and_markdown/

(use-package markdown-mode
  :ensure t
  :if (my-system-type-is-windows)
  :defer 10
  :mode ("\\.md\\'" . markdown-mode)
)

swiper - ivy-enhanced alternative to isearch

flexible, simple tools for minibuffer completion in Emacs

This repository contains:

  1. Ivy, a generic completion mechanism for Emacs.
  2. Counsel, a collection of Ivy-enhanced versions of common Emacs commands.
  3. Swiper, an Ivy-enhanced alternative to isearch.
(use-package swiper
  :ensure t
  ;;:if (my-system-type-is-windows)
  :config

  (setq ivy-display-style 'fancy) ;; fancy highlighting

  ;;advise swiper to recenter on exit
  (defun bjm-swiper-recenter (&rest args)
    "recenter display after swiper"
    (recenter)
    )
  (when (my-system-type-is-gnu)
    (advice-add 'swiper :after #'bjm-swiper-recenter)
    )

  ;(bind-key "C-s" 'swiper)
  ;;(global-set-key "\C-s" 'swiper)
)

counsel - Ivy-enhanced versions of common Emacs commands → M-x → my-map J

flexible, simple tools for minibuffer completion in Emacs

This repository contains:

  1. Ivy, a generic completion mechanism for Emacs.
  2. Counsel, a collection of Ivy-enhanced versions of common Emacs commands.
  3. Swiper, an Ivy-enhanced alternative to isearch.
(use-package counsel
  :ensure t
  :bind (:map my-map ("J" . counsel-imenu)) ;; http://irreal.org/blog/?p=6201 jumping to buffer org-heading
  :config
  (counsel-mode 1)
)

char-menu - insert special characters → F4

«This package allows to insert arbitrary symbols in Emacs in a very efficient and straightforward way. Whether you ever need to insert only a couple of proper punctuation symbols or you’re a Unicode geek who likes all sorts of arrows and fancy math symbols, this package may be of some use.»

(use-package char-menu
  :ensure t
  ;;:defer 10
  :config
  (setq char-menu
        '("" "" "" "×" "·" "" "" "" "°" "" "" "§" "«»" "»«" "‘’" "“”" "" "©" ""
         ("Arrows"     "" "" "" "" "" "" "" "")
         ("Math"       "¬" "" "" "" "" "×" "±" "" "÷" "")
         ("Greek"      "α" "β" "Y" "δ" "ε" "ζ" "η" "θ" "ι" "κ" "λ" "μ"
          "ν" "ξ" "ο" "π" "ρ" "σ" "τ" "υ" "φ" "χ" "ψ" "ω")
         ("Hatschek"   "Ǎ" "ǎ" "Č" "č" "Ď" "ď" "Ě" "ě" "Ǧ" "ǧ" "Ȟ" "ȟ"
          "Ǐ" "ǐ" "ǰ" "Ǩ" "ǩ" "Ľ" "ľ" "Ň" "ň" "Ǒ" "ǒ" "Ř" "ř" "Š" "š" "Ť" "ť"
          "Ǔ" "ǔ" "Ǚ" "ǚ" "Ž" "ž" "Ǯ" "ǯ")
         ("Umlaute"  "ä" "ö" "ü" "Ä" "Ö" "Ü" "ß")
        ))
  (global-set-key [f4] 'char-menu)
)

helm - completion and selection narrowing

This is something that really pushes Emacs usability.

https://github.com/emacs-helm/helm

«Emacs incremental completion and selection narrowing framework https://emacs-helm.github.io/helm/»

Helm is an Emacs framework for incremental completions and narrowing selections. It helps to rapidly complete file names, buffer names, or any other Emacs interactions requiring selecting an item from a list of possible choices. Helm is a fork of anything.el, which was originally written by Tamas Patrovic and can be considered to be its successor. Helm cleans the legacy code that is leaner, modular, and unchained from constraints of backward compatibility.

(use-package helm
  :ensure t
  :defer 10
)

wttrin - Weather in Emacs → my-map w

(use-package wttrin
  :ensure t
  :commands (wttrin)
  :defer 15
  :init
  (setq wttrin-default-cities '("graz" "ebreichsdorf" "st.poelten" "schladming" "malia"))
  (cond ((my-system-is-sherri)
         (bind-key "w" '(lambda () (interactive) (wttrin-query "graz") (toggle-truncate-lines)) my-map)
         )
        ((my-system-type-is-windows)
         (bind-key "w" '(lambda () (interactive) (wttrin-query "unterpremstatten") (toggle-truncate-lines)) my-map)
          )
        (t
         (bind-key "w" '(lambda () (interactive) (wttrin) (toggle-truncate-lines)) my-map)
         )
        )
  )

git-timemachine - Step through historic versions

Step through historic versions of git controlled file using everyone’s favourite editor

Visit a git-controlled file and issue M-x git-timemachine (or bind it to a keybinding of your choice). If you just need to toggle the time machine you can use M-x git-timemachine-toggle.

Use the following keys to navigate historic version of the file

pVisit previous historic version
nVisit next historic version
wCopy the abbreviated hash of the current historic version
WCopy the full hash of the current historic version
gGoto nth revision
qExit the time machine.
bRun magit-blame on the currently visited revision (if magit available).
(when (my-eval-if-binary-or-warn "git")

  (use-package git-timemachine
    :ensure t
    :defer 15
    :init

        ;; http://blog.binchen.org/posts/new-git-timemachine-ui-based-on-ivy-mode.html -> start from selected revision instead of HEAD
        (defun my-git-timemachine-show-selected-revision ()
          "Show last (current) revision of file."
          (interactive)
          (let (collection)
            (setq collection
                  (mapcar (lambda (rev)
                            ;; re-shape list for the ivy-read
                            (cons (concat (substring (nth 0 rev) 0 7) "|" (nth 5 rev) "|" (nth 6 rev)) rev))
                          (git-timemachine--revisions)))
            (ivy-read "commits:"
                      collection
                      :action (lambda (rev)
                                (git-timemachine-show-revision rev)))))

        (defun my-git-timemachine ()
          "Open git snapshot with the selected version.  Based on ivy-mode."
          (interactive)
          (unless (featurep 'git-timemachine)
            (require 'git-timemachine))
          (git-timemachine--start #'my-git-timemachine-show-selected-revision))

        )
)

pandoc-mode - An Emacs minor mode for interacting with Pandoc

Cool package but I don’t need it at the moment. Therefore disabled.

(when (my-eval-if-binary-or-warn "pandoc")
  (use-package pandoc-mode
    :ensure t
    :defer 10
  )
)

bm - visible bookmarks → my-map 8|9|0

https://github.com/joodland/bm

This package provides visible, buffer local, bookmarks and the ability to jump forward and backward to the next bookmark.

It was created because I missed the bookmarks from M$ Visual Studio in GNU Emacs. I think they provide an easy way to navigate in a buffer.

Features:

  • Auto remove bookmark after jump to it by bm-next or bm-previous:
  • Cycle through bookmarks in all open buffers in LIFO order
  • Toggle bookmarks. Jump to next/previous bookmark.
  • Setting bookmarks based on a regexp. (Useful when searching logfiles.)
  • Mouse navigation.
  • Annotate bookmarks.
  • Different wrapping modes.
  • Different bookmarks styles, line-only, fringe-only or both.
  • Persistent bookmarks (buffer local), also in non-file buffers (info) and indirect buffers.
  • List bookmarks (in all buffers) in a separate buffer.
  • Cycle through bookmarks in all open buffers.

via: http://pragmaticemacs.com/emacs/use-visible-bookmarks-to-quickly-jump-around-a-file/

(use-package bm
  :ensure t
  :defer 5
  :bind (:map my-map ("8" . bm-toggle))
  :bind (:map my-map ("9" . bm-previous))
  :bind (:map my-map ("0" . bm-next))
  )

adoc-mode - asciidoc mode

https://github.com/sensorflo/adoc-mode/wiki

AsciiDoc is a text document format for writing short documents, articles, books and UNIX man pages. AsciiDoc files can be translated to HTML and DocBook markups.

adoc-mode is an Emacs major mode for editing AsciiDoc files. It emphasizes on the idea that the document is highlighted so it pretty much looks like the final output. What must be bold is bold, what must be italic is italic etc. Meta characters are naturally still visible, but in a faint way, so they can be easily ignored.

(use-package adoc-mode
  :ensure t
  :defer 5
  :config
  (add-to-list
   'auto-mode-alist (cons "\\.adoc\\'" 'adoc-mode))
  )

suggest - suggest Elisp for given input and output

Oh, this is really cool: http://www.wilfred.me.uk/blog/2016/07/30/example-driven-development/

  • “Hey $COLLEAGUE, is there any function that takes this list and returns a list like this?”

Just read the web page - it’s hard to explain otherwise.

Disabled for now until I want to impress someone using my Emacs power ;-)

M-x suggest

I ran into “suggest–possibilities: Symbol’s value as variable is void: it” when C-c C-c: See id:2016-08-04-suggest

(use-package suggest
  :ensure t
  :defer 5
  )

move-text - move line up/down → M-, | M-.

«MoveText is extracted from Basic edit toolkit. It allows you to move the current line using M-up / M-down (or any other bindings you choose) if a region is marked, it will move the region instead.»

I don’t use it for now. Maybe after I got the requirement more often and memorize the commands.

(use-package move-text
   :load-path "~/.emacs.d/contrib/move-text/"
   :config
   (global-set-key (kbd "M-,")          'move-text-up)
   (global-set-key (kbd "M-.")          'move-text-down)
)
;; (require 'move-text)
;; (move-text-default-bindings)

command-log-mode → my-map k

2017-06-01: package was unavailable → disabled for now since I don’t use it anyway.

https://github.com/lewang/command-log-mode - «Show event history and command history of some or all buffers.»

Used in screencast video: https://www.reddit.com/r/emacs/comments/4yhfn6/emacs_screencast_acelink_swiper_lispy_and_macros/

To see the log buffer, call M-x clm/open-command-log-buffer.

The key strokes in the log are decorated with ISO9601 timestamps on the property `:time’ so if you want to convert the log for screencasting purposes you could use the time stamp as a key into the video beginning.

How to use:

  1. M-x command-log-mode
  2. my-map k
(use-package command-log-mode
  :ensure t
  :defer 10
  :diminish command-log-mode
  :config ;; executed after loading package
  (add-hook 'LaTeX-mode-hook 'command-log-mode)
  (bind-key "k" #'clm/open-command-log-buffer my-map)
)

A test for starting the mode probably together with the command-log-buffer:

(defun my-start-command-log-mode()
  "load the command-log mode and start it."
  (interactive "*")
  ;; M-x clm/open-command-log-buffer
  (clm/open-command-log-buffer)
)

scss-mode

https://github.com/antonj/scss-mode - «Major mode for editing SCSS files in Emacs.»

Command line utility sass is required, see http://sass-lang.com/

To install sass (haml): gem install haml

Also make sure sass location is in emacs PATH, example: (setq exec-path (cons (expand-file-name "~/.gem/ruby/1.8/bin") exec-path)) or =customize `scss-sass-command’= to point to your sass executable.

(when (my-eval-if-binary-or-warn "sass")
  (use-package scss-mode
    ;;:if (my-system-is-floyd-or-sherri)
    :ensure t
    :defer 10
    :config
    (autoload 'scss-mode "scss-mode")
    (add-to-list 'auto-mode-alist '("\\.scss\\'" . scss-mode))
    )
)

json-mode

(use-package json-mode
  :if (my-system-type-is-windows)
  :ensure t
  :defer 10
)

mode-icons - Show icons instead of mode names

https://github.com/ryuslash/mode-icons

via: https://www.reddit.com/r/emacs/comments/5fjri7/how_to_use_git_logo_in_modeline_instead_of/

This enhances the style of Emacs IMHO.

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

unicode-fonts - Configure Unicode fonts

https://github.com/rolandwalker/unicode-fonts

  • solved an issue where a host was using different-height-sized font for few special characters
  • see id:2016-08-19-unicode-enlarges-line-height
(use-package unicode-fonts
  :ensure t
  :if (my-system-is-floyd)
  :defer 10
  :config
  (unicode-fonts-setup)
)

goto-chg - visit places of previous changes in current buffer → F5|F6

(use-package goto-chg
   :load-path "~/.emacs.d/contrib//"
   :config
   (global-set-key [f2] 'goto-last-change)
   (global-set-key [f3] 'goto-last-change-reverse)
)

;(require 'goto-chg)

highlight-symbol → my-map h

This package does highlight all occurrences of a given word. Very handy when programming: visualize all occurrences of a variable/function.

(use-package highlight-symbol
  :ensure t
  :defer 10
  ;;(bind-key (kbd "h") #'highlight-symbol my-map)
  :bind (:map my-map ("h" . highlight-symbol))
  )
;; original: (global-set-key [(control f3)] 'highlight-symbol)
;; original: (global-set-key [f3] 'highlight-symbol-next)
;; original: (global-set-key [(shift f3)] 'highlight-symbol-prev)
;; original: (global-set-key [(meta f3)] 'highlight-symbol-query-replace)

restclient

GitHub - pashky/restclient.el: HTTP REST client tool for emacs

The restclient here is particular handy when it is combined with the Org-mode: see use of ob-restclient.el within the Org-mode headings.

This way, I am able to write REST requests right beneath my Org-mode documentation. The REST answers are added there as well. This tool also allows for using variables. More flexibility is almost impossible. ;-)

(use-package restclient
  :ensure t ;; install package if not found OR: (setq use-package-always-ensure t)
  :defer 10
  :if (my-system-type-is-windows)
  :init ;; executed before loading package
  (use-package json-reformat
     :load-path "~/.emacs.d/2del/restclient/"
     )
  ;; :mode "\\.rb\\'"
)

neotree → F9

NeoTree offers a file tree side-panel like NerdTree for Vim.

installed on 2015-03-22

(use-package neotree
  :ensure t
  :defer 20
  :config ;; executed after loading package
  (global-set-key [f9] 'neotree-toggle)
)

hydra

(use-package hydra
  :ensure t
  :defer 10
  :config ;; executed after loading package

  ;; from hydra-examples.el vvvvvvvvvvvvvvvvvvvvvvvvvvvv

  ;;** Example 7: toggle with Ruby-style docstring
  (defvar whitespace-mode nil)
  (defhydra hydra-toggle (:color pink)
    "
  _f_ auto-fill-mode:    %`auto-fill-function
  _t_ truncate-lines:    %`truncate-lines
  _w_ whitespace-mode:   %`whitespace-mode
  _l_ org link display:  %`org-descriptive-links
  _a_ abbrev-mode:       %`abbrev-mode
  _d_ debug-on-error:    %`debug-on-error
  "
    ("a" abbrev-mode nil)
    ("d" toggle-debug-on-error nil)
    ("f" auto-fill-mode nil)
    ("t" toggle-truncate-lines nil)
    ("w" whitespace-mode nil)
    ("l" org-toggle-link-display nil)
    ("q" nil "quit"))
  ;; Recommended binding:
  ;;(global-set-key (kbd "C-c C-v") 'hydra-toggle/body)
  (bind-key "M" #'hydra-toggle/body my-map)

  ;;** Example 9: s-expressions in the docstring
  ;; You can inline s-expresssions into the docstring like this:
  (defvar dired-mode-map)
  (declare-function dired-mark "dired")
  (when (bound-and-true-p hydra-examples-verbatim)
    (require 'dired)
    (defhydra hydra-marked-items (dired-mode-map "")
      "
  Number of marked items: %(length (dired-get-marked-files))
  "
      ("m" dired-mark "mark")))

  ;;** Example 10: apropos family
  (defhydra hydra-apropos (:color blue
                           :hint nil)
    "
  _a_propos        _c_ommand
  _d_ocumentation  _l_ibrary
  _v_ariable       _u_ser-option
  ^ ^       valu_e_"
    ("a" apropos)
    ("d" apropos-documentation)
    ("v" apropos-variable)
    ("c" apropos-command)
    ("l" apropos-library)
    ("u" apropos-user-option)
    ("e" apropos-value))
  ;; Recommended binding:
  (global-set-key (kbd "C-c h") 'hydra-apropos/body)

  ;;** Example 11: rectangle-mark-mode
  (require 'rect)
  (defhydra hydra-rectangle (:body-pre (rectangle-mark-mode 1)
                             :color pink
                             :post (deactivate-mark))
    "
    ^_k_^     _d_elete    _s_tring
  _h_   _l_   _o_k        _y_ank
    ^_j_^     _n_ew-copy  _r_eset
  ^^^^        _e_xchange  _u_ndo
  ^^^^        ^ ^         _p_aste
  "
    ("h" rectangle-backward-char nil)
    ("l" rectangle-forward-char nil)
    ("k" rectangle-previous-line nil)
    ("j" rectangle-next-line nil)
    ("e" hydra-ex-point-mark nil)
    ("n" copy-rectangle-as-kill nil)
    ("d" delete-rectangle nil)
    ("r" (if (region-active-p)
             (deactivate-mark)
           (rectangle-mark-mode 1)) nil)
    ("y" yank-rectangle nil)
    ("u" undo nil)
    ("s" string-rectangle nil)
    ("p" kill-rectangle nil)
    ("o" nil nil))
    ;; Recommended binding:
  (global-set-key (kbd "C-x SPC") 'hydra-rectangle/body)

  ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

)

My helper functions (part II)

Here I defined some functions I am using interactively and probably map to keys in the next section.

Optimizing search methods

My Org-mode files got big and numerous. I maintain roughly a third million lines of Org-mode within my files. This has an enormous performance impact on certain operations.

For searching within my Emacs files, I do use more sophisticated methods than isearch if possible. On operating systems that provide a decent shell environment, I use grep or git grep or ag.

helm-do-grep-ag: grep within files → my-map G

This is for using ag, the silver searcher:

Preconfigured helm for grepping with AG in `default-directory’.

(when (my-eval-if-binary-or-warn "ag")
  (bind-key "G" #'helm-do-grep-ag my-map)
)

my-search-method-according-to-numlines() → C-s

Choose the best/fastest search method depending on the maximum number of lines of the current buffer.

Read http://karl-voit.at/2016/04/09/chosing-emacs-search-method/ for the whole story.

(defun my-search-method-according-to-numlines ()
  (interactive)
  (if (and (buffer-file-name)
           (not (my-system-type-is-windows))
           (not (ignore-errors
                  (file-remote-p (buffer-file-name))))
           (if (eq major-mode 'org-mode)
               (> (buffer-size) 60000)
             (> (buffer-size) 300000)))
      (progn
        (save-buffer)
        (counsel-grep))
    (if (my-system-type-is-windows)
        (isearch-forward)
      (swiper--ivy (swiper--candidates))
      )
    ))

(global-set-key "\C-s" 'my-search-method-according-to-numlines)
;;(global-set-key "\C-s" 'isearch-forward)

PREVIOUS (simple) approach:

(defun my-search-method-according-to-numlines ()
  "Determines the number of lines of current buffer and chooses a search method accordingly"
  (interactive)
  (if (< (count-lines (point-min) (point-max)) 20000)
      (swiper)
    (isearch-forward)
    )
  )
;;fancy search:  (global-set-key "\C-s" 'swiper)
;;normal search: (global-set-key "\C-s" 'isearch-forward)

On 2017-06-17, I stubled over an even more sophisticated setup for deciding on a search tool: https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-ivy.el

my-toggle-beginner-setup() → F1

When I am working with Emacs, I do not use the menu bar nor the icon bar, for example. Those things got hidden in my configuration.

However, when I teach Emacs to people not familiar with the vast amount of customizations, I use the following functions to toggle my setup to look like a default Emacs.

(defvar my-toggle-beginner-setup-status nil
  "state of Emacs setup which is least confusing for beginners. t means beginner, nil means normal")
;;(make-variable-buffer-local 'my-toggle-beginner-setup-status)

(defun my-emacs-normal-setup ()
  "Hide things for my normal usage"
  (interactive)
  (if (functionp 'tool-bar-mode) (tool-bar-mode -1)) ;; hide icons
  (menu-bar-mode 0) ;; hide menu-bar
  (when (not (my-system-is-karl-voit-at))
    (scroll-bar-mode 0) ;; hide scroll-bar, I do have Nyan-mode instead!
    )
  (setq debug-on-quit t);; show debug information on canceling endless loops and so forth

  (org-expiry-insinuate)
  (setq org-log-into-drawer t)
  (org-bullets-mode 1)

  ;; http://www.emacswiki.org/emacs/sylecn
  ;;show nothing in *scratch* when started
  (setq initial-scratch-message nil)

  ;; ######################################################
  ;; handle CamelCaseParts as distinct words
  ;; http://ergoemacs.org/emacs/emacs_adv_tips.html
  ;; disabled 2017-10-10: not that useful ;; (global-subword-mode 1) ; 1 for on, 0 for off
  ;; https://www.gnu.org/software/emacs/manual/html_node/ccmode/Subword-Movement.html
  ;; FIXXME: this is a test for getting it work independent of
  ;; CamelCase words

  ;;(setq org-hide-leading-stars t)

  (load-theme 'wombat t) ;; dark theme

)

(defun my-emacs-beginner-setup ()
  "Make things nice for beginners"
  (interactive)
  (tool-bar-mode) ;; show icons
  (menu-bar-mode) ;; show menu-bar
  (scroll-bar-mode 1) ;; show scroll-bar
  (setq debug-on-quit nil);; no debug information on canceling endless loops and so forth

  ;; http://www.emacswiki.org/emacs/sylecn
  ;;show nothing in *scratch* when started
  (setq initial-scratch-message ";; This buffer is for notes you don't want to save\n;; If you want to create a file, visit that file with C-x C-f,\n;; then enter the text in that file's own buffer.\n\n")

  ;; http://ergoemacs.org/emacs/emacs_adv_tips.html
  ;; disabled 2017-10-10: not that useful ;; (global-subword-mode 0) ; 1 for on, 0 for off
  ;; https://www.gnu.org/software/emacs/manual/html_node/ccmode/Subword-Movement.html
  ;; FIXXME: this is a test for getting it work independent of CamelCase words

  ;;(setq org-hide-leading-stars nil)

  (org-bullets-mode 0)
  (org-expiry-deinsinuate);; omit automatically created drawers
  (setq org-log-into-drawer nil)

  (disable-theme 'wombat)

  ;; http://stackoverflow.com/questions/24684979/how-to-add-a-tool-bar-button-in-emacs
  ;;(add-hook 'after-init-hook
  ;;          (lambda ()
  ;;            (define-key global-map [tool-bar pdf-button]
  ;;              '(menu-item "Export to PDF" org-latex-export-to-pdf
  ;;                          :image (image :type png :file "~/.emacs.d/bin/icon_PDF_16x16.png")
  ;;                          ))))
  (define-key global-map [tool-bar pdf-button]
    '(menu-item "Export to PDF" org-latex-export-to-pdf
                :image (image :type png :file (concat my-user-emacs-directory "bin/icon_PDF_16x16.png"))
                ))
)


(my-emacs-normal-setup)

(defun my-toggle-beginner-setup ()
  "Toggle Emacs beginner setup and normal Emacs"
  (interactive)
  (cond (my-toggle-beginner-setup-status
         ;; normal mode
         (my-emacs-normal-setup)
         (message "As you please")
         (setq my-toggle-beginner-setup-status nil)
         )
        (t
         ;; make it easy for beginners
         (my-emacs-beginner-setup)
         (message "Welcome to Emacs!")
         (setq my-toggle-beginner-setup-status t)
         )
        )
  )

(global-set-key [f1] 'my-toggle-beginner-setup)

my-toggle-dark-bright-theme() → S-F1

Some times, I do have to switch from my default dark theme to a bright one in order to get a decent result for a projector or similar.

(defvar my-toggle-dark-bright-theme-status t
  "Toggle between dark emacs theme and bright emacs theme; nil means dark theme, t means bright theme")

(defun my-toggle-dark-bright-theme ()
  "Toggle between dark emacs theme and bright emacs theme"
  (interactive)
  (cond (my-toggle-dark-bright-theme-status
         (message "Loading bright theme")
         (disable-theme 'wombat)
         (setq my-toggle-dark-bright-theme-status nil)
         )
        (t
         (message "Loading dark theme")
         (load-theme 'wombat t) ;; dark theme
         (setq my-toggle-dark-bright-theme-status t)
         )
        )
  )

(global-set-key [(shift f1)] 'my-toggle-dark-bright-theme)

my-toggle-windows-split() - Toggle between split windows and a single window

http://thornydev.blogspot.co.at/2012/08/happiness-is-emacs-trifecta.html

(defun my-toggle-windows-split()
  "Switch back and forth between one window and whatever split of
windows we might have in the frame. The idea is to maximize the
current buffer, while being able to go back to the previous split
of windows in the frame simply by calling this command again."
  (interactive)
  (if (not (window-minibuffer-p (selected-window)))
      (progn
        (if (< 1 (count-windows))
            (progn
              (window-configuration-to-register ?u)
              (delete-other-windows))
          (jump-to-register ?u))))
                                        ;(my-iswitchb-close)
  )

Inserting time-stamps → my-map [dDtT]

Org-mode has some built-in methods to create active and inactive time-stamps. The following functions offer a shortcut to insert the current day as an Org-mode time-stamp when I am within an Org-mode buffer and in ISO 8601 format when I am in another major mode.

;; Insert immediate timestamp
(defun my-insert-timestamp()
  "Insert the current time in yyyy-mm-dd format."
  (interactive "*")
  (if (eq major-mode 'org-mode)
      (progn
	(org-insert-time-stamp nil t nil)
	(insert " ")
	)
    (insert (format-time-string "%Y-%m-%d" (current-time)))
    )
  )

(bind-key "t" #'my-insert-timestamp my-map)
(defun my-insert-timestamp-inactive()
  "Insert the current time in yyyy-mm-dd format."
  (interactive "*")
  (if (eq major-mode 'org-mode)
      (progn
	(org-insert-time-stamp nil t t)
	(insert " ")
	)
    (insert (format-time-string "%Y-%m-%d" (current-time)))
    )
  )

(bind-key "T" #'my-insert-timestamp-inactive my-map)
(defun my-insert-datestamp()
  "Insert the current date in yyyy-mm-dd format."
  (interactive "*")
  (if (eq major-mode 'org-mode)
      (progn
	(org-insert-time-stamp nil nil nil)
	(insert " ")
	)
    (insert (format-time-string "%Y-%m-%d" (current-time)))
    )
  )

(bind-key "d" #'my-insert-datestamp my-map)
(defun my-insert-datestamp-inactive()
  "Insert the current date in yyyy-mm-dd format."
  (interactive "*")
  (if (eq major-mode 'org-mode)
      (progn
	(org-insert-time-stamp nil nil t)
	(insert " ")
	)
    (insert (format-time-string "%Y-%m-%d" (current-time)))
    )
  )

(bind-key "D" #'my-insert-datestamp-inactive my-map)

my-sparse-tree-with-tag-filter() - ask for a tag and filter open Org-tasks → my-map F

The code asks for one or more tags and derives a sparse tree with all related open headings.

See: id:2014-11-02-filter-org-tasks-by-tag

(defun my-sparse-tree-with-tag-filter()
  "asks for a tag and generates sparse tree for all open tasks in current Org buffer
  that are associated with this tag"
  (interactive "*")
  (setq tag-for-filter
        (org-trim
         (org-icompleting-read "Tags: "
                               'org-tags-completion-function
                               nil nil nil 'org-tags-history))
        )
  (org-occur
   (concat "^\\*+ \\(NEXT\\|TODO\\|WAITING\\|STARTED\\) .+:"
           tag-for-filter
           ":")
   )
  )
(bind-key "F" #'my-sparse-tree-with-tag-filter my-map)

xml-pretty-print-region(…)

http://stackoverflow.com/questions/12492/pretty-printing-xml-files-on-emacs

(defun xml-pretty-print-region (begin end)
  "Pretty format XML markup in region. You need to have nxml-mode
http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
this.  The function inserts linebreaks to separate tags that have
nothing but whitespace between them.  It then indents the markup
by using nxml's indentation rules."
  (interactive "r")
  (save-excursion
    (nxml-mode)
    (goto-char begin)
    (while (search-forward-regexp "\>[ \\t]*\<" nil t)
      (backward-char) (insert "\n"))
    (indent-region begin end))
  (message "Ah, much better!"))

my-xml-pretty-print() - for the whole buffer

(defun my-xml-pretty-print()
  "mark whole buffer and call xml-pretty-print-region"
  (interactive)
  (mark-whole-buffer)
  (xml-pretty-print-region);; FIXXME: provide (begin end)
  )

OS X: mdfind (find via spotlight)

Code of this heading does provide access to the macOS spotlight search engine for Emacs. I did not use it quite often, as long as I was using macOS on my computers.

http://blog.zenspider.com/2007/03/locate-and-spotlight.html

(when (my-system-type-is-darwin)
  (defun locate-make-mdfind-command-line (search-string)
    (list "mdfind" (concat "kMDItemDisplayName=*" search-string "*")))
  (defun spotlight ()
    "Search for files by name using spotlight"
    (interactive)
    (let ((locate-command "mdfind")
	  (locate-make-command-line 'locate-make-mdfind-command-line))
      (call-interactively 'locate nil)))
  (defun spotlight-full ()
    "Search using spotlight"
    (interactive)
    (let ((locate-command "mdfind"))
      (call-interactively 'locate nil)))
  )

my-codenav-*: Code navigation → M-i | M-k

I found very handy navigation commands on Code Navigation in Emacs which I included here:

(defun my-codenav-imenu-candidates ()
  "Get the candidates list from imenu."
  (let* ((items (imenu--make-index-alist))
	 (items (delete (assoc "*Rescan*" items) items)))
    items))


(defun my-codenav-flatten-candidates (candidates)
  "Flatten CANDIDATES of imenu list."
  (let (result)
    (dolist (candidate candidates result)
      (if (imenu--subalist-p candidate)
          (setq result (append result (my-codenav-flatten-candidates (cdr candidate))))
        (add-to-list 'result candidate)))
    result))


(defun my-codenav-sort-candidates (candidates)
  (sort candidates (lambda (a b) (< (cdr a) (cdr b)))))


(defun my-codenav-current-symbol (names-and-pos)
  "Figure out current definition by checking positions of NAMES-AND-POS against current position."
  (let ((list-length (length names-and-pos))
        (current-pos (point))
        (current-index 0)
        (next-index 0))
    (dolist (symbol names-and-pos)
      ;; If we reaches the end, just return the last element
      ;; instead of returning index+1
      (setq next-index (if (< next-index (1- list-length))
                          (1+ current-index)
                         current-index))
      (let* ((current-symbol-pos (marker-position (cdr symbol)))
	     (next-symbol-pos (marker-position (cdr (nth next-index names-and-pos)))))
        (if (and (= current-index 0) (< current-pos current-symbol-pos))
            (return 0))
	(if (and (>= current-pos current-symbol-pos) (< current-pos next-symbol-pos))
	    (return current-index)))
      (setq current-index (1+ current-index)))
    ;; If last item, decrement index
    (if (eq current-index (length names-and-pos))
	(1- current-index)
      current-index)))

(defun my-codenav-next-definition ()
  "Navigate to next function/class definition."
  (interactive)
  (let* ((imenu-candidates (my-codenav-imenu-candidates))
         (names-and-pos (my-codenav-sort-candidates (my-codenav-flatten-candidates imenu-candidates)))
	 (current-symbol (my-codenav-current-symbol names-and-pos))
         (next-symbol-index (if (>= (1+ current-symbol) (length names-and-pos)) 0
                              (1+ current-symbol)))
	 (next-symbol (nth next-symbol-index names-and-pos)))
    (imenu next-symbol)))


(defun my-codenav-prev-definition ()
  "Navigate to previous function/class definition."
  (interactive)
  (let* ((imenu-candidates (my-codenav-imenu-candidates))
         (names-and-pos (my-codenav-sort-candidates (my-codenav-flatten-candidates imenu-candidates)))
	 (current-symbol (my-codenav-current-symbol names-and-pos))
         (prev-symbol-index (if (< (1- current-symbol) 0) (1- (length names-and-pos))
                              (1- current-symbol)))
	 (prev-symbol (nth prev-symbol-index names-and-pos)))
    (imenu prev-symbol)))

(global-set-key (kbd "M-i") (lambda () (interactive) (my-codenav-prev-definition)))
(global-set-key (kbd "M-k") (lambda () (interactive) (my-codenav-next-definition)))

Key bindings

In this heading, I do define many key bindings.

my-map, the ressurection → C-c C-,

=C-c ,= is defined by Org-mode and must be re-defined here, after Org-mode has messed it up:

(There might be a better way but this is my current workaround.)

(global-set-key (kbd "C-c C-,") 'my-map)
(global-set-key (kbd "C-c ,") 'my-map)

general navigation keys: Home, End, forward/backward word, scrolling

Home/End should behave like everywhere else:

(global-set-key [home] 'beginning-of-buffer)
(global-set-key [end]  'end-of-buffer)

Move back/forward word is essential to me:

(global-set-key [C-left] 'backward-word)
(global-set-key [C-right] 'forward-word)

2016-03-23: PageUp/Down (instead of line up/down) for keyboards without PgUp/Dn-keys:

(global-set-key (kbd "C-p") 'scroll-down-command)
(global-set-key (kbd "C-n") 'scroll-up-command)

I tried some of those but they did not stick:

;; https://www.reddit.com/r/emacs/comments/445w6s/whats_some_small_thing_in_your_dotemacs_that_you/czntjs2
;;(global-set-key (kbd "C-, l")          'avy-goto-line)
;;(global-set-key (kbd "C-, w")          'avy-goto-word-0)
;;(global-set-key (kbd "C-, .")          'winner-redo)
;;(global-set-key (kbd "C-, m")          'winner-undo)
;;(global-set-key (kbd "C-, w")          'ace-window)
;;(global-set-key (kbd "C-, s")          'workspace-goto)
;;(global-set-key (kbd "C-, ]")          'evil-jump-to-tag)
;;(global-set-key (kbd "C-, n")          'neotree-toggle)

C-f jumps 5 lines:

(global-set-key (kbd "C-f") '(lambda () (interactive) (forward-line 5)))

boxquote → my-map [qQ]

Box quote does something like this:

,----
| This is an example.
`----
(bind-key "q" #'boxquote-region my-map)
(bind-key "Q" #'boxquote-title my-map)

switching lines → my-map <up/down>

http://whattheemacsd.com//editing-defuns.el-02.html

Swapping two lines:

(defun my-move-line-down ()
  (interactive)
  (let ((col (current-column)))
    (save-excursion
      (forward-line)
      (transpose-lines 1))
    (forward-line)
    (move-to-column col)))

(defun my-move-line-up ()
  (interactive)
  (let ((col (current-column)))
    (save-excursion
      (forward-line)
      (transpose-lines -1))
    (move-to-column col)))

(bind-key (kbd "<up>") #'my-move-line-up my-map)
(bind-key (kbd "<down>") #'my-move-line-down my-map)

joining lines → my-map j

Joining the current line with the next one: http://whattheemacsd.com//key-bindings.el-03.html

(bind-key "j"
  (lambda ()
    (interactive)
    (join-line -1))
  my-map
)

web-jump → my-map w

«WebJump is a programmable Web hotlist (or bookmark) facility that uses Emacs completion to select a hotlist item and can prompt for query and option parameters.»

(require 'webjump)
(bind-key "w" #'webjump my-map)
(setq webjump-sites ;(append   ;; append instead of overwrite
      '(
	;; ------------------------------------------------------------------
	("Emacs Lisp List" . "anc.ed.ac.uk/~stephen/emacs/ell.html")
	("Ohio State Emacs Lisp Archive" .
	 [simple-query "www.cis.ohio-state.edu/emacs-lisp/"
		       "neutral.verbum.org/search?q=" "&archive=archive"])
	("PGP Key Server" .
	 [simple-query "pgp.mit.edu"
		       "pgp.mit.edu:11371/pks/lookup?op=index&search=" ""])
	;; my own jumps
	("Org-mode docu" . "http://orgmode.org/org.html")
	("Org-mode mailinglist" .
	 [simple-query "orgmode.org"
		       "http://search.gmane.org/?group=gmane.emacs.orgmode&query=" ""])
	("Debian Bug Number" .
	 [simple-query "www.debian.org/Bugs/"
		       "bugs.debian.org/cgi-bin/bugreport.cgi?bug="
		       ""])
	("EmacsWiki" .
	 [simple-query "www.emacswiki.org/cgi-bin/wiki.pl"
		       "www.emacswiki.org/cgi-bin/wiki.pl?search="
		       "&dosearch=1"])
	("Google" .
	 [simple-query "www.google.at" "www.google.at/search?q=" ""])
	("IMDB" .
	 [simple-query "www.imdb.com" "www.imdb.com/Find?select=All&for=" ""])
	;; ------------------------------------------------------------------
	) webjump-sample-sites ;)  ;; append instead of overwrite
	  )

Show recently files → my-map r

Show a dialog to open a recent file.

(bind-key "r" #'recentf-open-files my-map)

Outlook: edit/save message → my-map oe|os

Some interaction with Outlook:

(when (my-eval-if-binary-or-warn "outlook")
  (bind-key "oe" #'mno-edit-outlook-message my-map)
  (bind-key "os" #'mno-save-outlook-message my-map)
  )

org-mark-ring-goto() → my-map <left>

Jump to the previous position in the mark ring.

(bind-key (kbd "<left>") #'org-mark-ring-goto my-map)

open this config.org file → my-map .

Very handy to modify my config file: open it ;-)

(bind-key (kbd ".") (lambda()  ;; open main.el
			       (interactive)
			       (find-file (concat my-user-emacs-directory "config.org"))
			       )
          my-map
          )

open my org-mode teaser → my-map O

I’ve written an org-mode teaser file which can be found on https://github.com/novoid/org-mode-workshop

With this keyboard shortcut, I am able to quickly open the teaser file.

(bind-key (kbd "O") (lambda()
			       (interactive)
                               (when (my-system-type-is-gnu)
                                 (find-file
                               "~/src/org-mode-workshop/featureshow/org-mode-teaser.org")
                                 )
                               (when (my-system-type-is-windows)
                                 (find-file
                               "c:/Users/karl.voit/src/org-mode-workshop/featureshow/org-mode-teaser.org")
                                 )
			       )
          my-map
  )

OrgStruct folding

Until 2017-05, I was using the Orgstruct minor mode for navigating through my Emacs config file. With migrating my old main.el to this config.org, the Orgstruct mode got obsolete for me.

Following commands offer a better usability for folding and unfolding in OrgStruct mode:

2015-11-10 deactivated:

(bind-key "[" (lambda () (interactive) (org-cycle t)) my-map)
(bind-key "]" (lambda () (interactive) (org-cycle)) my-map)

my-fix-drawer-order() → my-map C

I once noticed broken PROPERTIES drawers because of a bug in the Org-mode version I was using back then. Unfortunately, it messed up my drawers unnoticed for some time. For fixing the most common stuff, I created a macro and stored it here.

It searches for :END: followed by :PROPERTIES: (assuming first drawer is :LOGBOOK: and toggles order of them:

(fset 'my-fix-drawer-order
   (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([19 58 69 78 68 58 17 10 58 80 82 79 80 69 82 84 73 69 83 58 return 1 67108896 19 58 69 78 68 58 5 23 18 58 76 79 71 66 79 79 75 58 return 25 return down] 0 "%d")) arg)))
(bind-key "C" #'my-fix-drawer-order my-map)

hippie-expand → M-/

«HippieExpand looks at the word before point and tries to expand it in various ways including expanding from a fixed list (like `‘expand-abbrev’’), expanding from matching text found in a buffer (like `‘dabbrev-expand’’) or expanding in ways defined by your own functions. Which of these it tries and in what order is controlled by a configurable list of functions.»

;(add-hook 'undo-tree-mode (lambda () (local-unset-key "C-/")))
;;failed;(global-set-key (kbd "C-c /") 'hippie-expand)

;; I could not make it work with C-/ - so I stick to M-/
(global-set-key (kbd "M-/") 'hippie-expand)

mark word|line|sentence|sexp|defun → my-map mw|ml|ms|mx|md

With these commands, I get great shortcuts to put the current word, line, sentence, sexp or defun into the marked region:

(bind-key (kbd "mw") #'mark-word my-map)

(defun mark-line (&optional arg)
  (interactive "p")
  (beginning-of-line)
  (let ((here (point)))
    (dotimes (i arg)
      (end-of-line))
    (set-mark (point))
    (goto-char here)))

(bind-key "m l" 'mark-line my-map)

(defun mark-sentence (&optional arg)
  (interactive "P")
  (backward-sentence)
  (mark-end-of-sentence arg))

(bind-key "m s" #'mark-sentence my-map)
(bind-key "m x" #'mark-sexp my-map)
(bind-key "m d" #'mark-defun my-map)

autostart

At the end of loading most of my configuration, I want to execute some things, some of them only in interactive mode.

(message "→★ finished loading config.org (w/o autostart) in %.2fs" (float-time (time-subtract (current-time) my-config-el-start-time)))

;; omit some things when running in batch-mode:
(when (not noninteractive)

  (global-set-key (kbd "M-x") 'counsel-M-x) ;; id:2017-03-02-cool-command-completion

  ;(sleep-for 2)
  (setq my-org-agenda-tags-column (- (- (window-total-width) 3)))
  (message (concat "Setting agenda tags column to " (number-to-string my-org-agenda-tags-column)))
  (setq org-agenda-tags-column my-org-agenda-tags-column) ;; total width minus 3

  (message "Creating agenda …")
  (my-org-agenda)

  (message "my-org-startup-visibility …")
  (my-org-startup-visibility)

)

custom variables

This somehow got written by Emacs. Honestly, I am not sure whether or not I should keep this here. Well, it does not hurt either.

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(org-contacts-address-property "CITY")
 '(org-contacts-birthday-property "BORN")
 '(org-contacts-files "~/org/contacts.org")
 '(org-contacts-icon-property "PHOTOGRAPH")
 '(safe-local-variable-values
   (quote
    ((eval ispell-change-dictionary "german8")
     (eval ispell-change-dictionary "american")
     (eval ispell-change-dictionary "en_US")
     (flyspell-default-dictionary . "german8")))))

(setq truncate-lines t);; https://www.emacswiki.org/emacs/TruncateLines - M-x toggle-truncate-lines

Closing and end for profiling

This is the end of the Elisp blocks to be tangled. Finishing up loading my configuration (famous last words):

(message "»»» Binaries not found in checks above: %s" my-binary-not-found-list)
(message "→★ finished loading config.org in %.2fs" (float-time (time-subtract (current-time) my-config-el-start-time)))

Current key mappings (sorted)

Here are some blocks that try to extract keyboard bindings from the configuration file here.

Mappings not using my-map (non-sorted output)

Mappings not using my-map (sorted output)

keyfunction
C-, lavy-goto-line
C-, nneotree-toggle
C-, wavy-goto-word-0
C-c %org-mark-ring-push
C-c <down>org-mark-ring-push
C-c <left>org-mark-ring-goto
C-f(lambda () (interactive) (forward-line 5
C-nscroll-up-command
C-pscroll-down-command
C-s-SPCmode-line-in-header
M-,move-text-up
M-.move-text-down
M-/hippie-expand
M-xcounsel-M-x) ;; id:2017-03-02-cool-command-completion
[(shift f1)]my-toggle-dark-bright-theme
[C-left]backward-word
[C-right]forward-word
[M-c]capitalize-word
[M-l]downcase-word
[M-u]upcase-word
[S-left]backward-word
[S-right]forward-word
[end]end-of-buffer
[f12]my-toggle-naked-emacs
[f1]my-toggle-beginner-setup
[f5]goto-last-change
[f6]goto-last-change-reverse
[f7]char-menu
[f8]neotree-toggle)
[f8]neotree-toggle
[home]beginning-of-buffer
[remap fill-paragraph]
global [tool-bar pdf-button]
global \C-ccorg-capture
org-mode C-c (org-mode-reftex-search
org-mode C-c )reftex-citation
org-mode RET
\C-caorg-agenda
\C-clorg-store-link
\C-cmmy-memacs-org-agenda
\C-smy-search-method-according-to-numlines

Mapping from my-map outside of use-package

  • [ ] fix script
\texttt{C-c ,}functioncomment

config.el: (define-key my-map P | pylookup-lookup | | main_before_moving_to_config.org.el: (define-key my-map P | pylookup-lookup | | main_sherri_before_configorg.el: (define-key my-map P | pylookup-lookup | | main_sherri_before_configorg_ORIG.el: (define-key my-map P | pylookup-lookup |

Mapping from my-map within use-package

\texttt{C-c ,}functioncomment
0bm-next
8bm-toggle
9bm-previous
RETeno-word-goto
Smy-synonym-current-word
SPCyankpad-insert
csmeargle
hhighlight-symbol
sspray-mode

Mapping of F-keys

id:2017-05-22-f-key-mapping

New mapping for F-keys: id:2017-05-26-new-F-key-bindings

KeyNew binding
<f1>my-toggle-beginner-setup
Shift-<f1>my-toggle-dark-bright-theme
<f2>goto-last-change
<f3>goto-last-change-reverse
<f4>char-menu
<f5>flyspell-mode
Shift-f5my-toggle-ispell-language
<f6>flyspell-goto-next-error
<f7>flyspell-correct-word-before-point
<f8>
<f9>neotree-toggle
<f10>menu-bar-open
<f11>toggle-frame-fullscreen
<f12>my-toggle-naked-emacs

Local Variables