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