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