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