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