]> git.donarmstrong.com Git - emacs.git/blob - .emacs
350375cf61d01d4697e385535893b15447f62ae3
[emacs.git] / .emacs
1 (custom-set-variables
2  ;; custom-set-variables was added by Custom.
3  ;; If you edit it by hand, you could mess it up, so be careful.
4  ;; Your init file should contain only one such instance.
5  ;; If there is more than one, they won't work right.
6  '(bibtex-user-optional-fields (quote (("annote" "Personal annotation (ignored)") ("abstract" "") ("pmid" "") ("doi" ""))))
7  '(calendar-latitude [33 57 north])
8  '(calendar-longitude [117 24 west])
9  '(case-fold-search t)
10  '(confirm-kill-emacs (quote y-or-n-p))
11  '(cperl-lazy-help-time nil)
12  '(debian-changelog-mailing-address "don@debian.org" t)
13  '(display-time t)
14  '(display-time-24hr-format t)
15  '(display-time-day-and-date t)
16  '(display-time-mode t)
17  '(font-latex-fontify-script nil)
18  '(font-latex-fontify-sectioning (quote color))
19  '(font-latex-script-display (quote (nil)))
20  '(global-auto-revert-mode t)
21  '(global-font-lock-mode t nil (font-lock))
22  '(global-set-key "\347" t)
23  '(iswitchb-mode t)
24  '(iswitchb-prompt-newbuffer nil)
25  '(log-edit-keep-buffer t)
26  '(mail-user-agent (quote sendmail-user-agent))
27  '(markdown-enable-math t)
28  '(markdown-follow-wiki-link-on-enter nil)
29  '(mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
30  '(post-email-address "don@donarmstrong.com")
31  '(post-kill-quoted-sig nil)
32  '(post-mail-message "mutt\\(ng\\|\\)-[a-z0-9]+-[0-9]+-.*")
33  '(post-uses-fill-mode nil)
34  '(ps-footer-font-size (quote (8 . 10)))
35  '(ps-header-font-size (quote (8 . 10)))
36  '(ps-header-title-font-size (quote (10 . 10)))
37  '(ps-line-number-color "blue")
38  '(ps-print-footer t)
39  '(ps-print-footer-frame nil)
40  '(ps-print-only-one-header t)
41  '(safe-local-variable-values (quote ((auto-save-default) (make-backup-files))))
42  '(sentence-end "[.?!][]\"')]*\\($\\|   \\| \\)[        
43 ]*")
44  '(sentence-end-double-space nil)
45  '(show-paren-mode t)
46  '(tool-bar-mode nil nil (tool-bar))
47  '(user-mail-address "don@donarmstrong.com")
48  '(vc-delete-logbuf-window nil)
49  '(vc-follow-symlinks t))
50
51 ;; use git before SVN; use CVS earlier, because I have CVS
52 ;; repositories inside of git directories
53 (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
54
55 ;; switch back to the old primary selection method
56 (setq x-select-enable-clipboard nil)
57 (setq x-select-enable-primary t)
58 ; (setq mouse-drag-copy-region t)
59
60 (fset 'perl-mode 'cperl-mode)
61 ;;(load-file "cperl-mode.el")
62 (add-to-list 'load-path '"~/lib/emacs_el/")
63 ;; this is the tiny-tools module from https://github.com/jaalto/project--emacs-tiny-tools.git
64 (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/tiny")
65 (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/other")
66 ;;(add-to-list 'Tex-style-path '"~/lib/emacs_el/auctex/")
67
68 (setq tinyprocmail--procmail-version "v3.22")
69 (add-hook 'tinyprocmail--load-hook 'tinyprocmail-install)
70 (require 'tinyprocmail)
71
72 (require 'vcl-mode)
73
74 (require 'tex-site)
75 ;;(require 'psvn)
76 (require 'cperl-mode)
77 ;;(require 'ecasound)
78 ;;(require 'emacs-wiki)
79 (require 'bibtex)
80 (require 'post)
81 ;;(require 'fixme)
82 (require 'google-weather)
83 (require 'org-google-weather)
84 (setq-default org-google-weather-format "%i %c, [%l,%h] %s %C")
85
86 ; http://julien.danjou.info/projects/emacs-packages#rainbow-mode
87 ; this colorizes color strings
88 (require 'rainbow-mode)
89 ; add ess to the x major mode
90 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
91 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
92
93 ; org mode agenda files
94 (setq org-agenda-files
95       (quote ("~/projects/debbugs/debbugs.org"
96               "~/projects/notes/notes.org"
97               "~/projects/origins_of_life/ool.org"
98               "~/projects/sysadmin/sndservers/sndservers.org"
99               "~/projects/chaim/chaim.org"
100               "~/projects/chaim/papers/gwas_paper_2012/gwas_paper.org"
101           "~/projects/reviews/reviews.org"
102               "~/projects/fh/fh.org")))
103
104 (setq org-global-properties '(("Effort_ALL 0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
105 (setq org-columns-default-format "%40ITEM(Task) %TAGS %PRIORITY %TODO %13SCHEDULED %13DEADLINE %6Effort{:}  %CLOCKSUM")
106
107 (setq org-default-notes-file "~/projects/notes/notes.org")
108 (setq org-capture-templates  ;; mail-specific note template, identified by "m"
109       '(("m" "Mail" entry (file+headline "~/projects/notes/refile.org" "Mail")
110          "* %?\n\n  Source: %u, %c\n  %i")
111         ("t" "todo" entry (file "~/projects/notes/refile.org")
112          "* TODO %?\n%U\n%a\n" :clock-in t :clock-resume t)
113         ("r" "respond" entry (file "~/projects/notes/refile.org")
114          "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
115         ("n" "note" entry (file "~/projects/notes/refile.org")
116          "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
117         ("j" "Journal" entry (file+datetree "~/projects/notes/diary.org")
118          "* %?\n%U\n" :clock-in t :clock-resume t)
119         ("w" "org-protocol" entry (file "~/projects/notes/refile.org")
120          "* TODO Review %c\n%U\n" :immediate-finish t)
121         ("p" "Phone call" entry (file "~/projects/notes/refile.org")
122          "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
123         ("h" "Habit" entry (file "~/projects/notes/refile.org")
124          "* NEXT %?\n%U\n%a\nSCHEDULED: %(format-time-string \"<%Y-%m-%d %a .+1d/3d>\")\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n")
125         )
126       )
127
128 ;; Remove empty LOGBOOK drawers on clock out
129 (defun bh/remove-empty-drawer-on-clock-out ()
130   (interactive)
131   (save-excursion
132     (beginning-of-line 0)
133     (org-remove-empty-drawer-at "LOGBOOK" (point))))
134
135 (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
136
137
138 ; resolve clocks after 10 minutes of idle; use xprintidle
139 (setq org-clock-idle-time 10)
140 (setq org-clock-x11idle-program-name "xprintidle")
141
142 ; this is from http://doc.norang.ca/org-mode.html#Capture
143 ; use C-M-r for org mode capture
144 (global-set-key (kbd "C-M-r") 'org-capture)
145
146 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
147 (setq org-refile-targets (quote ((nil :maxlevel . 9)
148                                  (org-agenda-files :maxlevel . 9))))
149
150 ; Use full outline paths for refile targets - we file directly with IDO
151 (setq org-refile-use-outline-path t)
152
153 ; Targets complete directly with IDO
154 (setq org-outline-path-complete-in-steps nil)
155
156 ; Allow refile to create parent tasks with confirmation
157 (setq org-refile-allow-creating-parent-nodes (quote confirm))
158
159 ; Use IDO for both buffer and file completion and ido-everywhere to t
160 (setq org-completion-use-ido t)
161 (setq ido-everywhere t)
162 (setq ido-max-directory-size 100000)
163 (ido-mode (quote both))
164
165 ;;;; Refile settings
166 ; Exclude DONE state tasks from refile targets
167 (defun bh/verify-refile-target ()
168   "Exclude todo keywords with a done state from refile targets"
169   (not (member (nth 2 (org-heading-components)) org-done-keywords)))
170
171 (setq org-refile-target-verify-function 'bh/verify-refile-target)
172
173 ;; ensure that emacsclient will show just the note to be edited when invoked
174 ;; from Mutt, and that it will shut down emacsclient once finished;
175 ;; fallback to legacy behavior when not invoked via org-protocol.
176 (require 'org-protocol)
177 (add-hook 'org-capture-mode-hook 'delete-other-windows)
178 (setq my-org-protocol-flag nil)
179 (defadvice org-capture-finalize (after delete-frame-at-end activate)
180   "Delete frame at remember finalization"
181   (progn (if my-org-protocol-flag (delete-frame))
182          (setq my-org-protocol-flag nil)))
183 (defadvice org-capture-refile (around delete-frame-after-refile activate)
184   "Delete frame at remember refile"
185   (if my-org-protocol-flag
186       (progn
187         (setq my-org-protocol-flag nil)
188         ad-do-it
189         (delete-frame))
190     ad-do-it)
191   )
192 (defadvice org-capture-kill (after delete-frame-at-end activate)
193   "Delete frame at remember abort"
194   (progn (if my-org-protocol-flag (delete-frame))
195          (setq my-org-protocol-flag nil)))
196 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
197   (setq my-org-protocol-flag t))
198
199
200 ;; org modules
201 (add-to-list 'org-modules 'org-habit)
202
203 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
204 (defun open-mail-in-mutt (message)
205   "Open a mail message in Mutt, using an external terminal.
206
207 Message can be specified either by a path pointing inside a
208 Maildir, or by Message-ID."
209   (interactive "MPath or Message-ID: ")
210   (shell-command
211    (format "xterm -e \"%s %s\""
212        (substitute-in-file-name "$HOME/bin/mutt_open") message)))
213
214 ;; add support for "mutt:ID" links
215 (org-add-link-type "mutt" 'open-mail-in-mutt)
216
217
218 (global-set-key "\C-xp" 'server-edit)
219
220 (setq-default auto-mode-alist (cons '("\.wml$" . 
221                               (lambda () (html-mode) (auto-fill-mode)))
222                             auto-mode-alist))
223
224 ;; Use c-mode for perl .xs files
225 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
226 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
227 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
228 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
229 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
230
231 ; use markdown mode for mdwn files
232 (add-to-list 'auto-mode-alist '("\\.mdwn$" . markdown-mode))
233
234
235
236
237 ; mail configuration
238 (add-to-list 'auto-mode-alist '("muttng-[a-z0-9]+-[0-9]+-" . message-mode))
239 (add-to-list 'auto-mode-alist '("muttngrc" . muttrc-mode))
240
241 (add-to-list 'auto-mode-alist '("mutt-[a-z0-9]+-[0-9]+-" . message-mode))
242 (add-to-list 'auto-mode-alist '("muttrc" . muttrc-mode))
243 (defun my-message-mode-settings ()
244   (font-lock-add-keywords nil
245                           '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
246                              (0 'message-multiply-quoted-text-face))
247                             ("^[ \t]*>[ \t]*>.*$"
248                              (0 'message-double-quoted-text-face))))
249   (local-set-key (kbd "C-c C-a") 'my-post-attach-file)
250   )
251 (add-hook 'message-mode-hook 'my-message-mode-settings)
252
253 (defun my-post-attach-file ()
254   "Prompt for an attachment."
255   (interactive)
256   (let ((file (read-file-name "Attach file: " nil nil t nil))
257         (description (string-read "Description: ")))
258     (my-header-attach-file file description)))
259
260 (symbol-function 'my-post-attach-file)
261
262 (defun my-header-attach-file (file description)
263   "Attach a FILE to the current message (works with Mutt).
264 Argument DESCRIPTION MIME description."
265   (interactive "fAttach file: \nsDescription: ")
266   (when (> (length file) 0)
267     (save-excursion
268       (save-match-data
269         (save-restriction
270           (widen)
271           (goto-char (point-min))
272           (search-forward-regexp "^$")
273           (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
274                           description "\n"))
275           (message (concat "Attached '" file "'."))
276           (setq post-has-attachment t))))))
277
278
279
280 (setq mail-yank-prefix "> ")
281
282 (global-unset-key "\M-g")
283 (global-set-key "\M-g" 'goto-line)
284
285 ;;(autoload 'perl-mode "cperl-mode"
286 ;;  "alternate mode for editing Perl programs" t)
287
288 ;; self-insert-command hack.
289 ;;   Without this, "if<SP>" expands to
290 ;;   if ( -!-) {
291 ;;   }
292 ;;   which really should be,
293 ;;   if (-!-) {
294 ;;   }
295 (setq cperl-hairy t
296       cperl-indent-level 4
297       cperl-auto-newline nil
298       cperl-auto-newline-after-colon nil
299       cperl-continued-statement-offset 4
300       cperl-brace-offset -1
301       cperl-continued-brace-offset 0
302       cperl-label-offset -4
303       cperl-highlight-variables-indiscriminately t
304       cperl-electric-lbrace-space nil
305       cperl-indent-parens-as-block nil
306       cperl-close-paren-offset -1
307       cperl-tab-always-indent t)
308 ;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
309
310
311
312 ;(load-library "php-mode")
313
314 (setq-default c-indent-level 4)
315 (setq-default c-brace-imaginary-offset 0)
316 (setq-default c-brace-offset -4)
317 (setq-default c-argdecl-indent 4)
318 (setq-default c-label-offset -4)
319 (setq-default c-continued-statement-offset 4)
320 ; tabs are annoying
321 (setq-default indent-tabs-mode nil)
322 (setq-default tab-width 4)
323
324
325 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
326 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
327 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
328 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
329 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
330
331 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
332 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
333 (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
334 (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
335 (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
336 (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
337 (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
338 (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
339 (add-hook 'LaTeX-mode-hook 'outline-minor-mode)   ; with AUCTeX LaTeX mode
340 (add-hook 'latex-mode-hook 'outline-minor-mode)   ; with Emacs latex mode
341
342 ; use smart quotes by default instead of `` and ''
343 ; taken from http://kieranhealy.org/esk/kjhealy.html
344 (setq TeX-open-quote "“")
345 (setq TeX-close-quote "”")
346
347 ;; (TeX-add-style-hook
348 ;;  "latex"
349 ;;  (lambda ()
350 ;;    (TeX-add-symbols
351 ;;     '("DLA" 1))))
352 ;; (custom-set-variables
353 ;;  '(font-latex-user-keyword-classes 
354 ;;    '(("fixme" 
355 ;;       ("DLA" "RZ")
356 ;;       font-lock-function-name-face 2 (command 1 t))))
357 ;; ) 
358
359 (require 'font-latex)
360 (setq font-latex-match-reference-keywords
361       '(
362         ("fref" "{")
363         ("Fref" "{")
364         ("citep" "{")
365         ("citet" "{")
366         ("acs" "{")
367         ("acsp" "{")
368         ("ac" "{")
369         ("acp" "{")
370         ("acl" "{")
371         ("aclp" "{")
372         ("acsu" "{")
373         ("aclu" "{")
374         ("acused" "{")
375 ;         ))
376 ; (setq font-latex-match-warning-keywords
377 ;       '(
378         ("DLA" "{")
379         ("RZ" "{")
380         ("OM" "{")
381         ("DL" "{")
382         ("fixme" "{")))
383       
384 (setq-default TeX-parse-self t)
385 (setq-default TeX-auto-save t)
386 (setq-default TeX-master nil)
387
388 ;; this doesn't seem to work; not currently sure why
389 ; (setq font-latex-user-keyword-classes
390 ;       '(("my-warning-commands"
391 ;          (("DLA" "{")
392 ;           ("RZ" "{")
393 ;           ("OM" "{")
394 ;           ("DL" "{")
395 ;           ("fixme" "{")
396 ;           )
397 ;          (:foreground "red" :weight bold :underline (:color foreground-color :style line)))
398 ;         ))
399
400
401 (defun insert-date ()
402   "Insert date at point."
403   (interactive)
404   (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
405 (global-set-key "\C-[d" 'insert-date)
406
407 (defun unfill-paragraph (arg)
408   "Pull this whole paragraph up onto one line."
409   (interactive "*p")
410   (let ((fill-column 10000))
411     (fill-paragraph arg))
412   )
413
414 ;(iswitchb-default-keybindings)
415
416 (column-number-mode t)
417 (setq-default reftex-plug-into-AUCTeX t)
418
419 (server-start)
420
421 (require 'mode-compile)
422
423 (setq-default reftex-default-bibliography
424       '("references.bib"))
425
426 (defadvice server-process-filter (after post-mode-message first activate)
427   "If the buffer is in post mode, overwrite the server-edit
428     message with a post-save-current-buffer-and-exit message."
429   (if (eq major-mode 'post-mode)
430       (message
431        (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
432                                         ; This is also needed to see the magic message.  Set to a higher
433                                         ; number if you have a faster computer or read slower than me.
434 '(font-lock-verbose 1000)
435 ;(setq-default server-temp-file-regexp "mutt\(-\|ng-\)")
436 ; (add-hook 'server-switch-hook 
437 ;         (function (lambda()
438 ;                     (cond ((string-match "Post" mode-name)
439 ;                            (post-goto-body)))
440 ;                     set-buffer-file-coding-system 'utf-8
441 ;                     )))
442
443
444 (add-hook 'post-mode-hook
445           (auto-fill-mode nil)
446           )
447 ; abbrev mode settings
448 ; load abbreviations from 
449 (setq abbrev-file-name       
450       "~/.emacs_abbrev_def")
451
452 ; read the abbrev file if it exists
453 (if (file-exists-p abbrev-file-name)
454     (quietly-read-abbrev-file))
455
456 ; for now, use abbrev mode everywhere
457 (setq default-abbrev-mode t)
458
459
460 (defun insert-function-documentation ()
461   "Insert function documentation"
462   (interactive)
463   (insert-file-contents "/home/don/lib/templates/perl_function_documentation" nil))
464 (global-set-key "\M-f" 'insert-function-documentation)
465
466 (eval-after-load "lilypond-mode" 
467   '(progn
468      (load-library "lyqi-mode")
469      (define-key LilyPond-mode-map "\C-cq" 'lyqi-mode)))
470
471 (autoload 'spamassassin-mode "spamassassin-mode" nil t)
472
473 (desktop-load-default)
474 (desktop-read)
475 '(iswitchb-mode on)
476 (custom-set-faces
477  ;; custom-set-faces was added by Custom.
478  ;; If you edit it by hand, you could mess it up, so be careful.
479  ;; Your init file should contain only one such instance.
480  ;; If there is more than one, they won't work right.
481  '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
482
483 (defun ess-change-directory (path)
484   "Set the current working directory to PATH for both *R* and Emacs."
485   (interactive "DDirectory to change to: ")
486
487   (when (file-exists-p path)
488     (ess-command (concat "setwd(\"" path "\")\n"))
489     ;; use file-name-as-directory to ensure it has trailing /
490     (setq default-directory (file-name-as-directory path))))
491
492 (put 'upcase-region 'disabled nil)
493 (put 'downcase-region 'disabled nil)
494 (put 'narrow-to-region 'disabled nil)
495
496 ;; The following lines are always needed. Choose your own keys.
497 (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
498 (add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when global-font-lock-mode is on
499 (global-set-key "\C-cl" 'org-store-link)
500 (global-set-key "\C-ca" 'org-agenda)
501 (global-set-key "\C-cb" 'org-iswitchb)
502 (setq-default org-log-done 'time)
503 (setq-default org-agenda-ndays 5)
504
505
506 (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
507 (add-hook 'message-mode-hook 'turn-on-flyspell)
508 (add-hook 'text-mode-hook 'turn-on-flyspell)
509 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
510 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
511 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
512 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
513 (defun turn-on-flyspell ()
514    "Force flyspell-mode on using a positive arg.  For use in hooks."
515    (interactive)
516    (flyspell-mode 1))
517
518 ;;; outlining support for ess modes
519 (add-hook 'ess-mode-hook
520       '(lambda ()
521          (outline-minor-mode)
522          (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
523          (defun outline-level ()
524            (cond ((looking-at "^##### ") 1)
525              ((looking-at "^#### ") 2)
526              ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
527              (t 1000)))
528          ))
529
530  ; Outline-minor-mode key map
531  (define-prefix-command 'cm-map nil "Outline-")
532  ; HIDE
533  (define-key cm-map "q" 'hide-sublevels)    ; Hide everything but the top-level headings
534  (define-key cm-map "t" 'hide-body)         ; Hide everything but headings (all body lines)
535  (define-key cm-map "o" 'hide-other)        ; Hide other branches
536  (define-key cm-map "c" 'hide-entry)        ; Hide this entry's body
537  (define-key cm-map "l" 'hide-leaves)       ; Hide body lines in this entry and sub-entries
538  (define-key cm-map "d" 'hide-subtree)      ; Hide everything in this entry and sub-entries
539  ; SHOW
540  (define-key cm-map "a" 'show-all)          ; Show (expand) everything
541  (define-key cm-map "e" 'show-entry)        ; Show this heading's body
542  (define-key cm-map "i" 'show-children)     ; Show this heading's immediate child sub-headings
543  (define-key cm-map "k" 'show-branches)     ; Show all sub-headings under this heading
544  (define-key cm-map "s" 'show-subtree)      ; Show (expand) everything in this heading & below
545  ; MOVE
546  (define-key cm-map "u" 'outline-up-heading)                ; Up
547  (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
548  (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
549  (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
550  (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
551  (global-set-key "\M-o" cm-map)
552
553 (defun my-org-mode-setup ()
554   (load-library "reftex")
555   (and (buffer-file-name)
556        (file-exists-p (buffer-file-name))
557        (progn
558          (reftex-parse-all)
559          (reftex-set-cite-format
560           '((?b . "[[bib::%l][%l-bib]]")
561             (?n . "[[note::%l][%l-notes]]")
562             (?c . "\\cite{%l}")
563             (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l paper]]")))
564          ))
565   (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
566   (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
567   (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
568   (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
569   )
570 (add-hook 'org-mode-hook 'my-org-mode-setup)
571
572 (defun org-mode-reftex-search ()
573   (interactive)
574   (org-open-link-from-string (format "[[notes:%s]]" (reftex-citation t))))
575
576 (defun open-research-paper (bibtexkey)
577   "Open a paper by bibtex key"
578   (interactive "bibtex key: ")
579   (shell-command
580    (format "%s %s"
581        (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
582 (org-add-link-type "papers" 'open-research-paper)
583
584
585 ;; stolen from
586 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
587 (defun my-rtcite-export-handler (path desc format)
588   (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
589   (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
590                    (match-string 1 path)))
591          (path (substring path 0 (match-beginning 0))))
592     (cond ((eq format 'latex)
593            (if (or (not desc) 
594                    (equal 0 (search "rtcite:" desc)))
595                (format "\\cite{%s}" search)
596              (format "\\cite[%s]{%s}" desc search))))))
597
598 (org-add-link-type "rtcite" 
599                    'org-bibtex-open
600                    'my-rtcite-export-handler)
601
602
603 (setq-default org-mobile-directory "/rzlab.ucr.edu:/sites/dav.donarmstrong.com/root/org/")
604 (setq-default org-directory "/home/don/org-mode/")
605 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
606
607 ;; org mode ical export
608 (setq org-icalendar-timezone "America/Los_Angeles")
609 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
610 (setq org-icalendar-store-UID t)
611
612 ;; org babel support
613 (org-babel-do-load-languages
614  'org-babel-load-languages
615  '((emacs-lisp . t )
616    (R . t)
617    (latex . t)))
618 ;; org-babel-by-backend
619 (defmacro org-babel-by-backend (&rest body)
620    `(case (if (boundp 'backend) 
621               (org-export-backend-name backend)
622             nil) ,@body))
623
624
625
626 ;; org latex
627 ;; stolen from http://kieranhealy.org/esk/kjhealy.html
628 (require 'org-latex)   
629 ;; Choose either listings or minted for exporting source code blocks.
630 ;; Using minted (as here) requires pygments be installed. To use the
631 ;; default listings package instead, use
632 ;; (setq org-latex-listings t)
633 ;; and change references to "minted" below to "listings"
634 (setq org-latex-listings 'minted)
635
636 ;; default settings for minted code blocks
637 (setq org-latex-minted-options
638       '(;("frame" "single")
639         ("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.
640         ("fontsize" "\\small")
641         ))
642 ;; turn off the default toc behavior; deal with it properly in headers to files.
643 (defun org-latex-no-toc (depth)  
644   (when depth
645     (format "%% Org-mode is exporting headings to %s levels.\n"
646             depth)))
647 (setq org-latex-format-toc-function 'org-latex-no-toc)
648
649 (require 'ox-latex)
650 (add-to-list 'org-latex-classes
651              '("memarticle"
652                "\\documentclass[11pt,oneside,article]{memoir}\n"
653                ("\\section{%s}" . "\\section*{%s}")
654                ("\\subsection{%s}" . "\\subsection*{%s}")
655                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
656                ("\\paragraph{%s}" . "\\paragraph*{%s}")
657                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
658
659 (add-to-list 'org-latex-classes
660              '("membook"
661                "\\documentclass[11pt,oneside]{memoir}\n"
662                ("\\chapter{%s}" . "\\chapter*{%s}")
663                ("\\section{%s}" . "\\section*{%s}")
664                ("\\subsection{%s}" . "\\subsection*{%s}")
665                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
666
667 (add-to-list 'org-latex-classes
668              '("letter"
669                "\\documentclass[11pt]{letter}"
670                ("\\section{%s}" . "\\section*{%s}")
671                ("\\subsection{%s}" . "\\subsection*{%s}")
672                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
673                ("\\paragraph{%s}" . "\\paragraph*{%s}")
674                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
675
676 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
677 ;; but adapted to use latexmk 4.22 or higher.  
678 (defun my-auto-tex-cmd ()
679   "When exporting from .org with latex, automatically run latex,
680                      pdflatex, or xelatex as appropriate, using latexmk."
681   (let ((texcmd)))
682   ;; default command: pdflatex 
683   (setq texcmd "latexmk -pdflatex='pdflatex -synctex=1 --shell-escape --' -pdf %f")        
684   ;; pdflatex -> .pdf
685   (if (string-match "LATEX_CMD: pdflatex" (buffer-string))
686       (setq texcmd "latexmk -pdflatex='pdflatex -synctex=1 --shell-escape' -pdf %f"))
687   ;; xelatex -> .pdf
688   (if (string-match "LATEX_CMD: xelatex" (buffer-string))
689       (setq texcmd "latexmk -pdflatex='xelatex -syntex=1 --shell-escape' -bibtex -use-make -pdf %f"))
690   ;; LaTeX compilation command
691   (setq org-latex-to-pdf-process (list texcmd)))
692
693 (add-hook 'org-latex-after-initial-vars-hook 'my-auto-tex-cmd)
694
695 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
696 (setq org-latex-packages-alist
697       '(("" "graphicx" t)
698         ("" "longtable" nil)
699         ("" "float" )))
700
701 ;; Custom packages
702 (defun my-auto-tex-parameters ()
703   "Automatically select the tex packages to include. See https://github.com/kjhealy/latex-custom-kjh for the support files included here."
704   ;; default packages for ordinary latex or pdflatex export
705   (setq org-latex-default-packages-alist
706         '(("AUTO" "inputenc" t)
707           ("minted,minion" "org-preamble-pdflatex" t)))        
708   ;; Packages to include when xelatex is used
709   (if (string-match "LATEX_CMD: xelatex" (buffer-string))
710       (setq org-latex-default-packages-alist
711             '(("minted" "org-preamble-xelatex" t) ))))
712
713 (add-hook 'org-latex-after-initial-vars-hook 'my-auto-tex-parameters)
714
715 ; support ignoring headers in org mode export to latex
716 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
717 (defadvice org-latex-headline (around my-latex-skip-headlines
718                                       (headline contents info) activate)
719   (if (member "ignoreheading" (org-element-property :tags headline))
720       (setq ad-return-value contents)
721     ad-do-it))
722
723 ; debian stuff
724 (setq-default debian-changelog-mailing-address "don@debian.org")
725 (setq-default debian-changelog-full-name "Don Armstrong")
726
727 ; ediff configuration
728 ; don't use the multi-window configuration
729 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
730
731 ; use iedit
732 (require 'iedit)
733 (define-key global-map (kbd "C-;") 'iedit-mode)
734 (global-set-key  (kbd "C-;") 'iedit-mode)
735
736 ; fix up css mode to not be silly
737 ; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
738 (setq cssm-indent-level 4)
739 (setq cssm-newline-before-closing-bracket t)
740 (setq cssm-indent-function #'cssm-c-style-indenter)
741 (setq cssm-mirror-mode nil)
742
743 (require 'multi-web-mode)
744 (setq mweb-default-major-mode 'html-mode)
745 (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
746                   (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
747                   (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
748 (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
749 (multi-web-global-mode 1)
750
751 ; clean-mode-line from http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
752 (defvar mode-line-cleaner-alist
753   `((auto-complete-mode . " α")
754     (yas/minor-mode . " υ")
755     (paredit-mode . " π")
756     (eldoc-mode . "")
757     (abbrev-mode . "")
758     (my-keys-minor-mode . "")
759     ;; Major modes
760     (lisp-interaction-mode . "λ")
761     (hi-lock-mode . "")
762     (python-mode . "Py")
763     (cperl-mode . "ρ")
764     (auctex-mode . "Lχ")
765     (org-agenda-mode . "øα")
766     (org-mode . "ø")
767     (emacs-lisp-mode . "EL")
768     (nxhtml-mode . "nx"))
769   "Alist for `clean-mode-line'.
770  
771 When you add a new element to the alist, keep in mind that you
772 must pass the correct minor/major mode symbol and a string you
773 want to use in the modeline *in lieu of* the original.")
774  
775  
776 (defun clean-mode-line ()
777   (interactive)
778   (loop for cleaner in mode-line-cleaner-alist
779         do (let* ((mode (car cleaner))
780                  (mode-str (cdr cleaner))
781                  (old-mode-str (cdr (assq mode minor-mode-alist))))
782              (when old-mode-str
783                  (setcar old-mode-str mode-str))
784                ;; major mode
785              (when (eq mode major-mode)
786                (setq mode-name mode-str)))))
787  
788  
789 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
790  
791 ;;; alias the new `flymake-report-status-slim' to
792 ;;; `flymake-report-status'
793 (defalias 'flymake-report-status 'flymake-report-status-slim)
794 (defun flymake-report-status-slim (e-w &optional status)
795   "Show \"slim\" flymake status in mode line."
796   (when e-w
797     (setq flymake-mode-line-e-w e-w))
798   (when status
799     (setq flymake-mode-line-status status))
800   (let* ((mode-line " Φ"))
801     (when (> (length flymake-mode-line-e-w) 0)
802       (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
803     (setq mode-line (concat mode-line flymake-mode-line-status))
804     (setq flymake-mode-line mode-line)
805     (force-mode-line-update)))
806
807 ; load sql-indent when sql is loaded
808 (eval-after-load "sql"
809   '(load-library "sql-indent"))
810
811 ; fix up tmux xterm keys
812 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
813 (if (getenv "TMUX")
814     (progn
815       (let ((x 2) (tkey ""))
816         (while (<= x 8)
817           ;; shift
818           (if (= x 2)
819               (setq tkey "S-"))
820           ;; alt
821           (if (= x 3)
822               (setq tkey "M-"))
823           ;; alt + shift
824           (if (= x 4)
825               (setq tkey "M-S-"))
826           ;; ctrl
827           (if (= x 5)
828               (setq tkey "C-"))
829           ;; ctrl + shift
830           (if (= x 6)
831               (setq tkey "C-S-"))
832           ;; ctrl + alt
833           (if (= x 7)
834               (setq tkey "C-M-"))
835           ;; ctrl + alt + shift
836           (if (= x 8)
837               (setq tkey "C-M-S-"))
838           
839           ;; arrows
840           (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
841           (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
842           (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
843           (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
844           ;; home
845           (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
846           ;; end
847           (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
848           ;; page up
849           (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
850           ;; page down
851           (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
852           ;; insert
853           (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
854           ;; delete
855           (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
856           ;; f1
857           (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
858           ;; f2
859           (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
860           ;; f3
861           (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
862           ;; f4
863           (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
864           ;; f5
865           (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
866           ;; f6
867           (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
868           ;; f7
869           (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
870           ;; f8
871           (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
872           ;; f9
873           (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
874           ;; f10
875           (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
876           ;; f11
877           (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
878           ;; f12
879           (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
880           ;; f13
881           (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
882           ;; f14
883           (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
884           ;; f15
885           (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
886           ;; f16
887           (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
888           ;; f17
889           (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
890           ;; f18
891           (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
892           ;; f19
893           (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
894           ;; f20
895           (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
896
897           (setq x (+ x 1))
898           ))
899       )
900   )
901
902 ; apparently things like to step on C-;, so we'll use a hack from
903 ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
904
905 (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
906
907 ; use iedit everywhere
908 (define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
909
910 (define-minor-mode my-keys-minor-mode
911   "A minor mode so that my key settings override annoying major modes."
912   t " my-keys" 'my-keys-minor-mode-map)
913
914 (my-keys-minor-mode 1)
915 (defun my-minibuffer-setup-hook ()
916   (my-keys-minor-mode 0))
917
918 (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
919 (defadvice load (after give-my-keybindings-priority)
920   "Try to ensure that my keybindings always have priority."
921   (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
922       (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
923         (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
924         (add-to-list 'minor-mode-map-alist mykeys))))
925 (ad-activate 'load)