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