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