]> git.donarmstrong.com Git - lib.git/blob - emacs_el/configuration/don-configuration.org
migrate org mode configuration to don-configuration.org
[lib.git] / emacs_el / configuration / don-configuration.org
1 #+PROPERTY: header-args:emacs-lisp :tangle don-configuration.el
2 * Load debugger
3
4 # if for some reason, things get pear-shaped, we want to be able to
5 # enter the debugger by sending -USR2 to emacs
6
7 #+BEGIN_SRC emacs-lisp
8 (setq debug-on-event 'siguser2)
9 #+END_SRC
10 * Add library paths
11
12 #+BEGIN_SRC emacs-lisp
13   (add-to-list 'load-path '"~/lib/emacs_el/")
14   (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/tiny")
15   (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/other")
16   (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
17 #+END_SRC
18
19 * Package management
20 ** package repositories and package manager
21 #+BEGIN_SRC emacs-lisp
22   (require 'package)
23   (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
24                            ("melpa" . "https://melpa.org/packages/")
25                            ("org" . "http://orgmode.org/elpa/") ))
26 #+END_SRC
27 ** [[https://github.com/jwiegley/use-package/][use-package]]
28 #+BEGIN_SRC emacs-lisp
29   (require 'use-package)
30   (package-initialize)
31 #+END_SRC
32 ** Paradox
33 #+BEGIN_SRC emacs-lisp
34   (package-initialize)
35   (use-package paradox
36     :ensure paradox
37   )
38 #+END_SRC
39 * Misc functions
40 ** with-library
41 #+BEGIN_SRC emacs-lisp
42 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
43 ;; execute conditional code when loading libraries
44 (defmacro with-library (symbol &rest body)
45   `(when (require ,symbol nil t)
46      ,@body))
47 (put 'with-library 'lisp-indent-function 1)
48 #+END_SRC
49
50
51 * Memory
52 #+BEGIN_SRC emacs-lisp
53   (setq global-mark-ring-max 128
54         mark-ring-max 128
55         kill-ring-max 128)
56
57   (defun don/minibuffer-setup-hook ()
58     (setq gc-cons-threshold most-positive-fixnum))
59
60   (defun don/minibuffer-exit-hook ()
61     (setq gc-cons-threshold 1048576))
62
63   (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
64   (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
65 #+END_SRC
66 * Modules
67 ** Flyspell 🐝 
68 #+BEGIN_SRC emacs-lisp
69   (use-package flyspell
70     :ensure t
71     :diminish flyspell-mode 🐝
72     :config
73     (add-hook 'message-mode-hook 'turn-on-flyspell)
74     (add-hook 'text-mode-hook 'turn-on-flyspell)
75     (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
76     (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
77     (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
78     :init
79     (setq ispell-program-name "ispell")
80     )
81
82 #+END_SRC
83 ** Winnermode
84 #+BEGIN_SRC emacs-lisp
85   (winner-mode 1)
86 #+END_SRC
87 ** Eyebrowse
88
89 #+BEGIN_SRC emacs-lisp
90   ;; (use-package eyebrowse
91   ;;   :ensure t
92   ;;   :diminish eyebrowse-mode
93   ;;   :init (setq eyebrowse-keymap-prefix (kbd "C-c C-\\"))
94   ;;   :config (progn
95   ;;             (setq eyebrowse-wrap-around t)
96   ;;             (eyebrowse-mode t)
97   ;; 
98   ;;             (defun my/eyebrowse-new-window-config ()
99   ;;               (interactive)
100   ;;               (let ((done nil))
101   ;;                 (dotimes (i 10)
102   ;;                   ;; start at 1 run till 0
103   ;;                   (let ((j (mod (+ i 1) 10)))
104   ;;                     (when (and (not done)
105   ;;                                (not (eyebrowse--window-config-present-p j)))
106   ;;                       (eyebrowse-switch-to-window-config j)
107   ;;                       (call-interactively 'eyebrowse-rename-window-config2 j)
108   ;;                       (setq done t)
109   ;;                       ))
110   ;;                   )))
111   ;; 
112   ;;             ;; I don't use latex-preview-pane
113   ;;             ;; (require 'latex-preview-pane)
114   ;;             ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
115   ;;             ;;   ;; latex-preview-pane uses window-parameters which are
116   ;;             ;;   ;; not preserved by eyebrowse, so we close the preview
117   ;;             ;;   ;; pane before switching, it will be regenerated when we
118   ;;             ;;   ;; edit the TeX file.
119   ;;             ;;   (when (lpp/window-containing-preview)
120   ;;             ;;     (delete-window (lpp/window-containing-preview))))
121   ;; 
122   ;;             ;; (add-to-list 'eyebrowse-pre-window-switch-hook
123   ;;             ;;              #'my/close-latex-preview-pane-before-eyebrowse-switch)
124   ;; 
125   ;;             ;; (my/set-menu-key "["  #'my/eyebrowse-new-window-config)
126   ;;             ;; (my/set-menu-key ";"  #'eyebrowse-prev-window-config)
127   ;;             ;; (my/set-menu-key "'"  #'eyebrowse-next-window-config)
128   ;;             ;; (my/set-menu-key "]"  #'eyebrowse-close-window-config)
129   ;;             ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
130   ;;             )
131   ;;   )
132 #+END_SRC
133
134 ** Window handling
135
136 *** Splitting
137 #+BEGIN_SRC emacs-lisp
138   (defun my/vsplit-last-buffer ()
139     "Split the window vertically and display the previous buffer."
140     (interactive)
141     (split-window-vertically)
142     (other-window 1 nil)
143     (switch-to-next-buffer))
144
145   (defun my/hsplit-last-buffer ()
146     "Split the window horizontally and display the previous buffer."
147     (interactive)
148     (split-window-horizontally)
149     (other-window 1 nil)
150     (switch-to-next-buffer))
151
152   (bind-key "C-x 2" 'my/vsplit-last-buffer)
153   (bind-key "C-x 3" 'my/hsplit-last-buffer)
154
155   (setq split-width-threshold  100)
156   (setq split-height-threshold 60)
157
158   (defun my/split-window-prefer-vertically (window)
159     "If there's only one window (excluding any possibly active
160            minibuffer), then split the current window horizontally."
161     (if (and (one-window-p t)
162              (not (active-minibuffer-window))
163              ( < (frame-width) (frame-height))
164              )
165         (let ((split-width-threshold nil))
166           (split-window-sensibly window))
167       (split-window-sensibly window)))
168
169   (setq split-window-preferred-function #'my/split-window-prefer-vertically)
170   (setq window-combination-resize t)
171 #+END_SRC
172
173 *** Compilation window
174
175 If there is no compilation window, open one at the bottom, spanning
176 the complete width of the frame. Otherwise, reuse existing window. In
177 the former case, if there was no error the window closes
178 automatically.
179
180 #+BEGIN_SRC emacs-lisp
181   (add-to-list 'display-buffer-alist
182                `(,(rx bos "*compilation*" eos)
183                  (display-buffer-reuse-window
184                   display-buffer-in-side-window)
185                  (reusable-frames . visible)
186                  (side            . bottom)
187                  (window-height   . 0.4)))
188 #+END_SRC
189
190 #+BEGIN_SRC emacs-lisp
191   (defun my/compilation-exit-autoclose (status code msg)
192     ;; If M-x compile exists with a 0
193     (when (and (eq status 'exit) (zerop code))
194       ;; and delete the *compilation* window
195       (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
196         (when (and (not (window-at-side-p compilation-window 'top))
197                    (window-at-side-p compilation-window 'left)
198                    (window-at-side-p compilation-window 'right))
199           (delete-window compilation-window))))
200     ;; Always return the anticipated result of compilation-exit-message-function
201     (cons msg code))
202
203   ;; Specify my function (maybe I should have done a lambda function)
204   (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
205 #+END_SRC
206
207 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
208 value, the compilation buffer scrolls automatically to follow the
209 output. If the value is ~first-error~, scrolling stops when the first
210 error appears, leaving point at that error. For any other non-nil
211 value, scrolling continues until there is no more output.
212
213 #+BEGIN_SRC emacs-lisp
214   (setq compilation-scroll-output 'first-error)
215 #+END_SRC
216
217 ** Mode line cleaning
218 *** Diminish
219 #+BEGIN_SRC emacs-lisp
220   (use-package diminish
221     :ensure t)
222 #+END_SRC
223
224 *** Delight 
225 #+BEGIN_SRC emacs-lisp
226   (use-package delight
227     :ensure t)
228 #+END_SRC
229
230 ** Jumping
231 *** Avy
232 #+BEGIN_SRC emacs-lisp
233 (use-package avy
234   :ensure t
235   :bind ("C-c C-SPC" . avy-goto-word-1)
236   :config (progn
237             (setq avy-background t)
238             (key-chord-define-global "jj"  #'avy-goto-word-1)))
239 #+END_SRC
240
241 ** Snippets
242
243 *** Yasnippet
244 #+BEGIN_SRC emacs-lisp
245   (use-package yasnippet
246     :ensure t
247     :diminish yas-minor-mode
248     :config (progn
249               (yas-global-mode)
250               (setq yas-verbosity 1)
251               (define-key yas-minor-mode-map (kbd "<tab>") nil)
252               (define-key yas-minor-mode-map (kbd "TAB") nil)
253               (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
254               ))
255 #+END_SRC
256
257 ** Helm Flx
258
259 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
260
261 #+BEGIN_SRC emacs-lisp
262 (use-package helm-flx
263   :ensure t
264   :config (progn
265             ;; these are helm configs, but they kind of fit here nicely
266             (setq helm-M-x-fuzzy-match                  t
267                   helm-bookmark-show-location           t
268                   helm-buffers-fuzzy-matching           t
269                   helm-completion-in-region-fuzzy-match t
270                   helm-file-cache-fuzzy-match           t
271                   helm-imenu-fuzzy-match                t
272                   helm-mode-fuzzy-match                 t
273                   helm-locate-fuzzy-match               nil
274                   helm-quick-update                     t
275                   helm-recentf-fuzzy-match              nil
276                   helm-semantic-fuzzy-match             t)
277             (helm-flx-mode +1)))
278 #+END_SRC
279
280
281 ** Tinyprocmail
282
283 #+BEGIN_SRC emacs-lisp
284   ;; load tinyprocmail
285   (use-package tinyprocmail
286     :ensure f
287     :config (with-library 'tinyprocmail
288               ;; (setq tinyprocmail--procmail-version "v3.22")
289               (add-hook 'tinyprocmail--load-hook 'tinyprocmail-install))
290   )
291 #+END_SRC
292
293 ** Magit
294 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
295   (use-package magit
296     :ensure t
297     :bind (("C-x g" . magit-status)
298            ("C-x C-g" . magit-status))
299     :config
300     ;; don't verify where we are pushing
301     (setq magit-push-always-verify nil)
302     ;; refine diffs always (hilight words)
303     (setq magit-diff-refine-hunk nil)
304     ;; load magit-annex
305     (setq load-path
306           (append '("~/lib/emacs_el/magit-annex")
307                   load-path))
308     ;; load magit-vcsh
309     (setq load-path
310           (append '("~/lib/emacs_el/magit-vcsh")
311                   load-path))
312     )
313   (use-package magit-annex
314     :ensure t
315   )
316   (use-package magit-vcsh
317     :ensure f ; currently not in melpa, so don't try to install
318   )
319 #+END_SRC
320
321 ** Perl
322 #+BEGIN_SRC emacs-lisp
323   (require 'cperl-mode)
324   ;; Use c-mode for perl .xs files
325   (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
326   (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
327   (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
328   (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
329   (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
330   (setq cperl-hairy t
331         cperl-indent-level 4
332         cperl-auto-newline nil
333         cperl-auto-newline-after-colon nil
334         cperl-continued-statement-offset 4
335         cperl-brace-offset -1
336         cperl-continued-brace-offset 0
337         cperl-label-offset -4
338         cperl-highlight-variables-indiscriminately t
339         cperl-electric-lbrace-space nil
340         cperl-indent-parens-as-block nil
341         cperl-close-paren-offset -1
342         cperl-tab-always-indent t)
343   ;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
344 #+END_SRC
345
346 ** Helm
347 #+BEGIN_SRC emacs-lisp
348   (use-package helm
349     :ensure t
350     :config
351     (helm-mode 1)
352     (define-key global-map [remap find-file] 'helm-find-files)
353     (define-key global-map [remap occur] 'helm-occur)
354     (define-key global-map [remap list-buffers] 'helm-buffers-list)
355     (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
356     (global-set-key (kbd "M-x") 'helm-M-x)
357     (unless (boundp 'completion-in-region-function)
358       (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
359       (define-key emacs-lisp-mode-map       [remap completion-at-point] 'helm-lisp-completion-at-point))
360     (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
361   )
362 #+END_SRC
363 ** Hydra
364 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
365 (require 'don-hydra)
366 #+END_SRC
367
368 ** Tramp
369 #+BEGIN_SRC emacs-lisp
370   (add-to-list 'tramp-methods '("vcsh"
371                                 (tramp-login-program "vcsh")
372                                 (tramp-login-args
373                                  (("enter")
374                                   ("%h")))
375                                 (tramp-remote-shell "/bin/sh")
376                                 (tramp-remote-shell-args
377                                  ("-c"))))
378 #+END_SRC
379 ** Reftex
380 #+BEGIN_SRC emacs-lisp
381   (use-package reftex
382     :ensure t
383     :config
384     (setq-default reftex-default-bibliography
385                     '("~/projects/research/references.bib")))
386 #+END_SRC
387 ** LaTeX
388 #+BEGIN_SRC emacs-lisp
389   (use-package tex
390     :defer t
391     :ensure auctex
392     :config
393     ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
394     ;; REFTEX (much enhanced management of cross-ref, labels, etc)
395     ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
396     ; (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
397     ; (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
398     ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
399     ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
400     (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
401     (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
402     (add-hook 'LaTeX-mode-hook 'outline-minor-mode)   ; with AUCTeX LaTeX mode
403     (add-hook 'latex-mode-hook 'outline-minor-mode)   ; with Emacs latex mode
404
405     (setq-default reftex-plug-into-AUCTeX t)
406     ;; support fake section headers
407     (setq TeX-outline-extra
408           '(("%chapter" 1)
409             ("%section" 2)
410             ("%subsection" 3)
411             ("%subsubsection" 4)
412             ("%paragraph" 5)))
413     ;; add font locking to the headers
414     (font-lock-add-keywords
415      'latex-mode
416      '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
417         0 'font-lock-keyword-face t)
418        ("^%chapter{\\(.*\\)}"       1 'font-latex-sectioning-1-face t)
419        ("^%section{\\(.*\\)}"       1 'font-latex-sectioning-2-face t)
420        ("^%subsection{\\(.*\\)}"    1 'font-latex-sectioning-3-face t)
421        ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
422        ("^%paragraph{\\(.*\\)}"     1 'font-latex-sectioning-5-face t)))
423
424     ;; use smart quotes by default instead of `` and ''
425     ;; taken from http://kieranhealy.org/esk/kjhealy.html
426     (setq TeX-open-quote "“")
427     (setq TeX-close-quote "”")
428
429     ;; (TeX-add-style-hook
430     ;;  "latex"
431     ;;  (lambda ()
432     ;;    (TeX-add-symbols
433     ;;     '("DLA" 1))))
434     ;; (custom-set-variables
435     ;;  '(font-latex-user-keyword-classes 
436     ;;    '(("fixme" 
437     ;;       ("DLA" "RZ")
438     ;;       font-lock-function-name-face 2 (command 1 t))))
439     ;; ) 
440     (setq-default TeX-parse-self t)
441     (setq-default TeX-auto-save t)
442     (setq-default TeX-master nil)
443     (eval-after-load
444         "latex"
445       '(TeX-add-style-hook
446         "cleveref"
447         (lambda ()
448           (if (boundp 'reftex-ref-style-alist)
449               (add-to-list
450                'reftex-ref-style-alist
451                '("Cleveref" "cleveref"
452                  (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
453           (reftex-ref-style-activate "Cleveref")
454           (TeX-add-symbols
455            '("cref" TeX-arg-ref)
456            '("Cref" TeX-arg-ref)
457            '("cpageref" TeX-arg-ref)
458            '("Cpageref" TeX-arg-ref)))))
459     (eval-after-load
460         "latex"
461       '(add-to-list 'LaTeX-fill-excluded-macros
462                     '("Sexpr")))
463
464     (use-package font-latex
465       :config
466       (setq font-latex-match-reference-keywords
467             '(
468               ("fref" "{")
469               ("Fref" "{")
470               ("citep" "{")
471               ("citet" "{")
472               ("acs" "{")
473               ("acsp" "{")
474               ("ac" "{")
475               ("acp" "{")
476               ("acl" "{")
477               ("aclp" "{")
478               ("acsu" "{")
479               ("aclu" "{")
480               ("acused" "{")
481               ("DLA" "{")
482               ("RZ" "{")
483               ("OM" "{")
484               ("DL" "{")
485               ("fixme" "{"))
486             )
487       )
488   )
489
490 #+END_SRC
491 ** Org
492 #+BEGIN_SRC emacs-lisp
493   (require 'org-mode-configuration)
494 #+END_SRC
495 *** Org-Gcal
496 #+BEGIN_SRC emacs-lisp
497   (use-package calfw
498     :ensure f
499     )
500   (use-package calfw-org
501     :ensure f
502     )
503   (use-package org-gcal
504     :ensure f
505     :config '((if (file-readable-p "~/.hide/org_gcal.el")
506                   (load-file "~/.hide/org_gcal.el"))
507               )
508     )
509 #+END_SRC
510 ** ESS
511 #+BEGIN_SRC emacs-lisp
512   (use-package ess
513     :ensure t
514     :config (require 'ess_configuration))
515 #+END_SRC
516
517 ** Rainbowmode
518 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
519
520 #+BEGIN_SRC emacs-lisp
521   (use-package rainbow-mode
522     ;; add ess to the x major mode
523     :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
524     (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
525   )
526 #+END_SRC
527
528 ** Polymode
529 #+BEGIN_SRC emacs-lisp
530   (use-package polymode
531     :config
532     (use-package poly-R)
533     (use-package poly-noweb)
534     (use-package poly-markdown)
535     :mode ("\\.Snw" . poly-noweb+r-mode)
536     :mode ("\\.Rnw" . poly-noweb+r-mode)
537     :mode ("\\.Rmd" . poly-markdown+r-mode)
538     )
539 #+END_SRC
540
541 ** Outlining
542 *** Outline magic
543 #+BEGIN_SRC emacs-lisp
544   (use-package outline-magic)
545 #+END_SRC
546 ** Writeroom Mode
547 #+BEGIN_SRC emacs-lisp
548   (use-package writeroom-mode
549     :config (add-hook 'writeroom-mode-hook 'auto-fill-mode)
550     )
551 #+END_SRC
552 ** GhostText/Atomic Chrome
553 #+BEGIN_SRC emacs-lisp
554   (use-package atomic-chrome
555     :config (atomic-chrome-start-server)
556     )
557 #+END_SRC
558 * Org Mode
559 ** Use-package and load things
560 #+BEGIN_SRC emacs-lisp
561
562   (use-package org
563     :config 
564
565 #+END_SRC
566 ** Agenda Configuration
567 #+BEGIN_SRC emacs-lisp
568   ;; The following lines are always needed. Choose your own keys.
569   (add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
570   (global-set-key "\C-cl" 'org-store-link)
571   (global-set-key "\C-ca" 'org-agenda)
572   (global-set-key "\C-cb" 'org-iswitchb)
573   (setq-default org-log-done 'time)
574   (setq-default org-agenda-ndays 5)
575
576   ;; agenda configuration
577   ;; Do not dim blocked tasks
578   (setq org-agenda-dim-blocked-tasks nil)
579   (setq org-agenda-inhibit-startup t)
580   (setq org-agenda-use-tag-inheritance nil)
581
582   ;; Compact the block agenda view
583   (setq org-agenda-compact-blocks t)
584
585   ;; Custom agenda command definitions
586   (setq org-agenda-custom-commands
587         (quote (("N" "Notes" tags "NOTE"
588                  ((org-agenda-overriding-header "Notes")
589                   (org-tags-match-list-sublevels t)))
590                 ("h" "Habits" tags-todo "STYLE=\"habit\""
591                  ((org-agenda-overriding-header "Habits")
592                   (org-agenda-sorting-strategy
593                    '(todo-state-down effort-up category-keep))))
594                 (" " "Agenda"
595                  ((agenda "" nil)
596                   (tags "REFILE"
597                         ((org-agenda-overriding-header "Tasks to Refile")
598                          (org-tags-match-list-sublevels nil)))
599                   (tags-todo "-CANCELLED/!"
600                              ((org-agenda-overriding-header "Stuck Projects")
601                               (org-agenda-skip-function 'bh/skip-non-stuck-projects)
602                               (org-agenda-sorting-strategy
603                                '(category-keep))))
604                   (tags-todo "-HOLD-CANCELLED/!"
605                              ((org-agenda-overriding-header "Projects")
606                               (org-agenda-skip-function 'bh/skip-non-projects)
607                               (org-tags-match-list-sublevels 'indented)
608                               (org-agenda-sorting-strategy
609                                '(category-keep))))
610                   (tags-todo "-CANCELLED/!NEXT"
611                              ((org-agenda-overriding-header (concat "Project Next Tasks"
612                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
613                                                                         ""
614                                                                       " (including WAITING and SCHEDULED tasks)")))
615                               (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
616                               (org-tags-match-list-sublevels t)
617                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
618                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
619                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
620                               (org-agenda-sorting-strategy
621                                '(todo-state-down effort-up category-keep))))
622                   (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
623                              ((org-agenda-overriding-header (concat "Project Subtasks"
624                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
625                                                                         ""
626                                                                       " (including WAITING and SCHEDULED tasks)")))
627                               (org-agenda-skip-function 'bh/skip-non-project-tasks)
628                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
629                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
630                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
631                               (org-agenda-sorting-strategy
632                                '(category-keep))))
633                   (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
634                              ((org-agenda-overriding-header (concat "Standalone Tasks"
635                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
636                                                                         ""
637                                                                       " (including WAITING and SCHEDULED tasks)")))
638                               (org-agenda-skip-function 'bh/skip-project-tasks)
639                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
640                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
641                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
642                               (org-agenda-sorting-strategy
643                                '(category-keep))))
644                   (tags-todo "-CANCELLED+WAITING|HOLD/!"
645                              ((org-agenda-overriding-header "Waiting and Postponed Tasks")
646                               (org-agenda-skip-function 'bh/skip-stuck-projects)
647                               (org-tags-match-list-sublevels nil)
648                               (org-agenda-todo-ignore-scheduled t)
649                               (org-agenda-todo-ignore-deadlines t)))
650                   (tags "-REFILE/"
651                         ((org-agenda-overriding-header "Tasks to Archive")
652                          (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
653                          (org-tags-match-list-sublevels nil))))
654                  nil))))
655
656   ; org mode agenda files
657   (setq org-agenda-files
658         (quote ("~/projects/org-notes/debbugs.org"
659             "~/projects/org-notes/notes.org"
660             "~/projects/org-notes/holidays.org"
661             "~/projects/org-notes/refile.org"
662             "~/projects/org-notes/diary.org"
663             "~/projects/org-notes/ool.org"
664             "~/projects/org-notes/sndservers.org"
665             "~/projects/org-notes/chaim.org"
666             "~/projects/org-notes/wildman.org"
667             "~/projects/org-notes/uddin.org"
668             "~/projects/org-notes/reviews.org"
669             "~/projects/org-notes/hpcbio.org"
670             "~/org-mode/from-mobile.org"
671             "~/projects/org-notes/fh.org")))
672
673   (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
674   (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
675   (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
676   (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
677   (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
678   (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
679   (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
680   (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
681   (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
682   ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
683   (defun org-agenda-timeline-all (&optional arg)
684     (interactive "P")
685     (with-temp-buffer
686       (dolist (org-agenda-file org-agenda-files)
687         (insert-file-contents org-agenda-file nil)
688         (end-of-buffer)
689         (newline))
690       (write-file "/tmp/timeline.org")
691       (org-agenda arg "L")))
692   (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
693   ;; add automatic reminders for appointments
694   (defadvice  org-agenda-redo (after org-agenda-redo-add-appts)
695     "Pressing `r' on the agenda will also add appointments."
696     (progn 
697       (setq appt-time-msg-list nil)
698       (org-agenda-to-appt)))
699
700 #+END_SRC
701 ** General config
702 #+BEGIN_SRC emacs-lisp
703   (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")))
704   (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
705
706   (setq org-default-notes-file "~/projects/org-notes/notes.org")
707   (setq org-id-link-to-org-use-id t)
708 #+END_SRC
709 ** Capture Templates
710 #+BEGIN_SRC emacs-lisp
711   (setq org-capture-templates  ;; mail-specific note template, identified by "m"
712         '(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
713            "* %?\n\n  Source: %u, [[%:link][%:description]]\n  %:initial")
714           ("t" "todo" entry (file "~/projects/org-notes/refile.org")
715            "* TODO %?\n  :PROPERTIES:\n  :END:\n  :LOGBOOK:\n  :END:\n%U\n%a\n" :clock-in t :clock-resume t)
716           ("r" "respond" entry (file "~/projects/org-notes/refile.org")
717            "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
718           ("n" "note" entry (file "~/projects/org-notes/refile.org")
719            "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
720           ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
721            "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
722           ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
723            "* %?\n%U\n" :clock-in t :clock-resume t)
724           ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
725            "* TODO Review %c\n%U\n" :immediate-finish t)
726           ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
727            "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
728           ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
729            "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
730           ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
731            "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
732           ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
733            "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
734           ("J" "job" entry (file "~/projects/org-notes/refile.org")
735            "* TODO Apply for %a%? :job:\nSCHEDULED: %(format-time-string \"<%Y-%m-%d 17:00-17:30>\")\n%U\n%a\n" :clock-in t :clock-resume t)
736           ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
737            "* NEXT %?\n%U\n%a\nSCHEDULED: %(format-time-string \"<%Y-%m-%d .+1d/3d>\")\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n%a\n")
738           )
739         )
740
741   ;; Remove empty LOGBOOK drawers on clock out
742   (defun bh/remove-empty-drawer-on-clock-out ()
743     (interactive)
744     (save-excursion
745       (beginning-of-line 0)
746       (org-remove-empty-drawer-at (point))))
747
748   (defun my/org-add-id ()
749     (interactive)
750     (save-excursion
751       (if (org-current-level)
752           ()
753         (forward-char 1)
754         )
755       (org-id-get-create)
756       )
757   )
758
759 #+END_SRC
760 ** Org mode key bindings
761 #+BEGIN_SRC emacs-lisp
762   ; org mode configuration from http://doc.norang.ca/org-mode.html
763   ;; Custom Key Bindings
764   (global-set-key (kbd "<f12>") 'org-agenda)
765   (global-set-key (kbd "<f5>") 'bh/org-todo)
766   (global-set-key (kbd "<S-f5>") 'bh/widen)
767   (global-set-key (kbd "<f7>") 'bh/set-truncate-lines)
768   (global-set-key (kbd "<f8>") 'org-cycle-agenda-files)
769   (global-set-key (kbd "<f9> <f9>") 'bh/show-org-agenda)
770   (global-set-key (kbd "<f9> b") 'bbdb)
771   (global-set-key (kbd "<f9> c") 'calendar)
772   (global-set-key (kbd "<f9> f") 'boxquote-insert-file)
773   (global-set-key (kbd "<f9> h") 'bh/hide-other)
774   (global-set-key (kbd "<f9> n") 'bh/toggle-next-task-display)
775   (global-set-key (kbd "<f9> w") 'widen)
776
777   ; change the outline mode prefix from C-c @ to C-c C-2
778   (setq outline-minor-mode-prefix "C-c C-2")
779   ;(add-hook 'outline-minor-mode-hook
780   ;          (lambda () (local-set-key (kbd "C-c C-2")
781   ;                                    outline-mode-prefix-map)))
782
783   (global-set-key (kbd "<f9> I") 'bh/punch-in)
784   (global-set-key (kbd "<f9> O") 'bh/punch-out)
785
786   (global-set-key (kbd "<f9> o") 'bh/make-org-scratch)
787
788   (global-set-key (kbd "<f9> r") 'boxquote-region)
789   (global-set-key (kbd "<f9> s") 'bh/switch-to-scratch)
790
791   (global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
792   (global-set-key (kbd "<f9> T") 'bh/toggle-insert-inactive-timestamp)
793
794   (global-set-key (kbd "<f9> v") 'visible-mode)
795   (global-set-key (kbd "<f9> l") 'org-toggle-link-display)
796   (global-set-key (kbd "<f9> SPC") 'bh/clock-in-last-task)
797   (global-set-key (kbd "C-<f9>") 'previous-buffer)
798   (global-set-key (kbd "M-<f9>") 'org-toggle-inline-images)
799   (global-set-key (kbd "C-x n r") 'narrow-to-region)
800   (global-set-key (kbd "C-<f10>") 'next-buffer)
801   (global-set-key (kbd "<f11>") 'org-clock-goto)
802   (global-set-key (kbd "C-<f11>") 'org-clock-in)
803   (global-set-key (kbd "C-s-<f12>") 'bh/save-then-publish)
804   (global-set-key (kbd "C-c c") 'org-capture)
805
806 #+END_SRC
807 ** Utility Functions
808 #+BEGIN_SRC emacs-lisp
809   (defun bh/hide-other ()
810     (interactive)
811     (save-excursion
812       (org-back-to-heading 'invisible-ok)
813       (hide-other)
814       (org-cycle)
815       (org-cycle)
816       (org-cycle)))
817
818   (defun bh/set-truncate-lines ()
819     "Toggle value of truncate-lines and refresh window display."
820     (interactive)
821     (setq truncate-lines (not truncate-lines))
822     ;; now refresh window display (an idiom from simple.el):
823     (save-excursion
824       (set-window-start (selected-window)
825                         (window-start (selected-window)))))
826
827   (defun bh/make-org-scratch ()
828     (interactive)
829     (find-file "/tmp/publish/scratch.org")
830     (gnus-make-directory "/tmp/publish"))
831
832   (defun bh/switch-to-scratch ()
833     (interactive)
834     (switch-to-buffer "*scratch*"))
835
836   (setq org-use-fast-todo-selection t)
837   (setq org-treat-S-cursor-todo-selection-as-state-change nil)
838
839   ; create function to create headlines in file. This comes from
840   ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
841   (defun my/org-add-ids-to-headlines-in-file ()
842     "Add ID properties to all headlines in the current file which
843   do not already have one."
844     (interactive)
845     (org-map-entries 'org-id-get-create))
846   ; if we wanted to do this to every buffer, do the following:
847   ; (add-hook 'org-mode-hook
848   ;           (lambda ()
849   ;             (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
850 #+END_SRC
851 ** Keywords (TODO)
852 #+BEGIN_SRC emacs-lisp
853   (setq org-todo-keywords
854         (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
855                 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
856
857   (setq org-todo-keyword-faces
858         (quote (("TODO" :foreground "red" :weight bold)
859                 ("NEXT" :foreground "blue" :weight bold)
860                 ("DONE" :foreground "forest green" :weight bold)
861                 ("WAITING" :foreground "orange" :weight bold)
862                 ("HOLD" :foreground "magenta" :weight bold)
863                 ("CANCELLED" :foreground "forest green" :weight bold)
864                 ("MEETING" :foreground "forest green" :weight bold)
865                 ("PHONE" :foreground "forest green" :weight bold))))
866
867   (setq org-todo-state-tags-triggers
868         (quote (("CANCELLED" ("CANCELLED" . t))
869                 ("WAITING" ("WAITING" . t))
870                 ("HOLD" ("WAITING") ("HOLD" . t))
871                 (done ("WAITING") ("HOLD"))
872                 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
873                 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
874                 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
875
876
877
878   ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
879   ; add ids on creation of nodes
880   (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
881
882
883   ; resolve clocks after 10 minutes of idle; use xprintidle
884   ; (setq org-clock-idle-time 10)
885   ; (setq org-clock-x11idle-program-name "xprintidle")
886
887   ; this is from http://doc.norang.ca/org-mode.html#Capture
888   ; use C-M-r for org mode capture
889   (global-set-key (kbd "C-M-r") 'org-capture)
890
891   ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
892   (setq org-refile-targets (quote ((nil :maxlevel . 9)
893                                    (org-agenda-files :maxlevel . 9))))
894
895   ; Use full outline paths for refile targets - we file directly with IDO
896   (setq org-refile-use-outline-path t)
897
898   ; Targets complete directly with IDO
899   (setq org-outline-path-complete-in-steps nil)
900
901   ; Allow refile to create parent tasks with confirmation
902   (setq org-refile-allow-creating-parent-nodes (quote confirm))
903
904   ; ; Use IDO for both buffer and file completion and ido-everywhere to t
905   ; (setq org-completion-use-ido t)
906   ; (setq ido-everywhere t)
907   ; (setq ido-max-directory-size 100000)
908   ; (ido-mode (quote both))
909   ; ; Use the current window when visiting files and buffers with ido
910   ; (setq ido-default-file-method 'selected-window)
911   ; (setq ido-default-buffer-method 'selected-window)
912   ; ; Use the current window for indirect buffer display
913   ; (setq org-indirect-buffer-display 'current-window)
914
915
916   ;;;; Refile settings
917   ; Exclude DONE state tasks from refile targets
918   (defun bh/verify-refile-target ()
919     "Exclude todo keywords with a done state from refile targets"
920     (not (member (nth 2 (org-heading-components)) org-done-keywords)))
921
922   (setq org-refile-target-verify-function 'bh/verify-refile-target)
923
924   ;; ensure that emacsclient will show just the note to be edited when invoked
925   ;; from Mutt, and that it will shut down emacsclient once finished;
926   ;; fallback to legacy behavior when not invoked via org-protocol.
927   (require 'org-protocol)
928   ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
929   (setq my-org-protocol-flag nil)
930   (defadvice org-capture-finalize (after delete-frame-at-end activate)
931     "Delete frame at remember finalization"
932     (progn (if my-org-protocol-flag (delete-frame))
933            (setq my-org-protocol-flag nil)))
934   (defadvice org-capture-refile (around delete-frame-after-refile activate)
935     "Delete frame at remember refile"
936     (if my-org-protocol-flag
937         (progn
938           (setq my-org-protocol-flag nil)
939           ad-do-it
940           (delete-frame))
941       ad-do-it)
942     )
943   (defadvice org-capture-kill (after delete-frame-at-end activate)
944     "Delete frame at remember abort"
945     (progn (if my-org-protocol-flag (delete-frame))
946            (setq my-org-protocol-flag nil)))
947   (defadvice org-protocol-capture (before set-org-protocol-flag activate)
948     (setq my-org-protocol-flag t))
949
950   (defadvice org-insert-todo-heading (after dla/create-id activate)
951     (org-id-get-create)
952     )
953
954   ;; org modules
955   (add-to-list 'org-modules 'org-habit)
956
957   ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
958   (defun open-mail-in-mutt (message)
959     "Open a mail message in Mutt, using an external terminal.
960
961   Message can be specified either by a path pointing inside a
962   Maildir, or by Message-ID."
963     (interactive "MPath or Message-ID: ")
964     (shell-command
965      (format "faf xterm -e \"%s %s\""
966          (substitute-in-file-name "$HOME/bin/mutt_open") message)))
967
968   ;; add support for "mutt:ID" links
969   (org-add-link-type "mutt" 'open-mail-in-mutt)
970
971   (defun my-org-mode-setup ()
972     (load-library "reftex")
973     (and (buffer-file-name)
974          (file-exists-p (buffer-file-name))
975          (progn
976            (reftex-parse-all)
977            (reftex-set-cite-format
978             '((?b . "[[bib:%l][%l-bib]]")
979               (?n . "[[notes:%l][%l-notes]]")
980               (?c . "\\cite{%l}")
981               (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
982            ))
983     (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
984     (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
985     (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
986     (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
987     )
988   (add-hook 'org-mode-hook 'my-org-mode-setup)
989
990   (defun org-mode-reftex-search ()
991     (interactive)
992     (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
993
994   (defun open-research-paper (bibtexkey)
995     "Open a paper by bibtex key"
996     (interactive "bibtex key: ")
997     (shell-command
998      (format "%s %s"
999          (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1000   (org-add-link-type "papers" 'open-research-paper)
1001   (defun open-research-paper-pdf (bibtexkey)
1002     "Open a paper pdf by bibtex key"
1003     (interactive "bibtex key: ")
1004     (shell-command
1005      (format "%s -p evince_annot %s"
1006          (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1007   (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1008
1009   (add-to-list 'org-link-abbrev-alist
1010                '("notes" .
1011                  "~/projects/research/paper_notes.org::#%s"))
1012
1013   ; I pretty much always want hiearchical checkboxes
1014   (setq org-hierachical-checkbox-statistics nil)
1015
1016   ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1017   (add-to-list 'org-structure-template-alist
1018                '("E" "\\begin{equation}\n?\n\\end{equation}"))
1019
1020    ;; stolen from
1021   ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1022   (defun my-rtcite-export-handler (path desc format)
1023     (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1024     (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1025                      (match-string 1 path)))
1026            (path (substring path 0 (match-beginning 0))))
1027       (cond ((eq format 'latex)
1028              (if (or (not desc) 
1029                      (equal 0 (search "rtcite:" desc)))
1030                  (format "\\cite{%s}" search)
1031                (format "\\cite[%s]{%s}" desc search))))))
1032
1033   (org-add-link-type "rtcite" 
1034                      'org-bibtex-open
1035                      'my-rtcite-export-handler)
1036
1037
1038 #+END_SRC
1039 ** Org Mobile Configuration
1040 #+BEGIN_SRC emacs-lisp
1041   (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1042   (when (string= system-name "linnode")
1043     (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1044   (setq-default org-directory "/home/don/org-mode/")
1045   (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1046
1047 #+END_SRC
1048 ** Org iCal Support
1049 #+BEGIN_SRC emacs-lisp
1050   ;; org mode ical export
1051   (setq org-icalendar-timezone "America/Los_Angeles")
1052   (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1053   ;; we already add the id manually
1054   ;; (setq org-icalendar-store-UID t)
1055
1056 #+END_SRC
1057 ** General Org Babel Configuration
1058 #+BEGIN_SRC emacs-lisp
1059   ;; org babel support
1060   (org-babel-do-load-languages
1061    'org-babel-load-languages
1062    '((emacs-lisp . t )
1063      (R . t)
1064      (latex . t)
1065      (ditaa . t)
1066      (dot . t)
1067      ))
1068   ;; use graphviz-dot for dot things
1069   (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1070   ;; org-babel-by-backend
1071   (defmacro org-babel-by-backend (&rest body)
1072      `(case (if (boundp 'backend) 
1073                 (org-export-backend-name backend)
1074               nil) ,@body))
1075
1076   (defun my/fix-inline-images ()
1077     (when org-inline-image-overlays
1078       (org-redisplay-inline-images)))
1079
1080   (add-hook 'org-babel-after-execute-hook
1081              'my/fix-inline-images)
1082
1083 #+END_SRC
1084 ** LaTeX configuration
1085    :PROPERTIES:
1086    :ID:       7135ba17-6a50-4eed-84ca-b90afa5b12f8
1087    :END:
1088 #+BEGIN_SRC emacs-lisp
1089   (require 'ox-latex)
1090   (add-to-list 'org-latex-classes
1091            '("memarticle"
1092          "\\documentclass[11pt,oneside,article]{memoir}\n"
1093          ("\\section{%s}" . "\\section*{%s}")
1094          ("\\subsection{%s}" . "\\subsection*{%s}")
1095          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1096          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1097          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1098
1099   (setq org-beamer-outline-frame-options "")
1100   (add-to-list 'org-latex-classes
1101            '("beamer"
1102          "\\documentclass[ignorenonframetext]{beamer}
1103   [NO-DEFAULT-PACKAGES]
1104   [PACKAGES]
1105   [EXTRA]"
1106          ("\\section{%s}" . "\\section*{%s}")
1107          ("\\subsection{%s}" . "\\subsection*{%s}")
1108          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1109          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1110          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1111
1112   (add-to-list 'org-latex-classes
1113            '("membook"
1114          "\\documentclass[11pt,oneside]{memoir}\n"
1115          ("\\chapter{%s}" . "\\chapter*{%s}")
1116          ("\\section{%s}" . "\\section*{%s}")
1117          ("\\subsection{%s}" . "\\subsection*{%s}")
1118          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1119
1120   (add-to-list 'org-latex-classes
1121            '("letter"
1122          "\\documentclass[11pt]{letter}
1123   [NO-DEFAULT-PACKAGES]
1124   [PACKAGES]
1125   [EXTRA]"
1126      ("\\section{%s}" . "\\section*{%s}")
1127          ("\\subsection{%s}" . "\\subsection*{%s}")
1128          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1129          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1130          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1131
1132   (add-to-list 'org-latex-classes
1133            '("dlacv"
1134          "\\documentclass{dlacv}
1135   [NO-DEFAULT-PACKAGES]
1136   [NO-PACKAGES]
1137   [NO-EXTRA]"
1138          ("\\section{%s}" . "\\section*{%s}")
1139          ("\\subsection{%s}" . "\\subsection*{%s}")
1140          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1141          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1142          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1143
1144
1145   (add-to-list 'org-latex-classes
1146            '("dlaresume"
1147          "\\documentclass{dlaresume}
1148   [NO-DEFAULT-PACKAGES]
1149   [NO-PACKAGES]
1150   [NO-EXTRA]"
1151          ("\\section{%s}" . "\\section*{%s}")
1152          ("\\subsection{%s}" . "\\subsection*{%s}")
1153          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1154          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1155          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1156
1157
1158   ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
1159   ;; but adapted to use latexmk 4.22 or higher.  
1160   (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
1161
1162   ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
1163   (setq org-latex-default-packages-alist
1164     '(("" "amsmath" t)
1165       ("" "unicode-math" t)
1166       ))
1167   (setq org-latex-packages-alist
1168     '(("" "graphicx" t)
1169       ("" "fontspec" t)
1170       ("" "xunicode" t)
1171       ("" "hyperref" t)
1172       ("" "url" t)
1173       ("" "rotating" t)
1174       ("" "longtable" nil)
1175       ("" "float" )))
1176
1177   ;; make equations larger
1178   (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
1179
1180   (defun org-create-formula--latex-header ()
1181     "Return LaTeX header appropriate for previewing a LaTeX snippet."
1182     (let ((info (org-combine-plists (org-export--get-global-options
1183              (org-export-get-backend 'latex))
1184             (org-export--get-inbuffer-options
1185              (org-export-get-backend 'latex)))))
1186       (org-latex-guess-babel-language
1187        (org-latex-guess-inputenc
1188     (org-splice-latex-header
1189      org-format-latex-header
1190      org-latex-default-packages-alist
1191      nil t
1192      (plist-get info :latex-header)))
1193        info)))
1194
1195
1196   ; support ignoring headers in org mode export to latex
1197   ; from http://article.gmane.org/gmane.emacs.orgmode/67692
1198   (defadvice org-latex-headline (around my-latex-skip-headlines
1199                     (headline contents info) activate)
1200     (if (member "ignoreheading" (org-element-property :tags headline))
1201     (setq ad-return-value contents)
1202       ad-do-it))
1203
1204   ;; keep latex logfiles
1205
1206   (setq org-latex-remove-logfiles nil)
1207
1208   ;; Resume clocking task when emacs is restarted
1209   (org-clock-persistence-insinuate)
1210   ;;
1211   ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
1212   (setq org-clock-history-length 23)
1213   ;; Resume clocking task on clock-in if the clock is open
1214   (setq org-clock-in-resume t)
1215   ;; Change tasks to NEXT when clocking in; this avoids clocking in when
1216   ;; there are things like PHONE calls
1217   (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
1218   ;; Separate drawers for clocking and logs
1219   (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
1220   ;; Save clock data and state changes and notes in the LOGBOOK drawer
1221   (setq org-clock-into-drawer t)
1222   (setq org-log-into-drawer t)
1223   ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
1224   (setq org-clock-out-remove-zero-time-clocks t)
1225   ;; Clock out when moving task to a done state
1226   (setq org-clock-out-when-done t)
1227   ;; Save the running clock and all clock history when exiting Emacs, load it on startup
1228   (setq org-clock-persist t)
1229   ;; Do not prompt to resume an active clock
1230   (setq org-clock-persist-query-resume nil)
1231   ;; Enable auto clock resolution for finding open clocks
1232   (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
1233   ;; Include current clocking task in clock reports
1234   (setq org-clock-report-include-clocking-task t)
1235
1236   ;; the cache seems to be broken
1237   (setq org-element-use-cache nil)
1238
1239   (defvar bh/keep-clock-running nil)
1240
1241   (defun bh/is-task-p ()
1242     "Any task with a todo keyword and no subtask"
1243     (save-restriction
1244       (widen)
1245       (let ((has-subtask)
1246             (subtree-end (save-excursion (org-end-of-subtree t)))
1247             (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1248         (save-excursion
1249           (forward-line 1)
1250           (while (and (not has-subtask)
1251                       (< (point) subtree-end)
1252                       (re-search-forward "^\*+ " subtree-end t))
1253             (when (member (org-get-todo-state) org-todo-keywords-1)
1254               (setq has-subtask t))))
1255         (and is-a-task (not has-subtask)))))
1256
1257   (defun bh/is-subproject-p ()
1258     "Any task which is a subtask of another project"
1259     (let ((is-subproject)
1260           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1261       (save-excursion
1262         (while (and (not is-subproject) (org-up-heading-safe))
1263           (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1264             (setq is-subproject t))))
1265       (and is-a-task is-subproject)))
1266
1267
1268   (defun bh/clock-in-to-next (kw)
1269     "Switch a task from TODO to NEXT when clocking in.
1270   Skips capture tasks, projects, and subprojects.
1271   Switch projects and subprojects from NEXT back to TODO"
1272     (when (not (and (boundp 'org-capture-mode) org-capture-mode))
1273       (cond
1274        ((and (member (org-get-todo-state) (list "TODO"))
1275          (bh/is-task-p))
1276     "NEXT")
1277        ((and (member (org-get-todo-state) (list "NEXT"))
1278          (bh/is-project-p))
1279     "TODO"))))
1280
1281   (defun bh/punch-in (arg)
1282     "Start continuous clocking and set the default task to the
1283   selected task.  If no task is selected set the Organization task
1284   as the default task."
1285     (interactive "p")
1286     (setq bh/keep-clock-running t)
1287     (if (equal major-mode 'org-agenda-mode)
1288     ;;
1289     ;; We're in the agenda
1290     ;;
1291     (let* ((marker (org-get-at-bol 'org-hd-marker))
1292            (tags (org-with-point-at marker (org-get-tags-at))))
1293       (if (and (eq arg 4) tags)
1294           (org-agenda-clock-in '(16))
1295         (bh/clock-in-organization-task-as-default)))
1296       ;;
1297       ;; We are not in the agenda
1298       ;;
1299       (save-restriction
1300     (widen)
1301     ; Find the tags on the current task
1302     (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
1303         (org-clock-in '(16))
1304       (bh/clock-in-organization-task-as-default)))))
1305
1306   (defun bh/punch-out ()
1307     (interactive)
1308     (setq bh/keep-clock-running nil)
1309     (when (org-clock-is-active)
1310       (org-clock-out))
1311     (org-agenda-remove-restriction-lock))
1312
1313   (defun bh/clock-in-default-task ()
1314     (save-excursion
1315       (org-with-point-at org-clock-default-task
1316     (org-clock-in))))
1317
1318   (defun bh/clock-in-parent-task ()
1319     "Move point to the parent (project) task if any and clock in"
1320     (let ((parent-task))
1321       (save-excursion
1322     (save-restriction
1323       (widen)
1324       (while (and (not parent-task) (org-up-heading-safe))
1325         (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1326           (setq parent-task (point))))
1327       (if parent-task
1328           (org-with-point-at parent-task
1329         (org-clock-in))
1330         (when bh/keep-clock-running
1331           (bh/clock-in-default-task)))))))
1332
1333   (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
1334
1335   (defun bh/clock-in-organization-task-as-default ()
1336     (interactive)
1337     (org-with-point-at (org-id-find bh/organization-task-id 'marker)
1338       (org-clock-in '(16))))
1339
1340   (defun bh/clock-out-maybe ()
1341     (when (and bh/keep-clock-running
1342            (not org-clock-clocking-in)
1343            (marker-buffer org-clock-default-task)
1344            (not org-clock-resolving-clocks-due-to-idleness))
1345       (bh/clock-in-parent-task)))
1346
1347   ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
1348
1349   (require 'org-id)
1350   (defun bh/clock-in-task-by-id (id)
1351     "Clock in a task by id"
1352     (org-with-point-at (org-id-find id 'marker)
1353       (org-clock-in nil)))
1354
1355   (defun bh/clock-in-last-task (arg)
1356     "Clock in the interrupted task if there is one
1357   Skip the default task and get the next one.
1358   A prefix arg forces clock in of the default task."
1359     (interactive "p")
1360     (let ((clock-in-to-task
1361        (cond
1362         ((eq arg 4) org-clock-default-task)
1363         ((and (org-clock-is-active)
1364           (equal org-clock-default-task (cadr org-clock-history)))
1365          (caddr org-clock-history))
1366         ((org-clock-is-active) (cadr org-clock-history))
1367         ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
1368         (t (car org-clock-history)))))
1369       (widen)
1370       (org-with-point-at clock-in-to-task
1371     (org-clock-in nil))))
1372
1373
1374   (defun org-export-to-ods ()
1375     (interactive)
1376     (let ((csv-file "data.csv"))
1377       (org-table-export csv-file "orgtbl-to-csv")
1378       (org-odt-convert csv-file "ods" 'open)))
1379
1380   ; allow for zero-width-space to be a break in regexp too
1381   ; (setcar org-emphasis-regexp-components "​ [:space:] \t('\"{")
1382   ; (setcar (nthcdr 1 org-emphasis-regexp-components) "​ [:space:]- \t.,:!?;'\")}\\")
1383   ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
1384
1385   ;; support inserting screen shots
1386   (defun my/org-insert-screenshot ()
1387     "Take a screenshot into a time stamped unique-named file in the
1388   same directory as the org-buffer and insert a link to this file."
1389     (interactive)
1390     (defvar my/org-insert-screenshot/filename)
1391     (setq my/org-insert-screenshot/filename
1392       (read-file-name
1393        "Screenshot to insert: "
1394        nil
1395        (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
1396        )
1397       )
1398     (call-process "import" nil nil nil my/org-insert-screenshot/filename)
1399     (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
1400     (org-display-inline-images))
1401
1402   (defun my/fix-inline-images ()
1403     (when org-inline-image-overlays
1404       (org-redisplay-inline-images)))
1405
1406   (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
1407
1408   ;; use xelatex to preview with imagemagick
1409   (add-to-list 'org-preview-latex-process-alist
1410            '(xelateximagemagick
1411         :programs ("xelatex" "convert")
1412         :description "pdf > png"
1413         :message "you need to install xelatex and imagemagick"
1414         :use-xcolor t
1415         :image-input-type "pdf"
1416         :image-output-type "png"
1417         :image-size-adjust (1.0 . 1.0)
1418         :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
1419         :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
1420            )
1421   ;; use xelatex by default
1422   (setq org-preview-latex-default-process 'xelateximagemagick)
1423
1424   ; from http://orgmode.org/Changes.html
1425   (defun my/org-repair-property-drawers ()
1426     "Fix properties drawers in current buffer.
1427    Ignore non Org buffers."
1428     (interactive)
1429     (when (eq major-mode 'org-mode)
1430       (org-with-wide-buffer
1431        (goto-char (point-min))
1432        (let ((case-fold-search t)
1433          (inline-re (and (featurep 'org-inlinetask)
1434                  (concat (org-inlinetask-outline-regexp)
1435                      "END[ \t]*$"))))
1436      (org-map-entries
1437       (lambda ()
1438         (unless (and inline-re (org-looking-at-p inline-re))
1439           (save-excursion
1440         (let ((end (save-excursion (outline-next-heading) (point))))
1441           (forward-line)
1442           (when (org-looking-at-p org-planning-line-re) (forward-line))
1443           (when (and (< (point) end)
1444                  (not (org-looking-at-p org-property-drawer-re))
1445                  (save-excursion
1446                    (and (re-search-forward org-property-drawer-re end t)
1447                     (eq (org-element-type
1448                      (save-match-data (org-element-at-point)))
1449                     'drawer))))
1450             (insert (delete-and-extract-region
1451                  (match-beginning 0)
1452                  (min (1+ (match-end 0)) end)))
1453             (unless (bolp) (insert "\n"))))))))))))
1454
1455 #+END_SRC
1456 ** End use-package
1457 #+BEGIN_SRC emacs-lisp
1458   )
1459 #+END_SRC
1460 * Keybindings
1461 ** Override other things
1462 #+BEGIN_SRC emacs-lisp
1463   ; apparently things like to step on C-;, so we'll use a hack from
1464   ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
1465
1466   (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
1467
1468   ; use iedit everywhere
1469   (define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
1470   ;; use outline mode keybindings everywhere
1471   ;; (define-key my-keys-minor-mode-map (kbd "C-;") 'my/mydra-outline/body)
1472
1473   (define-minor-mode my-keys-minor-mode
1474     "A minor mode so that my key settings override annoying major modes."
1475     t " my-keys" 'my-keys-minor-mode-map)
1476
1477   (my-keys-minor-mode 1)
1478   (defun my-minibuffer-setup-hook ()
1479     (my-keys-minor-mode 0))
1480
1481   (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
1482   (defadvice load (after give-my-keybindings-priority)
1483     "Try to ensure that my keybindings always have priority."
1484     (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
1485         (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
1486           (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
1487           (add-to-list 'minor-mode-map-alist mykeys))))
1488   (ad-activate 'load)
1489 #+END_SRC
1490
1491 * Misc (uncharacterized)
1492 #+BEGIN_SRC emacs-lisp
1493   (setq bibtex-user-optional-fields (quote (("annote" "Personal annotation (ignored)") ("abstract" "") ("pmid" "") ("doi" ""))))
1494   (setq calendar-latitude 40.11)
1495   (setq calendar-longitude -88.24)
1496   (setq case-fold-search t)
1497   (setq confirm-kill-emacs (quote y-or-n-p))
1498   (setq cperl-lazy-help-time nil)
1499   (setq debian-changelog-mailing-address "don@debian.org")
1500   (display-time)
1501   (setq display-time-24hr-format t)
1502   (setq display-time-day-and-date t)
1503   (display-time-mode 1)
1504   (setq font-latex-fontify-script nil)
1505   (setq font-latex-fontify-sectioning (quote color))
1506   (setq font-latex-script-display (quote (nil)))
1507   (global-auto-revert-mode 1)
1508   (global-font-lock-mode 1)
1509   (icomplete-mode 1)
1510   (setq log-edit-keep-buffer t)
1511   (setq mail-user-agent (quote sendmail-user-agent))
1512   (setq markdown-enable-math t)
1513   (setq markdown-follow-wiki-link-on-enter nil)
1514   (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
1515   (setq post-email-address "don@donarmstrong.com")
1516   (setq post-kill-quoted-sig nil)
1517   (setq post-mail-message "mutt\\(ng\\|\\)-[a-z0-9]+-[0-9]+-.*")
1518   (setq post-uses-fill-mode nil)
1519   (setq ps-footer-font-size (quote (8 . 10)))
1520   (setq ps-header-font-size (quote (8 . 10)))
1521   (setq ps-header-title-font-size (quote (10 . 10)))
1522   (setq ps-line-number-color "blue")
1523   (setq ps-print-footer t)
1524   (setq ps-print-footer-frame nil)
1525   (setq ps-print-only-one-header t)
1526   (setq safe-local-variable-values (quote ((auto-save-default) (make-backup-files))))
1527   (setq sentence-end "[.?!][]\"')]*\\($\\|   \\| \\)[    
1528   ]*")
1529   (setq sentence-end-double-space nil)
1530   ; enable matching parenthesis
1531   (show-paren-mode 1)
1532   (tool-bar-mode -1)
1533   (setq user-mail-address "don@donarmstrong.com")
1534   (setq vc-delete-logbuf-window nil)
1535   (setq vc-follow-symlinks t)
1536
1537   ;; use git before SVN; use CVS earlier, because I have CVS
1538   ;; repositories inside of git directories
1539   (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
1540
1541   ;; switch back to the old primary selection method
1542   (setq x-select-enable-clipboard nil)
1543   (setq x-select-enable-primary t)
1544   ; (setq mouse-drag-copy-region t)
1545
1546   (fset 'perl-mode 'cperl-mode)
1547   ;;(load-file "cperl-mode.el")
1548
1549   (require 'vcl-mode)
1550
1551   (require 'tex-site)
1552   ;;(require 'psvn)
1553   ;;(require 'ecasound)
1554   ;;(require 'emacs-wiki)
1555   (require 'bibtex)
1556   (require 'post)
1557   ;;(require 'fixme)
1558   ; (require 'google-weather)
1559   ; (require 'org-google-weather)
1560   ; (setq-default org-google-weather-format "%i %c, [%l,%h] %s %C")
1561   
1562   (global-set-key "\C-xp" 'server-edit)
1563
1564   (setq-default auto-mode-alist (cons '("\.wml$" . 
1565                     (lambda () (html-mode) (auto-fill-mode)))
1566                   auto-mode-alist))
1567
1568
1569   ; use markdown mode for mdwn files
1570   (add-to-list 'auto-mode-alist '("\\.mdwn$" . markdown-mode))
1571   (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
1572
1573
1574   ;; tramp configuration
1575   (setq tramp-use-ssh-controlmaster-options nil)
1576
1577   ; mail configuration
1578   (add-to-list 'auto-mode-alist '("muttng-[a-z0-9]+-[0-9]+-" . message-mode))
1579   (add-to-list 'auto-mode-alist '("muttngrc" . muttrc-mode))
1580
1581   (add-to-list 'auto-mode-alist '("mutt-[a-z0-9]+-[0-9]+-" . message-mode))
1582   (add-to-list 'auto-mode-alist '("muttrc" . muttrc-mode))
1583   (defun my-message-mode-settings ()
1584     (font-lock-add-keywords nil
1585                             '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1586                                (0 'message-multiply-quoted-text-face))
1587                               ("^[ \t]*>[ \t]*>.*$"
1588                                (0 'message-double-quoted-text-face))))
1589     (local-set-key (kbd "C-c C-a") 'my-post-attach-file)
1590     )
1591   (add-hook 'message-mode-hook 'my-message-mode-settings)
1592
1593   (defun my-post-attach-file ()
1594     "Prompt for an attachment."
1595     (interactive)
1596     (let ((file (read-file-name "Attach file: " nil nil t nil))
1597           (description (string-read "Description: ")))
1598       (my-header-attach-file file description)))
1599
1600   (symbol-function 'my-post-attach-file)
1601
1602   (defun my-header-attach-file (file description)
1603     "Attach a FILE to the current message (works with Mutt).
1604   Argument DESCRIPTION MIME description."
1605     (interactive "fAttach file: \nsDescription: ")
1606     (when (> (length file) 0)
1607       (save-excursion
1608         (save-match-data
1609           (save-restriction
1610             (widen)
1611             (goto-char (point-min))
1612             (search-forward-regexp "^$")
1613             (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1614                             description "\n"))
1615             (message (concat "Attached '" file "'."))
1616             (setq post-has-attachment t))))))
1617
1618
1619
1620   (setq mail-yank-prefix "> ")
1621
1622   (global-unset-key "\M-g")
1623   (global-set-key "\M-g" 'goto-line)
1624
1625   ;; self-insert-command hack.
1626   ;;   Without this, "if<SP>" expands to
1627   ;;   if ( -!-) {
1628   ;;   }
1629   ;;   which really should be,
1630   ;;   if (-!-) {
1631   ;;   }
1632
1633
1634
1635   ;(load-library "php-mode")
1636
1637   (setq-default c-indent-level 4)
1638   (setq-default c-brace-imaginary-offset 0)
1639   (setq-default c-brace-offset -4)
1640   (setq-default c-argdecl-indent 4)
1641   (setq-default c-label-offset -4)
1642   (setq-default c-continued-statement-offset 4)
1643   ; tabs are annoying
1644   (setq-default indent-tabs-mode nil)
1645   (setq-default tab-width 4)
1646
1647
1648   ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
1649   ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
1650   ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
1651   ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
1652   ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
1653
1654
1655   (defun insert-date ()
1656     "Insert date at point."
1657     (interactive)
1658     (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
1659   (global-set-key "\C-[d" 'insert-date)
1660
1661   (defun unfill-paragraph (arg)
1662     "Pull this whole paragraph up onto one line."
1663     (interactive "*p")
1664     (let ((fill-column 10000))
1665       (fill-paragraph arg))
1666     )
1667
1668   (column-number-mode t)
1669
1670   (server-start)
1671
1672   ; (require 'mode-compile)
1673
1674   (defadvice server-process-filter (after post-mode-message first activate)
1675     "If the buffer is in post mode, overwrite the server-edit
1676       message with a post-save-current-buffer-and-exit message."
1677     (if (eq major-mode 'post-mode)
1678         (message
1679          (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
1680                       ; This is also needed to see the magic message.  Set to a higher
1681                       ; number if you have a faster computer or read slower than me.
1682   '(font-lock-verbose 1000)
1683   ;(setq-default server-temp-file-regexp "mutt\(-\|ng-\)")
1684   ; (add-hook 'server-switch-hook 
1685   ;     (function (lambda()
1686   ;             (cond ((string-match "Post" mode-name)
1687   ;                (post-goto-body)))
1688   ;             set-buffer-file-coding-system 'utf-8
1689   ;             )))
1690   ; 
1691
1692   (add-hook 'post-mode-hook
1693         (auto-fill-mode nil)
1694         )
1695   ; abbrev mode settings
1696   ; load abbreviations from 
1697   (setq abbrev-file-name       
1698         "~/.emacs_abbrev_def")
1699
1700   ; read the abbrev file if it exists
1701   (if (file-exists-p abbrev-file-name)
1702       (quietly-read-abbrev-file))
1703
1704   ; for now, use abbrev mode everywhere
1705   (setq default-abbrev-mode t)
1706
1707
1708   (defun insert-function-documentation ()
1709     "Insert function documentation"
1710     (interactive)
1711     (insert-file-contents "/home/don/lib/templates/perl_function_documentation" nil))
1712   (global-set-key "\M-f" 'insert-function-documentation)
1713
1714   (eval-after-load "lilypond-mode" 
1715     '(progn
1716        (load-library "lyqi-mode")
1717        (define-key LilyPond-mode-map "\C-cq" 'lyqi-mode)))
1718
1719   (autoload 'spamassassin-mode "spamassassin-mode" nil t)
1720
1721   (desktop-load-default)
1722   (desktop-read)
1723   '(icomplete-mode on)
1724   (custom-set-faces
1725    ;; custom-set-faces was added by Custom.
1726    ;; If you edit it by hand, you could mess it up, so be careful.
1727    ;; Your init file should contain only one such instance.
1728    ;; If there is more than one, they won't work right.
1729    '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
1730
1731
1732   (put 'upcase-region 'disabled nil)
1733   (put 'downcase-region 'disabled nil)
1734   (put 'narrow-to-region 'disabled nil)
1735
1736   ; (defun turn-on-flyspell ()
1737   ;    "Force flyspell-mode on using a positive arg.  For use in hooks."
1738   ;    (interactive)
1739   ;    (flyspell-mode 1))
1740
1741
1742    ; Outline-minor-mode key map
1743    (define-prefix-command 'cm-map nil "Outline-")
1744    ; HIDE
1745    (define-key cm-map "q" 'hide-sublevels)    ; Hide everything but the top-level headings
1746    (define-key cm-map "t" 'hide-body)         ; Hide everything but headings (all body lines)
1747    (define-key cm-map "o" 'hide-other)        ; Hide other branches
1748    (define-key cm-map "c" 'hide-entry)        ; Hide this entry's body
1749    (define-key cm-map "l" 'hide-leaves)       ; Hide body lines in this entry and sub-entries
1750    (define-key cm-map "d" 'hide-subtree)      ; Hide everything in this entry and sub-entries
1751    ; SHOW
1752    (define-key cm-map "a" 'show-all)          ; Show (expand) everything
1753    (define-key cm-map "e" 'show-entry)        ; Show this heading's body
1754    (define-key cm-map "i" 'show-children)     ; Show this heading's immediate child sub-headings
1755    (define-key cm-map "k" 'show-branches)     ; Show all sub-headings under this heading
1756    (define-key cm-map "s" 'show-subtree)      ; Show (expand) everything in this heading & below
1757    ; MOVE
1758    (define-key cm-map "u" 'outline-up-heading)                ; Up
1759    (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
1760    (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
1761    (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
1762    (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
1763    (global-set-key "\M-o" cm-map)
1764
1765
1766   ; debian stuff
1767   (setq-default debian-changelog-mailing-address "don@debian.org")
1768   (setq-default debian-changelog-full-name "Don Armstrong")
1769
1770   ; ediff configuration
1771   ; don't use the multi-window configuration
1772   (setq ediff-window-setup-function 'ediff-setup-windows-plain)
1773
1774   ; use iedit
1775   (require 'iedit)
1776   (define-key global-map (kbd "C-;") 'iedit-mode)
1777   (global-set-key  (kbd "C-;") 'iedit-mode)
1778
1779   ; fix up css mode to not be silly
1780   ; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1781   (setq cssm-indent-level 4)
1782   (setq cssm-newline-before-closing-bracket t)
1783   (setq cssm-indent-function #'cssm-c-style-indenter)
1784   (setq cssm-mirror-mode nil)
1785
1786   (require 'multi-web-mode)
1787   (setq mweb-default-major-mode 'html-mode)
1788   (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
1789                     (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
1790                     (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
1791   (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
1792   (multi-web-global-mode 1)
1793
1794   ;;; alias the new `flymake-report-status-slim' to
1795   ;;; `flymake-report-status'
1796   (defalias 'flymake-report-status 'flymake-report-status-slim)
1797   (defun flymake-report-status-slim (e-w &optional status)
1798     "Show \"slim\" flymake status in mode line."
1799     (when e-w
1800       (setq flymake-mode-line-e-w e-w))
1801     (when status
1802       (setq flymake-mode-line-status status))
1803     (let* ((mode-line " Φ"))
1804       (when (> (length flymake-mode-line-e-w) 0)
1805         (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
1806       (setq mode-line (concat mode-line flymake-mode-line-status))
1807       (setq flymake-mode-line mode-line)
1808       (force-mode-line-update)))
1809
1810   ; load sql-indent when sql is loaded
1811   (eval-after-load "sql"
1812     '(load-library "sql-indent"))
1813
1814   ; fix up tmux xterm keys
1815   ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
1816   (defun fix-up-tmux-keys ()
1817       "Fix up tmux xterm keys"
1818       (if (getenv "TMUX")
1819           (progn
1820             (let ((x 2) (tkey ""))
1821               (while (<= x 8)
1822                 ;; shift
1823                 (if (= x 2)
1824                     (setq tkey "S-"))
1825                 ;; alt
1826                 (if (= x 3)
1827                     (setq tkey "M-"))
1828                 ;; alt + shift
1829                 (if (= x 4)
1830                     (setq tkey "M-S-"))
1831                 ;; ctrl
1832                 (if (= x 5)
1833                     (setq tkey "C-"))
1834                 ;; ctrl + shift
1835                 (if (= x 6)
1836                     (setq tkey "C-S-"))
1837                 ;; ctrl + alt
1838                 (if (= x 7)
1839                     (setq tkey "C-M-"))
1840                 ;; ctrl + alt + shift
1841                 (if (= x 8)
1842                     (setq tkey "C-M-S-"))
1843
1844                 ;; arrows
1845                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
1846                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
1847                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
1848                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
1849                 ;; home
1850                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
1851                 ;; end
1852                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
1853                 ;; page up
1854                 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
1855                 ;; page down
1856                 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
1857                 ;; insert
1858                 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
1859                 ;; delete
1860                 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
1861                 ;; f1
1862                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
1863                 ;; f2
1864                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
1865                 ;; f3
1866                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
1867                 ;; f4
1868                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
1869                 ;; f5
1870                 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
1871                 ;; f6
1872                 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
1873                 ;; f7
1874                 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
1875                 ;; f8
1876                 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
1877                 ;; f9
1878                 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
1879                 ;; f10
1880                 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
1881                 ;; f11
1882                 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
1883                 ;; f12
1884                 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
1885                 ;; f13
1886                 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
1887                 ;; f14
1888                 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
1889                 ;; f15
1890                 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
1891                 ;; f16
1892                 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
1893                 ;; f17
1894                 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
1895                 ;; f18
1896                 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
1897                 ;; f19
1898                 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
1899                 ;; f20
1900                 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
1901
1902                 (setq x (+ x 1))
1903                 ))
1904             )
1905         )
1906       )
1907   ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
1908
1909   ; procmailmode configuration
1910   (load "procmail_mode")
1911
1912   (load "mode-line-cleaner")
1913
1914   (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
1915     "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
1916     (if (or (buffer-modified-p)
1917             (verify-visited-file-modtime)
1918             (< (* 8 1024 1024) (buffer-size))
1919             (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
1920         ad-do-it
1921       (clear-visited-file-modtime)
1922       (not-modified)))
1923   (ad-activate 'ask-user-about-supersession-threat)
1924
1925   ; apparently things like to step on C-;, so we'll use a hack from
1926   ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
1927
1928   (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
1929
1930   ; use iedit everywhere
1931   (define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
1932
1933   (define-minor-mode my-keys-minor-mode
1934     "A minor mode so that my key settings override annoying major modes."
1935     t " my-keys" 'my-keys-minor-mode-map)
1936
1937   (my-keys-minor-mode 1)
1938   (defun my-minibuffer-setup-hook ()
1939     (my-keys-minor-mode 0))
1940
1941   (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
1942   (defadvice load (after give-my-keybindings-priority)
1943     "Try to ensure that my keybindings always have priority."
1944     (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
1945         (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
1946           (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
1947           (add-to-list 'minor-mode-map-alist mykeys))))
1948   (ad-activate 'load)
1949   (global-set-key "\M- " 'hippie-expand)
1950
1951 #+END_SRC
1952
1953 * END
1954 #+BEGIN_SRC emacs-lisp
1955   (provide 'don-configuration)
1956 #+END_SRC