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