Cross platform [1], Free Software [2], almost all features you can think of, graphical and in the shell: Learn once, use for everything [3].
» Get Emacs [4] «
Emacs is a self-documenting, extensible editor, a development environment and a platform for lisp-programs - for example programs to make programming easier, but also for todo-lists on steroids [5], reading email, posting to identi.ca [6], and a host of other stuff (learn lisp [7]).
It is one of the origins of GNU [8] and free software [9] (Emacs History [10]).
In Markdown-mode it looks like this:
More on emacs on my german Emacs page [11].
Update (2017-05): babcore is at 0.2, but I cannot currently update the marmalade package.
PDF-version [12] (for printing)
Package [13] (to install)
orgmode-version [14] (for editing)
repository [15] (for forking)
project page [16] (for fun ☺)
Emacs Lisp [17] (to use)
I have been tweaking my emacs configuration for years, now, and I added quite some cruft. But while searching for the right way to work, I also found some gems which I direly miss in pristine emacs.
This file is about those gems.
Babcore is strongly related to Prelude [18]. Actually it is just like prelude, but with the stuff I consider essential. And staying close to pristine Emacs, so you can still work at a coworkers desk.
But before we start, there is one crucial piece of advice which everyone who uses Emacs should know:
C-g: abort
Hold control and hit g.
That gets you out of almost any situation. If anything goes wrong, just hit C-g repeatedly till the problem is gone - or you cooled off far enough to realize that a no-op is the best way to react.
To repeat: If anything goes wrong, just hit C-g.
As Emacs package, babcore needs a proper header.
;; Copyright (C) 2013 Arne Babenhauserheide ;; Author: Arne Babenhauserheide (and various others in Emacswiki and elsewhere). ;; Maintainer: Arne Babenhauserheide ;; Created 03 April 2013 ;; Version: 0.1.0 ;; Version Keywords: core configuration ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License ;; as published by the Free Software Foundation; either version 3 ;; of the License, or (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/ [19]>. ;;; Commentary: ;; Quick Start / installation: ;; 1. Download this file and put it next to other files Emacs includes ;; 2. Add this to you .emacs file and restart emacs: ;; ;; (require 'babcore) ;; ;; Alternatively install via package.el: ;; ;; (require 'package) ;; (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/")) ;; (package-refresh-contents) ;; (package-install 'babcore) ;; ;; Use Case: Use a common core configuration so you can avoid the ;; tedious act of gathering all the basic stuff over the years and ;; can instead concentrate on the really cool new stuff Emacs offers ;; you. ;; ;;; Change Log: ;; 2016-06-05 - 0.1.0: replace desktop with better savehist config and ;; cleanup babcore. Replace flymake with flycheck. ;; Remove the eval-region key-chord. Simplify ;; x-urgent. Fix switching back from full-screen ;; mode. Remove babcore-shell-execute, since ;; async-shell-command (M-&) is a built-in which ;; does the job better. Add C-M-. as third alias ;; for goto-last-change. Add find-file-as-root and ;; a few fixes for encumbering behavior. ;; 2013-11-02 - Disable clipboard sync while exporting with org-mode ;; org-export-dispatch ;; 2013-10-22 - More useful frame titles ;; 2013-04-03 - Minor adjustments ;; 2013-02-29 - Initial release ;;; Code:
Additionally it needs the proper last line. See finish up for details.
The first thing you need in emacs 24. This gives you a convenient way to install just about anything, so you really should use it.
Also I hope that it will help consolidate the various emacs tips which float around into polished packages by virtue of giving people ways to actually get the package by name - and keep it updated almost automatically.
;; Convenient package handling in emacs (require 'package) ;; use packages from marmalade (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/")) ;; and the old elpa repo (add-to-list 'package-archives '("elpa-old" . "http://tromey.com/elpa/")) ;; and automatically parsed versiontracking repositories. (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/")) ;; Make sure a package is installed (defun package-require (package) "Install a PACKAGE unless it is already installed or a feature with the same name is already active. Usage: (package-require 'package)" ; try to activate the package with at least version 0. (package-activate package '(0)) ; try to just require the package. Maybe the user has it in his local config (condition-case nil (require package) ; if we cannot require it, it does not exist, yet. So install it. (error (progn (package-install package) (require package))))) ;; Initialize installed packages (package-initialize) ;; package init not needed, since it is done anyway in emacs 24 after reading the init ;; but we have to load the list of available packages, if it is not available, yet. (when (not package-archive-contents) (with-timeout (15 (message "updating package lists failed due to timeout")) (package-refresh-contents)))
Flycheck is an example of a quite complex feature which really everyone should have.
It can check any kind of code, and actually anything which can be verified with a program which gives line numbers.
This is a drop-in replacement for the older flymake. See Spotlight: Flycheck, a Flymake replacement [20] for reasons to switch to flycheck.
;; Flycheck: On the fly syntax checking (package-require 'flycheck) (add-hook 'after-init-hook #'global-flycheck-mode) ; stronger error display (defface flycheck-error '((t (:foreground "red" :underline (:color "Red1" :style wave) :weight bold))) "Flycheck face for errors" :group "flycheck")
This gives you inline auto-completion preview with an overlay window - even in the text-console. Partially this goes as far as API-hints (for example for elisp code). Absolutely essential.
;; Inline auto completion and suggestions (package-require 'auto-complete) ;; avoid competing with org-mode templates. (add-hook 'org-mode-hook (lambda () (make-local-variable 'ac-stop-words) (loop for template in org-structure-template-alist do (add-to-list 'ac-stop-words (concat "<" (car template))))))
To select a file in a huge directory, just type a few letters from that file in the correct order, leaving out the non-identifying ones. Darn cool!
; use ido mode for file and buffer Completion when switching buffers (require 'ido) (ido-mode t)
Printing in pristine emacs is woefully inadequate, even though it is a standard function in almost all other current programs.
It can be easy, though:
;; Convenient printing (require 'printing) (pr-update-menus t) ; make sure we use localhost as cups server (setenv "CUPS_SERVER" "localhost") (package-require 'cups)
Code folding is pretty cool to get an overview of a complex structure. So why shouldn’t you be able to do that with any kind of structured data?
; use allout minor mode to have outlining everywhere. (allout-mode)
Font-lock is the emacs name for syntax highlighting - in just about anything.
; syntax highlighting everywhere (global-font-lock-mode 1)
Org-mode is that kind of simple thing which evolves to a way of life when you realize that most of your needs actually are simple - and that the complex things can be done in simple ways, too.
It provides simple todo-lists, inline-code evaluation (as in this file) and a full-blown literate programming, reproducible research publishing platform. All from the same simple basic structure.
It might change your life… and it is the only planning solution which ever prevailed against my way of life and organization.
; Activate org-mode (require 'org) ; and some more org stuff ; http://orgmode.org/guide/Activation.html#Activation ; The following lines are always needed. Choose your own keys. (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
; And add babel inline code execution ; babel, for executing code in org-mode. (org-babel-do-load-languages 'org-babel-load-languages ; load all language marked with (lang . t). '((C . t) (R . t) (asymptote) (awk) (calc) (clojure) (comint) (css) (ditaa . t) (dot . t) (emacs-lisp . t) (fortran) (gnuplot . t) (haskell) (io) (java) (js) (latex) (ledger) (lilypond) (lisp) (matlab) (maxima) (mscgen) (ocaml) (octave) (org . t) (perl) (picolisp) (plantuml) (python . t) (ref) (ruby) (sass) (scala) (scheme) (screen) (sh . t) (shen) (sql) (sqlite)))
If you’re used to other editors, you’ll want to see lines wrapped nicely at the word-border instead of lines which either get cut at the end or in the middle of a word.
global-visual-line-mode gives you that.
; Add proper word wrapping (global-visual-line-mode t)
This is the kind of feature which looks tiny: Go to the place where you last changed something.
And then you get used to it and it becomes absolutely indispensable.
; go to the last change (package-require 'goto-chg) (global-set-key [(control .)] 'goto-last-change) ; M-. can conflict with etags tag search. But C-. can get overwritten ; by flyspell-auto-correct-word. And goto-last-change needs a really ; fast key. (global-set-key [(meta .)] 'goto-last-change) ; ensure that even in worst case some goto-last-change is available (global-set-key [(control meta .)] 'goto-last-change)
Whenever you write prosa, a spellchecker is worth a lot, but it should not unnerve you.
Install aspell [21], then activate flyspell-mode whenever you need it.
It needs some dabbling, though, to make it work nicely with non-english text.
(require 'flyspell) ; Make german umlauts work. (setq locale-coding-system 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (prefer-coding-system 'utf-8) ;aspell und flyspell (setq-default ispell-program-name "aspell") ;make aspell faster but less correctly (setq ispell-extra-args '("--sug-mode=ultra" "-w" "äöüÄÖÜßñ")) (setq ispell-list-command "list")
If you have to do the same action repeatedly, for example with flyspell hitting next-error and next-correction hundreds of times, the need to press control can really be a strain for your fingers.
Sure, you can use viper-mode and retrain your hands for the completely alien command set of vim.
A simpler solution is adding a sticky control key - and that’s what control-lock does: You get modal editing with your standard emacs commands.
Since I am a german, I simply use the german umlauts to toggle the control-lock. You will likely want to choose your own commands here.
; control-lock-mode, so we can enter a vi style command-mode with standard emacs keys. (package-require 'control-lock) ; also bind M-ü and M-ä to toggling control lock. (global-set-key (kbd "M-ü") 'control-lock-toggle) (global-set-key (kbd "C-ü") 'control-lock-toggle) (global-set-key (kbd "M-ä") 'control-lock-toggle) (global-set-key (kbd "C-ä") 'control-lock-toggle) (global-set-key (kbd "C-z") 'control-lock-toggle)
This is the second strike for saving your pinky. Yes, Emacs is hard on the pinky. Even if it were completely designed to avoid strain on the pinky, it would still be hard, because any system in which you do not have to reach for the mouse is hard on the pinky.
But it also provides some of the neatest tricks to reduce that strain, so you can make Emacs your pinky saviour.
The key chord mode allows you to hit any two keys at (almost) the same time to invoke commands. Since this can interfere with normal typing, I would only use it for letters which are rarely typed after each other.
These default chords have proven themselves to be useful in years of working with Emacs.
; use key chords invoke commands (package-require 'key-chord) (key-chord-mode 1) ; buffer actions (key-chord-define-global "vb" 'eval-buffer) (key-chord-define-global "cy" 'yank-pop) (key-chord-define-global "cg" "\C-c\C-c") ; frame actions (key-chord-define-global "xo" 'other-window); (key-chord-define-global "x1" 'delete-other-windows) (key-chord-define-global "x0" 'delete-window) (defun kill-this-buffer-if-not-modified () (interactive) ; taken from menu-bar.el (if (menu-bar-non-minibuffer-window-p) (kill-buffer-if-not-modified (current-buffer)) (abort-recursive-edit))) (key-chord-define-global "xk" 'kill-this-buffer-if-not-modified) ; file actions (key-chord-define-global "bf" 'ido-switch-buffer) (key-chord-define-global "cf" 'ido-find-file) (key-chord-define-global "vc" 'vc-next-action)
To complement these tricks, you should also install and use workrave [22] or at least type-break-mode [23].
These are ways to improve the integration of Emacs in a graphical environment.
We have this cool editor. But it is from the 90s, and some of the more modern concepts of graphical programs have not yet been integrated into its core. Maybe because everyone just adds them to the custom setup :)
On the other hand, Emacs always provided split windows and many of the “new” window handling functions in dwm and similar - along with a level of integration with which normal graphical desktops still have to catch up. Open a file, edit it as text, quickly switch to org-mode to be able to edit an ascii table more efficiently, then switch to html mode to add some custom structure - and all that with a consistent set of key bindings.
But enough with the glorification, let’s get to the integration of stuff where Emacs arguably still has weaknesses.
Get the current Emacs frame to the front. You can for example call this via emacsclient and set it as a keyboard shortcut in your desktop (for me it is F12):
emacsclient -e "(show-frame)"
This sounds much easier than it proves to be in the end… but luckily you only have to solve it once, then you can google it anywhere…
(defun show-frame (&optional frame) "Show the current Emacs frame or the FRAME given as argument. And make sure that it really shows up!" (raise-frame) ; yes, you have to call this twice. Don’t ask me why… ; select-frame-set-input-focus calls x-focus-frame and does a bit of ; additional magic. (select-frame-set-input-focus (selected-frame)) (select-frame-set-input-focus (selected-frame)))
Make Emacs announce itself in the tray.
;; let emacs blink when something interesting happens. ;; in KDE this marks the active Emacs icon in the tray. (defun x-urgency-hint (frame arg &optional source) "Set the x-urgency hint for the frame to arg: - If arg is nil, unset the urgency. - If arg is any other value, set the urgency. If you unset the urgency, you still have to visit the frame to make the urgency setting disappear (at least in KDE)." (let* ((wm-hints (append (x-window-property "WM_HINTS" frame "WM_HINTS" source nil t) nil)) (flags (car wm-hints))) (setcar wm-hints (if arg (logior flags #x100) (logand flags (lognot #x100)))) (x-change-window-property "WM_HINTS" wm-hints frame "WM_HINTS" 32 t))) (defun x-urgent (&optional arg) "Mark the current emacs frame as requiring urgent attention. With a prefix argument which does not equal a boolean value of nil, remove the urgency flag (which might or might not change display, depending on the window manager)." (interactive "P") (let (frame (selected-frame)) (x-urgency-hint frame (not arg))))
Hit F11 to enter fullscreen mode. Any self-respecting program should have that… and now Emacs does, too.
; fullscreen, taken from http://www.emacswiki.org/emacs/FullScreen#toc26 ; should work for X und OSX with emacs 23.x (TODO find minimum version). ; for windows it uses (w32-send-sys-command #xf030) (#xf030 == 61488) (defvar babcore-fullscreen-p nil "Check if fullscreen is on or off") (defvar babcore-stored-frame-width nil "width of the frame before going fullscreen") (defvar babcore-stored-frame-height nil "width of the frame before going fullscreen") (defun babcore-non-fullscreen () (interactive) (if (fboundp 'w32-send-sys-command) ;; WM_SYSCOMMAND restore #xf120 (w32-send-sys-command 61728) (progn (set-frame-parameter nil 'fullscreen nil) (set-frame-parameter nil 'width (if babcore-stored-frame-width babcore-stored-frame-width 82)) (sleep-for 0 1) ; 1ms sleep: workaround to avoid unsetting the width in the next command (set-frame-parameter nil 'height (if babcore-stored-frame-height babcore-stored-frame-height 42))))) (defun babcore-fullscreen () (interactive) (setq babcore-stored-frame-width (frame-width)) (setq babcore-stored-frame-height (frame-height)) (if (fboundp 'w32-send-sys-command) ;; WM_SYSCOMMAND maximaze #xf030 (w32-send-sys-command 61488) (set-frame-parameter nil 'fullscreen 'fullboth))) (defun toggle-fullscreen () (interactive) (setq babcore-fullscreen-p (not babcore-fullscreen-p)) (if babcore-fullscreen-p (babcore-non-fullscreen) (babcore-fullscreen))) (global-set-key [f11] 'toggle-fullscreen)
I always hate it when some usage pattern which is consistent almost everywhere fails with some program. Especially if that is easily avoidable.
This code fixes that for Emacs in KDE.
; Default KDE keybindings to make emacs nicer integrated into KDE. ; can treat C-m as its own mapping. ; (define-key input-decode-map "\C-m" [?\C-1]) (defun revert-buffer-preserve-modes () (interactive) (revert-buffer t nil t)) ; C-m shows/hides the menu bar - thanks to http://stackoverflow.com/questions/2298811/how-to-turn-off-alternative-enter-with-ctrlm-in-linux ; f5 reloads (defconst kde-default-keys-minor-mode-map (let ((map (make-sparse-keymap))) (set-keymap-parent map text-mode-map) (define-key map [f5] 'revert-buffer-preserve-modes) (define-key map [?\C-1] 'menu-bar-mode) (define-key map [?\C-+] 'text-scale-increase) (define-key map [?\C--] 'text-scale-decrease) ; shadows 'negative-argument which is also available via M-- and C-M--, though. (define-key map [C-kp-add] 'text-scale-increase) (define-key map [C-kp-subtract] 'text-scale-decrease) map) "Keymap for `kde-default-keys-minor-mode'.") ;; Minor mode for keypad control (define-minor-mode kde-default-keys-minor-mode "Adds some default KDE keybindings" :global t :init-value t :lighter "" :keymap 'kde-default-keys-minor-mode-map )
The titles of windows of GNU Emacs normally look pretty useless (just stating emacs@host), but it’s easy to make them display useful information:
;; Set the frame title as by http://www.emacswiki.org/emacs/FrameTitle (setq frame-title-format (list "%b ☺ " (user-login-name) "@" (system-name) "%[ - GNU %F " emacs-version) icon-title-format (list "%b ☻ " (user-login-name) "@" (system-name) " - GNU %F " emacs-version))
Now we can always see the name of the open buffer in the frame. No more searching for the right emacs window to switch to in the window list.
Actually you do not need any configuration here. Just use
M-x ucs-insert
To insert any unicode character. If you want to see them while selecting, have a look at xub-mode [24] from Ergo Emacs.
This is a default feature in most IDEs. Since Emacs allows you to build your own IDE, it does not offer it by default… but it should, since that does not disturb anything. So we add it.
fic-ext-mode highlight TODO and FIXME in comments for common programming languages.
;; Highlight TODO and FIXME in comments (package-require 'fic-ext-mode) (defun add-something-to-mode-hooks (mode-list something) "helper function to add a callback to multiple hooks" (dolist (mode mode-list) (add-hook (intern (concat (symbol-name mode) "-mode-hook")) something))) (add-something-to-mode-hooks '(c++ tcl emacs-lisp python text markdown latex) 'fic-ext-mode)
Now for something which should really be provided by default: You just wrote a cool emacs macro, and you are sure that you will need that again a few times.
Well, then save it!
In standard emacs that needs multiple steps. And I hate that. Something as basic as saving a macro should only need one single step. It does now (and Emacs is great, because it allows me to do this!).
This bridges the gap between function definitions and keyboard macros, making keyboard macros something like first class citizens in your Emacs.
; save the current macro as reusable function. (defun save-current-kbd-macro-to-dot-emacs (name) "Save the current macro as named function definition inside your initialization file so you can reuse it anytime in the future." (interactive "SSave Macro as: ") (name-last-kbd-macro name) (save-excursion (find-file-literally user-init-file) (goto-char (point-max)) (insert "\n\n;; Saved macro\n") (insert-kbd-macro name) (insert "\n")))
If you have a diary or similar, you should really use this. It only takes a few lines of code, but these few lines are the difference between encryption for those who know they need it and encryption for everyone.
; Activate transparent GnuPG encryption. (require 'epa-file) (epa-file-enable)
A shell without colors is really hard to read. Use M-&
to run your shell-commands asynchronously and in shell-mode (via async-shell-command
).
This is just an aestetic value: Use the directories from the freedesktop specification for save files.
Thanks to the folks at CERN [25] for this.
(setq backup-by-copying t ; don't clobber symlinks backup-directory-alist '(("." . "~/.local/share/emacs-saves")) ; don't litter my fs tree delete-old-versions t kept-new-versions 6 kept-old-versions 2 version-control t) ; use versioned backups
If I restart the computer I want my editor to make it easy for me to continue where I left off.
It’s bad enough that most likely my brain buffers were emptied. At least my editor should remember how to go on.
If I reopen a file, I want to start at the line at which I was when I closed it.
; save the place in files (require 'saveplace) (setq-default save-place t)
And I want to be able to call my recent commands in the minibuffer. I normally don’t type the full command name anyway, but rather C-r followed by a small part of the command. Losing that on restart really hurts, so I want to avoid that loss.
; save minibuffer history (require 'savehist) ;; increase the default history cutoff (setq history-length 500) (savehist-mode t) (setq savehist-additional-variables '(regexp-search-ring register-alist))
If this does not suffice for you, have a look at desktop [26], the chainsaw of Emacs persistency.
Finally one more minor adaption: Treat the clipboard gracefully. This is a tightrope stunt and getting it wrong can feel awkward.
This is the only setting for which I’m not sure that I got it right, but it’s what I use…
(setq x-select-enable-clipboard t)
But do not synchronize anything to the clipboard or primary selection (mouse-selection) while compiling an org-mode file. When I have it enabled, compiling an org-mode file to PDF locks KDE - I think it does so by filling up the clipboard. So the system clipboard is disabled, now, and I use the mouse-selection to transfer text from emacs to other parts.
; When I have x-select-enable-clipboard enabled, compiling an org-mode file to PDF locks ; KDE - I think it does so by filling up the clipboard. (defadvice org-export-dispatch-no-clipboard-advice (around org-export-dispatch) "Do not clobber the system-clipboard while compiling an org-mode file with `org-export`." (let ((select-active-regions nil) (x-select-enable-clipboard nil) (x-select-enable-primary nil) (interprogram-cut-function nil) (interprogram-paste-function nil)) ad-do-it)) (ad-activate 'org-export-dispatch-no-clipboard-advice t)
In case you mostly write free software, you might be as weary of hunting for the license header and copy pasting it into new files as I am. Free licenses, and especially copyleft licenses, are one of the core safeguards of free culture, because they give free software developers an edge over proprietarizing folks. But they are a pain to add to every file…
Well: No more. We now have legalese mode to take care of the inconvenient legal details for us, so we can focus on the code we write. Just call M-x legalese to add a GPL header, or C-u M-x legalese to choose another license.
(package-require 'legalese)
When I needed to open a file as root to do a quick edit, I used to
dump into a shell and run sudo nano FILE
, just because that was
faster. Since I started using find-current-as-root
, I no longer do
that: Opening the file as root is now convenient enough in Emacs to no
longer tempt me to drop to the shell.
;;; Open files as root - quickly (defcustom find-file-root-prefix "/sudo:root@localhost:" "Tramp root prefix to use.") (defun find-file-as-root () "Like `ido-find-file, but automatically edit the file with root-privileges (using tramp/sudo), if the file is not writable by user." (interactive) (let ((file (ido-read-file-name "Edit as root: "))) (unless (file-writable-p file) (setq file (concat find-file-root-prefix file))) (find-file file))) ;; or some other keybinding... ;; (global-set-key (kbd "C-x F") 'djcb-find-file-as-root) (defun find-current-as-root () "Reopen current file as root" (interactive) (set-visited-file-name (concat find-file-root-prefix (buffer-file-name))) (setq buffer-read-only nil))
This stuff should become obsolete, but at the moment it is still needed to improve the Emacs Experience.
;;;;;;;;;;;;; ;;; Fixes ;;; ;;;;;;;;;;;;;
;; Make comint recognize passwords in virtually all languages. (defcustom comint-password-prompt-regexp (concat "\\(^ *\\|" (regexp-opt '("Enter" "enter" "Enter same" "enter same" "Enter the" "enter the" "Old" "old" "New" "new" "'s" "login" "Kerberos" "CVS" "UNIX" " SMB" "LDAP" "[sudo]" "Repeat" "Bad") t) " +\\)" (regexp-opt '("Adgangskode" "adgangskode" "Contrasenya" "contrasenya" "Contraseña" "contraseña" "Geslo" "geslo" "Hasło" "hasło" "Heslo" "heslo" "Iphasiwedi" "iphasiwedi" "Jelszó" "jelszó" "Lozinka" "lozinka" "Lösenord" "lösenord" "Mot de passe " "Mot de Passe " "mot de Passe " "mot de passe " "Mật khẩu " "mật khẩu" "Parola" "parola" "Pasahitza" "pasahitza" "Pass phrase" "pass Phrase" "pass phrase" "Passord" "passord" "Passphrase" "passphrase" "Password" "password" "Passwort" "passwort" "Pasvorto" "pasvorto" "Response" "response" "Salasana" "salasana" "Senha" "senha" "Wachtwoord" "wachtwoord" "slaptažodis" "slaptažodis" "Лозинка" "лозинка" "Пароль" "пароль" "ססמה" "كلمة السر" "गुप्तशब्द" "शब्दकूट" "গুপ্তশব্দ" "পাসওয়ার্ড" "ਪਾਸਵਰਡ" "પાસવર્ડ" "ପ୍ରବେଶ ସଙ୍କେତ" "கடவுச்சொல்" "సంకేతపదము" "ಗುಪ್ತಪದ" "അടയാളവാക്ക്" "රහස්පදය" "ពាក្យសម្ងាត់ ៖ " "パスワード" "密码" "密碼" "암호")) "\\(?:\\(?:, try\\)? *again\\| (empty for no passphrase)\\| (again)\\)?\ \\(?: for [^:]+\\)?:\\s *\\'") "Regexp matching prompts for passwords in the inferior process. This is used by `comint-watch-for-password-prompt'." :version "24.3" :type 'regexp :group 'comint)
;; Mark all AC_* and AS_* functions as builtin. (add-hook 'autoconf-mode-hook (lambda () (add-to-list 'autoconf-font-lock-keywords '("\\(\\(AC\\|AS\\|AM\\)_.+?\\)\\((\\|\n\\)" (1 font-lock-builtin-face)))))
; tell emacs to ignore alt-gr clicks needed for M4 in the Neo Layout. (define-key special-event-map (kbd "<key-17>") 'ignore) (define-key special-event-map (kbd "<M-key-17>") 'ignore)
When you run yank-pop after a yank, it replaces the yanked text. When you did not do a yank before, it errors out.
This change makes yank-pop yank instead so you can simply hit C-y repeatedly to first yank and then cycle through the yank history.
; yank-pop should yank if the last command was no yank. (defun yank-pop (&optional arg) "Replace just-yanked stretch of killed text with a different stretch. At such a time, the region contains a stretch of reinserted previously-killed text. `yank-pop' deletes that text and inserts in its place a different stretch of killed text. With no argument, the previous kill is inserted. With argument N, insert the Nth previous kill. If N is negative, this is a more recent kill. The sequence of kills wraps around, so that after the oldest one comes the newest one. When this command inserts killed text into the buffer, it honors `yank-excluded-properties' and `yank-handler' as described in the doc string for `insert-for-yank-1', which see." (interactive "*p") (if (not (eq last-command 'yank)) (yank) (setq this-command 'yank) (unless arg (setq arg 1)) (let ((inhibit-read-only t) (before (< (point) (mark t)))) (if before (funcall (or yank-undo-function 'delete-region) (point) (mark t)) (funcall (or yank-undo-function 'delete-region) (mark t) (point))) (setq yank-undo-function nil) (set-marker (mark-marker) (point) (current-buffer)) (insert-for-yank (current-kill arg)) ;; Set the window start back where it was in the yank command, ;; if possible. (set-window-start (selected-window) yank-window-start t) (if before ;; This is like exchange-point-and-mark, but doesn't activate the mark. ;; It is cleaner to avoid activation, even though the command ;; loop would deactivate the mark because we inserted text. (goto-char (prog1 (mark t) (set-marker (mark-marker) (point) (current-buffer)))))) nil))
(setq visible-bell t)
TODO: Adjust vc-find-file-hook to call the vcs tool asynchronously.
Make it possible to just (require 'babcore) and add the proper package footer.
(provide 'babcore) ;;; babcore.el ends here
With the babcore you have a core setup which exposes some of the essential features of Emacs and adds basic integration with the system which is missing in pristine Emacs.
Now go and see the M-x package-list-packages to see where you can still go - or just use Emacs and add what you need along the way. The package list is your friend, as is Emacswiki [27].
Happy Hacking!
Note: As almost everything on this page, this text and code is available under the GPLv3 or later.
I currently cope with refactoring in an upstream project to which I maintain some changes which upstream does not merge. One nasty part is that the project converted from CamelCase for function names to words_with_underscores. And that created lots of merge errors.
Today I finally decided to speed up my work.
The first thing I needed was a function to convert a string in CamelCase to words_with_underscores. Since I’m lazy, I used google, and that turned up the CamelCase page of Emacswiki [28] - and with it the following string functions:
(defun split-name (s) (split-string (let ((case-fold-search nil)) (downcase (replace-regexp-in-string "\\([a-z]\\)\\([A-Z]\\)" "\\1 \\2" s))) "[^A-Za-z0-9]+")) (defun underscore-string (s) (mapconcat 'downcase (split-name s) "_"))
Quite handy - and elegantly executed. Now I just need to make this available for interactive use. For this, Emacs Lisp offers many useful ways to turn Editor information into program information, called interactive codes [29] - in my case the region-code: "r". This gives the function the beginning and the end of the currently selected region as arguments.
With this, I created an interactive function which de-camelcases and underscores the selected region:
(defun underscore-region (begin end) (interactive "r") (let* ((word (buffer-substring begin end)) (underscored (underscore-string word))) (save-excursion (widen) ; break out of the subregion so we can fix every usage of the function (replace-string word underscored nil (point-min) (point-max)))))
And now we’re almost there. Just create a macro which searches for a function, selects its name, de-camelcaeses and underscores it and then replaces every usage of the CamelCase name by the underscored name. This isn’t perfect refactoring (can lead to errors), but it’s fast and I see every change it does.
C-x C-(
C-s def
M-x mark-word
M-x underscore-region
C-x C-)
That’s it, now just call the macro repeatedly.
C-x eeeeee…
Now check the diff to fix where this 13 lines hack got something wrong ( like changing __init__
into _init_
- I won’t debug this, you’ve been warned ☺).
Happy Hacking!
Anhang | Größe |
---|---|
2015-01-14-Mi-camel-case-to-underscore.org [30] | 2.39 KB |
Update (2013-01-23): The new org-mode removed (org-make-link), so I replaced it with (concat) and uploaded a new example-file: org-custom-link-completion.el [31].
Happy Hacking!
I recently set up custom completion for two of my custom link types in Emacs [32] org-mode [5]. When I wrote on identi.ca about that [33], Greg Tucker-Kellog said that he’d like to see that [34]. So I decided, I’d publish my code.
The link types I regularly need are papers (PDFs of research papers I take notes about) and bib (the bibtex entries for the papers). The following are my custom link definitions :
(setq org-link-abbrev-alist '(("bib" . "~/Dokumente/Uni/Doktorarbeit-inverse-co2-ch4/aufschriebe/ref.bib::%s") ("notes" . "~/Dokumente/Uni/Doktorarbeit-inverse-co2-ch4/aufschriebe/papers.org::#%s") ("papers" . "~/Dokumente/Uni/Doktorarbeit-inverse-co2-ch4/aufschriebe/papers/%s.pdf")))
For some weeks I had copied the info into the links by hand. Thus an entry about a paper looks like the following.
* Title [[bib:identifier]] [[papers:name_without_suffix]]
This already suffices to be able to click the links for opening the PDF or showing the bibtex entry. Entering the links was quite inconvenient, though.
The trick to completion in org-mode is to create the function org-LINKTYPE-complete-link.
Let’s begin with the papers-links, because their completion is more basic than the completion of the bib-link.
First I created a helper function to replace all occurrences of a substring in a string1.
(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))))
As you can see, it’s quite simple: Just create a temporary buffer and and use the default replace-string function I’m using daily while editing. Don’t assume I had figured out that elegant way myself. I just searched for it in the net and adapted the nicest code I found :)
Now we get to the real completion:
<<string-replace>> (defun org-papers-complete-link (&optional arg) "Create a papers link using completion." (let (file link) (setq file (read-file-name "papers: " "papers/")) <<cleanup-link>> link))
The real magic is in read-file-name. That just uses the file-completion with a custom command prefix.
cleanup-link is only a small list of setq’s which removes parts of the filepath to make it compatible with the syntax for paper-links:
(let ((pwd (file-name-as-directory (expand-file-name "."))) (pwd1 (file-name-as-directory (abbreviate-file-name (expand-file-name "."))))) (setq file (string-replace "papers/" "" file)) (setq file (string-replace pwd "" (string-replace pwd1 "" file))) (setq file (string-replace ".pdf" "" file)) (setq link (concat "papers:" file)))
And that’s it. A few lines of simple elisp and I have working completion for a custom link-type which points to research papers - and can easily be adapted when I change the location of the papers.
Now don’t think I would have come up with all that elegant code myself. My favorite language is Python and I don’t think that I should have to know emacs lisp as well as Python. So I copied and adapted most of it from existing functions in emacs. Just use C-h C-f <function-name> and then follow the link to the code :)
Remember: This is free software. Reuse and learning from existing code is not just allowed but encouraged.
For the bib-links, I chose an even easier way. I just reused reftex-do-citation from reftex-mode:
<<reftex-setup>> (defun org-bib-complete-link (&optional arg) "Create a bibtex link using reftex autocompletion." (concat "bib:" (reftex-do-citation nil t nil)))
For reftex-do-citation to allow using the bib-style link, I needed some setup, but I already had that in place for explicit citation inserting (not generalized as link-type), so I don’t count following as part of the actual implementation. Also I likely copied most of it from emacs-wiki [3] :)
(defun org-mode-reftex-setup () (interactive) (and (buffer-file-name) (file-exists-p (buffer-file-name)) (progn ; Reftex should use the org file as master file. See C-h v TeX-master for infos. (setq TeX-master t) (turn-on-reftex) ; don’t ask for the tex master on every start. (reftex-parse-all) ;add a custom reftex cite format to insert links (reftex-set-cite-format '((?b . "[[bib:%l][%l-bib]]") (?n . "[[notes:%l][%l-notes]]") (?p . "[[papers:%l][%l-paper]]") (?t . "%t") (?h . "** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l-paper]]"))))) (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)
And that’s it. My custom link types now support useful completion.
For papers, I get an interactive file-prompt to just select the file. It directly starts in the papers folder, so I can simply enter a few letters which appear in the paper filename and hit enter (thanks to ido-mode).
For bibtex entries, a reftex-window opens in a lower split-screen and asks me for some letters which appear somewhere in the bibtex entry. It then shows all fitting entries in brief but nice format and lets me select the entry to enter. I simply move with the arrow-keys, C-n/C-p, n/p or even C-s/C-r for searching, till the correct entry is highlighted. Then I hit enter to insert it.
And that’s it. I hope you liked my short excursion into the world of extending emacs to stay focussed while connecting seperate data sets.
I never saw a level of (possible) integration and consistency anywhere else which even came close to the possibilities of emacs.
And by the way: This article was also written in org-mode, using its literate programming features [35] for code-samples which can actually be executed and extracted [36] at will.
To put it all together I just need the following:
<<org-papers-complete-link>> <<org-bib-complete-link>>
Now I use M-x org-babel-tangle to write the code to the file org-custom-link-completion.el. I attached that file for easier reference: org-custom-link-completion.el [31] :)
Have fun with Emacs!
PS: Should something be missing here, feel free to get it from my public .emacs.d [15]. I only extracted what seemed important, but I did not check if it runs in a pristine Emacs. My at-home branch is “fluss [37]”.
1 : Creating a custom function for string replace might not have been necessary, because some function might already exist for that. But writing it myself was faster than searching for it.
Anhang | Größe |
---|---|
2012-06-15-emacs-link-completion-bib.png [38] | 77.24 KB |
2012-06-15-Fr-org-link-completion.org [39] | 7.29 KB |
org-custom-link-completion.el [31] | 2.13 KB |
Nature [40] only gives me ris-formatted [41] citations, but I use bibtex [42].
Also ris is far from human readable.
ris can be reformatted to bibtext, but doing that manually disturbs my workflow when getting references while taking note about a paper in emacs.
I tend to search online for references, often just using google scholar [43], so when I find a ris reference, the first data I get for the ris-citation is a link.
bibutils [44]1 can convert ris to an intermediate xml format and then convert that to bibtex.
wget -O reference.ris RIS_URL
cat reference.ris | ris2xml | xml2bib >> ref.bib
This solves the problem, but it is not convenient, because I have to switch to the terminal, download the file, convert it and append the result to my bibtex file.
With the first step, getting the ris-citation is quite inconvenient. I need 3 steps just for getting a citation.
But those steps are always the same, and since I use Emacs [45], I can automate and integrate them very easily. So I created a simple function in emacs, which takes the url of a ris citation, converts it to bibtex and appends the result to my local bibtex file. Now I get a ris citation with a simple call to
M-x ris-citation-to-bib
Then I enter the url and the function appends the citation to my bibtex file.2
Feel free to integrate it into your own emacs setup (additionally to the GPLv3 [46] you can use any license used by emacswiki [3] or worg [47]).
(defun ris-citation-to-bib (&optional ris-url) "get a ris citation as bibtex in one step. Just call M-x ris-citation-to-bib and enter the ris url. Requires bibutils: http://sourceforge.net/p/bibutils/home/Bibutils/ " (interactive "Mris-url: ") (save-excursion (let ((bib-file "/home/arne/aufschriebe/ref.bib") (bib-buffer (get-buffer "ref.bib")) (ris-buffer (url-retrieve-synchronously ris-url))) ; firstoff check if we have the bib buffer. If yes, move point to the last line. (if (not (member bib-buffer (buffer-list))) (setq bib-buffer (find-file-noselect bib-file))) (progn (set-buffer bib-buffer) (goto-char (point-max))) (if ris-buffer (set-buffer ris-buffer)) (shell-command-on-region (point-min) (point-max) "ris2xml | xml2bib" ris-buffer) (let ((pmin (- (search-forward "@") 1)) (pmax (search-forward "}
"))) (if (member bib-buffer (buffer-list)) (progn (append-to-buffer bib-buffer pmin pmax) (kill-buffer ris-buffer) (set-buffer bib-buffer) (save-buffer) ))))))
Happy Hacking!
PS: When I don’t have the URL (many thanks to journals giving me only a download button), I open the file, select the content and hit M-|
(shell-command-on-region) with ris2xml | xml2bib
(searching backwards via C-r ris
so I to avoid typing the exact command) and get the bibtex version in the results buffer.
Kanban [48] for emacs [32] org-mode [49].
Update (2020): Kanban moved to sourcehut: https://hg.sr.ht/~arnebab/kanban.el [50]
Update (2013-04-13): Kanban.el now lives in its own repository: on bitbucket [51] and on a statically served http-repo [52] (to be independent from unfree software).
Update (2013-04-10): Thanks to Han Duply, kanban links now work for entries from other files. And I uploaded kanban.el on marmalade [53].
Some time ago I learned about kanban, and the obvious next step was: “I want to have a kanban board from org-mode”. I searched for it, but did not find any. Not wanting to give up on the idea, I implemented my own :)
The result are two functions: kanban-todo and kanban-zero.
TODO DOING DONE Refactor in such a way that the let Presentation manage dumb sprites return all actions on every command: Make the UiState adhere the list of Turn the model into a pure state
kanban-todo provides your TODO items as kanban-fields. You can move them in the table without having duplicates, so all the state maintenance is done in the kanban table. Once you are finished, you mark them as done and delete them from the table.
To set it up, put kanban.el [54] somewhere in your load path and (require 'kanban)
(more recent but potentially unstable version [55]). Then just add a table like the following:
| | | |
|---+---+---|
| | | |
| | | |
| | | |
| | | |
#+TBLFM: $1='(kanban-todo @# @2$2..@>$>)::@1='(kanban-headers $#)
Click C-c C-c
with the point on the TBLFMT line to update the table.
The important line is the #+TBLFM. That says “use my TODO items in the TODO column, except if they are in another column” and “add kanban headers for my TODO states”
The kanban-todo function takes an optional parameter match, which you can use to restrict the kanban table to given tags. The syntax is the same as for org-mode matchers [56]. The third argument allows you to provide a scope [57], for example a list of files.
To only set the scope, use nil
for the matcher.
See C-h f org-map-entries
and C-h v org-agenda-files
for details.
kanban-zero is a zero-state Kanban: All state is managed in org-mode and the table only displays the kanban items.
To set it up, put kanban.el [54] somwhere in your load path and (require 'kanban)
. Then just add a table like the following:
| | | |
|---+---+---|
| | | |
| | | |
| | | |
| | | |
#+TBLFM: @2$1..@>$>='(kanban-zero @# $#)::@1='(kanban-headers $#)
The important line is the #+TBLFM. That says “show my org items in the appropriate column” and “add kanban headers for my TODO states”.
Click C-c C-c
with the point on the TBLFMT line to update the table.
The kanban-zero function takes an optional parameter match, which you can use to restrict the kanban table to given tags. The syntax is the same as for org-mode matchers [56]. The third argument allows you to provide a scope [57], for example a list of files.
To only set the scope, use nil
for the matcher.
An example for matcher and scope would be:
#+TBLFM: @2$1..@>$>='(kanban-zero @# $# "1w6" '("/home/arne/.emacs.d/private/org/emacs-plan.org"))::@1='(kanban-headers $#)
See C-h f org-map-entries
and C-h v org-agenda-files
for details.
To contribute to kanban.el, just change the file and write a comment about your changes. Maybe I’ll setup a repo on Bitbucket at some point…
In the Hexbattle [58] game-draft, I use kanban to track my progress:
Table of Contents
- 1 Kanban
- 2 refactor Hexbattle
- 2.1 Structure plan:
- 2.2 First all logic from UiState into the model. Model gets all state which is independent of the UI. Any necessary interaction in UiState calls model methods. √
- 2.3 Refactor in such a way that the UiState and (even more importantly) the input do not need to call the model directly anymore.
- 2.4 Make the UiState adhere the list of possible commands.
- 2.5 Turn the model into a pure state machine.
1 Kanban
❢ STARTED ✔ Refactor in such a way that the let Presentation manage dumb sprites return all actions on every command: Make the UiState adhere the list of Turn the model into a pure state 2 refactor Hexbattle 1w6
… and so on …
To make the todo states easier to grok directly you can use unicode symbols for them. Example:
#+SEQ_TODO: ❢ ☯ ⧖ | ☺ ✔ DEFERRED ✘
| ❢ | ☯ | ⧖ | ☺ | |---+---+---+---| | | | | | #+TBLFM: @1='(kanban-headers $#)::@2$1..@>$>='(kanban-zero @# $#)
In my setup they are ❢ (todo) ☯ (doing) ⧖ (waiting) and ☺ (to report). Not shown in the kanban Table are ✔ (finished), ✘ (dropped) and deferred (later), because they don’t require any action from me, so I don’t need to see them all the time.
If you want to create a shared kanban table, you can use the excellent transparent network access options from Emacs tramp to collect kanban entries directly via SSH.
To use that, simply pass an explicit list of files to kanban-zero as 4th argument (if you don’t use tag matching just use nil as 3rd argument). "/ssh:host:path/to/file.org" retrieves the file ~/path/to/file.org from the host.
| ❢ | ☯ | |---+---| | | | #+TBLFM: @1='(kanban-headers $#)::@2$1..@>$>='(kanban-zero @# $# nil (list (buffer-file-name) "/ssh:localhost:plan.org"))
Caveeat: all included kanban files have to use at least some of the same todo states: kanban.el only retrieves TODO states which are used in the current buffer.
Anhang | Größe |
---|---|
kanban.el [54] | 5.86 KB |
I use Emacs [4] Org-Mode [5] for writing all kinds of articles. The standard format for org-mode is to show the table of contents before all other content, but that requires people to scroll down to see whether the article is interesting for them. Therefore I want the abstract to be shown before the table of contents.
There is an old guide for showing the abstract before the TOC in org-mode<8 [59], but since I use org-mode 8, that wasn’t applicable to me.
With a short C-h v org-toc TAB TAB (means: search all variables which start with org- and containt -toc) I found the following even simpler way. After I got that solution working, I found that this was still much too complex and that org-mode actually provides an even easier and very convenient way to add the TOC at any place.
(from the manual [60])
At the beginning of your file (after the title) add
#+OPTIONS: toc:nil
Then after the abstract add a TOC:
#+BEGIN_ABSTRACT Abstract #+END_ABSTRACT #+TOC: headlines 2
Done. Have fun with org-mode!
This is the complicated way I tried first. It only works with LaTeX, but there it works. Better use the simple way.
Set org-export-with-toc to nil as file-local variable. This means you just append the following to the file:
# Local Variables: # org-export-with-toc: nil # End:
(another nice local variable is org-confirm-babel-evaluate: nil, but don’t set that globally, otherwise you could run untrusted code when you export org-mode files from others. When this is set file-local, emacs will ask you for each file you open whether you want to accept the variable setting)
Then write the abstract before the first heading and add tableofcontents after it. Example:
#+BEGIN_ABSTRACT Abstract #+END_ABSTRACT #+LATEX: \tableofcontents
Anhang | Größe |
---|---|
2013-11-21-Do-emacs-orgmode-abstract-before-toc.pdf [61] | 143.29 KB |
2013-11-21-Do-emacs-orgmode-abstract-before-toc.org [62] | 2.23 KB |
As example: Connecting to #youbroketheinternet.
emerge privoxy torsocks net-vpn/tor # rc-config start privoxy tor # rc-update add privoxy default # rc-update add tor default mkdir -p ~/.local/EMACS_TOR_HOME/.emacs.d echo "(require 'socks)" >> ~/.local/EMACS_TOR_HOME/.emacs.d/init.el HOME=~/.local/EMACS_TOR_HOME torify emacs --title "Emacs-torified" # M-x customize-variable RET socks-server RET # host: localhost # port: 9050 # type: Socks v5 # (C-x C-s to save and set) # M-x erc-select # server loupsycedyglgamf.onion # port 67 # the welcome channel is good to go.
@marjoleink asked on identi.ca [65]1, if it is possible to use emacs org-mode for showing scaled screenshots inline while writing. Since I thought I’d enjoy some hacking, I decided to take the challenge.
It does not do auto-scaling of embedded images, as far as I know, but the use case of screenshots can be done with a simple function (add this to your ~/.emacs or ~/.emacs.d/init.el):
(defun org-insert-scaled-screenshot () "Insert a scaled screenshot for inline display into your org-mode buffer." (interactive) (let ((filename (concat "screenshot-" (substring (shell-command-to-string "date +%Y%m%d%H%M%S") 0 -1 ) ".png"))) (let ((scaledname (concat filename "-width300.png")))
(shell-command (concat "import -window root " filename)) (shell-command (concat "convert -adaptive-resize 300 " filename " " scaledname)) (insert (concat "[[./" scaledname "]]")))))
Now just call M-x org-redisplay-inline-images
to see the screenshot (or add it to the function).
In action:
Have fun with Emacs - and happy hacking!
PS: In case it’s not obvious: The screenshot shows emacs just as the screenshot is being shot - with the method shown here ☺)
Matthew Gregg: @marjoleink "way of life" thing again, but if you can invest some time, org-mode is a really powerful note keeping environment. → Marjolein Katsma: @mcg I'm sure it is - but seriously: can you embed a diagram2 or screenshot, scale it, and link it to itself? ↩
For diagrams, you can just insert a link to the image file without description, then org-mode can show it inline. To get an even nicer user-experience (plain text diagrams or ascii-art), you can use inline code via org-babel [66] using graphviz (dot) or ditaa - the latter is used for the diagrams in my complete Mercurial branching strategy [67]. ↩
Anhang | Größe |
---|---|
screenshot-20121122101933-width300.png [68] | 108.08 KB |
screenshot-20121122101933-width600.png [69] | 272.2 KB |
If you want to use the literate programming features in emacs org-mode, you can try this minimal example to get started: Activate org-babel-tangle [70], then put this into the file noweb-test.org
:
Minimal example for noweb in org-mode
* Assign
First we assign abc:
#+begin_src python :noweb-ref assign_abc
abc = "abc"
#+end_src
* Use
Then we use it in a function:
#+begin_src python :noweb tangle :tangle noweb-test.py
def x():
<<assign_abc>>
return abc
print(x())
#+end_src
noweb-test.org [71]
Hit C-c C-c
to evaluate the source block. Hit C-c C-v C-t
to put the expanded code into the file noweb-test.py
.
The exported code looks like this:
def x(): abc = "abc" return abc
print(x())
noweb-test.py [72]
(html generated with org-export-as-html-to-buffer
and slightly reniced to escape the additional parsing I have on my site)
And with org-export-as-pdf
we get this:
noweb-test.pdf [73]
Add :results output
to the #+begin_src
line of the second block to see the print results under that block when you hit C-c C-c
in the block.
You can also use properties of headlines for giving the noweb-ref. Org-mode can then even concatenate several source blocks into one noweb reference. Just hit C-c C-x p
to set a property (or use M-x org-set-property), then set noweb-ref
to the name you want to use to embed all blocks under this heading together.
Note: org-babel prefixes each line of an included code-block with the prefix used for the reference (here <<assign_abc>>
). This way you can easily include blocks inside python [74] functions.
Note: To keep noweb-references literally in the output or similar, have a look at the different options to :noweb [75].
Note: To do this with shell-code, it’s useful to change the noweb markers to {{{ and }}}, because << and >> are valid shell-syntax, so they disturb the highlighting in sh-mode. Also confirming the evaluation every time makes plain exporting problematic. To fix this, just add the following somewhere in the file (to keep this simple, just add it to the end):
# Local Variables:
# org-babel-noweb-wrap-start: "{{{"
# org-babel-noweb-wrap-end: "}}}"
# org-confirm-babel-evaluate: nil
# org-export-allow-bind-keywords: t
# End:
Have fun with Emacs [32] and org-mode [5]!
Anhang | Größe |
---|---|
noweb-test.pdf [73] | 81.69 KB |
noweb-test.org [71] | 290 Bytes |
noweb-test.py.txt [72] | 49 Bytes |
noweb-test-pdf.png [76] | 6.05 KB |
Update 2017: a block with
sem -j ...
seems to block in recent versions of Emacs until all subtasks are done. It would be great if someone could figure out why (though it likely is the right thing to do). To circumvent that, you can daemonize the job in sem, but that might have unwanted side-effects:sem "[job] &"
Emacs [4] Org-mode [5] provides the wonderful babel-capability: Including code-blocks in any language directly in org-mode documents in plain text.
In default usage, running such code freezes my emacs until the code is finished, though.
Up to a few weeks ago, I solved this with a custom function, which spawns a new emacs as script runner for the specific code:
; Execute babel source blocks asynchronously by just opening a new emacs. (defun bab/org-babel-execute-src-block-new-emacs () "Execute the current source block in a separate emacs, so we do not block the current emacs." (interactive) (let ((line (line-number-at-pos)) (file (buffer-file-name))) (async-shell-command (concat "TERM=vt200 emacs -nw --find-file " file " --eval '(goto-line " (number-to-string line) ")' --eval " "'(let ((org-confirm-babel-evaluate nil))(org-babel-execute-src-block t))' " "--eval '(kill-emacs 0)'"))))
and its companion for exporting to beamer-latex presentation pdf:
; Export as pdf asynchronously by just opening a new emacs. (defun bab/org-beamer-export-new-emacs () "Export the current file in a separate emacs, so we do not block the current emacs." (interactive) (let ((line (line-number-at-pos)) (file (buffer-file-name))) (async-shell-command (concat "TERM=vt200 emacs -nw --find-file " file " --eval '(goto-line " (number-to-string line) ")' --eval " "'(let ((org-confirm-babel-evaluate nil))(org-beamer-export-to-pdf))' " "--eval '(kill-emacs 0)'"))))
But for shell-scripts there’s a much simpler alternative:
Instead of spawning an external process, I can just use GNU Parallel [77] for the long-running program-calls in the shell-code. For example like this (real code-block):
#+BEGIN_SRC sh :exports none oldPWD=$(pwd) cd ~/tm5tools/plotting filename="./obsheat-increasing.png" >/dev/null 2>/dev/null sem -j -1 ./plotstation.py -c ~/sun-work/ct-production-out-5x7e300m1.0 -C "aircraft" -c ~/sun-work/ct-production-out-5x7e300m1.0no-aircraft -C "continuous" --obsheat --station allnoaa --title "\"Reducing observation coverage\"" -o ${oldPWD}/${filename} cd - #+END_SRC
Let me explain this.
sem
is a part of GNU parallel which makes parallel execution easy. Essentially it gives us a simple version of the convenience we know from make
.
for i in {1..100}; do sem -j -1 [code] # run N-1 processes with N as the number of # pocessors in my computer done
This means that the above org-mode block will finish instantly, but there will be a second process managed by GNU parallel which executes the plotting script.
The big advantage here is that I can also set this to execute on exporting a document which might run hundreds of code-blocks. If I did this with naive multiprocessing, that would spawn 100 processes which overwhelm the memory of my system (yes, I did that…).
sem -j -1
ensures, that this does not happen. Essentially it provides a process-pool with which it executes the code.
If you use this on export, take care to add a final code-block which waits until all other blocks finished:
sem --wait
If you use GNU parallel to run programs, the arguments are interpreted two times: once when you pass them to sem
and a second time when sem
passes them on. Due to this, you have to add escaped quote-marks for every string which contains whitespace. This can look like the following code (the example above reduced to its essential parts):
sem -j -1 ./plotstation.py --title "\"Reducing observation coverage\""
I stumbled over this a few times, but the convenience of GNU parallel is worth the small extra-caution.
Besides: For easier editing of inline-source-code, set org-src-fontify-natively
to true (t), either via M-x customize-variable
or by adding the following to your .emacs:
(setq org-src-fontify-natively t)
With the tool sem
from GNU parallel you get parallel execution of shell code-blocks in emacs org-mode using the familiar syntax from make:
sem -j -1 [escaped code]
I often write small articles on some experience I make, and since I want to move towards using static pages more often, I tried using emacs org-mode publishing for that. Strangely the simple usecase of publishing a single file seems quite a bit more complex than needed, so I document the steps here.
This is my first use of org-publish, so I likely do not use it perfectly. But as it stands, it works. You can find the org-publish version of this article at draketo.de/proj/orgmode-single-file [78].
I recently lost a dynamic page to hackers. I could not recover the content from all the spam which flooded it. It was called good news and I had wanted to gather positive news which encourage getting active - but I never really found the time to get it running. See what is left of it: http://gute-neuigkeiten.de [79]
Any dynamic page carries a big maintenance cost, because I have to update all the time to keep it safe from spammers who want to abuse it for commercial spam - in the least horrible case. I can choose a managed solution, but that makes me dependant on the hoster providing what I need. Or I can take the sledgehammer and just use a static site: It never does any writes to the webserver, so there is nothing to hack.
As you can see, that’s what I’m doing nowadays.
Because after having used MacOS for almost a decade and then various visual-oriented programs for another five years, Emacs is nowadays the program which is most convenient to me. It achieves a level of integration and usability which is still science-fiction in other systems - at least when you’re mostly working with text.
And Org-mode is to Emacs as Emacs is to the Operating System: It begins as a simple todo-list and accompanies you all the way towards programming, reproducible research - and publishing websites.
Currently I first publish the single file to FTP and then rename it to index.html. This translates to the following publish settings:
(setq private-publish-ftp-proj (concat "/ftp:" USER "@" HOST ":arnebab/proj/")) (setq org-publish-project-alist '(("orgmode-single-file" :base-directory "~/.emacs.d/private/journal" :publishing-directory (concat private-publish-ftp-proj "orgmode-single-file/") :base-extension "org" :publishing-function org-html-publish-to-html :completion-function (lambda () (rename-file (concat private-publish-ftp-proj "orgmode-single-file/2013-11-25-Mo-publish-single-file-org-mode.html") (concat private-publish-ftp-proj "orgmode-single-file/index.html") t)) :section-numbers nil :with-toc t :html-preamble t :exclude ".*" :include ["2013-11-25-Mo-publish-single-file-org-mode.org"])))
Now I can use C-c C-e P x orgmode-single-file to publish this file to the webserver whenever I change it.
Note the lambda: I just copy the published to index.html, because I did not find out, how to rename the file by just setting an option. :index-filename did not work. But likely I missed something which would make this much nicer.
Note that if I had wanted to publish a folder full of files, this would have been much easier: There actually is an option to create an automatic index-file and sitemap.
For more details, read the org-mode publishing guide [80].
This is not as simple as I would like it to be. Maybe (or rather: likely) there is a simpler way. But I can now publish arbitrary org-mode files to my webserver without much effort (and without having to switch context so some other program). And that’s something I’ve been missing for a long time, so I’m very happy to finally have it.
And it was less pain that I feared, though publishing this via my drupal-site, too, obviously shows that I’m still far from moving to static pages for everything. For work-in-progress, this is great, though - for example for my Basics for Guile Scheme [81].
Update 2021: Fixed links that died with Bitbuckets hosting.
I just found the excellent pydoc-info mode [82] for emacs [32] from Jon Waltman. It allows me to hit C-h S
in a python file and enter a module name to see the documentation right away. If the point is on a symbol (=module or class or function), I can just hit enter to see its docs.
In its default configuration (see the Readme [83]) it “only” reads the python documentation. This alone is really cool when writing new python code, but it s not enough, since I often use third party modules.
And now comes the treat: If those modules use sphinx [84] for documentation (≥1.1), I can integrate them just like the standard python documentation!
It took me some time to get it right, but now I have all the documentation for the inverse modelling framework I contribute to directly at my fingertips: Just hit C-h S ENTER
when I’m on some symbol and a window shows me the docs:
The text in this image is from Wouter Peters. Used here as short citation which should be legal almost everywhere under citation rules.
I want to save you the work of figuring out how to do that yourself, so here’s a short guide for integrating the documentation for your python program into emacs.
The prerequisite for integrating your own documentation is to use sphinx [85] for documenting your code. See their tutorial [86] for info how to set it up. As soon as sphinx works for you, follow this guide to integrate your docs in your emacs.
First get pydoc-info and the python infofile (adapt this to your local setup):
# get the mode
cd ~/.emacs.d/libs
hg clone https://hg.sr.ht/~arnebab/pydoc-info
# and the pregenerated info-file for python
wget http://www.draketo.de/dateien/python.info.gz
gunzip python.info.gz
sudo cp python.info /usr/share/info
sudo install-info --info-dir=/usr/share/info python.info
To build the info file for python yourself, have a look at the Readme [83].
Now turn your own documentation into an info document and install it.
Sphinx uses a core configuration file named conf.py. Add the following to that file, replacing all values but index and False by the appropriate names for you project:
# One entry per manual page.
# list of tuples (startdocname,
# targetname, title, author, dir_entry,
# description, category, toctree_only).
texinfo_documents = [
('index', # startdocname, keep this!
'TARGETNAME', # targetname
u'Long Title', # title
u'Author Name', # author
'Name in the Directory Index of Info', # dir_entry
u'Long Description', # description
'Software Development', # cathegory
False), # better keep this, too, i think.
]
Then call sphinx and install the info files like this (maybe adapted to your local setup):
sphinx-build -b texinfo source/ texinfo/
cd texinfo
sudo install-info --info-dir=/usr/share/info TARGETNAME.info
sudo cp TARGETNAME.info /usr/share/info/
Finally add the following to your .emacs (or wherever you store your personal adaptions):
; Show python-documentation as info-pages via C-h S
(setq load-path (cons "~/.emacs.d/libs/pydoc-info" load-path))
(require 'pydoc-info)
(info-lookup-add-help
:mode 'python-mode
:parse-rule 'pydoc-info-python-symbol-at-point
:doc-spec
'(("(python)Index" pydoc-info-lookup-transform-entry)
("(TARGETNAME)Index" pydoc-info-lookup-transform-entry)))
Anhang | Größe |
---|---|
emacs-pydoc.png [87] | 52 KB |
emacs-pydoc-standardlibrary.png [88] | 34.22 KB |
I wrote some recipes for creating the kinds of slides I need with emacs org-mode export to beamer latex.
Update: Read ox-beamer [89] to see how to adapt this to work with the new export engine in org-mode 0.8.
[90] The recipes as PDF (21 slides, 247 KiB) [90]
[91] The org-mode sources (12.2 KiB) [91]
Below is an html export of the org-mode file. Naturally it does not look as impressive as the real slides, but it captures all the sources, so I think it has some value.
Note: To be able to use the simple block-creation commands, you need to add #+startup: beamer to the header of your file or explicitely activate org-beamer with M-x org-beamer-mode
.
PS: I hereby allow use of these slides under any of the licenses used by worg [47] and/or the emacs wiki [3].
Hello World #+LaTeX_CLASS: beamer #+BEAMER_FRAME_LEVEL: 2 * Hello ** Hello GNU Nice to see you!
done: Your first org-beamer presentation.
Recipes #+LaTeX_CLASS: beamer #+BEAMER_FRAME_LEVEL: 2 * Introduction ** org-mode + beamer = love *** Code :BMCOL: :PROPERTIES: :BEAMER_col: 0.7 :END: <example block> *** Simple block :BMCOL:B_block: :PROPERTIES: :BEAMER_col: 0.3 :BEAMER_env: block :END: it's that easy!
it's that easy!
** Two columns - in commands *** Commands C-c C-b | 0.7 C-c C-b b C-n <eTAB (write example) C-n C-n *** Result C-c C-b | 0.3 C-c C-b b even easier - and faster!
even easier - and faster!
*** Column 1 :B_ignoreheading:BMCOL: :PROPERTIES: :BEAMER_env: ignoreheading :BEAMER_col: 0.5 :END: *** One *** Three *** Column 2 :BMCOL:B_ignoreheading: :PROPERTIES: :BEAMER_col: 0.5 :BEAMER_env: ignoreheading :END: *** Two *** Four
*** C-c C-b | 0.5 # column C-c C-b i # ignore heading *** One C-c C-b b # block *** Three C-c C-b b *** C-c C-b | 0.5 C-c C-b i *** Two C-c C-b b *** Four C-c C-b b
*** Code :B_block:BMCOL: :PROPERTIES: :BEAMER_env: block :BEAMER_col: 0.5 :BEAMER_envargs: C[t] :END: *** Result :B_block:BMCOL: :PROPERTIES: :BEAMER_env: block :BEAMER_col: 0.5 :END: pretty nice!
pretty nice!
\tiny
*** :B_columns: :PROPERTIES: :BEAMER_env: columns :END: **** Code :BMCOL: :PROPERTIES: :BEAMER_col: 0.6 :END: **** Result :BMCOL: :PROPERTIES: :BEAMER_col: 0.4 :END: *** Underneath :B_ignoreheading: :PROPERTIES: :BEAMER_env: ignoreheading :END: Much text underneath! Very Much. Maybe too much. The whole width!
\normalsize
Much text underneath! Very Much. Maybe too much. The whole width!
#+begin_quote Emacs org-mode is a great presentation tool - Fast to beautiful slides. - Arne Babenhauserheide #+end_quote
Emacs org-mode is a great presentation tool - Fast to beautiful slides.
- Arne Babenhauserheide
\( 1 + 2 = 3 \) is clear
\[ 1 + 2 \cdot 3 = 7 \]
\( 1 + 2 = 3 \) is clear
\( \LaTeX \) gives a space after math mode. \LaTeX{} does it, too. \LaTeX does not. At the end of a sentence both work. Try \LaTeX. Or try \LaTeX{}. Only \( \LaTeX \) and \( \LaTeX{} \) also work with HTML export.
\( \LaTeX \) gives a space after math mode.
\LaTeX{} does it, too.
\LaTeX does not.
At the end of a sentence both work. Try \LaTeX. Or try \LaTeX{}.
Only \( \LaTeX \) and \( \LaTeX{} \) also work with HTML export.
#+caption: GNU Emacs icon #+label: fig:emacs-icon [[/usr/share/icons/hicolor/128x128/apps/emacs.png]] This is image (\ref{fig:emacs-icon})
GNU Emacs icon
This is image (emacs-icon)
Autoscaled to the block width!
: #+bla: foo : * Example Header
Gives an example, which does not interfere with regular org-mode parsing.
#+begin_example content #+end_example
Gives a simpler multiline example which can interfere.
#+bla: foo * Example Header
Gives an example, which does not interfere with regular org-mode parsing.
content
Gives a simpler multiline example which can interfere.
<Title> #+startup: beamer #+LaTeX_CLASS: beamer #+LaTeX_CLASS_OPTIONS: [bigger] #+AUTHOR: <empty for none, if missing: inferred> #+DATE: <empty for none, if missing: today> #+BEAMER_FRAME_LEVEL: 2 #+TITLE: <causes <Title> to be regular content!>
Put these lines into your .emacs or in a file your .emacs pulls in - i.e. via (require 'mysettings) if the other file is named mysettings.el and ends in (provide 'mysettings).
(org-babel-do-load-languages ; babel, for executing 'org-babel-load-languages ; code in org-mode. '((sh . t) (emacs-lisp . t))) (require 'org-latex) ; latex export (add-to-list ; with highlighting 'org-export-latex-packages-alist '("" "minted")) (add-to-list 'org-export-latex-packages-alist '("" "color")) (setq org-export-latex-listings 'minted)
You can easily set these via M-x customize-variable.
(custom-set-variables ; in ~/.emacs, only one instance '(org-export-latex-classes (quote ; in the init file! (("beamer" "\\documentclass{beamer}" org-beamer-sectioning)))) '(org-latex-to-pdf-process (quote ((concat "pdflatex -interaction nonstopmode" "-shell-escape -output-directory %o %f") "bibtex $(basename %b)" (concat "pdflatex -interaction nonstopmode" "-shell-escape -output-directory %o %f") (concat "pdflatex -interaction nonstopmode" "-shell-escape -output-directory %o %f")))))
(concat "…" "…") is used here to get nice, short lines. Use the concatenated string instead ("pdflatex…%f").
To get org-mode and edit .org files effortlessly.
emerge emacs
To create the presentation.
emerge dev-tex/latex-beamer app-text/texlive
To color the source code (with minted).
emerge dev-python/pygments
Thanks go to the writers of emacs and org-mode, and for this guide in particular to the authors of the org-beamer tutorial on worg [94].
Thank you for your great work!
This presentation is licensed under the GPL [95] (v3 or later) with the additional permission to distribute it without the sources and the copy of the GPL if you give a link to those.1
1 : \tiny As additional permission under GNU GPL version 3 section 7, you may distribute these works without the copy of the GNU GPL normally required by section 4, provided you include a license notice and a URL through which recipients can access the Corresponding Source and the copy of the GNU GPL.\normalsize
Anhang | Größe |
---|---|
emacs-org-beamer-recipes-thumnail.png [96] | 8.92 KB |
emacs-org-beamer-recipes-thumnail-org.png [97] | 20.61 KB |
2012-08-08-Mi-recipes-for-beamer-latex-presentation-using-emacs-org-mode.pdf [90] | 247.11 KB |
2012-08-08-Mi-recipes-for-beamer-latex-presentation-using-emacs-org-mode.org [91] | 12.18 KB |
I recently needed to send an email to many people1.
Putting all of them into the BCC field did not work (mail rejected by provider) and when I split it into 2 emails, many did not see my mail because it was flagged as potential spam (they were not in the To-Field)2.
I did not want to put them all into the To-Field, because that would have spread their email-addresses around, which many would not want3.
So I needed a different solution. Which I found in the extensibility of emacs [45] and wanderlust [98]4. It now carries the name wl-draft-send-to-multiple-receivers-from-buffer
.
You simply write the email as usual via wl-draft
, then put all email addresses you want write to into a buffer and call M-x wl-draft-send-to-multiple-receivers-from-buffer
. It asks you about the buffer with email addresses, then shows you all addresses and asks for confirmation.
Then it sends one email after the other, with a randomized wait of 0-10 seconds between messages to avoid flagging as spam.
If you want to use it, just add the following to your .emacs:
(defun wl-draft-clean-mail-address (address) (replace-regexp-in-string "," "" address))
(defun wl-draft-send-to-multiple-receivers (addresses) (loop for address in addresses do (progn (wl-user-agent-insert-header "To" (wl-draft-clean-mail-address address)) (let ((wl-interactive-send nil)) (wl-draft-send)) (sleep-for (random 10)))))
(defun wl-draft-send-to-multiple-receivers-from-buffer (&optional addresses-buffer-name) "Send a mail to multiple recipients - one recipient at a time" (interactive "BBuffer with one address per line") (let ((addresses nil)) (with-current-buffer addresses-buffer-name (setq addresses (split-string (buffer-string) "\n"))) (if (y-or-n-p (concat "Send this mail to " (mapconcat 'identity addresses ", "))) (wl-draft-send-to-multiple-receivers addresses))))
Happy Hacking!
The email was about the birth of my second child, and I wanted to inform all people I care about (of whom I have the email address), which amounted to 220 recipients. ↩
Naturally this technique could be used for real spamming, but to be frank: People who send spam won’t need it. They will already have much more sophisticated methods. This little trick just reduces the inconvenience brought upon us by the measures which are necessary due to spam. Otherwise I could just send a mail with 1000 receivers in the BCC field - which is how it should be. ↩
It only needs one careless friend, and your connections to others get tracked in facebook and the likes. For more information on Facebook, see Stallman about Facebook [99]. ↩
Sure, there are also template mails and all such, but learning to use these would consume just as much time as extending emacs - and would be much less flexible: Should I need other ways to transform my mails, I’ll be able to just reuse my code. ↩
I just realized that I let myself be distracted by all kinds of not-so-useful stuff instead of finally getting to type the text I already wanted to transcribe from stenografic at the beginning of … last week.
Let’s take a break for a screenshot of the final version, because that’s what we really want to gain from this article: a distraction-free screenshot as distraction from the text :)
As you can see, the distractions are removed — the screenshot is completely full screen and only the text is left. If you switch to the minibuffer (i.e. via M-x), the status bar (modeline) is shown.
To remove the distractions I looked again at WriteRoom [101] and DarkRoom and similar which show just the text I want to write. More exactly: I thought about looking at them again, but at second thought I decided to see if I could not just customize emacs to do the same, backed with all the power you get from several decades of being THE editor for many great hackers.
It took some googling and reading emacs wiki, and then some Lisp-hacking, but finally it’s 4 o’clock in the morning and I’m writing this in my own darkroom mode1, toggled on and off by just hitting F11.
I build on hide-mode-line (livejournal post [102] or webonastick [103]) as well as the full-screen info in the emacs wiki [104].
The whole code just takes 76 lines of code plus 26 lines comments and whitespace:
;;;; Activate distraction free editing with F11 ; hide mode line, from http://dse.livejournal.com/66834.html / http://webonastick.com (autoload 'hide-mode-line "hide-mode-line" nil t) ; word counting (require 'wc) (defun count-words-and-characters-buffer () "Display the number of words and characters in the current buffer." (interactive) (message (concat "The current buffer contains " (number-to-string (wc-non-interactive (point-min) (point-max))) " words and " (number-to-string (- (point-max) (point-min))) " letters."))) ; fullscreen, taken from http://www.emacswiki.org/emacs/FullScreen#toc26 ; should work for X und OSX with emacs 23.x (TODO find minimum version). ; for windows it uses (w32-send-sys-command #xf030) (#xf030 == 61488) (defvar babcore-fullscreen-p t "Check if fullscreen is on or off") (setq babcore-stored-frame-width nil) (setq babcore-stored-frame-height nil) (defun babcore-non-fullscreen () (interactive) (if (fboundp 'w32-send-sys-command) ;; WM_SYSCOMMAND restore #xf120 (w32-send-sys-command 61728) (progn (set-frame-parameter nil 'width (if babcore-stored-frame-width babcore-stored-frame-width 82)) (set-frame-parameter nil 'height (if babcore-stored-frame-height babcore-stored-frame-height 42)) (set-frame-parameter nil 'fullscreen nil)))) (defun babcore-fullscreen () (interactive) (setq babcore-stored-frame-width (frame-width)) (setq babcore-stored-frame-height (frame-height)) (if (fboundp 'w32-send-sys-command) ;; WM_SYSCOMMAND maximaze #xf030 (w32-send-sys-command 61488) (set-frame-parameter nil 'fullscreen 'fullboth))) (defun toggle-fullscreen () (interactive) (setq babcore-fullscreen-p (not babcore-fullscreen-p)) (if babcore-fullscreen-p (babcore-non-fullscreen) (babcore-fullscreen))) (global-set-key [f11] 'toggle-fullscreen) ; simple darkroom with fullscreen, fringe, mode-line, menu-bar and scroll-bar hiding. (defvar darkroom-enabled nil) ; TODO: Find out if menu bar is enabled when entering darkroom. If yes: reenable. (defvar darkroom-menu-bar-enabled nil) (defun toggle-darkroom () (interactive) (if (not darkroom-enabled) (setq darkroom-enabled t) (setq darkroom-enabled nil)) (hide-mode-line) (if darkroom-enabled (progn (toggle-fullscreen) ; if the menu bar was enabled, reenable it when disabling darkroom (if menu-bar-mode (setq darkroom-menu-bar-enabled t) (setq darkroom-menu-bar-enabled nil)) ; save the frame configuration to be able to restore to the exact previous state. (if darkroom-menu-bar-enabled (menu-bar-mode -1)) (scroll-bar-mode -1) (let ((fringe-width (* (window-width (get-largest-window)) (/ (- 1 0.61803) (1+ (count-windows))))) (char-width-pixels 6)) ; 8 pixels is the default, 6 is the average char width in pixels ; for some fonts: ; http://www.gnu.org/software/emacs/manual/html_node/emacs/Fonts.html (set-fringe-mode (truncate (* fringe-width char-width-pixels)))) (add-hook 'after-save-hook 'count-words-and-characters-buffer)) (progn (if darkroom-menu-bar-enabled (menu-bar-mode)) (scroll-bar-mode t) (set-fringe-mode nil) (remove-hook 'after-save-hook 'count-words-and-characters-buffer) (toggle-fullscreen)))) ; Activate with M-F11 -> enhanced fullscreen :) (global-set-key [M-f11] 'toggle-darkroom) (provide 'activate-darkroom)
Also I now activated cua-mode to make it easier to interact with other programs: C-c and C-x now copy/cut when the mark is active. Otherwise they are the usual prefix keys. To force them to be the prefix keys, I can use control-shift-c/-x. I thought this would disturb me, but it does not.
To make it faster, I also told cua-mode to have a maximum delay of 50ms, so I don’t feel the delay. Essentially I just put this in my ~/.emacs:
(cua-mode t)
(setq cua-prefix-override-inhibit-delay 0.005)
Well, did this get me to transcribe the text? Not really, since I spent the time building my own DarkRoom/WriteRoom, but I enjoyed the little hacking and it might help me get it done tomorrow - and get far more other stuff done.
And it is really fun to write in DarkRoom mode ;)
PS: If you like the simple darkroom, please leave a comment [105]!
I hereby declare that anyone is allowed to use this post and the screenshot under the same licensing as if it had been written in emacswiki [3].
Actually there already is a darkroom mode [106], but it only works for windows. If you use that platform, you might enjoy it anyway. So you might want to call this mode “simple darkroom”, or darkroom x11 :) ↩
Anhang | Größe |
---|---|
2011-01-22-emacs-darkroom.png [100] | 97.37 KB |
I have to sift through 6 really boring config files. To stay sane, I call in Emacs [107] for support.
My task looks like this:
[108]
(click for full size [108])
In the lower left window I check the identifier in the table I have to complete (left column), then I search for all instances of that identifier in the right window and insert the instrument type, the SIGMA (uncertainty due to representation error defined for the type of the instrument and the location of the site) and note whether the site is marked as assimilated in the config file.
Then I also check all the other config files and note whether the site is assimilated there.
Drudge work. There are people who can do this kind of work. My wife would likely be able to do it faster without tool support than I can do it with tool support. But I’m really bad at that: When the task gets too boring I tend to get distracted - for example by writing this article.
To get the task done anyway, I create tools which make it more enjoyable. And with Emacs that’s actually quite easy, because Emacs provides most required tools out of the box.
Firstoff: My workflow before adding tools was like this:
xo
to switch from the lower left window to the config file at the right.M-x occur
then type the station identifier. This displays all occurances of the station identifier within the config file in the upper left window.xo
twice to switch to the lower left window again.I now want to simplify this to a single command per line. I’ll use F9
as key, because that isn’t yet used for other things in my Emacs setup and because it is easy to reach and my default keybinding as “useful shortcut for this file”. Other single-keystroke options would be F7
and F8
. All other F-keys are already used :)
To make this easy, I define a macro:
C-x C-(
.C-n
and C-a
.C-SPACE
and select the whole identifier with M-f
.M-x downcase-region
, copy it with M-w
and undo the downcasing with C-x u
(or use the undo key; I defined one in my xmodmap).C-x o
M-x occur
, inserting the identifier with C-y
.C-x o
C-x o
(yes, twice) to get back into the list of sites.M-f
and kill the word with C-BACKSPACE
.C-x C-)
.kmacro-call-macro
to F9
with M-x local-set-key
F9
kmacro-call-macro
.Done.
My workflow is now reduced to this:
F9
I’m pretty sure that this will save me more time today than I spent writing this text ☺
Happy hacking!
Anhang | Größe |
---|---|
2015-01-26-sane-with-emacs-task.png [108] | 79.85 KB |
2015-01-26-sane-with-emacs-task-200.png [109] | 7.79 KB |
2015-01-26-sane-with-emacs-task-300.png [110] | 15.92 KB |
2015-01-26-sane-with-emacs-task-400.png [111] | 27.28 KB |
2015-01-26-sane-with-emacs-task-450.png [112] | 33.83 KB |
Update 2023: I no longer work at the University [113]. Nowadays I would use this setup as starting point, but with more focus on using org for reproducibility [114] (I have German instructions [115] for that) when the first version is ready for submission, export it as LaTeX, and work directly on that, because you’ll need detailed changes in LaTeX.
PDF-version [116] (for printing)
orgmode-version [117] (for editing)
Emacs Org mode is an excellent tool for reproducible research [118],1 but research is only relevant if people learn about it.2 To reach people with scientific work, you need to publish your results in a Journal, so I show here how to publish in ACP [119] with Emacs Org mode.3
To use this tutorial, you need
The first step in publishing to ACPD is to activate org-mode and latex export and to create a latex-class in Emacs. To do so, just add the following to your ~/.emacs (or ~/.emacs.d/init.el) and eval it (for example by moving to the closing parenthesis and typing C-x C-e):
(require 'org) (require 'org-latex) (require 'ox-latex) (setq org-latex-packages-alist (quote (("" "color" t) ("" "minted" t) ("" "parskip" t))) org-latex-pdf-process (quote ( "pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f" "bibtex $(basename %b)" "pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f" "pdflatex -interaction nonstopmode -shell-escape -output-directory %o %f"))) (add-to-list 'org-latex-classes `("copernicus_discussions" "\\documentclass{copernicus_discussions} [NO-DEFAULT-PACKAGES] [PACKAGES] [EXTRA]" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" "\\newpage" "\\subsection*{%s}" "\\newpage") ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}")) )
This allows you to use #+Latex_Class: copernicus_discussions in your org-mode file to set the PDF to export for ACPD.
Also you will likely want to use reftex [123] for nice bibtex integration. To get it, add the following to your ~/.emacs or ~/.emacs.d/init.el:
(require 'reftex-cite) (defun org-mode-reftex-setup () (interactive) (and (buffer-file-name) (file-exists-p (buffer-file-name)) (progn ; Reftex should use the org file as master file. See C-h v TeX-master for infos. (setq TeX-master t) (turn-on-reftex) ; enable auto-revert-mode to update reftex when bibtex file changes on disk (global-auto-revert-mode t) ; careful: this can kill the undo ; history when you change the file ; on-disk. (reftex-parse-all) ; add a custom reftex cite format to insert links ; This also changes any call to org-citation! (reftex-set-cite-format '((?c . "\\citet{%l}") ; natbib inline text (?i . "\\citep{%l}") ; natbib with parens )))) (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)
The first line adds reftex-citations with C-c [, the rest sets some reftex-defaults and adds a menu which allows you to chose using \textbackslash citep{} instead of \textbackslash cite{} (this is what ACPD requires).
For nice Sourcecode highlighting, you should also install Pygmentize [124] and then add the following to your .emacs.d:
(add-to-list 'org-latex-packages-alist '("" "minted")) (add-to-list 'org-latex-packages-alist '("" "color")) (setq org-latex-listings 'minted) ; add emacs lisp support for minted (setq org-latex-custom-lang-environments '((emacs-lisp "common-lispcode")))
As next step, unzip the copernicus latex package [120] in the folder you want to use for writing your article (do use a dedicated folder for that: org-mode leaves around some files). And remember to use a version-tracking system like Mercurial [125], so you can always take snapshots of your current state.
This will give you the following files:
Ensure that all of them are in your folder, not in a subfolder. If necessary copy them there.
Also get lineno.sty [122] and copy it into your folder.
If you want to use unicode-symbols in your text, add uniinput.sty [126], too.
Using the ACPD style requires some deviations from the standard org-mode export process. Luckily org-mode is flexible to adapt to them. Setup your document as follows:
#+title: YOUR TITLE #+Options: toc:nil ^:nil #+BIND: org-latex-title-command "" #+Latex_Class: copernicus_discussions #+LaTeX_CLASS_OPTIONS: [acpd, hvmath, online] # Nice code-blocks #+BEGIN_SRC elisp :noweb no-export :exports results (setq org-latex-minted-options '(("bgcolor" "mintedbg") ("frame" "single") ("framesep" "6pt") ("mathescape" "true") ("fontsize" "\\footnotesize"))) nil #+END_SRC #+BEGIN_ABSTRACT Abstract #+END_ABSTRACT #+TOC: headlines 2 #+Latex: \runningtitle{SHORT TITLE} #+Latex: \runningauthor{SHORT AUTHOR} #+Latex: \correspondence{AUTHOR NAME\\ EMAIL} #+Latex: \affil{YOUR UNIVERSITY} #+Latex: \author[2,*]{SECOND AUTHOR} #+Latex: \author[1]{THIRD AUTHOR SAME INSTITUTE} #+Latex: \affil[2]{SECOND UNIVERSITY} #+Latex: \affil[*]{now at: THIRD UNIVERSITY} #+Latex: \received{} #+Latex: \pubdiscuss{} #+Latex: \revised{} #+Latex: \accepted{} #+Latex: \published{} #+Latex: %% These dates will be inserted by ACPD #+Latex: \firstpage{1} #+Latex: \maketitle #+Latex: \introduction # * Introduction * Second section * Discussion #+Latex: \conclusions # * Conclusions #+Latex: \appendix # use acknowledgements for multiple #+BEGIN_acknowledgement Foo Bar Baz. #+END_acknowledgement #+Latex: \bibliographystyle{copernicus} #+Latex: \bibliography{ABSOLUTE_PATH_TO_YOUR_BIBTEX_FILE_WITHOUT_.bib_SUFFIX}{} # Local Variables: # org-confirm-babel-evaluate: nil # org-export-allow-bind-keywords: t # End:
Let’s look at this in more detail.
As first step, we set the LaTeX class. In the options we select the journal (acpd) and such - you can find the detailed options in the latex-instructions [121] from ACP.
#+Latex_Class: copernicus_discussions #+LaTeX_CLASS_OPTIONS: [acpd, hvmath, online]
The table of contents is set to be shown after the Abstract by setting the toc:nil option and later explicitely calling #+TOC: headlines 2. In org-mode this is really straightforward.
Delaying \textbackslash maketitle is a bit more convoluted than delaying the TOC. First we add the local variable org-export-allow-bind-keywords: t at the bottom to allow file-local custom bindings for functions in the file, then we inactivate the title-command with #+BIND: org-latex-title-command /""/ and finally we add \textbackslash maketitle where we need it.
This defines the variables minted uses for beautiful code-blocks. Without this, your code-blocks will just look like inline text.
#+BEGIN_SRC elisp :noweb no-export :exports results (setq org-latex-minted-options '(("bgcolor" "mintedbg") ("frame" "single") ("framesep" "6pt") ("mathescape" "true") ("fontsize" "\\footnotesize"))) nil #+END_SRC
The Introduction and the conclusions have their own commands in ACPD, because they use them to add bookmarks. You can also use he commands to specify another name.
We call the commands with #+LaTeX: (just like some others) which allows us to explicitely add arbitrary LaTeX-code.
The appendix should be used sparingly. It changes the numbering of the pages.
#+Latex: \appendix
The bibliography allows referring to entries from your general bibtex-file. Ensure that you use the correct absolute path to that file. For more information, see the org-tutorial page for biblatex [127].
This allows us to just run all code snippets which we embedded in the document when we export the file. If we do not set this local variable, we have to acknowledge each source block before it runs (the block with local variables also contains the variable which allows binding functions on a per-file basis, as explained above).
# Local Variables: # org-confirm-babel-evaluate: nil # org-export-allow-bind-keywords: t # End:
With this setup, you can publish your paper with ACPD using org-mode for the actual writing, which has a much lower overhead than LaTeX and offers quite a few unique features for more efficient working - from easy referencing over inline math preview to planning and code-evaluation directly in your file.
General methods for using Emacs org-mode in scientific publishing have been described by \citet{SchulteEmacs2012}.
Research, or rather science not only means to learn new things and to uncover secrets, but just as importantly to share what you learn. Fun fact: The German word for science is “Wissenschaft”, built from the words “wissen” (knowledge) and “schaft” (from schaffen: create), so it more exactly captures the essence of scientific work than the word “science”, that is based on the latin word “scientia” which just means knowledge. It isn’t enough to just learn. Creating knowledge requires telling it to others, so they can build upon it.
I chose ACPD as target for this article, because it is an Open Access journal, and because I want to publish in it (which makes it a rather natural choice for a tutorial).
For years I regularly stumbled over LaTeX-Errors in the form of
Unicode char \u8:χ not set up for use with LaTeX
. I always took the chickens path and replaced the unicode characters with the tex-escapes in the file. That was easy, but it made my files needlessly unreadable. Today I decided to FIX the problem once and for all. And it worked. Easily.
Firstoff: The problem I’m facing is that my keyboard layout [128] makes it effortless for me to input characters like ℂ Σ and χ. But LaTeX cannot cope with them out-of-the-box. Org-mode [5] already catches most of these problems, so I can write things like x² instead of x^2
, but occasionally it stumbles.
The solution to that is actually pretty simple: I only need to declare the escapes-sequences LaTeX should use when it sees one of the characters (to be used before \begin{document}!):
\DeclareUnicodeCharacter{03C7}{\chi}
Or in org-mode:
#+LaTeX_HEADER: \DeclareUnicodeCharacter{03C7}{\chi}
To do this more easily, you can use the uniinput.ins [129] and uniinput.dtx [130] from the neo-layout project [128]. Run latex uniinput.ins
to generate uniinput.sty
which you can put next to your latex files and use with \usepackage{uniinput}
(instructions in German [131]).
Thanks go to Wikibooks:LaTeX [132] for this. Their solution suggests then to read several Unicode definition documents for tracking down the codepoint of the character. But we can make that easier with Emacs [4] (almost everything is easier with Emacs ☺).
Instead of browsing huge documents manually, we simply rely on the unicode-definitions in Emacs: Move the cursor over the char and execute M-x describe-char
.
When used with χ, this shows the following output:
position: 672 of 35513 (2%), column: 0
character: χ (displayed as χ) (codepoint 967, #o1707, #x3c7)
preferred charset: unicode-bmp (Unicode Basic Multilingual Plane (U+0000..U+FFFF))
code point in charset: 0x03C7
… (and a bit more) …
What we need is code point in charset: Just leave out the 0x
and you have the codepoint.
For the document I currently write, I now use the following definitions:
#+LaTeX_HEADER: \DeclareUnicodeCharacter{03C7}{\chi}
#+LaTeX_HEADER: \DeclareUnicodeCharacter{B2}{^{2}}
And that makes χ² work.
Happy Hacking - and have fun with Emacs Org-Mode!
By default Emacs [107] Orgmode [133] uses uppercase words for todo keywords. But having tens of entries marked with TODO and DONE in my file looked horribly cluttered to me. So I searched for alternatives. After a few months of experimentation, I decided on the following scheme. It served me well ever since:
To set this in org-mode, just add the following to the header (and reopen the document, for example with C-x C-v
):
#+SEQ_TODO: ❢ ☯ ⧖ | ☺ ✔ ⌚ ✘
or for the complex case (with details on what I do)
#+SEQ_TODO: ❢ ☯ ⚙ ✍ ⧖ | ☺ ✔ ⌚ ✘
Then use C-c C-t
or SHIFT-→
(shift + right arrow) to switch to the next state or SHIFT-←
(shift + left arrow) to switch to the previous state.
Anything before the |
in the SEQ_TODO is shown in red (not yet done), anything after the |
is show in green (done). Things which get triggered when something is done (like storing the time of a scheduled entry [134]) happen when the state crosses the |
.
And with that, my orgmode documents are not only very useful but also look pretty lean. Just as good as having a GUI with images, but additionally I can access them over SSH and edit the todo state with any tool - because it’s just text.
I just needed to tweak my Emacs [45] org-mode [5] to beamer-latex [135] export to embed images into a figure environment (not wrapfigure!). After lots of googling and documentation reading I decided to bite the bullet and just read the source. Which proved to be much easier than I had expected.
This tutorial requires at least org-mode 8.0 (before that you had to use hacks to get figure without a caption). It is only tested for org-mode 8.0.2: The code you see when you read the source might look different in other versions.
I just needed to tweak my org-mode to beamer-latex export to embed images I produce by a codesnippet in a figure environment. Practially speaking: I had this
#+BEGIN_SRC sh :exports results :results output raw echo '[[./image.png]]' #+END_SRC
which produces this latex snippet
\includegraphics[width=.9\linewidth]{./image.png}
and I needed a snippet which instead produces this:
\begin{figure}[htb] \centering \includegraphics[width=.9\linewidth]{./image.png} \end{figure}
After lots of googling and documentation reading I decided to bite the bullet and just read the source. Which proved to be much easier than I had expected (warning: obscure list of commands follows. Will be explained afterwards):
C-h f org-latex-export-as-latex C-x C-o C-s .el C-b ENTER C-s figure C-s C-s C-s ...
And less than a minute after starting, I saw this:
(float (let ((float (plist-get attr :float))) (cond ((string= float "wrap") 'wrap) ((string= float "multicolumn") 'multicolumn) ((or (string= float "figure") (org-element-property :caption parent)) 'figure))))
Translated: Just add this to the output of the source block:
#+attr_latex: :float figure
which makes the sh block look like this:
#+BEGIN_SRC sh :exports results :results output raw echo '#+attr_latex: :float figure' echo '[[./image.png]]' #+END_SRC
And voila, the export works and the latex looks like this:
\begin{figure}[htb] \centering \includegraphics[width=.9\linewidth]{./image.png} \end{figure}
Mission accomplished!
For all those who are not fluid in emacs commands, Here’s a short breakdown here’s a breakdown of my source-reading process:
C-h f org-latex-export-as-latex
Get the help (Control-h) for the function (f) org-latex-export-as-latex. I knew that org-mode calls that. If you did not know it, you could have simply used C-h k C-e (get help on the export keyboard shortcut) which would have led you to the function org-export-dispatch and the source file ox.el. But since the org-mode guides tell you to use M-x org-latex-export-as-latex, the function to search for is actually pretty obvious. Alternatively just use M-x org-latex- and then type TAB 2 times. That will show you all the export functions.
C-x C-o
Switch to the other buffer.
C-s .el C-b ENTER
Focus on the source file and open it (the canonical suffix for emacs lisp files is .el).
C-s figure C-s C-s C-s ...
Search for figure. Repeat 9 times to find the correct place in the code (in emacs that’s really easy and fast to do).
Voilà, you found the snippet which tells you that you can use the float-keyword (:float) with the argument "figure".
Using the source was actually faster than googling in this case - and if you practise it, you learn bits and pieces about the foundation of the program you use, which will enable you to adapt it even better to your needs in the future.
And with that, I conclude this text.
Enjoy your Emacs and Happy Hacking!
Anhang | Größe |
---|---|
2013-08-28-Mi-use-the-source-beamer-figure.org [136] | 3.8 KB |
Because I am lazy,1 and that makes me fast.
(download (ogg theora video) [137])
Using Macros to avoid tedious tasks
I record a macro to find ~, then activate the mark and find a space.
C-s ~, C-SPACE, C-s SPACE
Then kill the region and type ${}
C-w ${}
That’s it.
☺
recorded with recordmydesktop: recordmydesktop --delay 10 --width 800 --height 600 --on-the-fly-encoding
I have lots of stuff to do, so I cannot afford not being lazy ☺ ↩
Anhang | Größe |
---|---|
using-emacs-macros-to-reduce-tedious-work-screencast.ogv [137] | 17.81 MB |
using-emacs-macros-to-reduce-tedious-work-screencast.org [138] | 397 Bytes |
I would love to be able to use KDE with emacs-style keyboard shortcuts, because Emacs offers a huge set of already clearly defined shortcuts for many different situations. Since its users tend to do very much with the keyboard alone, even more obscure tasks are available via shortcuts.
I think that this would be useful, because Emacs is like a kind of nongraphical desktop environment itself (just look at emacspeak [139]!). For all those who use Emacs in a KDE environment, it could be a nice timesaver to be able to just use their accustomed bindings.
It also has a mostly clean structure for the bindings:
C-x anything
" does changes which affect things outside the content of the current buffer.C-c anything
" is kept for specific actions of programs. For example "C-c C-c
" in an email sends the email, while "C-c C-c
" in a version tracking commit message finishes the message and starts the actual commit. C-anything but x or c
" acts on the content you're currently editing. M-x
" opens a 'command-selection-dialog' (just like alt-f2). You can run commands by name.M-anything but x
" is a different flavor of "C-anything but x or c
". For example "C-f
" moves the cursor one character forward, while "M-f
" moves one word forward. "C-v
" moves one page forward, while "M-v
" moves one page backwards. On the backend side, this would require being able to define multistep shortcuts. Everything else is just porting the emacs shortcuts to KDE actions.
The actual porting of shortcuts would then require mapping of the Emacs commands to KDE actions.
Some examples:
C-s
" searches in a file. Replaces C-f
. C-r
" searches backwards. C-x C-s
" saves a file -> close. Replaces C-w
. C-x C-f
" opens a file -> Open. Replaces C-o
. C-x C-c
" closes the program -> quit. Replaces C-q
. C-x C-b
" switches between buffers/files/tabs -> switch the open file. Replaces alt-right_arrow and a few other (to my knowledge) inconsistent bindings. C-x C-2
" splits a window (or part of a window) vertically. "C-x C-o" switches between the parts. "C-x C-1
" undoes the split and keeps the currently selected part. "C-x C-0
" undoes the split and hides the currently selected part.How to add show multiple images on one page in the latex-export of emacs org-mode. I had this problem. This is my current solution.
Use the package subfig:
#+latex_header: \usepackage{subfig}
And create an image:
import pylab as pl import numpy as np x = np.random.random(size=(2,1000)) pl.scatter(x[0,:], x[1,:], marker=".") pl.savefig("test.png") print "\label{fig:image}" print "[[./test.png]]"
\label{fig:image}
Image: \ref{fig:image}
#+BEGIN_LaTeX \begin{figure}\centering \subfloat[A gull]{\label{fig:latex-gull} \includegraphics[width=0.3\textwidth]{test} } \subfloat[A tiger]{\label{fig:latex-tiger} \includegraphics[width=0.3\textwidth]{test} } \subfloat[A mouse]{\label{fig:latex-mouse} \includegraphics[width=0.3\textwidth]{test} } \caption{Multiple pictures}\label{fig:latex-animals} \end{figure} #+END_LaTeX
Latex-Animals \ref{fig:latex-animals}.
#+latex: \begin{figure}\centering #+latex: \subfloat[A gull]{\label{fig:org-gull} #+attr_latex: :width 0.3\textwidth [[./test.png]] #+latex: }\subfloat[A tiger]{\label{fig:org-tiger} #+attr_latex: :width 0.3\textwidth [[./test.png]] #+latex: }\subfloat[A mouse]{\label{fig:org-mouse} #+attr_latex: :width 0.3\textwidth [[./test.png]] #+latex: }\caption{Multiple pictures}\label{fig:org-animals} #+latex: \end{figure}
Org-Animals \ref{fig:org-animals}.
Anhang | Größe |
---|---|
test.png [142] | 98.4 KB |
2014-01-14-Di-org-mode-multiple-images-per-page.pdf [140] | 281.84 KB |
2014-01-14-Di-org-mode-multiple-images-per-page.org [141] | 2.48 KB |
This is my wanderlust.el file to read kmail maildirs. You need to define every folder you want to read.
;; mode:-*-emacs-lisp-*- ;; wanderlust (setq elmo-maildir-folder-path "~/.kde/share/apps/kmail/mail" ;; where i store my mail wl-stay-folder-window t ;; show the folder pane (left) wl-folder-window-width 25 ;; toggle on/off with 'i' wl-smtp-posting-server "smtp.web.de" ;; put the smtp server here wl-local-domain "draketo.de" ;; put something here... wl-message-id-domain "web.de" ;; ...
file continued:
wl-from "Arne Babenhauserheide" ;; my From: ;; note: all below are dirs (Maildirs) under elmo-maildir-folder-path ;; the '.'-prefix is for marking them as maildirs wl-fcc ".sent-mail" ;; sent msgs go to the "sent"-folder wl-fcc-force-as-read t ;; mark sent messages as read wl-default-folder ".inbox" ;; my main inbox wl-draft-folder ".drafts" ;; store drafts in 'postponed' wl-trash-folder ".trash" ;; put trash in 'trash' wl-spam-folder ".gruppiert/Spam" ;; ...spam as well wl-queue-folder ".queue" ;; we don't use this ;; check this folder periodically, and update modeline wl-biff-check-folder-list '(".todo") ;; check every 180 seconds ;; (default: wl-biff-check-interval) ;; hide many fields from message buffers wl-message-ignored-field-list '("^.*:") wl-message-visible-field-list '("^\\(To\\|Cc\\):" "^Subject:" "^\\(From\\|Reply-To\\):" "^Organization:" "^Message-Id:" "^\\(Posted\\|Date\\):" ) wl-message-sort-field-list '("^From" "^Organization:" "^X-Attribution:" "^Subject" "^Date" "^To" "^Cc")) ; Encryption via GnuPG (require 'mailcrypt) (load-library "mailcrypt") ; provides "mc-setversion" (mc-setversion "gpg") ; for PGP 2.6 (default); also "5.0" and "gpg" (autoload 'mc-install-write-mode "mailcrypt" nil t) (autoload 'mc-install-read-mode "mailcrypt" nil t) (add-hook 'mail-mode-hook 'mc-install-write-mode) (add-hook 'wl-summary-mode-hook 'mc-install-read-mode) (add-hook 'wl-mail-setup-hook 'mc-install-write-mode) ;(setq mc-pgp-keydir "~/.gnupg") ;(setq mc-pgp-path "gpg") (setq mc-encrypt-for-me t) (setq mc-pgp-user-id "FE96C404") (defun mc-wl-verify-signature () (interactive) (save-window-excursion (wl-summary-jump-to-current-message) (mc-verify))) (defun mc-wl-decrypt-message () (interactive) (save-window-excursion (wl-summary-jump-to-current-message) (let ((inhibit-read-only t)) (mc-decrypt)))) (eval-after-load "mailcrypt" '(setq mc-modes-alist (append (quote ((wl-draft-mode (encrypt . mc-encrypt-message) (sign . mc-sign-message)) (wl-summary-mode (decrypt . mc-wl-decrypt-message) (verify . mc-wl-verify-signature)))) mc-modes-alist))) ; flowed text ;; Reading f=f (autoload 'fill-flowed "flow-fill") (add-hook 'mime-display-text/plain-hook (lambda () (when (string= "flowed" (cdr (assoc "format" (mime-content-type-parameters (mime-entity-content-type entity))))) (fill-flowed)))) ; writing f=f ;(mime-edit-insert-tag "text" "plain" "; format=flowed") (provide 'private-wanderlust)
I now use a ~/.folders file, to manage my non-kmail maildir subscriptions, too. It looks like this:
.sent-mail .~/.local/share/mail/mgl_spam "mgl spam" .~/.local/share/mail/to.arne_bab "to arne_bab" .inbox "inbox" .trash "Trash" ..gruppiert.directory/.inbox.directory/Freunde "Freunde" .drafts "Drafts" ..gruppiert.directory/.alt.directory/Posteingang-2011-09-18 "2011-09-18" .outbox
The mail in ~/.local/share/mail
is fetched via fetchmail and procmail to have a really reliable mail fetching system which does not rely on a non-broken database or free space on the disk to keep working…
For a long time it bothered me that auto-complete made it necessary for me to abort completion before being able to use org-mode templates [143].
I typed <s
and auto-complete showed stuff like <string
, forcing me to hit C-g before I could use TAB to complete the template with org-mode.
I fixed this for me by adding all the org-mode structure templates as stop-words:
;; avoid competing with org-mode templates. (add-hook 'org-mode-hook (lambda () (make-local-variable 'ac-stop-words) (loop for template in org-structure-template-alist do (add-to-list 'ac-stop-words (concat "<" (car template))))))
Note, that with this snippet you will have to reopen a file if you add an org-mode template and want it recognized as stop-word in that file.
PS: I added this as bug-report to auto-complete [144], so with some luck you might not have to bother with this, if you’re willing to simply wait for the next release ☺
Links:
[1] http://www.gnu.org/software/emacs/#Platforms
[2] http://www.gnu.org/philosophy/free-sw.html
[3] http://emacswiki.org
[4] http://gnu.org/s/emacs
[5] http://orgmode.org
[6] http://identi.ca
[7] http://www.lisperati.com/casting-spels-emacs/html/casting-spels-emacs-1.html
[8] http://gnu.org
[9] https://www.draketo.de/light/english/politics-and-free-software
[10] http://emacswiki.org/emacs/EmacsHistory
[11] https://www.draketo.de/licht/freie-software/emacs
[12] http://draketo.de/proj/babcore/babcore.pdf
[13] http://marmalade-repo.org/packages/babcore
[14] http://draketo.de/proj/babcore/babcore.org
[15] http://bitbucket.org/ArneBab/.emacs.d
[16] http://draketo.de/proj/babcore/
[17] http://draketo.de/proj/babcore/babcore.el
[18] http://batsov.com/prelude/
[19] http://www.gnu.org/licenses/
[20] https://www.masteringemacs.org/article/spotlight-flycheck-a-flymake-replacement
[21] http://aspell.net/
[22] http://www.workrave.org/
[23] http://www.emacswiki.org/emacs/TypeBreakMode
[24] http://ergoemacs.org/emacs/unicode-browser.html
[25] https://twiki.cern.ch/twiki/bin/view/CDS/EmacsTips
[26] https://www.gnu.org/software/emacs/manual/html_node/emacs/Saving-Emacs-Sessions.html#Saving-Emacs-Sessions
[27] http://emacswiki.org/
[28] http://www.emacswiki.org/emacs/CamelCase
[29] http://www.gnu.org/software/emacs/manual/html_node/elisp/Interactive-Codes.html
[30] https://www.draketo.de/files/2015-01-14-Mi-camel-case-to-underscore.org
[31] https://www.draketo.de/files/org-custom-link-completion_0.el
[32] http://gnu.org/software/emacs
[33] http://identi.ca/notice/94534869
[34] https://twitter.com/gtuckerkellogg/status/212735789837193216
[35] https://www.draketo.de/licht/freie-software/emacs/paper-zu-org-mode-f-r-reproducible-research
[36] http://orgmode.org/manual/Working-With-Source-Code.html
[37] https://bitbucket.org/ArneBab/.emacs.d/src/fluss
[38] https://www.draketo.de/files/2012-06-15-emacs-link-completion-bib_1.png
[39] https://www.draketo.de/files/2012-06-15-Fr-org-link-completion.org
[40] http://www.nature.com/
[41] http://en.wikipedia.org/wiki/RIS_%28file_format%29
[42] http://tug.ctan.org/pkg/bibtex
[43] http://scholar.google.com
[44] http://sourceforge.net/p/bibutils/home/Bibutils/
[45] https://www.draketo.de/light/english/emacs
[46] http://license.draketo.de
[47] http://orgmode.org/worg/
[48] http://en.wikipedia.org/wiki/Kanban
[49] https://www.draketo.de/orgmode.org
[50] https://hg.sr.ht/~arnebab/kanban.el
[51] https://bitbucket.org/ArneBab/kanban.el
[52] http://draketo.de/proj/kanban/
[53] http://marmalade-repo.org/packages/kanban/0.1.1
[54] https://www.draketo.de/files/kanban.el
[55] https://bitbucket.org/ArneBab/.emacs.d/src/fluss/lisplets/kanban.el
[56] http://orgmode.org/manual/Matching-tags-and-properties.html
[57] http://orgmode.org/manual/Agenda-files.html#fn-1
[58] http://bitbucket.org/ArneBab/hexbattle
[59] http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-11-1
[60] http://orgmode.org/manual/Table-of-contents.html
[61] https://www.draketo.de/files/2013-11-21-Do-emacs-orgmode-abstract-before-toc.pdf
[62] https://www.draketo.de/files/2013-11-21-Do-emacs-orgmode-abstract-before-toc.org
[63] https://www.emacswiki.org/emacs/ErcProxy#toc2
[64] http://youbroketheinternet.org/#overlay
[65] http://identi.ca/conversation/97136907#notice-98020110
[66] http://orgmode.org/worg/org-contrib/babel/
[67] https://www.draketo.de/light/english/mercurial/complete-branching-strategy
[68] https://www.draketo.de/files/screenshot-20121122101933-width300.png
[69] https://www.draketo.de/files/screenshot-20121122101933-width600.png
[70] http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming
[71] https://www.draketo.de/files/noweb-test.org
[72] https://www.draketo.de/files/noweb-test.py.txt
[73] https://www.draketo.de/files/noweb-test.pdf
[74] http://python.org
[75] http://orgmode.org/manual/noweb.html
[76] https://www.draketo.de/files/noweb-test-pdf.png
[77] http://gnu.org/s/parallel
[78] http://draketo.de/proj/orgmode-single-file/
[79] http://gute-neuigkeiten.de
[80] http://orgmode.org/manual/Publishing.html#Publishing
[81] https://www.draketo.de/proj/guile-basics
[82] https://hg.sr.ht/~arnebab/pydoc-info
[83] https://hg.sr.ht/~arnebab/pydoc-info/browse/README?rev=tip
[84] https://www.sphinx-doc.org
[85] https://www.sphinx-doc.org/en/master/
[86] https://www.sphinx-doc.org/en/master/tutorial/index.html
[87] https://www.draketo.de/files/emacs-pydoc_0.png
[88] https://www.draketo.de/files/emacs-pydoc-standardlibrary_0.png
[89] http://orgmode.org/worg/exporters/beamer/ox-beamer.html
[90] https://www.draketo.de/files/2012-08-08-Mi-recipes-for-beamer-latex-presentation-using-emacs-org-mode_1.pdf
[91] https://www.draketo.de/files/2012-08-08-Mi-recipes-for-beamer-latex-presentation-using-emacs-org-mode_1.org
[92] https://bitbucket.org/rivanvx/beamer
[93] http://pygments.org
[94] http://orgmode.org/worg/org-tutorials/org-beamer/tutorial.html
[95] http://gnu.org/licenses/gpl.html
[96] https://www.draketo.de/files/emacs-org-beamer-recipes-thumnail.png
[97] https://www.draketo.de/files/emacs-org-beamer-recipes-thumnail-org.png
[98] http://emacswiki.org/emacs/WanderLust
[99] http://stallman.org/facebook.html
[100] https://www.draketo.de/files/2011-01-22-emacs-darkroom.png
[101] http://www.emacswiki.org/emacs/WriteRoom
[102] http://dse.livejournal.com/66834.html
[103] http://webonastick.com
[104] http://www.emacswiki.org/emacs/FullScreen
[105] https://www.draketo.de/comment/reply/424#comment-form
[106] https://bitbucket.org/phromo/darkroom-mode
[107] https://www.draketo.de/english/emacs
[108] https://www.draketo.de/files/2015-01-26-sane-with-emacs-task.png
[109] https://www.draketo.de/files/2015-01-26-sane-with-emacs-task-200.png
[110] https://www.draketo.de/files/2015-01-26-sane-with-emacs-task-300.png
[111] https://www.draketo.de/files/2015-01-26-sane-with-emacs-task-400.png
[112] https://www.draketo.de/files/2015-01-26-sane-with-emacs-task-450.png
[113] https://www.draketo.de/english/songs/new-horizons-science
[114] https://www.jstatsoft.org/article/view/v046i03
[115] http://www.draketo.de/reproduzierbare-veroeffentlichungen
[116] https://www.draketo.de/files/howto-write-for-acpd-with-emacs.pdf
[117] https://www.draketo.de/files/howto-write-for-acpd-with-emacs.org
[118] http://www.jstatsoft.org/v46/i03/
[119] http://www.atmos-chem-phys-discuss.net/
[120] http://www.atmospheric-chemistry-and-physics.net/Copernicus_LaTeX_Package_v_2_7.zip
[121] http://www.atmospheric-chemistry-and-physics.net/submission/latex_instructions.html
[122] http://tug.ctan.org/tex-archive/macros/latex/contrib/lineno/lineno.sty
[123] http://www.gnu.org/software/auctex/reftex.html
[124] http://pygments.org/
[125] http://mercurial.selenic.com
[126] http://wiki.neo-layout.org/attachment/ticket/317/uniinput.sty
[127] http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-17-1
[128] http://neo-layout.org
[129] http://wiki.neo-layout.org/export/2476/latex/Standard-LaTeX/uniinput.ins
[130] http://wiki.neo-layout.org/export/2476/latex/Standard-LaTeX/uniinput.dtx
[131] http://wiki.neo-layout.org/browser/latex/Standard-LaTeX/README.txt
[132] http://en.wikibooks.org/wiki/LaTeX/Special_Characters#Extending_the_support
[133] http://orgmode.org/
[134] http://orgmode.org/manual/Deadlines-and-scheduling.html
[135] http://de.wikipedia.org/wiki/Beamer_(LaTeX)
[136] https://www.draketo.de/files/2013-08-28-Mi-use-the-source-beamer-figure.org
[137] https://www.draketo.de/files/using-emacs-macros-to-reduce-tedious-work-screencast.ogv
[138] https://www.draketo.de/files/using-emacs-macros-to-reduce-tedious-work-screencast.org
[139] http://emacspeak.sourceforge.net/
[140] https://www.draketo.de/files/2014-01-14-Di-org-mode-multiple-images-per-page.pdf
[141] https://www.draketo.de/files/2014-01-14-Di-org-mode-multiple-images-per-page.org
[142] https://www.draketo.de/files/test.png
[143] http://orgmode.org/manual/Easy-Templates.html#Easy-Templates
[144] https://github.com/auto-complete/auto-complete/issues/306