- Somewhat inspired by Sacha Chua’s Emacs configuration.
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
- Just run
make
- Version currently installed: 9.2
- 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
(server-start)
(setq custom-file "~/.gnu-emacs-custom")
(load custom-file)
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
(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 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)
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)
))
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)
)
)
(add-hook 'org-mode-hook
'(lambda ()
(setq org-file-apps
(append '(
("\\.png\\'" . default)
) org-file-apps ))))
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
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))))
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)
)
)
)
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)
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)
https://github.com/Malabarba/paradox
(use-package paradox
:ensure t
:init
(paradox-enable))
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)")))
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)
https://github.com/rexim/org-cliplink
(use-package org-cliplink
:ensure t)
(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) )
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 is a package that allows you to try out Emacs packages without installing them. https://github.com/larstvei/Try
(use-package try
:ensure t
)
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))
(use-package company
:ensure t)
(use-package company-anaconda
:ensure t
:after company
:config
(add-to-list 'company-backends 'company-anaconda)
)
https://github.com/justbur/emacs-which-keynn
(use-package which-key
:ensure t)
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: http://mkmcc.github.io/software/bibslurp.html (in MELPA)
(use-package bibslurp
:ensure t)
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)
)
(use-package magit
:ensure t
:bind ("C-x g" . magit-status)
)
(use-package diminish
:ensure t)
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)
)
https://www.emacswiki.org/emacs/RainbowDelimiters
(use-package rainbow-delimiters
:ensure t
:config
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
)
http://www.emacswiki.org/emacs/Htmlize
Simultaneously edit multiple regions in buffer. http://www.emacswiki.org/emacs/Iedit
(use-package iedit
:ensure t)
Distraction free writing. https://github.com/joostkremers/writeroom-mode
(use-package writeroom-mode
:ensure t)
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))
http://jblevins.org/projects/markdown-mode/
(use-package markdown-mode
:ensure t
:init (setq auto-mode-alist
(cons '("\\.mdml$" . markdown-mode) auto-mode-alist)))
(use-package markdown-toc
:ensure t)
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)
https://github.com/davep/uptimes.el
(use-package uptimes
:ensure t)
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.
http://me.in-berlin.de/~myrkr/dictionary/index.html
(use-package dictionary
:ensure t)
Lookup and insert translations from dict.cc without leaving emacs
https://github.com/cqql/dictcc.el
(use-package dictcc
:ensure t)
Restart emacs from within emacs
https://github.com/iqbalansari/restart-emacs
(use-package restart-emacs
:ensure t)
https://github.com/bbatsov/zenburn-emacs
Load zenburn colour theme when starting emacs.
(use-package zenburn-theme
:ensure t
:config
(load-theme 'zenburn))
https://github.com/milkypostman/powerline
(use-package powerline
:ensure t
:config
(powerline-default-theme)
)
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
)
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))
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)))
(use-package offlineimap
:ensure t
)
https://github.com/vibhavp/emacs-xkcd xkcd reader for Emacs. Nerd on!
(use-package xkcd
:ensure t)
It can get cold in winter. M-x fireplace
https://github.com/johanvts/emacs-fireplace
(use-package fireplace
:ensure t)
These packages are in ~/emacs-scripts/
as specfied in the
load-path in Init file.
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 "\\(--\\|\\)")
)
http://www.emacswiki.org/emacs/SimpleWikiMode
(use-package simple-wiki)
An Emacs mode for editing Wikidot markup
https://github.com/infochimps-customers/wikidot-mode
(use-package wikidot-mode)
http://www.emacswiki.org/emacs/PrintingPackage
(use-package printing
:config
(pr-update-menus t))
Uniquify buffer names. See e.g. here or here.
(require 'uniquify)
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"))
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@]+\\)")
- 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))
(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)
(global-set-key (kbd "<menu>") 'nil)
(blink-cursor-mode 0)
(setq shift-select-mode nil)
(setq mouse-yank-at-point t)
(setq transient-mark-mode t)
(show-paren-mode t)
(recentf-mode 1)
(global-set-key "\M- " 'hippie-expand)
(setq truncate-lines t)
(setq truncate-lines t)
(add-hook 'minibuffer-setup-hook
(lambda () (setq truncate-lines nil)))
(do not accidentally close emacs)
(setq kill-emacs-query-functions
(cons (lambda () (yes-or-no-p "Really Quit Emacs? "))
kill-emacs-query-functions))
(put 'upcase-region 'disabled nil)
(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
(defalias 'list-buffers 'ibuffer)
(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)))
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-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)
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")))
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)
)))
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)))