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