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