]> git.donarmstrong.com Git - lib.git/blob - emacs_el/configuration/don-configuration.org
it's password-store-generate
[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   (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
34                            ("melpa" . "https://melpa.org/packages/")
35                            ("org" . "http://orgmode.org/elpa/") ))
36   (eval-and-compile
37     (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
38   (mapc #'(lambda (add) (add-to-list 'load-path add))
39     (eval-when-compile
40       (package-initialize)
41       (unless (package-installed-p 'use-package)
42         (package-refresh-contents)
43         (package-install 'use-package))
44       (let ((package-user-dir-real (file-truename package-user-dir)))
45         ;; The reverse is necessary, because outside we mapc
46         ;; add-to-list element-by-element, which reverses.
47         (nreverse (apply #'nconc
48                  ;; Only keep package.el provided loadpaths.
49                  (mapcar #'(lambda (path)
50                      (if (string-prefix-p package-user-dir-real path)
51                          (list path)
52                        nil))
53                      load-path))))))
54
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   (use-package tramp
778     :config
779     (add-to-list 'tramp-methods '("vcsh"
780                                   (tramp-login-program "vcsh")
781                                   (tramp-login-args
782                                    (("enter")
783                                     ("%h")))
784                                   (tramp-remote-shell "/bin/sh")
785                                   (tramp-remote-shell-args
786                                    ("-c")))))
787 #+END_SRC
788 ** Reftex
789 #+BEGIN_SRC emacs-lisp
790   (use-package reftex
791     :ensure t
792     :config
793     (setq-default reftex-default-bibliography
794                     '("~/projects/research/references.bib")))
795 #+END_SRC
796 ** BibTex
797 #+BEGIN_SRC emacs-lisp
798   (use-package bibtex
799     :config (setq bibtex-user-optional-fields
800                   (quote (("annote" "Personal annotation (ignored)")
801                           ("abstract" "")
802                   ("pmid" "")
803                   ("doi" ""))))
804     )
805
806 #+END_SRC
807 ** LaTeX
808 #+BEGIN_SRC emacs-lisp
809   (use-package tex
810     :defer t
811     :ensure auctex
812     :config
813     ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
814     ;; REFTEX (much enhanced management of cross-ref, labels, etc)
815     ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
816     ; (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
817     ; (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
818     ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
819     ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
820     (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
821     (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
822     (add-hook 'LaTeX-mode-hook 'outline-minor-mode)   ; with AUCTeX LaTeX mode
823     (add-hook 'latex-mode-hook 'outline-minor-mode)   ; with Emacs latex mode
824
825     (setq-default reftex-plug-into-AUCTeX t)
826     ;; support fake section headers
827     (setq TeX-outline-extra
828           '(("%chapter" 1)
829             ("%section" 2)
830             ("%subsection" 3)
831             ("%subsubsection" 4)
832             ("%paragraph" 5)))
833     ;; add font locking to the headers
834     (font-lock-add-keywords
835      'latex-mode
836      '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
837         0 'font-lock-keyword-face t)
838        ("^%chapter{\\(.*\\)}"       1 'font-latex-sectioning-1-face t)
839        ("^%section{\\(.*\\)}"       1 'font-latex-sectioning-2-face t)
840        ("^%subsection{\\(.*\\)}"    1 'font-latex-sectioning-3-face t)
841        ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
842        ("^%paragraph{\\(.*\\)}"     1 'font-latex-sectioning-5-face t)))
843
844     ;; use smart quotes by default instead of `` and ''
845     ;; taken from http://kieranhealy.org/esk/kjhealy.html
846     (setq TeX-open-quote "“")
847     (setq TeX-close-quote "”")
848
849     ;; (TeX-add-style-hook
850     ;;  "latex"
851     ;;  (lambda ()
852     ;;    (TeX-add-symbols
853     ;;     '("DLA" 1))))
854     ;; (custom-set-variables
855     ;;  '(font-latex-user-keyword-classes 
856     ;;    '(("fixme" 
857     ;;       ("DLA" "RZ")
858     ;;       font-lock-function-name-face 2 (command 1 t))))
859     ;; ) 
860     (setq-default TeX-parse-self t)
861     (setq-default TeX-auto-save t)
862     (setq-default TeX-master nil)
863     (eval-after-load
864         "latex"
865       '(TeX-add-style-hook
866         "cleveref"
867         (lambda ()
868           (if (boundp 'reftex-ref-style-alist)
869               (add-to-list
870                'reftex-ref-style-alist
871                '("Cleveref" "cleveref"
872                  (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
873           (reftex-ref-style-activate "Cleveref")
874           (TeX-add-symbols
875            '("cref" TeX-arg-ref)
876            '("Cref" TeX-arg-ref)
877            '("cpageref" TeX-arg-ref)
878            '("Cpageref" TeX-arg-ref)))))
879     (eval-after-load
880         "latex"
881       '(add-to-list 'LaTeX-fill-excluded-macros
882                     '("Sexpr")))
883
884     (use-package font-latex
885       :config
886       (setq font-latex-match-reference-keywords
887             '(
888               ("fref" "{")
889               ("Fref" "{")
890               ("citep" "{")
891               ("citet" "{")
892               ("acs" "{")
893               ("acsp" "{")
894               ("ac" "{")
895               ("acp" "{")
896               ("acl" "{")
897               ("aclp" "{")
898               ("acsu" "{")
899               ("aclu" "{")
900               ("acused" "{")
901               ("DLA" "{")
902               ("RZ" "{")
903               ("OM" "{")
904               ("DL" "{")
905               ("fixme" "{"))
906             )
907       )
908     (setq font-latex-fontify-script nil)
909     (setq font-latex-fontify-sectioning (quote color))
910     (setq font-latex-script-display (quote (nil)))
911   )
912
913 #+END_SRC
914 ** ESS
915 #+BEGIN_SRC emacs-lisp
916   (use-package ess
917     :ensure t
918     :commands R
919     :mode ("\\.R\\'" . ess-r-mode)
920     :bind (:map ess-mode-map
921                 ("C-c C-R" . dla/ess-region-remote-eval))
922     :init
923     (autoload 'ess-r-mode "ess-site" nil t)
924     (autoload 'R "ess-site" nil t)
925     :config
926     ; actually load the rest of ess
927     (require 'ess-site)
928     (defun ess-change-directory (path)
929       "Set the current working directory to PATH for both *R* and Emacs."
930       (interactive "Directory to change to: ")
931     
932       (when (file-exists-p path)
933         (ess-command (concat "setwd(\"" path "\")\n"))
934         ;; use file-name-as-directory to ensure it has trailing /
935         (setq default-directory (file-name-as-directory path))))
936     (add-hook 'ess-mode-hook 'flyspell-prog-mode)
937     ;; outlining support for ess modes
938     (add-hook
939      'ess-mode-hook
940      '(lambda ()
941         (outline-minor-mode)
942         (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
943         (defun outline-level ()
944           (cond ((looking-at "^##### ") 1)
945                 ((looking-at "^#### ") 2)
946                 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
947                 (t 1000)))
948         ))
949     (defun dla/ess-region-remote-eval (start end)
950       "Evaluate region in a remote ESS instance"
951       (interactive "r")
952       (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***"))
953       kill-buffer "***essregionremoteeval***")
954     ;; Don't restore history or save workspace image
955     '(inferior-R-args "--no-restore-history --no-save")
956     )
957 #+END_SRC
958
959 ** Rainbowmode
960 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
961
962 #+BEGIN_SRC emacs-lisp
963   (use-package rainbow-mode
964     ;; add ess to the x major mode
965     :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
966     (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
967   )
968 #+END_SRC
969
970 ** Polymode
971 #+BEGIN_SRC emacs-lisp
972   (use-package polymode
973     :config
974     (use-package poly-R)
975     (use-package poly-noweb)
976     (use-package poly-markdown)
977     :mode ("\\.Snw" . poly-noweb+r-mode)
978     :mode ("\\.Rnw" . poly-noweb+r-mode)
979     :mode ("\\.Rmd" . poly-markdown+r-mode)
980     )
981 #+END_SRC
982
983 ** Outlining
984 *** Outline magic
985 #+BEGIN_SRC emacs-lisp
986   (use-package outline-magic)
987 #+END_SRC
988 *** Outline mode
989 #+BEGIN_SRC emacs-lisp
990 ;; change the outline mode prefix from C-c @ to C-c C-2
991 (setq outline-minor-mode-prefix "C-c C-2")
992 ;;(add-hook 'outline-minor-mode-hook
993 ;;          (lambda () (local-set-key (kbd "C-c C-2")
994 ;;                                    outline-mode-prefix-map)))
995
996 #+END_SRC
997 ** Writeroom Mode
998 #+BEGIN_SRC emacs-lisp
999   (use-package writeroom-mode
1000     :config
1001     (defun my/writing-mode ()
1002       "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1003       (interactive)
1004       (if writeroom-mode
1005           (progn
1006             (writeroom-mode -1)
1007             (visual-line-mode -1)
1008             (auto-fill-mode -1)
1009             (visual-fill-column-mode -1)
1010             )
1011         (visual-line-mode 1)
1012         (auto-fill-mode 1)
1013         (visual-fill-column-mode 1)
1014         (writeroom-mode 1))
1015       )
1016     )
1017 #+END_SRC
1018 ** GhostText/Atomic Chrome
1019 #+BEGIN_SRC emacs-lisp
1020   (use-package atomic-chrome
1021     :config
1022     (ignore-errors (atomic-chrome-start-server))
1023     (setq atomic-chrome-buffer-open-style 'full)
1024     )
1025 #+END_SRC
1026 ** Multiple Cursors
1027    :PROPERTIES:
1028    :ID:       6fcf218b-a762-4c37-9339-a8202ddeb544
1029    :END:
1030 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1031 #+BEGIN_SRC emacs-lisp
1032   (use-package multiple-cursors
1033     :bind* (("C-;" . mc/mark-all-dwim)
1034             ("C-<" . mc/mark-previous-like-this)
1035             ("C->" . mc/mark-next-like-this)
1036             ("C-S-c C-S-c" . mc/edit-lines))
1037     )
1038 #+END_SRC
1039 ** Web Mode
1040 #+BEGIN_SRC emacs-lisp
1041   (use-package web-mode
1042     :config
1043     (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1044     (setq web-mode-enable-engine-detection t)
1045     (setq web-mode-engines-alist
1046           '(("template-toolkit" . "\\.tmpl\\'")))
1047     )
1048 #+END_SRC
1049 ** Spamassassin Mode
1050 #+BEGIN_SRC emacs-lisp
1051   (use-package spamassassin-mode
1052     :commands spamassassin-mode
1053     :ensure f
1054     )
1055 #+END_SRC
1056 ** Password Store
1057 #+BEGIN_SRC emacs-lisp
1058   (use-package password-store
1059     :ensure f
1060     :commands password-store-edit password-store-generate
1061     )
1062 #+END_SRC
1063 ** CSS mode
1064 #+BEGIN_SRC emacs-lisp
1065   (use-package css
1066     :mode "\\.css'"
1067     :config
1068     ;; fix up css mode to not be silly
1069     ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1070     (setq cssm-indent-level 4)
1071     (setq cssm-newline-before-closing-bracket t)
1072     (setq cssm-indent-function #'cssm-c-style-indenter)
1073     (setq cssm-mirror-mode nil))
1074 #+END_SRC
1075 ** Abbrev Mode
1076 #+BEGIN_SRC emacs-lisp
1077   (use-package abbrev
1078     :diminish abbrev-mode
1079     :config
1080     ;; load abbreviations from 
1081     (setq abbrev-file-name       
1082           "~/.emacs_abbrev_def")
1083
1084     ;; read the abbrev file if it exists
1085     (if (file-exists-p abbrev-file-name)
1086         (quietly-read-abbrev-file))
1087
1088     ;; for now, use abbrev mode everywhere
1089     (setq default-abbrev-mode t))
1090 #+END_SRC
1091
1092 * Email
1093 ** Mutt
1094 *** Message-mode
1095 #+BEGIN_SRC emacs-lisp
1096   (use-package message
1097     :ensure f
1098     :diminish (message "✉")
1099     :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1100     :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1101     :hook 'my/message-mode-settings
1102     :hook 'turn-on-flyspell
1103     :bind (:map message-mode-map
1104         ("C-c C-a" . my/post-attach-file))
1105     :delight (message-mode "✉")
1106     :config
1107     (defun my/message-mode-settings ()
1108       (font-lock-add-keywords nil
1109                   '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1110                  (0 'message-multiply-quoted-text-face))
1111                 ("^[ \t]*>[ \t]*>.*$"
1112                  (0 'message-double-quoted-text-face))))
1113       )
1114
1115     (defun my/post-attach-file ()
1116       "Prompt for an attachment."
1117       (interactive)
1118       (let ((file (read-file-name "Attach file: " nil nil t nil)))
1119         (my/header-attach-file file "")))
1120
1121     (defun my/header-attach-file (file description)
1122       "Attach a FILE to the current message (works with Mutt).
1123     Argument DESCRIPTION MIME description."
1124       (interactive "fAttach file: \nsDescription: ")
1125       (when (> (length file) 0)
1126     (save-excursion
1127       (save-match-data
1128         (save-restriction
1129           (widen)
1130           (goto-char (point-min))
1131           (search-forward-regexp "^$")
1132           (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1133                   description "\n"))
1134           (message (concat "Attached '" file "'."))
1135           (setq post-has-attachment t))))))
1136
1137     (setq mail-yank-prefix "> ")
1138   )
1139 #+END_SRC
1140 *** Muttrc mode
1141 #+BEGIN_SRC emacs-lisp
1142   (use-package muttrc-mode
1143     :mode "muttngrc"
1144     :mode "muttrc"
1145   )
1146
1147 #+END_SRC
1148 * Base emacs
1149 ** Reverting buffers
1150 #+BEGIN_SRC emacs-lisp
1151   (use-package autorevert
1152     :diminish auto-revert-mode
1153     :config
1154     (setq global-auto-revert-non-file-buffers t
1155           global-auto-revert-ignore-modes '(pdf-view-mode)
1156           auto-revert-verbose nil)
1157     (global-auto-revert-mode 1))
1158 #+END_SRC
1159 * Org Mode
1160 ** Use-package and load things
1161 #+BEGIN_SRC emacs-lisp
1162
1163   (use-package org
1164     :delight (org-mode "ø")
1165     :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1166     :bind (("C-c l"  . org-store-link)
1167            ("C-c a"  . org-agenda)
1168            ("C-c b"  . org-iswitchb))
1169 #+END_SRC
1170 ** Agenda Configuration
1171 #+BEGIN_SRC emacs-lisp
1172   :config
1173   (setq-default org-log-done 'time)
1174   (setq-default org-agenda-ndays 5)
1175
1176   ;; agenda configuration
1177   ;; Do not dim blocked tasks
1178   (setq org-agenda-dim-blocked-tasks nil)
1179   (setq org-agenda-inhibit-startup t)
1180   (setq org-agenda-use-tag-inheritance nil)
1181
1182   ;; Compact the block agenda view
1183   (setq org-agenda-compact-blocks t)
1184
1185   ;; Custom agenda command definitions
1186   (setq org-agenda-custom-commands
1187         (quote (("N" "Notes" tags "NOTE"
1188                  ((org-agenda-overriding-header "Notes")
1189                   (org-tags-match-list-sublevels t)))
1190                 ("h" "Habits" tags-todo "STYLE=\"habit\""
1191                  ((org-agenda-overriding-header "Habits")
1192                   (org-agenda-sorting-strategy
1193                    '(todo-state-down effort-up category-keep))))
1194                 (" " "Agenda"
1195                  ((agenda "" nil)
1196                   (tags "REFILE"
1197                         ((org-agenda-overriding-header "Tasks to Refile")
1198                          (org-tags-match-list-sublevels nil)))
1199                   (tags-todo "-CANCELLED/!"
1200                              ((org-agenda-overriding-header "Stuck Projects")
1201                               (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1202                               (org-agenda-sorting-strategy
1203                                '(category-keep))))
1204                   (tags-todo "-HOLD-CANCELLED/!"
1205                              ((org-agenda-overriding-header "Projects")
1206                               (org-agenda-skip-function 'bh/skip-non-projects)
1207                               (org-tags-match-list-sublevels 'indented)
1208                               (org-agenda-sorting-strategy
1209                                '(category-keep))))
1210                   (tags-todo "-CANCELLED/!NEXT"
1211                              ((org-agenda-overriding-header (concat "Project Next Tasks"
1212                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
1213                                                                         ""
1214                                                                       " (including WAITING and SCHEDULED tasks)")))
1215                               (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1216                               (org-tags-match-list-sublevels t)
1217                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1218                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1219                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1220                               (org-agenda-sorting-strategy
1221                                '(todo-state-down effort-up category-keep))))
1222                   (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1223                              ((org-agenda-overriding-header (concat "Project Subtasks"
1224                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
1225                                                                         ""
1226                                                                       " (including WAITING and SCHEDULED tasks)")))
1227                               (org-agenda-skip-function 'bh/skip-non-project-tasks)
1228                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1229                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1230                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1231                               (org-agenda-sorting-strategy
1232                                '(category-keep))))
1233                   (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1234                              ((org-agenda-overriding-header (concat "Standalone Tasks"
1235                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
1236                                                                         ""
1237                                                                       " (including WAITING and SCHEDULED tasks)")))
1238                               (org-agenda-skip-function 'bh/skip-project-tasks)
1239                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1240                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1241                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1242                               (org-agenda-sorting-strategy
1243                                '(category-keep))))
1244                   (tags-todo "-CANCELLED+WAITING|HOLD/!"
1245                              ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1246                               (org-agenda-skip-function 'bh/skip-stuck-projects)
1247                               (org-tags-match-list-sublevels nil)
1248                               (org-agenda-todo-ignore-scheduled t)
1249                               (org-agenda-todo-ignore-deadlines t)))
1250                   (tags "-REFILE/"
1251                         ((org-agenda-overriding-header "Tasks to Archive")
1252                          (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1253                          (org-tags-match-list-sublevels nil))))
1254                  nil))))
1255
1256   ; org mode agenda files
1257   (setq org-agenda-files
1258         (quote ("~/projects/org-notes/debbugs.org"
1259             "~/projects/org-notes/notes.org"
1260             "~/projects/org-notes/holidays.org"
1261             "~/projects/org-notes/refile.org"
1262             "~/projects/org-notes/diary.org"
1263             "~/projects/org-notes/ool.org"
1264             "~/projects/org-notes/sndservers.org"
1265             "~/projects/org-notes/chaim.org"
1266             "~/projects/org-notes/wildman.org"
1267             "~/projects/org-notes/uddin.org"
1268             "~/projects/org-notes/reviews.org"
1269             "~/org-mode/from-mobile.org"
1270             "~/projects/org-notes/fh.org")))
1271
1272   (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1273   (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
1274   (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1275   (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1276   (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1277   (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1278   (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1279   (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1280   (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1281   ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1282   (defun org-agenda-timeline-all (&optional arg)
1283     (interactive "P")
1284     (with-temp-buffer
1285       (dolist (org-agenda-file org-agenda-files)
1286         (insert-file-contents org-agenda-file nil)
1287         (goto-char (point-max))
1288         (newline))
1289       (write-file "/tmp/timeline.org")
1290       (org-agenda arg "L")))
1291   (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1292
1293 #+END_SRC
1294 ** General config
1295 #+BEGIN_SRC emacs-lisp
1296   (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")))
1297   (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1298
1299   (setq org-default-notes-file "~/projects/org-notes/notes.org")
1300   (setq org-id-link-to-org-use-id 'use-existing)
1301 #+END_SRC
1302 ** Capture Templates
1303 #+BEGIN_SRC emacs-lisp
1304   (setq org-capture-templates  ;; mail-specific note template, identified by "m"
1305         '(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
1306            "* %?\n\n  Source: %u, [[%:link][%:description]]\n  %:initial")
1307           ("t" "todo" entry (file "~/projects/org-notes/refile.org")
1308            "* TODO %?\n  :PROPERTIES:\n  :END:\n  :LOGBOOK:\n  :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1309           ("r" "respond" entry (file "~/projects/org-notes/refile.org")
1310            "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1311           ("n" "note" entry (file "~/projects/org-notes/refile.org")
1312            "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1313           ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
1314            "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1315           ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1316            "* %?\n%U\n" :clock-in t :clock-resume t)
1317           ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
1318            "* TODO Review %c\n%U\n" :immediate-finish t)
1319           ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
1320            "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1321           ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
1322            "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1323           ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1324            "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1325           ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
1326            "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1327           ("J" "job" entry (file "~/projects/org-notes/refile.org")
1328            "* 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)
1329           ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
1330            "* 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")
1331           )
1332         )
1333
1334   ;; Remove empty LOGBOOK drawers on clock out
1335   (defun bh/remove-empty-drawer-on-clock-out ()
1336     (interactive)
1337     (save-excursion
1338       (beginning-of-line 0)
1339       (org-remove-empty-drawer-at (point))))
1340
1341   (defun my/org-add-id ()
1342     (interactive)
1343     (save-excursion
1344       (if (org-current-level)
1345           ()
1346         (forward-char 1)
1347         )
1348       (org-id-get-create)
1349       )
1350   )
1351
1352 #+END_SRC
1353 ** Org mode key bindings
1354 #+BEGIN_SRC emacs-lisp
1355   ;; org mode configuration from http://doc.norang.ca/org-mode.html
1356   ;; Custom Key Bindings
1357   :bind* (("<f9> a" . org-agenda)
1358           ("<f9> I" . bh/punch-in)
1359           ("<f9> O" . bh/punch-out)
1360           ("<f9> SPC" . bh/clock-in-last-task)
1361           ("<f12>" . org-agenda)
1362           ;; ("<f5>" . bh/org-todo)
1363           ("<S-f5>" . bh/widen)
1364           ("<f7>" . bh/set-truncate-lines)
1365           ("<f8>" . org-cycle-agenda-files)
1366           ("<f9> <f9>" . bh/show-org-agenda)
1367           ("<f9> b" . bbdb)
1368           ("<f9> c" . calendar)
1369           ("<f9> f" . boxquote-insert-file)
1370           ("<f9> h" . bh/hide-other)
1371           ("<f9> n" . bh/toggle-next-task-display)
1372           ("<f9> w" . widen)
1373
1374           ("<f9> o" . bh/make-org-scratch)
1375
1376           ("<f9> r" . boxquote-region)
1377           ("<f9> s" . bh/switch-to-scratch)
1378
1379           ("<f9> t" . bh/insert-inactive-timestamp)
1380           ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1381
1382           ("<f9> v" . visible-mode)
1383           ("<f9> l" . org-toggle-link-display)
1384           ("<f9> SPC" . bh/clock-in-last-task)
1385           ("C-<f9>" . previous-buffer)
1386           ("M-<f9>" . org-toggle-inline-images)
1387           ("C-x n r" . narrow-to-region)
1388           ("C-<f10>" . next-buffer)
1389           ("<f11>" . org-clock-goto)
1390           ("C-<f11>" . org-clock-in)
1391           ("C-s-<f12>" . bh/save-then-publish)
1392           ("C-c c" . org-capture))
1393   :config
1394 #+END_SRC
1395 ** Utility Functions
1396 #+BEGIN_SRC emacs-lisp
1397   (defun bh/hide-other ()
1398     (interactive)
1399     (save-excursion
1400       (org-back-to-heading 'invisible-ok)
1401       (hide-other)
1402       (org-cycle)
1403       (org-cycle)
1404       (org-cycle)))
1405
1406   (defun bh/set-truncate-lines ()
1407     "Toggle value of truncate-lines and refresh window display."
1408     (interactive)
1409     (setq truncate-lines (not truncate-lines))
1410     ;; now refresh window display (an idiom from simple.el):
1411     (save-excursion
1412       (set-window-start (selected-window)
1413                         (window-start (selected-window)))))
1414
1415   (defun bh/make-org-scratch ()
1416     (interactive)
1417     (find-file "/tmp/publish/scratch.org")
1418     (gnus-make-directory "/tmp/publish"))
1419
1420   (defun bh/switch-to-scratch ()
1421     (interactive)
1422     (switch-to-buffer "*scratch*"))
1423
1424   (setq org-use-fast-todo-selection t)
1425   (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1426
1427   ; create function to create headlines in file. This comes from
1428   ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1429   (defun my/org-add-ids-to-headlines-in-file ()
1430     "Add ID properties to all headlines in the current file which
1431   do not already have one."
1432     (interactive)
1433     (org-map-entries 'org-id-get-create))
1434   (defun dla/org-update-ids-to-headlines-in-file ()
1435     "Add or replace ID properties to all headlines in the current file 
1436   (or narrowed region)."
1437     (interactive)
1438     (org-map-entries '(lambda () (org-id-get-create t))))
1439   ; if we wanted to do this to every buffer, do the following:
1440   ; (add-hook 'org-mode-hook
1441   ;           (lambda ()
1442   ;             (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1443 #+END_SRC
1444 ** Keywords (TODO)
1445 #+BEGIN_SRC emacs-lisp
1446   (setq org-todo-keywords
1447         (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1448                 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1449
1450   (setq org-todo-keyword-faces
1451         (quote (("TODO" :foreground "red" :weight bold)
1452                 ("NEXT" :foreground "blue" :weight bold)
1453                 ("DONE" :foreground "forest green" :weight bold)
1454                 ("WAITING" :foreground "orange" :weight bold)
1455                 ("HOLD" :foreground "magenta" :weight bold)
1456                 ("CANCELLED" :foreground "forest green" :weight bold)
1457                 ("MEETING" :foreground "forest green" :weight bold)
1458                 ("PHONE" :foreground "forest green" :weight bold))))
1459
1460   (setq org-todo-state-tags-triggers
1461         (quote (("CANCELLED" ("CANCELLED" . t))
1462                 ("WAITING" ("WAITING" . t))
1463                 ("HOLD" ("WAITING") ("HOLD" . t))
1464                 (done ("WAITING") ("HOLD"))
1465                 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1466                 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1467                 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1468
1469
1470
1471   ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1472   ; add ids on creation of nodes
1473   (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1474
1475
1476   ; resolve clocks after 10 minutes of idle; use xprintidle
1477   ; (setq org-clock-idle-time 10)
1478   ; (setq org-clock-x11idle-program-name "xprintidle")
1479
1480   ; this is from http://doc.norang.ca/org-mode.html#Capture
1481   ; use C-M-r for org mode capture
1482   (global-set-key (kbd "C-M-r") 'org-capture)
1483
1484   ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1485   (setq org-refile-targets (quote ((nil :maxlevel . 9)
1486                                    (org-agenda-files :maxlevel . 9))))
1487
1488   ; Use full outline paths for refile targets - we file directly with IDO
1489   (setq org-refile-use-outline-path t)
1490
1491   ; Targets complete directly with IDO
1492   (setq org-outline-path-complete-in-steps nil)
1493
1494   ; Allow refile to create parent tasks with confirmation
1495   (setq org-refile-allow-creating-parent-nodes (quote confirm))
1496
1497   ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1498   ; (setq org-completion-use-ido t)
1499   ; (setq ido-everywhere t)
1500   ; (setq ido-max-directory-size 100000)
1501   ; (ido-mode (quote both))
1502   ; ; Use the current window when visiting files and buffers with ido
1503   ; (setq ido-default-file-method 'selected-window)
1504   ; (setq ido-default-buffer-method 'selected-window)
1505   ; ; Use the current window for indirect buffer display
1506   ; (setq org-indirect-buffer-display 'current-window)
1507
1508
1509   ;;;; Refile settings
1510   ; Exclude DONE state tasks from refile targets
1511   (defun bh/verify-refile-target ()
1512     "Exclude todo keywords with a done state from refile targets"
1513     (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1514
1515   (setq org-refile-target-verify-function 'bh/verify-refile-target)
1516
1517   ;; ensure that emacsclient will show just the note to be edited when invoked
1518   ;; from Mutt, and that it will shut down emacsclient once finished;
1519   ;; fallback to legacy behavior when not invoked via org-protocol.
1520   (require 'org-protocol)
1521   ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1522   (setq my-org-protocol-flag nil)
1523   (defadvice org-capture-finalize (after delete-frame-at-end activate)
1524     "Delete frame at remember finalization"
1525     (progn (if my-org-protocol-flag (delete-frame))
1526            (setq my-org-protocol-flag nil)))
1527   (defadvice org-capture-refile (around delete-frame-after-refile activate)
1528     "Delete frame at remember refile"
1529     (if my-org-protocol-flag
1530         (progn
1531           (setq my-org-protocol-flag nil)
1532           ad-do-it
1533           (delete-frame))
1534       ad-do-it)
1535     )
1536   (defadvice org-capture-kill (after delete-frame-at-end activate)
1537     "Delete frame at remember abort"
1538     (progn (if my-org-protocol-flag (delete-frame))
1539            (setq my-org-protocol-flag nil)))
1540   (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1541     (setq my-org-protocol-flag t))
1542
1543   (defadvice org-insert-todo-heading (after dla/create-id activate)
1544     (org-id-get-create)
1545     )
1546
1547   ;; org modules
1548   (add-to-list 'org-modules 'org-habit)
1549
1550   ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1551   (defun open-mail-in-mutt (message)
1552     "Open a mail message in Mutt, using an external terminal.
1553
1554   Message can be specified either by a path pointing inside a
1555   Maildir, or by Message-ID."
1556     (interactive "MPath or Message-ID: ")
1557     (shell-command
1558      (format "faf xterm -e \"%s %s\""
1559          (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1560
1561   ;; add support for "mutt:ID" links
1562   (org-add-link-type "mutt" 'open-mail-in-mutt)
1563
1564   (defun my-org-mode-setup ()
1565     ; (load-library "reftex")
1566     (and (buffer-file-name)
1567          (file-exists-p (buffer-file-name))
1568          (progn
1569            ; (reftex-parse-all)
1570            (reftex-set-cite-format
1571             '((?b . "[[bib:%l][%l-bib]]")
1572               (?n . "[[notes:%l][%l-notes]]")
1573               (?c . "\\cite{%l}")
1574               (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1575            ))
1576     (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1577     (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1578     (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1579     (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1580     )
1581   (add-hook 'org-mode-hook 'my-org-mode-setup)
1582
1583   (defun org-mode-reftex-search ()
1584     (interactive)
1585     (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1586
1587   (defun open-research-paper (bibtexkey)
1588     "Open a paper by bibtex key"
1589     (interactive "bibtex key: ")
1590     (shell-command
1591      (format "%s %s"
1592          (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1593   (org-add-link-type "papers" 'open-research-paper)
1594   (defun open-research-paper-pdf (bibtexkey)
1595     "Open a paper pdf by bibtex key"
1596     (interactive "bibtex key: ")
1597     (shell-command
1598      (format "%s -p evince_annot %s"
1599          (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1600   (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1601
1602   (add-to-list 'org-link-abbrev-alist
1603                '("notes" .
1604                  "~/projects/research/paper_notes.org::#%s"))
1605
1606   ; I pretty much always want hiearchical checkboxes
1607   (setq org-hierachical-checkbox-statistics nil)
1608
1609   ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1610   (add-to-list 'org-structure-template-alist
1611                '("E" "\\begin{equation}\n?\n\\end{equation}"))
1612
1613    ;; stolen from
1614   ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1615   (defun my-rtcite-export-handler (path desc format)
1616     (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1617     (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1618                      (match-string 1 path)))
1619            (path (substring path 0 (match-beginning 0))))
1620       (cond ((eq format 'latex)
1621              (if (or (not desc) 
1622                      (equal 0 (search "rtcite:" desc)))
1623                  (format "\\cite{%s}" search)
1624                (format "\\cite[%s]{%s}" desc search))))))
1625
1626   (org-add-link-type "rtcite" 
1627                      'org-bibtex-open
1628                      'my-rtcite-export-handler)
1629
1630
1631 #+END_SRC
1632 ** Org Mobile Configuration
1633 #+BEGIN_SRC emacs-lisp
1634   (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1635   (when (string= system-name "linnode")
1636     (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1637   (setq-default org-directory "/home/don/org-mode/")
1638   (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1639
1640 #+END_SRC
1641 ** Org iCal Support
1642 #+BEGIN_SRC emacs-lisp
1643   ;; org mode ical export
1644   (setq org-icalendar-timezone "America/Los_Angeles")
1645   (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1646   ;; we already add the id manually
1647   (setq org-icalendar-store-UID t)
1648
1649 #+END_SRC
1650 ** General Org Babel Configuration
1651 #+BEGIN_SRC emacs-lisp
1652   ;; org babel support
1653   (org-babel-do-load-languages
1654    'org-babel-load-languages
1655    '((emacs-lisp . t )
1656      (R . t)
1657      (latex . t)
1658      (ditaa . t)
1659      (dot . t)
1660      ))
1661   ;; use graphviz-dot for dot things
1662   (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1663   ;; org-babel-by-backend
1664   (defmacro org-babel-by-backend (&rest body)
1665      `(case (if (boundp 'backend) 
1666                 (org-export-backend-name backend)
1667               nil) ,@body))
1668
1669   (defun my/fix-inline-images ()
1670     (when org-inline-image-overlays
1671       (org-redisplay-inline-images)))
1672
1673   (add-hook 'org-babel-after-execute-hook
1674              'my/fix-inline-images)
1675
1676 #+END_SRC
1677 ** LaTeX configuration
1678    :PROPERTIES:
1679    :ID:       7135ba17-6a50-4eed-84ca-b90afa5b12f8
1680    :END:
1681 #+BEGIN_SRC emacs-lisp
1682   (require 'ox-latex)
1683   (add-to-list 'org-latex-classes
1684            '("memarticle"
1685          "\\documentclass[11pt,oneside,article]{memoir}\n"
1686          ("\\section{%s}" . "\\section*{%s}")
1687          ("\\subsection{%s}" . "\\subsection*{%s}")
1688          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1689          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1690          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1691
1692   (setq org-beamer-outline-frame-options "")
1693   (add-to-list 'org-latex-classes
1694            '("beamer"
1695          "\\documentclass[ignorenonframetext]{beamer}
1696   [NO-DEFAULT-PACKAGES]
1697   [PACKAGES]
1698   [EXTRA]"
1699          ("\\section{%s}" . "\\section*{%s}")
1700          ("\\subsection{%s}" . "\\subsection*{%s}")
1701          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1702          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1703          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1704
1705   (add-to-list 'org-latex-classes
1706            '("membook"
1707          "\\documentclass[11pt,oneside]{memoir}\n"
1708          ("\\chapter{%s}" . "\\chapter*{%s}")
1709          ("\\section{%s}" . "\\section*{%s}")
1710          ("\\subsection{%s}" . "\\subsection*{%s}")
1711          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1712
1713   (add-to-list 'org-latex-classes
1714            '("letter"
1715          "\\documentclass[11pt]{letter}
1716   [NO-DEFAULT-PACKAGES]
1717   [PACKAGES]
1718   [EXTRA]"
1719      ("\\section{%s}" . "\\section*{%s}")
1720          ("\\subsection{%s}" . "\\subsection*{%s}")
1721          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1722          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1723          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1724
1725   (add-to-list 'org-latex-classes
1726            '("dlacv"
1727          "\\documentclass{dlacv}
1728   [NO-DEFAULT-PACKAGES]
1729   [NO-PACKAGES]
1730   [NO-EXTRA]"
1731          ("\\section{%s}" . "\\section*{%s}")
1732          ("\\subsection{%s}" . "\\subsection*{%s}")
1733          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1734          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1735          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1736
1737
1738   (add-to-list 'org-latex-classes
1739            '("dlaresume"
1740          "\\documentclass{dlaresume}
1741   [NO-DEFAULT-PACKAGES]
1742   [NO-PACKAGES]
1743   [NO-EXTRA]"
1744          ("\\section{%s}" . "\\section*{%s}")
1745          ("\\subsection{%s}" . "\\subsection*{%s}")
1746          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1747          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1748          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1749
1750
1751   ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
1752   ;; but adapted to use latexmk 4.22 or higher.  
1753   (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
1754
1755   ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
1756   (setq org-latex-default-packages-alist
1757     '(("" "amsmath" t)
1758       ("" "unicode-math" t)
1759       ))
1760   (setq org-latex-packages-alist
1761     '(("" "graphicx" t)
1762       ("" "fontspec" t)
1763       ("" "xunicode" t)
1764       ("" "hyperref" t)
1765       ("" "url" t)
1766       ("" "rotating" t)
1767       ("" "longtable" nil)
1768       ("" "float" )))
1769
1770   ;; make equations larger
1771   (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
1772
1773   (defun org-create-formula--latex-header ()
1774     "Return LaTeX header appropriate for previewing a LaTeX snippet."
1775     (let ((info (org-combine-plists (org-export--get-global-options
1776              (org-export-get-backend 'latex))
1777             (org-export--get-inbuffer-options
1778              (org-export-get-backend 'latex)))))
1779       (org-latex-guess-babel-language
1780        (org-latex-guess-inputenc
1781     (org-splice-latex-header
1782      org-format-latex-header
1783      org-latex-default-packages-alist
1784      nil t
1785      (plist-get info :latex-header)))
1786        info)))
1787
1788
1789   ; support ignoring headers in org mode export to latex
1790   ; from http://article.gmane.org/gmane.emacs.orgmode/67692
1791   (defadvice org-latex-headline (around my-latex-skip-headlines
1792                     (headline contents info) activate)
1793     (if (member "ignoreheading" (org-element-property :tags headline))
1794     (setq ad-return-value contents)
1795       ad-do-it))
1796
1797   ;; keep latex logfiles
1798
1799   (setq org-latex-remove-logfiles nil)
1800
1801   ;; Resume clocking task when emacs is restarted
1802   (org-clock-persistence-insinuate)
1803   ;;
1804   ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
1805   (setq org-clock-history-length 23)
1806   ;; Resume clocking task on clock-in if the clock is open
1807   (setq org-clock-in-resume t)
1808   ;; Change tasks to NEXT when clocking in; this avoids clocking in when
1809   ;; there are things like PHONE calls
1810   (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
1811   ;; Separate drawers for clocking and logs
1812   (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
1813   ;; Save clock data and state changes and notes in the LOGBOOK drawer
1814   (setq org-clock-into-drawer t)
1815   (setq org-log-into-drawer t)
1816   ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
1817   (setq org-clock-out-remove-zero-time-clocks t)
1818   ;; Clock out when moving task to a done state
1819   (setq org-clock-out-when-done t)
1820   ;; Save the running clock and all clock history when exiting Emacs, load it on startup
1821   (setq org-clock-persist t)
1822   ;; Do not prompt to resume an active clock
1823   (setq org-clock-persist-query-resume nil)
1824   ;; Enable auto clock resolution for finding open clocks
1825   (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
1826   ;; Include current clocking task in clock reports
1827   (setq org-clock-report-include-clocking-task t)
1828
1829   ;; the cache seems to be broken
1830   (setq org-element-use-cache nil)
1831
1832   (defvar bh/keep-clock-running nil)
1833
1834   (defun bh/is-task-p ()
1835     "Any task with a todo keyword and no subtask"
1836     (save-restriction
1837       (widen)
1838       (let ((has-subtask)
1839             (subtree-end (save-excursion (org-end-of-subtree t)))
1840             (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1841         (save-excursion
1842           (forward-line 1)
1843           (while (and (not has-subtask)
1844                       (< (point) subtree-end)
1845                       (re-search-forward "^\*+ " subtree-end t))
1846             (when (member (org-get-todo-state) org-todo-keywords-1)
1847               (setq has-subtask t))))
1848         (and is-a-task (not has-subtask)))))
1849   (defun bh/is-project-p ()
1850     "Any task with a todo keyword subtask"
1851     (save-restriction
1852       (widen)
1853       (let ((has-subtask)
1854             (subtree-end (save-excursion (org-end-of-subtree t)))
1855             (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1856         (save-excursion
1857           (forward-line 1)
1858           (while (and (not has-subtask)
1859                       (< (point) subtree-end)
1860                       (re-search-forward "^\*+ " subtree-end t))
1861             (when (member (org-get-todo-state) org-todo-keywords-1)
1862               (setq has-subtask t))))
1863         (and is-a-task has-subtask))))
1864
1865   (defun bh/is-subproject-p ()
1866     "Any task which is a subtask of another project"
1867     (let ((is-subproject)
1868           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1869       (save-excursion
1870         (while (and (not is-subproject) (org-up-heading-safe))
1871           (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1872             (setq is-subproject t))))
1873       (and is-a-task is-subproject)))
1874
1875
1876   (defun bh/clock-in-to-next (kw)
1877     "Switch a task from TODO to NEXT when clocking in.
1878   Skips capture tasks, projects, and subprojects.
1879   Switch projects and subprojects from NEXT back to TODO"
1880     (when (not (and (boundp 'org-capture-mode) org-capture-mode))
1881       (cond
1882        ((and (member (org-get-todo-state) (list "TODO"))
1883          (bh/is-task-p))
1884     "NEXT")
1885        ((and (member (org-get-todo-state) (list "NEXT"))
1886          (bh/is-project-p))
1887     "TODO"))))
1888
1889   (defun bh/punch-in (arg)
1890     "Start continuous clocking and set the default task to the
1891   selected task.  If no task is selected set the Organization task
1892   as the default task."
1893     (interactive "p")
1894     (setq bh/keep-clock-running t)
1895     (if (equal major-mode 'org-agenda-mode)
1896     ;;
1897     ;; We're in the agenda
1898     ;;
1899     (let* ((marker (org-get-at-bol 'org-hd-marker))
1900            (tags (org-with-point-at marker (org-get-tags-at))))
1901       (if (and (eq arg 4) tags)
1902           (org-agenda-clock-in '(16))
1903         (bh/clock-in-organization-task-as-default)))
1904       ;;
1905       ;; We are not in the agenda
1906       ;;
1907       (save-restriction
1908     (widen)
1909     ; Find the tags on the current task
1910     (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
1911         (org-clock-in '(16))
1912       (bh/clock-in-organization-task-as-default)))))
1913
1914   (defun bh/punch-out ()
1915     (interactive)
1916     (setq bh/keep-clock-running nil)
1917     (when (org-clock-is-active)
1918       (org-clock-out))
1919     (org-agenda-remove-restriction-lock))
1920
1921   (defun bh/clock-in-default-task ()
1922     (save-excursion
1923       (org-with-point-at org-clock-default-task
1924     (org-clock-in))))
1925
1926   (defun bh/clock-in-parent-task ()
1927     "Move point to the parent (project) task if any and clock in"
1928     (let ((parent-task))
1929       (save-excursion
1930     (save-restriction
1931       (widen)
1932       (while (and (not parent-task) (org-up-heading-safe))
1933         (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1934           (setq parent-task (point))))
1935       (if parent-task
1936           (org-with-point-at parent-task
1937         (org-clock-in))
1938         (when bh/keep-clock-running
1939           (bh/clock-in-default-task)))))))
1940
1941   (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
1942
1943   (defun bh/clock-in-organization-task-as-default ()
1944     (interactive)
1945     (org-with-point-at (org-id-find bh/organization-task-id 'marker)
1946       (org-clock-in '(16))))
1947
1948   (defun bh/clock-out-maybe ()
1949     (when (and bh/keep-clock-running
1950            (not org-clock-clocking-in)
1951            (marker-buffer org-clock-default-task)
1952            (not org-clock-resolving-clocks-due-to-idleness))
1953       (bh/clock-in-parent-task)))
1954
1955   ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
1956
1957   (require 'org-id)
1958   (defun bh/clock-in-task-by-id (id)
1959     "Clock in a task by id"
1960     (org-with-point-at (org-id-find id 'marker)
1961       (org-clock-in nil)))
1962
1963   (defun bh/clock-in-last-task (arg)
1964     "Clock in the interrupted task if there is one
1965   Skip the default task and get the next one.
1966   A prefix arg forces clock in of the default task."
1967     (interactive "p")
1968     (let ((clock-in-to-task
1969        (cond
1970         ((eq arg 4) org-clock-default-task)
1971         ((and (org-clock-is-active)
1972           (equal org-clock-default-task (cadr org-clock-history)))
1973          (caddr org-clock-history))
1974         ((org-clock-is-active) (cadr org-clock-history))
1975         ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
1976         (t (car org-clock-history)))))
1977       (widen)
1978       (org-with-point-at clock-in-to-task
1979     (org-clock-in nil))))
1980
1981
1982   (defun org-export-to-ods ()
1983     (interactive)
1984     (let ((csv-file "data.csv"))
1985       (org-table-export csv-file "orgtbl-to-csv")
1986       (org-odt-convert csv-file "ods" 'open)))
1987
1988   ; allow for zero-width-space to be a break in regexp too
1989   ; (setcar org-emphasis-regexp-components "​ [:space:] \t('\"{")
1990   ; (setcar (nthcdr 1 org-emphasis-regexp-components) "​ [:space:]- \t.,:!?;'\")}\\")
1991   ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
1992
1993   ;; support inserting screen shots
1994   (defun my/org-insert-screenshot ()
1995     "Take a screenshot into a time stamped unique-named file in the
1996   same directory as the org-buffer and insert a link to this file."
1997     (interactive)
1998     (defvar my/org-insert-screenshot/filename)
1999     (setq my/org-insert-screenshot/filename
2000       (read-file-name
2001        "Screenshot to insert: "
2002        nil
2003        (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2004        )
2005       )
2006     (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2007     (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2008     (org-display-inline-images))
2009
2010   (defun my/fix-inline-images ()
2011     (when org-inline-image-overlays
2012       (org-redisplay-inline-images)))
2013
2014   (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2015
2016   ;; use xelatex to preview with imagemagick
2017   (add-to-list 'org-preview-latex-process-alist
2018            '(xelateximagemagick
2019         :programs ("xelatex" "convert")
2020         :description "pdf > png"
2021         :message "you need to install xelatex and imagemagick"
2022         :use-xcolor t
2023         :image-input-type "pdf"
2024         :image-output-type "png"
2025         :image-size-adjust (1.0 . 1.0)
2026         :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2027         :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2028            )
2029   ;; use xelatex by default
2030   (setq org-preview-latex-default-process 'xelateximagemagick)
2031
2032   ; from http://orgmode.org/Changes.html
2033   (defun my/org-repair-property-drawers ()
2034     "Fix properties drawers in current buffer.
2035    Ignore non Org buffers."
2036     (interactive)
2037     (when (eq major-mode 'org-mode)
2038       (org-with-wide-buffer
2039        (goto-char (point-min))
2040        (let ((case-fold-search t)
2041          (inline-re (and (featurep 'org-inlinetask)
2042                  (concat (org-inlinetask-outline-regexp)
2043                      "END[ \t]*$"))))
2044      (org-map-entries
2045       (lambda ()
2046         (unless (and inline-re (org-looking-at-p inline-re))
2047           (save-excursion
2048         (let ((end (save-excursion (outline-next-heading) (point))))
2049           (forward-line)
2050           (when (org-looking-at-p org-planning-line-re) (forward-line))
2051           (when (and (< (point) end)
2052                  (not (org-looking-at-p org-property-drawer-re))
2053                  (save-excursion
2054                    (and (re-search-forward org-property-drawer-re end t)
2055                     (eq (org-element-type
2056                      (save-match-data (org-element-at-point)))
2057                     'drawer))))
2058             (insert (delete-and-extract-region
2059                  (match-beginning 0)
2060                  (min (1+ (match-end 0)) end)))
2061             (unless (bolp) (insert "\n"))))))))))))
2062
2063 #+END_SRC
2064 ** Org-Gcal
2065 #+BEGIN_SRC emacs-lisp
2066   (use-package calfw
2067     :ensure f
2068     )
2069   (use-package calfw-org
2070     :ensure f
2071     )
2072   (use-package org-gcal
2073     :ensure f
2074     :config '((if (file-readable-p "~/.hide/org_gcal.el")
2075                   (load-file "~/.hide/org_gcal.el"))
2076               )
2077     )
2078 #+END_SRC
2079 ** appt integration
2080 #+BEGIN_SRC emacs-lisp
2081   (use-package appt
2082     :ensure f
2083     :config
2084     ;; Show notification 10 minutes before event
2085     (setq appt-message-warning-time 10)
2086     ;; Disable multiple reminders
2087     (setq appt-display-interval appt-message-warning-time)
2088     (setq appt-display-mode-line nil)
2089
2090     ;; add automatic reminders for appointments
2091     (defun my/org-agenda-to-appt ()
2092       (interactive)
2093       (setq appt-time-msg-list nil)
2094       (org-agenda-to-appt))
2095     ;; add reminders when starting emacs
2096     (my/org-agenda-to-appt)
2097     ;; when rebuilding the agenda
2098     (defadvice  org-agenda-redo (after org-agenda-redo-add-appts)
2099       "Pressing `r' on the agenda will also add appointments."
2100       (my/org-agenda-to-appt)
2101       )
2102     ;; when saving all org buffers
2103     (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2104       "Re-add appts after saving all org buffers"
2105       (my/org-agenda-to-appt))
2106     ;; Display appointments as a window manager notification
2107     (setq appt-disp-window-function 'my/appt-display)
2108     (setq appt-delete-window-function (lambda () t))
2109
2110     (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2111
2112     (defun my/appt-display (min-to-app new-time msg)
2113       (if (atom min-to-app)
2114       (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2115     (dolist (i (number-sequence 0 (1- (length min-to-app))))
2116       (start-process "my/appt-notification-app" nil my/appt-notification-app
2117                      (nth i min-to-app) (nth i msg))))
2118       )
2119     )
2120
2121
2122 #+END_SRC
2123 ** End use-package
2124 #+BEGIN_SRC emacs-lisp
2125   )
2126 #+END_SRC
2127 * Keybindings
2128 ** Goto line
2129 #+BEGIN_SRC emacs-lisp
2130   (global-unset-key "\M-g")
2131   (global-set-key (kbd "M-g l") 'goto-line)
2132 #+END_SRC
2133 * Debian
2134 ** debian-changelog
2135 #+BEGIN_SRC emacs-lisp
2136   (use-package debian-changelog
2137     :ensure f
2138     :mode "debian/changelog"
2139     :config
2140     (setq debian-changelog-mailing-address "don@debian.org")
2141     (setq debian-changelog-full-name "Don Armstrong"))
2142 #+END_SRC
2143 * Misc (uncharacterized)
2144 #+BEGIN_SRC emacs-lisp
2145   (setq calendar-latitude 38.6)
2146   (setq calendar-longitude -121.5)
2147   (setq case-fold-search t)
2148   (setq confirm-kill-emacs (quote y-or-n-p))
2149   (setq cperl-lazy-help-time nil)
2150   (display-time)
2151   (setq display-time-24hr-format t)
2152   (setq display-time-day-and-date t)
2153   (display-time-mode 1)
2154   (global-font-lock-mode 1)
2155   (icomplete-mode 1)
2156   (setq log-edit-keep-buffer t)
2157   (setq mail-user-agent (quote sendmail-user-agent))
2158   (setq markdown-enable-math t)
2159   (setq markdown-follow-wiki-link-on-enter nil)
2160   (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2161   (setq ps-footer-font-size (quote (8 . 10)))
2162   (setq ps-header-font-size (quote (8 . 10)))
2163   (setq ps-header-title-font-size (quote (10 . 10)))
2164   (setq ps-line-number-color "blue")
2165   (setq ps-print-footer t)
2166   (setq ps-print-footer-frame nil)
2167   (setq ps-print-only-one-header t)
2168   (setq sentence-end "[.?!][]\"')]*\\($\\|   \\| \\)[    
2169   ]*")
2170   (setq sentence-end-double-space nil)
2171   ; enable matching parenthesis
2172   (show-paren-mode 1)
2173   (tool-bar-mode -1)
2174   (setq user-mail-address "don@donarmstrong.com")
2175   (setq vc-delete-logbuf-window nil)
2176   (setq vc-follow-symlinks t)
2177
2178   ;; use git before SVN; use CVS earlier, because I have CVS
2179   ;; repositories inside of git directories
2180   (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
2181
2182   ;; switch back to the old primary selection method
2183   (setq x-select-enable-clipboard nil)
2184   (setq x-select-enable-primary t)
2185   ; (setq mouse-drag-copy-region t)
2186
2187   (fset 'perl-mode 'cperl-mode)
2188   ;;(load-file "cperl-mode.el")
2189
2190   ;; tramp configuration
2191   (setq tramp-use-ssh-controlmaster-options nil)
2192
2193   (setq-default c-indent-level 4)
2194   (setq-default c-brace-imaginary-offset 0)
2195   (setq-default c-brace-offset -4)
2196   (setq-default c-argdecl-indent 4)
2197   (setq-default c-label-offset -4)
2198   (setq-default c-continued-statement-offset 4)
2199   ; tabs are annoying
2200   (setq-default indent-tabs-mode nil)
2201   (setq-default tab-width 4)
2202
2203
2204   ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2205   ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2206   ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2207   ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2208   ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2209
2210
2211   (defun insert-date ()
2212     "Insert date at point."
2213     (interactive)
2214     (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2215   (global-set-key "\C-[d" 'insert-date)
2216
2217   (defun unfill-paragraph (arg)
2218     "Pull this whole paragraph up onto one line."
2219     (interactive "*p")
2220     (let ((fill-column 10000))
2221       (fill-paragraph arg))
2222     )
2223
2224   (column-number-mode t)
2225  
2226 #+END_SRC
2227 ** Desktop-save-mode
2228 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2229 emacs, and use a different desktop file to restore history
2230 #+BEGIN_SRC emacs-lisp
2231   (use-package emacs
2232     :demand
2233     :config
2234     (setq desktop-base-file-name
2235           (convert-standard-filename
2236            (concat ".emacs"
2237                    (or (getenv "EMACS_SERVER_NAME")
2238                        "")
2239                    ".desktop")
2240            ))
2241     (setq desktop-base-lock-name
2242           (convert-standard-filename
2243            (concat desktop-base-file-name
2244                    ".lock")))
2245     (setq desktop-auto-save-timeout 60)
2246     (setq desktop-restore-eager 5)
2247     (setq desktop-lazy-verbose nil)
2248     (desktop-save-mode 1)
2249     ; (desktop-read)
2250   )
2251 #+END_SRC
2252 ** Misc (Uncharacterized)
2253 #+BEGIN_SRC emacs-lisp
2254   '(icomplete-mode on)
2255   (custom-set-faces
2256    ;; custom-set-faces was added by Custom.
2257    ;; If you edit it by hand, you could mess it up, so be careful.
2258    ;; Your init file should contain only one such instance.
2259    ;; If there is more than one, they won't work right.
2260    '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2261
2262
2263   (put 'upcase-region 'disabled nil)
2264   (put 'downcase-region 'disabled nil)
2265   (put 'narrow-to-region 'disabled nil)
2266
2267   ; (defun turn-on-flyspell ()
2268   ;    "Force flyspell-mode on using a positive arg.  For use in hooks."
2269   ;    (interactive)
2270   ;    (flyspell-mode 1))
2271
2272
2273    ; Outline-minor-mode key map
2274    (define-prefix-command 'cm-map nil "Outline-")
2275    ; HIDE
2276    (define-key cm-map "q" 'outline-hide-sublevels)    ; Hide everything but the top-level headings
2277    (define-key cm-map "t" 'outline-hide-body)         ; Hide everything but headings (all body lines)
2278    (define-key cm-map "o" 'outline-hide-other)        ; Hide other branches
2279    (define-key cm-map "c" 'outline-hide-entry)        ; Hide this entry's body
2280    (define-key cm-map "l" 'outline-hide-leaves)       ; Hide body lines in this entry and sub-entries
2281    (define-key cm-map "d" 'outline-hide-subtree)      ; Hide everything in this entry and sub-entries
2282    ; SHOW
2283    (define-key cm-map "a" 'outline-show-all)          ; Show (expand) everything
2284    (define-key cm-map "e" 'outline-show-entry)        ; Show this heading's body
2285    (define-key cm-map "i" 'outline-show-children)     ; Show this heading's immediate child sub-headings
2286    (define-key cm-map "k" 'outline-show-branches)     ; Show all sub-headings under this heading
2287    (define-key cm-map "s" 'outline-show-subtree)      ; Show (expand) everything in this heading & below
2288    ; MOVE
2289    (define-key cm-map "u" 'outline-up-heading)                ; Up
2290    (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
2291    (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
2292    (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
2293    (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
2294    (global-set-key "\M-o" cm-map)
2295   ; fix up tmux xterm keys
2296   ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2297   (defun fix-up-tmux-keys ()
2298       "Fix up tmux xterm keys"
2299       (if (getenv "TMUX")
2300           (progn
2301             (let ((x 2) (tkey ""))
2302               (while (<= x 8)
2303                 ;; shift
2304                 (if (= x 2)
2305                     (setq tkey "S-"))
2306                 ;; alt
2307                 (if (= x 3)
2308                     (setq tkey "M-"))
2309                 ;; alt + shift
2310                 (if (= x 4)
2311                     (setq tkey "M-S-"))
2312                 ;; ctrl
2313                 (if (= x 5)
2314                     (setq tkey "C-"))
2315                 ;; ctrl + shift
2316                 (if (= x 6)
2317                     (setq tkey "C-S-"))
2318                 ;; ctrl + alt
2319                 (if (= x 7)
2320                     (setq tkey "C-M-"))
2321                 ;; ctrl + alt + shift
2322                 (if (= x 8)
2323                     (setq tkey "C-M-S-"))
2324
2325                 ;; arrows
2326                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2327                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2328                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2329                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2330                 ;; home
2331                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2332                 ;; end
2333                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2334                 ;; page up
2335                 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2336                 ;; page down
2337                 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2338                 ;; insert
2339                 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2340                 ;; delete
2341                 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2342                 ;; f1
2343                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2344                 ;; f2
2345                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2346                 ;; f3
2347                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2348                 ;; f4
2349                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2350                 ;; f5
2351                 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2352                 ;; f6
2353                 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2354                 ;; f7
2355                 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2356                 ;; f8
2357                 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2358                 ;; f9
2359                 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2360                 ;; f10
2361                 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2362                 ;; f11
2363                 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2364                 ;; f12
2365                 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2366                 ;; f13
2367                 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2368                 ;; f14
2369                 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2370                 ;; f15
2371                 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2372                 ;; f16
2373                 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2374                 ;; f17
2375                 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2376                 ;; f18
2377                 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2378                 ;; f19
2379                 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2380                 ;; f20
2381                 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2382
2383                 (setq x (+ x 1))
2384                 ))
2385             )
2386         )
2387       )
2388   ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2389
2390   (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2391     "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2392     (if (or (buffer-modified-p)
2393             (verify-visited-file-modtime)
2394             (< (* 8 1024 1024) (buffer-size))
2395             (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2396         ad-do-it
2397       (clear-visited-file-modtime)
2398       (not-modified)))
2399   (ad-activate 'ask-user-about-supersession-threat)
2400 #+END_SRC
2401
2402 * Start Server
2403 #+BEGIN_SRC emacs-lisp
2404   (use-package server
2405     :config
2406     (setq server-name
2407           (or (getenv "EMACS_SERVER_NAME")
2408               "server"))
2409     (unless (server-running-p)
2410       (global-set-key "\C-xp" 'server-edit)
2411       (server-start)))
2412 #+END_SRC
2413
2414
2415
2416 * END
2417 #+BEGIN_SRC emacs-lisp
2418   (provide 'don-configuration)
2419 #+END_SRC