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