+'(iswitchb-mode on)
+(custom-set-faces
+ ;; 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.
+ '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
+
+(defun ess-change-directory (path)
+ "Set the current working directory to PATH for both *R* and Emacs."
+ (interactive "DDirectory to change to: ")
+
+ (when (file-exists-p path)
+ (ess-command (concat "setwd(\"" path "\")\n"))
+ ;; use file-name-as-directory to ensure it has trailing /
+ (setq default-directory (file-name-as-directory path))))
+
+(put 'upcase-region 'disabled nil)
+(put 'downcase-region 'disabled nil)
+(put 'narrow-to-region 'disabled nil)
+
+;; The following lines are always needed. Choose your own keys.
+(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
+(add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when global-font-lock-mode is on
+(global-set-key "\C-cl" 'org-store-link)
+(global-set-key "\C-ca" 'org-agenda)
+(global-set-key "\C-cb" 'org-iswitchb)
+(setq-default org-log-done 'time)
+(setq-default org-agenda-ndays 5)
+
+
+(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
+(add-hook 'message-mode-hook 'turn-on-flyspell)
+(add-hook 'text-mode-hook 'turn-on-flyspell)
+(add-hook 'c-mode-common-hook 'flyspell-prog-mode)
+(add-hook 'cperl-mode-hook 'flyspell-prog-mode)
+(add-hook 'tcl-mode-hook 'flyspell-prog-mode)
+(add-hook 'ess-mode-hook 'flyspell-prog-mode)
+(defun turn-on-flyspell ()
+ "Force flyspell-mode on using a positive arg. For use in hooks."
+ (interactive)
+ (flyspell-mode 1))
+
+;;; outlining support for ess modes
+(add-hook 'ess-mode-hook
+ '(lambda ()
+ (outline-minor-mode)
+ (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
+ (defun outline-level ()
+ (cond ((looking-at "^##### ") 1)
+ ((looking-at "^#### ") 2)
+ ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
+ (t 1000)))
+ ))
+
+ ; Outline-minor-mode key map
+ (define-prefix-command 'cm-map nil "Outline-")
+ ; HIDE
+ (define-key cm-map "q" 'hide-sublevels) ; Hide everything but the top-level headings
+ (define-key cm-map "t" 'hide-body) ; Hide everything but headings (all body lines)
+ (define-key cm-map "o" 'hide-other) ; Hide other branches
+ (define-key cm-map "c" 'hide-entry) ; Hide this entry's body
+ (define-key cm-map "l" 'hide-leaves) ; Hide body lines in this entry and sub-entries
+ (define-key cm-map "d" 'hide-subtree) ; Hide everything in this entry and sub-entries
+ ; SHOW
+ (define-key cm-map "a" 'show-all) ; Show (expand) everything
+ (define-key cm-map "e" 'show-entry) ; Show this heading's body
+ (define-key cm-map "i" 'show-children) ; Show this heading's immediate child sub-headings
+ (define-key cm-map "k" 'show-branches) ; Show all sub-headings under this heading
+ (define-key cm-map "s" 'show-subtree) ; Show (expand) everything in this heading & below
+ ; MOVE
+ (define-key cm-map "u" 'outline-up-heading) ; Up
+ (define-key cm-map "n" 'outline-next-visible-heading) ; Next
+ (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
+ (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
+ (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
+ (global-set-key "\M-o" cm-map)
+
+(defun my-org-mode-setup ()
+ (load-library "reftex")
+ (and (buffer-file-name)
+ (file-exists-p (buffer-file-name))
+ (progn
+ (reftex-parse-all)
+ (reftex-set-cite-format
+ '((?b . "[[bib::%l][%l-bib]]")
+ (?n . "[[note::%l][%l-notes]]")
+ (?c . "\\cite{%l}")
+ (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l paper]]")))
+ ))
+ (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
+ (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
+ (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
+ (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
+ )
+(add-hook 'org-mode-hook 'my-org-mode-setup)
+
+(defun org-mode-reftex-search ()
+ (interactive)
+ (org-open-link-from-string (format "[[notes:%s]]" (reftex-citation t))))
+
+(defun open-research-paper (bibtexkey)
+ "Open a paper by bibtex key"
+ (interactive "bibtex key: ")
+ (shell-command
+ (format "%s %s"
+ (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
+(org-add-link-type "papers" 'open-research-paper)
+
+; I pretty much always want hiearchical checkboxes
+(setq org-hierachical-checkbox-statistics nil)
+
+;; stolen from
+;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
+(defun my-rtcite-export-handler (path desc format)
+ (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
+ (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
+ (match-string 1 path)))
+ (path (substring path 0 (match-beginning 0))))
+ (cond ((eq format 'latex)
+ (if (or (not desc)
+ (equal 0 (search "rtcite:" desc)))
+ (format "\\cite{%s}" search)
+ (format "\\cite[%s]{%s}" desc search))))))
+
+(org-add-link-type "rtcite"
+ 'org-bibtex-open
+ 'my-rtcite-export-handler)
+
+
+(setq-default org-mobile-directory "/rzlab.ucr.edu:/sites/dav.donarmstrong.com/root/org/")
+(setq-default org-directory "/home/don/org-mode/")
+(setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
+
+;; org mode ical export
+(setq org-icalendar-timezone "America/Los_Angeles")
+(setq org-icalendar-use-scheduled '(todo-start event-if-todo))
+(setq org-icalendar-store-UID t)
+
+;; org babel support
+(org-babel-do-load-languages
+ 'org-babel-load-languages
+ '((emacs-lisp . t )
+ (R . t)
+ (latex . t)))
+;; org-babel-by-backend
+(defmacro org-babel-by-backend (&rest body)
+ `(case (if (boundp 'backend)
+ (org-export-backend-name backend)
+ nil) ,@body))
+
+
+
+;; org latex
+;; stolen from http://kieranhealy.org/esk/kjhealy.html
+(require 'org-latex)
+;; Choose either listings or minted for exporting source code blocks.
+;; Using minted (as here) requires pygments be installed. To use the
+;; default listings package instead, use
+;; (setq org-latex-listings t)
+;; and change references to "minted" below to "listings"
+; (setq org-latex-listings 'minted)
+
+;; default settings for minted code blocks
+(setq org-latex-minted-options
+ '(;("frame" "single")
+ ("bgcolor" "bg") ; bg will need to be defined in the preamble of your document. It's defined in org-preamble-pdflatex.sty and org-preamble-xelatex.sty below.
+ ("fontsize" "\\small")
+ ))
+;; turn off the default toc behavior; deal with it properly in headers to files.
+(defun org-latex-no-toc (depth)
+ (when depth
+ (format "%% Org-mode is exporting headings to %s levels.\n"
+ depth)))
+(setq org-latex-format-toc-function 'org-latex-no-toc)
+
+(require 'ox-latex)
+(add-to-list 'org-latex-classes
+ '("memarticle"
+ "\\documentclass[11pt,oneside,article]{memoir}\n"
+ ("\\section{%s}" . "\\section*{%s}")
+ ("\\subsection{%s}" . "\\subsection*{%s}")
+ ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
+ ("\\paragraph{%s}" . "\\paragraph*{%s}")
+ ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
+
+(add-to-list 'org-latex-classes
+ '("membook"
+ "\\documentclass[11pt,oneside]{memoir}\n"
+ ("\\chapter{%s}" . "\\chapter*{%s}")
+ ("\\section{%s}" . "\\section*{%s}")
+ ("\\subsection{%s}" . "\\subsection*{%s}")
+ ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
+
+(add-to-list 'org-latex-classes
+ '("letter"
+ "\\documentclass[11pt]{letter}
+[NO-DEFAULT-PACKAGES]
+[PACKAGES]
+[EXTRA]"
+ ("\\section{%s}" . "\\section*{%s}")
+ ("\\subsection{%s}" . "\\subsection*{%s}")
+ ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
+ ("\\paragraph{%s}" . "\\paragraph*{%s}")
+ ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
+
+;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
+;; but adapted to use latexmk 4.22 or higher.
+(setq org-latex-pdf-process '("latexmk -pdflatex=xelatex -bibtex -use-make -pdf %f"))
+
+;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
+(setq org-latex-default-packages-alist
+ '())
+(setq org-latex-packages-alist
+ '(("" "graphicx" t)
+ ("" "fontspec" t)
+ ("" "xunicode" t)
+ ("" "hyperref" t)
+ ("" "url" t)
+ ("" "rotating" t)
+ ("" "longtable" nil)
+ ("" "float" )))
+
+(defun org-create-formula--latex-header ()
+ "Return LaTeX header appropriate for previewing a LaTeX snippet."
+ (let ((info (org-combine-plists (org-export--get-global-options
+ (org-export-get-backend 'latex))
+ (org-export--get-inbuffer-options
+ (org-export-get-backend 'latex)))))
+ (org-latex-guess-babel-language
+ (org-latex-guess-inputenc
+ (org-splice-latex-header
+ org-format-latex-header
+ org-latex-default-packages-alist
+ nil t
+ (plist-get info :latex-header)))
+ info)))
+
+
+; support ignoring headers in org mode export to latex
+; from http://article.gmane.org/gmane.emacs.orgmode/67692
+(defadvice org-latex-headline (around my-latex-skip-headlines
+ (headline contents info) activate)
+ (if (member "ignoreheading" (org-element-property :tags headline))
+ (setq ad-return-value contents)
+ ad-do-it))
+
+; debian stuff
+(setq-default debian-changelog-mailing-address "don@debian.org")
+(setq-default debian-changelog-full-name "Don Armstrong")
+
+; ediff configuration
+; don't use the multi-window configuration
+(setq ediff-window-setup-function 'ediff-setup-windows-plain)
+
+; use iedit
+(require 'iedit)
+(define-key global-map (kbd "C-;") 'iedit-mode)
+(global-set-key (kbd "C-;") 'iedit-mode)
+
+; fix up css mode to not be silly
+; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
+(setq cssm-indent-level 4)
+(setq cssm-newline-before-closing-bracket t)
+(setq cssm-indent-function #'cssm-c-style-indenter)
+(setq cssm-mirror-mode nil)
+
+(require 'multi-web-mode)
+(setq mweb-default-major-mode 'html-mode)
+(setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
+ (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
+ (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
+(setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
+(multi-web-global-mode 1)
+
+; clean-mode-line from http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
+(defvar mode-line-cleaner-alist
+ `((auto-complete-mode . " α")
+ (yas/minor-mode . " υ")
+ (paredit-mode . " π")
+ (eldoc-mode . "")
+ (abbrev-mode . "")
+ (my-keys-minor-mode . "")
+ ;; Major modes
+ (lisp-interaction-mode . "λ")
+ (hi-lock-mode . "")
+ (python-mode . "Py")
+ (cperl-mode . "ρ")
+ (auctex-mode . "Lχ")
+ (org-agenda-mode . "øα")
+ (org-mode . "ø")
+ (emacs-lisp-mode . "EL")
+ (nxhtml-mode . "nx"))
+ "Alist for `clean-mode-line'.
+
+When you add a new element to the alist, keep in mind that you
+must pass the correct minor/major mode symbol and a string you
+want to use in the modeline *in lieu of* the original.")
+
+
+(defun clean-mode-line ()
+ (interactive)
+ (loop for cleaner in mode-line-cleaner-alist
+ do (let* ((mode (car cleaner))
+ (mode-str (cdr cleaner))
+ (old-mode-str (cdr (assq mode minor-mode-alist))))
+ (when old-mode-str
+ (setcar old-mode-str mode-str))
+ ;; major mode
+ (when (eq mode major-mode)
+ (setq mode-name mode-str)))))
+
+
+(add-hook 'after-change-major-mode-hook 'clean-mode-line)
+
+;;; alias the new `flymake-report-status-slim' to
+;;; `flymake-report-status'
+(defalias 'flymake-report-status 'flymake-report-status-slim)
+(defun flymake-report-status-slim (e-w &optional status)
+ "Show \"slim\" flymake status in mode line."
+ (when e-w
+ (setq flymake-mode-line-e-w e-w))
+ (when status
+ (setq flymake-mode-line-status status))
+ (let* ((mode-line " Φ"))
+ (when (> (length flymake-mode-line-e-w) 0)
+ (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
+ (setq mode-line (concat mode-line flymake-mode-line-status))
+ (setq flymake-mode-line mode-line)
+ (force-mode-line-update)))
+
+; load sql-indent when sql is loaded
+(eval-after-load "sql"
+ '(load-library "sql-indent"))
+
+; fix up tmux xterm keys
+; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
+(if (getenv "TMUX")
+ (progn
+ (let ((x 2) (tkey ""))
+ (while (<= x 8)
+ ;; shift
+ (if (= x 2)
+ (setq tkey "S-"))
+ ;; alt
+ (if (= x 3)
+ (setq tkey "M-"))
+ ;; alt + shift
+ (if (= x 4)
+ (setq tkey "M-S-"))
+ ;; ctrl
+ (if (= x 5)
+ (setq tkey "C-"))
+ ;; ctrl + shift
+ (if (= x 6)
+ (setq tkey "C-S-"))
+ ;; ctrl + alt
+ (if (= x 7)
+ (setq tkey "C-M-"))
+ ;; ctrl + alt + shift
+ (if (= x 8)
+ (setq tkey "C-M-S-"))
+
+ ;; arrows
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
+ ;; home
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
+ ;; end
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
+ ;; page up
+ (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
+ ;; page down
+ (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
+ ;; insert
+ (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
+ ;; delete
+ (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
+ ;; f1
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
+ ;; f2
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
+ ;; f3
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
+ ;; f4
+ (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
+ ;; f5
+ (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
+ ;; f6
+ (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
+ ;; f7
+ (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
+ ;; f8
+ (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
+ ;; f9
+ (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
+ ;; f10
+ (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
+ ;; f11
+ (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
+ ;; f12
+ (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
+ ;; f13
+ (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
+ ;; f14
+ (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
+ ;; f15
+ (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
+ ;; f16
+ (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
+ ;; f17
+ (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
+ ;; f18
+ (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
+ ;; f19
+ (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
+ ;; f20
+ (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
+
+ (setq x (+ x 1))
+ ))
+ )
+ )
+
+; apparently things like to step on C-;, so we'll use a hack from
+; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
+
+(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
+
+; use iedit everywhere
+(define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
+
+(define-minor-mode my-keys-minor-mode
+ "A minor mode so that my key settings override annoying major modes."
+ t " my-keys" 'my-keys-minor-mode-map)
+
+(my-keys-minor-mode 1)
+(defun my-minibuffer-setup-hook ()
+ (my-keys-minor-mode 0))
+
+(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
+(defadvice load (after give-my-keybindings-priority)
+ "Try to ensure that my keybindings always have priority."
+ (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
+ (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
+ (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
+ (add-to-list 'minor-mode-map-alist mykeys))))
+(ad-activate 'load)