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