Knusper's Emacs configuration

Table of Contents

1 Configuration

1.1 Notes

1.2 Init file

We still need an Init File (~/.emacs.d/init.el or ~/.emacs) that loads org-mode, sets up the paths for packages that we don't install via the package manager.

Before starting emacs with this init file, we install org-mode and AuCTeX on the system where this .emacs is delployed.

When org-mode is installed, we can open this file and run C-c C-v C~t to tangle this file.

To tangle the file from the command line:

emacs --batch -l org -f org-babel-tangle

.emacs or .emacs.d/init.el

;; ~/.emacs.d/init.el (or ~/.emacs)

;; This sets up the load path so that we can override it
(package-initialize nil)
(add-to-list 'load-path (expand-file-name "~/emacs-scripts/"))

;; org-mode
(add-to-list 'load-path (expand-file-name "~/emacs-scripts/org-9.1.13/lisp/"))
(add-to-list 'load-path "~/emacs-scripts/org-9.1.13/contrib/lisp" t)
(eval-after-load "info"
     (add-to-list 'Info-directory-list "~/emacs-scripts/org-9.1.13/doc/")))

;; auctex
(add-to-list 'load-path (expand-file-name "~/.emacs.d/site-lisp/auctex"))
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

;; Load the rest of the packages
(package-initialize nil)
(setq package-enable-at-startup nil)

;; rather than using org-babel-load file I tangle this file (C-c C-v C-t)
;; and load it directly
;; (load-file "~/Org/dotemacs_project/Knusper.el")  ;; uncomment this line, after this file has been tangled

1.2.1 Notes on org-mode installation

  • Just run make
  • Version currently installed: 9.1.13

1.2.2 Notes on AucTeX installation

1.2.3 General Start the emacs server
(server-start) Load Custom File
(setq custom-file "~/.gnu-emacs-custom")
(load custom-file)

1.3 Personal Information

(setq user-full-name "Edmund Christian Herenz")

1.4 Mode-specific settings

1.4.1 Notes

I install AucTeX + org-mode manually, as these are the modes that I depend on most for my work. For this reason I want full control over the installation process.

See also: Notes on org-mode installation and Notes on AucTeX installation

1.4.2 LateX

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(setq LaTeX-math-menu-unicode t)
(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)
(require 'reftex)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(setq reftex-cite-format 'natbib)

;; use mupdf as default PDF viewer
(with-eval-after-load "tex"
  (add-to-list 'TeX-view-program-list '("mupdf" "/usr/bin/mupdf %o"))
  (setcdr (assq 'output-pdf TeX-view-program-selection) '("mupdf")))

1.4.3 Org-Mode

Load org-mode:

(require 'org)  

Open org-mode files in org-mode:

(setq auto-mode-alist
      (cons '("\\.org$" . org-mode) auto-mode-alist))

Reasonable default key bindings:

(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(setq org-log-done t)

Open png image files with default image viewer on system:

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

org-mode defines some key bindings, that override some of my personal global key-bindings - these key bindings are disabled here:

(eval-after-load 'org
    ;; these are my windmove key-bindings
    (define-key org-mode-map (kbd "<C-S-right>") nil)
    (define-key org-mode-map (kbd "<C-S-left>") nil)
    (define-key org-mode-map (kbd "<C-S-up>") nil)
    (define-key org-mode-map (kbd "<C-S-down>") nil)

Intedentation needs to be preserved, otherwise tangled python3 source blocks from org-mode files will not run.

(setq org-src-preserve-indentation t) Set width to inline images

The following setting enables inline images to be scaled when displayed inline (org-toggle-inline-images):

(setq org-image-actual-width nil)

Now, put this before an image link to scale it #+ATTR_ORG: :width 500px "Ugly" Hack to disable PDFs in links to open in DocView Mode

This is from No idea why it is so complicated, to have linked PDF files popping up in an external viewer (btw., I use mupdf)

(defun ensc/mailcap-mime-data-filter (filter)
  (mapcar (lambda(major)
        (append (list (car major))
            (remove nil
                (mapcar (lambda(minor)
                (when (funcall filter (car major) (car minor) (cdr minor))
                    (cdr major)))))

(defun ensc/no-pdf-doc-view-filter (major minor spec)
  (if (and (string= major "application")
 (string= minor "pdf")
 (member '(viewer . doc-view-mode) spec))

(eval-after-load 'mailcap
     (setq mailcap-mime-data
 (ensc/mailcap-mime-data-filter 'ensc/no-pdf-doc-view-filter))))

1.5 Packages

1.5.1 Package Archives

MELPA is the king of emacs package archives. Follow MELPA on Twitter.

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

1.5.2 Packages I use use-package - automatically download and install packages

We use use-package to automatically download and install packages, if they are not present on the system. Of course, when firing up EMACS for the first time on a fresh system, use-package needs to be automagically installed first.

(if (not (package-installed-p 'use-package))
      (package-install 'use-package)))

(require 'use-package) Package List
  1. Essential
    1. which-key

      (use-package which-key
        :ensure t)
    2. ebib

      Ebib: (in MELPA)

      Copy of settings copied from .gnu_emacs_custom

      (use-package ebib
        :ensure t
        (setq ebib-index-columns
               (("timestamp" 12 t)
                ("Entry Key" 20 t)
                ("Author/Editor" 40 nil)
                ("Year" 6 t)
                ("Title" 50 t))))
        (setq ebib-index-default-sort (quote ("timestamp" . descend)))
        (setq ebib-index-default-sort (quote ("timestamp" . descend)))
        (setq ebib-preload-bib-files (quote ("~/science_works/bibliography.bib")))
        (setq ebib-timestamp-format "%Y.%m.%d")
        (setq ebib-use-timestamp t))
    3. bibslurp-ads

      Bibslurp: (in MELPA)

      (use-package bibslurp
        :ensure t)
    4. yascroll-mode

      yascroll.el is Yet Another Scroll Bar Mode for GNU Emacs.

      (use-package yascroll
        :ensure t
        (global-yascroll-bar-mode 1)
        (setq yascroll:delay-to-hide 0.8)
    5. magit

      (use-package magit 
        :ensure t
        :bind ("C-x g" . magit-status)
    6. diminish
      (use-package diminish
        :ensure t)
    7. tea-time

      With tea-time I never forget about the tea. Using this soundbite from my favorite movie "The Italian Job".

      (use-package tea-time
        :ensure t
        (setq tea-time-sound "~/.sounds/tea.ogg")
        (setq tea-time-sound-command "ogg123 -q %s")
    8. 2048
    9. buffer-move

      (use-package buffer-move
        :ensure t
        (global-set-key (kbd "<S-s-up>")     'buf-move-up)
        (global-set-key (kbd "<S-s-down>")   'buf-move-down)
        (global-set-key (kbd "<S-s-left>")   'buf-move-left)
        (global-set-key (kbd "<S-s-right>")  'buf-move-right)
    10. smex
      (use-package smex
        :ensure t
        (global-set-key (kbd "M-x") 'smex)
    11. rainbow-delimiters

      (use-package rainbow-delimiters
        :ensure t
        (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
    12. htmlize
    13. iedit

      Simultaneously edit multiple regions in buffer.

      (use-package iedit
        :ensure t)
    14. writeroom-mode

      Distraction free writing.

      (use-package writeroom-mode
        :ensure t)
    15. auto-complete

      (use-package auto-complete
        :ensure t
        (global-auto-complete-mode t) 
        (add-hook 'python-mode-hook 'jedi:setup)
        (setq jedi:setup-keys t)
    16. markdown-mode

      (use-package markdown-mode
        :ensure t
        :init (setq auto-mode-alist
                    (cons '("\\.mdml$" . markdown-mode) auto-mode-alist)))
      1. markdown-toc
        (use-package markdown-toc
          :ensure t)
    17. jedi

      (use-package jedi
        :ensure t
    18. org-bullets

      The following gold is from

      (use-package org-bullets
        :ensure t
        (setq org-bullets-bullet-list
              '("◉" "◎" "⚫" "○" "►" "◇"))
        (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
      (setq org-todo-keywords '((sequence "☛ TODO(t)" "|" "✔ DONE(d)")
      (sequence "⚑ WAITING(w)" "|")
      (sequence "|" "✘ CANCELED(c)")))
    19. pager and for the default keybindings (the latter depends on the former).

      (use-package pager
        :ensure t)
      (use-package pager-default-keybindings
        :ensure t)
    20. uptimes

      (use-package uptimes
        :ensure t)
    21. dired-quicksort

      Quick and easy sorting in dired - just press "S".

      (use-package dired-quick-sort
        :ensure t

      With this configuration S is bound to invoke the dired-quick-sort hydra.

    22. Dictionary

      (use-package dictionary
        :ensure t)
  2. Appearance
    1. zenburn colour theme

      Load zenburn colour theme when starting emacs.

      (if (string=(system-name) "knuspertop")
          (use-package zenburn-theme
            :ensure t
            (load-theme 'zenburn))
        (use-package plan9-theme
          :ensure t
          (load-theme 'plan9)))
      (use-package zenburn-theme
        :ensure t
        (load-theme 'zenburn))
    2. powerline

      (use-package powerline
        :ensure t
    3. beacon

      (use-package beacon
        :ensure t
        :diminish beacon-mode
        (beacon-mode 1)
        (setq beacon-dont-blink-commands nil) ;; always blink
        ;; (setq beacon-lighter '"Λ") - 
        (add-to-list 'beacon-dont-blink-major-modes 'Man-mode)
        (add-to-list 'beacon-dont-blink-major-modes 'shell-mode)
        (add-to-list 'beacon-dont-blink-major-modes 'inferior-python-mode)
        (add-to-list 'beacon-dont-blink-major-modes 'xkcd-mode)
        :diminish beacon-mode
  3. Email
    1. muttrc-mode

      Syntax highlighting in muttrc file.

      (use-package muttrc-mode
        :ensure t
         (setq auto-mode-alist
                  (append '((".muttrc\\'" . muttrc-mode))
    2. offlineimap
      (use-package offlineimap
        :ensure t
  4. Fun
    1. xkcd xkcd reader for Emacs. Nerd on!

      (use-package xkcd
        :ensure t)
    2. fireplace

      It can get cold in winter. M-x fireplace

      (use-package fireplace
        :ensure t)
    3. tea-time

      With tea-time I never forget about the tea. Using this soundbite from my favorite movie "The Italian Job".

      (use-package tea-time
        :ensure t
        (setq tea-time-sound "~/.sounds/tea.ogg")
        (setq tea-time-sound-command "ogg123 -q %s")
    4. 2048

1.5.3 Packages not in ELPA or MELPA

These packages are in ~/emacs-scripts/ as specfied in the load-path in 1.2. post-mode for mutt

Note: Cheers, as a default in post-signature-pattern is not a good idea!

(use-package post
  (setq post-signature-pattern "\\(--\\|\\)")
  ) simple-wiki wikidot mode

An Emacs mode for editing Wikidot markup

(use-package wikidot-mode)

1.5.4 Part of emacs printing

(use-package printing
  (pr-update-menus t)) uniquify

Uniquify buffer names. See e.g. here or here.

(require 'uniquify) Midnight Mode (disabled)

Bury unused buffers after some time (4:30 in the morning).

(use-package midnight
  (midnight-delay-set 'midnight-delay "4:30am")) Abbrev-mode

  • but currently not used
(if (file-exists-p abbrev-file-name)
(setq save-abbrevs t)  
;; in org-mode, we want expansions with trailing or leading slashes -
;; this might need some modification
(abbrev-table-put org-mode-abbrev-table :regexp "\\(\\\\[a-z0-9@]+\\)") ido-mode Part of Emacs

(use-package ido
  (ido-mode t)
  (setq ido-enable-flex-matching t)
  (setq ido-everywhere t)
  (setq ido-max-prospects 50)
  (setq ido-max-window-height 0.25)

1.6 User Interface

1.6.1 Window Configuration

  • no tooltips
  • no toolbar
  • no menu
  • no scrollbar
(when window-system
  (tooltip-mode -1)
  (tool-bar-mode -1)
  (menu-bar-mode -1)
  (scroll-bar-mode -1))

1.6.2 Various settings move around between windows using C-S-Arrow keys (wind-move)
(global-set-key (kbd "<C-S-up>")     'windmove-up)
(global-set-key (kbd "<C-S-down>")   'windmove-down)
(global-set-key (kbd "<C-S-left>")   'windmove-left)
(global-set-key (kbd "<C-S-right>")  'windmove-right) disable <menu>-key
(global-set-key (kbd "<menu>") 'nil) disable blinking cursor
(blink-cursor-mode 0) disable Shift+Arrow to select text
(setq shift-select-mode nil) middle-click pastes at point, not at mouse position
(setq mouse-yank-at-point t) transient-mark-mode
(setq transient-mark-mode t) highlight matching parenthesis based on point
(show-paren-mode t) recent files mode
(recentf-mode 1) Bind hippie-expand to M-<SPC> - Peace!
(global-set-key "\M- " 'hippie-expand) never truncate the lines in my buffer [DISABLED]
(setq truncate-lines t) always truncate lines, but never the mini-buffer
(setq truncate-lines t)
(add-hook 'minibuffer-setup-hook
      (lambda () (setq truncate-lines nil))) Emacs close confirmation

(do not accidentally close emacs)

(setq kill-emacs-query-functions
      (cons (lambda () (yes-or-no-p "Really Quit Emacs? "))
            kill-emacs-query-functions)) enable disabled command - upcase region
(put 'upcase-region 'disabled nil) desktop-save-mode

(see Sect. 42 "Saving Emacs Sessions" in Emacs User Manual)

(desktop-save-mode 1)
(setq desktop-restore-eager 10)
(setq desktop-save t) ;; save without asking user ibuffer insted of list-buffers
(defalias 'list-buffers 'ibuffer)
  1. adjust ibuffer column widths
    (setq ibuffer-formats
          '((mark modified read-only " "
                  (name 30 30 :left :elide) " "
                  (size 9 -1 :right) " "
                  (mode 16 16 :left :elide) " " filename-and-process)
            (mark " " (name 16 -1) " " filename))) eshell-stuff

em-joc - not used anymore

 (require 'em-joc)
  (defun eshell/info (subject)
    "Read the Info manual on SUBJECT."
    (let ((buf (current-buffer)))
      (let ((node-exists (ignore-errors (Info-menu subject))))
        (if node-exists
;;          We want to switch back to *eshell* if the requested
;;          Info manual doesn't exist.
          (switch-to-buffer buf)
          (eshell-print (format "There is no Info manual on %s.\n"

1.6.3 Electric Pairs

(electric-pair-mode 1)
(defvar markdown-electric-pairs '((?* . ?*)) "Electric pairs for markdown-mode.")
(defun markdown-add-electric-pairs ()
  (setq-local electric-pair-pairs (append electric-pair-pairs markdown-electric-pairs))
  (setq-local electric-pair-text-pairs electric-pair-pairs))
(add-hook 'markdown-mode-hook 'markdown-add-electric-pairs)

1.6.4 Move around between windows (wind-move)

Move around between windows using C-S-Arrow keys (wind-move). Better than pressing repeatedly C-x o. (Seems not to work in org-mode?)

(global-set-key (kbd "<C-S-up>")     'windmove-up)
(global-set-key (kbd "<C-S-down>")   'windmove-down)
(global-set-key (kbd "<C-S-left>")   'windmove-left)
(global-set-key (kbd "<C-S-right>")  'windmove-right)

1.7 Convenience functions not shipped in emacs

1.7.1 Timestamps

Command to insert timestamps into text - e.g.: 27.10.2015, 12:25 Inspired from

(defun timestamp ()
  (insert (format-time-string "%d.%m.%Y, %H:%M")))

1.7.2 Count Words & Characters


(defun my-count-words-region (posBegin posEnd)
  "Print number of words and chars in region."
  (interactive "r")
  (message "Counting …")
    (let (wordCount charCount)
      (setq wordCount 0)
      (setq charCount (- posEnd posBegin))
      (goto-char posBegin)
      (while (and (< (point) posEnd)
                  (re-search-forward "\\w+\\W*" posEnd t))
        (setq wordCount (1+ wordCount)))

      (message "Words: %d. Chars: %d." wordCount charCount)

1.7.3 Unfill Region / Unfill Paragraph


(defun unfill-paragraph ()
  "Replace newline chars in current paragraph by single spaces.
This command does the inverse of `fill-paragraph'."
  (let ((fill-column 90002000)) ; 90002000 is just random. you can use `most-positive-fixnum'
    (fill-paragraph nil)))
(defun unfill-region (start end)
  "Replace newline chars in region by single spaces.
This command does the inverse of `fill-region'."
  (interactive "r")
  (let ((fill-column 90002000))
    (fill-region start end)))

Author: Edmund Christian Herenz

Created: 2018-09-03 Mon 17:48

Emacs 24.5.1 (Org mode 9.1.13)