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