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