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