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