Recently I've been setting up an org-mode file in emacs which holds my entire "init.el" to run emacs from. As its all quite stable now and working well, I'm putting it up here in case others want to try something similar.

Installation instructions

* installation Instructions
Then copy it into =~/.emacs.d/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 
# [[file:../blog/2014/05/15/][this blog entry]]).
# - 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.

# My ~/.emacs.d/init.el file contains only:
# --8<---------------cut here---------------start------------->8---
# ;;; -*- emacs-lisp-mode -*- --- init file
# ;;; mine from 12-11-2014

# (package-initialize)
# (require 'ob-tangle)
# (org-babel-load-file "~/.emacs.d/org/")

# (provide 'init.el)
# ;;; init.el ends here
# --8<---------------cut here---------------end--------------->8---
# (require 'org)
# ;; Load the actual configuration file
# (org-babel-load-file
#   (expand-file-name (concat user-emacs-directory ".emacs.d/org/")))

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/ 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.

* a-z my key bindings
C-x n e  ;; latex narrow-to-environment

* loading files
** debug on error
 #+BEGIN_SRC emacs-lisp
  (setq debug-on-error t
  debug-on-signal nil
  debug-on-quit nil)
#+BEGIN_SRC emacs-lisp
(require 'package)
(add-to-list 'package-archives '("marmalade"."") t)
(add-to-list 'package-archives '("melpa"."") t)
(add-to-list 'package-archives '("GNU"."") t)
(setq package-enable-at-startup nil)
[2014-11-21 Fri 18:08]

** Adding .el files stored in folder elisp
#+BEGIN_SRC emacs-lisp
(setq load-path (cons "/home/$USER/.emacs.d/lisp" load-path))
;; This sets up the load path so that we can override it
(package-initialize nil)
;; Override the packages with the git version of Org and other packages
(add-to-list 'load-path "~/git/org-mode/lisp")
(add-to-list 'load-path "~/git/org-mode/contrib/lisp")
;; Load the rest of the packages
(package-initialize t)
(setq package-enable-at-startup nil)
(add-to-list 'load-path "/home/$USER/.emacs.d/personal-elisp")
(add-to-list 'load-path "/home/$USER/.emacs.d/lisp")
(add-to-list 'load-path "/home/$USER/.emacs.d/elpa")
(setq custom-file "/home/$USER/.emacs.d/custom.el")
(load custom-file)
(require 'tabbar)
(tabbar-mode t)
(linum-mode 0)
(require 'setup-autocomplete)
(require 'rainbow-delimiters)
(require 'rainbow-mode)
(require 'flycheck)
(require 'bookmark+)
(require 'paredit)
(show-paren-mode t)
(require 'bind-key)
(require 'imenu+)
(require 'org-bullets)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode t)))
(require 'org-capture)
(require 'remember)
(require 'org-remember)
(require 'org-w3m)
(require 'buffer-move)
(require 'bm)
(setq bm-marker 'bm-marker-right)

(add-hook 'emacs-lisp-mode-hook 'paredit-mode)
(add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode)
(show-paren-mode 1)
(electric-pair-mode 1)

(setq display-time-mode t)
; '(global-smart-tab-mode t)
 (setq show-paren-mode t)
 '(show-smartparens-global-mode +1)
(setq column-number-mode t)
(setq selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;; Language Environment
(set-language-environment 'utf-8)

(setq org-startup-indented t)
(require 'imenu+)
(setq org-agenda-skip-deadline-if-done t)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook
                  '(lambda() (set-fill-column 68)))
(add-hook 'org-mode-hook
                  '(lambda() (linum-mode -1)))
[2014-11-12 Wed 19:08]

* emacs aesthetics:
** Remove splash screen
#+BEGIN_SRC emacs-lisp
  (setq inhibit-splash-screen t)
[2014-11-13 Thu 18:45]
** Remove start up cruft
#+BEGIN_SRC emacs-lisp
  ;; Switch off start up message to have scatch buffer
  (setq inhibit-startup-message t)
  ;; Nothing in scratch buffer
  (setq initial-scratch-message nil)
  ; each line of text gets one line on the screen (i.e., text will run
  ; off the left instead of wrapping around onto a new line)
  (setq-default truncate-lines 1)
  (visual-line-mode t)
  ; truncate lines even in partial-width windows
  (setq truncate-partial-width-windows 1)
[2014-11-14 Fri 11:26]

** Text coloring
#+BEGIN_SRC emacs-lisp
  (global-font-lock-mode t)
[2014-11-13 Thu 18:46]

** Parenthesis
#+BEGIN_SRC emacs-lisp
  (require 'paren)
  (load-library "paren")
   (show-paren-mode 1)
   (transient-mark-mode t)
[2014-11-14 Fri 11:36]

** autocomplete
#+BEGIN_SRC emacs-lisp
  (add-to-list 'load-path "~/.emacs.d/elpa/auto-complete")
  (require 'auto-complete)
  (add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-20140803.2118/dict")
  (require 'auto-complete-config)
  (global-auto-complete-mode t)
[2014-11-14 Fri 11:32]
** misc
#+BEGIN_SRC emacs-lisp
  (show-paren-mode 1) ; turn on paren match highlighting
  (setq auto-save-default nil) ; stop creating #autosave# files
[2014-11-17 Mon 11:20]

* shortcuts
** Load emacs initialization file
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-c i")
  (lambda() (interactive)(org-babel-load-file "~/.emacs.d/org/")))
[2014-11-11 Tue 15:24]

** Reload buffer
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-x C-r") 'revert-this-buffer)
[2014-11-11 Tue 15:26]
** new buffer
#+BEGIN_SRC emacs-lisp
  (defun xah-new-empty-buffer ()
    "Open a new empty buffer."
    (let ((buf (generate-new-buffer "untitled")))
      (switch-to-buffer buf)
      (funcall (and initial-major-mode))))
[2014-11-17 Mon 11:30]

** Use X clipboard (cut'n paste)
#+BEGIN_SRC emacs-lisp
  (cua-mode t)
  ;; CUA mode sets up key bindings used in many other applications (`C-x',
  ;; `C-c', `C-v' and `C-z').
  ;; The `C-x' and `C-c' keys only do cut and copy when the region is active, so
  ;; in most cases, they do not conflict with the normal function of these
  ;; prefix keys.

** use yasnippet
#+BEGIN_SRC emacs-lisp
  (add-to-list 'load-path
  (require 'yasnippet)
  (yas-global-mode t)
         (require 'dropdown-list)
         (setq yas-prompt-functions '(yas-dropdown-prompt
  ;; default TAB key is occupied by auto-complete
  (global-set-key (kbd "C-c ; u") 'yas/expand)
  ;; default hotkey `C-c & C-s` is still valid
  (global-set-key (kbd "C-c ; s") 'yas/insert-snippet)
  ;; use yas/completing-prompt when ONLY when `M-x yas/insert-snippet'
  ;; thanks to capitaomorte for providing the trick.
  (defadvice yas/insert-snippet (around use-completing-prompt activate)
       "Use `yas/completing-prompt' for `yas/prompt-functions' but only here..."
         (let ((yas-prompt-functions '(yas/completing-prompt)))
     (setq yas-snippet-dirs '("~/.emacs.d/snippets"))
  (add-hook 'text-mode-hook 'yas-minor-mode)
  (add-hook 'prog-mode-hook 'yas-minor-mode)
  (add-hook 'LaTeX-mode-hook 'yas-minor-mode)
  (require 'snippet)
  ;; [09:54:45; 12.11.2014]
  (setq yas-prompt-functions
        (cons 'yas-ido-prompt
         (remove 'yas-ido-prompt
[2014-11-13 Thu 18:52]

#+BEGIN_SRC emacs-lisp
  ;; load yasnippet
  (require 'yasnippet)
;; source =
[2014-11-16 Sun 14:31]

** jump to a definition - use 'M-i'
#+BEGIN_SRC emacs-lisp
  ;; Jump to a definition in the current file. (This is awesome.)
  (global-set-key (kbd "M-i") 'prelude-ido-goto-symbol)
  (require 'imenu)
  (set-default 'imenu-auto-rescan t)
  (defun prelude-ido-goto-symbol (&optional symbol-list)
    "Refresh imenu and jump to a place in the buffer using Ido."
     (unless (featurep 'imenu)
       (require 'imenu nil t))
      ((not symbol-list)
       (let ((ido-mode ido-mode)
              (if (boundp 'ido-enable-flex-matching)
                  ido-enable-flex-matching t))
             name-and-pos symbol-names position)
         (unless ido-mode
           (ido-mode 1)
           (setq ido-enable-flex-matching t))
         (while (progn
                 (setq imenu--index-alist nil)
                  (prelude-ido-goto-symbol (imenu--make-index-alist))
                  (setq selected-symbol
                        (ido-completing-read "Symbol? " symbol-names))
                  (string= (car imenu--rescan-item) selected-symbol)))
         (unless (and (boundp 'mark-active) mark-active)
           (push-mark nil t nil))
         (setq position (cdr (assoc selected-symbol name-and-pos)))
          ((overlayp position)
           (goto-char (overlay-start position)))
           (goto-char position)))))
      ((listp symbol-list)
       (dolist (symbol symbol-list)
         (let (name position)
            ((and (listp symbol) (imenu--subalist-p symbol))
             (prelude-ido-goto-symbol symbol))
            ((listp symbol)
             (setq name (car symbol))
             (setq position (cdr symbol)))
            ((stringp symbol)
             (setq name symbol)
             (setq position
                   (get-text-property 1 'org-imenu-marker symbol))))
          (unless (or (null position) (null name)
                      (string= (car imenu--rescan-item) name))
            (add-to-list 'symbol-names name)
            (add-to-list 'name-and-pos (cons name position))))))))
[2014-11-16 Sun 16:09]

* small fixes
** Auto-fill-mode
#+BEGIN_SRC emacs-lisp
  (defun auto-fill-mode-on () (auto-fill-mode t))
  (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)

** Asking for confirmation concisely:                                   :WEB:
Link: [[]]
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
#+BEGIN_SRC emacs-lisp
(defalias 'yes-or-no-p 'y-or-n-p)
(setq use-dialog-box nil)
[2014-11-16 Sun 16:38]
** buffer control
#+BEGIN_SRC emacs-lisp
(define-prefix-command 'ctl-z-map)
(global-set-key (kbd "C-z") 'ctl-z-map)
(global-set-key (kbd "C-z C-c") 'compile)
(global-set-key (kbd "C-z C-b") 'switch-bury-or-kill-buffer)

(defun switch-bury-or-kill-buffer (&optional aggr)
  "With no argument, switch (but unlike C-x b, without the need
to confirm).  With C-u, bury current buffer.  With double C-u,
kill it (unless it's modified)."
  (interactive "P")
   ((eq aggr nil) (switch-to-buffer (other-buffer)))
   ((equal aggr '(4)) (bury-buffer))
   ((equal aggr '(16)) (kill-buffer-if-not-modified (current-buffer)))))
;; source -
[2014-11-16 Sun 18:24]
C-z C-c        ;; compile
C-z C-b        ;; move to next buffer
C-u C-z C-b    ;; bury current buffer
C-u C-u C-z C-b ;; kill the current buffer, only if its NOT modified

* org-mode convenient configuration
** Default directory
#+BEGIN_SRC emacs-lisp
  (setq org-directory "~/.emacs.d/org/")
[2014-11-12 Wed 19:07]

** Cosmetics
#+BEGIN_SRC emacs-lisp
  (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
[2014-11-13 Thu 20:14]

** Agenda
*** renew
#+BEGIN_SRC emacs-lisp
   ;; Get appointments for today
   (defun my-org-agenda-to-appt ()
    (setq appt-time-msg-list nil)
    (let ((org-deadline-warning-days 0))    ;; will be automatic in org 5.23
  ;; Run once, activate and schedule refresh
  (appt-activate t)
  (run-at-time "24:01" nil 'my-org-agenda-to-appt)
[2014-11-14 Fri 12:15]
** auto archive tasks
#+BEGIN_SRC emacs-lisp
(setq org-todo-state-tags-triggers '(("CANCELLED" ("ARCHIVE" . t))))
(defun my-org-archive-done-tasks ()
  (org-map-entries 'org-archive-subtree "/DONE" 'file))
(setq org-agenda-repeating-timestamp-show-all nil)
(org-agenda nil "a") ;; automatically creates an agenda  when emacs starts
(setq org-archive-all-done t)
[2014-11-20 Thu 12:15]

* agenda config
#+BEGIN_SRC emacs-lisp
    (setq org-agenda-span 21)
    (setq agenda-files (quote ("/home/$USER/.emacs.d/org/"
[2014-11-17 Mon 13:04]

** org todo keywords
#+BEGIN_SRC emacs-lisp
(setq org-todo-keywords
       ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!/!)")
         "WAITING(w@/!)" "HOLD(h@/!)" "|"
         "CANCELLED(c@/!)" "PHONE"))))

(setq org-todo-keyword-faces
      (quote (("TODO" :background "red1" :foreground "black" :weight bold :box (:line-width 2))
              ("NEXT" :foreground "OrangeRed" :weight bold)
              ("DONE" :background "forest green" :weight bold :box (:line-width 2 :style released-button))  
              ("WAITING" :foreground "blue" :weight bold)
              ("HOLD" :foreground "magenta" :weight bold)
              ("CANCELLED" :foreground "gray" :weight bold)
              ("PHONE" :foreground "gold" :weight bold)))
[2014-11-13 Thu 20:16]

** org misc
#+BEGIN_SRC emacs-lisp
(setq org-fontify-done-headline t)
[2014-11-13 Thu 20:20]
** strike-through of done tasks
#+BEGIN_SRC emacs-lisp
(setq org-fontify-done-headline t)
 '(org-done ((t (:foreground "forest green"   
                 :weight normal
                 :strike-through t))))
            ((((class color) (min-colors 16) (background dark)) 
               (:foreground "LightSalmon" :strike-through t)))))
[2014-11-21 Fri 11:49]
source -

** archiving
#+BEGIN_SRC emacs-lisp
(setq org-archive-mark-done nil)
(setq org-archive-location "%s_archive::* Archived Tasks")
(define-key org-mode-map (kbd "<f4>") 'org-advertized-archive-subtree)
[2014-11-21 Fri 11:05]
# FIXME: The archiving needs a lot more work on it, before I can
# realise it. 
#+BEGIN_SRC emacs-lisp
(defun bh/skip-non-archivable-tasks ()
  "Skip trees that are not available for archiving"
    ;; Consider only tasks with done todo headings as archivable candidates
    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max))))
          (subtree-end (save-excursion (org-end-of-subtree t))))
      (if (member (org-get-todo-state) org-todo-keywords-1)
          (if (member (org-get-todo-state) org-done-keywords)
              (let* ((daynr (string-to-int (format-time-string "%d" (current-time))))
                     (a-month-ago (* 60 60 24 (+ daynr 1)))
                     (last-month (format-time-string "%Y-%m-" (time-subtract (current-time) (seconds-to-time a-month-ago))))
                     (this-month (format-time-string "%Y-%m-" (current-time)))
                     (subtree-is-current (save-excursion
                                           (forward-line 1)
                                           (and (< (point) subtree-end)
                                                (re-search-forward (concat last-month "\\|" this-month) subtree-end t)))))
                (if subtree-is-current
                    subtree-end ; Has a date in this month or last month, skip it
                  nil))  ; available to archive
            (or subtree-end (point-max)))
[2014-11-21 Fri 11:05]
source -
This seems to be setup to archive stuff after one month.

* org-mode shortcuts
** Fix view TODO tree:                                                 :LUKA:
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-c v") 'org-show-todo-tree)
[16:34:40; 24.04.2013]
** Org-store-link:                                                   :ARNAUD:
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-c l") 'org-store-link)
[16:35:48; 24.04.2013]

** Navigating through org-mode:
Additional shortcuts for navigating through org-mode documents:
#+BEGIN_SRC emacs-lisp
  (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)
[2014-11-17 Mon 13:18]

** Narrowing
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.
** update cookies
#+BEGIN_SRC emacs-lisp
(defun myorg-update-parent-cookie ()
  (when (equal major-mode 'org-mode)

(defadvice org-kill-line (after fix-cookies activate)

(defadvice kill-whole-line (after fix-cookies activate)
;source =
[2014-11-14 Fri 06:39]
** appointments
#+BEGIN_SRC emacs-lisp
(appt-activate t)
;; 5 minute warning
(setq appt-message-warning-time '15)
(setq appt-display-interval '5)

;; Setup zenify, we tell appt to use window, and replace default function
(setq appt-display-format 'window)
(setq appt-disp-window-function (function my-appt-disp-window))
[2014-11-14 Fri 11:43]

#+BEGIN_SRC emacs-lisp
(defun djcb-popup (title msg &optional icon sound)
  "Show a popup if we're on X, or echo it otherwise; TITLE is the title
of the message, MSG is the context. Optionally, you can provide an ICON and
a sound to be played"

  (when sound (shell-command
                (concat "mplayer -really-quiet " sound " 2> /dev/null")))
  (if (eq window-system 'x)
    (shell-command (concat "notify-send "

                     (if icon (concat "-i " icon) "")
                     " '" title "' '" msg "'"))
    ;; text only version

    (message (concat title ": " msg))))

(djcb-popup "Warning" "The end is near"
         "/usr/share/icons/test.png" "/usr/share/sounds/beep.ogg")

;; the appointment notification facility
  appt-message-warning-time 15 ;; warn 15 min in advance

  appt-display-mode-line t     ;; show in the modeline
  appt-display-format 'window) ;; use our func
(appt-activate 1)              ;; active appt (appointment notification)
(display-time)                 ;; time display is required for this...

 ;; update appt each time agenda opened

(add-hook 'org-finalize-agenda-hook 'org-agenda-to-appt)

;; our little façade-function for djcb-popup
 (defun djcb-appt-display (min-to-app new-time msg)
    (djcb-popup (format "Appointment in %s minute(s)" min-to-app) msg
      "/usr/share/icons/gnome/32x32/status/appointment-soon.png" ))

      ;; "/usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg"

  (setq appt-disp-window-function (function djcb-appt-display))

;; you might also want to set:
;;   (setq org-agenda-skip-unavailable-files t)
;; so these warnings won't annoy the little remember-frame
;; also: I have noted infrequent problems when using ElScreen
;;  (the wrong frame might be chosen for Remember in about 10% of the cases)
[2014-11-14 Fri 12:07]

#+BEGIN_SRC emacs-lisp
(defun my-appt-disp-window (min-to-app new-time msg)
       (save-window-excursion (async-shell-command
       (concat "/usr/bin/zenity --info --title='Appointment' --text='" msg "'")   nil nil)))
[2014-11-14 Fri 11:44]
** html to org-mode
#+BEGIN_SRC emacs-lisp
(require 'org-w3m)
;;; C-c C-x M-w in w3m buffer
[2014-11-15 Sat 16:30]

** toggle-agenda-include-all-todo
#+BEGIN_SRC emacs-lisp
; This function makes it easier to toggle variables
(defun toggle-variable (var)
  "toggles boolean variable"
  (interactive "vToggle variable: ")
  (set var (not (symbol-value var)))
  (message "%s set to %s" var (symbol-value var))
;; toggle agenda view todos
(defun toggle-agenda-include-all-todo()
  "toggle the truncate-lines variable between true and false"
(toggle-variable 'org-agenda-include-all-todo)
(global-set-key [f3] 'toggle-agenda-include-all-todo)
[2014-11-19 Wed 22:38]

** remove deadlines done and appointment done
#+BEGIN_SRC emacs-lisp
(setq org-agenda-skip-deadline-if-done t)
;; Remove completed scheduled tasks from the agenda view
(setq org-agenda-skip-scheduled-if-done t)
[2014-11-20 Thu 16:39]

* org-mode + babel:
** Seamless use of babel (no confirmation, lazy export)              :ARNAUD:
#+BEGIN_SRC emacs-lisp
  (setq org-export-babel-evaluate nil)
  (setq org-confirm-babel-evaluate nil)
** Some initial languages we want org-babel to support:              :ARNAUD:
#+BEGIN_SRC emacs-lisp
     (sh . t)
     (python . t)
     (R . t)
     (ruby . t)
     (ditaa . t)
     (dot . t)
     (octave . t)
     (sqlite . t)
     (perl . t)
     (screen . t)
     (plantuml . t)
     (lilypond . t)

** Adding source code blocks:                                          :LUKA:
*** With capital letters:
To use this type <S and then TAB
#+BEGIN_SRC emacs-lisp
  (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
#+BEGIN_SRC emacs-lisp
  (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
#+BEGIN_SRC emacs-lisp
  (add-to-list 'org-structure-template-alist
        '("r" "#+begin_src R :results output :session :exports both\n\n#+end_src" "<src lang=\"R\">\n\n</src>"))

To use this type <R and then TAB
#+BEGIN_SRC emacs-lisp
  (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\n\n#+end_src" "<src lang=\"R\">\n\n</src>"))

*** Python code:
To use this type <p and then TAB
#+BEGIN_SRC emacs-lisp
  (add-to-list 'org-structure-template-alist
        '("p" "#+begin_src python :results output raw :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))
*** Bash "sh" code:
To use this type <b and then TAB
#+BEGIN_SRC emacs-lisp
  (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).
#+BEGIN_SRC emacs-lisp
  (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]
** Evaluating whole subtree:                                           :LUKA:
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-c S-t") 'org-babel-execute-subtree)

[15:25:16; 17.12.2013]
** Display images                                                    :ARNAUD:
#+BEGIN_SRC emacs-lisp
  (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)

* remember
;; source =
[2014-11-16 Sun 06:38]
**  Remember some history
#+BEGIN_SRC emacs-lisp
;; savehist keeps track of some history
(setq savehist-additional-variables
      ;; search entries
      '(search ring regexp-search-ring)
      ;; save every minute
      savehist-autosave-interval 60
      ;; keep the home clean
      savehist-file (concat user-emacs-directory "savehist"))
(savehist-mode t)
[2014-11-16 Sun 16:15]

**  Remember recent files
#+BEGIN_SRC emacs-lisp
;; save recent files
(require 'recentf)
(recentf-mode 1)
(setq recentf-save-file (concat user-emacs-directory "recentf")
      recentf-max-saved-items 200
      recentf-max-menu-items 20)
(recentf-mode t)
[2014-11-16 Sun 16:16]

* capture
** setup
#+BEGIN_SRC emacs-lisp
(setq org-default-notes-file (concat org-directory "/"))
(global-set-key (kbd "C-c c") 'org-capture)
(define-key global-map "\C-cc" 'org-capture)
;; (global-set-key (kbd "<F6>") 'org-capture)
(define-key org-capture-mode-map "C-c C-c" 'org-capture-finalize)
[2014-11-17 Mon 10:45]
;;(global-set-key (kbd "<f6>") 'org-capture) ;; this works
#+BEGIN_SRC emacs-lisp
(defun mrb/add-tags-in-capture()
  "Insert tags in a capture window without losing the point"

(bind-key "C-c C-t" 'mrb/add-tags-in-capture org-capture-mode-map)
[2014-11-19 Wed 16:35]

** templates
#+BEGIN_SRC emacs-lisp
(setq org-capture-templates
(quote (
("a" "Appointment" entry (file+datetree "~/.emacs.d/org/" "Calendar")
"* APPT %^{Description} %^g
Added: %U")
 ("x" "Check-box" checkitem 
       (file+headline "~/.emacs.d/org/" "Check-box"))
("c" "Clipboard" entry (file+headline "~/.emacs.d/org/" "") 
      "* %U %^{Head Line} %^g
 ("o" "Contacts" entry
      (file+headline "~/org/" "")
      "* %^{Name} :CONTACT:
 ("d" "Daily note" table-line (file+olp "~/.emacs.d/org/" "Daily notes")
          "| %u | %^{Note} |"
("l" "Log Time" entry (file+datetree
"~/.emacs.d/org/" )
"** %U - %^{Activity}  :TIME:")
("n" "Notes" entry (file+datetree "~/.emacs.d/org/")
"* %^{Description} %^g 
Added: %U")
 ("q" "Quick note" item
         (file+headline "~/.emacs.d/org/" "Quick notes"))
 ("s" "Someday" entry (file+datetree "~/.emacs.d/org/" "")
      "* %U %^{Someday Heading} 
("t" "Todo" entry (file+headline "~/.emacs.d/org/" "Tasks")
"* TODO %?\n %i\n %a")
[2014-11-22 Sat 13:02]

* menus
#+BEGIN_SRC emacs-lisp
(easy-menu-define sk-menu org-mode-map "My Org"
       ["Wrap Text" auto-fill-mode]
     ("Clock" ;; submenu
       ["In" org-clock-in]
       ["Out" org-clock-out]
       ["Resolve" org-resolve-clocks]
       ["Goto" org-clock-goto]
     ("Agenda" ;; submenu
       ["Regular View" org-agenda-list]
       ["Show Agenda" org-agenda]
[2014-11-20 Thu 16:42]

* using themes
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f11>") 'disable-theme)
(global-set-key (kbd "<f12>") 'load-theme)
[2014-11-14 Fri 06:11]

#+begin_src emacs-lisp
;;; F12 loads a theme, and autounloads a prior theme
;;; F11 can unload a theme

;;(add-to-list 'load-path "/usr/share/emacs24/site-lisp/emacs-goodies-el/color-theme.el")
;;(add-to-list 'load-path "/home/$USER/.emacs.d/themes/color-theme-tomorrow.el")
;;(require 'color-theme)
;;(require 'color-theme-tomorrow)
;;(eval-after-load "color-theme"
;;  '(progn
;;     (color-theme-initialize)
;;     (color-theme-lethe)))
;;    (tomorrow-day-theme)
;;(defface popup-mouse-face nil nil)
;;(defface ac-candidate-face nil nil)
;; Please set your themes directory to 'custom-theme-load-path
(add-to-list 'custom-theme-load-path
             (file-name-as-directory "/home/$USER/git/replace-colorthemes"))
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(add-to-list 'custom-theme-load-path "~/.emacs.d/elpa")
;; load your favorite theme
;;(load-theme 'solarized-light t t)
;;(load-theme 'solarized-dark t t)
;;(enable-theme 'solarized-dark)
;; (load-theme 'soft-stone t t)
;; (enable-theme 'soft-stone)
;; (load-theme 'badger t t)
;; (enable-theme 'badger)
;; (load-theme 'clarity t t)
;; (enable-theme 'clarity)
;; (load-theme 'clues t t)
;; (enable-theme 'clues)
;; (load-theme 'oswald t t)
;; (enable-theme 'oswald)
;; (load-theme 'stekene-dark t t)
;; (enable-theme 'stekene-dark)
;; (load-theme 'alect-black-alt t t)
;; (enable-theme 'alect-black-alt)
;; (load-theme 'tsdh-dark t t)
;; (enable-theme 'tsdh-dark)
;; (load-theme 'tango t t)
;; (enable-theme 'tango)
;; (load-theme 'tty-dark t t)
;; (enable-theme 'tty-dark)
;; (load-theme 'tty-dark t t)
;; (enable-theme 'tty-dark)
;; (load-theme 'manoj-dark t t)
;; (enable-theme 'manoj-dark)
;; (load-theme 'renegade t t)
;; (enable-theme 'renegade)
;; (load-theme 'brin t t)
;; (enable-theme 'brin)
;; (load-theme 'spolsky t t)
;; (enable-theme 'spolsky)
;; (load-theme 'ir-black t t)
;; (enable-theme 'ir-black)
;; (load-theme 'niflheim t t)
;; (enable-theme 'niflheim)
(load-theme 'darkest-midnight t t) ;; my own theme
(enable-theme 'darkest-midnight)
;; (load-theme 'monokai t t)
;; (enable-theme 'monokai)

(add-to-list 'custom-theme-load-path
(add-to-list 'custom-theme-load-path "/home/$USER/.emacs.d/themes")
(add-to-list 'custom-theme-load-path "/home/$USER/.emacs.d/elpa")
;; set up a variable and initialize it
(defvar tj-current-theme 'flatui "Current Color Theme")
;; Install the default scheme
(load-theme tj-current-theme t)
;; Function to first disable current theme, then create
;; and install a new one
(defun tj-load-theme (new-theme)
  "Disable existing themes before loading new theme"
  (disable-theme tj-current-theme)
  (setq tj-current-theme new-theme)
  (load-theme tj-current-theme))

;; Example menu
(easy-menu-add-item ;; console
 nil nil
 '(["1) Dark - Goldenrod" (tj-load-theme 'goldenrod) :active t]
   ["2) Dark - Darkest midnight" (tj-load-theme 'darkest-midnight) :active t]
   ["3) Dark - soft-morning" (tj-load-theme 'soft-morning) :active t]
   ["4) Light - darkest-dawn" (tj-load-theme 'darkest-dawn) :active t]
   ["5) Light - Wheat" (tj-load-theme 'wheat) :active t]
   ["6) Dark - Smyx" (tj-load-theme 'smyx) :active t]
   ["7) Light - monokai" (tj-load-theme 'monokai) :active t]
   ["8) Dark - dark-emacs" (tj-load-theme 'dark-emacs) :active t]
   ["9) Dark - pok-wob" (tj-load-theme 'pok-wob) :active t]
   ["10) clues" (tj-load-theme 'clues) :active t]
   ["11) soft-stone" (tj-load-theme 'soft-stone) :active t]
   ["12) busybee" (tj-load-theme 'busybee) :active t]
   ["13) niflheim" (tj-load-theme 'niflheim) :active t]
   ["14) badger" (tj-load-theme 'badger) :active t]
   ["15) cyberpunk" (tj-load-theme 'cyberpunk) :active t]
   ["16) robin-hood" (tj-load-theme 'robin-hood) :active t]
   ["17) soft-morning" (tj-load-theme 'soft-morning) :active t]
   ["18) charcoal-black" (tj-load-theme 'charcoal-black) :active t]
   ["19) classic" (tj-load-theme 'classic) :active t]
   ["20) Light - prez" (tj-load-theme 'prez) :active t]
   ["21) subatomic-enhanced" (tj-load-theme 'subatomic-enhanced) :active t]
   ["22) dakrone" (tj-load-theme 'dakrone) :active t]
   ["23) flatui" (tj-load-theme 'flatui) :active t]
   ["24) whiteboard" (tj-load-theme 'whiteboard) :active t]
   ["25) Dark - bliss" (tj-load-theme 'bliss) :active t]
   ["26) Dark - mellow" (tj-load-theme 'mellow) :active t]
   ["27) Dark - mustard" (tj-load-theme 'mustard) :active t]
   ["28) Dark - peacock" (tj-load-theme 'peacock) :active t]
   ["29) Dark - slime" (tj-load-theme 'slime) :active t]
[2014-11-11 Tue 16:18]

* desktop
** desktop commands
;; ;; Automatically save and restore sessions
#+begin_src emacs-lisp
(setq desktop-dirname             "~/.emacs.d/desktop/"
      desktop-base-file-name      "emacs.desktop"
      desktop-base-lock-name      "lock"
      desktop-path                (list desktop-dirname)
      desktop-save                t
          desktop-auto-save-timeout 600
      desktop-files-not-to-save   "^$" ;reload tramp paths
      desktop-load-locked-desktop nil)
(desktop-save-mode t)

(defun my-desktop ()
  "Load the desktop and enable autosaving"
  (let ((desktop-load-locked-desktop "ask"))
    (desktop-save-mode t)))

(add-hook 'auto-save-hook (lambda () (desktop-save-in-desktop-dir)))

* load packages
** imenu
#+BEGIN_SRC emacs-lisp
;; setting up 'imenu'
(add-hook 'org-mode-hook
(lambda () (imenu-add-to-menubar "Imenu")))
(setq org-imenu-depth 6)

(add-hook 'LaTeX-mode-hook
(lambda () (imenu-add-to-menubar "Imenu")))
(setq latex-imenu-depth 6)
[2014-11-22 Sat 13:51]

#+BEGIN_SRC emacs-lisp
(require 'paradox)
(require 'imenu-anywhere)
    (global-set-key (kbd "C-+") 'imenu-anywhere)
[2014-11-14 Fri 11:15]

** delete-this-file
#+BEGIN_SRC emacs-lisp
  (defun delete-this-file ()   ;;; use M-x delete-this-file
    "Delete (move to trash) the file that is associated with the current buffer."
    (let ((filename (buffer-file-name)))
      (delete-file filename t)
[18:40:52; 12.11.2014]

** kill this buffer
#+BEGIN_SRC emacs-lisp
 (defun kill-this-buffer ()
   (kill-buffer (current-buffer)))
;; (global-set-key (kbd "C-x C-k") 'kill-this-buffer)
(bind-key "C-x C-k" 'kill-this-buffer)
[2014-11-13 Thu 19:21]

** revert this buffer
#+BEGIN_SRC emacs-lisp
 (defun revert-this-buffer ()
   (revert-buffer nil t t)
   (message (concat "Reverted buffer " (buffer-name))))
;; (global-set-key (kbd "C-x C-r") 'revert-this-buffer)
(bind-key "C-x C-r" 'revert-this-buffer)
[2014-11-13 Thu 19:20]

** insert timestamp
#+BEGIN_SRC emacs-lisp
 (define-key global-map (kbd "C-x C-a")
   '(lambda () (interactive)
      (when (eq major-mode 'org-mode)
        (org-insert-time-stamp nil t t)
        (insert "\n"))))
[2014-11-13 Thu 19:20]

** save my todo's
#+BEGIN_SRC emacs-lisp
;;; from
(defun todo (desc)
  (interactive "s to do: ")
  (let*((todo-file "~/.emacs.d/org/")
        (todo-buffer (get-file-buffer todo-file)) )
    (append-to-file (format "%s\n" desc) nil todo-file) ; ignored
    (if todo-buffer
          (set-buffer todo-buffer)
          (revert-buffer t t) )))) ; IGNORE-AUTO NOCONFIRM
[2014-11-12 Wed 19:44]

** bookmarks
#+BEGIN_SRC emacs-lisp
;; Make sure the repository is loaded as early as possible
(setq bm-restore-repository-on-load t)
(require 'bm)

;; Loading the repository from file when on start up.
(add-hook' after-init-hook 'bm-repository-load)

;; Restoring bookmarks when on file find.
(add-hook 'find-file-hooks 'bm-buffer-restore)

;; Saving bookmark data on killing a buffer
(add-hook 'kill-buffer-hook 'bm-buffer-save)

;; Saving the repository to file when on exit.
;; kill-buffer-hook is not called when Emacs is killed, so we
;; must save all bookmarks first.
(add-hook 'kill-emacs-hook '(lambda nil

;; Update bookmark repository when saving the file.
(add-hook 'after-save-hook 'bm-buffer-save)

;; Restore bookmarks when buffer is reverted.
(add-hook 'after-revert-hook 'bm-buffer-restore)
[2014-11-14 Fri 11:20]

** timeline
#+BEGIN_SRC emacs-lisp
(defun org-agenda-timeline-all (&optional arg)
  (interactive "P")
    (dolist (org-agenda-file org-files-list)
      (insert-file-contents org-agenda-file nil)
    (write-file "~/.emacs.d/org/")
    (org-agenda arg "L")))

(define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
[2014-11-14 Fri 12:03]

* functions
** insert date
#+BEGIN_SRC emacs-lisp
(defun insert-date ()
  "Insert current date dd-mm-yyyy."
  (when (use-region-p)
    (delete-region (region-beginning) (region-end) )
  (insert (format-time-string "%d-%m-%Y"))
[2014-11-17 Mon 19:32]

** word
#+BEGIN_SRC emacs-lisp
(defun words-dictionary ()
(thing-at-point 'word))))
(defun words-thesaurus ()
(thing-at-point 'word))))
(defun words-google ()
(if (region-active-p)
(url-hexify-string (buffer-substring (region-beginning)
(thing-at-point 'word)))))
(defvar words-funcs '()
"functions to run in `words'. Each entry is a list of (key menu-name function).")
(setq words-funcs
'(("d" "ictionary" words-dictionary)
("t" "hesaurus" words-thesaurus)
("g" "oogle" words-google)))

(defun words ()
(lambda (tup)
(concat "[" (elt tup 0) "]"
(elt tup 1) " "))
words-funcs "") ": "))
(let ((input (read-char-exclusive)))
(char-to-string input) words-funcs)

(defun words-atd ()
"Send paragraph at point to After the deadline for spell and grammar checking."

(let* ((url-request-method "POST")
(url-request-data (format
(thing-at-point 'paragraph))))
(xml  (with-current-buffer
(xml-parse-region url-http-end-of-headers (point-max))))
(results (car xml))
(errors (xml-get-children results 'error)))

(switch-to-buffer-other-frame "*ATD*")
(dolist (err errors)
(let* ((children (xml-node-children err))
;; for some reason I could not get the string out, and had to do this.
(s (car (last (nth 1 children))))
;; the last/car stuff doesn't seem right. there is probably
;; a more idiomatic way to get this
(desc (last (car (xml-get-children children 'description))))
(type (last (car (xml-get-children children 'type))))
(suggestions (xml-get-children children 'suggestions))
(options (xml-get-children (xml-node-name suggestions) 'option))
(opt-string  (mapconcat
(lambda (el)
(when (listp el)
(car (last el))))
" ")))
(insert (format "** %s ** %s
Description: %s
Suggestions: %s
" s type desc opt-string))))))
(add-to-list 'words-funcs
'("s" "spell/grammar" words-atd)
t) ; append
(require 'keyset)
[2014-11-14 Fri 11:52]
** from dired to w3m
#+BEGIN_SRC emacs-lisp
(defun dired-w3m-find-file ()
   (require 'w3m)
   (let ((file (dired-get-filename)))
     (if (y-or-n-p (format "Open 'w3m' %s " (file-name-nondirectory file)))
         (w3m-find-file file))))
** save tabs
#+BEGIN_SRC emacs-lisp
(defun w3m-register-desktop-save ()
  "Set `desktop-save-buffer' to a function returning the current URL."
  (setq desktop-save-buffer (lambda (desktop-dirname) w3m-current-url)))

(add-hook 'w3m-mode-hook 'w3m-register-desktop-save)

(defun w3m-restore-desktop-buffer (d-b-file-name d-b-name d-b-misc)
  "Restore a `w3m' buffer on `desktop' load."
  (when (eq 'w3m-mode desktop-buffer-major-mode)
    (let ((url d-b-misc))
      (when url
        (require 'w3m)
        (if (string-match "^file" url)
            (w3m-find-file (substring url 7))
          (w3m-goto-url-new-session url))

(add-to-list 'desktop-buffer-mode-handlers '(w3m-mode . w3m-restore-desktop-buffer))
* save and backup
** global save
#+BEGIN_SRC emacs-lisp
 (kbd "M-8")
 (lambda ()
  (save-some-buffers t)))

[15:40:49; 12.11.2014]
** desktop backup
#+BEGIN_SRC emacs-lisp
  ;;; from Tassilo Horn 11/08/14, as amended by me 24/09/14
  (setq version-control t
            backup-by-copying t
        delete-old-versions t
        delete-by-moving-to-trash t
        kept-new-versions 7
        kept-old-versions 0
        ;; auto-save-default t               ; auto-save every buffer that visits a file
        ;; auto-save-timeout 10              ; number of seconds idle time before auto-save (default: 30)
        ;; auto-save-interval 200            ; number of keystrokes between auto-saves
            auto-save-visited-file-name t
        backup-directory-alist '(("." . "~/.emacs.d/backup/")))

  (require 'auto-save-buffers-enhanced)
     (auto-save-buffers-enhanced t)

  (require 'backup-each-save)
  ;;(add-hook 'after-save-hook 'backup-each-save)
  (defun backup-each-save-filter (filename)
    (let ((ignored-filenames
           '("^/tmp" "semantic.cache$" "\\.emacs-places$"
             "\\.recentf$" ".newsrc\\(\\.eld\\)?"))
          (matched-ignored-filename nil))
       (lambda (x)
         (when (string-match x filename)
           (setq matched-ignored-filename t)))
      (not matched-ignored-filename)))
  (setq backup-each-save-filter-function 'backup-each-save-filter)
  [2014-11-13 Thu 19:21]

** saveplace
#+BEGIN_SRC emacs-lisp
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file (expand-file-name ".places" user-emacs-directory))
[2014-11-13 Thu 14:34]

* modeline
 ;;; modeline - based on
#+begin_src emacs-lisp
  (setq-default mode-line-format
                    " "
                    " | "
                    "dir: "
                   '(:eval (file-name-nondirectory (directory-file-name default-directory)))
                    " | "
                    ;; '%02' to set to 2 chars at least; prevents flickering
                    " | "
                    '(:eval (propertize (format-time-string "%H:%M")))
                    " | "
                    '(:eval (emacs-uptime "%hh"))
                    " | "
                    '(:eval (if (buffer-modified-p) "M" "-"))
                    '(:eval (if buffer-read-only    "R" "-"))
                    '(:eval (if (window-dedicated-p (selected-window)) "D" "-"))
                    " | "
                   '(:eval (propertize "%p" ))   ;; % above top
                   '(:eval (propertize "%I" ))  ;; size
                   " | "
                   ;;'(:eval vc-mode)
                                   " | "
                         " | "
                         ;; git-modeline
                         " | "
                         ;; Some specific information about the current buffer
                         (flycheck-mode flycheck-mode-line) ;; Flycheck status
                  " | "
[2014-11-13 Thu 19:21]

* key-bindings
  #+BEGIN_SRC emacs-lisp
    ;; Basic key bindings
    (global-set-key "\C-h" 'delete-backward-char)
    (global-set-key "\C-w" 'backward-kill-word)
    (global-set-key "\C-xs" 'save-buffer)
    (global-set-key "\M-w" 'kill-region)
    (global-set-key "\C-m" 'newline-and-indent)
    (global-set-key (kbd "<S-return>") 'newline)
    (global-set-key [C-return] 'newline-and-indent)
    (global-set-key "\M-n" 'goto-line)
    (global-set-key "\M-N" 'what-line)
    (global-set-key "\M-?" 'help-for-help)
    (global-set-key "\C-cx" 'my-ctrl-c-x-command)
    (global-set-key "\C-ca" 'org-agenda)
    (global-set-key "\C-cl" 'org-store-link)
    (global-set-key "\C-cL" 'org-insert-link-global)
    (global-set-key "\C-cO" 'org-open-at-point-global)
    (if (eq window-system 'x)
        (shell-command "xmodmap -e 'clear Lock' -e 'keycode 66 = F13'"))
    (global-set-key [f13] 'execute-extended-command)  ;;sets caps-lock as meta-key
    (global-set-key (kbd "C-x f") 'org-footnote-action)
    (global-set-key (kbd "C-c l") 'linum-mode)
    (global-set-key (kbd "C-x o") 'outline-minor-mode-prefix)
    ;; commenting out code
    (global-set-key (kbd "C-x ;") 'comment-region)
    (global-set-key (kbd "C-x C-r") 'revert-this-buffer)
    (global-set-key (kbd "C-x C-k") 'kill-this-buffer)
    (global-set-key (kbd "C-x C-t") 'todo)
    (global-set-key (kbd "C-x y") 'bm-toggle)
    (global-set-key (kbd "<f2>")   'bm-next)
    (global-set-key (kbd "<S-f2>") 'bm-previous)
    (global-set-key (kbd "C-x 8") 'lusty-file-explorer)
    (global-set-key (kbd "C-x 7") 'lusty-buffer-explorer)
    (global-set-key (kbd "C-x 2") 'imenu-add-to-menubar)

     (global-unset-key (kbd "C-c o"))
     (global-set-key (kbd "C-c o a") 'org-agenda-list)
     (global-set-key (kbd "C-c o t") 'org-todo-list)
     (global-set-key (kbd "C-c o p") 'org-insert-property-drawer)
     (global-set-key (kbd "C-c o d") 'org-date)
     (global-set-key (kbd "C-c o j") 'org-journal-entry)
     (global-set-key (kbd "\C-c a") 'org-agenda)

    (global-unset-key (kbd "<f9>"))
    (global-set-key (kbd "<f9> <f9>") 'org-agenda-list)
    (global-set-key (kbd "<f9> <f8>") 'org-todo-list)

    (global-set-key (kbd "C-c C-n") 'deft-new-file)

 (global-set-key (kbd "C-c w s") 'w3m-search)
 (global-set-key (kbd "C-c w t") 'w3m-goto-url-new-session)
 (global-set-key (kbd "C-c w o") 'w3m-goto-url)
;; source =

* languages
** LaTeX
#+BEGIN_SRC emacs-lisp
(require 'latex-extra)
 (add-hook 'LaTeX-mode-hook #'latex-extra-mode)
(require 'magic-latex-buffer)
(add-hook 'latex-mode-hook 'magic-latex-buffer)
[2014-11-14 Fri 11:22]
*** narrow to environment
#+BEGIN_SRC emacs-lisp
(defun LaTeX-narrow-to-environment (&optional count)
  "Narrow buffer to current LaTeX environment (or COUNT
environments around point)"
  (interactive "p")
  (LaTeX-mark-environment count)
  (narrow-to-region (save-excursion
                      (goto-char (region-beginning))
I decided that C-x n e is a natural binding:
[2014-11-16 Sun 18:36]
#+BEGIN_SRC emacs-lisp
(eval-after-load 'latex
  '(define-key LaTeX-mode-map (kbd "C-x n e")
[2014-11-16 Sun 18:37]

** Markdown
#+BEGIN_SRC emacs-lisp
 (setq markdown-imenu-generic-expression
     '(("title"  "^\\(.*\\)[\n]=+$" 1)
       ("h2-"    "^\\(.*\\)[\n]-+$" 1)
       ("h1"   "^# \\(.*\\)$" 1)
       ("h2"   "^## \\(.*\\)$" 1)
       ("h3"   "^### \\(.*\\)$" 1)
       ("h4"   "^#### \\(.*\\)$" 1)
       ("h5"   "^##### \\(.*\\)$" 1)
       ("h6"   "^###### \\(.*\\)$" 1)
       ("fn"   "^\\[\\^\\(.*\\)\\]" 1)
 (add-hook 'markdown-mode-hook
           (lambda ()
             (setq imenu-generic-expression markdown-imenu-generic-expression)))
;source =
[2014-11-14 Fri 05:22]
** w3m
*** autoload
#+BEGIN_SRC emacs-lisp
      (autoload 'browse-url-interactive-arg "browse-url"))
*** browse url
#+BEGIN_SRC emacs-lisp
(setq browse-url-browser-function 'w3m-browse-url)
 (autoload 'w3m-browse-url "w3m" "Ask a WWW browser to show a URL." t)
 (global-set-key "\C-xm" 'browse-url-at-point)
*** open a new tab
#+BEGIN_SRC emacs-lisp
(setq browse-url-browser-function 'w3m-browse-url
          browse-url-new-window-flag t)
[2014-11-17 Mon 19:44]

*** remove trailing whitespace
#+BEGIN_SRC emacs-lisp
(add-hook 'w3m-display-hook
              (lambda (url)
                (let ((buffer-read-only nil))
[2014-11-15 Sat 08:33]

*** misc
#+BEGIN_SRC emacs-lisp
;;change default browser for 'browse-url'  to w3m
(setq browse-url-browser-function 'w3m-goto-url-new-session)

**** search on wikipedia
#+BEGIN_SRC emacs-lisp
;;i need this often
(defun wikipedia-search (search-term)
  "Search for SEARCH-TERM on wikipedia"
   (let ((term (if mark-active
                   (buffer-substring (region-beginning) (region-end))
       (format "Wikipedia (%s):" term) nil nil term)))
**** w3m-open-site
#+BEGIN_SRC emacs-lisp
;;when I want to enter the web address all by hand
(defun w3m-open-site (site)
  "Opens site in new w3m session with 'http://' appended"
   (list (read-string "Enter website address(default: w3m-home):" nil nil w3m-home-page nil )))
   (concat "http://" site)))
# source =
[2014-11-15 Sat 08:58]

**** utf-8
#+BEGIN_SRC emacs-lisp
(setq w3m-coding-system 'utf-8
          w3m-file-coding-system 'utf-8
          w3m-file-name-coding-system 'utf-8
          w3m-input-coding-system 'utf-8
          w3m-output-coding-system 'utf-8
          w3m-terminal-coding-system 'utf-8)
[2014-11-15 Sat 16:19]
**** ascii
#+BEGIN_SRC emacs-lisp
(standard-display-ascii ?\225 [?+])
(standard-display-ascii ?\227 [?-])
(standard-display-ascii ?\222 [?'])
[2014-11-15 Sat 16:22]
**** w3m filter url
#+BEGIN_SRC emacs-lisp
(setq w3m-use-filter t)
;; send all pages through one filter
(setq w3m-filter-rules `(("\\`.+" w3m-filter-all)))

(defun w3m-filter-all (url)
  (let ((list '(
                ;; add more as you see fit!
                ("&#187;" ">>")
                ("&laquo class="comment">;" "<")
                ("&raquo class="comment">;" ">")
                ("&ouml class="comment">;" "o")
                ("&#8230;" "...")
                ("&#8216;" "'")
                ("&#8217;" "'")
                ("&rsquo class="comment">;" "'")
                ("&lsquo class="comment">;" "'")
                ("\u2019" "\'")
                ("\u2018" "\'")
                ("\u201c" "\"")
                ("\u201d" "\"")
                ("&rdquo class="comment">;" "\"")
                ("&ldquo class="comment">;" "\"")
                ("&#8220;" "\"")
                ("&#8221;" "\"")
                ("\u2013" "-")
                ("\u2014" "-")
                ("&#8211;" "-")
                ("&#8212;" "-")
                ("&ndash class="comment">;" "-")
                ("&mdash class="comment">;" "-")
  (while list
    (let ((pat (car (car list)))
          (rep (car (cdr (car list)))))
      (goto-char (point-min))
      (while (search-forward pat nil t)
        (replace-match rep))
      (setq list (cdr list))))))
[2014-11-15 Sat 16:23]
*** w3m to org-mode. retaining the html links
#+BEGIN_SRC emacs-lisp
(defun w3m-get-buffer-with-org-style ()
  "Get current buffer content with `org-mode' style.
This function will encode `link-title' and `link-location' with `org-make-link-string'.
And move buffer content to lastest of kill ring.
So you can yank in `org-mode' buffer to get `org-mode' style content."
  (let (transform-start
    (if mark-active
          (setq transform-start (region-beginning))
          (setq transform-end (region-end))
      (setq transform-start (point-min))
      (setq transform-end (point-max)))
    (message "Start transform link to `org-mode' style, please wait...")
      (goto-char transform-start)
      (while (and (not out-bound)             ;not out of transform bound
                  (not (w3m-no-next-link-p))) ;not have next link in current buffer
        ;; store current point before jump next anchor
        (setq temp-position (point))
        ;; move to next anchor when current point is not at anchor
        (or (w3m-anchor (point)) (w3m-get-next-link-start))
        (if (<= (point) transform-end)  ;if current point is not out of transform bound
              ;; get content between two links.
              (if (> (point) temp-position)
                  (setq return-content (concat return-content (buffer-substring temp-position (point)))))
              ;; get link location at current point.
              (setq link-location (w3m-anchor (point)))
              ;; get link title at current point.
              (setq link-title (buffer-substring (point) (w3m-get-anchor-end)))
              ;; concat `org-mode' style url to `return-content'.
              (setq return-content (concat return-content (org-make-link-string link-location link-title))))
          (goto-char temp-position)     ;reset point before jump next anchor
          (setq out-bound t)            ;for break out `while' loop
      ;; concat rest context of current buffer
      (if (< (point) transform-end)
          (setq return-content (concat return-content (buffer-substring (point) transform-end))))
      (kill-new return-content)
      (message "Transform link completed. You can get it from lastest kill ring."))))

(defun w3m-get-anchor-start ()
  "Move and return `point' for thst start of the current anchor."
  (goto-char (or (previous-single-property-change (point) 'w3m-anchor-sequence) ;get start position of anchor
                 (point)))                                                      ;or current point

(defun w3m-get-anchor-end ()
  "Move and return `point' after the end of current anchor."
  (goto-char (or (next-single-property-change (point) 'w3m-anchor-sequence) ;get end position of anchor
                 (point)))                                                  ;or current point

(defun w3m-get-next-link-start ()
  "Move and return `point' for that start of the current link."
  (catch 'reach
    (while (next-single-property-change (point) 'w3m-anchor-sequence) ;jump to next anchor
      (goto-char (next-single-property-change (point) 'w3m-anchor-sequence))
      (when (w3m-anchor (point))        ;return point when current is valid link
        (throw 'reach nil))))

(defun w3m-get-prev-link-start ()
  "Move and return `point' for that end of the current link."
  (catch 'reach
    (while (previous-single-property-change (point) 'w3m-anchor-sequence) ;jump to previous anchor
      (goto-char (previous-single-property-change (point) 'w3m-anchor-sequence))
      (when (w3m-anchor (point))        ;return point when current is valid link
        (throw 'reach nil))))

(defun w3m-no-next-link-p ()
  "Return t if no next link after cursor.
Otherwise, return nil."
    (equal (point) (w3m-get-next-link-start))))

(defun w3m-no-prev-link-p ()
  "Return t if no prevoius link after cursor.
Otherwise, return nil."
    (equal (point) (w3m-get-prev-link-start))))
[2014-11-15 Sat 16:25]
** w3m browse url
#+BEGIN_SRC emacs-lisp
;; make browse-url-url-at-point use w3m links if they exist
(defadvice browse-url-url-at-point (after w3m-anchor-at-point activate)
        "Browse the url at point. If w3m-anchor finds a url, use it."
        (setq ad-return-value

(global-set-key "\C-c C-x C-c" 'browse-url-url-at-point)
[2014-11-15 Sat 16:47]

* quit emacs
** gnus group exit
 #+BEGIN_SRC emacs-lisp
  ;; hook to run before quitting emacs
 (add-hook 'before-kill-emacs-hook 'gnus-group-exit)
 [2014-11-13 Thu 14:39]

* testbed
** bash source
#+BEGIN_SRC emacs-lisp
  ;;; If 1st line begins with #!, make the file executable when saving
  ;;; Glenn Morris <rgm22 at> Sun Jul 07 11:11:51 2002
  (if (fboundp 'executable-make-buffer-file-executable-if-script-p)
      (add-hook 'after-save-hook

  ;;; in an empty file, when shell-script-mode is enabled, add the #! line
  ;;; retroj on #emacs Sun Dec 13 12:14:52 2009
  (add-hook 'sh-mode-hook (lambda () (if (eq
           (buffer-size) 0) (executable-set-magic "bash"))))

#+BEGIN_SRC emacs-lisp
(require 'bash-completion)
[2014-11-13 Thu 14:24]

** boxquote
#+BEGIN_SRC emacs-lisp
  (require 'boxquote)
  (global-set-key [f7] 'boxquote-region)
  (global-set-key (kbd "C-c q y")   'boxquote-yank)
  (global-set-key (kbd "C-c q r")   'boxquote-region)
  (global-set-key (kbd "C-c q u")   'boxquote-unbox-region)
  (global-set-key (kbd "C-c q t")   'boxquote-title)
  (global-set-key (kbd "C-c q i")   'boxquote-insert-file)
  (global-set-key (kbd "C-c q k")   'boxquote-kill)
  (global-set-key (kbd "C-c q s")   'boxquote-shell-command)
  (global-set-key (kbd "C-c q b")   'boxquote-buffer)
  (global-set-key (kbd "C-c q p")   'boxquote-paragraph)
  (global-set-key (kbd "C-c q n")   'boxquote-narrow-to-boxquote)
  (global-set-key (kbd "C-c q w")   'boxquote-where-is)
  (global-set-key (kbd "C-c q d f") 'boxquote-describe-function)
  (global-set-key (kbd "C-c q d k") 'boxquote-describe-key)
  (global-set-key (kbd "C-c q d v") 'boxquote-describe-variable)

#+BEGIN_SRC emacs-lisp
  (setq boxquote-top-and-tail "────"
        boxquote-top-corner "╭"
        boxquote-bottom-corner "╰"
        boxquote-side "│"
** details in status bar
#+BEGIN_SRC emacs-lisp
  ;; my-frame-title-refresh
  ; Show date and current time, GNU Emacs version and `buffer-file-name'
  ; if available, `buffer-name' otherwise
  (defun my-frame-title-refresh ()
      (setq frame-title-format
            `((buffer-file-name "buffer-file-name: %f" ("%b"))
              "      "
              ,(format-time-string "Weekday: %A")
              "      "
              ,(format-time-string "Date: %Y/%m/%d")
              "      "
              ,(format-time-string "Time:  ")
              ,(replace-regexp-in-string "\n" ""
                  (shell-command-to-string "date -u +%H:%M"))
              " UTC"
              "      "
              ,(substring (emacs-version) 0 20)

  ; Update frame title every minute
  (run-with-timer 1 60 'my-frame-title-refresh)

** custom safe themes
#+BEGIN_SRC emacs-lisp
(setq custom-safe-themes t)
[2014-11-13 Thu 14:21]

** ido
#+BEGIN_SRC emacs-lisp
(ido-mode 1)
(setq ido-enable-flex-matching t
      ido-use-virtual-buffers t)
;;(ido-mode 1)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
 (setq ido-use-filename-at-point 'guess)
(setq ido-create-new-buffer 'always)
(setq ido-file-extensions-order '(".org" ".txt" ".py" ".emacs" ".xml" ".el" ".ini" ".cfg" ".cnf"))
 (setq ido-ignore-extensions t)

(defun ido-recentf-open ()
  "Use `ido-completing-read' to \\[find-file] a recent file"
  (if (find-file (ido-completing-read "Find recent file: " recentf-list))
      (message "Opening file...")
    (message "Aborting")))
[2014-11-13 Thu 10:42]

#+BEGIN_SRC emacs-lisp
;; Use ido everywhere
(require 'ido-ubiquitous)
(ido-ubiquitous-mode 1)

;; Fix ido-ubiquitous for newer packages
(defmacro ido-ubiquitous-use-new-completing-read (cmd package)
  `(eval-after-load ,package
     '(defadvice ,cmd (around ido-ubiquitous-new activate)
        (let ((ido-ubiquitous-enable-compatibility nil))

(ido-ubiquitous-use-new-completing-read webjump 'webjump)
(ido-ubiquitous-use-new-completing-read yas/expand 'yasnippet)
(ido-ubiquitous-use-new-completing-read yas/visit-snippet-file 'yasnippet)
[2014-11-17 Mon 19:43]

** deft
#+BEGIN_SRC emacs-lisp
(require 'deft)
;; (setq deft-use-filename-as-title t)
(global-set-key [f8] 'deft)
(when (require 'deft nil 'noerror)
      deft-extension "org"
      deft-directory "~/.emacs.d/deft/"
      deft-text-mode 'org-mode)
(setq deft-use-filename-as-title t)
(global-set-key (kbd "C-x C-g") 'deft-find-file))
[2014-11-14 Fri 11:55]
** whitespace-mode
#+BEGIN_SRC emacs-lisp
(defun my-whitespace-mode-hook ()
  (setq whitespace-action '(auto-cleanup)
        whitespace-style  '(face tabs trailing lines-tail empty)
        ;; use fill-column value instead
        whitespace-line-column nil)
[2014-11-16 Sun 13:59]

*** Helper function for cleaning whitespace from buffers.
#+BEGIN_SRC emacs-lisp
(defun buffer-cleanup ()
  "Clean up the buffer"
  (untabify (point-min) (point-max))
  (indent-region (point-min) (point-max)))

(global-set-key (kbd "C-c n") 'buffer-cleanup)

** Allow narrowing
This allows you to focus in on a part of a file and make your buffer
only show this part. Useful for doing buffer global search and
replace, for example, when you only want to impact a part of a file.

#+BEGIN_SRC emacs-lisp
(put 'narrow-to-region 'disabled nil)
[2014-11-16 Sun 16:53]
** Generic aligning of code
Bind a key for aligning code by refexp
#+BEGIN_SRC emacs-lisp
 ;; Align your code in a pretty way.
 (global-set-key (kbd "C-x \\") 'align-regexp)
** buffer movement commands
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook '(lambda ()
   (local-set-key [C-S-up]    'buf-move-up)
   (local-set-key [C-S-down]  'buf-move-down)
   (local-set-key [C-S-left]  'buf-move-left)
   (local-set-key [C-S-right] 'buf-move-right)))
[2014-11-18 Tue 14:53]

** clock-agenda
#+BEGIN_SRC emacs-lisp
(setq org-agenda-custom-commands
      '(("Z" "todays agenda"
         ((agenda ""))
         ((org-agenda-span 'day)
          (org-agenda-start-with-log-mode 'clockcheck)
          (org-agenda-start-with-clockreport-mode t)
          (org-agenda-log-mode-items '(closed clock state))
          (org-agenda-overriding-header "Today's Agenda")))))
[2014-11-19 Wed 11:34]

* spell-checking
** for some modes
#+BEGIN_SRC emacs-lisp
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
[2014-11-15 Sat 11:06]

** Add spell checker to the file
#+BEGIN_SRC emacs-lisp
;; Use hunspell instead of ispell
(if (file-exists-p "/usr/bin/hunspell")
      (setq ispell-program-name "hunspell")
      (eval-after-load "ispell"
        '(progn (defun ispell-get-coding-system () 'utf-8)))))
(setq ispell-program-name "hunspell")
(require 'rw-hunspell)
(require 'rw-language-and-country-codes)
(require 'rw-ispell)
(setq ispell-dictionary "en_GB_hunspell")
(setq ispell-personal-dictionary "/home/$USER/.emacs.d/ac-dict/my-dict.txt")
[2014-11-15 Sat 10:57]

One thing that you must be aware of is to NOT put this file in "~/.emacs.d/" because if you do it will overwrite your basic "init.el" when it is tangled, think 'compiled', which starts emacs off!

You also need to put "ob-tangle.el" into "~/.emacs.d/" along with 'init.el' so that it all works. Once its all in place, then just start emacs the same way that you usually do, and watch it all appear as if by magic! :)

I use "gnus" to deal with my email, and that configuration is set up right at the end of my "" and quite happily sits there just waiting to be called for use.

When I first started setting it all up, it was very daunting, moving from something that I knew worked, to something that I wasn't sure about, and neither did I really understand how it would work! But now its been up and running for several weeks I feel quite comfortable with it all.

Yes, it has blown up in my face, with emacs totally refusing to load my setup, and I couldn't see why not! That required about four hours just patiently going through it line by line, and examining for anything! Typos, missing closing brackets, too many brackets, new command-line errors it was showing me that I hadn't seen before! I eventually found that the problem lay in a block of code that I'd just put in, and which when commented out allowed emacs to run properly. I learnt then to time-stamp each block of code that I inserted which would help in finding any future problems.

Now, emacs is extremely stable, as is gnus, and its working more as I want it to, without so much unnecessary commented out code. I still try out new snippets of code, but I'm far more wary of it, and if it looks like it won't fit in my scheme of things, then I just leave it alone and don't put it in.

I hope its useful for you and that you have fun setting it all up. I know that I have and feel much more comfortable with my setup now


comments powered by Disqus