+;;;--------------------------------------------------------------------------
+;;; Org-mode hacking.
+
+(defadvice org-agenda-list (around mdw-preserve-links activate)
+ (let ((mdw-diary-for-org-mode-p t))
+ ad-do-it))
+
+(defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
+ "Return a string rather than a list."
+ (with-temp-buffer
+ (let ((anyp nil))
+ (dolist (e (let ((ee ad-return-value))
+ (if (atom ee) (list ee) ee)))
+ (when e
+ (when anyp (insert ?\n))
+ (insert e)
+ (setq anyp t)))
+ (setq ad-return-value
+ (and anyp (buffer-string))))))
+
+;; Fighting with Org-mode's evil key maps.
+
+(defcustom mdw-evil-keymap-keys
+ '(([S-up] . [?\C-c up])
+ ([S-down] . [?\C-c down])
+ ([S-left] . [?\C-c left])
+ ([S-right] . [?\C-c right])
+ (([M-up] [?\e up]) . [C-up])
+ (([M-down] [?\e down]) . [C-down])
+ (([M-left] [?\e left]) . [C-left])
+ (([M-right] [?\e right]) . [C-right]))
+ "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
+The value is an alist mapping evil keys (as a list, or singleton)
+to good keys (in the same form)."
+ :type '(alist :key-type (choice key-sequence (repeat key-sequence))
+ :value-type key-sequence))
+
+(defun mdw-clobber-evil-keymap (keymap)
+ "Replace evil key bindings in the KEYMAP.
+Evil key bindings are defined in `mdw-evil-keymap-keys'."
+ (dolist (entry mdw-evil-keymap-keys)
+ (let ((binding nil)
+ (keys (if (listp (car entry))
+ (car entry)
+ (list (car entry))))
+ (replacements (if (listp (cdr entry))
+ (cdr entry)
+ (list (cdr entry)))))
+ (catch 'found
+ (dolist (key keys)
+ (setq binding (lookup-key keymap key))
+ (when binding
+ (throw 'found nil))))
+ (when binding
+ (dolist (key keys)
+ (define-key keymap key nil))
+ (dolist (key replacements)
+ (define-key keymap key binding))))))
+
+(defcustom mdw-org-latex-defs
+ '(("strayman"
+ "\\documentclass{strayman}
+\\usepackage[utf8]{inputenc}
+\\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
+\\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
+ ("\\section{%s}" . "\\section*{%s}")
+ ("\\subsection{%s}" . "\\subsection*{%s}")
+ ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
+ ("\\paragraph{%s}" . "\\paragraph*{%s}")
+ ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
+ "Additional LaTeX class definitions."
+ :type '(alist :key-type string
+ :value-type (list string
+ (alist :inline t
+ :key-type string
+ :value-type string))))
+
+(setq org-emphasis-regexp-components
+ '("- \t('\"{}" ; prematch
+ "- \t.,:!?;'\")}\\[" ; postmatch
+ " \t\r\n" ; /forbidden/ as border
+ "." ; body regexp
+ 1)) ; maximum newlines
+
+(setq org-entities-user
+ ;; NAME LATEX MATHP HTML ASCII LATIN1 UTF8
+ '(("relax" "" nil "" "" "" "")))
+
+(eval-after-load "org-latex"
+ '(setq org-export-latex-classes
+ (append mdw-org-latex-defs org-export-latex-classes)))
+
+(eval-after-load "ox-latex"
+ '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
+ org-latex-caption-above nil
+ org-latex-default-packages-alist '(("AUTO" "inputenc" t)
+ ("T1" "fontenc" t)
+ ("" "fixltx2e" nil)
+ ("" "graphicx" t)
+ ("" "longtable" nil)
+ ("" "float" nil)
+ ("" "wrapfig" nil)
+ ("" "rotating" nil)
+ ("normalem" "ulem" t)
+ ("" "textcomp" t)
+ ("" "marvosym" t)
+ ("" "wasysym" t)
+ ("" "amssymb" t)
+ ("" "hyperref" nil)
+ "\\tolerance=1000")))
+
+(setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
+ org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
+ org-export-docbook-xslt-stylesheet
+ "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
+