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