]> git.donarmstrong.com Git - emacs.git/blob - .emacs
add org mode integration with emacs
[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")
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
52 ;; switch back to the old primary selection method
53 (setq x-select-enable-clipboard nil)
54 (setq x-select-enable-primary t)
55 ; (setq mouse-drag-copy-region t)
56
57 (fset 'perl-mode 'cperl-mode)
58 ;;(load-file "cperl-mode.el")
59 (add-to-list 'load-path '"~/lib/emacs_el/")
60 ;; this is the tiny-tools module from https://github.com/jaalto/project--emacs-tiny-tools.git
61 (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/tiny")
62 (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/other")
63 ;;(add-to-list 'Tex-style-path '"~/lib/emacs_el/auctex/")
64
65 (setq tinyprocmail--procmail-version "v3.22")
66 (add-hook 'tinyprocmail--load-hook 'tinyprocmail-install)
67 (require 'tinyprocmail)
68
69 (require 'tex-site)
70 ;;(require 'psvn)
71 (require 'cperl-mode)
72 ;;(require 'ecasound)
73 ;;(require 'emacs-wiki)
74 (require 'bibtex)
75 (require 'post)
76 ;;(require 'fixme)
77 (require 'google-weather)
78 (require 'org-google-weather)
79 (setq-default org-google-weather-format "%i %c, [%l,%h] %s %C")
80
81 ; org mode agenda files
82 (setq org-agenda-files
83       (quote ("~/projects/debbugs/notes.org"
84               "~/projects/notes/notes.org"
85               "~/projects/origins_of_life/ool.org"
86               "~/projects/sysadmin/sndservers/sndservers.org"
87               "~/projects/chaim/chaim.org"
88               "~/projects/fh/fh.org")))
89
90 (setq org-default-notes-file "~/projects/notes/notes.org")
91 (setq org-capture-templates  ;; mail-specific note template, identified by "m"
92       '(("m" "Mail" entry (file+headline "~/projects/notes/refile.org" "Mail")
93          "* %?\n\n  Source: %u, %c\n  %i")
94         ("t" "todo" entry (file "~/projects/notes/refile.org")
95          "* TODO %?\n%U\n%a\n" :clock-in t :clock-resume t)
96         ("r" "respond" entry (file "~/projects/notes/refile.org")
97          "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
98         ("n" "note" entry (file "~/projects/notes/refile.org")
99          "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
100         ("j" "Journal" entry (file+datetree "~/projects/notes/diary.org")
101          "* %?\n%U\n" :clock-in t :clock-resume t)
102         ("w" "org-protocol" entry (file "~/projects/notes/refile.org")
103          "* TODO Review %c\n%U\n" :immediate-finish t)
104         ("p" "Phone call" entry (file "~/projects/notes/refile.org")
105          "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
106         ("h" "Habit" entry (file "~/projects/notes/refile.org")
107          "* 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")
108         )
109       )
110
111 ;; Remove empty LOGBOOK drawers on clock out
112 (defun bh/remove-empty-drawer-on-clock-out ()
113   (interactive)
114   (save-excursion
115     (beginning-of-line 0)
116     (org-remove-empty-drawer-at "LOGBOOK" (point))))
117
118 (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
119
120
121 ; this is from http://doc.norang.ca/org-mode.html#Capture
122 ; use C-M-r for org mode capture
123 (global-set-key (kbd "C-M-r") 'org-capture)
124
125 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
126 (setq org-refile-targets (quote ((nil :maxlevel . 9)
127                                  (org-agenda-files :maxlevel . 9))))
128
129 ; Use full outline paths for refile targets - we file directly with IDO
130 (setq org-refile-use-outline-path t)
131
132 ; Targets complete directly with IDO
133 (setq org-outline-path-complete-in-steps nil)
134
135 ; Allow refile to create parent tasks with confirmation
136 (setq org-refile-allow-creating-parent-nodes (quote confirm))
137
138 ; Use IDO for both buffer and file completion and ido-everywhere to t
139 (setq org-completion-use-ido t)
140 (setq ido-everywhere t)
141 (setq ido-max-directory-size 100000)
142 (ido-mode (quote both))
143
144 ;;;; Refile settings
145 ; Exclude DONE state tasks from refile targets
146 (defun bh/verify-refile-target ()
147   "Exclude todo keywords with a done state from refile targets"
148   (not (member (nth 2 (org-heading-components)) org-done-keywords)))
149
150 (setq org-refile-target-verify-function 'bh/verify-refile-target)
151
152 ;; ensure that emacsclient will show just the note to be edited when invoked
153 ;; from Mutt, and that it will shut down emacsclient once finished;
154 ;; fallback to legacy behavior when not invoked via org-protocol.
155 (require 'org-protocol)
156 (add-hook 'org-capture-mode-hook 'delete-other-windows)
157 (setq my-org-protocol-flag nil)
158 (defadvice org-capture-finalize (after delete-frame-at-end activate)
159   "Delete frame at remember finalization"
160   (progn (if my-org-protocol-flag (delete-frame))
161          (setq my-org-protocol-flag nil)))
162 (defadvice org-capture-kill (after delete-frame-at-end activate)
163   "Delete frame at remember abort"
164   (progn (if my-org-protocol-flag (delete-frame))
165          (setq my-org-protocol-flag nil)))
166 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
167   (setq my-org-protocol-flag t))
168
169 (global-set-key "\C-xp" 'server-edit)
170
171 (setq-default auto-mode-alist (cons '("\.wml$" . 
172                               (lambda () (html-mode) (auto-fill-mode)))
173                             auto-mode-alist))
174
175 ;; Use c-mode for perl .xs files
176 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
177 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
178 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
179 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
180 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
181
182 (add-to-list 'auto-mode-alist '("muttng-[a-z0-9]+-[0-9]+-" . post-mode))
183 (add-to-list 'auto-mode-alist '("muttngrc" . muttrc-mode))
184
185 (add-to-list 'auto-mode-alist '("mutt-[a-z0-9]+-[0-9]+-" . post-mode))
186 (add-to-list 'auto-mode-alist '("muttrc" . muttrc-mode))
187
188 (add-to-list 'auto-mode-alist '("\\.mdwn$" . markdown-mode))
189
190
191
192 (global-unset-key "\M-g")
193 (global-set-key "\M-g" 'goto-line)
194
195 ;;(autoload 'perl-mode "cperl-mode"
196 ;;  "alternate mode for editing Perl programs" t)
197
198 ;; self-insert-command hack.
199 ;;   Without this, "if<SP>" expands to
200 ;;   if ( -!-) {
201 ;;   }
202 ;;   which really should be,
203 ;;   if (-!-) {
204 ;;   }
205 (setq-default cperl-hairy t
206       cperl-indent-level 4
207 ;;      cperl-auto-newline t
208 ;;      cperl-auto-newline-after-colon t
209       cperl-continued-statement-offset 4
210       cperl-brace-offset -4
211       cperl-label-offset -4
212       cperl-highlight-variables-indiscriminately t
213       cperl-electric-lbrace-space nil
214       )
215 (add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
216
217
218
219 ;(load-library "php-mode")
220
221 (setq-default c-indent-level 8)
222 (setq-default c-brace-imaginary-offset 0)
223 (setq-default c-brace-offset -8)
224 (setq-default c-argdecl-indent 8)
225 (setq-default c-label-offset -8)
226 (setq-default c-continued-statement-offset 8)
227 ; tabs are annoying
228 (setq-default indent-tabs-mode nil)
229 (setq-default tab-width 8)
230
231
232 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
233 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
234 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
235 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
236 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
237
238 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
239 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
240 (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
241 (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
242 (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
243 (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
244 (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
245 (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
246 (add-hook 'LaTeX-mode-hook 'outline-minor-mode)   ; with AUCTeX LaTeX mode
247 (add-hook 'latex-mode-hook 'outline-minor-mode)   ; with Emacs latex mode
248
249 ;; (TeX-add-style-hook
250 ;;  "latex"
251 ;;  (lambda ()
252 ;;    (TeX-add-symbols
253 ;;     '("DLA" 1))))
254 ;; (custom-set-variables
255 ;;  '(font-latex-user-keyword-classes 
256 ;;    '(("fixme" 
257 ;;       ("DLA" "RZ")
258 ;;       font-lock-function-name-face 2 (command 1 t))))
259 ;; ) 
260
261 (require 'font-latex)
262 (add-to-list 'font-latex-match-reference-keywords "fref")
263 (add-to-list 'font-latex-match-reference-keywords "Fref")
264 (add-to-list 'font-latex-match-reference-keywords "citep")
265 (add-to-list 'font-latex-match-reference-keywords "citet")
266 (font-latex-match-reference-make)
267 (add-to-list 'font-latex-match-function-keywords "DLA")
268 (add-to-list 'font-latex-match-function-keywords "RZ")
269 (add-to-list 'font-latex-match-function-keywords "OM")
270 (add-to-list 'font-latex-match-function-keywords "DL")
271 (add-to-list 'font-latex-match-function-keywords "fixme")
272 (add-to-list 'font-latex-match-function-keywords "acs")
273 (add-to-list 'font-latex-match-function-keywords "acsp")
274 (add-to-list 'font-latex-match-function-keywords "ac")
275 (add-to-list 'font-latex-match-function-keywords "acp")
276 (add-to-list 'font-latex-match-function-keywords "acl")
277 (add-to-list 'font-latex-match-function-keywords "aclp")
278 (add-to-list 'font-latex-match-function-keywords "acsu")
279 (add-to-list 'font-latex-match-function-keywords "aclu")
280 (add-to-list 'font-latex-match-function-keywords "acused")
281 (font-latex-match-function-make)
282 (setq-default TeX-parse-self t)
283 (setq-default TeX-auto-save t)
284 (setq-default TeX-master nil)
285
286 (defun insert-date ()
287   "Insert date at point."
288   (interactive)
289   (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
290 (global-set-key "\C-[d" 'insert-date)
291
292 (defun unfill-paragraph (arg)
293   "Pull this whole paragraph up onto one line."
294   (interactive "*p")
295   (let ((fill-column 10000))
296     (fill-paragraph arg))
297   )
298
299 ;(iswitchb-default-keybindings)
300
301 (column-number-mode t)
302 (setq-default reftex-plug-into-AUCTeX t)
303
304 (server-start)
305
306 (require 'mode-compile)
307
308 (setq-default reftex-default-bibliography
309       '("references.bib"))
310
311 (defadvice server-process-filter (after post-mode-message first activate)
312   "If the buffer is in post mode, overwrite the server-edit
313     message with a post-save-current-buffer-and-exit message."
314   (if (eq major-mode 'post-mode)
315       (message
316        (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
317                                         ; This is also needed to see the magic message.  Set to a higher
318                                         ; number if you have a faster computer or read slower than me.
319 '(font-lock-verbose 1000)
320 ;(setq-default server-temp-file-regexp "mutt\(-\|ng-\)")
321 ; (add-hook 'server-switch-hook 
322 ;         (function (lambda()
323 ;                     (cond ((string-match "Post" mode-name)
324 ;                            (post-goto-body)))
325 ;                     set-buffer-file-coding-system 'utf-8
326 ;                     )))
327
328
329 (add-hook 'post-mode-hook
330           (auto-fill-mode nil)
331           )
332
333 (fset 'insert-function-documentation
334    [?\C-x ?i home ?\C-k ?/ ?h ?o ?m ?e ?/ ?d ?o ?n ?/ ?l ?i ?b ?/ ?t ?e ?m ?p ?l ?a ?t ?e ?s ?/ ?p ?e ?r ?l ?_ ?f ?u ?n ?c ?t ?i ?o ?n ?_ ?d ?o ?c ?u ?m ?e ?n ?t ?a ?t ?i ?o ?n return])
335 (global-set-key "\M-f" 'insert-function-documentation)
336
337 (eval-after-load "lilypond-mode" 
338   '(progn
339      (load-library "lyqi-mode")
340      (define-key LilyPond-mode-map "\C-cq" 'lyqi-mode)))
341
342 (autoload 'spamassassin-mode "spamassassin-mode" nil t)
343
344 (desktop-load-default)
345 (desktop-read)
346 '(iswitchb-mode on)
347 (custom-set-faces
348   ;; custom-set-faces was added by Custom.
349   ;; If you edit it by hand, you could mess it up, so be careful.
350   ;; Your init file should contain only one such instance.
351   ;; If there is more than one, they won't work right.
352  '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
353
354 (defun ess-change-directory (path)
355   "Set the current working directory to PATH for both *R* and Emacs."
356   (interactive "DDirectory to change to: ")
357
358   (when (file-exists-p path)
359     (ess-command (concat "setwd(\"" path "\")\n"))
360     ;; use file-name-as-directory to ensure it has trailing /
361     (setq default-directory (file-name-as-directory path))))
362
363 (put 'upcase-region 'disabled nil)
364
365 (put 'downcase-region 'disabled nil)
366
367 (put 'narrow-to-region 'diabled nil)
368
369 ;; The following lines are always needed. Choose your own keys.
370 (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
371 (add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when global-font-lock-mode is on
372 (global-set-key "\C-cl" 'org-store-link)
373 (global-set-key "\C-ca" 'org-agenda)
374 (global-set-key "\C-cb" 'org-iswitchb)
375 (setq-default org-log-done 'time)
376 (setq-default org-agenda-ndays 5)
377
378
379 (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
380 (add-hook 'message-mode-hook 'turn-on-flyspell)
381 (add-hook 'text-mode-hook 'turn-on-flyspell)
382 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
383 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
384 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
385 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
386 (defun turn-on-flyspell ()
387    "Force flyspell-mode on using a positive arg.  For use in hooks."
388    (interactive)
389    (flyspell-mode 1))
390
391 ;;; outlining support for ess modes
392 (add-hook 'ess-mode-hook
393           '(lambda ()
394              (outline-minor-mode)
395              (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function(.*{\\)")
396              (defun outline-level
397                (lambda () (interactive) (cond ((looking-at "^##### ") 1)((looking-at "^#### ") 2)((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3) (t 1000)))
398                )))
399
400  ; Outline-minor-mode key map
401  (define-prefix-command 'cm-map nil "Outline-")
402  ; HIDE
403  (define-key cm-map "q" 'hide-sublevels)    ; Hide everything but the top-level headings
404  (define-key cm-map "t" 'hide-body)         ; Hide everything but headings (all body lines)
405  (define-key cm-map "o" 'hide-other)        ; Hide other branches
406  (define-key cm-map "c" 'hide-entry)        ; Hide this entry's body
407  (define-key cm-map "l" 'hide-leaves)       ; Hide body lines in this entry and sub-entries
408  (define-key cm-map "d" 'hide-subtree)      ; Hide everything in this entry and sub-entries
409  ; SHOW
410  (define-key cm-map "a" 'show-all)          ; Show (expand) everything
411  (define-key cm-map "e" 'show-entry)        ; Show this heading's body
412  (define-key cm-map "i" 'show-children)     ; Show this heading's immediate child sub-headings
413  (define-key cm-map "k" 'show-branches)     ; Show all sub-headings under this heading
414  (define-key cm-map "s" 'show-subtree)      ; Show (expand) everything in this heading & below
415  ; MOVE
416  (define-key cm-map "u" 'outline-up-heading)                ; Up
417  (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
418  (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
419  (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
420  (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
421  (global-set-key "\M-o" cm-map)
422
423 (defun my-org-mode-setup ()
424  (when (and (buffer-file-name)
425             (file-exists-p (buffer-file-name)))
426   (load-library "reftex")
427   (and (buffer-file-name)
428         (file-exists-p (buffer-file-name))
429         (reftex-parse-all))
430    (reftex-set-cite-format
431      '((?b . "[[bib::%l]]")
432        (?n . "[[note::%l]]"))))
433    (define-key org-mode-map "\C-c\C-g" 'reftex-citation)
434 )
435 (add-hook 'org-mode-hook 'my-org-mode-setup)
436
437 (setq-default org-mobile-directory "/rzlab.ucr.edu:/sites/dav.donarmstrong.com/root/org/")
438 (setq-default org-directory "/home/don/org-mode/")
439 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
440
441 ; debian stuff
442 (setq-default debian-changelog-mailing-address "don@debian.org")
443 (setq-default debian-changelog-full-name "Don Armstrong")
444
445 ; use iedit
446 (require 'iedit)
447 (define-key global-map (kbd "C-;") 'iedit-mode)
448 (global-set-key  (kbd "C-;") 'iedit-mode)
449
450 (require 'multi-web-mode)
451 (setq mweb-default-major-mode 'html-mode)
452 (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
453                   (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
454                   (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
455 (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
456 (multi-web-global-mode 1)
457
458
459 ; apparently things like to step on C-;, so we'll use a hack from
460 ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
461
462 (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
463
464 ; use iedit everywhere
465 (define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
466
467 (define-minor-mode my-keys-minor-mode
468   "A minor mode so that my key settings override annoying major modes."
469   t " my-keys" 'my-keys-minor-mode-map)
470
471 (my-keys-minor-mode 1)
472 (defun my-minibuffer-setup-hook ()
473   (my-keys-minor-mode 0))
474
475 (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
476 (defadvice load (after give-my-keybindings-priority)
477   "Try to ensure that my keybindings always have priority."
478   (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
479       (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
480         (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
481         (add-to-list 'minor-mode-map-alist mykeys))))
482 (ad-activate 'load)