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