;;; .emacs -- a GNU Emacs initialization file

;;;_ About

;; Author:                   Markus Gattol
;; Licence:                  GPLv3 or higher
;; Operating System:         DebianGNU/* (I exclusively use this OS)

;; This is my (Markus Gatol) .emacs file which has grown over time,
;; gets re-factored and re-assembled (at least parts of it) from time
;; to time -- it is in constant development.

;; allout-mode:
;;      This file is prepared for Emacs allout-mode. For more
;;      information see http://www.emacswiki.org/cgi-bin/wiki/AllOut

;;      After you have loaded `allout.el' and issued `M-x allout-mode'
;;      [1] I recommend to issue `C-h m' and read the
;;      allout part. Key bindings and hot-spot operations are very
;;      good to know about. Especially the hot-spot action in
;;      conjunction with `i' and `h' is a very helpful way to get an
;;      overview.

;;      Convention for allout-mode: In certain cases (where long
;;      comments to applied code) comment is separated from referring
;;      code via a `allout-distinctive-bullets-string'.  Therefore, a
;;      `\' bullet contain comment referring to code preceded by `-'
;;      bullet.

;;      [1] To start/learn how to use allout-mode, it would probably
;;      be the best to open the file `allout.el' itself within GNU
;;      Emacs using `allout-mode' since it is already formatted in
;;      `allout-mode' style so you can get the best feeling for the
;;      magnitude of power that comes with `allout-mode' -- If you
;;      fear to alter your in production state `allout.el' file
;;      unintentionally, simply copy it to `/tmp' and go from there
;;      (I'd recommend to do so ...).

;; The boxquoted transcript below shows how one would do the afore
;; mentioned:

;; ,----[ How to do it using the CLI (Command Line Interface) e.g. Bash ]
;; | sa@pc1:~$ locate allout.el
;; | /usr/share/emacs/21.4/lisp/allout.el
;; | /usr/share/emacs/21.4/lisp/allout.elc
;; | /usr/share/emacs/22.0.97/lisp/allout.el.gz
;; | /usr/share/emacs/22.0.97/lisp/allout.elc
;; | sa@pc1:~$ cp /usr/share/emacs/21.4/lisp/allout.el /tmp/
;; | sa@pc1:~$ cd /tmp/
;; | sa@pc1:/tmp$ emacs allout.el &
;; `----

;; Those who don't want to leave GNU Emacs for the above can of course
;; do so:

;; ,----[ M-x term RET would make usage of ]
;; | term is an interactive compiled Lisp function in `term.el'.
;; | (term program)
;; |
;; | Start a terminal-emulator in a new buffer.
;; | The buffer is in Term mode; see `term-mode' for the
;; | commands to use in that buffer.
;; |
;; | Type C-c b to switch to another buffer.
;; |
;; | [back]
;; `----

;; or one might prefer

;; ,----[ M-x shell RET would make usage of ]
;; | shell is an interactive autoloaded Lisp function in `shell'.
;; | (shell &optional buffer)
;; |
;; | Run an inferior shell, with I/O through buffer (which defaults to `*shell*').
;; | Interactively, a prefix arg means to prompt for buffer.
;; | If buffer exists but shell process is not running, make new shell.
;; | If buffer exists and shell process is running, just switch to buffer.
;; | Program used comes from variable `explicit-shell-file-name',
;; |  or (if that is nil) from the ESHELL environment variable,
;; |  or (if that is nil) from `shell-file-name'.
;; | If a file `~/.emacs_SHELLNAME' exists, or `~/.emacs.d/init_SHELLNAME.sh',
;; | it is given as initial input (but this may be lost, due to a timing
;; | error, if the shell discards input when it starts up).
;; | The buffer is put in Shell mode, giving commands for sending input
;; | and controlling the subjobs of the shell.  See `shell-mode'.
;; | See also the variable `shell-prompt-pattern'.
;; |
;; | To specify a coding system for converting non-ASCII characters
;; | in the input and output to the shell, use C-x RET c
;; | before M-x shell.  You can also specify this with C-x RET p
;; | in the shell buffer, after you start the shell.
;; | The default comes from `process-coding-system-alist' and
;; | `default-process-coding-system'.
;; |
;; | The shell file name (sans directories) is used to make a symbol name
;; | such as `explicit-csh-args'.  If that symbol is a variable,
;; | its value is used as a list of arguments when invoking the shell.
;; | Otherwise, one argument `-i' is passed to the shell.
;; |
;; | (Type C-h m in the shell buffer for a list of commands.)
;; |
;; | [back]
;; `----

;;      I fiddle on my .emacs on a regular so sections marked with
;;      `FIXME' need to be fixed/adapted or at least some thoughts
;;      need to be spend on them. Nevertheless, the *code as is* works
;;      fine. The `FIXME' parts are commented out for further
;;      adaptations.

;; Privacy
;;      For privacy reasons, some lines of my .emacs are mangled
;;      before posted or exposed for public view on the Internet. This
;;      is especially true for the Gnus part of my .emacs since it
;;      contains some passwords and the like. Also, I have to make
;;      sure my .emacs does not contain information that could become
;;      problematic for other folks (e.g. their email address could be
;;      used to send SPAM to them) that am in touch with.
;;      Nevertheless, that privacy thing does not effect the quality
;;      or quantity of this file -- in essence I do things like
;;      s/my.real.email.address.org/foo.bar.org/.

;;      U p d a t e:
;;      Instead of doing a `replace-match' or something like that on
;;      all my with `;priv' marked lines, I now do a combined thing of
;;      instantly marking stuff with `;priv' when tinkering with my
;;      `.emacs' and then replace the secret token with a variable,
;;      after I finished *the creative phase*, which then gets
;;      included with all other secret variables stored in a separate
;;      file (see the line with `emacs_secrets' in this
;;      file). Also, the convention I am following is to precede each
;;      variable replaced with `priv-...' e.g. `priv-my-name' or
;;      `priv-my-imap-password' so everytime you see a variable
;;      starting with `priv-', you now know this variable is evaluated
;;      and replaced with something stored in `emacs_secrets'.

;; Info Manual
;;      Assuming you are reading my .emacs within GNU Emacs having
;;      issued `C-h i' and `info.el' is loaded (if not you might put a
;;      `(require 'info)' into your `.emacs' anyways).

;;      If you find, throughout my `.emacs,' something that looks like
;;      that `(Info-goto-node "(Emacs)Copying")' put point (= cursor)
;;      behind this form and press `C-x C-e' (this evaluates the form
;;      before point) and you're automatically presented with a
;;      particular page in the info manual which explains, in detail,
;;      what the code you're starring at does. Use the navigate
;;      commands e.g. `n', `p', `l', `u', etc. to move around quickly
;;      or `C-h m' to get more information about available
;;      commands. Also, maybe you want to split your window `C-x 3' as
;;      I do, and then look at my `.emacs' and the info manual at the
;;      same time.

;; Gnus & Others
;;      This file (.emacs) also contains _all_ of my gnus settings. I
;;      do not have a .gnus.el file. See node Communication -> Gnus.

;;      Generally, I have all GNU Emacs related customization in
;;      >>just one file<< -- .emacs that is. So don't wonder if you
;;      also find all ERC etc. settings other folks sometimes split
;;      out into separate files within this file.

;; Coding Style
;;      When I was starting to use GNU Emacs I was already an
;;      old-school C hacker (wow ...) which is why I am used to
;;      http://en.wikipedia.org/wiki/GNU_Coding_Standards for example
;;      and therefore one will find elisp code formatted like this in
;;      here. Just reformat it if you feel you want to but please do
;;      not complain about it -- it's just another (yes, I know
;;      unusual for elisp...) coding style which I find very helpful
;;      getting a good overview.

;;      Whatever you do, DO NOT contact me regarding "You are
;;      partially using C-style (GNU Coding Style to be precisely)
;;      code formatting in your .emacs. Why is that? Can you change it
;;      to "normal" elisp coding standard for me? My reaction to that
;;      would probably be, feeding my good old bogofilter fellow
;;      (awesome, that fellow just can't get enough -- the more he
;;      eats, the better he gets ... :).

;;  That seems to be the right moment/place to start a song of praise
;;  for Gnus and my spam filter rules [2]. I did not have a single
;;  false positive (ham considered spam) or positive false (spam
;;  considered ham) for the last two months -- saying that with the
;;  knowledge, I am getting ~5-30 spam messages (mail or news) per
;;  day! That's all possible because of the combined whitelist,
;;  blacklist, statistical approach I am using and the time statistics
;;  for ham and spam could evolve.
;;  However, if a spam message manages slipping through my barriers, I
;;  mark it as spam with `M-d' in summary-buffer which means it get's
;;  noticed by the blacklist and the bogofilter back end (do not
;;  confuse spam back ends with common back ends like nnml etc.) for
;;  future detection as being spam and not ham.

;;  [2] See `gnus-parameters', fancy mail splitting as well as the
;;  Spam section in the Gnus part of this file.

;; In general, hints for improvements etc. are always welcome!  Have
;; fun and enjoy reading!

;;;_ Parking Slot

     ; All kind of not yet solved, planned for future
     ; integration/adaption or whatnot stuff goes here.

;;;_#1 Ignore FROM adress field in mail headers in certain cases


;;;_#2 figure the system type GNU Emacs is running on

;system-type <-- just evaluate

;;;_#3 May be useful at some point

;; ,----[ C-h f gnus-summary-supersede-article RET ]
;; | gnus-summary-supersede-article is an interactive compiled Lisp function in `gnus-msg.el'.
;; | (gnus-summary-supersede-article)
;; |
;; | Compose an article that will supersede a previous article.
;; | This is done simply by taking the old article and adding a Supersedes
;; | header line with the old Message-ID.
;; |
;; | [back]
;; `----

;;;_ Load and initialize

;;;_. Specify the root directory for all Emacs related Code
(setq emacs-root-dir (concat (getenv "HOME") "/em/"))

;;;_. `Info-default-directory-list' path settings for Info

;;;_ , dvc
(add-to-list 'Info-default-directory-list (expand-file-name (concat emacs-root-dir "libs/scm/dvc/texinfo")) t)

;;;_. Load libraries and .el resp .elc files (`load-path', `load-file')

;;;_ , Load whole Directories

; The `t' is accountable for appending *to the end* of the list
; instead of appending to the beginning of the list. I always put my
; own resp. third party code not yet packaged and availiable in
; directories which are appended to the end of the list in order to
; preferably load packaged versions of the same code if available.

; In short: By using `t' the packaged version takes precedence over my
; own resp. third party code.

;;;_  . Up-to-date development code

; Take a look at:
;            my website -> emacs_notes_cheat_sheets.html ->
;            Development Versions of Emacs Packages
; on how I manage to follow up-to-date versions of the below projects.

; Muse GIT Tree
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/muse/lisp")))

; Planner GIT Tree
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/planner")))

; Remember GIT Tree
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/remember")))

(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/bbdb/lisp")))
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/bbdb/bits")))

(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/w3m")))

; DVC BZR Tree
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/scm/dvc/lisp")))

;;;_  . Via APT (Advanced Packaging Tool) or single not up-to-date files

;prepend to `load-path'
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/pgg")))
;; (add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/htmlize")))
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/allout")))
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/scm/psvn")))
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/haml")))
; (add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/sass")))

;append to `load-path'
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/ps")) t)
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/unbound")) t)
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/bm+")) t)
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/wtf")) t)
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/pastie")) t)
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/pwsafe")) t)
(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/etexshow")) t)
;(add-to-list 'load-path (expand-file-name (concat emacs-root-dir "libs/css") t)
;(add-to-list 'load-path (expand-file-name "/usr/share/emacs/site-lisp/bbdb/lisp") t)

;;;_ , Just load single Files

; In contrast to the "Load all code within directory XY" this approach
; is more fine-grained.

; This file contains all my secrets settings e.g. passwords for gnus
; stuff -- see what I wrote in the "Privacy" section within the
; "About" part of this file
(load-file (concat (getenv "HOME") "/" ".sec/emacs_secrets"))

;;;_ , Load libraries which are not loaded further down

(require 'cl)
(require 'advice)
(require 'bytecomp)
;; (require 'htmlize)
(require 'timer)
(require 'setnu)
(require 'wtf)
; (require 'sass-mode)
(eval-after-load "buff-menu" '(require 'buff-menu+))
(load-library "pastie.el")

;;;_. Initialize and do some miscellaneous settings

;;;_ , Miscellaneous stuff

; (menu-bar-mode nil)
(fset 'yes-or-no-p 'y-or-n-p) ; `y' and `n' instead of `yes' and `no'
(tool-bar-mode -1)
(fringe-mode 'none)
(show-paren-mode t)
(transient-mark-mode t)       ; make the current 'selection' visible
(delete-selection-mode t)     ; delete the selection area with a keypress
(global-font-lock-mode t)
(column-number-mode t)
(split-window-horizontally)   ; I want four equal sized windows created
(split-window-horizontally)   ; at startup. Three times split-window-horizontally
(split-window-horizontally)   ; followed by balance-windows does the trick.
(set-scroll-bar-mode 'nil)
(winner-mode t) ; use with C-c left or C-c right
(savehist-mode t)

(setq default-truncate-lines t)
(setq sentence-end-double-space 'nil)    ; Since my sentences end with `. ' and not `.  '
(setq default-major-mode 'text-mode)
(setq x-select-enable-clipboard t)       ; copy/paste between emacs and e.g. iceweasel
(setq require-final-newline 'visit-save) ; all files end with `\n'
(setq term-buffer-maximum-size 0)        ; no pager-like behavior with ansi-term
(setq backup-by-copying t)
(setq compilation-scroll-output t)

(global-auto-revert-mode 1)
(setq global-auto-revert-non-file-buffers t)

; Elevate some limits
(setq max-lisp-eval-depth '4000)
(setq max-specpdl-size '10000)

; Enable disabled commands
(put 'scroll-left 'disabled nil)
(put 'scroll-right 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'erase-buffer 'disabled nil)

; Disable enabled commands/keybindings
(put 'overwrite-mode 'disabled t)
(global-unset-key (kbd "<f10>")) ; since I use f10 for w3m

; If being with `No Gnus v0.6' next to the version of Gnus that comes
; packaged with emacs, one should avoid loading a mixture of libraries
; from both versions of Gnus. To do so you should prevent loading any
; of emacs gnus libraries before `No Gnus v0.6' starts because the
; user triggerd that action.

;; (setq load-path (remove-if
;;                   (lambda (x)
;;                     (when (string-match "gnus-" x) t)) load-path)
;; )

;;;_ , Debian stuff

;;;_  .  apt-sources - major mode for editing Debian sources.list files

;;;_  .  apt-utils - interface to APT (Debian package management)

;;;_  .  debian-bug - an Emacs command to submit a bug report

;;;_  .  deb-view - view contents of Debian package, similarly to tar-mode

;;;_  .  gnus-BTS - provides buttons for bug numbers seen in Gnus messages

;(require 'gnus-BTS)

;;;_  .  preseed - major mode for editing debian-installer preseed files

;;;_ , automatically create path

; some sort of mkdir -p for non existing paths
;   when opening a non-existing file (e.g. myfile) within some yet
;   non-existing directory, it automatically creates the file and
;   /path/to/file/myfile when the file is saved witin emacs

(add-hook 'before-save-hook
          '(lambda ()
             (or (file-exists-p (file-name-directory buffer-file-name))
                 (make-directory (file-name-directory buffer-file-name) t))))

;;;_ , automatically delete trailing whitespace

(add-hook 'before-save-hook 'delete-trailing-whitespace)

;;;_ , automatically untabify buffers

(add-hook 'before-save-hook '(lambda () (untabify (point-min) (point-max))))

;;;_ , autosave

; save every 100 characters typed
(setq auto-save-interval 100)

; save after 10 seconds of idle time
(setq auto-save-timeout 10)

(defun my-save-buffer-if-visiting-file (&optional args)
  "Save the current buffer only if it is visiting a file"
    (if (buffer-file-name)
        (save-buffer args)

; This causes files that I'm editing to be saved automatically by the
; emacs auto-save functionality.  I'm hoping to break myself of the
; c-x c-s twitch.
(add-hook 'auto-save-hook 'my-save-buffer-if-visiting-file)

;;;_ , pwsafe

(require 'pwsafe)
(setq pwsafe-primary-database (concat emacs-root-dir "pwsafe/pwsafe_data"))
(setq pwsafe-keep-passwd t)

;;;_ , my-remove-duplicates

; This little fellow is great. It removes duplicates from region i.e.
; transforms "foo baz foo bar baz" into "foo baz bar".

(defun my-remove-duplicates (start end)
  (interactive "r")
    (goto-char start)
    (narrow-to-region start end)
    (let ((seen nil) (word nil) (s start))
      (while (forward-word)
        (when (setq word (word-at-point))
          (if (member word seen)
              (kill-region s (point))
            (setq seen (cons word seen)) ))
        (setq s (point))))

;;;_ , my-compute-replace-region

(defun  my-compute-replace-region (n) (interactive "nEnter multiplicator: ")
  (let ((result (* n (string-to-number (buffer-substring (point) (mark))))))
   (kill-region (point) (mark))
   (insert (format "%d"result))

;;;_ , my-reverse-chars-in-region

; This one is fun too; makes "Hey baby ..." into "... ybab yeH"

(defun my-reverse-chars-in-region (start end)
  "Reverse the region character by character without reversing lines.
Use `reverse-region' to reverse the lines in the region."
  (interactive "r")
  (let ((str (buffer-substring start end)))
    (delete-region start end)
    (dolist (line (split-string str "\n"))
      (let (
               (mapcar (lambda (c)
                             (or (matching-paren c)
                           (reverse (append line nil))
        (when chars
          (apply 'insert chars)

;;;_ , my-unique-lines

(defun my-unique-lines (beg end)
  "Unique lines in region.
Called from a program, there are two arguments:
BEG and END (region to sort)."
  (interactive "r")
      (narrow-to-region beg end)
      (goto-char (point-min))
      (while (not (eobp))
        (kill-line 1)
        (let ((next-line (point)))
               (format "^%s" (car kill-ring)) nil t
            (replace-match "" nil nil)
          (goto-char next-line)

;;;_ , 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 "Week/Day of year: %W/%j")
            "      "
            ,(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)

;;;_ , my-surround-sexp

; http://www.emacswiki.org/cgi-bin/wiki/FormattingText

;;;_  . my-surround-sexp-0

 (defun my-surround-sexp-0 ()
        (forward-sexp 1)
        (insert "=")
        (backward-sexp 1)
        (insert "=")

;;;_  . my-surround-sexp-1

 (defun my-surround-sexp-1 ()
        (forward-sexp 1)
        (insert "*")
        (backward-sexp 1)
        (insert "*")

;;;_  . my-surround-sexp-2

(defun my-surround-sexp-2 (char)
  (interactive "cInsert surrounding character ... ")
  (let ((bounds (bounds-of-thing-at-point 'sexp)))
    (when bounds
      (goto-char (cdr bounds))
      (insert char)
      (goto-char (car bounds))
      (insert char)
      (forward-sexp 2)

;;;_  . my-surround-sexp-3

; `insert-pair' has been used here.

(defun my-surround-sexp-3  (number open close)
    "nNumber sexp: \ncPress opening char ... \ncPress closing char ... ")
     (insert-pair number open close)
   (forward-sexp number))

;;;_ , Auto bytecompile

(defun byte-compile-init-file ()
  (when (equal buffer-file-name user-init-file)
     (let ((byte-compile-warnings '(unresolved)))
          (when (file-exists-p (concat user-init-file ".elc"))
                (delete-file (concat user-init-file ".elc"))
          (byte-compile-file user-init-file)
          (message "Just compiled %s " user-init-file)

(add-hook 'kill-buffer-hook 'byte-compile-init-file)

;;;_ , htmlize-init-file

; I provide my `.emacs' to the public on my website. This function has
; been written in order to provide an up-to-date `.emacs' at all times
; i.e. every time I quit the buffer after altering something in my
; `.emacs' the html as well as plain text version is put into a
; directory together with all the other website related `.html' pages.

;; FIXME (however, it is working now ... still a hack)
;; (setq emacs-not-hidden "dot_emacs")
;; (setq emacs-not-hidden ".emacs")

;; (defun htmlize-init-file ()
;;   ; Run some tests
;;   (when (and  (equal buffer-file-name user-init-file)
;;               (file-exists-p user-init-file)
;;               (file-exists-p website-public-xhtml-dir)
;;         )
;;         (if (file-exists-p (concat website-public-xhtml-dir emacs-not-hidden))
;;                 (delete-file (concat website-public-xhtml-dir emacs-not-hidden))
;;         )
;;         (if (file-exists-p (concat website-public-xhtml-dir emacs-not-hidden ".html"))
;;                 (delete-file (concat website-public-xhtml-dir emacs-not-hidden ".html"))
;;         )
;;         ; After testing comes the beef
;;         (copy-file user-init-file (concat website-public-xhtml-dir emacs-not-hidden))
;;         (htmlize-file (concat website-public-xhtml-dir emacs-not-hidden))
;;         (message "Just htmlized %s " user-init-file)
;;   )
;; )

;; (add-hook 'kill-buffer-hook 'htmlize-init-file)

;;;_ , Fun startup message

;; (defconst animate-n-steps 50)
;; (defun with-emacs-2-the-stars-and-beyond ()
;;   (animate-string
;;      (concat "Fly me to the moon and let me play among the stars."
;;              "\n"
;;              "      Let me see a sunset on Jupiter or Mars."
;;              "\n"
;;              "\n"
;;              "\n"
;;              "               "
;;              (substring (emacs-version) 0 16)
;;              "  -- free software for free people ..."
;;      )
;;                   20 0)
;;   (newline-and-indent)
;;   (newline-and-indent)
;; )

;(add-hook 'after-init-hook 'with-emacs-2-the-stars-and-beyond)

;;;_ , command-history

; See `chistory.el'

; 1) I use `command-history' which is bound to `C-x c' on a regular
; 2) Using `repeat-complex-command' wich is bound to `C-x M-:' per
; default is also pretty useful

(setq list-command-history-max '100)

;;;_ , higlight-changes-mode

;(global-highlight-changes-mode t)
(setq highlight-changes-global-changes-existing-buffers t)

;;;_ , unfill-paragraph

(defun unfill-paragraph ()
"The opposite of fill-paragraph Takes a multi-line paragraph and
makes it into a single line of text."
  (let ((fill-column (point-max)))
        (fill-paragraph nil))

;;;_ , my-sum-up-region

(defun my-sum-up-region (start end)
  (interactive "r")
  (message "%s"   (reduce '+
          (mapcar (lambda (x) (string-to-number x))
                  (split-string (buffer-substring start end) "\n")))))

;;;_ , number-lines-region

; This function allows one to indicate the starting value with the
; numeric prefix argument. The default value is 1. To begin at zero,
; type `M-0 M-x number-lines-region'. Negative numbers are also
; supported. Numbers are right aligned followed by a period and a
; space. If the point is at the beginning of the region, the lines
; will be numbered in descending order. If a line is already prefixed
; with a number, it will be overwritten with the new value.

(defun number-lines-region (start end &optional beg)
  (interactive "*r\np")
  (let* ((lines (count-lines start end))
         (from (or beg 1))
         (to (+ lines (1- from)))
         (numbers (number-sequence from to))
         (width (max (length (int-to-string lines))
                     (length (int-to-string from)))))
    (if (= start (point))
        (setq numbers (reverse numbers)))
    (goto-char start)
    (dolist (n numbers)
        (if (looking-at " *-?[0-9]+\\. ")
            (replace-match "")))
      (insert (format (concat "%" (int-to-string width) "d  ") n))

;;;_ , ffap (find file at point)

; See (Info-goto-node "(emacs)FFAP")


;;;_ , ispell and aspell

;Well, no ... I will leave it in my `~/' for now ...
;(setq ispell-personal-dictionary

;;;_ , semanticdb

(setq semanticdb-default-save-directory (concat emacs-root-dir "semanticdb"))

;;;_ , Restore desktop, buffers, point etc.

;;;_  . Desktop restore

(require 'desktop)
(desktop-save-mode t)
(setq inhibit-startup-message t)
(setq history-length 1500)
(add-to-list 'desktop-globals-to-save 'file-name-history)

; Right now (Tue Jul 17 2007) `desktop-dirname' does not allow to set
; another dirname than `/home/username'
;(setq desktop-dirname (concat emacs-root-dir "desktop/"))
;(setq desktop-base-file-name "emacs_desktop")

;;;_  . Save place within files

(require 'saveplace)
(setq save-place-file (concat emacs-root-dir "saveplace/places"))
(setq-default save-place t)

;;;_ , Backup files and version control

; See (Info-goto-node "(emacs)Numbered Backups")
(setq version-control t)
(setq kept-new-versions 2)
(setq kept-old-versions 2)
(setq delete-old-versions t)

;;;_ , point-stack - remember position and jump back
;(require 'point-stack)

;;;_ , date and time

; See `my-date-insert-1', `my-date-insert-2' and `my-date-insert-3'

;;;_ , mouse related stuff

;;;_ , allout-mode

; for version 2.2+ of allout.el do s/(outline-init t)/(allout-init t)/
(require 'allout)
(allout-init t)

;;;_ , filladapt

;; See http://www.emacswiki.org/cgi-bin/wiki/FillAdapt for more
;; information.

(require 'filladapt)
(setq-default filladapt-mode t)

;; Use
;;     (add-hook 'text-mode-hook 'turn-on-filladapt-mode)
;; to have Filladapt always enabled in Text mode.
;; Use
;;     (add-hook 'c-mode-hook 'turn-off-filladapt-mode)
;; to have Filladapt always disabled in C mode.

;;;_ , flyspell

; Next to the code in this section (not specific to any mode, use
; case, ...) look out for specific settings e.g. `add-hook' settings
; and the like with flyspell

; Note the possibility to easily toggle `flyspell-mode' with `C-c t f'

;;;_  . Activate (positive arg)

(dolist (hook '(text-mode-hook))
  (add-hook hook (lambda () (flyspell-mode 1)))

;;;_  . Deactivate (negative arg)

(dolist (hook '(change-log-mode-hook log-edit-mode-hook))
  (add-hook hook (lambda () (flyspell-mode -1)))

;;;_ , folding

(load "folding" 'nomessage 'noerror)

;;;_ , toggle-option

(require 'toggle-option)

(setq toggle-option-list
         (flyspell-mode function nil nil)
         (auto-fill-mode function nil nil)
         (abbrev-mode function nil nil)
         (dedicated-mode function nil nil)
         (highlight-changes-visible-mode function nil nil)

;;;_ , IDO (InteractivelyDoThings)

; See http://www.emacswiki.org/cgi-bin/wiki/InteractivelyDoThings

(require 'ido)
(ido-mode t)
(setq ido-save-directory-list-file (concat emacs-root-dir "ido/ido.last"))
(setq ido-enable-flex-matching t)

; For the function below see http://www.emacswiki.org/cgi-bin/wiki/RecentFiles
; I also did s/recentf-list/file-name-history/

; Initially I wanted to use `recentf-list' but then considered using
; `file-name-history' would be way cooler since that would provide me
; with a choice for any file ever entered in the minibuffer.

(defun recentf-interactive-complete ()
  "Find a file in the `file-name-history' using ido for completion."
  (let* ((all-files file-name-history)
         (file-assoc-list (mapcar (lambda (x) (cons (file-name-nondirectory x) x)) all-files))
         (filename-list (remove-duplicates (mapcar 'car file-assoc-list) :test 'string=))
          (lambda ()
            (setq ido-temp-list filename-list)))
         (filename (ido-read-buffer "Find File: "))
         (result-list (delq nil (mapcar (lambda (x) (if (string= (car x) filename) (cdr x))) file-assoc-list)))
         (result-length (length result-list)))
           ((= result-length 0) filename)
           ((= result-length 1) (car result-list))
           ( t
             (let ((ido-make-buffer-list-hook
                     (lambda () (setq ido-temp-list result-list))))
               (ido-read-buffer (format "%d matches:" result-length))))

;;;_ , uniquify
; See (Info-goto-node "(emacs) Uniquify")

(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
(setq uniquify-trailing-separator-p t)

;;;_ , recentf

; See http://www.emacswiki.org/cgi-bin/wiki/RecentFiles

(require 'recentf)
(recentf-mode 1)
(setq recentf-save-file (concat emacs-root-dir "recentf/recentf"))

; And to make use of it ...

; Well, for now this code is gone since I figured, making usage of
; `recentf-interactive-complete' is way better - whatever I decided to
; keep the three recentf lines above around since they cause no harm ...

;;;_ , cyclebuffer

; Well, this is already part of Emacs CVS so see for keybindings where
; I set them.

;;;_ , windmov

(require 'windmove)

;;;_ , abbrev

(setq abbrev-file-name (concat emacs-root-dir "abbrev/abbrev_file"))
(setq abbrev-backup-file-name (concat abbrev-file-name "_backup"))

; Add misspellings to my abbrev table, so that abbrev-mode will fix
; them henceforth
(setq flyspell-abbrev-p t)

; Save abbrevs when files are saved or quit emacs. Unfortunately this
; seems just to work when I quit emacs but not with (C-x C-s)
; `save-buffer'
(setq save-abbrevs 'silently)

; Write file `abbrev-file-name' anytime a global abbreviation is added
(defadvice add-global-abbrev
           (after make-sure-its-saved activate)

;;;_  . Take care that `(concat emacs-root-dir abbrev/abbrev_defs)' is backuped

(defun backup-abbrev-file ()
  (when (file-exists-p abbrev-file-name)

     (if (file-exists-p abbrev-backup-file-name)

         ;Create backups from `abbrev-file-name' as well as
         (if (> (with-temp-buffer
                   (insert-file-contents abbrev-file-name)
                   (count-lines (point-min) (point-max)))
                   (insert-file-contents abbrev-backup-file-name)
                   (count-lines (point-min) (point-max)))
               (copy-file abbrev-backup-file-name
                      (concat abbrev-backup-file-name
               (delete-file abbrev-backup-file-name)
               (copy-file abbrev-file-name abbrev-backup-file-name)
               (message "Just backuped %s   and   %s"
                        abbrev-file-name abbrev-backup-file-name)

         ; Restore `abbrev-file-name' from `abbrev-backup-file-name'
         ; but allow to delete up to 100 entries in `abbrev-file-name'
         ; when using `M-x edit-abbrevs'
         (if (< (with-temp-buffer
                        (insert-file-contents abbrev-file-name)
                        (count-lines (point-min) (point-max)))
                (- (with-temp-buffer
                      (insert-file-contents abbrev-backup-file-name)
                      (count-lines (point-min) (point-max))) 100)
              (delete-file abbrev-file-name)
              (copy-file abbrev-backup-file-name abbrev-file-name)
              (message "Just restored  %s   from   %s"
                       abbrev-file-name abbrev-backup-file-name)

     ; `abbrev-backup-file-name' does not exist yet -> create it
     (if (not (file-exists-p abbrev-backup-file-name))
         (copy-file abbrev-file-name abbrev-backup-file-name)
         (message "Just backuped %s " abbrev-file-name)

; Trigger the function when I quit emacs
(add-hook 'kill-emacs-hook 'backup-abbrev-file)

; load all my abbreviations from `abbrev-file-name'
(load-file abbrev-file-name)

;;;_ , dabbrev - Dynamic Abbreviation

; See http://www.emacswiki.org/cgi-bin/wiki/DynamicAbbreviations

(require 'dabbrev)

;;;_ , multi-protocol remote file access

; See (Info-goto-node "(tramp)Top") as well as
; http://www.emacswiki.org/cgi-bin/wiki/TrampMode

; What I also consider very useful is
;(Info-goto-node "(tramp)Version Control")

(require 'tramp)

(setq tramp-default-method "ssh")

;;;_  . ease the local editing of files owned by root

; There is no `tramp-file-name-path' function present so I don't how
; it can be used below.

;; (defvar find-file-root-prefix
;;         (if (featurep 'xemacs)
;;             "/[sudo/root@localhost]"
;;          "/sudo:root@localhost:" )
;; "*The filename prefix used to open a file with `find-file-root'."
;; )

;; (defvar find-file-root-history nil
;;   "History list for files found using `find-file-root'.")

;; (defvar find-file-root-hook nil
;;   "Normal hook for functions to run after finding a \"root\" file.")

;; (defun find-file-root ()
;; "*Open a file as the root user. Prepends `find-file-root-prefix'
;; to the selected file name so that it maybe accessed via the
;; corresponding tramp method."

;;  (interactive)
;;  ; We bind the variable `file-name-history' locally so we can use a
;;  ; separate history list for "root" files.
;;  (let* (
;;              (file-name-history find-file-root-history)
;;              (name              (or buffer-file-name default-directory))
;;              (tramp             (and (tramp-tramp-file-p name)
;;                                      (tramp-dissect-file-name name)
;;                         )
;;         )
;;         path dir file
;;        )

;;    ;; If called from a "root" file, we need to fix up the path.
;;    (when tramp
;;      (setq path (tramp-file-name-path tramp)
;;            dir       (file-name-directory path))
;;    )

;;    (when (setq file (read-file-name "Find file (UID = 0): " dir path))
;;      (find-file (concat find-file-root-prefix file))
;;      ;; If this all succeeded save our new history list.
;;      (setq find-file-root-history file-name-history)
;;      ;; allow some user customization
;;      (run-hooks 'find-file-root-hook)
;;    )
;;  )
;; )

;; (global-set-key (kbd "C-c f f") 'find-file-root)

;;;_ , unbound - find unbound keys

(require 'unbound) ;use `describe-unbound-keys'

;;;_ , Display number of lines, words and characters in region

(defun my-count-words-region (start end)
   (interactive "r")
      (let ((n 0))
        (goto-char start)
        (while (< (point) end)
          (if (forward-word 1)
              (setq n (1+ n))
        (message "Region has %d words" n)

;making use of `my-count-words-region'
(defun my-count-lines-words-characters-region (start end)
  "Print number of lines words and characters in the region."
  (interactive "r")
  (message "Region has %d lines, %d words, %d characters."
          (count-lines start end)
          (my-count-words-region start end)
          (- end start)

;;;_ , fortune

(require 'fortune)
(setq fortune-dir   "/usr/share/games/fortunes")
(setq fortune-file  "/usr/share/games/fortunes/mjg")

;;;_ , Insert date/time at point

(defun my-date-insert-0-non-interactive () (interactive)
"Insert date in format like `seconds since 1970-01-01 00:00:00 UTC'"
  (replace-regexp-in-string "\n" "" ;remove `\n'
            (shell-command-to-string "date +%s")

(defun my-date-insert-0 () (interactive)
"Insert date in format like `seconds since 1970-01-01 00:00:00 UTC'"
  (insert (replace-regexp-in-string "\n" "" ;remove `\n'
            (shell-command-to-string "date +%s")

(defun my-date-insert-1 () (interactive)
"Insert date in format like `month year' e.g. `June 2007'."
  (insert (replace-regexp-in-string "\n" "" ;remove `\n'
            (shell-command-to-string "date +%B' '%Y")

(defun my-date-insert-2 () (interactive)
"Insert date in format like `Sun Dec 14 18:34:47 UTC 2008'."
  (insert (replace-regexp-in-string "\n" "" ;remove `\n'
            (shell-command-to-string "date -u")

(defun my-date-insert-3 () (interactive)
"Insert date in format like `Sunday 2007-07-08 [12:19 UTC]'."
  (insert (replace-regexp-in-string "\n" "" ;remove `\n'
             (shell-command-to-string "date +%A")
             " "
             (shell-command-to-string "date +%Y-%m-%d")
             "   "
             (shell-command-to-string "date -u +%H:%M")
             " UTC"

(defun my-date-insert-4 () (interactive)
"Insert date in format like `* YearMonthDayHourMinute:' e.g. `*
200711062045: '."
              "* "
              (replace-regexp-in-string "\n" "" ;remove `\n'
                (shell-command-to-string "date +%Y%m%d%H%M")
              ": "
              "<literal><p class=\"first_paragraph\"></literal>\n"

(defun my-date-insert-5 () (interactive)
"Insert date in format like `2007-07-08'."
  (insert (replace-regexp-in-string "\n" "" ;remove `\n'
;;;              (shell-command-to-string "date +%A")
;;;              " "
             (shell-command-to-string "date +%Y-%m-%d")
;;;              "  ["
;;;              (shell-command-to-string "date -u +%H:%M")
;;;              " UTC]"

;;;_ , dired

(setq dired-dwim-target t)
(setq dired-recursive-copies 'always)
(setq dired-recursive-deletes 'always)
(setq image-dired-external-viewer "/usr/bin/gimp")

;;;_ , dired-x

; See (Info-goto-node "(dired-x) Top")
(require 'dired-x)

;;;_  . Omit

(dired-omit-mode 1)
(setq dired-omit-files (concat dired-omit-files "\\|^\\."))
(setq dired-omit-extensions `(,@dired-omit-extensions ".avi" ".mp3"))

;;;_  . Local Variables

; I only made a keybinding. For the rest, I kept all the defaults e.g.
; files containing the local varibles per directory are called
; `.dired'.

;;;_  . Shell Command Guessing

; I will set this later when actually needed/wanted.

;;; (setq dired-guess-shell-alist-user
;;;       (list
;;;        (list "\\.foo$" "FOO-COMMAND");; fixed rule
;;;        ;; possibly more rules...
;;;        (list "\\.bar$";; rule with condition test
;;;               '(if CONDITION
;;;                    "BAR-COMMAND-1"
;;;                  "BAR-COMMAND-2"))))

;;;_  . Virtual Dired

; The data forensic dudes might go wild about virtual dired -- they
; can do a `ls -alR / > my_forensic_file' and then investigate it
; _offline_ via virtual dired.

;;;_  . Advanced Mark Commands

; (Info-goto-node "(dired-x) Advanced Mark Commands")

;;;_ , image-dired

; See http://www.emacswiki.org/cgi-bin/wiki/Tumme
(require 'image-dired)

(setq image-dired-show-all-from-dir-max-files 100)
(setq image-dired-thumb-margin 4)
(setq image-dired-thumb-relief 0)

;;;_  . directories

(setq imd-images-dir (concat (getenv "HOME") "/mm/si/image-dired"))
(setq imd-meta-data-dir imd-images-dir)

(setq image-dired-dir (concat imd-images-dir "/image-dired_thumbnails"))
(setq image-dired-main-image-directory (concat imd-images-dir"/temp"))

;;;_  . files

(setq image-dired-db-file (concat imd-meta-data-dir "/image-dired_db"))
(setq image-dired-temp-image-file (concat imd-images-dir "/image-dired_temp_file"))
(setq image-dired-temp-rotate-image-file (concat imd-images-dir "/dired_rotate_temp_file"))

;;;_  . gallery

(setq image-dired-gallery-dir (concat imd-images-dir "/gallery"))
(setq image-dired-gallery-hidden-tags
        `("private" "hidden" "pending" ,@priv-image-dired-gallery-tags))

(setq gallery-http-root "")

(setq image-dired-gallery-image-root-url
        (concat gallery-http-root image-dired-gallery-dir))

(setq image-dired-gallery-thumb-image-root-url
        (concat gallery-http-root image-dired-gallery-dir "/thumbs"))

;;;_ Web

;;;_. standard browser to open URLs within GNU Emacs

; See http://www.emacswiki.org/cgi-bin/wiki/BrowseUrl for more information.

(setq gnus-button-url 'browse-url-generic
      browse-url-generic-program "iceweasel"
      browse-url-browser-function gnus-button-url)

;;;_. w3m

(require 'w3m)
(require 'w3m-namazu)

;;;_ , miscellaneous

(setq w3m-default-display-inline-images t)
(setq w3m-use-cookies t)

;;;_ , show line numbers
;(add-hook 'w3m-mode-hook 'turn-on-setnu-mode)
;(add-hook 'w3m-delete-buffer-hook 'setnu-mode)

;;;_ , Miscellaneous Functions

;;;_  . my-w3m-copy-url-at-point

(defun my-w3m-copy-url-at-point ()
  (let ((url (w3m-anchor)))
    (if (w3m-url-valid url)
        (kill-new (w3m-anchor))
        (message "No URL at point!")

;;;_  . my-interactive-w3m-search

(defun my-interactive-w3m-search ()
      (let ((current-prefix-arg t))
        (call-interactively 'w3m-search)

;;;_ Communication

;;;_. Gnus

;;;_ , miscellaneous settings

;;;_  . Personal settings

(setq user-full-name priv-my-name)
(setq user-mail-address priv-my-sunoano1-mail-address)

;;;_  . Gnus common settings

(setq gnus-home-directory (concat emacs-root-dir "gnus"))
(setq nnml-directory (concat emacs-root-dir "gnus/Mail"))
(setq gnus-article-save-directory (concat emacs-root-dir "gnus/News"))

(setq gnus-default-article-saver 'gnus-summary-save-in-file)
(setq gnus-visual t)
(setq gnus-backup-startup-file t)
(setq gnus-init-file nil)
(setq gnus-inhibit-startup-message t)

(require 'gnus-msg)
(setq mail-user-agent 'gnus-user-agent)

;;;_  . Agent - Gnus Unplugged

; I did all agent settings with group parameters -- therefore see
; `gnus-parameters'

;;;_    . miscellaneous

; See (Info-goto-node "(gnus)Category Syntax")

(require 'gnus-agent)

(setq gnus-agent-go-online t)
(setq gnus-agent-expire-days 30) ; used in `my-article-old-p' (see below)
(setq gnus-agent-synchronize-flags t)
(add-hook 'gnus-select-article-hook 'gnus-agent-fetch-selected-article)

; see (Info-goto-node "(gnus)Category Syntax") for the below settings
(setq gnus-agent-low-score 0)
(setq gnus-agent-high-score 99)
(setq gnus-agent-short-article 80)
(setq gnus-agent-long-article 200)

;;;_    . a function definition to decide to (not to) download old articles

(defun my-article-old-p ()
  "Say whether an article is old."
  (< (time-to-days (date-to-time (mail-header-date gnus-headers)))
     (- (time-to-days (current-time)) gnus-agent-expire-days))

; add to alist for short term (just `old' instead of
; `my-article-old-p') usage

(setq  gnus-category-predicate-alist
  (append gnus-category-predicate-alist
         '((old . my-article-old-p)))

;;;_   , caching and article backlogs

(setq gnus-keep-backlog 3000)

;;;_   , partially fetch old headers

(setq gnus-fetch-old-headers 'some)

;;;_  . EPG/PGG/MIME

; Note that pgg is now superseeded by epg (easyPG). In fact, pgg is
; obsolete now; same goes for mailcrypt, it is obsolte as well. One
; should use epg now which is shipped with Emacs.

;;;_   , pgg

; See (Info-goto-node "(pgg)Top")
;     (Info-goto-node "(gnus)Using MIME")
;     (Info-goto-node "(message)Security")
;     (Info-goto-node "(gnus)MIME Commands")
;     (Info-goto-node "(emacs-mime)Top")
;     (Info-goto-node "(gnus)group parameters")

; (require 'pgg)
; (setq pgg-scheme 'gpg)
; (setq pgg-default-scheme 'gpg)
; (setq pgg-passphrase-cache-expiry '7200)
; (setq pgg-query-keyserver t)
; (setq pgg-default-keyserver-address "subkeys.pgp.net")
; (setq pgg-default-user-id priv-my-keyid)    ; using the key ID here
; (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)

;;;_   , EasyPG

; epa-mail-sign without a prefix argument works

(require 'epa)

(setq mml2015-use 'epg)
(setq mml2015-encrypt-to-self t)
(setq mml2015-verbose t)
(setq mml2015-always-trust nil)
(setq mml2015-passphrase-cache-expiry '7200)

(add-hook 'message-setup-hook
          (lambda ()
            (if gnus-newsgroup-name
                (let ((signers (gnus-group-get-parameter
                  (if signers
                      (set (make-local-variable 'mml2015-signers)

(setq gnus-message-replysign t
      gnus-message-replyencrypt t
      gnus-message-replysignencrypted t
      gnus-treat-x-pgp-sig t
      mm-verify-option 'always
      mm-decrypt-option 'always

;;;_   , MIME

(setq gnus-buttonized-mime-types

(setq mm-coding-system-priorities
      '(iso-latin-1 iso-latin-9 mule-utf-8))

; Rewriting file names of MIME parts i.e. process email attachments of
; unenlightened users e.g. delete control characters, delete shell
; gotchas, handle whitespace, make downcase, etc.

(setq mm-file-name-rewrite-functions

;;;_  . Daemon

; Check for new articles automatically
(gnus-demon-add-handler 'gnus-group-get-new-news 30 7)

; `gnus-demon-init' is already called via `gnus-demon-add-handler'

;;;_  . Boxqoute

; See Keybindings - those are not Gnus specific but global as I set them
; to be.

;;;_  . HTML stuff

;;;_   , do not render HTML - only show text

(eval-after-load "mm-decode"
      (add-to-list 'mm-discouraged-alternatives "text/html")
      (add-to-list 'mm-discouraged-alternatives "text/richtext")))

;;;_   , if for whatever reason HTML should be rendered do it with w3m

(setq mm-text-html-renderer 'w3m)

;;;_  . Repair TOFU, broken attribution, etc.

(require 'deuglify)
(defun standard-wash-this-article ()
;        (gnus-article-fill-cited-article nil '100)

(add-hook 'gnus-article-decode-hook 'standard-wash-this-article)

;;;_  . Layout for windows and buffers

;;;_   , window layout settings

 ;;(setq gnus-always-force-window-configuration t)

   (horizontal 1.0
    (vertical 0.74
     (article 1.0)
     (summary 0.4)
    (vertical 1.0
     (group 1.0 point)
     (server 0.18)

   (horizontal 1.0
    (vertical 0.74
     (article 1.0)
     (summary 0.4)
    (vertical 1.0
     (group 1.0)
     (server 0.18 point)

   (horizontal 1.0
    (vertical 0.74
     (article 1.0)
     (summary 0.4 point)
    (vertical 1.0
     (group 1.0)
     (server 0.18)

   (horizontal 1.0
    (vertical 0.74
     (article 1.0 point)
     (summary 0.4)
    (vertical 1.0
     (group 1.0)
     (server 0.18)

;;;_  . Supercite

(autoload 'sc-cite-original     "supercite" "Supercite 3.1" t)
(autoload 'sc-submit-bug-report "supercite" "Supercite 3.1" t)

;see supercite manual section 5.1 for more information about the below
(add-hook 'mail-citation-hook 'sc-cite-original)
(setq news-reply-header-hook nil)
;(add-hook 'sc-load-hook 'sc-setup-filladapt)

;see supercite manual section 6.2 for more information about the below
;; (setq sc-auto-fill-region-p nil)
(setq sc-fixup-whitespace-p t)

(setq sc-preferred-header-style 0) ; now set to `0'; was set to `6' before
(setq sc-reference-tag-string " >| ")
(setq sc-citation-leader " ")

(setq sc-preferred-attribution-list
            '("sc-lastchoice" "x-attribution" "sc-consult"
              "initials" "firstname" "lastname"))

(setq sc-attrib-selection-list
            ((".*" . (bbdb/sc-consult-attr
              (sc-mail-field "sc-from-address")))))))

; allow the retrieval of the name of a person who is a) in the BBDB
; and b) has only included their net address in the message
(setq sc-mail-glom-frame
   '((begin                        (setq sc-mail-headers-start (point)))
     ("^x-attribution:[ \t]+.*$"   (sc-mail-fetch-field t) nil t)
     ("^\\S +:.*$"                 (sc-mail-fetch-field) nil t)
     ("^$"                         (progn (bbdb/sc-default)
                                   (list 'abort '(step . 0))))
     ("^[ \t]+"                    (sc-mail-append-field))
     (sc-mail-warn-if-non-rfc822-p (sc-mail-error-in-mail-field))
     (end                          (setq sc-mail-headers-end (point))))


;use this to filter away noise in author names - ;see supercite manual
;section 7.3 for more information about the below

;;;_  . gnus-registry

(require 'gnus-registry)

;;;_  . mail-alias
; See (Info-goto-node "(bbdb) Mail Sending Interfaces") and
; http://www.emacswiki.org/cgi-bin/wiki/BbdbMailingLists

(add-hook 'message-setup-hook 'bbdb-define-all-aliases t)

;;;_ , buffer specific settings

;;;_  . concerning only one particular buffer

;;;_   , article buffer

(setq gnus-article-mode-line-format "Gnus: %G [%w] Mime parts:%m Score:%z Subject:%S ")

;;;_    . MIME and Charset

(setq gnus-mime-display-multipart-related-as-mixed t)

;(setq gnus-default-charset 'utf-8)

;;;_   , group buffer

(setq gnus-topic-indent-level 3)
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
(setq gnus-permanently-visible-groups ".*")
(add-hook 'gnus-select-group-hook 'gnus-group-set-timestamp)

;;;_    . group line format

(setq gnus-group-line-format
      "%P|%B|%M%o%S%L[%6t|%3i]%6y :%(%~(pad-right 65)g%):%6,6~(cut 2)d\n")

;;;_    . topic line format

; Make gnus-topic-line into another color -- see (Info-goto-node
; "(gnus)Formatting Fonts"). For colors take a look at
; http://en.wikipedia.org/wiki/Web_colors

; Stupid! Why do you set faces like this. Use M-x list-faces
; RET and the customize feature so that stuff goes to the
; boffom of `.emacs'.

(setq gnus-face-1 'bold)
(copy-face 'bold 'my-topic-line-face)
(set-face-foreground 'my-topic-line-face "#4682B4")
(setq gnus-face-100 'my-topic-line-face)

; The gnus-face-100 is used in gnus-topic-line-format

(setq gnus-topic-line-format "%100{%i[ %(%{%n%}%) -- %A ]%v%}\n")

;;;_    . group sorting

(setq gnus-group-sort-function
      '(gnus-group-sort-by-alphabet gnus-group-sort-groups-by-rank))

(add-hook 'gnus-summary-exit-hook 'gnus-group-sort-groups-by-rank)
(add-hook 'gnus-summary-exit-hook 'gnus-summary-bubble-group)

;;;_    . group parameters

(setq gnus-parameters
;;;_      . mail
;;;_       , groups
;;;_        . family
;;;_        . misc
;;;_        . spam
; This is the S P A M group for ALL messages (mail and news)
         ; .... spam rules ............
         (gnus-article-sort-functions (gnus-article-sort-by-chars))
         (spam-contents gnus-group-spam-classification-spam)
         (ham-process-destination . "nnml:junk2ham")
; Regarding the above line -- from there (`nnml:junk2ham'), I manually
; move/copy ham to a group where it belongs plus I can use them for
; ham training. Of course I have to inspect my spam group
; `nnml:m.junk' occasionally in order to find false positives (i.e.
; legitimate mails, that were wrongly judged as spam) and remove the
; spam mark (`M-d') -- then at group exit all false positives are
; moved/copied to `nnml:junk2ham'.

         ;The below line is redundancy since other groups already
         ;contain the same rule but keeping it doesn't harm --
         ;everythime I visit and exit the spam group I can be sure all
         ;senders are added to the blacklist
         (spam-process ((spam spam-use-blacklist)
                        (spam spam-use-bogofilter)))
         ; .... agent parameters ......
         (agent-predicate . true)
         (agent-score . file)
         ; - - agent score rule - -
         ; .... posting style .........
            (name "NoName")
            (address "spam_is_for@the_weak.com")
         ; .... group parameters ......
         (display . 22) ;counting starts at zero so 15 results in 16
         ; .... local variables .......
;;;_       , people
;;;_        . realname
;;;_         , firstname and lastname
        (,priv-my-gmail0-mail-address-gp ; FIXME replace with priv-my-sunoano1-mail-address-gp once my own email system is up and running
         ; .... spam rules ............
         (spam-contents gnus-group-spam-classification-ham)
         (spam-process-destination . "nnimap:m.junk")
         (spam-process ((spam spam-use-blacklist)
                        (ham spam-use-whitelist)     ; for ham groups only
                        (ham spam-use-bogofilter)    ; for ham groups only
                        (spam spam-use-bogofilter)))
         ; .... agent parameters ......
         (agent-predicate . true)
         (agent-score . file)
         ; - - agent score rule - -
         ; .... posting style .........
            (name priv-my-name)
            (address priv-my-sunoano1-mail-address)
            (signature-file (concat emacs-root-dir "gnus/sig/m.realname"))
            (mml2015-signers priv-my-keyid)
         ; .... group parameters ......
         (display . 20)
         ; .... local variables .......
;;;_         , only firstname
         ; .... spam rules ............
         (spam-contents gnus-group-spam-classification-ham)
         (spam-process-destination . "nnimap:m.junk")
         (spam-process ((spam spam-use-blacklist)
                        (ham spam-use-whitelist)     ; for ham groups only
                        (ham spam-use-bogofilter)    ; for ham groups only
                        (spam spam-use-bogofilter)))
         ; .... agent parameters ......
         (agent-predicate . true)
         (agent-score . file)
         ; - - agent score rule - -
         ; .... posting style .........
            (name priv-my-name)
            (address priv-my-gmail1-mail-address)
         ; .... group parameters ......
         (display . 20)
         ; .... local variables .......
;;;_        . suno ano
        (,priv-my-gmail2-mail-address-gp ; FIXME replace with priv-my-sunoano0-mail-address-gp once I have my own email system up and running
         ; .... spam rules ............
         (spam-contents gnus-group-spam-classification-ham)
         (spam-process-destination . "nnimap:m.junk")
         (spam-process ((spam spam-use-blacklist)
                        (ham spam-use-whitelist)     ; for ham groups only
                        (ham spam-use-bogofilter)    ; for ham groups only
                        (spam spam-use-bogofilter)))
         ; .... agent parameters ......
         (agent-predicate . true)
         (agent-score . file)
         ; - - agent score rule - -
         ; .... posting style .........
            (name priv-my-syn-name)
            (address priv-my-sunoano0-mail-address)
            (signature-file (concat emacs-root-dir "gnus/sig/m.suno"))
            (mml2015-signers priv-my-syn-keyid)
         ; .... group parameters ......
         (display . 20)
         ; .... local variables .......
;;;_       , domains
;;;_        . education
;;;_         , website
        (,priv-my-gmail4-mail-address-gp ; FIXME replace with priv-my-sunoano4-mail-address-gp once I have my own email system up and running
         ; .... spam rules ............
         (spam-contents gnus-group-spam-classification-ham)
         (spam-process-destination . "nnimap:m.junk")
         (spam-process ((spam spam-use-blacklist)
                        (ham spam-use-whitelist)     ; for ham groups only
                        (ham spam-use-bogofilter)    ; for ham groups only
                        (spam spam-use-bogofilter)))
         ; .... agent parameters ......
         (agent-predicate . true)
         (agent-score . file)
         ; - - agent score rule - -
         ; .... posting style .........
            (name priv-my-syn-name)
            (address priv-my-sunoano2-mail-address)
            (signature-file (concat emacs-root-dir "gnus/sig/m.suno"))
            (mml2015-signers priv-my-syn-keyid)
         ; .... group parameters ......
         (display . 20)
         ; .... local variables .......

;;;_         , tugraz
;;;         ("\\`nnml:m\\.do\\.tugraz"
;;;          ; .... spam rules ............
;;;          (spam-contents gnus-group-spam-classification-ham)
;;;          (spam-process-destination . "nnml:m.junk")
;;;          (spam-process ((spam spam-use-blacklist)
;;;                         (ham spam-use-whitelist)
;;;                         (ham spam-use-bogofilter)
;;;                         (spam spam-use-bogofilter)))
;;;          ; .... agent parameters ......
;;;          (agent-predicate . true)
;;;          (agent-score . file)
;;;          ; - - agent score rule - -
;;;          ; .... posting style .........
;;;          (posting-style
;;;             (name priv-my-name)
;;;             (address priv-my-tugraz-mail-address)
;;;             (signature-file (concat emacs-root-dir "gnus/sig/m.academia"))
;;;             (body (concat "\n\n"priv-my-firstname",\nwith fondest regards.\n"))
;;;          )
;;;          ; .... group parameters ......
;;;          (display . 20)
;;;          ; .... local variables .......
;;;         )
;;;_        . work
;;;_         , 1
         ; .... spam rules ............
         (spam-contents gnus-group-spam-classification-ham)
         (spam-process-destination . "nnml:m.junk")
         (spam-process ((spam spam-use-blacklist)
                        (ham spam-use-whitelist)
                        (ham spam-use-bogofilter)
                        (spam spam-use-bogofilter)))
         ; .... agent parameters ......
         (agent-predicate . true)
         (agent-score . file)
         ; - - agent score rule - -
         ; .... posting style .........
            (name priv-my-name)
            (address priv-my-work0-mail-address)
            (signature-file (concat emacs-root-dir "gnus/sig/m.work"))
            ;(body (concat "\n\n"priv-my-firstname",\nwith fondest regards.\n"))
         ; .... group parameters ......
         (display . 20)
         ; .... local variables .......
;;;_         , 2
;;;_       , default
; Note, those need be the last block within each group since they
; catch everything!

;;;               ("\\`nnml:m\\..*"
;;;                ; .... spam rules ............
;;;                (spam-contents gnus-group-spam-classification-ham)
;;;                (spam-process-destination . "nnml:m.junk")
;;;                (spam-process ((spam spam-use-blacklist)
;;;                               (ham spam-use-whitelist)
;;;                               (ham spam-use-bogofilter)
;;;                               (spam spam-use-bogofilter)))
;;;                ; .... agent parameters ......
;;;                (agent-predicate . true)
;;;                (agent-score . file)
;;;                ; - - agent score rule - -
;;;                ; .... posting style .........
;;;                (posting-style
;;;                   (name "NoName")
;;;                )
;;;                ; .... group parameters ......
;;;                (display . 15)
;;;                ; .... local variables .......
;;;               )
;;;_      . mailing lists
;;;_       , mailing lists default
; Note, those need be the last block within each group since they
; catch everything!

;;;               ("\\`nnml:ml\\..*"
;;;                 ; .... spam rules ............
;;;                 (spam-contents gnus-group-spam-classification-ham)
;;;                 (spam-process-destination . "nnml:m.junk")
;;;                 (spam-process ((spam spam-use-blacklist)
;;;                                (ham spam-use-whitelist)
;;;                                (ham spam-use-bogofilter)
;;;                                (spam spam-use-bogofilter)))
;;;                 ; .... agent parameters ......
;;;                 (agent-predicate or high short (not old))
;;;                 (agent-score . file)
;;;                 ; - - agent score rule - -
;;;                 ; .... posting style .........
;;;                 (posting-style
;;;                    (name priv-my-firstname)
;;;                    (address priv-my-gmail1-mail-address)
;;;                 )
;;;                 ; .... group parameters ......
;;;                 (display . [or (not killed) (not expire)])
;;;                 ; .... local variables ......
;;;                  (gnus-thread-sort-functions
;;;                 '(gnus-thread-sort-by-number
;;;                   gnus-thread-sort-by-date
;;;                   gnus-thread-sort-by-total-score))
;;;               )
;;;_      . news
;;;_       , gmane default
         ; .... spam rules ............
         (spam-contents gnus-group-spam-classification-ham)
         (spam-process-destination . "nnml:m.junk")
         (spam-process ((spam spam-use-gmane)
                        (spam spam-use-blacklist)
                        (ham spam-use-whitelist)
                        (ham spam-use-bogofilter)
                        (spam spam-use-bogofilter)))
         (spam-autodetect . t)
         (spam-autodetect-methods spam-use-BBDB          ;never mark incoming mail from folk in my BBDB as spam
                                  spam-use-whitelist     ;same as above but for sender addresses not in my BBDB
                                  spam-use-regex-headers ;server-side SpamAssassin tags
                                  spam-use-blacklist     ;sender addresses from spam declared messages
                                  spam-use-bogofilter)   ;therefore bogofilter needs to be installed
         ; .... agent parameters ......
         (agent-predicate or high short (not old))
         (agent-score . file)
         ; - - agent score rule - -
             ;("Mr. Foo Bar" 100 nil s)
             ("debian\\|emacs\\|linux\\|gnu\\|fsf" 100 nil s)
             ("Nose and Face" -100 nil s)
             ("debian\\|emacs\\|linux\\|gnu\\|fsf" 100 nil s)
           ; lower the score of articles that have been
           ; crossposted to >= 3 groups
             ("[^:\n]+:[0-9]+ +[^:\n]+:[0-9]+ +[^:\n]+:[0-9]+" -100 nil r)
         ; .... posting style .........
            (name priv-my-name)
            (address priv-my-sunoano1-mail-address)
         ; .... group parameters ......
         (display . 20)
         ; .... local variables .......
;;;_       , news groups default
; Note, those need be the last block within each group since they
; catch everything!

                ; .... spam rules ............
                (spam-contents gnus-group-spam-classification-ham)
                (spam-process-destination . "nnml:m.junk")
                (spam-process ((spam spam-use-blacklist)
                               (ham spam-use-whitelist)
                               (ham spam-use-bogofilter)
                               (spam spam-use-bogofilter)))
                ; .... agent parameters ......
                (agent-predicate and short (not old))
                (agent-score . file)
                ; - - agent score rule - -
                ; .... posting style .........
                   (name priv-my-name)
                   (address priv-my-sunoano1-mail-address)
                ; .... group parameters ......
                (display . 15)
                ; .... local variables .......
;;;_      . default
; Now, if no catch had happened before, this one catches ANYTHING from
; any backends and groups ...

           ; .... spam rules ............
           (spam-contents gnus-group-spam-classification-ham)
           (spam-process-destination . "nnml:m.junk")
           (spam-process ((spam spam-use-blacklist)
                          (ham spam-use-whitelist)
                          (ham spam-use-bogofilter)
                          (spam spam-use-bogofilter)))
           (spam-autodetect . t)
           (spam-autodetect-methods spam-use-BBDB          ;never mark incoming mail from folk in my BBDB as spam
                                    spam-use-whitelist     ;same as above but for sender addresses not in my BBDB
                                    spam-use-regex-headers ;server-side SpamAssassin tags
                                    spam-use-blacklist     ;sender addresses from spam declared messages
                                    spam-use-bogofilter)   ;therefore bogofilter needs to be installed
           ; .... agent parameters ......
           (agent-predicate or high short (not old))
           (agent-score . file)
           ; - - agent score rule - -
           ; .... posting style .........
              (name "NoName")
              (address "default_for_all@groups.org")
           ; .... group parameters ......
           (display . all)
           ; .... local variables .......
;;;_      . closing parenthesis
;;;_   , summary buffer

(setq gnus-summary-mode-line-format "Gnus: %G [%A] Score:%z ur+us:%Z")

(setq gnus-summary-line-format
   "%O :%U%R %B %s %-68=|%4L |%-20,20f |%&user-date; \n")

(setq gnus-thread-sort-functions
      '(gnus-thread-sort-by-number gnus-thread-sort-by-date))

(setq gnus-summary-display-while-building t)

(setq gnus-nov-is-evil t)

;;;_    . duplicate suppression

(setq gnus-suppress-duplicates t)
(setq gnus-duplicate-file (concat emacs-root-dir "gnus/News/suppression"))
(setq gnus-save-duplicate-list t)
(setq gnus-duplicate-list-length 2000)

;;;_    . after `g' in summary buffer show group buffer

;See (Info-goto-node "(gnus)Exiting the Summary Buffer")

(defun switch-window-show-group-buffer-with-point ()
    (other-window 1)
    (switch-to-buffer "*Group*")

(add-hook 'gnus-summary-exit-hook 'switch-window-show-group-buffer-with-point)

;;;_   , server buffer

(setq gnus-server-line-format "%s%8a{%(%h:%w%)}\n")

;;;_  . concerning >= 2 buffers at once

;;;_   , summary and article buffer

;;;_    . list identifiers

(setq gnus-list-identifiers
        "^ +"                            ;leading blanks
        "Changes committed *"
;;         "heimat123: "
;;         "heimat-dvd: "
;;         "\\[Pilotmgr\\]"
;;         "\\[Vaio-pcg-c1-general\\]"

;;;_ , mail and news

;;;_  . news, mail and mail2news gateways
;;;_   , misc
;;;_    . gnus-select-method
(setq gnus-select-method
      '(nntp "news.gnus.org"
        (nntp-connection-timeout 360)
        (nntp-open-connection-function nntp-open-network-stream)
        (nntp-address "news.gnus.org")

(setq gnus-secondary-select-methods '((nnimap "")))

;;;_    . newsgroup size

(setq gnus-large-newsgroup nil)

;;;_   , Gmane - mail2news gateway

;See (Info-goto-node "(gnus)Mail and Post")

;;;_   , archiving messages
(setq gnus-gcc-mark-as-read t)

;;;_    . set the back end

(setq gnus-message-archive-method
      '(nnml "archive"
                 (nnml-get-new-mail nil)
                 (nnml-inhibit-expiry t)

;;;_    . sort outgoing messages into archive groups

(setq gnus-message-archive-group
      '((if (message-news-p)

;;;_   , scoring

; All articles have a default score (`gnus-summary-default-score'),
; which is 0 by default.  This score may be raised or lowered either
; interactively or by score files.  Articles that have a score lower
; than `gnus-summary-mark-below' are marked as read.

; Gnus will read any "score files" that apply to the current group
; before generating the summary buffer.

  ; Note, auto-expiring and adaptive scoring doesn't really mix very
  ; well (see (Info-goto-node "(gnus)Adaptive Scoring") and
  ; (Info-goto-node "(gnus)Expiring Mail").

     ;If using adaptive scoring, then use it in conjunction
     ;with "total-expire" but NOT with "auto-expire".

     ;If you put `total-expire' in the group parameters,
     ;articles will not be marked as expirable, but all read
     ;articles will be put through the expiry process.

; I use adaptive scoring -- see (Info-goto-node "(gnus)Adaptive
; Scoring") as well as (Info-goto-node "(gnus)Score File Format")

  ; When you read an article, or mark an article as read, or kill an
  ; article, you leave marks behind.  On exit from the group, Gnus can
  ; sniff these marks and add score elements depending on what marks
  ; it finds.

(setq gnus-use-adaptive-scoring t)
(setq gnus-decay-scores t)

(setq gnus-default-adaptive-score-alist
    (gnus-ticked-mark (from 4))
    (gnus-dormant-mark (from 5))
    (gnus-del-mark (from -4) (subject -1))
    (gnus-read-mark (from 4) (subject 2))
    (gnus-expirable-mark (from -1) (subject -1))
    (gnus-killed-mark (from -1) (subject -3))
    (gnus-catchup-mark (from -1) (subject -1))

;; FIXME -- that stuff doesn't belong here. The question is, do I need
;; it at all?
;;     (mark 0)
;;     (expunge -100)
;;     (mark-and-expunge -200)
;;     (thread-mark-and-expunge -400)
;;     (read-only nil)

;;;_  . news only

(setq nntp-authinfo-file (concat emacs-root-dir "gnus/nntp_authinfo"))

;;;_   , get news

(add-to-list 'gnus-secondary-select-methods
      '(nntp "news.gmane.org"
        (nntp-connection-timeout 240)
        (nntp-open-connection-function nntp-open-network-stream)
        (nntp-address "news.gmane.org")

;;;_  . mail only

(setq nnimap-authinfo-file (concat emacs-root-dir "gnus/nnimap_authinfo"))

;;;_   , receive

;;;_    . pop server settings

;; (setq mail-sources `(
;;                      (pop :server     ,priv-pop-gmx-mail-server
;;                           :user       ,priv-gmx-mail-user
;;                           :password   ,priv-pop-gmx-password
;;                      )
;;                     )
;; )

;;;_    . imap server settings

;;;_     , gmail0

(add-to-list 'gnus-secondary-select-methods
               `(nnimap                ,priv-gmail0-mail-user
                  (nnimap-address      ,priv-imap-gmail-mail-server)
                  (nnimap-server-port  993)
                  (nnimap-stream       ssl)

;;;_     , gmail1

(add-to-list 'gnus-secondary-select-methods
               `(nnimap                ,priv-gmail1-mail-user
                  (nnimap-address      ,priv-imap-gmail-mail-server)
                  (nnimap-server-port  993)
                  (nnimap-stream       ssl)

;;;_     , gmail2

(add-to-list 'gnus-secondary-select-methods
               `(nnimap                ,priv-gmail2-mail-user
                  (nnimap-address      ,priv-imap-gmail-mail-server)
                  (nnimap-server-port  993)
                  (nnimap-stream       ssl)

;;;_     , gmail3

(add-to-list 'gnus-secondary-select-methods
               `(nnimap                ,priv-gmail3-mail-user
                  (nnimap-address      ,priv-imap-gmail-mail-server)
                  (nnimap-server-port  993)
                  (nnimap-stream       ssl)

;;;_     , gmail4

(add-to-list 'gnus-secondary-select-methods
               `(nnimap                ,priv-gmail4-mail-user
                  (nnimap-address      ,priv-imap-gmail-mail-server)
                  (nnimap-server-port  993)
                  (nnimap-stream       ssl)

;;;_    . nnmail - split mail

;;;_     , own function - create split based on string found in mail body

; U s a g e:
; but `(: split-on-body)' into `nnmail-split-fancy list' and fiddle on
; the string and group (function is parked here for later use ...)

;; (defun split-on-body ()
;;   (save-excursion
;;     (save-restriction
;;       (widen)
;;       (goto-char (point-min))
;;       (when (re-search-forward "Some.*string" nil t)
;;         "string.group"))))

;;;_     , code that does the splitting

(setq nnmail-message-id-cache-file (concat emacs-root-dir "gnus/nnmail_cache"))
(setq nnmail-message-id-cache-length 10000)
(setq nnmail-crosspost nil)
(setq nnmail-treat-duplicates 'warn)
(setq nnmail-cache-accepted-message-ids t)

(setq nnmail-split-fancy-with-parent-ignore-groups "")
(setq nnmail-cache-ignore-groups '(".*:out\\..*"))

(setq nnmail-split-methods 'nnmail-split-fancy)

;;;_      . nnmail-split-fancy

; The block below drives the whole shebang (i.e. rules to sort mail in
; groups plus spam checking for incoming mail - the more specific a
; rule is, the earlier it is listed - last one catches all)

; NOTE: nnmail-split-fancy != nnimap-split-fancy

(setq nnmail-split-fancy

;;;_       ,split current message into the same group as its parent

        ; Works among all back ends regardless of type --
        ; (gnus-registry needs to be loaded and initialized in order
        ; to make it available)
        (: gnus-registry-split-fancy-with-parent)

        ; Only cares about nnmail back ends
        ;(: nnmail-split-fancy-with-parent)

;;;_       ,spam execution

        (: spam-split 'spam-use-BBDB          ; 1)
                      'spam-use-whitelist     ; 2)
                      'spam-use-regex-headers ; 3)
                      'spam-use-blacklist     ; 4)
                      'spam-use-bogofilter)   ; 5)

; 1) never mark incoming mail from folk in my BBDB as spam
; 2) same as 1) but for sender addresses not in my BBDB
; 3) server-side e.g. SpamAssassin tags
; 4) sender addresses from spam declared messages
; 5) therefore bogofilter needs to be installed -- with DebianGNU/*
;    `apt-get install bogofilter' installs bogofilter

;;;_       , domains

;;;_        . tugraz
(any ,priv-split-regex-tugraz ,priv-split-group-tugraz)

;;;_        . work
(any ,priv-split-regex-work ,priv-split-group-work)

;;;_       , groups

;;;_        . family
(any ,priv-split-regex-helga0 ,priv-split-group-family)
(any ,priv-split-regex-mike0  ,priv-split-group-family)

;;;_       , people

;;;_        . suno ano
(any ,priv-split-regex-suno0 ,priv-split-group-suno)

;;;_        . myself (real name)
(any ,priv-split-regex-myself0 ,priv-split-group-myself)
(any ,priv-split-regex-myself1 ,priv-split-group-myself)
(any ,priv-split-regex-myself2 ,priv-split-group-myself)

;;;_       , mailing lists

; Well, now that I use Gmane those rules below are no more
; needed but I'll keep them since they cause no harm.

;; (any "debian-\\b\\(\\w+\\)@lists\\.debian\\.org" "ml.debian.\\1")

;; (any "vserver@list\\.linux-vserver\\.org" "ml.lvs")

;; (any "pnet-developers@dotgnu\\.org" "ml.DotGNU.devel")
;; (any "libjit-developers@dotgnu\\.org" "ml.DotGNU.libjit")
;; (any "phpgroupware-developers@gnu\\.org" "ml.DotGNU.phpgroupware")

;; (any "bugs@gnus.org" "ml.gnus.bugs")
;; (any "ding@gnus.org\\|ding-owner@lists.math.uh.edu
;;       \\|majordomo-owner@lists.math.uh.edu" "ml.gnus.development")

;; (any "muse-el-discuss.*@gna.org" "ml.muse.discussion")
;; (any "muse-el-commits.*@gna.org" "ml.muse.commits")

;; ;;;_       ,junk

;; This part is no more needed since it's done via spam settings

;;      (from ".*mailings@gmx\\.net" "m.junk")
;;      (from ".*gmx-gmbh.de" "m.junk")

;;;_       ,finally a group that catches all not matched before


;;;_      . nnimap-split-fancy

; NOTE: nnmail-split-fancy != nnimap-split-fancy

;;;_    . nnimap - split mail

;;;_    . Spam treatment

;;;_     ,

; Note, there are several ways how to cope with spam. I recommend
; reading the relevant parts within the gnus manual.

; - (Info-goto-node "(gnus)Thwarting Email Spam")
; - (Info-goto-node "(gnus)NoCeM")
; - (Info-goto-node "(gnus)Spam Package")


(setq spam-log-to-registry t)
(setq spam-mark-ham-unread-before-move-from-spam-group t)
(setq spam-mark-only-unseen-as-spam t)
(setq spam-autodetect-recheck-messages t)

(setq spam-split-group "m.junk") ;unqualified group name

;;;_     , bogofilter stuff

; See (Info-goto-node "(gnus)Bogofilter")

(setq spam-use-bogofilter t)

; Specifiy my own path for the bogofilter databasefile -- default would
; be `~/.bogofilter'
(setq spam-bogofilter-database-directory
      (concat emacs-root-dir "gnus/News/spam/bogofilter.db"))

;;;_   , send

;;;_    . server settings

;;;_     , gmail smtp

;   problem here is that when somebody sends mail to e.g.
;   foo@example.com and I reply, my reply address is always
;   priv-smtp2-username

(setq send-mail-function             'smtpmail-send-it
      message-send-mail-function     'smtpmail-send-it
      smtpmail-starttls-credentials  `((,priv-smtp2-mail-server ,priv-smtp2-port nil nil))
      smtpmail-auth-credentials      `((,priv-smtp2-mail-server ,priv-smtp2-port ,priv-smtp3-username ,priv-smtp3-pw))
      smtpmail-default-smtp-server   priv-smtp2-mail-server   ; needs to be before `(require 'smtpmail)'
      smtpmail-smtp-server           priv-smtp2-mail-server
      smtpmail-smtp-service          priv-smtp2-port
      smtpmail-local-domain          "sunoano.org")

;;;_     , smtp relay

;   here I had no problem as desribed with gmail's setting above

;; (setq send-mail-function 'smtpmail-send-it)
;; (setq message-send-mail-function 'smtpmail-send-it)

;; (setq smtpmail-smtp-service 587)

;; (setq smtpmail-default-smtp-server priv-smtp1-mail-server) ; needs to come before `(require 'smtpmail)'
;; (setq smtpmail-auth-credentials
;;         `((
;;            ,priv-smtp1-mail-server
;;            ,priv-smtp1-port
;;            ,priv-smtp1-username
;;            ,priv-smtp1-pw
;;          ))
;; )

;;;_     , general settings

;(setq smtpmail-debug-info t) ; needed only for debuging
(require 'smtpmail)
;(require 'starttls)
;(require 'nnimap)

;;;_    . composing/sending mail settings

;;;_     , line break

; when composing a mail, automatically make line brakes after 72 columns
(add-hook 'message-mode-hook
          (lambda ()
            (setq fill-column 72)

;;;_     , spelling (flyspell and gnus)

; Change the `ispell' dictionary based on what group you're in

; (add-hook 'gnus-select-group-hook
;           (lambda ()
;             (cond
;              ((string-match
;                "^de\\." (gnus-group-real-name gnus-newsgroup-name))
;               (ispell-change-dictionary "deutsch"))
;              (t
;               (ispell-change-dictionary "english")))))

;;;_     , posting styles

; Markus's posting styles are integrated into `gnus-parameters'. For
; more information see (Info-goto-node "(gnus)Posting Styles") and
; (Info-goto-node "(gnus)Group Parameters")

  ;;  From supercite manual section 7.1
  ;;    For this reason, Supercite recognizes a special mail header,
  ;; `X-Attribution:', which if present, tells Supercite the
  ;; attribution string preferred by the original author.  It is the
  ;; value of this header that is associated with the
  ;; `"x-attribution"' key in the attribution alist.  Currently, you
  ;; can override the preference of this key by changing
  ;; `sc-preferred-attribution-list', but that isn't polite, and in
  ;; the future Supercite may hard-code this.  For now, it is
  ;; suggested that if you change the order of the keys in this list,
  ;; that `"x-attribution"' always be first, or possible second behind
  ;; only `"sc-lastchoice"'.  This latter is the default.

;;;_. ERC

;; (require 'erc)

;; ;;;_ , Modules and their settings

;; ;;;_  . autojoin

;; (require 'erc-autojoin)

;; (erc-autojoin-mode 1)
;; (setq erc-autojoin-channels-alist
;;        '(("freenode.net"
;;                     "#emacs"
;;                     "#nethack")
;;          ("oftc.net"
;;                     "#bitlbee")
;;      )
;; )

;; (erc-select :server "irc.freenode.net"
;;          :port 6667
;;          :nick priv-nick-0
;;          :full-name priv-my-name
;; )

;; (erc-select :server "irc.oftc.net"
;;          :port 6667
;;          :nick priv-nick-0
;;          :full-name priv-my-name
;; )

;; ;;;_  . spelling

;;   (when  (require erc-spelling nil t)
;;     (add-hook 'erc-mode-hook
;;               (lambda ()
;;                 (erc-spelling-init (current-buffer))

;;                 ;; on some versions of Emacs, this function is already
;;                 ;; bound to this key ... but it doesn't hurt to be
;;                 ;; sure.
;;                 (local-set-key (kbd "M-TAB") 'flyspell-auto-correct-word)

;;                 )))

;; ; ------ third party examples Start ----------

;; ;;; erc is the emacs irc chat client-- waste time productively
;; (setq erc-server "irc.freenode.net"
;;        erc-port 6667
;;        erc-nick "meandtheshell"
;;        erc-user-full-name "Suno Ano"
;;        erc-public-away-p t;lets ppl know how long you were away
;;        erc-prompt-for-password nil)

;; ;; automatically join channels when we start-up
;; (require 'erc-autojoin) (erc-autojoin-mode 1)
;; (setq erc-autojoin-channels-alist
;;        '(("freenode.net" "#zsh" "#emacs" "#perl" "#web")))

;; ;; timestamp the conversations
;; (erc-timestamp-mode 1)

;; ;;; function that returns a random element when passed a list
;; ;;; Thanks to Riastradh
;; (defun random-choose (list)
;;   (nth (random (length list)) list))

;; (defun erc-cmd-LATER (&rest ignore)
;;   (interactive)
;;   (erc-cmd-QUIT (random-choose
;;                               '("...and miles to go before i sleep."
;;                                 "adieu..."
;;                                 "another long day's journey into night."))))

;; ;;; when erc buffer gets to 23,000 lines it's time to flush
;; ;;; kensanata
;; (defun erc-cmd-FLUSH (&rest ignore)
;;   "Erase the current buffer. When the ERC buffer has 23,000 lines it's time to flush!"
;;   (let ((inhibit-read-only t))
;;      (erase-buffer)
;;      t))

;; ;;; hilite occurences of my nick in the emacs modeline
;; (erc-match-mode 1)
;; (setq erc-keywords '("\\be1f\\b"))
;; ;(setq erc-current-nick-highlight-type 'nick)

;; ;;don't flood buffer with quit/joins when a netsplit happens
;; (require 'erc-netsplit)
;; (erc-netsplit-mode 1)

;; ;; split the window when we get a privmsg
;; (setq erc-auto-query 'window-noselect)

;; ;;; switch to next ERC buffer -kensanata
;; (defun switch-to-irc ()
;;   "Switch to an IRC buffer, or run `erc-select'.
;;     When called repeatedly, cycle through the buffers."
;;   (interactive)
;;   (let ((buffers (and (fboundp 'erc-buffer-list)
;;                                          (erc-buffer-list))))
;;      (when (eq (current-buffer) (car buffers))
;;          (bury-buffer)
;;                (setq buffers (cdr buffers)))
;;         (if buffers
;;             (switch-to-buffer (car buffers))
;;           (erc-select))))

;; (global-set-key (kbd "C-c b") 'switch-to-irc)

;; ; ------ third party examples End ----------

;;;_ Personal Information Management

;;;_. muse-mode

;;;_ , Load modules

; common basic modules
(require 'muse)
(require 'muse-mode)      ; load authoring mode
(require 'muse-project)   ; muse project maintainance
(require 'muse-colors)    ; load coloring/font-lock module
(require 'muse-wiki)      ; load Wiki support
;(require 'muse-http)      ; publish muse over http
(require 'muse-protocols) ; support for diffent protocols
(require 'muse-publish)   ;
(require 'muse-backlink)  ;

; publishing styles
(require 'muse-html)      ; html and xhtml
(require 'muse-latex)     ; propably the best if you're into maths
(require 'muse-latex2png) ; publish <latex> tags
(require 'muse-texinfo)   ; what FSF folks use - I simply love it!
(require 'muse-book)
(require 'muse-docbook)
(require 'muse-xml)
(require 'muse-journal)   ; for blogging

(setq muse-colors-inline-images nil)

;;;_  . Hooks with muse-mode

(add-hook 'muse-mode-hook 'turn-on-muse-list-edit-minor-mode)
(add-hook 'muse-mode-hook 'footnote-mode)
(add-hook 'muse-mode-hook (lambda () (abbrev-mode t)))
(add-hook 'muse-mode-hook (lambda () (auto-fill-mode 1)))
(add-hook 'muse-mode-hook (lambda () (flyspell-mode 1)))

;;;_ , Path settings

; Basically there are some groups of file-system paths one is
; confronted with - I'll assign those path to variables to ease
; coding/understanding and to get a more flexible code base.

; - local muse source
; - local published output styles e.g. html, pdf, etc.
; - additional stuff i.e. style sheets, images, documents (pdf), audio, etc.
; - remote directory/path (for uploading i.e. a httpd to serve content)

; Adapt all paths below to suit your setup ...

;;;_  . Miscellaneous

(setq the-authors-name priv-my-syn-name)     ;replace with your name

;;;_  . Project names

(setq planner-project "pim")
(setq website-project "ws")
(setq weblog-project  "blog")

;;;_  . Local muse source

; Planner, weblog and website, all are `.muse' files in the first place.

(setq muse-and-planner-root-dir (concat (getenv "HOME") "/0/0/"))

(setq website-dir (concat muse-and-planner-root-dir website-project "/"))    ;The Website
(setq weblog-dir  (concat muse-and-planner-root-dir weblog-project "/"))     ;The Weblog
(setq planner-dir (concat muse-and-planner-root-dir planner-project "/")) ;The PIM

; And finally the place where I work/edit the stuff on a daily basis
(setq website-local (concat website-dir "local/"))
(setq weblog-local  (concat weblog-dir  "local/"))
(setq planner-local (concat planner-dir "local/"))

;;;_  . Local published output e.g. html, pdf, etc.

; The `.muse' files got picked up for transforming them into various
; output formats.

;;;_   , Website

; The output formats I've chosen to create for all website related
; `.muse' files.

(setq website-public-docbook-dir (concat website-dir "public_docbook/"))
(setq website-public-latex-dir   (concat website-dir "public_latex/"))
(setq website-public-pdf-dir     (concat website-dir "public_pdf/"))
(setq website-public-texinfo-dir (concat website-dir "public_texinfo"))
;(setq website-public-xhtml-dir   (concat website-dir "public_xhtml/"))
(setq website-public-xhtml-dir   website-dir)
(setq website-public-xml-dir     (concat website-dir "public_xml/"))

;;;_   , Weblog

;(setq weblog-public-xhtml-dir (concat weblog-dir "public_xhtml/"))
(setq weblog-public-xhtml-dir weblog-dir)
;(setq weblog-public-rss-dir   (concat weblog-dir "public_rss/"))
(setq weblog-public-rss-dir   weblog-dir)

;;;_   , Planner

; See (Info-goto-node "(planner-el)Top")

(setq planner-public-pdf-dir   (concat planner-dir "public_pdf/"))
;(setq planner-public-xhtml-dir (concat planner-dir "public_xhtml/"))
(setq planner-public-xhtml-dir planner-dir)
(setq planner-public-xml-dir   (concat planner-dir "public_xml/"))
(setq planner-public-rss-dir   (concat planner-dir "public_rss/"))

;;;_  . Style sheet and images

; I decided to have separate directories
;(setq style-sheet-dir         (concat muse-and-planner-root-dir "misc/css/"))
;(setq website-image-dir       (concat muse-and-planner-root-dir "misc/mm/si/"))
;(setq website-video-dir       (concat muse-and-planner-root-dir "misc/mm/di/"))
;(setq website-audio-dir       (concat muse-and-planner-root-dir "misc/mm/audio/"))
;(setq website-documents-dir   (concat muse-and-planner-root-dir "misc/mm/documents/")) ;my manual, books, etc.

(setq style-sheet-dir         "/misc/css/")
(setq website-image-dir       "/misc/mm/si/")
(setq website-video-dir       "/misc/mm/di/")
(setq website-audio-dir       "/misc/mm/audio/")
(setq website-documents-dir   "/misc/mm/documents/") ;my manual, books, etc.

;;;_   , Style sheets

; Some particular style sheets
(setq default-style-sheet (concat style-sheet-dir "default.css"))

;;;_   , Images

; Directory settings
(setq website-image-components-dir (concat website-image-dir "components/"))
(setq website-image-content-dir    (concat website-image-dir "content/"))
(setq website-favicon-dir          (concat website-image-components-dir "favicon/"))

; Particular images
(setq backlink-arrow-image      (concat website-image-components-dir "list_item.gif"))
;(setq website-favicon-ico-image (concat website-favicon-dir "favicon_pink_sa.ico"))
;(setq website-favicon-ico-image (concat website-favicon-dir "favicon_pink_mg.ico"))
(setq website-favicon-ico-image (concat website-favicon-dir "favicon_grey.ico"))
(setq website-favicon-gif-image (concat website-favicon-dir "animated_favicon.gif"))

;;;_   , Video

;;;_   , Audio

;;;_   , Documents

;;;_  . Remote directory/path (upload things i.e. a httpd to serve content)

; Just replace to fit your webroot accordingly
(setq remote-root-no-protocol-prefix "www.markus-gattol.name")
(setq remote-http-root    (concat "http://" remote-root-no-protocol-prefix ))
(setq remote-ftp-root     (concat "ftp://"  remote-root-no-protocol-prefix ))

;;;_ , Functions

;;;_  . Composing the site

;;;_   , my-muse-index-as-string-{whitelist,blacklist}

; While muse-index-as-string returns all muse pages, those are either
; returning only pages matching a particular regex (whitelist) or all
; pages not matching a particular regex (blacklist) i.e. excluding
; those pages who match the regex. Below is an example of how to use it:

;;; <markup>
;;; <lisp>(my-muse-index-as-string-whitelist "debian" t)</lisp></markup>

(defun my-muse-index-as-string-whitelist (&optional filter as-list exclude-private exclude-current)
  "Generate an index of all Muse pages matching FILTER i.e whitelisting.
FILTER is a string resp. regex.
If AS-LIST is non-nil, insert a dash and spaces before each item.
If EXCLUDE-PRIVATE is non-nil, exclude files that have private permissions.
If EXCLUDE-CURRENT is non-nil, exclude the current file from the output.

Example of how to use it within muse source code (toggle
fontlocking with C-c C-l):

<lisp>(my-muse-index-as-string-whitelist \"debian\" t)</lisp></markup>
  (let ((files (sort (copy-alist (muse-project-file-alist))
                      (lambda (l r)
                        (string-lessp (car l) (car r)))))))

    (setq files (remove-if-not
                            (lambda (conn)
                              (string-match filter (car conn)))

    (when (and exclude-current (muse-page-name))
      (setq files (delete (assoc (muse-page-name) files) files)))
      (while files
        (unless (and exclude-private
                     (muse-project-private-p (cdar files)))
          (insert (if as-list " - " "") "[[" (caar files) "]]\n"))
        (setq files (cdr files)))

(defun my-muse-index-as-string-blacklist (&optional filter as-list exclude-private exclude-current)
  "Generate an index of all Muse pages not matching FILTER i.e blacklisting.
FILTER is a string resp. regex.
If AS-LIST is non-nil, insert a dash and spaces before each item.
If EXCLUDE-PRIVATE is non-nil, exclude files that have private permissions.
If EXCLUDE-CURRENT is non-nil, exclude the current file from the output.

Example of how to use it within muse source code (toggle
fontlocking with C-c C-l):

<lisp>(my-muse-index-as-string-whitelist \"debian\" t)</lisp></markup>
  (let ((files (sort (copy-alist (muse-project-file-alist))
                      (lambda (l r)
                        (string-lessp (car l) (car r)))))))

    (setq files (remove-if
                            (lambda (conn)
                              (string-match filter (car conn)))

    (when (and exclude-current (muse-page-name))
      (setq files (delete (assoc (muse-page-name) files) files)))
      (while files
        (unless (and exclude-private
                     (muse-project-private-p (cdar files)))
          (insert (if as-list " - " "") "[[" (caar files) "]]\n"))
        (setq files (cdr files)))

;;;_   , Insert tags e.g. `<verse>', `<example>', etc.

;;;_    . Insert `<math>' tags

(defun muse-insert-math-tags ()  (interactive)
"This function inserts example tags i.e.<math> followed by
 (insert "<math>\\scriptscriptstyle</math>")

;;;_    . Insert `<verse>' tags

(defun muse-insert-verse-tags ()  (interactive)
"This function inserts example tags i.e.<verse> followed by
 (insert "<verse>\n**\n</verse>")

;;;_    . Insert `<exmample>' tags

(defun muse-insert-example-tags ()  (interactive)
"This function inserts example tags i.e.<example> followed by
 (insert "<example>\n</example>")

;;;_    . Insert `<code>' tags

(defun muse-insert-code-tags ()  (interactive)
"This function inserts code tags i.e.<code> followed by
 (insert "<code></code>")

;;;_    . Insert `<comment>' tags

(defun muse-insert-comment-tags ()  (interactive)
"This function inserts comment tags i.e.<comment> followed by
 (insert "<comment>\n</comment>")

;;;_    . Insert `<lisp>' tags

(defun muse-insert-lisp-tags ()  (interactive)
"This function inserts lisp tags i.e.<lisp> followed by
 (insert "<lisp>\n</lisp") ;the lack of `>' is to avoid interpretation

;;;_    . Insert `<python>' tags

(defun muse-insert-python-tags ()  (interactive)
"This function inserts python tags i.e.<python> followed by
 (insert "<python>\n</python>")

;;;_    . Insert `<src>' tags for different programming modes

;;;_     , emacs-lisp

(defun muse-insert-src-emacs-lisp-tags ()  (interactive)
"This function inserts src tags i.e.<src \"emacs-lisp\"> followed
by </src>"
 (insert "<src \"emacs-lisp\">\n</src>")

;;;_   , Insert blank lines into xhtml output

(defun muse-html-insert-blank-line () (interactive)
"Insert a blank line in order to create a blank line in html and
xhtml output."
        (insert "<br>\n"))

;;;_   , Insert source of quotation

(defun muse-insert-quotation-source-wikipedia ()  (interactive)
"This function inserts `(Wikipedia)' into muse source code in
order to rightfully  reefer to the quoted source."
 (insert "*([[http://en.wikipedia.org/wiki/Main_Page][Wikipedia]])*")

(defun muse-insert-quotation-source-urbandictionary ()  (interactive)
"This function inserts `(The Urban Dictionary)' into muse source
code in order to rightfully reefer to the quoted source."
 (insert "*([[http://www.urbandictionary.com/][The Urban Dictionary]])*")

;;;_    . The freedictionary and its subdictionaries

(defun muse-insert-quotation-source-freedictionary ()  (interactive)
"This function inserts `(The Free Dictionary)' into muse source
code in order to rightfully reefer to the quoted source."
 (insert "*([[http://www.thefreedictionary.com/][The Free Dictionary]])*")

(defun muse-insert-quotation-source-free-computing-dictionary ()  (interactive)
"This function inserts `(The Free Computing Dictionary)' into
muse source code in order to rightfully reefer to the quoted
 (insert "*([[http://computing-dictionary.thefreedictionary.com][The Free Computing Dictionary]])*")

;;;_   , Creating the menu for the website

(defun muse-xhtml-menu (items)
  "This function makes use of muse-project-menu-list. It is
  intended to create the menu for the website."
  (concat "<div class=\"menu\">"
          "<div class=\"menuhead\">Website Sections</div>"
          "<div class=\"menubody\">"
          (mapconcat (function (lambda (item)
                               (concat "<div class=\"menuitem\">\n"
                                                   (cadr (cdr item))
                                                   "<a href=\""
                                                   (cadr item)
                                                   (car item)

;;;_   , Content listing

(defun muse-publish-content ()
"This function creates a list of contents with regards to the
current page. Also, it is possible to specify the
contentdepth. The contentdepth directive needs to be present in
the header section of a page for the content listing to be
displayed. The numeric parameter specifies to which depth the
content listing should be generated. 1 will only include the
top-level headlines while 2, 3 etc. will include the
corresponding lower levels."
  (let ((depths (muse-publishing-directive "contentdepth")))
    (when depths
      (let ((depth (string-to-number depths)))
        (when (not (eq depth 0))
          (insert "<td class='contents'>
                       <div class='contenthead'>Table of Contents</div>
                       <div class='contentbody'>")
          (my-muse-html-insert-contents depth)
          (unless (eobp) (forward-char))
          (insert "</div></td>"))))))

; `muse-html-insert-contents' has been renamed into
; `my-muse-html-insert-contents' and modified to fit my needs. The
; modification is tiny I just needed to replace `"<dt>\n"' by `"<dt
; class=\"contents\">\n"' in order to play well with my CSS

(defun my-muse-html-insert-contents (depth)
  "Scan the current document and generate a table of contents at point.
DEPTH indicates how many levels of headings to include.  The default is 2."
  (let ((max-depth (or depth 2))
        (index 1)
        base contents l end)
      (goto-char (point-min))
      (search-forward "Page published by Emacs Muse begins here" nil t)
      (catch 'done
        (while (re-search-forward "<h\\([0-9]+\\)>\\(.+?\\)</h\\1>$" nil t)
          (unless (and (get-text-property (point) 'read-only)
                       (not (get-text-property (match-beginning 0)
            (remove-text-properties (match-beginning 0) (match-end 0)
                                    '(muse-contents nil))
            (setq l (1- (string-to-number (match-string 1))))
            (if (null base)
                (setq base l)
              (if (< l base)
                  (throw 'done t)))
            (when (<= l max-depth)
              ;; escape specials now before copying the text, so that we
              ;; can deal sanely with both emphasis in titles and
              ;; special characters
              (goto-char (match-end 2))
              (setq end (point-marker))
              (muse-publish-escape-specials (match-beginning 2) end
                                            nil 'document)
              (muse-publish-mark-read-only (match-beginning 2) end)
              (setq contents (cons (cons l (buffer-substring-no-properties
                                            (match-beginning 2) end))
              (set-marker end nil)
              (goto-char (match-beginning 2))
              (muse-html-insert-anchor (concat "sec" (int-to-string index)))
              (setq index (1+ index)))))))
    (setq index 1 contents (nreverse contents))
    (let ((depth 1) (sub-open 0) (p (point)))
      (muse-insert-markup "<div class=\"contents\">\n<dl>\n")
      (while contents
        (muse-insert-markup "<dt class=\"contents\">\n"
                            "<a href=\"#sec" (int-to-string index) "\">"
                            (muse-html-strip-links (cdar contents))
        (setq index (1+ index)
              depth (caar contents)
              contents (cdr contents))
        (when contents
           ((< (caar contents) depth)
            (let ((idx (caar contents)))
              (while (< idx depth)
                (muse-insert-markup "</dl>\n</dd>\n")
                (setq sub-open (1- sub-open)
                      idx (1+ idx)))))
           ((> (caar contents) depth) ; can't jump more than one ahead
            (muse-insert-markup "<dd>\n<dl>\n")
            (setq sub-open (1+ sub-open))))))
      (while (> sub-open 0)
        (muse-insert-markup "</dl>\n</dd>\n")
        (setq sub-open (1- sub-open)))
      (muse-insert-markup "</dl>\n</div>\n")
      (muse-publish-mark-read-only p (point)))))

;;;_   , Page status

(defun muse-publish-status ()
"Display a small note about the status of the page."
  (let ((status  (muse-publishing-directive "status")))
    (when status
      (let ((tmp (split-string status "|")))
        (concat "<div class='status"(pop tmp)"'>Status: "(pop tmp)"</div>")

;;;_   , Pagecode

(defun muse-publish-pagecode ()
"Display a small note about the pagecode of the page."
  (let ((pagecode  (muse-publishing-directive "pagecode")))
    (when pagecode
        (concat "Pagecode: "pagecode)

;;;_  . Publishing

;;;_   , Turning relative links into absolute ones

; See http://www.mwolson.org/projects/emacs-config/muse-init.el.html
; for more information.

;;; (defun my-muse-pdf-make-links-absolute (str &rest ignored)
;;;   "Make relative links absolute."
;;;   (when str
;;;     (save-match-data
;;;       (if (string-match "\\`[/.]+" str)
;;;           (replace-match "http://www.mwolson.org/" nil t str)
;;;         str
;;;       )
;;;     )
;;;   )
;;; )

;;;_ , Create and manage muse projects

;;;_  . Editing

;;;_   , headings

(setq muse-colors-autogen-headings nil)

; Because I am to nerdy, header faces have been set with customize
; -- therefore they are stored at the bottom of this file in
;    `custom-set-faces'

;;;_   , tags

;;;_    . comment tags

(defface muse-comment
  '((((class color) (background light))
     (:foreground "firebrick"))
    (((class color) (background dark))
     (:foreground "DeepPink4")))
  "Face for comment text."
  :group 'muse-colors

(defun muse-colors-comment-tag (beg end)
  "Strip properties and colorize with `muse-comment'."
  (muse-unhighlight-region beg end)
  (let ((multi (save-excursion
                 (goto-char beg)
                 (forward-line 1)
                 (> end (point)))))
    (add-text-properties beg end `(face muse-comment
                                   font-lock-multiline ,multi)))

(add-to-list 'muse-colors-tags
             '("comment"  t nil nil muse-colors-comment-tag) t)

;;;_    . verse tags

(defface muse-verse
  '((((class color) (background light))
     (:foreground "peru" :italic t))
    (((class color) (background dark))
     (:foreground "DeepPink4")))
  "Face for verse text."
  :group 'muse-colors

(defun muse-colors-verse-tag (beg end)
  "Strip properties and colorize with `muse-verse'."
  (muse-unhighlight-region beg end)
  (let ((multi (save-excursion
                 (goto-char beg)
                 (forward-line 1)
                 (> end (point)))))
    (add-text-properties beg end `(face muse-verse
                                   font-lock-multiline ,multi)))

(add-to-list 'muse-colors-tags
             '("verse"  t nil nil muse-colors-verse-tag) t)

;;;_    . math tags

(defface muse-math
  '((((class color) (background light))
     (:foreground "cyan4"))
    (((class color) (background dark))
     (:foreground "DeepPink4")))
  "Face for math text."
  :group 'muse-colors

(defun muse-colors-math-tag (beg end)
  "Strip properties and colorize with `muse-math'."
  (muse-unhighlight-region beg end)
  (let ((multi (save-excursion
                 (goto-char beg)
                 (forward-line 1)
                 (> end (point)))))
    (add-text-properties beg end `(face muse-math
                                   font-lock-multiline ,multi)))

(add-to-list 'muse-colors-tags
             '("math"  t nil nil muse-colors-math-tag) t)

;;;_   , Wiki settings

(setq muse-wiki-ignore-bare-project-names t)

;; (setq muse-wiki-interwiki-alist
;;       '(("PlugWiki" . "http://purduelug.org/wiki/")
;;         ("EmacsWiki" . "http://www.emacswiki.org/cgi-bin/wiki/")
;;         ("ArchWiki" . "http://gnuarch.org/gnuarchwiki/")
;;         ;; abbreviations
;;         ("CERIAS" . "http://www.cerias.purdue.edu/")
;;         ("PlannerMode" . "http://www.emacswiki.org/cgi-bin/wiki/PlannerMode")
;;         ("RememberMode" . "http://www.emacswiki.org/cgi-bin/wiki/RememberMode")
;;         ("GP2X" . "http://www.gp2x.co.uk/")
;;         ("UbuntuLinux" . "http://ubuntulinux.org/")
;;         ("PLUG" . "http://purduelug.org/")
;;         ("PAC" . "http://web.ics.purdue.edu/~pac/")))

;;;_  . Manage

;;;_   , muse-project-alist

(setq muse-project-alist

          :default "index"
          :base "html"
          :path "/home/sa/misc/hi/pci/"
;;         (
;;           :base "latex"
;;           :path ,website-public-latex-dir
;;         )
;;         (
;;        :base "texinfo"
;;        :path ,website-public-texinfo-dir
;;      )
;;         (
;;           :base "docbook"
;;           :path ,website-public-docbook-dir
;;         )
;;         (
;;           :base "xml"
;;           :path ,website-public-xml-dir
;;         )
;;         (
;;           :base "pdf"
;;           :path ,website-public-pdf-dir
;;         )

;;;_    . Website

          :default "index"
          :base "xhtml"
          :path ,website-public-xhtml-dir
;;         (
;;           :base "latex"
;;           :path ,website-public-latex-dir
;;         )
;;         (
;;        :base "texinfo"
;;        :path ,website-public-texinfo-dir
;;      )
;;         (
;;           :base "docbook"
;;           :path ,website-public-docbook-dir
;;         )
;;         (
;;           :base "xml"
;;           :path ,website-public-xml-dir
;;         )
;;         (
;;           :base "pdf"
;;           :path ,website-public-pdf-dir
;;         )

;;;_    . Blog

; There's another example at
; http://www.mwolson.org/projects/emacs-config/muse-init.el.html

          ,@(muse-project-alist-dirs weblog-local)
          :default "journal"

        ,@(muse-project-alist-styles weblog-local            ;Source dir
                                     weblog-public-xhtml-dir ;Output dir
                                     "journal-xhtml")        ;Publishing Style

        ,@(muse-project-alist-styles weblog-local          ;Source dir
                                     weblog-public-rss-dir ;Output dir
                                     "journal-rss")        ;Publishing Style

; `muse-project-alist-dirs' means publish this directory and its
; subdirectories. Arguments are as follows. The
; `muse-project-alist-dirs' part is also needed, using Argument 1.
;  1. Source directory
;  2. Output directory
;  3. Publishing style

;;;_    . Planner

; :default, :major-mode; :visit-link etc. are so called
; *keyword symbols* see (Info-goto-node "(elisp)Symbol Type")

          :default "taskpool"
          :major-mode planner-mode
          :visit-link planner-visit-link
;;      (
;;        :base "planner-pdf"
;;        :path ,planner-public-pdf-dir
;;      )
          :base "planner-xhtml"
          :path ,planner-public-xhtml-dir
;;;         (
;;;           :base "planner-xml"
;;;           :path ,planner-public-xml-dir
;;;         )

;;;_    . closing parenthesis


;;;_  . Publishing

; See (Info-goto-node "(muse)Publishing Styles")

;;;_   , Website

;;;_    . Components for either Header or Footer

; A listing of all components (without specific order) later to be
; included into either header or footer.

;;;_     , Favicon

(setq website-favicon-image
"<link rel=\"shortcut icon\" href=\"<lisp>website-favicon-ico-image</lisp>\"/>"

;Put the below line into `website-favicon-image' as the second of two
;lines (first one is already in place) in order to get an animated
;favicon if you want something really annoying :)

;<link rel=\"icon\" href=\"<lisp>website-favicon-gif-image</lisp>\" type=\"image/gif\" >

;;;_     , Charset

(setq muse-html-charset-default "utf-8"
      muse-html-encoding-default 'utf-8)

;;;_     , Doc type

(setq muse-xhtml-doctype
"<?xml version=\"1.0 encoding=\"<lisp>(muse-html-encoding)</lisp> \"?>

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"

;;;_     , Style sheet

(setq muse-xhtml-style-sheet
         "<link rel=\"stylesheet\"
                href=\"<lisp>default-style-sheet</lisp>\" />"

;;;_     , Menu

; Use this variable to create the menu items

;(setq website-public-xhtml-dir-short "/ws/public_xhtml/")
(setq website-public-xhtml-dir-short "/ws/")
(setq muse-project-menu-list
    ("Home"                 ,(concat website-public-xhtml-dir-short "home.html") "")
    ("FAQs"                 ,(concat website-public-xhtml-dir-short "faq.html") "")
    ;("About this Site"      ,(concat website-public-xhtml-dir-short "about_this_site.html") "")
    ;("Hints / Ads"          ,(concat website-public-xhtml-dir-short "advertisements.html") "")
    ("About Me"             ,(concat website-public-xhtml-dir-short "about_me.html") "")
    ("Weblog"               ,(concat website-public-xhtml-dir-short "weblog.html") "")
    ("Photo Albums"         "/albums/index.html" "")
    ;("Contact"              ,(concat website-public-xhtml-dir-short "contact.html") "")
    ;("RSS"           ,,(concat base-dir "/tools/rss.html")
    ;                 ,,(concat "<img src=\"" base-dir "/base/images/xml.png\" />&nbsp;"))

;;;_     , Licence

; Let folks know about their rights and duties

; The content of my website has to be licenced as well as the code
; needs to be covered by a licence. So I've chosen:

; c o n t e n t:
; Creative Commons Attribution-Share Alike 3.0 License

; c o d e:

(setq muse-xhtml-license
"<!-- Creative Commons Licence -->
<div id=\"license\">
  <div id=\"licenseim\">
    <a rel=\"license\"
      alt=\"Creative Commons License\" border=\"0\" />
  <div id=\"licensetx\">
    The content of this site is licensed under
    <a rel=\"license\"
    Creative Commons Attribution-Share Alike 3.0 License</a>.
<!-- /Creative Commons Licence  -->


<rdf:RDF xmlns=\"http://web.resource.org/cc/\"
<Work rdf:about=\"\">
   <dc:title>Never Ending Science</dc:title>
   <dc:description>Markus Gattol's Weblog</dc:description>
   <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/Text\" />
   <dc:source rdf:resource=\"<lisp>remote-http-root</lisp>/\"/>
   <license rdf:resource=\"http://creativecommons.org/licenses/by-sa/3.0/\" />

<License rdf:about=\"http://creativecommons.org/licenses/by-sa/3.0/\">
   <permits rdf:resource=\"http://web.resource.org/cc/Reproduction\" />
   <permits rdf:resource=\"http://web.resource.org/cc/Distribution\" />
   <requires rdf:resource=\"http://web.resource.org/cc/Notice\" />
   <requires rdf:resource=\"http://web.resource.org/cc/Attribution\" />
   <permits rdf:resource=\"http://web.resource.org/cc/DerivativeWorks\" />
   <requires rdf:resource=\"http://web.resource.org/cc/ShareAlike\" />



;;;_    . Header/Footer

;;;_     , Website specific header/footer

;;;_      . Website XHTML Header

;;;_       , <head></head> section of the Website XHTML Header

(setq muse-html-meta-content-type "application/xhtml+xml")

(setq muse-xhtml-head

    <title><lisp>(muse-publishing-directive \"title\")</lisp></title>

    <meta name=\"generator\" content=\"muse.el\" />

    <meta http-equiv=\"<lisp>muse-html-meta-http-equiv</lisp>\"
          content=\"<lisp>muse-html-meta-content-type</lisp>\" />

      (let ((maintainer (muse-style-element :maintainer)))
        (when maintainer
          (concat \"<link rev=\\\"made\\\" href=\\\"\" maintainer \"\\\" />\")))



<script type=\"text/javascript\">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-17869550-1']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);



;;;_       , <body></body> section of the Website XHTML Header

(setq muse-xhtml-headline
"<div id=\"sunoheader\">
  <div id=\"sunoheadertop\">

    <div id=\"sunoheadertitle\">
      <img id=\"sunotitleimg\"
           src=\"/misc/mm/si/components/me_thumb.jpg\" />

    <div id=\"sunoheadertext\">
      <div id=\"sunoheadeng\">
                Connector, geek, investor, agnostic, sportsman, libertarian, business enabler, globetrotter, <a href=\"/ws/business_global.html\">cosmopolitan</a>, autodidact, funny finch, tech evangelist,<br/>
                socially liberal but fiscally conservative, innovator, artist, software developer, Schöngeist ... elegantiorum litterarum amans oder studiosus ...<br/><br/>
                This is the website of Markus Gattol.
                It is composed, driven and <a href=\"/ws/debian_security.html\">secured</a>/<a href=\"/ws/dm-crypt_luks.html\">encrypted</a> exclusively by Open Source Software.
                The speciality of this<br/> website is that it is seamlessly integrating into my daily working environment (<a href=\"/ws/python.html\">Python</a> + <a href=\"/ws/mongodb.html\">MongoDB</a> + <a href=\"/ws/debian_notes_cheat_sheets.html\">Linux</a> + <a href=\"/ws/ssh.html\">SSH</a> + <a href=\"/ws/scm.html\">GIT</a>)
                which therefore means<br/> it becomes a fully fledged and automatized publishing and communication platform. It will be under construction until 2014.<br/><br/>
                <a href=\"http://en.wikipedia.org/wiki/Free-software\">Open Source / Free Software</a>, because freedom is in everyone's language ...<br/>Frihed Svoboda Libertà Vrijheid เสรีภาพ Liberté Freiheit Cê̤ṳ-iù Ελευθερία Свобода חרות Bebas Libertada 自由

    <div id=\"sunoheaderbottom\">
        <img id=\"sunoheadimg\"
             src=\"/misc/mm/si/components/line_grey.png\" />


;;;_       , Finally the Header as it is to be included into XHTML output

; Finnally, merging the above bits together All elements described in
; the previous section are brought together in a header and a footer
; that surrounds the page content.

(setq muse-xhtml-header
<html xmlns=\"http://www.w3.org/1999/xhtml\">

    <div id=\"header\">


    <table id=\"body\"><tr valign=\"top\">
      <td id=\"left\">
        <lisp>(muse-xhtml-menu muse-project-menu-list)</lisp>
      <td id=\"content\">
    <table class=\"headline\">
        <tr class=\"headline\">
          <td class=\"leftheadline\">
            <div class=\"info\">
              <div class=\"title\">
                <lisp>(muse-publishing-directive \"title\")</lisp>
              <div class=\"status\">
              <div class=\"pagecode\">
              <div class=\"lastchange\">
                Last changed: <lisp>(my-date-insert-3)</lisp>
              <div class=\"about\">
                <strong>Abstract:</strong><br /><hr />
                <lisp>(muse-publishing-directive \"about\")</lisp>
    <!-- Page -->\n"

;;;_      . Website XHTML Footer

(setq muse-xhtml-footer
"<!-- End of page -->\n
    <div id=\"footer\">

;;;_     , Weblog specific header/footer

;;;_   , Planner

;;;_    . Components for either Header or Footer

;;;_     , Planner specific header/footer

;;;_      . planner-xhtml-header

;; `planner-xhtml-header'
;;      Header used when publishing Planner XHTML files.  This may be text
;;      or a filename.

(setq planner-xhtml-header
<html xmlns=\"http://www.w3.org/1999/xhtml\">

    <div id=\"header\">


    <table id=\"body\"><tr valign=\"top\">
      <td id=\"left\">
        <lisp>(muse-xhtml-menu muse-project-menu-list)</lisp>
      <td id=\"content\">
    <table class=\"headline\">
        <tr class=\"headline\">
          <td class=\"leftheadline\">
            <div class=\"info\">
              <div class=\"title\">
                <lisp>(muse-publishing-directive \"title\")</lisp>
              <div class=\"status\">
              <div class=\"lastchange\">
                Last changed: <lisp>(my-date-insert-3)</lisp>
    <!-- Page -->\n"

;;;_      . planner-xhtml-footer

;; `planner-xhtml-footer'
;;      Footer used when publishing Planner XHTML files.  This may be text
;;      or a filename.

(setq planner-xhtml-footer
"<!-- End of page -->
    <div id=\"footer\">

;; `planner-html-inner-header'
;;      Extra header section that can be embedded within
;;      `planner-html-header' and `planner-xhtml-header'.

;; `planner-html-inner-footer'
;;      Extra header section that can be embedded within
;;      `planner-html-footer' and `planner-xhtml-footer'.

;;;_   , Journal

;;;_    . Components for either Header or Footer

;;;_. journal

(setq muse-journal-date-format "%A, %Y-%m-%d ")
(setq muse-journal-rss-base-url (concat remote-http-root "/blog/"))

;;; (setq muse-journal-rss-enclosure-types-alist
;;;         '(
;;;       ("mp3" . "audio/mpeg")
;;;       ("jpeg" . "image/jpeg")
;;;       ("png" . "image/png")
;;;      )
;;; )

(setq muse-journal-html-entry-template
"<div class=\"entry\">
  <a name=\"%anchor%\" style=\"text-decoration: none\">&nbsp;</a>
  <div class=\"entry-body\">
    <div class=\"entry-head\">
      <div class=\"entry-date\">
        <span class=\"date\">%date%</span>
      <div class=\"entry-title\">
    <div class=\"entry-text\">

; FIXME - remove at some point when sure it may never be needed
; original below
;;; (setq muse-journal-html-entry-template
;;; "<div class=\"entry\">
;;;   <a name=\"%anchor%\" style=\"text-decoration: none\">&nbsp;</a>
;;;   <div class=\"entry-body\">
;;;     <div class=\"entry-head\">
;;;       <div class=\"entry-date\">
;;;         <span class=\"date\">%date%</span>
;;;       </div>
;;;       <div class=\"entry-title\">
;;;         <h2>%title%</h2>
;;;       </div>
;;;     </div>
;;;     <div class=\"entry-text\">
;;;       <div class=\"entry-qotd\">
;;;         <p>%qotd%</p>
;;;       </div>
;;;         %text%
;;;     </div>
;;;   </div>
;;; </div>\n\n"
;;; )

;;;_. planner-remember resp. remember-mode

(require 'remember-planner)
(add-hook 'remember-mode-hook (lambda () (abbrev-mode t)))

;;;             'flyspell-mode
;;;             'turn-on-auto-fill

;;Use BBDB to complete names and addresses
(setq remember-handler-functions '(remember-planner-append))
(setq remember-annotation-functions planner-annotation-functions)

;;;_. planner-mode

;;;_ , planner generell

(require 'planner)
;(setq planner-project "my_planner") <-- already set - see above

; See (Info-goto-node "(muse)Projects") for (setq muse-project-alist
; ...) which contains the project management part for planner.

;;publish files automatically when I save them
;;      (eval-after-load "muse-mode"
;;        (add-hook 'after-save-hook
;;                  #'(lambda ()
;;                      (when (planner-derived-mode-p 'muse-mode)
;;                        (muse-project-publish nil)))
;;                  nil t))

(setq planner-carry-tasks-forward 0)
(setq planner-renumber-notes-automatically t)
(add-hook 'planner-mode-hook 'allout-mode) ; enable allout-mode at
                                           ; planner startup

;;;_ , planner day/plan page templates

;;;_  . planner-day-page-template

(defun planner-dpt ()
  "Template to build new planner day pages."
       "#contentdepth 2\n<literal><div class=\"navigate_daypages\"></literal>\n[[<lisp>(planner-get-previous-existing-day (planner-page-name))</lisp>][< Previous Day]] [[/pim/planner_index.html#overview][| Index |]] [[<lisp>(planner-get-next-existing-day (planner-page-name))</lisp>][Next Day >]]\n<literal></div></literal>\n\n* Schedule\n\n* Index of Note Headlines\n\n<notes>\n\n* Notes\n\n* Tasks\n"

(setq planner-day-page-template 'planner-dpt)

;;;_  . planner-plan-page-template

(defun planner-ppt ()
  "Template to build new planner plan/project pages."
"#title Insert Title ...
#status notok | Project is in its early stage.
#contentdepth 2

The reader can use either one of the two links below to *center* himself
again i.e. either go to the *index page* or the *main page* of Suno Ano's
to-the-net-published PIM (Personal Information Manager) system data.

Pick the first one to start at the very beginning. This one explains
what the schedule is, how to read it i.e. a description of certain
symbols etc., why it is so valuable to Suno and how it works. Pick the
second one if you already know about the PIM (Personal Information
Manager) system Suno uses and how he uses it to manage his schedule.
You should know all the different symbols and icons and what they
determine in order to be able to understand the information below. If
you have problems to understand it, then pick the first link, take
your time to read and then come back.

 1. Back to the [[/ws/my_schedule.html][main page]] of Suno Ano's schedule. The main page has a
    [[/ws/my_schedule.html#how_to_read_the_schedule][section]] which describes how to read this pages.
 2. Back to PIM (Personal Information Manager) [[/pim/planner_index.html#overview][index]]. All pages in
    Suno's schedule can be reached from the index page -- it is the
    center of Suno's to-the-net-published PIM data.

The sections below match the GTD (Getting Things Done) [[/ws/gtd.html#planning][planning]] major
model. There are three special sections -- *Index of Note Headlines*, *Notes* and *Tasks*
contain data that is generated from the PIM (Personal Information Manager) system. *Index of Note Headlines* is not part of the planning major model
but just in place to provide an index for *Notes* which matches the *Brainstorming* part of the planning major model. The *Tasks* section matches the
*Identifying next Actions* phase of the planning major model.

* Defining the Purpose\n* Envisioning the Outcome\n* Index of Note Headlines\n<notes>\n* Notes\n* Organizing / Project Plan\n* Tasks\n"

(setq planner-plan-page-template 'planner-ppt)

;;;_ , planner-appt - Appointments with planner

;; (require 'planner-appt)

;; (planner-appt-use-schedule)
;; (planner-appt-insinuate)
;; (setq planner-appt-sort-schedule-on-update-flag t)

;; (setq planner-appt-update-appts-on-save-flag t)
;; (planner-appt-schedule-cyclic-insinuate)

;; (setq planner-appt-forthcoming-days 27)

;; (planner-appt-calendar-insinuate)
;; (setq appt-message-warning-time 180)
;; (setq appt-display-interval 60)

;;;_ , planner-cyclic

;If there are tasks that you have to do regularly, you can have
;Planner schedule those tasks automatically.

(require 'planner-cyclic)

(setq planner-cyclic-diary-file
      (concat emacs-root-dir "planner_cyclic/planner_cyclic_tasks_file"))
(setq planner-cyclic-diary-nag nil)
(setq planner-appt-schedule-cyclic-behaviour 'future)

;;;_ , planner-registry

;;; ; The code below needs to go texually after the code that loaded
;;; ; main planner i.e. `planner.el'

;;; (require 'planner-registry)
;;; (planner-registry-initialize)

;;; (setq planner-registry-file
;;;        (concat emacs-root-dir "planner_registry/planner_registry_file.el"))

;;; ; registry to be updated each time a Planner file is saved
;;; (planner-registry-insinuate)

;;;_ , planner-id

(require 'planner-id)

(setq planner-id-add-task-id-flag t)
(setq planner-id-update-automatically t)
(setq planner-id-tracking-file
      (concat emacs-root-dir "planner_id/planner_id_tracking_file"))

;;;_ , planner-rank

(require 'planner-rank)

(setq planner-sort-tasks-key-function 'planner-sort-tasks-by-rank)

(add-hook 'planner-create-task-from-buffer-hook 'planner-rank-change)
(add-hook 'planner-create-task-from-buffer-hook 'planner-rank-update-all)
(add-hook 'planner-create-task-from-buffer-hook 'planner-sort-tasks)

(add-hook 'planner-create-task-hook 'planner-rank-change)
(add-hook 'planner-create-task-hook 'planner-rank-update-all)
(add-hook 'planner-create-task-hook 'planner-sort-tasks)

;;;_ , planner-deadline

(require 'planner-deadline)

;;;_ , planner-trunk

(require 'planner-trunk)

; from rarest so to most frequent occurrence i.e. rarest at the top
(setq planner-trunk-rule-list
  ("\\`[0-9][0-9][0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9]\\'" nil
     ("delegated" "Delegated Tasks")
     ("errands" "Errands")
     ("travel.before" "Before Traveling")
     ("travel.during" "During Traveling")
     ("travel.after" "After Traveling")
     ("communicate.video" "Video Communication")
     ("communicate.audio" "Audio Communication")
     ("communicate.text" "Text Communication")
     ("entity.people" "Entity - People")
     ("entity.company" "Entity - Company")
     ("entity.organization" "Entity - Organization")
     ("place.otg" "Place - On-the-Go")
     ("place.home" "Place - At Home")
     ("place.office" "Place - At the Office")
     ("sk.science" "Skills and Knowledge - Science and Research")
     ("sk.it" "Skills and Knowledge - IT (Information Technology)")
     ("resource.body" "Body")
     ("resource.entertainment" "Entertainment")
     ("resource.hardware" "Hardware")
     ("resource.software" "Software")
     ("lof.1" "Levels of Focus - Level 1 also known as Life Goals")
     ("lof.2" "Levels of Focus - Level 2 also known as 5 year Visions")
     ("lof.3" "Levels of Focus - Level 3 also known as Yearly Goals")
     ("lof.4" "Levels of Focus - Level 4 also known as Areas of Responsibility")
     ("lof.5" "Levels of Focus - Level 5 also known as Current Projects")
     ("lof.6" "Levels of Focus - Level 6 also known as Current Actions")
     ("cyclic" "Cyclic Tasks:")
     ("taskpool" "Miscellaneous") ;last one is taken per default if non of the previous matches

(add-hook 'planner-mode-hook 'planner-trunk-tasks)

;;;_ , planner-multi

(require 'planner-multi)

;;;_ , planner-task-overview

(require 'planner-tasks-overview)

;;;_ , planner-notes-index

(require 'planner-notes-index)

;;;_ , planner-w3m

(require 'planner-w3m)

;;;_ , planner-notes-index

(require 'planner-notes-index)

;;;_ , planner-annotations

; This sections is about how to use planner with many other Emacs
; packages so one can make annotations from <some_package> to planner
; automatically witout the need for copy-paste. Those annotations then
; not just provide the information directly annotated but also
; metadata like links to it etc. For further information on the matter
; please read (Info-goto-node "(planner-el)Annotations").
; An important variable here is `planner-annotation-functions'

;;;_  . gnus

; see `planner-gnus.el' hint use `M-x find-library RET planner-gnus.el
; RET' or (Info-goto-node "(planner-el)Gnus") for details

(require 'planner-gnus)

;;;_  . BBDB

; see `planner-bbdb.el' or (Info-goto-node "(planner-el)Contacts and
; Conversations")

(require 'planner-bbdb)

;;;_  . ERC

; see `planner-erc.el' or (Info-goto-node "(planner-el)Contacts and
; Conversations") for details

(require 'planner-erc)

;;;_ , planner-publish

(require 'planner-publish)

;; (setq planner-publish-markup-regexps
;;   '(;(1270 planner-id-regexp 0 "") uncommented since I want to publish my global task
;;     ;                              ID' so folks can refer to tasks by their ID
;;    (1275 "^#\\([A-C]\\)\\([0-9]*\\)\\s-*\\([_oXDCP]\\)\\s-*\\(.+\\)" 0 task)
;;    (1280 "^\\.#[0-9]+\\s-*" 0 note)
;;    (3200 planner-date-regexp 0 link)
;;    )
;; )

(setq planner-publish-markup-regexps
  '((1270 "\\(\\s-*{{Rank:\\s-+\\([0-9][\\.\\-][0-9]+\\)\\s-+-\\s-+I=\\([0-9]\\)\\s-+U=\\([0-9]\\)}}\\)" 0 "")
    (1271 "{{\\([^:\n]+\\):" 0 " / Task ID: ")
    (1272 "}}" 0 " / ")
    ;; (1273 "(" 0 "")
    ;; (1274 ")" 0 "")
    (1275 "^#\\([A-C]\\)\\([0-9]*\\)\\s-*\\([_oXDCP]\\)\\s-*\\(.+\\)" 0 task)
    (1280 "^\\.#[0-9]+\\s-*" 0 note)
    (3200 planner-date-regexp 0 link)

;;;_ , planner-zoom

(require 'planner-zoom)

;;;_  . unset some local keybindings made when loading planner-zoom

; `planner-zoom' has some local keybindings which overlap with some of
; my own, global keybindings. The keybinds in question where those
; made for `windmove-*'.
; So, I unset the local keybindins made by `planner-zoom' and made my
; own e.g. the one for `planner-zoom-iprev' (see further down within
; the keybindings section of my `.emacs')

(defun my-planner-unset-local-keybindings ()
"Remove some keybindings for planner major mode. In special, I
wanted to use the S-arrow keys e.g. S-<up> for navigation, so I
had to unset the local keybindings for them made by
  (local-unset-key (kbd "S-<up>"))
  (local-unset-key (kbd "S-<down>"))
  (local-unset-key (kbd "S-<left>"))
  (local-unset-key (kbd "S-<right>")))

(add-hook 'planner-mode-hook 'my-planner-unset-local-keybindings t)

;;;_ , planner-rss

(setq planner-rss-base-url (concat remote-http-root planner-public-rss-dir))

(setq planner-rss-category-feeds
   ,(concat planner-public-rss-dir "planner.misc.xml")
   ,(concat "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<rss version=\"2.0\">
<title>Markus Gattol's Planner Notes RSS Feed</title>
<link>" remote-http-root "</link>
<description>This RSS feed contains notes from Planner, my PIM (Personal Information Manager) system.</description>
<generator>Emacs Muse</generator>

(setq planner-rss-feed-limits '(("." nil 20)))
(add-to-list 'remember-planner-append-hook 'planner-rss-add-note t)

;;;_. org-mode

; After evaluation, I am back to Planner.

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

;;;_. bbdb

(require 'bbdb)

(setq bbdb-root-dir (concat emacs-root-dir "bbdb/"))
(setq bbdb-file (concat bbdb-root-dir "bbdb"))

;FIXME - working on wks but not on sub therfore commented out
(bbdb-initialize 'gnus 'message 'sc)

(setq bbdb-send-mail-style 'gnus)
(setq bbdb-dwim-net-address-allow-redundancy t)
(setq bbdb-quiet-about-name-mismatches t)
(setq bbdb-north-american-phone-numbers-p nil)
(setq bbdb-check-zip-codes-p nil)
(setq bbdb-offer-save 1)

(defun ignore-obfuscated-addresses ()
  ;; gmane sometimes obfuscates email addresses (while keeping names),
  ;; which would cause prompting for adding the `new' e-mail address to
  ;; the existing record for entries in the bbdb
  (if (string-match "public\\.gmane\\.org$" net)
    ;; launchpad also sometimes associates names with
    ;; ######@bugs.launchpad.net e-mail addresses.
    (if (string-match "bugs\\.launchpad\\.net$" net)
      ;; otherwise, ask.

(setq bbdb-always-add-addresses 'ignore-obfuscated-addresses)

;;;_ Document Engineering

;;;_. auctex

;;;_ , initialize some stuff

(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-auto-untabify t)
(setq TeX-display-help t)
(setq TeX-save-query nil)
(setq TeX-clean-confirm nil)
(setq-default TeX-master nil)

;;;_ , hook(s)
(add-hook 'TeX-mode-hook (lambda () (TeX-fold-mode 1)))
(add-hook 'TeX-mode-hook (lambda () (TeX-source-specials-mode 1)))
(add-hook 'TeX-mode-hook (lambda () (TeX-toggle-debug-bad-boxes)))
(add-hook 'TeX-mode-hook (lambda () (TeX-toggle-debug-warnings)))
(add-hook 'TeX-mode-hook (lambda () (outline-minor-mode)))
(add-hook 'TeX-mode-hook (lambda () (abbrev-mode t)))
(add-hook 'TeX-mode-hook (lambda () (auto-fill-mode 1)))

(add-hook 'TeX-mode-hook 'LaTeX-math-mode)

;;;_ , etexshow

(autoload 'etexshow "etexshow"  "Browswer for ConTeXt commands." t)

(setq etexshow-xml-files-alist
  `((,(concat emacs-root-dir "libs/etexshow/cont-en.xml") .
     ,(concat "/tmp/cont-en.cache"))))

(setq etexshow-comment-file
  (concat emacs-root-dir "libs/etexshow/cont-en-comments.xml"))

;;;_. doc-view

(setq TeX-PDF-mode t)
(setq revert-without-query '(".+pdf$"))
(add-hook 'doc-view-mode-hook 'auto-revert-mode)

;;;_ Programming

;;;_. IDE

;;;_ , ecb
(require 'ecb)

; http://ecb.sourceforge.net/docs/Changing-the-ECB-layout.html#Changing%20the%20ECB-layout
(setq ecb-layout-name "leftright2")

;;;_. cedet

;;;_. SCM (Software Configuration Management)

;;;_ , DVC (Distributed Version Control)
; http://fsw.gsfc.nasa.gov/GDS/dvc-intro.html

(require 'dvc-autoloads)

(setq dvc-config-directory (concat emacs-root-dir "libs/scm/dvc_config/"))
(setq xgit-log-max-count '5000)
(setq dvc-tips-enabled 'nil)
;(setq dvc-log-edit-other-frame 't)

; set the one below at some point in the future
; xgit-mail-notification-sign-off-p
; xgit-apply-patch-mapping

;;;_ , SVN (Subversion)

;;;_. Compiling, testing, diff, debugging, etc.

;;;_ , TODO
; This subsection can be thought of as a to do list ...

; http://www.emacswiki.org/cgi-bin/emacs-jp/SkeletonMode
; See (Info-goto-node "(emacs)Building")
; http://www.emacswiki.org/cgi-bin/wiki/eassist.el

;;;_ , ediff

(require 'ediff)
(setq ediff-split-window-function 'split-window-horizontally)
(setq diff-switches "-U 4")

;;;_. Minor/Major mode settings

;;;_ , css mode

(require 'css-mode)
;(setq auto-mode-alist (append '(("\\.css$" . css-mode)) auto-mode-alist))
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))

;;;_ , cc mode

;; (defun my-c-mode-common-hook ()
;;   (c-toggle-hungry-state -1)
;;   (c-toggle-auto-newline 1)
;;   (setq c-basic-offset 2))

;; (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

;;;_ , python mode
(require 'python)
(add-hook 'python-mode-hook 'pylint-python-hook)
(add-hook 'python-mode-hook 'eldoc-mode)

;;;_  . rope (refactoring etc.)
;(require 'pymacs)
;(pymacs-load "ropemacs" "rope-")
;(setq ropemacs-enable-autoimport t)

; --------------------------------------------
;;;_  . folding

;; (defun py-outline-level ()
;;   (let (buffer-invisibility-spec)
;;     (save-excursion
;;       (skip-chars-forward "\t ")
;;       (current-column))))

;; (defun my-python-folding-hook ()
;;   ; outline uses this regexp to find headers. I match lines with no indent and indented "class"
;;   ; and "def" lines.
;;   (setq outline-regexp "[^ \t]\\|[ \t]*\\(def\\|class\\) ")
;;   ; enable our level computation
;;   (setq outline-level 'py-outline-level)
;; ;;;   ; do not use their \C-c@ prefix, too hard to type. Note this overides some python mode bindings
;; ;;;   (setq outline-minor-mode-prefix "\C-c")
;;   ; turn on outline mode
;;   (outline-minor-mode t)
;;   ; initially hide all but the headers
;;   (hide-body)
;; )

; --------------------------------------------
;; (require 'semantic-tag-folding)

;; (defun my-python-folding-hook ()
;;   (global-semantic-tag-folding-mode 1)
;;   (local-set-key (kbd "M-f") 'semantic-tag-folding-fold-block)
;;   (local-set-key (kbd "M-F") 'semantic-tag-folding-show-block)
;; )

;; (add-hook 'python-mode-hook 'my-python-folding-hook)
; --------------------------------------------

;;;_ Keybindings

; ,----[ Remember ]
; |
; | C-c and F5 to F9 are reserved for user key binding -- see
; | (Info-goto-node "(emacs)Keymaps") for more information
; |
; | The two-character keys consisting of `C-c' followed by a letter
; | are reserved for user customizations.  Lisp programs are not
; | supposed to define these keys, so the bindings you make for them
; | will be available in all major modes and will never get in the
; | way of anything.
; `----

; A short listing of what key binding goes with what functionality
; ----------------------------------------------------------------
; You may notice, the http://en.wikipedia.org/wiki/Radix_tree style
; e.g. look at the boxquote part and compare the function name to the
; order of keys within a key sequence.

; The first unique character (by start looking from the beginning of a
; token) within a functions name is the last one in the key sequence
; to which this particular function is bound (in the context of all
; function names of course) -- this way, the key setting becomes
; unique).

; f5                       - dired
; f6                       - muse-mode
; f7                       - SCMs (Software Configuration Management) Systems
; f8                       - Gnus
; f9                       - planner/remember-mode
; f10                      - w3m (per default bound to `menu-bar-open')

; C-{right,left}           - {forward,backward} sexp
; C-S-{right,left}         - {forward,backward} sentence
; C-c b                    - boxquote
; C-c <tab>                - indent-relative
; C-c r                    - rectangle
; C-c t                    - toggle some mode
; C-c o                    - open recently opened file

; M-{up,down}              - cycle among buffers within the current window
; M-{right,left}           - {forward,backward} word
; M-n                      - number-lines-region
; M-{s,g}                  - point-stack
; S-{up,down,left,right}   - move point from window to some other window

;;;_. sort-lines

(global-set-key (kbd "s-l") 'sort-lines)

;;;_. text-scale-adjust

(global-set-key (kbd "s-<right>") 'text-scale-increase)
(global-set-key (kbd "s-<left>")  'text-scale-decrease)
(global-set-key (kbd "s-<tab>")   'text-scale-adjust)

;;;_. delete blank lines

(global-set-key (kbd "s-z") 'delete-blank-lines)

;;;_. midnight-mode
; autokill buffers, a neat feature if you have Emacs running for days
; or more.

(require 'midnight)

(setq midnight-delay '14400)
(setq clean-buffer-list-delay-general '2)

;; clean-buffer-list-kill-buffer-names
;; clean-buffer-list-kill-regexps

;; clean-buffer-list-kill-never-buffer-names
;; clean-buffer-list-kill-never-regexps

;; clean-buffer-list-delay-general
;; clean-buffer-list-delay-special

;;;_. remember buffer position, jump back
;;;_ , viss-bookmarks

(require 'linemark)
(global-set-key (kbd "s-s")       'viss-bookmark-toggle)
(global-set-key (kbd "s-<up>")    'viss-bookmark-prev-buffer)
(global-set-key (kbd "s-<down>")  'viss-bookmark-next-buffer)
(global-set-key (kbd "s-c")       'viss-bookmark-clear-all-buffer)

;;;_ , point-stack
;(global-set-key (kbd "M-s") 'point-stack-push) ;set
;(global-set-key (kbd "M-g") 'point-stack-pop)  ;jump back

;;;_. yank: swap `suspend-frame' and `yank'

(global-set-key (kbd "C-y") 'suspend-frame)
(global-set-key (kbd "C-z") 'yank)
(global-set-key (kbd "M-z") 'yank-pop)

;;;_. flyspell-mode

(global-set-key [S-down-mouse-1] 'flyspell-correct-word)

;;;_. just-one-space

(global-set-key (kbd "C-c s") 'just-one-space)

;;;_. my-remove-duplicates

(global-set-key (kbd "C-c D") 'my-remove-duplicates)

;;;_. my-compute-replace-region

(global-set-key (kbd "C-c C") 'my-compute-replace-region)

;;;_. my-reverse-chars-in-region

(global-set-key (kbd "C-c R") 'my-reverse-chars-in-region)

;;;_. my-unique-lines

(global-set-key (kbd "C-c U") 'my-unique-lines)

;;;_. pastie

(global-set-key (kbd "C-x p b") 'pastie-buffer)
(global-set-key (kbd "C-x p r") 'pastie-region)
(global-set-key (kbd "C-x p g") 'pastie-get)

;;;_. wtf

(global-set-key (kbd "C-x w") 'wtf-is)

;;;_. bbdb-snarf

; Take a look at (Info-goto-node "(bbdb)bbdb-snarf")

(global-set-key (kbd "<f8> s") 'bbdb-snarf)

;;;_. save-buffers-kill-terminal

(global-set-key (kbd "<f1> K") 'save-buffers-kill-terminal)

;;;_. capitalize-region

; That's catching two flys with one stroke. It happened that I
; accidentialy hit `C-x C-c' and so quit Emacs. `C-x C-c' is per
; default bound to `save-buffers-kill-terminal'
(global-set-key (kbd "C-x C-c") 'capitalize-region)

;;;_. replace-string

;Note: query-replace and then `!' does the same
(global-set-key (kbd "M-&") 'replace-string)

;;;_. my-surround-sexp

(global-set-key (kbd "s-1") 'my-surround-sexp-0)
(global-set-key (kbd "s-2") 'my-surround-sexp-1)
(global-set-key (kbd "s-3") 'my-surround-sexp-2)

;;;_. scrolling

(global-set-key (kbd "M-S-<left>")  (lambda () (interactive) (scroll-left 2)))
(global-set-key (kbd "M-S-<right>") (lambda () (interactive) (scroll-right 2)))
(global-set-key (kbd "M-S-<up>")    (lambda () (interactive) (scroll-up 3)))
(global-set-key (kbd "M-S-<down>")  (lambda () (interactive) (scroll-down 3)))

;;;_. Debian related stuff

;;;_ ,  apt-sources - major mode for editing Debian sources.list files

;;;_ ,  apt-utils - interface to APT (Debian package management)

;;;_ ,  debian-bug - an Emacs command to submit a bug report

;;;_ ,  deb-view - view contents of Debian package, similarly to tar-mode

;;;_ ,  gnus-BTS - provides buttons for bug numbers seen in Gnus messages

;;;_ ,  preseed - major mode for editing debian-installer preseed files

;;;_. SCM (Software Configuration Management)

;;;_ , SVN (Subversion)
; (global-set-key (kbd "<f7> S") 'svn-status)

;;;_ , GIT
; I am using Emac's DVC (Distributed Version Control) for GIT

(global-set-key (kbd "<f7> i") 'dvc-init)
(global-set-key (kbd "<f7> d") 'dvc-dired-jump)

;;;_  . main entry points/functions
(global-set-key (kbd "<f7> S") 'dvc-status)
(global-set-key (kbd "<f7> D") 'dvc-diff)
(global-set-key (kbd "<f7> C") 'dvc-changelog)
(global-set-key (kbd "<f7> B") 'dvc-bookmarks)
(global-set-key (kbd "<f7> L") 'dvc-open-internal-log-buffer)
(global-set-key (kbd "<f7> P") 'dvc-show-process-buffer)
(global-set-key (kbd "<f7> E") 'dvc-show-last-error-buffer)

;; dvc-purge-files
;; dvc-rename
;; dvc-inventory

;;;_  . branches and external repositories

;; dvc-missing
;; dvc-merge
;; dvc-pull
;; dvc-update
;; dvc-submit-patch
;; dvc-bookmarks
;; dvc-clone
;; dvc-create-branch
;; dvc-select-branch
;; dvc-list-branches

;;;_  . gnus interaction

;; see dvc-insinuate-gnus
;; K t l `dvc-gnus-article-extract-log-message'
;; K t v `dvc-gnus-article-view-patch'
;; K t m `dvc-gnus-article-view-missing'
;; K t a `dvc-gnus-article-apply-patch'
;; K t p `dvc-gnus-article-apply-patch-with-selected-destination'

;;;_. w3m

(global-set-key (kbd "<f10> W") 'w3m)

;;;_ , unset some local keybindings in w3m major mode

(defun my-w3m-unset-local-keybindings ()
"Remove some keybindings for w3m major mode. In special, I wanted
to use the arrow keys for navigation, so I had to unset the local
keybindings for them."
  (local-unset-key (kbd "<up>"))
  (local-unset-key (kbd "<down>"))
  (local-unset-key (kbd "<left>"))
  (local-unset-key (kbd "<right>")))

(add-hook 'w3m-mode-hook 'my-w3m-unset-local-keybindings)

;;;_ , Add new keys resp. alter existing ones
(add-hook 'w3m-mode-hook
          '(lambda ()
 (define-key w3m-mode-map (kbd "S")           'my-interactive-w3m-search)
 (define-key w3m-mode-map (kbd "s")           'w3m-search)
 (define-key w3m-mode-map (kbd "<f10> c u")   'my-w3m-copy-url-at-point)
 (define-key w3m-mode-map (kbd "<tab>")       'w3m-next-anchor)
 (define-key w3m-mode-map (kbd "<backtab>")   'w3m-previous-anchor)
 (define-key w3m-mode-map (kbd "<delete>")    'w3m-scroll-down-or-previous-url)
 (define-key w3m-mode-map (kbd "<f10> v p")   'w3m-view-this-url)
 (define-key w3m-mode-map (kbd "<f10> v e")   'w3m-view-url-with-external-browser)
 (define-key w3m-mode-map (kbd "<f10> v n")   'w3m-view-this-url-new-session)
 (define-key w3m-mode-map (kbd "n")           'w3m-view-next-page)
 (define-key w3m-mode-map (kbd "p")           'w3m-view-previous-page)
 (define-key w3m-mode-map (kbd "=")           'w3m-view-header)
 (define-key w3m-mode-map (kbd "\\")          'w3m-view-source)
 (define-key w3m-mode-map (kbd "^")           'w3m-view-parent-page)
 (define-key w3m-mode-map (kbd "<mouse-2>")   'w3m-mouse-view-this-url)
 (define-key w3m-mode-map (kbd "S-<mouse-2>") 'w3m-mouse-view-this-url-new-session)
 (define-key w3m-mode-map (kbd "<f10> a c")   'w3m-bookmark-add-current-url)
 (define-key w3m-mode-map (kbd "<f10> a p")   'w3m-bookmark-add-this-url)
 (define-key w3m-mode-map (kbd "+")           'w3m-antenna-add-current-url)
 (define-key w3m-mode-map (kbd "A")           'w3m-antenna)
 (define-key w3m-mode-map (kbd "<f10> p u")   'w3m-print-this-url)
 (define-key w3m-mode-map (kbd "<f10> p c")   'w3m-print-current-url)
 (define-key w3m-mode-map (kbd "<f10> d c")   'w3m-download)
 (define-key w3m-mode-map (kbd "<f10> d p")   'w3m-download-this-url)
 (define-key w3m-mode-map (kbd "<f10> g u")   'w3m-goto-url)
 (define-key w3m-mode-map (kbd "<f10> g n")   'w3m-goto-url-new-session)
 (define-key w3m-mode-map (kbd "<f10> h")     'w3m-gohome)
 (define-key w3m-mode-map (kbd "<f10> i t")   'w3m-toggle-inline-images)
 (define-key w3m-mode-map (kbd "<f10> i s")   'w3m-save-image)
 (define-key w3m-mode-map (kbd "<f10> n")     'w3m-namazu)
 (define-key w3m-mode-map (kbd "h")           'w3m-history)
 (define-key w3m-mode-map (kbd "H")           'w3m-db-history)
 (define-key w3m-mode-map (kbd "R")           'w3m-reload-this-page)
 (define-key w3m-mode-map (kbd "v")           'w3m-bookmark-view)
 (define-key w3m-mode-map (kbd "<f10> w")     'w3m-weather)
 (define-key w3m-mode-map (kbd "]")           'w3m-next-form)
 (define-key w3m-mode-map (kbd "[")           'w3m-previous-form)
 (define-key w3m-mode-map (kbd "}")           'w3m-next-image)
 (define-key w3m-mode-map (kbd "{")           'w3m-previous-image)
 (define-key w3m-mode-map (kbd "<f10> <f10>") 'w3m-submit-form)
 (define-key w3m-mode-map (kbd "q")           'w3m-close-window)
 (define-key w3m-mode-map (kbd "Q")           'w3m-quit)

;;;_. command-history

(global-set-key (kbd "C-x c") 'command-history)

;;;_. browse-kill-ring

(global-set-key (kbd "C-x z") 'browse-kill-ring)

;;;_. repeat

(global-set-key (kbd "C-x y") 'repeat)

;;;_. underhat-region

(global-set-key (kbd "C-c C-^") 'underhat-region)

;;;_. narrow-to-region

;This ones are already bound

;; ,----[ C-h f narrow-to-region RET ]
;; | narrow-to-region is an interactive built-in function in `C source code'.
;; | It is bound to C-x n n.
;; | (narrow-to-region start end)
;; |
;; | Restrict editing in this buffer to the current region.
;; | The rest of the text becomes temporarily invisible and untouchable
;; | but is not deleted; if you save the buffer in a file, the invisible
;; | text is included in the file.  C-x n w makes all visible again.
;; | See also `save-restriction'.
;; |
;; | When calling from a program, pass two arguments; positions (integers
;; | or markers) bounding the text that should remain visible.
;; `----

;;;_. erase-buffer

(global-set-key (kbd "C-c e") 'erase-buffer)

;;;_. unfill-paragraph

(global-set-key (kbd "M-Q") 'unfill-paragraph)

;;;_. number-lines-region

(global-set-key (kbd "M-n") 'number-lines-region)

;;;_. dired

; When I got promted for a directory after hitting `<f5> D', I use the
; minibuffer history to quickly enter a directory (Info-goto-node
; "(emacs)Minibuffer History")

(global-set-key (kbd "<f5> D")   'dired-other-frame)
(global-set-key (kbd "<f5> m r")
                (lambda () (interactive)
                      (region-beginning) (region-end)))

; From (Info-goto-node "(emacs) Misc Dired Features")
(global-set-key (kbd "<f5> c d") 'dired-compare-directories)
;(global-set-key (kbd "<f5> c f") 'dired-copy-filename-as-kill) just use `w'

; ---------- wdired
(setq wdired-allow-to-change-permissions t)

; ---------- dired with find resp. locate
(global-set-key (kbd "<f5> f n") 'find-name-dired) ; find per file name; equivalent to `% m REGEX RET'
(global-set-key (kbd "<f5> f c") 'find-grep-dired) ; find per file content; equivalent to `%g REGEX RET'
(global-set-key (kbd "<f5> f l") 'locate-with-filter)

;;;_. dired-x

(global-set-key (kbd "<f5> o a") 'dired-omit-here-always)
(global-set-key (kbd "<f5> v d") 'dired-virtual)

;;;_ , Advanced Mark Commands

(global-set-key (kbd "<f5> m e") 'dired-mark-extension)
(global-set-key (kbd "<f5> m s") 'dired-mark-sexp)
(global-set-key (kbd "<f5> f e") 'dired-flag-extension)

;;;_  . Special Marking Function

; See (Info-goto-node "(dired-x) Special Marking Function")

;;;_. image-dired

;;;_ , maybe replacement functions for macros

;;; image-dired-display-window
;;;    Function: Return window where `image-dired-display-image-buffer' is visible.

;;; image-dired-thumbnail-window
;;;   Function: Return window where `image-dired-thumbnail-buffer' is visible.

;;; image-dired-get-buffer-window
;;;   Function: Return window where buffer BUF is.

;;; image-dired-kill-buffer-and-window M-x ... RET
;;;   Command: Kill the current buffer and, if possible, also the window.

;;; image-dired-restore-window-configuration
;;;   Command: Restore window configuration.

;;;_ , keyboard macros

;;;_  . image-dired (split windows and arrange buffers)

;;;_   , macros

; split windows
(fset 'my-window-split
            [?\C-x ?3 ?\C-x ?2])

; assign buffers to windows as I think is good
(fset 'my-open-and-arrange-buffers
   [kp-enter M-up S-up ?\C-x ?b ?i ?m ?a ?g ?e ?- ?d ?i ?r ?e ?d return])

;;;_   , keybindings making use of the macros

;;;_    . keybindings to macros above

(global-set-key (kbd "<f5> S") 'my-window-split)             ; split
(global-set-key (kbd "<f5> A") 'my-open-and-arrange-buffers) ; arrange

;;;_    . the meta binding which combines all the above

; This is the one I always use. I start dired the usual way (<f5> D),
; head to the directory I am interested in, mark the files I'd like to
; view and then hit `<f5> I'

(global-set-key (kbd "<f5> I") (kbd "<f5> S C-t d <f5> A"))

; That's the first try before I gave up since it was already 3am
;; (global-set-key (kbd "<f5> i")
;;      '(lambda () (interactive)
;;           (progn (my-window-split)
;;                  (image-dired-display-thumbs)
;;                  (my-open-and-arrange-buffers)
;;           )
;;          )
;; )

;;;_ , gallery

(global-set-key (kbd "<f5> c g") 'image-dired-gallery-generate)

;;;_ , slideshow

(global-set-key (kbd "<f5> s S") 'image-dired-slideshow-start)
(global-set-key (kbd "<f5> s s") 'image-dired-slideshow-stop)
(global-set-key (kbd "<f5> SPC") 'image-dired-slideshow-step)

;;;_ , dired buffer specific

(global-set-key (kbd "<f5> s a") 'image-dired-show-all-from-dir)
(global-set-key (kbd "<f5> c e") 'image-dired-copy-with-exif-file-name)
(global-set-key (kbd "<f5> c t") 'image-dired-dired-edit-comment-and-tags)
(global-set-key (kbd "<f5> d p") 'image-dired-dired-display-properties)
(global-set-key (kbd "<f5> a t") 'image-dired-tag-files)
(global-set-key (kbd "<f5> d t") 'image-dired-delete-tag)
(global-set-key (kbd "<f5> c a") 'image-dired-dired-comment-files)
(global-set-key (kbd "<f5> m t") 'image-dired-mark-tagged-files)

;;;_ , thumbnail specific

(global-set-key (kbd "<f5> t d") 'image-dired-display-thumbs)
(global-set-key (kbd "<f5> t a") 'image-dired-display-thumbs-append)
(global-set-key (kbd "<f5> t c") 'image-dired-create-thumbs)
(global-set-key (kbd "<f5> t D") 'image-dired-delete-char)
(global-set-key (kbd "<f5> t r") 'image-dired-refresh-thumb)

;;;_ , thumbnail buffer specific

; use `t t' (`image-dired-tag-thumbnail') or `t r'
; (`image-dired-tag-thumbnail-remove') in the thumbnail buffer. Those
; work in the thumbnail buffer only and are another way next to
; `image-dired-dired-edit-comment-and-tags' to quickly add/remove tags
; and comments on images.

;;;_. allout-mode
(global-set-key (kbd "C-c `")  'allout-hide-bodies)
(global-set-key (kbd "C-c ~")  'allout-show-all)

(global-set-key (kbd "C-`") 'allout-beginning-of-current-entry)
(global-set-key (kbd "C-~") 'allout-end-of-entry)
(global-set-key (kbd "s-`") 'allout-end-of-current-subtree)

(global-set-key (kbd "C-c SPC C-t") 'allout-mark-topic)

;;;_. muse-mode

;;;_ , Set [local]keybindings

;;;_  . Show `muse-index'

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> i")

;;;_  . Insert hard line break

; This is a local keybinding for muse-mode. It just affects muse major
; mode. What it does is, it inserts a hard line break into muse source
; code which will then be published. Any of the output formats creates
; its specific "translation" of the <br> tag.

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "C-<return>")

;;;_  . Insert source for quotation

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> q w")
             (define-key muse-mode-map (kbd "<f6> q u")
             (define-key muse-mode-map (kbd "<f6> q f d")
             (define-key muse-mode-map (kbd "<f6> q f c")

;;;_  . footnotes with muse

; See http://www.emacswiki.org/cgi-bin/wiki/FootnoteMode and
; (Info-goto-mode "(muse)Footnotes")

; Note ALL functions start with `F'

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> f r")
             (define-key muse-mode-map (kbd "<f6> f g")
             (define-key muse-mode-map (kbd "<f6> f d")
             (define-key muse-mode-map (kbd "<f6> f c")
             (define-key muse-mode-map (kbd "<f6> f b")
             (define-key muse-mode-map (kbd "<f6> f a")
             (define-key muse-mode-map (kbd "<f6> f i")
             (define-key muse-mode-map (kbd "<f6> f R")

;;;_  . Insert package information = short describtion + debtags

; That sould be a global key since I may use it at some point with ERC
; or so

(global-set-key (kbd "<f6> T")
   (lambda (tool)
        "sInsert tool respectively command name: "
             "*** "
             (shell-quote-argument tool)
                  "debtags show "
                  (shell-quote-argument tool)
                  " | egrep '^Name:|^Package:|^Description:|^Tag'"


;;;_  . Insert tags e.g. `<example>'

;;;_   , Insert `<math>' tags

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> t m")

;;;_   , Insert `<example>' tags

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> t e")

;;;_   , Insert `<code>' tags

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> t c")

;;;_   , Insert `<verse>' tags

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> t v")

;;;_    . Insert `<comment>' tags

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> t C")

;;;_   , Insert `<pyhton>' tags

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> t p")

;;;_   , Insert `<lisp>' tags

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> t l")

;;;_   , Insert `<src>' tags

;;;_    . emacs-lisp

(add-hook 'muse-mode-hook
          '(lambda ()
             (define-key muse-mode-map (kbd "<f6> t s e")

;;;_ , Unset local keybinding(s) for muse-mode

;;;_  . point-stack-push
;(add-hook 'muse-mode-hook
;          '(lambda ()
;             (local-unset-key (kbd "M-s"))
;           )

;;;_. planner-mode

;;;_ , Tasks

;---------- Invoke planner
; Start planning for the day - carrying unfinished tasks forward
(global-set-key (kbd "<f9> T") 'plan)

;---------- Invoke planner with LOF (Levels of Focus) page 6
; See wiki page GTD (Getting Things Done) for more information.
(global-set-key (kbd "<f9> p")
                (lambda () (interactive) (planner-goto-plan-page "lof.6")))

;---------- Invoke planner with LOF (Levels of Focus) page 5
; See wiki page GTD (Getting Things Done) for more information.
(global-set-key (kbd "<f9> P")
                (lambda () (interactive) (planner-goto-plan-page "lof.5")))

;---------- task creation
(global-set-key (kbd "<f9> c") 'planner-create-task-from-buffer)
(global-set-key (kbd "<f9> C") 'planner-create-task)

;---------- overview and navigation
(global-set-key (kbd "<f9> o") 'planner-tasks-overview-show-summary)
(global-set-key (kbd "<f9> O") 'planner-tasks-overview)
;(global-set-key (kbd "<f9> r") 'planner-registry-show)
(global-set-key (kbd "<f9> g") 'planner-goto-plan-page)

; planner-zoom
(global-set-key (kbd "<f9> <kp-8>") 'planner-zoom-iup)
(global-set-key (kbd "<f9> <kp-2>") 'planner-zoom-idown)
(global-set-key (kbd "<f9> <kp-6>") 'planner-zoom-inext)
(global-set-key (kbd "<f9> <kp-4>") 'planner-zoom-iprev)

;---------- move through planner day pages
(global-set-key (kbd "<f9> -") 'planner-goto-previous-daily-page)
(global-set-key (kbd "<f9> +") 'planner-goto-next-daily-page)

;---------- manage tasks
(global-set-key (kbd "<f9> m u")    'planner-multi-update-task)
(global-set-key (kbd "<f9> m d")    'planner-delete-task)
(global-set-key (kbd "<f9> m D")    'planner-multi-task-delete-this-page)
(global-set-key (kbd "<f9> m e")    'planner-multi-edit-task-description)
(global-set-key (kbd "<f9> m r")    'planner-multi-replan-task)
(global-set-key (kbd "<f9> m s")    'planner-sort-tasks) ; done automatically anyways
(global-set-key (kbd "<f9> m m")    'planner-multi-copy-or-move-task)
(global-set-key (kbd "<f9> t x")    'planner-multi-task-xref)
(global-set-key (kbd "<f9> n x")    'planner-multi-note-xref)
(global-set-key (kbd "<f9> <up>")   'planner-raise-task)
(global-set-key (kbd "<f9> <down>") 'planner-lower-task)

;           manage tasks . task rank
(global-set-key (kbd "<f9> m U") 'planner-rank-update-all)
(global-set-key (kbd "<f9> m c") 'planner-rank-change)
; use the one above to change the task rank; works also for multi
; tasks across several plan and/or day pages

;----------  task status
(global-set-key (kbd "<f9> s o") 'planner-task-open)
(global-set-key (kbd "<f9> s p") 'planner-task-in-progress)
(global-set-key (kbd "<f9> s P") 'planner-task-pending)
(global-set-key (kbd "<f9> s d") 'planner-task-done)
(global-set-key (kbd "<f9> s D") 'planner-task-delegated)
(global-set-key (kbd "<f9> s c") 'planner-task-cancelled)

;----------  deadline
(global-set-key (kbd "<f9> d a") 'planner-deadline-add)
(global-set-key (kbd "<f9> d r") 'planner-deadline-remove)
(global-set-key (kbd "<f9> d c") 'planner-deadline-change)
(global-set-key (kbd "<f9> d u") 'planner-deadline-update)

;---------- planner-appt i.e. appointments
(global-set-key (kbd "<f9> a f") 'planner-appt-forthcoming-display)
(global-set-key (kbd "<f9> a a") 'planner-appt-show-alerts)

; --------- planner-id
(global-set-key (kbd "<f9> i a") 'planner-id-add-task)
(global-set-key (kbd "<f9> i A") 'planner-id-add-task-id-to-all)
(global-set-key (kbd "<f9> i s") 'planner-id-search-id)

(global-set-key (kbd "<f9> i f") 'planner-id-follow-id-at-point)
(global-set-key (kbd "<f9> i j") 'planner-id-jump-to-linked-task)

;;;_ , Notes

(global-set-key (kbd "<f9> R") 'remember-region)
(global-set-key (kbd "<f9> r") 'remember)

(global-set-key (kbd "<f9> n d") 'planner-multi-note-delete)
(global-set-key (kbd "<f9> n D") 'planner-multi-note-delete-this-page)

(global-set-key (kbd "<f9> n r") 'planner-replan-note)
(global-set-key (kbd "<f9> n R") 'planner-renumber-notes)
(global-set-key (kbd "<f9> n u") 'planner-update-note)
(global-set-key (kbd "<f9> n s") 'planner-search-notes)
(global-set-key (kbd "<f9> n j") 'planner-jump-to-linked-note)
(global-set-key (kbd "<f9> n c") 'planner-create-note-from-task)

; --------- planner-rss
(global-set-key (kbd "<f9> n a") 'planner-rss-add-note)

;;;_. gnus

;start gnus in a separate frame
(global-set-key (kbd "<f8> G") 'gnus-other-frame)

;;;_. cycle buffers

(global-set-key (kbd "M-<up>")    'bs-cycle-next)
(global-set-key (kbd "M-<down>")  'bs-cycle-previous)

;;;_. move among windows

; I use windmove which is part of Emacs now anyways

(global-set-key (kbd "<S-up>")    'windmove-up)
(global-set-key (kbd "<S-down>")  'windmove-down)
(global-set-key (kbd "<S-left>")  'windmove-left)
(global-set-key (kbd "<S-right>") 'windmove-right)

;;;_. forward word OR sexp OR sentence

(global-set-key (kbd "M-<right>") 'forward-word)
(global-set-key (kbd "M-<left>")  'backward-word)

(global-set-key (kbd "C-<right>") 'forward-sexp)
(global-set-key (kbd "C-<left>")  'backward-sexp)

(global-set-key (kbd "C-S-<right>") 'forward-sentence)
(global-set-key (kbd "C-S-<left>")  'backward-sentence)

;;;_. toggling between n cases with n >=2

; There is more than one way to accomplish this:
; - (global-set-key (kbd "C-c t f") 'flyspell-mode) for example
; - the usage of `toggle-option'

;;;_ , flyspell-mode

(global-set-key (kbd "C-c t f")
                  (fset 'toggle-flyspell-mode
                    (lambda () "Toggle flyspell-mode"
                      (toggle-option 'flyspell-mode)

;;;_ , auto-fill-mode

(global-set-key (kbd "C-c t a")
                  (fset 'toggle-auto-fill-mode
                    (lambda () "Toggle auto-fill-mode"
                      (toggle-option 'auto-fill-mode)

;;;_ , abbrev-mode

(global-set-key (kbd "C-c t A")
                  (fset 'toggle-abbrev-mode
                    (lambda () "Toggle abbrev-mode"
                      (toggle-option 'abbrev-mode)

;;;_ , dedicated-mode

(global-set-key (kbd "C-c t d")
                  (fset 'toggle-dedicated-mode
                    (lambda () "Toggle dedicated-mode"
                      (toggle-option 'dedicated-mode)

;;;_ , highlight-changes-mode

(global-set-key (kbd "C-c t h")
                  (fset 'toggle-highlight-changes-mode
                    (lambda () "Toggle highlight-changes-mode"
                      (toggle-option 'highlight-changes-visible-mode)

;;;_. indent relative

(global-set-key (kbd "C-<tab>") 'indent-relative)

;;;_. rectangle

(global-set-key (kbd "C-c r c g")   'calc-grab-rectangle)

(global-set-key (kbd "C-c r s r")   'string-rectangle)
(global-set-key (kbd "C-c r s i")   'string-insert-rectangle)

(global-set-key (kbd "C-c r k")     'kill-rectangle)
(global-set-key (kbd "C-c r z")     'yank-rectangle)

(global-set-key (kbd "C-c r c l e") 'clear-rectangle)
(global-set-key (kbd "C-c r c l o") 'close-rectangle)
(global-set-key (kbd "C-c r d e")   'delete-rectangle)

(global-set-key (kbd "C-c r d i")   'delimit-columns-rectangle)
(global-set-key (kbd "C-c r o")     'open-rectangle)
(global-set-key (kbd "C-c r r r")   'replace-rectangle)

;;;_. boxquote

(require 'boxquote)

(global-set-key (kbd "C-c b z")   'boxquote-yank)
(global-set-key (kbd "C-c b r")   'boxquote-region)
(global-set-key (kbd "C-c b u")   'boxquote-unbox-region)
(global-set-key (kbd "C-c b t")   'boxquote-title)
(global-set-key (kbd "C-c b i")   'boxquote-insert-file)
(global-set-key (kbd "C-c b k")   'boxquote-kill)
(global-set-key (kbd "C-c b s")   'boxquote-shell-command)

(global-set-key (kbd "C-c b b")   'boxquote-buffer)
(global-set-key (kbd "C-c b p")   'boxquote-paragraph)
(global-set-key (kbd "C-c b n")   'boxquote-narrow-to-boxquote)

(global-set-key (kbd "C-c b w")   'boxquote-where-is)
(global-set-key (kbd "C-c b d f") 'boxquote-describe-function)
(global-set-key (kbd "C-c b d k") 'boxquote-describe-key)
(global-set-key (kbd "C-c b d v") 'boxquote-describe-variable)

;;;_. dynamic abbreviation

(global-set-key (kbd "M-e") 'dabbrev-expand)
(global-set-key (kbd "M-E") 'dabbrev-completion)

;;;_. open (recently) opened files using `file-name-history'

(global-set-key (kbd "C-c o") 'recentf-interactive-complete)

;;;_. ansi-term

; Do not ask for a shell to start since I am on DebianGNU/Linux with
; GNU Borne Again Shell anyways
(global-set-key (kbd "C-c a t")
                (lambda () (interactive) (ansi-term "/bin/bash")))

;;;_. my-get-file-name-with-absolute-path

; A marvelous thing indeed! Since I make statements in file X about
; file Y (e.g. referring to it) on a regular we (#emacs and I that is)
; came up with the below code.

; Put point into buffer showing the file of which you want to get the
; absolute path plus its name appended to the path and hit `M-p' (the
; path with the appended filename gets written to the kill-ring). Then
; move back to (or not) the buffer and/or position you want to have
; the path plus appended filename to be and hit `C-y'.

(defun my-get-file-name-with-absolute-path
       () (interactive)
            (message "Buffer is currently visiting the file at location: %s"

(global-set-key (kbd "M-p")
                (lambda () (interactive)

                         (kill-new (buffer-file-name))

;;;_. my-insert-filename-with-absolute-path

; I often need to input some absolute path, leading to some directory
; or file into the current buffer -- this function asks for the file
; and inputs the absolute path at point.

(defun my-insert-filename-with-absolute-path (file)
 "Interactively ask for file/directory name and insert absolute path at point."
 (interactive "FPath: ")
 (insert (expand-file-name file)))

(global-set-key (kbd "M-P") 'my-insert-filename-with-absolute-path)

;;;_. my-sum-up-region

(global-set-key (kbd "C-c C-SPC") 'my-sum-up-region)

;;;_. unbound

(global-set-key (kbd "C-c C-u") 'describe-unbound-keys)

;;;_. occur

; Use `C-u 3 M-x occur' as well to view 3 lines after/before a regex match
(global-set-key (kbd "C-c C-o") 'occur)

;;;_. my-count-lines-words-characters-region

(global-set-key (kbd "C-c C-r") 'my-count-lines-words-characters-region)

;;;_. highlight-changes-mode

(global-set-key (kbd "<s-prior>") 'highlight-changes-previous-change)
(global-set-key (kbd "<s-next>")  'highlight-changes-next-change)
(global-set-key (kbd "s-SPC")     'highlight-changes-remove-highlight)

;;;_. fortune

; See (Info-goto-node "(elisp)Shell Arguments") and
; http://www.emacswiki.org/cgi-bin/wiki/Fortune

; On DebianGNU/* install the package fortune and those language
; specifics you'd like. Also, if you want to, put your own file into
; `/usr/share/games/fortunes', use decent formating (just take a look
; at the others) and then use the command `strfile' on your file to
; create the `.dat' file of your personal fortune file.

; ,----[ Hint ]
; |  When prompted for either file or pattern just hitting RET
; |  equals the regex `*'
; `----

; ,----[ Example Usage ]
; |
; | `RET elephant RET'
; |       search ALL fortune files for quotations which contain the
; |       pattern `elephant'
; |
; | `education RET RET'
; |       output all quotations of the fortunefile `education'
; |
; | `art RET money RET'
; |       output all quotations which contain the pattern `money' AND
; |       are contained in the fortunefile called `art'
; `----

(global-set-key (kbd "C-c f")
                (lambda (file pattern)
                            "sFortunefile to take quotation from: \nsPattern to search for: ")
                                 (concat "fortune "
                                         (shell-quote-argument file)
                                         " -i -m "
                                         (shell-quote-argument pattern)
                                         " | sed 's/^%//' -"

;;;_. recenter - center point in window and redisplay frame

; By default, `C-l' is bound to `recenter' with `arg' of nil which
; means erase the entire frame and then redraw with point in the
; center of the current window. That's fine but let's also provide two
; additional positioning variants

; redraw frame and position point at the top of the buffer
(global-set-key (kbd "C-c <up>") '(lambda () (interactive) (recenter 1)))

; redraw frame and position point at the bottom of the buffer
(global-set-key (kbd "C-c <down>") '(lambda () (interactive) (recenter -1)))

;;;_. Insert date in custom formated manner

(global-set-key (kbd "C-c SPC m") 'my-date-insert-1)
(global-set-key (kbd "C-c SPC t") 'my-date-insert-2)
(global-set-key (kbd "C-c SPC T") 'my-date-insert-5)
(global-set-key (kbd "C-c SPC w") 'my-date-insert-4) ;for muse-journal.el

(setq muse-html-style-sheet "<style type=\"text/css\">\n
  margin: .4em 0 .5em 0;\n
  line-height: 1.5em;\n

  margin: 3em 0em 2em 0em;\n

  font-family: Arial, Helvetica, Futura, sans-serif;\n
  color: black;\n
  margin: 0;\n
  padding: 0;\n
  font-size: 0.95em;\n
  width: 98%;\n
  margin-left: auto;\n
  margin-right: auto;\n

  font-size: 2em;\n
  font-weight: bold;\n
  margin-top: .3em;\n
  text-align: left;\n
  padding-top: .3em;\n
  padding-right: 0.7em;\n

  background: black;\n
  color: #ffffff;\n
  border: 1px solid #000000;\n
  font-family: sans-serif;\n
  font-size: 1.5em;\n
  font-weight: bold;\n
  margin: 6em 0em 2em 0em;\n
  padding-bottom: .4em;\n
  padding-left: .5em;\n
  padding-top: .1em;\n

  border: 2px dashed #535353;\n
  font-family: sans-serif;\n
  font-size: 1.2em;\n
  font-weight: bold;\n
  margin: 3em 0em 1em 0em;\n
  padding-bottom: .2em;\n
  padding-left: .5em;\n
  padding-top: .2em;\n

  border-right: 1px dashed #535353;\n
  border-top: 1px dashed #535353;\n
  font-family: sans-serif;\n
  font-size: 1.2em;\n
  margin: 2em 0em 0em 0em;\n
  padding-bottom: .5em;\n
  padding-left: .5em;\n
  padding-top: .5em;\n

  font-family: sans-serif;\n
  font-size: 1.0em;\n
  margin: 2em 0em 0em 0em;\n
  padding-bottom: .5em;\n
  padding-left: .5em;\n
  padding-top: .5em;\n

  font-family: sans-serif;\n
  font-size: 1em;\n
  margin: 2em 3em 0em 0em;\n
  padding-bottom: .5em;\n
  padding-left: .5em;\n
  padding-top: .5em;\n

  padding: 1em;\n
  color: black;\n
  background-color: #EDEFF2;\n
  line-height: 1.1em;\n
  margin: 0em 0em 2em 1.1em;\n
  overflow: auto;\n
  width: 98%;\n

 overflow-x: auto;\n
 width: 700px;\n
 margin-left: 8em;\n

  background-color: #EDEFF2;\n


;;;_ Local emacs variables

 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(canlock-password "a2c507628f7a84656af354b9909b8d0367eb480b")
 '(ecb-options-version "2.32"))

 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t nil)))
 '(buffer-menu-delete-mark ((t (:background "Red" :foreground "white" :weight bold))))
 '(buffer-menu-modified-mark ((t (:foreground "red" :weight bold))))
 '(buffer-menu-read-only-mark ((t (:foreground "black"))))
 '(buffer-menu-save-mark ((t (:background "green" :foreground "white" :weight bold))))
 '(buffer-menu-size ((t (:foreground "black"))))
 '(buffer-menu-star-buffer ((t (:foreground "black"))))
 '(buffer-menu-time ((t (:foreground "black"))))
 '(buffer-menu-view-mark ((t (:background "LightBlue" :foreground "white" :weight bold))))
 '(compilation-error ((t (:foreground "red" :underline nil :height 100 :width condensed))))
 '(cursor ((t (:background "green"))))
 '(diff-added ((t (:inherit diff-changed :foreground "green3"))))
 '(diff-removed ((t (:inherit diff-changed :foreground "DeepSkyBlue4"))))
 '(flyspell-duplicate ((t (:background "Gold3" :foreground "black"))))
 '(flyspell-incorrect ((t (:background "red" :foreground "black"))))
 '(font-lock-comment-face ((((class color) (min-colors 88) (background light)) (:foreground "DeepSkyBlue4"))))
 '(font-lock-constant-face ((((class color) (min-colors 88) (background light)) (:foreground "green3"))))
 '(fringe ((((class color) (background light)) (:background "white"))))
 '(gnus-button ((t nil)))
 '(gnus-cite-1 ((((class color) (background light)) (:foreground "cyan4"))))
 '(gnus-cite-10 ((((class color) (background light)) (:foreground "red"))))
 '(gnus-cite-11 ((((class color) (background light)) (:background "red" :foreground "white"))))
 '(gnus-cite-2 ((((class color) (background light)) (:foreground "dodger blue"))))
 '(gnus-cite-3 ((((class color) (background light)) (:foreground "forestgreen"))))
 '(gnus-cite-4 ((((class color) (background light)) (:foreground "sienna2"))))
 '(gnus-cite-5 ((((class color) (background light)) (:foreground "orange2"))))
 '(gnus-cite-6 ((((class color) (background light)) (:foreground "maroon3"))))
 '(gnus-cite-7 ((((class color) (background light)) (:foreground "maroon2"))))
 '(gnus-cite-8 ((((class color) (background light)) (:foreground "red3"))))
 '(gnus-cite-9 ((((class color) (background light)) (:foreground "red2"))))
 '(gnus-cite-attribution ((t (:foreground "black"))))
 '(gnus-header-content ((t (:foreground "indianred4"))))
 '(gnus-header-newsgroups ((t (:foreground "MidnightBlue"))))
 '(gnus-signature ((t nil)))
 '(gnus-summary-selected ((t (:box (:line-width 1 :color "green" :style released-button)))))
 '(highlight-changes ((((min-colors 88) (class color)) (:background "gray95"))))
 '(highlight-changes-delete ((((min-colors 88) (class color)) (:background "gray80"))))
 '(mode-line ((((class color) (min-colors 88)) (:background "LightGreen" :foreground "black" :box (:line-width 2 :color "green" :style released-button) :height 0.8))))
 '(mode-line-buffer-id ((t (:foreground "black" :weight bold))))
 '(mode-line-highlight ((((class color) (min-colors 88)) (:box (:line-width 2 :color "black" :style released-button)))))
 '(mode-line-inactive ((default (:weight light :height 0.8)) (((class color) (min-colors 88) (background light)) (:background "LightBlue" :foreground "black"))))
 '(muse-bad-link ((t (:foreground "blue" :underline nil :weight normal))))
 '(muse-comment ((((class color) (background light)) (:foreground "DeepSkyBlue4"))))
 '(muse-header-1 ((t (:background "black" :foreground "white" :weight bold :height 1.5))))
 '(muse-header-2 ((t (:foreground "black" :box (:line-width 1 :color "black") :weight bold :height 1.3))))
 '(muse-header-3 ((t (:foreground "black" :weight bold :height 1.1))))
 '(muse-header-4 ((t (:foreground "grey50" :weight bold :height 1.1))))
 '(muse-header-5 ((t (:foreground "grey40" :height 0.85))))
 '(muse-link ((t (:foreground "blue" :underline nil :weight normal))))
 '(planner-delegated-task-face ((t (:foreground "grey40"))))
 '(planner-high-priority-task-face ((t (:foreground "red1"))))
 '(planner-id-face ((((class color) (background light)) (:foreground "grey60" :height 0.9))))
 '(planner-in-progress-task-face ((t (:weight bold :height 1.3))))
 '(planner-low-priority-task-face ((t (:foreground "black"))))
 '(planner-medium-priority-task-face ((t (:foreground "orange"))))
 '(planner-note-headline-face ((t (:foreground "black" :height 1.0))))
 '(region ((((class color) (min-colors 88) (background light)) (:background "LightBlue"))))
 '(vertical-border ((nil (:foreground "white")))))

;;;Local Variables:
;;;allout-layout: (0 : 0)