Knusper's Emacs configuration
Table of Contents
- 1. Configuration
- 1.1. Notes
- 1.2. Init file
- 1.3. Personal Information
- 1.4. Mode-specific settings
- 1.5. Packages
- 1.6. User Interface
- 1.6.1. Window Configuration
- 1.6.2. Various settings
- 1.6.2.1. move around between windows using C-S-Arrow keys (wind-move)
- 1.6.2.2. disable <menu>-key
- 1.6.2.3. disable blinking cursor
- 1.6.2.4. disable Shift+Arrow to select text
- 1.6.2.5. middle-click pastes at point, not at mouse position
- 1.6.2.6. transient-mark-mode
- 1.6.2.7. highlight matching parenthesis based on point
- 1.6.2.8. recent files mode
- 1.6.2.9. Bind hippie-expand to M-<SPC> - Peace!
- 1.6.2.10. never truncate the lines in my buffer [DISABLED]
- 1.6.2.11. always truncate lines, but never the mini-buffer
- 1.6.2.12. Emacs close confirmation
- 1.6.2.13. enable disabled command - upcase region
- 1.6.2.14. desktop-save-mode
- 1.6.2.15. user ibuffer insted of list-buffers
- 1.6.2.16. eshell-stuff
- 1.6.3. Electric Pairs
- 1.6.4. Move around between windows (wind-move)
- 1.7. Convenience functions not shipped in emacs
1 Configuration
1.1 Notes
- Somewhat inspired by Sacha Chua's Emacs configuration.
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 Knusper.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" '(progn (info-initialize) (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
- Download AucTeX from https://www.gnu.org/software/auctex/download-for-unix.html
- Compile using
./configure --prefix=$HOME/.emacs.d/site-lisp/auctex --with-lispdir=$HOME/.emacs.d/site-lisp/auctex --without-texmf-dir
- Version currently installed: 11.89
1.2.3 General
1.2.3.1 Start the emacs server
(server-start)
1.2.3.2 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 (progn ;; 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)
1.4.3.1 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
1.4.3.2 "Ugly" Hack to disable PDFs in links to open in DocView Mode
This is from http://emacs.stackexchange.com/a/24580/5254 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)) minor)) (cdr major))))) mailcap-mime-data)) (defun ensc/no-pdf-doc-view-filter (major minor spec) (if (and (string= major "application") (string= minor "pdf") (member '(viewer . doc-view-mode) spec)) nil t)) (eval-after-load 'mailcap '(progn (setq mailcap-mime-data (ensc/mailcap-mime-data-filter 'ensc/no-pdf-doc-view-filter))))
1.4.3.3 Org-bullets
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" . "https://melpa.org/packages/") t)
1.5.2 Packages I use
1.5.2.1 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)) (progn (package-refresh-contents) (package-install 'use-package))) (require 'use-package)
1.5.2.2 Package List
- Essential
- which-key
https://github.com/justbur/emacs-which-keynn
(use-package which-key :ensure t)
- ebib
Ebib: http://joostkremers.github.io/ebib/ (in MELPA)
Copy of settings copied from
.gnu_emacs_custom
(use-package ebib :ensure t :config (setq ebib-index-columns (quote (("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))
- bibslurp-ads
Bibslurp: http://mkmcc.github.io/software/bibslurp.html (in MELPA)
(use-package bibslurp :ensure t)
- yascroll-mode
yascroll.el is Yet Another Scroll Bar Mode for GNU Emacs. https://github.com/m2ym/yascroll-el
(use-package yascroll :ensure t :config (global-yascroll-bar-mode 1) (setq yascroll:delay-to-hide 0.8) )
- magit
(use-package magit :ensure t :bind ("C-x g" . magit-status) )
- diminish
(use-package diminish :ensure t)
- 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 :config (setq tea-time-sound "~/.sounds/tea.ogg") (setq tea-time-sound-command "ogg123 -q %s") )
- 2048
- buffer-move
https://github.com/lukhas/buffer-move
(use-package buffer-move :ensure t :config (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) )
- smex
(use-package smex :ensure t :config (smex-initialize) (global-set-key (kbd "M-x") 'smex) )
- rainbow-delimiters
https://www.emacswiki.org/emacs/RainbowDelimiters
(use-package rainbow-delimiters :ensure t :config (add-hook 'prog-mode-hook #'rainbow-delimiters-mode) )
- htmlize
- iedit
Simultaneously edit multiple regions in buffer. http://www.emacswiki.org/emacs/Iedit
(use-package iedit :ensure t)
- writeroom-mode
Distraction free writing. https://github.com/joostkremers/writeroom-mode
(use-package writeroom-mode :ensure t)
- auto-complete
(use-package auto-complete :ensure t :config (global-auto-complete-mode t) (add-hook 'python-mode-hook 'jedi:setup) (setq jedi:setup-keys t) )
- markdown-mode
http://jblevins.org/projects/markdown-mode/
(use-package markdown-mode :ensure t :init (setq auto-mode-alist (cons '("\\.mdml$" . markdown-mode) auto-mode-alist)))
- jedi
https://tkf.github.io/emacs-jedi/latest/
(use-package jedi :ensure t )
- org-bullets
The following gold is from https://thraxys.wordpress.com/2016/01/14/pimp-up-your-org-agenda/
(use-package org-bullets :ensure t :init (setq org-bullets-bullet-list '("◉" "◎" "⚫" "○" "►" "◇")) :config (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)")))
- pager
https://github.com/emacsorphanage/pager and for the default keybindings https://github.com/nflath/pager-default-keybindings (the latter depends on the former).
(use-package pager :ensure t) (use-package pager-default-keybindings :ensure t)
- uptimes
https://github.com/davep/uptimes.el
(use-package uptimes :ensure t)
- dired-quicksort
Quick and easy sorting in dired - just press "S".
https://www.topbug.net/blog/2016/08/17/dired-quick-sort-sort-dired-buffers-quickly-in-emacs/
(use-package dired-quick-sort :ensure t :init (dired-quick-sort-setup))
With this configuration
S
is bound to invoke thedired-quick-sort
hydra. - Dictionary
http://me.in-berlin.de/~myrkr/dictionary/index.html
(use-package dictionary :ensure t)
- which-key
- Appearance
- zenburn colour theme
https://github.com/bbatsov/zenburn-emacs
Load zenburn colour theme when starting emacs.
(if (string=(system-name) "knuspertop") (use-package zenburn-theme :ensure t :config (load-theme 'zenburn)) (use-package plan9-theme :ensure t :config (load-theme 'plan9))) (use-package zenburn-theme :ensure t :config (load-theme 'zenburn))
- powerline
https://github.com/milkypostman/powerline
(use-package powerline :ensure t :config (powerline-default-theme) )
- beacon
https://github.com/Malabarba/beacon
(use-package beacon :ensure t :diminish beacon-mode :config (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 )
- zenburn colour theme
- Email
- muttrc-mode
Syntax highlighting in muttrc file.
(use-package muttrc-mode :ensure t :config (setq auto-mode-alist (append '((".muttrc\\'" . muttrc-mode)) auto-mode-alist)))
- offlineimap
(use-package offlineimap :ensure t )
- muttrc-mode
- Fun
- xkcd
https://github.com/vibhavp/emacs-xkcd xkcd reader for Emacs. Nerd on!
(use-package xkcd :ensure t)
- fireplace
It can get cold in winter.
M-x fireplace
https://github.com/johanvts/emacs-fireplace(use-package fireplace :ensure t)
- 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 :config (setq tea-time-sound "~/.sounds/tea.ogg") (setq tea-time-sound-command "ogg123 -q %s") )
- 2048
- xkcd
1.5.3 Packages not in ELPA or MELPA
These packages are in ~/emacs-scripts/
as specfied in the
load-path in 1.2.
1.5.3.1 post-mode for mutt
http://post-mode.sourceforge.net/
Note: Cheers,
as a default in post-signature-pattern
is not a
good idea!
(use-package post :config (setq post-signature-pattern "\\(--\\|\\)") )
1.5.3.2 simple-wiki
http://www.emacswiki.org/emacs/SimpleWikiMode
(use-package simple-wiki)
1.5.3.3 wikidot mode
An Emacs mode for editing Wikidot markup
https://github.com/infochimps-customers/wikidot-mode
(use-package wikidot-mode)
1.5.4 Part of emacs
1.5.4.1 printing
http://www.emacswiki.org/emacs/PrintingPackage
(use-package printing :config (pr-update-menus t))
1.5.4.3 Midnight Mode (disabled)
http://www.emacswiki.org/emacs/MidnightMode
Bury unused buffers after some time (4:30 in the morning).
(use-package midnight :config (midnight-delay-set 'midnight-delay "4:30am"))
1.5.4.4 Abbrev-mode
http://www.emacswiki.org/emacs/AbbrevMode
- but currently not used
(if (file-exists-p abbrev-file-name) (quietly-read-abbrev-file)) (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@]+\\)")
1.5.4.5 ido-mode
http://www.emacswiki.org/emacs/InteractivelyDoThings Part of Emacs
(use-package ido :config (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
1.6.2.1 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)
1.6.2.2 disable <menu>-key
(global-set-key (kbd "<menu>") 'nil)
1.6.2.3 disable blinking cursor
(blink-cursor-mode 0)
1.6.2.4 disable Shift+Arrow to select text
(setq shift-select-mode nil)
1.6.2.5 middle-click pastes at point, not at mouse position
(setq mouse-yank-at-point t)
1.6.2.6 transient-mark-mode
(setq transient-mark-mode t)
1.6.2.7 highlight matching parenthesis based on point
(show-paren-mode t)
1.6.2.8 recent files mode
(recentf-mode 1)
1.6.2.9 Bind hippie-expand to M-<SPC> - Peace!
(global-set-key "\M- " 'hippie-expand)
1.6.2.10 never truncate the lines in my buffer [DISABLED]
(setq truncate-lines t)
1.6.2.11 always truncate lines, but never the mini-buffer
(setq truncate-lines t) (add-hook 'minibuffer-setup-hook (lambda () (setq truncate-lines nil)))
1.6.2.12 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))
1.6.2.13 enable disabled command - upcase region
(put 'upcase-region 'disabled nil)
1.6.2.14 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
1.6.2.15 user ibuffer insted of list-buffers
(defalias 'list-buffers 'ibuffer)
1.6.2.16 eshell-stuff
em-joc - not used anymore
(require 'em-joc) (defun eshell/info (subject) "Read the Info manual on SUBJECT." (let ((buf (current-buffer))) (Info-directory) (let ((node-exists (ignore-errors (Info-menu subject)))) (if node-exists 0 ;; 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" subject)) 1))))
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 http://emacswiki.org/emacs/InsertingTodaysDate
(defun timestamp () (interactive) (insert (format-time-string "%d.%m.%Y, %H:%M")))
1.7.2 Count Words & Characters
From http://ergoemacs.org/emacs/elisp_count-region.html
(defun my-count-words-region (posBegin posEnd) "Print number of words and chars in region." (interactive "r") (message "Counting …") (save-excursion (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
Source: http://ergoemacs.org/emacs/emacs_unfill-paragraph.html
(defun unfill-paragraph () "Replace newline chars in current paragraph by single spaces. This command does the inverse of `fill-paragraph'." (interactive) (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)))