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