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