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