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