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