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