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