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