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