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