Emacs init file written in org-mode

Table of Contents


---> misc
| ---> 2016
| ---> 2015
| ---> 2014
| ---> 2013
| ---> 2012
`--> Agenda

This file is my .emacs configuration file (more precisely my ~/.emacs.d/init.el configuration). I stole it from Luka Stanisic who stole parts from mine a long time ago and cleaned (with org-mode) and improved everything. It is so convenient that I think it is time to share it. Note that it comprises my personal website publishing configuration that you should not really need but that you can inspire on.

To have a nice emacs configuration, you'll need:

If you're a Mac OS X user, read this.

Installation Instructions


First download this file (the original source file, which is also is available at the end of this document if the previous link ever gets broken)

Then copy it into ~/.emacs.d/init.org.

  • If you are using Mac OS X, remove every line containing the word xclip in this file (you may also be interested in reading this blog entry or this one that I wrote but that may be obsolete as I do not use MacOS X myself). Do not forget to then remove everything about xclip.
  • Otherwise, you should consider installing xclip (sudo apt-get install xclip in a shell and M-x package-install the xclip package within emacs) as it will ease interactions with emacs when running in a terminal.

Then do M-x org-babel-load-file (M-x means pressing Alt and x simultaneously to get the emacs prompt that allows you to call emacs functions, also remember you can press Tab to activate auto completion) and provide ~/.emacs.d/init.org. This should evaluate every piece of emacs-lisp code available here.

Next time, simply reload changes with "C-c i". If some stuff does not work (in particular in the org-mode website generation section or in the tabs section), just comment them and proceed.

Once you've reach this point, you have a working emacs with many convenient features activated.

Org-mode header

You'll want to have a journal so I strongly suggest you put the following lines on the top of ~/org/journal.org. This is where your notes captured with C-c c (this is explained in the following section) will go.

# -*- mode: org -*-
# -*- coding: utf-8 -*-
#+STARTUP: overview indent inlineimages logdrawer
#+TITLE:       Journal
#+AUTHOR:      Arnaud Legrand (original author, replace with your name)
#+LANGUAGE:    en
#+TAGS: POLARIS(P) LIG(L) HOME(H) Europe(E) Blog(B) noexport(n) Stats(S)
#+TAGS: Epistemology(E) Vulgarization(V) Teaching(T) R(R) OrgMode(O)
#+OPTIONS:   H:3 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc

Short documentation on emacs shortcuts:

Emacs shortcuts

Here are a few convenient emacs shortcuts for those that have never used emacs. Note that you may want to use two hours to follow the emacs tutorial (C-h t).

  • C-x C-c exit
  • C-x C-s save buffer
  • C-g panic mode ;) type this whenever you want to exit an awful series of shortcuts
  • C-x C-e call make
  • C-a jump to beginning of the line
  • C-e jump to end of the line
  • C-Space start selection marker
  • C-l reposition the screen
  • C-_ undo
  • C-s search
  • M-% replace
  • C-x C-h get the list of emacs shortcuts
  • C-c C-h get the list of emacs shortcuts considering the mode you are currently using (e.g., C, Lisp, org, …)

There are a bunch of cheatsheets also available out there.


Many emacs shortcuts start by C-x. Org-mode's shortcuts generaly start with C-c:

  • Tab fold/unfold
  • C-c C-c do something useful here (tag, execute, …)
  • C-c c capture (finish capturing with C-c C-c, this is explained on the top of the buffer that just opened)
  • C-c C-o open link
  • C-c C-t switch todo
  • C-c C-e export
  • M-Enter new item/section
  • C-c a agenda (try the L option)
  • C-c C-a attach files
  • C-c C-d set a deadl1ine (use S-arrows to navigate in the dates)
  • A-arrows move subtree (add shift for the whole subtree)

Org-mode Babel (for litterate programming)

  • <s + tab template for source bloc. You'll get this:

    #+BEGIN_SRC sh

    Now if you C-c C-c, it will execute the block

    | #journal.org# |
    | journal.html  |
    | journal.org   |
    | journal.org~  |
  • Source blocks have many options (formatting, arguments, names, sessions,…), which is why I have my own shortcuts <b + tab bash block (or B for sessions)

    #+begin_src sh :results output :exports both
    ls /tmp/*201*.pdf
    : /tmp/2015_02_bordeaux_otl_tutorial.pdf
    : /tmp/2015-ASPLOS.pdf
    : /tmp/2015-Europar-Threadmap.pdf
    : /tmp/europar2016-1.pdf
    : /tmp/europar2016.pdf
    : /tmp/M2-PDES-planning-examens-janvier2016.pdf
  • I have defined many such templates in my configuration. You can give a try to <h,<l,<e,<p,<m,<r,<R,…

Loading files:

Benefiting from org-mode's contrib

;;  (add-to-list 'load-path "/usr/share/org-mode/lisp/")
  (add-to-list 'load-path "/home/alegrand/Work/org-mode/install/org-mode/emacs/site-lisp/org/")


(require 'package)
(setq package-archives
'(("ELPA" . "http://tromey.com/elpa/")
   ("gnu" . "http://elpa.gnu.org/packages/")
   ("melpa" . "http://melpa.milkbox.net/packages/")
   ("marmalade" . "http://marmalade-repo.org/packages/")))

Adding .el files stored in folder elisp:   WEB

(add-to-list 'load-path "~/lib/elisp/")
;; (add-to-list 'load-path "~/.emacs.d/elpa/org-20150302/")
(add-to-list 'load-path "~/.emacs.d/elpa/xclip-1.3/")
;; (add-to-list 'load-path "~/.emacs.d/elpa/htmlize-20130207.1202/")
(add-to-list 'load-path "~/.emacs.d/elpa/polymode-20151013.814/")
(add-to-list 'load-path "~/.emacs.d/elpa/lua-mode-20150518.942/")
(add-to-list 'load-path "~/.emacs.d/elpa/toc-org-20150801.748/")
(add-to-list 'load-path "~/.emacs.d/elpa/epresent-20150324.610/")

[10:42:15; 24.06.2013]

Loading babel:   ARNAUD

Really loading babel

(require 'org-install)
(require 'org)
;; (require 'org-html)

[17:28:05; 30.05.2013]

Font lock   WEB

Useful if you want to export org files in batch mode…

(require 'font-lock)      
(require 'cc-mode) 

File/mode association   ARNAUD

(setq auto-mode-alist
   (append (mapcar 'purecopy
      '(("\\.c$"   . c-mode)
        ("\\.h$"   . c-mode)
        ("\\.c.simp$" . c-mode)
        ("\\.h.simp$" . c-mode)
        ("\\.a$"   . c-mode)
        ("\\.w$"   . cweb-mode)
        ("\\.cc$"   . c++-mode)
        ("\\.S$"   . asm-mode)
        ("\\.s$"   . asm-mode)
        ("\\.p$"   . pascal-mode)
        ("\\.Rmd$" . poly-markdown-mode)
        ("\\.pas$" . pascal-mode)
        ("\\.tex$" . LaTeX-mode)
        ("\\.txi$" . Texinfo-mode)
        ("\\.el$"  . emacs-lisp-mode)
        ("emacs"  . emacs-lisp-mode)
        ("\\.ml[iylp]?" . tuareg-mode)
        ("[mM]akefile" . makefile-mode)
        ("[mM]akefile.*" . makefile-mode)
        ("\\.mak" . makefile-mode)
        ("\\.cshrc" . sh-mode)
        ("\\.html$" . html-mode)
        ("\\.org$" . org-mode)
)) auto-mode-alist))

Emacs aesthetics:

Remove splash screen:   WEB

(setq inhibit-splash-screen t)

[16:29:14; 24.04.2013]

Change frame name of emacs:   LUKA WEB

(setq frame-title-format
  '("Emacs - " (buffer-file-name "%f"
    (dired-directory dired-directory "%b"))))

[16:29:40; 24.04.2013]

Font size   ARNAUD

;; (set-default-font "9x15")
;; (set-frame-font "-1ASC-Droid Sans Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1")
(set-frame-font "-PfEd-DejaVu Sans Mono-normal-normal-normal-*-29-*-*-*-m-0-iso10646-1")

Text coloring   ARNAUD

  (global-font-lock-mode t)
    '(flyspell-incorrect ((t (:inverse-video t)))))
  ;;  (set-face-attribute 'flyspell-incorrect (t (:inverse-video t)))

Line and column numbering   ARNAUD

(line-number-mode 1)
(column-number-mode 1)

Parenthesis   ARNAUD

(load-library "paren")
(show-paren-mode 1)
(transient-mark-mode t)
(require 'paren)


Load emacs initialization file:   LUKA

(global-set-key (kbd "C-c i") 
(lambda() (interactive)(org-babel-load-file "~/.emacs.d/init.org")))

[16:28:10; 24.04.2013]

UTF 8 by default   ARNAUD

(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

Keyboard fix for Mac OS X users…   ADRIEN

Thanks to Adrien Lebre for providing me with this ns-use-mac-modifier-symbols thing. Unfortunately, this is broken at the moment (I tried to wrap the command around the cond but it should fail on mac).

 ((string-equal system-type "darwin")   ; Mac OS X
     ns-command-modifier 'meta         ; Apple/Command key is Meta
         ns-alternate-modifier nil         ; Option is the Mac Option key
         ns-use-mac-modifier-symbols  nil  ; display standard Emacs (and not standard Mac) modifier symbols

CUA mode a.k.a C-x, C-c, C-v

Yuck! Many people like this but I hate it as it conflicts with some of my other shortcuts (e.g., the ones for spelling a region).

;; (cua-mode t)

Hide/show the C block:   LUKA WEB

(add-hook 'c-mode-common-hook
    (local-set-key (kbd "C-c <right>") 'hs-show-block)
    (local-set-key (kbd "C-c <left>")  'hs-hide-block)
    (local-set-key (kbd "C-c <up>")    'hs-hide-all)
    (local-set-key (kbd "C-c <down>")  'hs-show-all)
    (hs-minor-mode t)))

[16:32:57; 24.04.2013]

Reload buffer:   ARNAUD

(global-set-key [f5] '(lambda () (interactive) (revert-buffer nil t nil)))

[16:34:57; 24.04.2013]

Compile / Make

(global-set-key "\^x\^e" 'compile)

Navigate back in text   ARNAUD

(defun jump-mark ()
  (set-mark-command (point)))
(defun beginning-of-defun-and-mark ()
  (push-mark (point))
(defun end-of-defun-and-mark ()
  (push-mark (point))

(global-set-key "\^c\^b" 'beginning-of-defun-and-mark)
(global-set-key "\^c\^e" 'end-of-defun-and-mark)
(global-set-key "\^c\^j" 'jump-mark)
(global-set-key [S-f6] 'jump-mark)              ;; jump from mark to mark

Goto line   ARNAUD

(global-set-key "\M-g" 'goto-line)

Use X clipboard (cut'n paste)   WEB

Since I switched to emacs 24, cutting and pasting to emacs has become burdensome. For example, I had to do S-C-c after selecting terminals areas before being able to copy in emacs. With the following commants, I don't have to do this anymore. I wish it would have eased interactions when running emacs in a terminal (i.e., with -nw) but it does not. :( http://stackoverflow.com/questions/13036155/how-to-to-combine-emacs-primary-clipboard-copy-and-paste-behavior-on-ms-windows

(setq select-active-regions nil)
(setq x-select-enable-primary t)
(setq x-select-enable-clipboard t)
(setq mouse-drag-copy-region t)

Cut'n paste in no-window mode   WEB

Despite what can be found in many old discussions on emacs mailing lists, it seems to be possible and the trick is to use xclip! http://stackoverflow.com/questions/4580835/emacs-copy-kill-ring-to-system-clipboard-in-nowindow-mode http://stackoverflow.com/questions/5288213/how-can-i-paste-the-selected-region-outside-of-emacs/14659015#14659015

If you simply use the following commands, then emacs cut-n-paste works just perfectly with the X clipboard. I can select in emacs no window and then paste with the middle-click button! :) Many thanks to Vijay for pointing me out that I had forgotten the "require" line… :)

;;  (if(string-equal system-type "gnu/linux")   ; Linux!
;;      (
       (require (quote xclip))
       (xclip-mode 1)
;;      )()
;;        )

Increase/decrease text size in emacs   WEB

(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
;; C-x C-0 restores the default font size

[11:26:47; 18.04.2014]

Add spell checker to the file   WEB

;; Inspired from http://tex.stackexchange.com/questions/166681/changing-language-of-flyspell-emacs-with-a-shortcut
;; (defun spell (choice)
;;    "Switch between language dictionaries."
;;    (interactive "cChoose:  (a) American | (f) Francais")
;;     (cond ((eq choice ?1)
;;            (setq flyspell-default-dictionary "american")
;;            (setq ispell-dictionary "american")
;;            (ispell-kill-ispell))
;;           ((eq choice ?2)
;;            (setq flyspell-default-dictionary "francais")
;;            (setq ispell-dictionary "francais")
;;            (ispell-kill-ispell))
;;           (t (message "No changes have been made."))) )

(define-key global-map (kbd "C-c s a") (lambda () (interactive) (ispell-change-dictionary "american")))
(define-key global-map (kbd "C-c s f") (lambda () (interactive) (ispell-change-dictionary "francais")))
(define-key global-map (kbd "C-c s r") 'flyspell-region)
(define-key global-map (kbd "C-c s b") 'flyspell-buffer)
(define-key global-map (kbd "C-c s s") 'flyspell-mode)

Invoke magit (for git)   WEB

From http://magit.vc/manual/magit.pdf

(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-x M-g") 'magit-dispatch-popup)
;; (global-magit-file-mode 1)

Visual-line-mode (line wrap)   WEB

From https://www.emacswiki.org/emacs/LineWrap

(define-key global-map (kbd "C-c w") 'visual-line-mode)

Small fixes:

PDF with LaTeX by default   ARNAUD

(defun auto-fill-mode-on () (TeX-PDF-mode 1))
(add-hook 'tex-mode-hook 'TeX-PDF-mode-on)
(add-hook 'latex-mode-hook 'TeX-PDF-mode-on)
(setq TeX-PDF-mode t)


(defun auto-fill-mode-on () (auto-fill-mode 1))
(add-hook 'text-mode-hook 'auto-fill-mode-on)
(add-hook 'emacs-lisp-mode 'auto-fill-mode-on)
(add-hook 'tex-mode-hook 'auto-fill-mode-on)
(add-hook 'latex-mode-hook 'auto-fill-mode-on)

C coding style   WEB

From http://www.emacswiki.org/emacs/IndentingC.

  (setq c-default-style "k&r")
  (setq c-basic-offset 2)

Convenient shortcut to reindent C files

 (defun c-reformat-buffer()
    (setq sh-indent-command (concat
                             "indent -i2 -kr --no-tabs"
  (define-key c-mode-base-map [f7] 'c-reformat-buffer)

Asking for confirmation concisely:   WEB

Link: http://org.ryuslash.org/dotfiles/emacs/init.html#sec-7-1 Being asked to type in yes explicitly all the time gets very tedious. I understand that it is safer since y is much easier to type in accidentally than yes and so the potential to say yes to things you don't want is there, but I haven't had any such problems yet.

(defalias 'yes-or-no-p 'y-or-n-p)

[16:27:20; 24.04.2013]

Org-mode convenient configuration

Default directory

(setq org-directory "~/org/")


(setq org-hide-leading-stars t)
(setq org-alphabetical-lists t)
(setq org-src-fontify-natively t)  ;; you want this to activate coloring in blocks
(setq org-src-tab-acts-natively t) ;; you want this to have completion in blocks
(setq org-hide-emphasis-markers t) ;; to hide the *,=, or / markers
(setq org-pretty-entities t)       ;; to have \alpha, \to and others display as utf8 http://orgmode.org/manual/Special-symbols.html


Add short cut keys for the org-agenda   ARNAUD

(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-capture)
(global-set-key (kbd "C-c a") 'org-agenda)
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map (kbd "C-c a") 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(setq org-default-notes-file "~/org/notes.org")
     (define-key global-map "\C-cd" 'org-capture)
(setq org-capture-templates (quote (("t" "Todo" entry (file+headline "~/org/liste.org" "Tasks") "* TODO %?
  %a" :prepend t) ("j" "Journal" entry (file+datetree "~/org/journal.org") "* %?
Entered on %U

Agenda config   ARNAUD

(setq org-agenda-include-all-todo t)
(setq org-agenda-include-diary t)

Google agenda   ARNAUD

(setq org-agenda-files (quote ("~/org/liste.org" "~/org/google.org")))
(setq revert-without-query (quote ("google.org")))

Org-id for storing objects ???   ARNAUD

(setq org-id-method (quote uuidgen))

Setting "Wrap at window edge" for .org mode:   WEB

;; (global-visual-line-mode t)

[16:32:35; 24.04.2013]

Heading is DONE when all checkboxes are checked:   WEB

Mark heading done when all checkboxes are checked.

An item consists of a list with checkboxes. When all of the checkboxes are checked, the item should be considered complete and its TODO state should be automatically changed to DONE. The code below does that. This version is slightly enhanced over the one in the mailing list (see http://thread.gmane.org/gmane.emacs.orgmode/42715/focus=42721) to reset the state back to TODO if a checkbox is unchecked.

Note that the code requires that a checkbox statistics cookie (the [/] or [%] thingie in the headline - see the Checkboxes section in the manual) be present in order for it to work. Note also that it is too dumb to figure out whether the item has a TODO state in the first place: if there is a statistics cookie, a TODO/DONE state will be added willy-nilly any time that the statistics cookie is changed.

;; see http://thread.gmane.org/gmane.emacs.orgmode/42715
(eval-after-load 'org-list
  '(add-hook 'org-checkbox-statistics-hook (function ndk/checkbox-list-complete)))

(defun ndk/checkbox-list-complete ()
    (org-back-to-heading t)
    (let ((beg (point)) end)
      (setq end (point))
      (goto-char beg)
      (if (re-search-forward "\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" end t)
            (if (match-end 1)
                (if (equal (match-string 1) "100%")
                    ;; all done - do the state change
                    (org-todo 'done)
                  (org-todo 'todo))
              (if (and (> (match-end 2) (match-beginning 2))
                       (equal (match-string 2) (match-string 3)))
                  (org-todo 'done)
                (org-todo 'todo)))))))

[16:27:59; 24.04.2013]

Allow shift selection in org-mode   LUKA

Luka suggested using this: https://www.emacswiki.org/emacs/org-cua-dwim.el I simply pasted it here and it seemed to work like a charm.

(defun org-cua-dwim-turn-on-org-cua-mode-partial-support ()
  "This turns on org-mode cua-mode partial support; Assumes
shift-selection-mode is available."
  (set (make-local-variable 'org-support-shift-select) t)
  (cua-mode 1)
  (add-hook 'pre-command-hook 'cua--pre-command-handler nil t)
  (add-hook 'post-command-hook 'cua--post-command-handler nil t)
  (set (make-local-variable 'cua-mode) t)
  (set (make-local-variable 'org-cua-dwim-was-move) nil)
  (set (make-local-variable 'shift-select-mode) nil))

(add-hook 'org-mode-hook 'org-cua-dwim-turn-on-org-cua-mode-partial-support)

(defvar org-cua-dwim-was-move nil)
(defvar org-cua-dwim-debug nil)
(defvar org-cua-dwim t)

(defadvice handle-shift-selection (around org-cua-dwim)
  (let ((is-org-mode (and (not (minibufferp))
                          (eq major-mode 'org-mode)))
        (do-it t))
    (setq org-cua-dwim-shift-translated this-command-keys-shift-translated)
    (when (and org-cua-dwim
               is-org-mode this-command-keys-shift-translated
               (not org-cua-dwim-was-move))
      (when org-cua-dwim-debug
        (message "Turn ON shift-select-mode & delete-selection-mode"))
      (delete-selection-mode 1)
      (set (make-local-variable 'org-cua-dwim-was-move) t)
      (set (make-local-variable 'cua--last-region-shifted) t)
      (set (make-local-variable 'cua--explicit-region-start) nil)
      (set (make-local-variable 'shift-select-mode) t)
      (set (make-local-variable 'cua-mode) nil))
    (when (and org-cua-dwim
               is-org-mode (not this-command-keys-shift-translated)
      (when org-cua-dwim-debug
        (message "Turn Off shift-select-mode & delete-selection-mode"))
      (delete-selection-mode -1)
      (set (make-local-variable 'shift-select-mode) nil)
      (set (make-local-variable 'cua-mode) t)
      (set (make-local-variable 'org-cua-dwim-was-move) nil))
    (when do-it
    (when (and org-cua-dwim

(defmacro org-cua-dwim-fix-cua-command (cmd)
  "Defines advice for a CUA-command that will turn on CUA mode
before runnind ant hen run the `cua--precommand-handler'"
     (defadvice ,(intern cmd) (around org-cua-dwim)
     "Try to fix the org copy and paste problem."
     (when (and (not (minibufferp)) (not cua-mode)
                (eq major-mode 'org-mode))
       (when org-cua-dwim-debug
         (message "Turn Off shift-select-mode & delete-selection-mode  (CUA command)"))
       (delete-selection-mode -1)
       (set (make-local-variable 'shift-select-mode) nil)
       (set (make-local-variable 'cua-mode) t)
       (set (make-local-variable 'org-cua-dwim-was-move) nil)
     (ad-activate ',(intern cmd))))

;; Advise all CUA commands active when selection is active
(org-cua-dwim-fix-cua-command "cua--prefix-override-handler")
(org-cua-dwim-fix-cua-command "cua-repeat-replace-region")
(org-cua-dwim-fix-cua-command "cua--shift-control-c-prefix")
(org-cua-dwim-fix-cua-command "cua--shift-control-x-prefix")
(org-cua-dwim-fix-cua-command "cua-toggle-rectangle-mark")
(org-cua-dwim-fix-cua-command "cua-delete-region")
(org-cua-dwim-fix-cua-command "cua-cut-region")
(org-cua-dwim-fix-cua-command "cua-copy-region")
(org-cua-dwim-fix-cua-command "cua-cancel")
(org-cua-dwim-fix-cua-command "cua-toggle-global-mark")
(org-cua-dwim-fix-cua-command "cua-paste")
(org-cua-dwim-fix-cua-command "cua-exchange-point-and-mark")
(org-cua-dwim-fix-cua-command "cua-scroll-down")
(org-cua-dwim-fix-cua-command "cua-scroll-up")
(org-cua-dwim-fix-cua-command "cua-set-mark")
(org-cua-dwim-fix-cua-command "cua-paste-pop")

(ad-activate 'handle-shift-selection)

Org-mode shortcuts

Adding date with brackets with command "C-c d":   LUKA

(global-set-key (kbd "C-c d") 'insert-date)
(defun insert-date (prefix)
    "Insert the current date. With prefix-argument, use ISO format. With
   two prefix arguments, write out the day and month name."
    (interactive "P")
    (let ((format (cond
                   ((not prefix) "** %Y-%m-%d")
                   ((equal prefix '(4)) "[%Y-%m-%d]"))))
      (insert (format-time-string format))))

[16:34:01; 24.04.2013]

Adding date with command "C-c t":   LUKA

(global-set-key (kbd "C-c t") 'insert-time-date)
(defun insert-time-date (prefix)
    "Insert the current date. With prefix-argument, use ISO format. With
   two prefix arguments, write out the day and month name."
    (interactive "P")
    (let ((format (cond
                   ((not prefix) "[%H:%M:%S; %d.%m.%Y]")
                   ((equal prefix '(4)) "[%H:%M:%S; %Y-%m-%d]"))))
      (insert (format-time-string format))))

[16:34:15; 24.04.2013]

Fix view TODO tree:   LUKA

(global-set-key (kbd "C-c v") 'org-show-todo-tree)

[16:34:40; 24.04.2013]

Org-store-link:   ARNAUD

(global-set-key (kbd "C-c l") 'org-store-link)

[16:35:48; 24.04.2013]

Adding shortcut for interactively inserting git link:   LUKA

;; (require 'org-git-link) ;; Made some personal modifications
;; (global-set-key (kbd "C-c g") 'org-git-insert-link-interactively)

[16:36:31; 24.04.2013]

Adding shortcut for data entry:   LUKA

(global-set-key (kbd "C-c e") (lambda ()
                  (insert "** data#\n*** git:\n#+begin_src sh\ngit log -1\n#+end_src\n*** Notes:" )))
                  ;;(insert "** data#\n[[shell:git log -1][git]]\n" )))
                  ;;(insert "** data#\n[[shell:git log -1][git]]\n" (format-time-string "[%H:%M:%S; %d.%m.%Y]" ))))

[16:36:15; 24.04.2013]

Navigating through org-mode:

Additional shortcuts for navigating through org-mode documents:

(global-set-key (kbd "C-c <up>") 'outline-up-heading)
(global-set-key (kbd "C-c <left>") 'outline-previous-visible-heading)
(global-set-key (kbd "C-c <right>") 'outline-next-visible-heading)

[18:01:07; 27.05.2013]


Convenient built-in shortcuts.

C-x n s     (org-narrow-to-subtree)
    Narrow buffer to current subtree.
C-x n b     (org-narrow-to-block)
    Narrow buffer to current block.
C-x n w     (widen)
    Widen buffer to remove narrowing.

Navigating through org-mode: Goto last entry   WEB


(defun org-goto-last-heading-in-tree ()
  (org-forward-heading-same-level 1)     ; 1. Move to next tree
  (outline-previous-visible-heading 1)   ; 2. Move to last heading in previous tree
  (let ((org-special-ctrl-a/e t))        ; 3. Ignore tags when
    (org-end-of-line)))                  ;    moving to the end of the line
(define-key org-mode-map (kbd "C-c g") 'org-goto-last-heading-in-tree)
(defun goto-last-heading ()
(global-set-key (kbd "C-c <down>") 'goto-last-heading)

Org-mode + babel:

Seamless use of babel (no confirmation, lazy export)   ARNAUD

(setq org-export-babel-evaluate nil) ;; This is for org-mode<9. 
;;  Otherwise, you need to set #+PROPERTY: header-args :eval never-export in the beginning or your document
(setq org-confirm-babel-evaluate nil)

Some initial languages we want org-babel to support:   ARNAUD

     (shell . t)
     (python . t)
     (R . t)
     (ruby . t)
     (ocaml . t)
     (ditaa . t)
     (dot . t)
     (octave . t)
     (sqlite . t)
     (perl . t)
     (screen . t)
     (plantuml . t)
     (lilypond . t)
     (org . t)
     (makefile . t)
  (setq org-src-preserve-indentation t)

Adding source code blocks:   LUKA

With capital letters:

To use this type <S and then TAB

(add-to-list 'org-structure-template-alist
        '("S" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>"))

Emacs-elisp code:

To use this type <m and then TAB

(add-to-list 'org-structure-template-alist
        '("m" "#+begin_src emacs-lisp\n\n#+end_src" "<src lang=\"emacs-lisp\">\n\n</src>"))

R code:

To use this type <r and then TAB. This creates an R block for textual output.

(add-to-list 'org-structure-template-alist
        '("r" "#+begin_src R :results output :session *R* :exports both\n\n#+end_src" "<src lang=\"R\">\n\n</src>"))

To use this type <R and then TAB. This creates an R block for graphics that are stored in the /tmp/.

(add-to-list 'org-structure-template-alist
        '("R" "#+begin_src R :results output graphics :file (org-babel-temp-file \"figure\" \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>"))

To use this type <RR and then TAB. This creates an R block for graphics that are stored in the directory of the current file.

(add-to-list 'org-structure-template-alist
        '("RR" "#+begin_src R :results output graphics :file  (org-babel-temp-file (concat (file-name-directory (or load-file-name buffer-file-name)) \"figure-\") \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>"))

Python code

To use this type <p and then TAB

(add-to-list 'org-structure-template-alist
        '("p" "#+begin_src python :results output :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))
(add-to-list 'org-structure-template-alist
        '("P" "#+begin_src python :results output :session *python* :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))

Bash "sh" code:

To use this type <b and then TAB

(add-to-list 'org-structure-template-alist
        '("b" "#+begin_src sh :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))

To use this type <B and then TAB. This comes with a session argument (e.g., in case you want to keep ssh connexions open).

(add-to-list 'org-structure-template-alist
        '("B" "#+begin_src sh :session foo :results output :exports both \n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))

[18:23:44; 21.06.2013]


(add-to-list 'org-structure-template-alist
        '("g" "#+begin_src dot :results output graphics :file \"/tmp/graph.pdf\" :exports both
   digraph G {
      node [color=black,fillcolor=white,shape=rectangle,style=filled,fontname=\"Helvetica\"];
   }\n#+end_src" "<src lang=\"dot\">\n\n</src>"))

Evaluating whole subtree:   LUKA

(global-set-key (kbd "C-c S-t") 'org-babel-execute-subtree)

[15:25:16; 17.12.2013]

Display images   ARNAUD

(add-hook 'org-babel-after-execute-hook 'org-display-inline-images) 
(add-hook 'org-mode-hook 'org-display-inline-images)
(add-hook 'org-mode-hook 'org-babel-result-hide-all)

Org-mode LaTeX export


 (unless (boundp 'org-latex-classes) (setq org-latex-classes nil))

 (add-to-list 'org-latex-classes '("acm-proc-article-sp" "\\documentclass{acm_proc_article-sp}\n \[NO-DEFAULT-PACKAGES]\n \[EXTRA]\n  \\usepackage{graphicx}\n  \\usepackage{hyperref}"  ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}")                       ("\\subsubsection{%s}" . "\\subsubsection*{%s}")                       ("\\paragraph{%s}" . "\\paragraph*{%s}")                       ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

 (setq org-latex-to-pdf-process '("pdflatex -interaction nonstopmode -output-directory %o %f ; bibtex `basename %f | sed 's/\.tex//'` ; pdflatex -interaction nonstopmode -output-directory  %o %f ; pdflatex -interaction nonstopmode -output-directory %o %f"))

General articles   LUKA

I'm not completely sure I need this. I could probably remove it…

(add-to-list 'org-latex-classes '("article" "\\documentclass{article}\n \[NO-DEFAULT-PACKAGES]\n \[EXTRA]\n  \\usepackage{graphicx}\n  \\usepackage{hyperref}"  ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}")                       ("\\subsubsection{%s}" . "\\subsubsection*{%s}")                       ("\\paragraph{%s}" . "\\paragraph*{%s}")                       ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

[15:18:27; 16.05.2013]

Edit thunderbird/icedove emails with emacs:

Use org mode for eml files (useful for thunderbird plugin)   WEB

Stolen from http://pragmaticemacs.com/emacs/use-emacs-for-thunderbird-emails/

(add-to-list 'auto-mode-alist '("\\.eml\\'" . org-mode))

Remote file editing-TRAMP:   WEB

This is installed by default for most of emacs Remote File Editing Using Emacs

Emacs has a package called TRAMP (Transparent Remote (file) Access, Multiple Protocol) which allows you to edit files on remote machines via SSH. Since Emacs 22, TRAMP is included with the distribution.

All you need to do is add the following lines to your .emacs file,

(require 'tramp)
(setq tramp-default-method "scp")

Then in order to open a file on a remote machine, you can use,

C-x C-f /user@your.host.com:/path/to/file

If you don't want to enter your password every time you open or save a file consider using Public Key Authentication.

TRAMP mode can also be used to edit files on the same machine as another user, if you want to open some file as root you can use,

C-x C-f /root@ [12:25:12; 13.06.2013]