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