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