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