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