Skip to content

Latest commit

 

History

History
executable file
·
1141 lines (891 loc) · 31.6 KB

Knusper.org

File metadata and controls

executable file
·
1141 lines (891 loc) · 31.6 KB

ECH’s Emacs configuration

Notes

Init file

Init file - code and notes

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.2/lisp/"))
  (add-to-list 'load-path "~/emacs-scripts/org-9.2/contrib/lisp" t)
  (eval-after-load "info"
    '(progn
	  (info-initialize)
	  (add-to-list 'Info-directory-list "~/emacs-scripts/org-9.2/doc/")))
  (require 'org-tempo) ;; old-school structure templates

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

Notes on org-mode installation

  • Just run make
  • Version currently installed: 9.2

Notes on AucTeX installation

General

Start the emacs server

(server-start)

Load Custom File

(setq custom-file "~/.gnu-emacs-custom")
(load custom-file)

Mode-specific settings

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

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

Org-Mode

org-mode is installed manually (see above). Load org-mode:

(require 'org)  

Open org-mode files in org-mode:

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

Store time when a task is done

(setq org-log-done t)

Latex font-highlight in org-mode

     (eval-after-load 'org '(setf org-highlight-latex-and-related
	'(latex)))

Since 9.2 we also need to load org-tempo to have quick acces to “structure templates”:

(require 'org-tempo)

Key bindings

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)
(global-set-key (kbd "C-c c") 'org-capture)

org-mode defines some key bindings, that override my key-bindings for wind-move - 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)
	  ))

Capture Templates

The capture template for bookmarks requires org-cliplink to be installed

 (setq org-capture-templates
	    '(
	      ("b" "Bookmark" entry (file+headline "~/Org/bookmarks.org" "Bookmarks")
	       "* %(org-cliplink-capture) %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)
	      )
	    )

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

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

org-agenda-category-icon-alist

Icons in this list visually “pimp-up” the org-mode agenda. I use the symbols provided by the all-the-icons package, installed further below.

   (eval-after-load 'all-the-icons
   '(setq org-agenda-category-icon-alist 
	    `(
	      ("talk"
	       ,(list
		 (all-the-icons-faicon "graduation-cap"  :face 'all-the-icons-red))
	       nil nil :ascent center)
	      ("flight"
	       ,(list
		 (all-the-icons-alltheicon "swift"  :face 'all-the-icons-blue))
	       nil nil :ascent center)
	      ("mail"
	       ,(list
		 (all-the-icons-octicon "mail"  :face 'all-the-icons-yellow))
	       nil nil :ascent center)
	      ("observe"
	       ,(list
		 (all-the-icons-octicon "telescope"  :face 'all-the-icons-lyellow))
	       nil nil :ascent center)
	     )
	    )
   )

Packages

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)

Package signature verification for ELPA: http://elpa.gnu.org/packages/gnu-elpa-keyring-update.html

(use-package gnu-elpa-keyring-update
  :ensure t)

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)

Paradox - a better package manager for emacs

https://github.com/Malabarba/paradox

(use-package paradox
  :ensure t
  :init
  (paradox-enable))

List of used packages

org-mode related

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

orgtbl-aggregate

Aggregating a table is creating a new table by computing sums, averages, and so on, out of material from the first table.

https://github.com/tbanel/orgaggregate

This really should be part of org-mode at some point.

     (use-package orgtbl-aggregate
	 :ensure t)

org-cliplink

https://github.com/rexim/org-cliplink

     (use-package org-cliplink
	 :ensure t)

Essential

ido / swiper / counsel

     (use-package ivy
	 :ensure t
	 :init
	 (ivy-mode 1)
	 )

     (use-package counsel
	 :ensure t
	 :config
	 (global-set-key (kbd "M-x") 'counsel-M-x)
	 (global-set-key (kbd "C-x C-f") 'counsel-find-file)
     )

     (use-package swiper
	 :ensure t
	 :config
	 (global-set-key (kbd "C-s") 'swiper) )

smex

counsel-M-x can re-use functions provided by smex - then counsel-M-x behaves like smex on steroids.

(use-package smex
  :ensure t
  )

try

Try is a package that allows you to try out Emacs packages without installing them. https://github.com/larstvei/Try

     (use-package try
	 :ensure t
	 )

anaconda-mode

Code navigation, documentation lookup and completion for Python. https://github.com/proofit404/anaconda-mode

     (use-package anaconda-mode
	 :ensure t
	 :config
	 (add-hook 'python-mode-hook 'anaconda-mode)
	 (add-hook 'python-mode-hook 'anaconda-eldoc-mode))
auto-complete for anaconda with company-mode
	(use-package company
	  :ensure t)
	(use-package company-anaconda
	  :ensure t
	  :after company
	  :config
	  (add-to-list 'company-backends 'company-anaconda)
	)

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-window-size 28)
	 (setq ebib-preload-bib-files (quote ("~/science_works/bibliography.bib")))
	 (setq ebib-timestamp-format "%Y.%m.%d")
	 (setq ebib-use-timestamp t)
	 (setq ebib-uniquify-keys 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

https://magit.vc

     (use-package magit 
	 :ensure t
	 :bind ("C-x g" . magit-status)
	 )

diminish

(use-package diminish
  :ensure t)

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

rainbow-delimiters

https://www.emacswiki.org/emacs/RainbowDelimiters

(use-package rainbow-delimiters
  :ensure t
  :config
  (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
  )

htmlize

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

olivetti

Less hardcore than writeroom mode, since only “buffer local”.

https://github.com/rnkn/olivetti

     (use-package olivetti
	 :ensure t
	 :config (setq olivetti-body-width 90))

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)))
markdown-toc
(use-package markdown-toc
  :ensure t)

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 the dired-quick-sort hydra.

dictionary

http://me.in-berlin.de/~myrkr/dictionary/index.html

     (use-package dictionary
	 :ensure t)

dictcc

Lookup and insert translations from dict.cc without leaving emacs

https://github.com/cqql/dictcc.el

     (use-package dictcc
	 :ensure t)

restart-emacs

Restart emacs from within emacs

https://github.com/iqbalansari/restart-emacs

     (use-package restart-emacs
	 :ensure t)

Appearance

zenburn colour theme

https://github.com/bbatsov/zenburn-emacs

Load zenburn colour theme when starting emacs.

     (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
	 :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 'woman-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
	 )

all-the-icons

https://github.com/domtronn/all-the-icons.el

     (use-package all-the-icons
	 :ensure t)

Make sure to not forget to run M-x all-the-icons-install-fonts on a fresh installation.

I use icons from all-the-icons in org-agenda-category-icon-alist.

Moreover, with all-the-icons-dired dired buffers look really neat!

     (use-package all-the-icons-dired
	 :ensure t
	 :init
	 (add-hook 'dired-mode-hook 'all-the-icons-dired-mode))

Email

muttrc-mode

Syntax highlighting in muttrc file.

Was removed from melpa, so currently not available… There appears to be a replacement https://github.com/neomutt/muttrc-mode-el. However, its not in melpa yet … For now I download it manually and place it in ~/emacs-scripts/

     (autoload 'muttrc-mode "muttrc-mode.el"
	 "Major mode to edit muttrc files" t)
     (setq auto-mode-alist
	     (append '(("muttrc\\'" . muttrc-mode))
		     auto-mode-alist))

Old - if it is in melpa at some point we use this again

(use-package muttrc-mode
  :ensure t
  :config
   (setq auto-mode-alist
            (append '((".muttrc\\'" . muttrc-mode))
                    auto-mode-alist)))

offlineimap

     (use-package offlineimap
       :ensure t
	 )

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)

Packages not in ELPA or MELPA

These packages are in ~/emacs-scripts/ as specfied in the load-path in Init file.

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

simple-wiki

http://www.emacswiki.org/emacs/SimpleWikiMode

(use-package simple-wiki)

wikidot mode

An Emacs mode for editing Wikidot markup

https://github.com/infochimps-customers/wikidot-mode

(use-package wikidot-mode)

Part of emacs

printing

http://www.emacswiki.org/emacs/PrintingPackage

(use-package printing
  :config
  (pr-update-menus t))

uniquify

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

(require 'uniquify)

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

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@]+\\)")

User Interface

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

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)

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

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)

Convenience functions not shipped in emacs

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

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

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