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