]> git.donarmstrong.com Git - lib.git/blob - emacs_el/configuration/don-configuration.org
6d96c8991af18dd8b9bc8fb9e603b42bbf9595fd
[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 * Add library paths
11
12 #+BEGIN_SRC emacs-lisp
13   (add-to-list 'load-path '"~/lib/emacs_el/")
14   (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/tiny")
15   (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/other")
16   (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
17 #+END_SRC
18
19 * Package management
20 ** package repositories and package manager
21 #+BEGIN_SRC emacs-lisp
22   (require 'package)
23   (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
24                            ("melpa" . "https://melpa.org/packages/")
25                            ("org" . "http://orgmode.org/elpa/") ))
26 #+END_SRC
27 ** [[https://github.com/jwiegley/use-package/][use-package]]
28 #+BEGIN_SRC emacs-lisp
29   (package-initialize)
30   (require 'use-package)
31 #+END_SRC
32 ** Paradox
33 #+BEGIN_SRC emacs-lisp
34   (use-package paradox
35     :ensure paradox
36   )
37 #+END_SRC
38 * Disable custom-vars
39 #+BEGIN_SRC emacs-lisp
40   ;; Set the custom file to /dev/null and don't bother to load it
41   (setq custom-file "/dev/null")
42 #+END_SRC
43 * Misc functions
44 ** with-library
45 #+BEGIN_SRC emacs-lisp
46 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
47 ;; execute conditional code when loading libraries
48 (defmacro with-library (symbol &rest body)
49   `(when (require ,symbol nil t)
50      ,@body))
51 (put 'with-library 'lisp-indent-function 1)
52 #+END_SRC
53
54 * Variables
55 ** Safe Local Variables
56 #+BEGIN_SRC emacs-lisp
57   (setq safe-local-variable-values 
58         (quote ((auto-save-default)
59                 (make-backup-files)
60                 (cperl-indent-level . 4)
61                 (indent-level . 4)
62                 (indent-tabs-mode . f)
63                 )))
64 #+END_SRC
65 * Memory
66 #+BEGIN_SRC emacs-lisp
67   (setq global-mark-ring-max 128
68         mark-ring-max 128
69         kill-ring-max 128)
70
71   (defun don/minibuffer-setup-hook ()
72     (setq gc-cons-threshold most-positive-fixnum))
73
74   (defun don/minibuffer-exit-hook ()
75     (setq gc-cons-threshold 1048576))
76
77   (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
78   (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
79 #+END_SRC
80 * Modules
81 ** Flyspell 🐝 
82 #+BEGIN_SRC emacs-lisp
83   (use-package flyspell
84     :ensure t
85     :diminish flyspell-mode 🐝
86     :config
87     (add-hook 'message-mode-hook 'turn-on-flyspell)
88     (add-hook 'text-mode-hook 'turn-on-flyspell)
89     (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
90     (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
91     (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
92     :init
93     (setq ispell-program-name "ispell")
94     )
95
96 #+END_SRC
97 ** Winnermode
98 #+BEGIN_SRC emacs-lisp
99   (winner-mode 1)
100 #+END_SRC
101 ** Eyebrowse
102
103 #+BEGIN_SRC emacs-lisp
104   ;; (use-package eyebrowse
105   ;;   :ensure t
106   ;;   :diminish eyebrowse-mode
107   ;;   :init (setq eyebrowse-keymap-prefix (kbd "C-c C-\\"))
108   ;;   :config (progn
109   ;;             (setq eyebrowse-wrap-around t)
110   ;;             (eyebrowse-mode t)
111   ;; 
112   ;;             (defun my/eyebrowse-new-window-config ()
113   ;;               (interactive)
114   ;;               (let ((done nil))
115   ;;                 (dotimes (i 10)
116   ;;                   ;; start at 1 run till 0
117   ;;                   (let ((j (mod (+ i 1) 10)))
118   ;;                     (when (and (not done)
119   ;;                                (not (eyebrowse--window-config-present-p j)))
120   ;;                       (eyebrowse-switch-to-window-config j)
121   ;;                       (call-interactively 'eyebrowse-rename-window-config2 j)
122   ;;                       (setq done t)
123   ;;                       ))
124   ;;                   )))
125   ;; 
126   ;;             ;; I don't use latex-preview-pane
127   ;;             ;; (require 'latex-preview-pane)
128   ;;             ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
129   ;;             ;;   ;; latex-preview-pane uses window-parameters which are
130   ;;             ;;   ;; not preserved by eyebrowse, so we close the preview
131   ;;             ;;   ;; pane before switching, it will be regenerated when we
132   ;;             ;;   ;; edit the TeX file.
133   ;;             ;;   (when (lpp/window-containing-preview)
134   ;;             ;;     (delete-window (lpp/window-containing-preview))))
135   ;; 
136   ;;             ;; (add-to-list 'eyebrowse-pre-window-switch-hook
137   ;;             ;;              #'my/close-latex-preview-pane-before-eyebrowse-switch)
138   ;; 
139   ;;             ;; (my/set-menu-key "["  #'my/eyebrowse-new-window-config)
140   ;;             ;; (my/set-menu-key ";"  #'eyebrowse-prev-window-config)
141   ;;             ;; (my/set-menu-key "'"  #'eyebrowse-next-window-config)
142   ;;             ;; (my/set-menu-key "]"  #'eyebrowse-close-window-config)
143   ;;             ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
144   ;;             )
145   ;;   )
146 #+END_SRC
147
148 ** Window handling
149
150 *** Splitting
151 #+BEGIN_SRC emacs-lisp
152   (defun my/vsplit-last-buffer ()
153     "Split the window vertically and display the previous buffer."
154     (interactive)
155     (split-window-vertically)
156     (other-window 1 nil)
157     (switch-to-next-buffer))
158
159   (defun my/hsplit-last-buffer ()
160     "Split the window horizontally and display the previous buffer."
161     (interactive)
162     (split-window-horizontally)
163     (other-window 1 nil)
164     (switch-to-next-buffer))
165
166   (bind-key "C-x 2" 'my/vsplit-last-buffer)
167   (bind-key "C-x 3" 'my/hsplit-last-buffer)
168
169   (setq split-width-threshold  100)
170   (setq split-height-threshold 60)
171
172   (defun my/split-window-prefer-vertically (window)
173     "If there's only one window (excluding any possibly active
174            minibuffer), then split the current window horizontally."
175     (if (and (one-window-p t)
176              (not (active-minibuffer-window))
177              ( < (frame-width) (frame-height))
178              )
179         (let ((split-width-threshold nil))
180           (split-window-sensibly window))
181       (split-window-sensibly window)))
182
183   (setq split-window-preferred-function #'my/split-window-prefer-vertically)
184   (setq window-combination-resize t)
185 #+END_SRC
186
187 *** Compilation window
188
189 If there is no compilation window, open one at the bottom, spanning
190 the complete width of the frame. Otherwise, reuse existing window. In
191 the former case, if there was no error the window closes
192 automatically.
193
194 #+BEGIN_SRC emacs-lisp
195   (add-to-list 'display-buffer-alist
196                `(,(rx bos "*compilation*" eos)
197                  (display-buffer-reuse-window
198                   display-buffer-in-side-window)
199                  (reusable-frames . visible)
200                  (side            . bottom)
201                  (window-height   . 0.4)))
202 #+END_SRC
203
204 #+BEGIN_SRC emacs-lisp
205   (defun my/compilation-exit-autoclose (status code msg)
206     ;; If M-x compile exists with a 0
207     (when (and (eq status 'exit) (zerop code))
208       ;; and delete the *compilation* window
209       (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
210         (when (and (not (window-at-side-p compilation-window 'top))
211                    (window-at-side-p compilation-window 'left)
212                    (window-at-side-p compilation-window 'right))
213           (delete-window compilation-window))))
214     ;; Always return the anticipated result of compilation-exit-message-function
215     (cons msg code))
216
217   ;; Specify my function (maybe I should have done a lambda function)
218   (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
219 #+END_SRC
220
221 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
222 value, the compilation buffer scrolls automatically to follow the
223 output. If the value is ~first-error~, scrolling stops when the first
224 error appears, leaving point at that error. For any other non-nil
225 value, scrolling continues until there is no more output.
226
227 #+BEGIN_SRC emacs-lisp
228   (setq compilation-scroll-output 'first-error)
229 #+END_SRC
230
231 ** Mode line cleaning
232 *** Diminish
233 #+BEGIN_SRC emacs-lisp
234   (use-package diminish
235     :ensure t)
236 #+END_SRC
237
238 *** Delight 
239 #+BEGIN_SRC emacs-lisp
240   (use-package delight
241     :ensure t)
242 #+END_SRC
243
244 ** Jumping
245 *** Avy
246 #+BEGIN_SRC emacs-lisp
247 (use-package avy
248   :ensure t
249   :bind ("C-c C-SPC" . avy-goto-word-1)
250   :config (progn
251             (setq avy-background t)
252             (key-chord-define-global "jj"  #'avy-goto-word-1)))
253 #+END_SRC
254
255 ** Snippets
256 *** Yasnippet
257 #+BEGIN_SRC emacs-lisp
258   (use-package yasnippet
259     :ensure t
260     :diminish yas-minor-mode
261     :config (progn
262               (yas-global-mode)
263               (setq yas-verbosity 1)
264               (define-key yas-minor-mode-map (kbd "<tab>") nil)
265               (define-key yas-minor-mode-map (kbd "TAB") nil)
266               (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
267               (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
268                                        "~/lib/emacs_el/yasnippet-snippets/snippets/"))
269               (add-to-list 'hippie-expand-try-functions-list
270                                'yas-hippie-try-expand)
271               )
272     )
273 #+END_SRC
274 *** Auto-YASnippet
275 #+BEGIN_SRC emacs-lisp
276   (use-package auto-yasnippet
277     :bind (("H-w" . aya-create)
278            ("H-y" . aya-expand)
279            )
280     )
281 #+END_SRC
282 ** Helm Flx
283
284 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
285
286 #+BEGIN_SRC emacs-lisp
287 (use-package helm-flx
288   :ensure t
289   :config (progn
290             ;; these are helm configs, but they kind of fit here nicely
291             (setq helm-M-x-fuzzy-match                  t
292                   helm-bookmark-show-location           t
293                   helm-buffers-fuzzy-matching           t
294                   helm-completion-in-region-fuzzy-match t
295                   helm-file-cache-fuzzy-match           t
296                   helm-imenu-fuzzy-match                t
297                   helm-mode-fuzzy-match                 t
298                   helm-locate-fuzzy-match               nil
299                   helm-quick-update                     t
300                   helm-recentf-fuzzy-match              nil
301                   helm-semantic-fuzzy-match             t)
302             (helm-flx-mode +1)))
303 #+END_SRC
304
305
306 ** Tinyprocmail
307
308 #+BEGIN_SRC emacs-lisp
309   ;; load tinyprocmail
310   (use-package tinyprocmail
311     :ensure f
312     :config (with-library 'tinyprocmail
313               ;; (setq tinyprocmail--procmail-version "v3.22")
314               (add-hook 'tinyprocmail--load-hook 'tinyprocmail-install))
315   )
316 #+END_SRC
317
318 ** Magit
319 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
320   (use-package magit
321     :ensure t
322     :bind (("C-x g" . magit-status)
323            ("C-x C-g" . magit-status))
324     :config
325     ;; don't verify where we are pushing
326     (setq magit-push-always-verify nil)
327     ;; refine diffs always (hilight words)
328     (setq magit-diff-refine-hunk nil)
329     ;; load magit-annex
330     (setq load-path
331           (append '("~/lib/emacs_el/magit-annex")
332                   load-path))
333     ;; load magit-vcsh
334     (setq load-path
335           (append '("~/lib/emacs_el/magit-vcsh")
336                   load-path))
337     )
338   (use-package magit-annex
339     :ensure t
340   )
341   (use-package magit-vcsh
342     :ensure f ; currently not in melpa, so don't try to install
343   )
344 #+END_SRC
345
346 ** Perl
347 #+BEGIN_SRC emacs-lisp
348   (require 'cperl-mode)
349   ;; Use c-mode for perl .xs files
350   (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
351   (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
352   (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
353   (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
354   (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
355   (setq cperl-hairy t
356         cperl-indent-level 4
357         cperl-auto-newline nil
358         cperl-auto-newline-after-colon nil
359         cperl-continued-statement-offset 4
360         cperl-brace-offset -1
361         cperl-continued-brace-offset 0
362         cperl-label-offset -4
363         cperl-highlight-variables-indiscriminately t
364         cperl-electric-lbrace-space nil
365         cperl-indent-parens-as-block nil
366         cperl-close-paren-offset -1
367         cperl-tab-always-indent t)
368   ;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
369 #+END_SRC
370
371 ** Helm
372 #+BEGIN_SRC emacs-lisp
373   (use-package helm
374     :ensure t
375     :config
376     (helm-mode 1)
377     (define-key global-map [remap find-file] 'helm-find-files)
378     (define-key global-map [remap occur] 'helm-occur)
379     (define-key global-map [remap list-buffers] 'helm-buffers-list)
380     (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
381     (global-set-key (kbd "M-x") 'helm-M-x)
382     (unless (boundp 'completion-in-region-function)
383       (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
384       (define-key emacs-lisp-mode-map       [remap completion-at-point] 'helm-lisp-completion-at-point))
385     (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
386   )
387 #+END_SRC
388 ** Hydra
389 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
390 (require 'don-hydra)
391 #+END_SRC
392
393 ** Tramp
394 #+BEGIN_SRC emacs-lisp
395   (add-to-list 'tramp-methods '("vcsh"
396                                 (tramp-login-program "vcsh")
397                                 (tramp-login-args
398                                  (("enter")
399                                   ("%h")))
400                                 (tramp-remote-shell "/bin/sh")
401                                 (tramp-remote-shell-args
402                                  ("-c"))))
403 #+END_SRC
404 ** Reftex
405 #+BEGIN_SRC emacs-lisp
406   (use-package reftex
407     :ensure t
408     :config
409     (setq-default reftex-default-bibliography
410                     '("~/projects/research/references.bib")))
411 #+END_SRC
412 ** LaTeX
413 #+BEGIN_SRC emacs-lisp
414   (use-package tex
415     :defer t
416     :ensure auctex
417     :config
418     ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
419     ;; REFTEX (much enhanced management of cross-ref, labels, etc)
420     ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
421     ; (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
422     ; (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
423     ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
424     ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
425     (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
426     (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
427     (add-hook 'LaTeX-mode-hook 'outline-minor-mode)   ; with AUCTeX LaTeX mode
428     (add-hook 'latex-mode-hook 'outline-minor-mode)   ; with Emacs latex mode
429
430     (setq-default reftex-plug-into-AUCTeX t)
431     ;; support fake section headers
432     (setq TeX-outline-extra
433           '(("%chapter" 1)
434             ("%section" 2)
435             ("%subsection" 3)
436             ("%subsubsection" 4)
437             ("%paragraph" 5)))
438     ;; add font locking to the headers
439     (font-lock-add-keywords
440      'latex-mode
441      '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
442         0 'font-lock-keyword-face t)
443        ("^%chapter{\\(.*\\)}"       1 'font-latex-sectioning-1-face t)
444        ("^%section{\\(.*\\)}"       1 'font-latex-sectioning-2-face t)
445        ("^%subsection{\\(.*\\)}"    1 'font-latex-sectioning-3-face t)
446        ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
447        ("^%paragraph{\\(.*\\)}"     1 'font-latex-sectioning-5-face t)))
448
449     ;; use smart quotes by default instead of `` and ''
450     ;; taken from http://kieranhealy.org/esk/kjhealy.html
451     (setq TeX-open-quote "“")
452     (setq TeX-close-quote "”")
453
454     ;; (TeX-add-style-hook
455     ;;  "latex"
456     ;;  (lambda ()
457     ;;    (TeX-add-symbols
458     ;;     '("DLA" 1))))
459     ;; (custom-set-variables
460     ;;  '(font-latex-user-keyword-classes 
461     ;;    '(("fixme" 
462     ;;       ("DLA" "RZ")
463     ;;       font-lock-function-name-face 2 (command 1 t))))
464     ;; ) 
465     (setq-default TeX-parse-self t)
466     (setq-default TeX-auto-save t)
467     (setq-default TeX-master nil)
468     (eval-after-load
469         "latex"
470       '(TeX-add-style-hook
471         "cleveref"
472         (lambda ()
473           (if (boundp 'reftex-ref-style-alist)
474               (add-to-list
475                'reftex-ref-style-alist
476                '("Cleveref" "cleveref"
477                  (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
478           (reftex-ref-style-activate "Cleveref")
479           (TeX-add-symbols
480            '("cref" TeX-arg-ref)
481            '("Cref" TeX-arg-ref)
482            '("cpageref" TeX-arg-ref)
483            '("Cpageref" TeX-arg-ref)))))
484     (eval-after-load
485         "latex"
486       '(add-to-list 'LaTeX-fill-excluded-macros
487                     '("Sexpr")))
488
489     (use-package font-latex
490       :config
491       (setq font-latex-match-reference-keywords
492             '(
493               ("fref" "{")
494               ("Fref" "{")
495               ("citep" "{")
496               ("citet" "{")
497               ("acs" "{")
498               ("acsp" "{")
499               ("ac" "{")
500               ("acp" "{")
501               ("acl" "{")
502               ("aclp" "{")
503               ("acsu" "{")
504               ("aclu" "{")
505               ("acused" "{")
506               ("DLA" "{")
507               ("RZ" "{")
508               ("OM" "{")
509               ("DL" "{")
510               ("fixme" "{"))
511             )
512       )
513   )
514
515 #+END_SRC
516 *** Org-Gcal
517 #+BEGIN_SRC emacs-lisp
518   (use-package calfw
519     :ensure f
520     )
521   (use-package calfw-org
522     :ensure f
523     )
524   (use-package org-gcal
525     :ensure f
526     :config '((if (file-readable-p "~/.hide/org_gcal.el")
527                   (load-file "~/.hide/org_gcal.el"))
528               )
529     )
530 #+END_SRC
531 ** ESS
532 #+BEGIN_SRC emacs-lisp
533   (use-package ess
534     :ensure t
535     :config
536     (defun ess-change-directory (path)
537       "Set the current working directory to PATH for both *R* and Emacs."
538       (interactive "DDirectory to change to: ")
539     
540       (when (file-exists-p path)
541         (ess-command (concat "setwd(\"" path "\")\n"))
542         ;; use file-name-as-directory to ensure it has trailing /
543         (setq default-directory (file-name-as-directory path))))
544     (add-hook 'ess-mode-hook 'flyspell-prog-mode)
545     ;; outlining support for ess modes
546     (add-hook
547      'ess-mode-hook
548      '(lambda ()
549         (outline-minor-mode)
550         (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
551         (defun outline-level ()
552           (cond ((looking-at "^##### ") 1)
553                 ((looking-at "^#### ") 2)
554                 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
555                 (t 1000)))
556         ))
557     (add-hook 'ess-mode-hook
558               '(lambda ()
559                  (local-set-key (kbd "C-c C-R")
560                                 'dla/ess-region-remote-eval)))
561
562     ;; Don't restore history or save workspace image
563     '(inferior-R-args "--no-restore-history --no-save")
564     )
565 #+END_SRC
566
567 ** Rainbowmode
568 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
569
570 #+BEGIN_SRC emacs-lisp
571   (use-package rainbow-mode
572     ;; add ess to the x major mode
573     :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
574     (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
575   )
576 #+END_SRC
577
578 ** Polymode
579 #+BEGIN_SRC emacs-lisp
580   (use-package polymode
581     :config
582     (use-package poly-R)
583     (use-package poly-noweb)
584     (use-package poly-markdown)
585     :mode ("\\.Snw" . poly-noweb+r-mode)
586     :mode ("\\.Rnw" . poly-noweb+r-mode)
587     :mode ("\\.Rmd" . poly-markdown+r-mode)
588     )
589 #+END_SRC
590
591 ** Outlining
592 *** Outline magic
593 #+BEGIN_SRC emacs-lisp
594   (use-package outline-magic)
595 #+END_SRC
596 ** Writeroom Mode
597 #+BEGIN_SRC emacs-lisp
598   (use-package writeroom-mode
599     :config (add-hook 'writeroom-mode-hook 'auto-fill-mode)
600     )
601 #+END_SRC
602 ** GhostText/Atomic Chrome
603 #+BEGIN_SRC emacs-lisp
604   (use-package atomic-chrome
605     :config (atomic-chrome-start-server)
606     (setq atomic-chrome-buffer-open-style 'full)
607     )
608 #+END_SRC
609 ** Multiple Cursors
610    :PROPERTIES:
611    :ID:       6fcf218b-a762-4c37-9339-a8202ddeb544
612    :END:
613 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
614 #+BEGIN_SRC emacs-lisp
615   (use-package multiple-cursors
616     :bind (("C-;" . mc/mark-all-dwim)
617            ("C-<" . mc/mark-previous-like-this)
618            ("C->" . mc/mark-next-like-this)
619            ("C-S-c C-S-c" . mc/edit-lines))
620     )
621 #+END_SRC
622 * Org Mode
623 ** Use-package and load things
624 #+BEGIN_SRC emacs-lisp
625
626   (use-package org
627     :config 
628
629 #+END_SRC
630 ** Agenda Configuration
631 #+BEGIN_SRC emacs-lisp
632   ;; The following lines are always needed. Choose your own keys.
633   (add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
634   (global-set-key "\C-cl" 'org-store-link)
635   (global-set-key "\C-ca" 'org-agenda)
636   (global-set-key "\C-cb" 'org-iswitchb)
637   (setq-default org-log-done 'time)
638   (setq-default org-agenda-ndays 5)
639
640   ;; agenda configuration
641   ;; Do not dim blocked tasks
642   (setq org-agenda-dim-blocked-tasks nil)
643   (setq org-agenda-inhibit-startup t)
644   (setq org-agenda-use-tag-inheritance nil)
645
646   ;; Compact the block agenda view
647   (setq org-agenda-compact-blocks t)
648
649   ;; Custom agenda command definitions
650   (setq org-agenda-custom-commands
651         (quote (("N" "Notes" tags "NOTE"
652                  ((org-agenda-overriding-header "Notes")
653                   (org-tags-match-list-sublevels t)))
654                 ("h" "Habits" tags-todo "STYLE=\"habit\""
655                  ((org-agenda-overriding-header "Habits")
656                   (org-agenda-sorting-strategy
657                    '(todo-state-down effort-up category-keep))))
658                 (" " "Agenda"
659                  ((agenda "" nil)
660                   (tags "REFILE"
661                         ((org-agenda-overriding-header "Tasks to Refile")
662                          (org-tags-match-list-sublevels nil)))
663                   (tags-todo "-CANCELLED/!"
664                              ((org-agenda-overriding-header "Stuck Projects")
665                               (org-agenda-skip-function 'bh/skip-non-stuck-projects)
666                               (org-agenda-sorting-strategy
667                                '(category-keep))))
668                   (tags-todo "-HOLD-CANCELLED/!"
669                              ((org-agenda-overriding-header "Projects")
670                               (org-agenda-skip-function 'bh/skip-non-projects)
671                               (org-tags-match-list-sublevels 'indented)
672                               (org-agenda-sorting-strategy
673                                '(category-keep))))
674                   (tags-todo "-CANCELLED/!NEXT"
675                              ((org-agenda-overriding-header (concat "Project Next Tasks"
676                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
677                                                                         ""
678                                                                       " (including WAITING and SCHEDULED tasks)")))
679                               (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
680                               (org-tags-match-list-sublevels t)
681                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
682                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
683                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
684                               (org-agenda-sorting-strategy
685                                '(todo-state-down effort-up category-keep))))
686                   (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
687                              ((org-agenda-overriding-header (concat "Project Subtasks"
688                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
689                                                                         ""
690                                                                       " (including WAITING and SCHEDULED tasks)")))
691                               (org-agenda-skip-function 'bh/skip-non-project-tasks)
692                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
693                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
694                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
695                               (org-agenda-sorting-strategy
696                                '(category-keep))))
697                   (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
698                              ((org-agenda-overriding-header (concat "Standalone Tasks"
699                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
700                                                                         ""
701                                                                       " (including WAITING and SCHEDULED tasks)")))
702                               (org-agenda-skip-function 'bh/skip-project-tasks)
703                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
704                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
705                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
706                               (org-agenda-sorting-strategy
707                                '(category-keep))))
708                   (tags-todo "-CANCELLED+WAITING|HOLD/!"
709                              ((org-agenda-overriding-header "Waiting and Postponed Tasks")
710                               (org-agenda-skip-function 'bh/skip-stuck-projects)
711                               (org-tags-match-list-sublevels nil)
712                               (org-agenda-todo-ignore-scheduled t)
713                               (org-agenda-todo-ignore-deadlines t)))
714                   (tags "-REFILE/"
715                         ((org-agenda-overriding-header "Tasks to Archive")
716                          (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
717                          (org-tags-match-list-sublevels nil))))
718                  nil))))
719
720   ; org mode agenda files
721   (setq org-agenda-files
722         (quote ("~/projects/org-notes/debbugs.org"
723             "~/projects/org-notes/notes.org"
724             "~/projects/org-notes/holidays.org"
725             "~/projects/org-notes/refile.org"
726             "~/projects/org-notes/diary.org"
727             "~/projects/org-notes/ool.org"
728             "~/projects/org-notes/sndservers.org"
729             "~/projects/org-notes/chaim.org"
730             "~/projects/org-notes/wildman.org"
731             "~/projects/org-notes/uddin.org"
732             "~/projects/org-notes/reviews.org"
733             "~/projects/org-notes/hpcbio.org"
734             "~/org-mode/from-mobile.org"
735             "~/projects/org-notes/fh.org")))
736
737   (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
738   (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
739   (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
740   (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
741   (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
742   (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
743   (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
744   (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
745   (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
746   ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
747   (defun org-agenda-timeline-all (&optional arg)
748     (interactive "P")
749     (with-temp-buffer
750       (dolist (org-agenda-file org-agenda-files)
751         (insert-file-contents org-agenda-file nil)
752         (end-of-buffer)
753         (newline))
754       (write-file "/tmp/timeline.org")
755       (org-agenda arg "L")))
756   (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
757   ;; add automatic reminders for appointments
758   (defadvice  org-agenda-redo (after org-agenda-redo-add-appts)
759     "Pressing `r' on the agenda will also add appointments."
760     (progn 
761       (setq appt-time-msg-list nil)
762       (org-agenda-to-appt)))
763
764 #+END_SRC
765 ** General config
766 #+BEGIN_SRC emacs-lisp
767   (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")))
768   (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
769
770   (setq org-default-notes-file "~/projects/org-notes/notes.org")
771   (setq org-id-link-to-org-use-id t)
772 #+END_SRC
773 ** Capture Templates
774 #+BEGIN_SRC emacs-lisp
775   (setq org-capture-templates  ;; mail-specific note template, identified by "m"
776         '(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
777            "* %?\n\n  Source: %u, [[%:link][%:description]]\n  %:initial")
778           ("t" "todo" entry (file "~/projects/org-notes/refile.org")
779            "* TODO %?\n  :PROPERTIES:\n  :END:\n  :LOGBOOK:\n  :END:\n%U\n%a\n" :clock-in t :clock-resume t)
780           ("r" "respond" entry (file "~/projects/org-notes/refile.org")
781            "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
782           ("n" "note" entry (file "~/projects/org-notes/refile.org")
783            "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
784           ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
785            "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
786           ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
787            "* %?\n%U\n" :clock-in t :clock-resume t)
788           ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
789            "* TODO Review %c\n%U\n" :immediate-finish t)
790           ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
791            "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
792           ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
793            "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
794           ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
795            "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
796           ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
797            "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
798           ("J" "job" entry (file "~/projects/org-notes/refile.org")
799            "* TODO Apply for %a%? :job:\nSCHEDULED: %(format-time-string \"<%Y-%m-%d 17:00-17:30>\")\n%U\n%a\n" :clock-in t :clock-resume t)
800           ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
801            "* 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")
802           )
803         )
804
805   ;; Remove empty LOGBOOK drawers on clock out
806   (defun bh/remove-empty-drawer-on-clock-out ()
807     (interactive)
808     (save-excursion
809       (beginning-of-line 0)
810       (org-remove-empty-drawer-at (point))))
811
812   (defun my/org-add-id ()
813     (interactive)
814     (save-excursion
815       (if (org-current-level)
816           ()
817         (forward-char 1)
818         )
819       (org-id-get-create)
820       )
821   )
822
823 #+END_SRC
824 ** Org mode key bindings
825 #+BEGIN_SRC emacs-lisp
826   ; org mode configuration from http://doc.norang.ca/org-mode.html
827   ;; Custom Key Bindings
828   (global-set-key (kbd "<f12>") 'org-agenda)
829   (global-set-key (kbd "<f5>") 'bh/org-todo)
830   (global-set-key (kbd "<S-f5>") 'bh/widen)
831   (global-set-key (kbd "<f7>") 'bh/set-truncate-lines)
832   (global-set-key (kbd "<f8>") 'org-cycle-agenda-files)
833   (global-set-key (kbd "<f9> <f9>") 'bh/show-org-agenda)
834   (global-set-key (kbd "<f9> b") 'bbdb)
835   (global-set-key (kbd "<f9> c") 'calendar)
836   (global-set-key (kbd "<f9> f") 'boxquote-insert-file)
837   (global-set-key (kbd "<f9> h") 'bh/hide-other)
838   (global-set-key (kbd "<f9> n") 'bh/toggle-next-task-display)
839   (global-set-key (kbd "<f9> w") 'widen)
840
841   ; change the outline mode prefix from C-c @ to C-c C-2
842   (setq outline-minor-mode-prefix "C-c C-2")
843   ;(add-hook 'outline-minor-mode-hook
844   ;          (lambda () (local-set-key (kbd "C-c C-2")
845   ;                                    outline-mode-prefix-map)))
846
847   (global-set-key (kbd "<f9> I") 'bh/punch-in)
848   (global-set-key (kbd "<f9> O") 'bh/punch-out)
849
850   (global-set-key (kbd "<f9> o") 'bh/make-org-scratch)
851
852   (global-set-key (kbd "<f9> r") 'boxquote-region)
853   (global-set-key (kbd "<f9> s") 'bh/switch-to-scratch)
854
855   (global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
856   (global-set-key (kbd "<f9> T") 'bh/toggle-insert-inactive-timestamp)
857
858   (global-set-key (kbd "<f9> v") 'visible-mode)
859   (global-set-key (kbd "<f9> l") 'org-toggle-link-display)
860   (global-set-key (kbd "<f9> SPC") 'bh/clock-in-last-task)
861   (global-set-key (kbd "C-<f9>") 'previous-buffer)
862   (global-set-key (kbd "M-<f9>") 'org-toggle-inline-images)
863   (global-set-key (kbd "C-x n r") 'narrow-to-region)
864   (global-set-key (kbd "C-<f10>") 'next-buffer)
865   (global-set-key (kbd "<f11>") 'org-clock-goto)
866   (global-set-key (kbd "C-<f11>") 'org-clock-in)
867   (global-set-key (kbd "C-s-<f12>") 'bh/save-then-publish)
868   (global-set-key (kbd "C-c c") 'org-capture)
869
870 #+END_SRC
871 ** Utility Functions
872 #+BEGIN_SRC emacs-lisp
873   (defun bh/hide-other ()
874     (interactive)
875     (save-excursion
876       (org-back-to-heading 'invisible-ok)
877       (hide-other)
878       (org-cycle)
879       (org-cycle)
880       (org-cycle)))
881
882   (defun bh/set-truncate-lines ()
883     "Toggle value of truncate-lines and refresh window display."
884     (interactive)
885     (setq truncate-lines (not truncate-lines))
886     ;; now refresh window display (an idiom from simple.el):
887     (save-excursion
888       (set-window-start (selected-window)
889                         (window-start (selected-window)))))
890
891   (defun bh/make-org-scratch ()
892     (interactive)
893     (find-file "/tmp/publish/scratch.org")
894     (gnus-make-directory "/tmp/publish"))
895
896   (defun bh/switch-to-scratch ()
897     (interactive)
898     (switch-to-buffer "*scratch*"))
899
900   (setq org-use-fast-todo-selection t)
901   (setq org-treat-S-cursor-todo-selection-as-state-change nil)
902
903   ; create function to create headlines in file. This comes from
904   ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
905   (defun my/org-add-ids-to-headlines-in-file ()
906     "Add ID properties to all headlines in the current file which
907   do not already have one."
908     (interactive)
909     (org-map-entries 'org-id-get-create))
910   ; if we wanted to do this to every buffer, do the following:
911   ; (add-hook 'org-mode-hook
912   ;           (lambda ()
913   ;             (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
914 #+END_SRC
915 ** Keywords (TODO)
916 #+BEGIN_SRC emacs-lisp
917   (setq org-todo-keywords
918         (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
919                 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
920
921   (setq org-todo-keyword-faces
922         (quote (("TODO" :foreground "red" :weight bold)
923                 ("NEXT" :foreground "blue" :weight bold)
924                 ("DONE" :foreground "forest green" :weight bold)
925                 ("WAITING" :foreground "orange" :weight bold)
926                 ("HOLD" :foreground "magenta" :weight bold)
927                 ("CANCELLED" :foreground "forest green" :weight bold)
928                 ("MEETING" :foreground "forest green" :weight bold)
929                 ("PHONE" :foreground "forest green" :weight bold))))
930
931   (setq org-todo-state-tags-triggers
932         (quote (("CANCELLED" ("CANCELLED" . t))
933                 ("WAITING" ("WAITING" . t))
934                 ("HOLD" ("WAITING") ("HOLD" . t))
935                 (done ("WAITING") ("HOLD"))
936                 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
937                 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
938                 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
939
940
941
942   ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
943   ; add ids on creation of nodes
944   (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
945
946
947   ; resolve clocks after 10 minutes of idle; use xprintidle
948   ; (setq org-clock-idle-time 10)
949   ; (setq org-clock-x11idle-program-name "xprintidle")
950
951   ; this is from http://doc.norang.ca/org-mode.html#Capture
952   ; use C-M-r for org mode capture
953   (global-set-key (kbd "C-M-r") 'org-capture)
954
955   ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
956   (setq org-refile-targets (quote ((nil :maxlevel . 9)
957                                    (org-agenda-files :maxlevel . 9))))
958
959   ; Use full outline paths for refile targets - we file directly with IDO
960   (setq org-refile-use-outline-path t)
961
962   ; Targets complete directly with IDO
963   (setq org-outline-path-complete-in-steps nil)
964
965   ; Allow refile to create parent tasks with confirmation
966   (setq org-refile-allow-creating-parent-nodes (quote confirm))
967
968   ; ; Use IDO for both buffer and file completion and ido-everywhere to t
969   ; (setq org-completion-use-ido t)
970   ; (setq ido-everywhere t)
971   ; (setq ido-max-directory-size 100000)
972   ; (ido-mode (quote both))
973   ; ; Use the current window when visiting files and buffers with ido
974   ; (setq ido-default-file-method 'selected-window)
975   ; (setq ido-default-buffer-method 'selected-window)
976   ; ; Use the current window for indirect buffer display
977   ; (setq org-indirect-buffer-display 'current-window)
978
979
980   ;;;; Refile settings
981   ; Exclude DONE state tasks from refile targets
982   (defun bh/verify-refile-target ()
983     "Exclude todo keywords with a done state from refile targets"
984     (not (member (nth 2 (org-heading-components)) org-done-keywords)))
985
986   (setq org-refile-target-verify-function 'bh/verify-refile-target)
987
988   ;; ensure that emacsclient will show just the note to be edited when invoked
989   ;; from Mutt, and that it will shut down emacsclient once finished;
990   ;; fallback to legacy behavior when not invoked via org-protocol.
991   (require 'org-protocol)
992   ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
993   (setq my-org-protocol-flag nil)
994   (defadvice org-capture-finalize (after delete-frame-at-end activate)
995     "Delete frame at remember finalization"
996     (progn (if my-org-protocol-flag (delete-frame))
997            (setq my-org-protocol-flag nil)))
998   (defadvice org-capture-refile (around delete-frame-after-refile activate)
999     "Delete frame at remember refile"
1000     (if my-org-protocol-flag
1001         (progn
1002           (setq my-org-protocol-flag nil)
1003           ad-do-it
1004           (delete-frame))
1005       ad-do-it)
1006     )
1007   (defadvice org-capture-kill (after delete-frame-at-end activate)
1008     "Delete frame at remember abort"
1009     (progn (if my-org-protocol-flag (delete-frame))
1010            (setq my-org-protocol-flag nil)))
1011   (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1012     (setq my-org-protocol-flag t))
1013
1014   (defadvice org-insert-todo-heading (after dla/create-id activate)
1015     (org-id-get-create)
1016     )
1017
1018   ;; org modules
1019   (add-to-list 'org-modules 'org-habit)
1020
1021   ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1022   (defun open-mail-in-mutt (message)
1023     "Open a mail message in Mutt, using an external terminal.
1024
1025   Message can be specified either by a path pointing inside a
1026   Maildir, or by Message-ID."
1027     (interactive "MPath or Message-ID: ")
1028     (shell-command
1029      (format "faf xterm -e \"%s %s\""
1030          (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1031
1032   ;; add support for "mutt:ID" links
1033   (org-add-link-type "mutt" 'open-mail-in-mutt)
1034
1035   (defun my-org-mode-setup ()
1036     (load-library "reftex")
1037     (and (buffer-file-name)
1038          (file-exists-p (buffer-file-name))
1039          (progn
1040            (reftex-parse-all)
1041            (reftex-set-cite-format
1042             '((?b . "[[bib:%l][%l-bib]]")
1043               (?n . "[[notes:%l][%l-notes]]")
1044               (?c . "\\cite{%l}")
1045               (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1046            ))
1047     (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1048     (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1049     (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1050     (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1051     )
1052   (add-hook 'org-mode-hook 'my-org-mode-setup)
1053
1054   (defun org-mode-reftex-search ()
1055     (interactive)
1056     (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1057
1058   (defun open-research-paper (bibtexkey)
1059     "Open a paper by bibtex key"
1060     (interactive "bibtex key: ")
1061     (shell-command
1062      (format "%s %s"
1063          (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1064   (org-add-link-type "papers" 'open-research-paper)
1065   (defun open-research-paper-pdf (bibtexkey)
1066     "Open a paper pdf by bibtex key"
1067     (interactive "bibtex key: ")
1068     (shell-command
1069      (format "%s -p evince_annot %s"
1070          (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1071   (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1072
1073   (add-to-list 'org-link-abbrev-alist
1074                '("notes" .
1075                  "~/projects/research/paper_notes.org::#%s"))
1076
1077   ; I pretty much always want hiearchical checkboxes
1078   (setq org-hierachical-checkbox-statistics nil)
1079
1080   ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1081   (add-to-list 'org-structure-template-alist
1082                '("E" "\\begin{equation}\n?\n\\end{equation}"))
1083
1084    ;; stolen from
1085   ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1086   (defun my-rtcite-export-handler (path desc format)
1087     (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1088     (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1089                      (match-string 1 path)))
1090            (path (substring path 0 (match-beginning 0))))
1091       (cond ((eq format 'latex)
1092              (if (or (not desc) 
1093                      (equal 0 (search "rtcite:" desc)))
1094                  (format "\\cite{%s}" search)
1095                (format "\\cite[%s]{%s}" desc search))))))
1096
1097   (org-add-link-type "rtcite" 
1098                      'org-bibtex-open
1099                      'my-rtcite-export-handler)
1100
1101
1102 #+END_SRC
1103 ** Org Mobile Configuration
1104 #+BEGIN_SRC emacs-lisp
1105   (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1106   (when (string= system-name "linnode")
1107     (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1108   (setq-default org-directory "/home/don/org-mode/")
1109   (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1110
1111 #+END_SRC
1112 ** Org iCal Support
1113 #+BEGIN_SRC emacs-lisp
1114   ;; org mode ical export
1115   (setq org-icalendar-timezone "America/Los_Angeles")
1116   (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1117   ;; we already add the id manually
1118   ;; (setq org-icalendar-store-UID t)
1119
1120 #+END_SRC
1121 ** General Org Babel Configuration
1122 #+BEGIN_SRC emacs-lisp
1123   ;; org babel support
1124   (org-babel-do-load-languages
1125    'org-babel-load-languages
1126    '((emacs-lisp . t )
1127      (R . t)
1128      (latex . t)
1129      (ditaa . t)
1130      (dot . t)
1131      ))
1132   ;; use graphviz-dot for dot things
1133   (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1134   ;; org-babel-by-backend
1135   (defmacro org-babel-by-backend (&rest body)
1136      `(case (if (boundp 'backend) 
1137                 (org-export-backend-name backend)
1138               nil) ,@body))
1139
1140   (defun my/fix-inline-images ()
1141     (when org-inline-image-overlays
1142       (org-redisplay-inline-images)))
1143
1144   (add-hook 'org-babel-after-execute-hook
1145              'my/fix-inline-images)
1146
1147 #+END_SRC
1148 ** LaTeX configuration
1149    :PROPERTIES:
1150    :ID:       7135ba17-6a50-4eed-84ca-b90afa5b12f8
1151    :END:
1152 #+BEGIN_SRC emacs-lisp
1153   (require 'ox-latex)
1154   (add-to-list 'org-latex-classes
1155            '("memarticle"
1156          "\\documentclass[11pt,oneside,article]{memoir}\n"
1157          ("\\section{%s}" . "\\section*{%s}")
1158          ("\\subsection{%s}" . "\\subsection*{%s}")
1159          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1160          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1161          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1162
1163   (setq org-beamer-outline-frame-options "")
1164   (add-to-list 'org-latex-classes
1165            '("beamer"
1166          "\\documentclass[ignorenonframetext]{beamer}
1167   [NO-DEFAULT-PACKAGES]
1168   [PACKAGES]
1169   [EXTRA]"
1170          ("\\section{%s}" . "\\section*{%s}")
1171          ("\\subsection{%s}" . "\\subsection*{%s}")
1172          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1173          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1174          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1175
1176   (add-to-list 'org-latex-classes
1177            '("membook"
1178          "\\documentclass[11pt,oneside]{memoir}\n"
1179          ("\\chapter{%s}" . "\\chapter*{%s}")
1180          ("\\section{%s}" . "\\section*{%s}")
1181          ("\\subsection{%s}" . "\\subsection*{%s}")
1182          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1183
1184   (add-to-list 'org-latex-classes
1185            '("letter"
1186          "\\documentclass[11pt]{letter}
1187   [NO-DEFAULT-PACKAGES]
1188   [PACKAGES]
1189   [EXTRA]"
1190      ("\\section{%s}" . "\\section*{%s}")
1191          ("\\subsection{%s}" . "\\subsection*{%s}")
1192          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1193          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1194          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1195
1196   (add-to-list 'org-latex-classes
1197            '("dlacv"
1198          "\\documentclass{dlacv}
1199   [NO-DEFAULT-PACKAGES]
1200   [NO-PACKAGES]
1201   [NO-EXTRA]"
1202          ("\\section{%s}" . "\\section*{%s}")
1203          ("\\subsection{%s}" . "\\subsection*{%s}")
1204          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1205          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1206          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1207
1208
1209   (add-to-list 'org-latex-classes
1210            '("dlaresume"
1211          "\\documentclass{dlaresume}
1212   [NO-DEFAULT-PACKAGES]
1213   [NO-PACKAGES]
1214   [NO-EXTRA]"
1215          ("\\section{%s}" . "\\section*{%s}")
1216          ("\\subsection{%s}" . "\\subsection*{%s}")
1217          ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1218          ("\\paragraph{%s}" . "\\paragraph*{%s}")
1219          ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1220
1221
1222   ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
1223   ;; but adapted to use latexmk 4.22 or higher.  
1224   (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
1225
1226   ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
1227   (setq org-latex-default-packages-alist
1228     '(("" "amsmath" t)
1229       ("" "unicode-math" t)
1230       ))
1231   (setq org-latex-packages-alist
1232     '(("" "graphicx" t)
1233       ("" "fontspec" t)
1234       ("" "xunicode" t)
1235       ("" "hyperref" t)
1236       ("" "url" t)
1237       ("" "rotating" t)
1238       ("" "longtable" nil)
1239       ("" "float" )))
1240
1241   ;; make equations larger
1242   (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
1243
1244   (defun org-create-formula--latex-header ()
1245     "Return LaTeX header appropriate for previewing a LaTeX snippet."
1246     (let ((info (org-combine-plists (org-export--get-global-options
1247              (org-export-get-backend 'latex))
1248             (org-export--get-inbuffer-options
1249              (org-export-get-backend 'latex)))))
1250       (org-latex-guess-babel-language
1251        (org-latex-guess-inputenc
1252     (org-splice-latex-header
1253      org-format-latex-header
1254      org-latex-default-packages-alist
1255      nil t
1256      (plist-get info :latex-header)))
1257        info)))
1258
1259
1260   ; support ignoring headers in org mode export to latex
1261   ; from http://article.gmane.org/gmane.emacs.orgmode/67692
1262   (defadvice org-latex-headline (around my-latex-skip-headlines
1263                     (headline contents info) activate)
1264     (if (member "ignoreheading" (org-element-property :tags headline))
1265     (setq ad-return-value contents)
1266       ad-do-it))
1267
1268   ;; keep latex logfiles
1269
1270   (setq org-latex-remove-logfiles nil)
1271
1272   ;; Resume clocking task when emacs is restarted
1273   (org-clock-persistence-insinuate)
1274   ;;
1275   ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
1276   (setq org-clock-history-length 23)
1277   ;; Resume clocking task on clock-in if the clock is open
1278   (setq org-clock-in-resume t)
1279   ;; Change tasks to NEXT when clocking in; this avoids clocking in when
1280   ;; there are things like PHONE calls
1281   (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
1282   ;; Separate drawers for clocking and logs
1283   (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
1284   ;; Save clock data and state changes and notes in the LOGBOOK drawer
1285   (setq org-clock-into-drawer t)
1286   (setq org-log-into-drawer t)
1287   ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
1288   (setq org-clock-out-remove-zero-time-clocks t)
1289   ;; Clock out when moving task to a done state
1290   (setq org-clock-out-when-done t)
1291   ;; Save the running clock and all clock history when exiting Emacs, load it on startup
1292   (setq org-clock-persist t)
1293   ;; Do not prompt to resume an active clock
1294   (setq org-clock-persist-query-resume nil)
1295   ;; Enable auto clock resolution for finding open clocks
1296   (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
1297   ;; Include current clocking task in clock reports
1298   (setq org-clock-report-include-clocking-task t)
1299
1300   ;; the cache seems to be broken
1301   (setq org-element-use-cache nil)
1302
1303   (defvar bh/keep-clock-running nil)
1304
1305   (defun bh/is-task-p ()
1306     "Any task with a todo keyword and no subtask"
1307     (save-restriction
1308       (widen)
1309       (let ((has-subtask)
1310             (subtree-end (save-excursion (org-end-of-subtree t)))
1311             (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1312         (save-excursion
1313           (forward-line 1)
1314           (while (and (not has-subtask)
1315                       (< (point) subtree-end)
1316                       (re-search-forward "^\*+ " subtree-end t))
1317             (when (member (org-get-todo-state) org-todo-keywords-1)
1318               (setq has-subtask t))))
1319         (and is-a-task (not has-subtask)))))
1320   (defun bh/is-project-p ()
1321     "Any task with a todo keyword subtask"
1322     (save-restriction
1323       (widen)
1324       (let ((has-subtask)
1325             (subtree-end (save-excursion (org-end-of-subtree t)))
1326             (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1327         (save-excursion
1328           (forward-line 1)
1329           (while (and (not has-subtask)
1330                       (< (point) subtree-end)
1331                       (re-search-forward "^\*+ " subtree-end t))
1332             (when (member (org-get-todo-state) org-todo-keywords-1)
1333               (setq has-subtask t))))
1334         (and is-a-task has-subtask))))
1335
1336   (defun bh/is-subproject-p ()
1337     "Any task which is a subtask of another project"
1338     (let ((is-subproject)
1339           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1340       (save-excursion
1341         (while (and (not is-subproject) (org-up-heading-safe))
1342           (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1343             (setq is-subproject t))))
1344       (and is-a-task is-subproject)))
1345
1346
1347   (defun bh/clock-in-to-next (kw)
1348     "Switch a task from TODO to NEXT when clocking in.
1349   Skips capture tasks, projects, and subprojects.
1350   Switch projects and subprojects from NEXT back to TODO"
1351     (when (not (and (boundp 'org-capture-mode) org-capture-mode))
1352       (cond
1353        ((and (member (org-get-todo-state) (list "TODO"))
1354          (bh/is-task-p))
1355     "NEXT")
1356        ((and (member (org-get-todo-state) (list "NEXT"))
1357          (bh/is-project-p))
1358     "TODO"))))
1359
1360   (defun bh/punch-in (arg)
1361     "Start continuous clocking and set the default task to the
1362   selected task.  If no task is selected set the Organization task
1363   as the default task."
1364     (interactive "p")
1365     (setq bh/keep-clock-running t)
1366     (if (equal major-mode 'org-agenda-mode)
1367     ;;
1368     ;; We're in the agenda
1369     ;;
1370     (let* ((marker (org-get-at-bol 'org-hd-marker))
1371            (tags (org-with-point-at marker (org-get-tags-at))))
1372       (if (and (eq arg 4) tags)
1373           (org-agenda-clock-in '(16))
1374         (bh/clock-in-organization-task-as-default)))
1375       ;;
1376       ;; We are not in the agenda
1377       ;;
1378       (save-restriction
1379     (widen)
1380     ; Find the tags on the current task
1381     (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
1382         (org-clock-in '(16))
1383       (bh/clock-in-organization-task-as-default)))))
1384
1385   (defun bh/punch-out ()
1386     (interactive)
1387     (setq bh/keep-clock-running nil)
1388     (when (org-clock-is-active)
1389       (org-clock-out))
1390     (org-agenda-remove-restriction-lock))
1391
1392   (defun bh/clock-in-default-task ()
1393     (save-excursion
1394       (org-with-point-at org-clock-default-task
1395     (org-clock-in))))
1396
1397   (defun bh/clock-in-parent-task ()
1398     "Move point to the parent (project) task if any and clock in"
1399     (let ((parent-task))
1400       (save-excursion
1401     (save-restriction
1402       (widen)
1403       (while (and (not parent-task) (org-up-heading-safe))
1404         (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1405           (setq parent-task (point))))
1406       (if parent-task
1407           (org-with-point-at parent-task
1408         (org-clock-in))
1409         (when bh/keep-clock-running
1410           (bh/clock-in-default-task)))))))
1411
1412   (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
1413
1414   (defun bh/clock-in-organization-task-as-default ()
1415     (interactive)
1416     (org-with-point-at (org-id-find bh/organization-task-id 'marker)
1417       (org-clock-in '(16))))
1418
1419   (defun bh/clock-out-maybe ()
1420     (when (and bh/keep-clock-running
1421            (not org-clock-clocking-in)
1422            (marker-buffer org-clock-default-task)
1423            (not org-clock-resolving-clocks-due-to-idleness))
1424       (bh/clock-in-parent-task)))
1425
1426   ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
1427
1428   (require 'org-id)
1429   (defun bh/clock-in-task-by-id (id)
1430     "Clock in a task by id"
1431     (org-with-point-at (org-id-find id 'marker)
1432       (org-clock-in nil)))
1433
1434   (defun bh/clock-in-last-task (arg)
1435     "Clock in the interrupted task if there is one
1436   Skip the default task and get the next one.
1437   A prefix arg forces clock in of the default task."
1438     (interactive "p")
1439     (let ((clock-in-to-task
1440        (cond
1441         ((eq arg 4) org-clock-default-task)
1442         ((and (org-clock-is-active)
1443           (equal org-clock-default-task (cadr org-clock-history)))
1444          (caddr org-clock-history))
1445         ((org-clock-is-active) (cadr org-clock-history))
1446         ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
1447         (t (car org-clock-history)))))
1448       (widen)
1449       (org-with-point-at clock-in-to-task
1450     (org-clock-in nil))))
1451
1452
1453   (defun org-export-to-ods ()
1454     (interactive)
1455     (let ((csv-file "data.csv"))
1456       (org-table-export csv-file "orgtbl-to-csv")
1457       (org-odt-convert csv-file "ods" 'open)))
1458
1459   ; allow for zero-width-space to be a break in regexp too
1460   ; (setcar org-emphasis-regexp-components "​ [:space:] \t('\"{")
1461   ; (setcar (nthcdr 1 org-emphasis-regexp-components) "​ [:space:]- \t.,:!?;'\")}\\")
1462   ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
1463
1464   ;; support inserting screen shots
1465   (defun my/org-insert-screenshot ()
1466     "Take a screenshot into a time stamped unique-named file in the
1467   same directory as the org-buffer and insert a link to this file."
1468     (interactive)
1469     (defvar my/org-insert-screenshot/filename)
1470     (setq my/org-insert-screenshot/filename
1471       (read-file-name
1472        "Screenshot to insert: "
1473        nil
1474        (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
1475        )
1476       )
1477     (call-process "import" nil nil nil my/org-insert-screenshot/filename)
1478     (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
1479     (org-display-inline-images))
1480
1481   (defun my/fix-inline-images ()
1482     (when org-inline-image-overlays
1483       (org-redisplay-inline-images)))
1484
1485   (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
1486
1487   ;; use xelatex to preview with imagemagick
1488   (add-to-list 'org-preview-latex-process-alist
1489            '(xelateximagemagick
1490         :programs ("xelatex" "convert")
1491         :description "pdf > png"
1492         :message "you need to install xelatex and imagemagick"
1493         :use-xcolor t
1494         :image-input-type "pdf"
1495         :image-output-type "png"
1496         :image-size-adjust (1.0 . 1.0)
1497         :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
1498         :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
1499            )
1500   ;; use xelatex by default
1501   (setq org-preview-latex-default-process 'xelateximagemagick)
1502
1503   ; from http://orgmode.org/Changes.html
1504   (defun my/org-repair-property-drawers ()
1505     "Fix properties drawers in current buffer.
1506    Ignore non Org buffers."
1507     (interactive)
1508     (when (eq major-mode 'org-mode)
1509       (org-with-wide-buffer
1510        (goto-char (point-min))
1511        (let ((case-fold-search t)
1512          (inline-re (and (featurep 'org-inlinetask)
1513                  (concat (org-inlinetask-outline-regexp)
1514                      "END[ \t]*$"))))
1515      (org-map-entries
1516       (lambda ()
1517         (unless (and inline-re (org-looking-at-p inline-re))
1518           (save-excursion
1519         (let ((end (save-excursion (outline-next-heading) (point))))
1520           (forward-line)
1521           (when (org-looking-at-p org-planning-line-re) (forward-line))
1522           (when (and (< (point) end)
1523                  (not (org-looking-at-p org-property-drawer-re))
1524                  (save-excursion
1525                    (and (re-search-forward org-property-drawer-re end t)
1526                     (eq (org-element-type
1527                      (save-match-data (org-element-at-point)))
1528                     'drawer))))
1529             (insert (delete-and-extract-region
1530                  (match-beginning 0)
1531                  (min (1+ (match-end 0)) end)))
1532             (unless (bolp) (insert "\n"))))))))))))
1533
1534 #+END_SRC
1535 ** End use-package
1536 #+BEGIN_SRC emacs-lisp
1537   )
1538 #+END_SRC
1539 * Keybindings
1540 ** Override other things
1541 #+BEGIN_SRC emacs-lisp
1542   ; apparently things like to step on C-;, so we'll use a hack from
1543   ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
1544
1545   (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
1546
1547   ; use mc everywhere
1548   (define-key my-keys-minor-mode-map (kbd "C-;") 'mc/mark-all-dwim)
1549   ;; use outline mode keybindings everywhere
1550   ;; (define-key my-keys-minor-mode-map (kbd "C-;") 'my/mydra-outline/body)
1551
1552   (define-minor-mode my-keys-minor-mode
1553     "A minor mode so that my key settings override annoying major modes."
1554     t " my-keys" 'my-keys-minor-mode-map)
1555
1556   (my-keys-minor-mode 1)
1557   (defun my-minibuffer-setup-hook ()
1558     (my-keys-minor-mode 0))
1559
1560   (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
1561   (defadvice load (after give-my-keybindings-priority)
1562     "Try to ensure that my keybindings always have priority."
1563     (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
1564         (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
1565           (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
1566           (add-to-list 'minor-mode-map-alist mykeys))))
1567   (ad-activate 'load)
1568 #+END_SRC
1569
1570 * Misc (uncharacterized)
1571 #+BEGIN_SRC emacs-lisp
1572   (setq bibtex-user-optional-fields (quote (("annote" "Personal annotation (ignored)") ("abstract" "") ("pmid" "") ("doi" ""))))
1573   (setq calendar-latitude 40.11)
1574   (setq calendar-longitude -88.24)
1575   (setq case-fold-search t)
1576   (setq confirm-kill-emacs (quote y-or-n-p))
1577   (setq cperl-lazy-help-time nil)
1578   (setq debian-changelog-mailing-address "don@debian.org")
1579   (display-time)
1580   (setq display-time-24hr-format t)
1581   (setq display-time-day-and-date t)
1582   (display-time-mode 1)
1583   (setq font-latex-fontify-script nil)
1584   (setq font-latex-fontify-sectioning (quote color))
1585   (setq font-latex-script-display (quote (nil)))
1586   (global-auto-revert-mode 1)
1587   (global-font-lock-mode 1)
1588   (icomplete-mode 1)
1589   (setq log-edit-keep-buffer t)
1590   (setq mail-user-agent (quote sendmail-user-agent))
1591   (setq markdown-enable-math t)
1592   (setq markdown-follow-wiki-link-on-enter nil)
1593   (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
1594   (setq post-email-address "don@donarmstrong.com")
1595   (setq post-kill-quoted-sig nil)
1596   (setq post-mail-message "mutt\\(ng\\|\\)-[a-z0-9]+-[0-9]+-.*")
1597   (setq post-uses-fill-mode nil)
1598   (setq ps-footer-font-size (quote (8 . 10)))
1599   (setq ps-header-font-size (quote (8 . 10)))
1600   (setq ps-header-title-font-size (quote (10 . 10)))
1601   (setq ps-line-number-color "blue")
1602   (setq ps-print-footer t)
1603   (setq ps-print-footer-frame nil)
1604   (setq ps-print-only-one-header t)
1605   (setq sentence-end "[.?!][]\"')]*\\($\\|   \\| \\)[    
1606   ]*")
1607   (setq sentence-end-double-space nil)
1608   ; enable matching parenthesis
1609   (show-paren-mode 1)
1610   (tool-bar-mode -1)
1611   (setq user-mail-address "don@donarmstrong.com")
1612   (setq vc-delete-logbuf-window nil)
1613   (setq vc-follow-symlinks t)
1614
1615   ;; use git before SVN; use CVS earlier, because I have CVS
1616   ;; repositories inside of git directories
1617   (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
1618
1619   ;; switch back to the old primary selection method
1620   (setq x-select-enable-clipboard nil)
1621   (setq x-select-enable-primary t)
1622   ; (setq mouse-drag-copy-region t)
1623
1624   (fset 'perl-mode 'cperl-mode)
1625   ;;(load-file "cperl-mode.el")
1626
1627   (require 'vcl-mode)
1628
1629   (require 'tex-site)
1630   ;;(require 'psvn)
1631   ;;(require 'ecasound)
1632   ;;(require 'emacs-wiki)
1633   (require 'bibtex)
1634   (require 'post)
1635   ;;(require 'fixme)
1636   ; (require 'google-weather)
1637   ; (require 'org-google-weather)
1638   ; (setq-default org-google-weather-format "%i %c, [%l,%h] %s %C")
1639   
1640   (global-set-key "\C-xp" 'server-edit)
1641
1642   (setq-default auto-mode-alist (cons '("\.wml$" . 
1643                     (lambda () (html-mode) (auto-fill-mode)))
1644                   auto-mode-alist))
1645
1646
1647   ; use markdown mode for mdwn files
1648   (add-to-list 'auto-mode-alist '("\\.mdwn$" . markdown-mode))
1649   (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
1650
1651
1652   ;; tramp configuration
1653   (setq tramp-use-ssh-controlmaster-options nil)
1654
1655   ; mail configuration
1656   (add-to-list 'auto-mode-alist '("muttng-[a-z0-9]+-[0-9]+-" . message-mode))
1657   (add-to-list 'auto-mode-alist '("muttngrc" . muttrc-mode))
1658
1659   (add-to-list 'auto-mode-alist '("mutt-[a-z0-9]+-[0-9]+-" . message-mode))
1660   (add-to-list 'auto-mode-alist '("muttrc" . muttrc-mode))
1661   (defun my-message-mode-settings ()
1662     (font-lock-add-keywords nil
1663                             '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1664                                (0 'message-multiply-quoted-text-face))
1665                               ("^[ \t]*>[ \t]*>.*$"
1666                                (0 'message-double-quoted-text-face))))
1667     (local-set-key (kbd "C-c C-a") 'my-post-attach-file)
1668     )
1669   (add-hook 'message-mode-hook 'my-message-mode-settings)
1670
1671   (defun my-post-attach-file ()
1672     "Prompt for an attachment."
1673     (interactive)
1674     (let ((file (read-file-name "Attach file: " nil nil t nil))
1675           (description (string-read "Description: ")))
1676       (my-header-attach-file file description)))
1677
1678   (symbol-function 'my-post-attach-file)
1679
1680   (defun my-header-attach-file (file description)
1681     "Attach a FILE to the current message (works with Mutt).
1682   Argument DESCRIPTION MIME description."
1683     (interactive "fAttach file: \nsDescription: ")
1684     (when (> (length file) 0)
1685       (save-excursion
1686         (save-match-data
1687           (save-restriction
1688             (widen)
1689             (goto-char (point-min))
1690             (search-forward-regexp "^$")
1691             (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1692                             description "\n"))
1693             (message (concat "Attached '" file "'."))
1694             (setq post-has-attachment t))))))
1695
1696
1697
1698   (setq mail-yank-prefix "> ")
1699
1700   (global-unset-key "\M-g")
1701   (global-set-key "\M-g" 'goto-line)
1702
1703   ;; self-insert-command hack.
1704   ;;   Without this, "if<SP>" expands to
1705   ;;   if ( -!-) {
1706   ;;   }
1707   ;;   which really should be,
1708   ;;   if (-!-) {
1709   ;;   }
1710
1711
1712
1713   ;(load-library "php-mode")
1714
1715   (setq-default c-indent-level 4)
1716   (setq-default c-brace-imaginary-offset 0)
1717   (setq-default c-brace-offset -4)
1718   (setq-default c-argdecl-indent 4)
1719   (setq-default c-label-offset -4)
1720   (setq-default c-continued-statement-offset 4)
1721   ; tabs are annoying
1722   (setq-default indent-tabs-mode nil)
1723   (setq-default tab-width 4)
1724
1725
1726   ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
1727   ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
1728   ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
1729   ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
1730   ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
1731
1732
1733   (defun insert-date ()
1734     "Insert date at point."
1735     (interactive)
1736     (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
1737   (global-set-key "\C-[d" 'insert-date)
1738
1739   (defun unfill-paragraph (arg)
1740     "Pull this whole paragraph up onto one line."
1741     (interactive "*p")
1742     (let ((fill-column 10000))
1743       (fill-paragraph arg))
1744     )
1745
1746   (column-number-mode t)
1747
1748   (server-start)
1749
1750   ; (require 'mode-compile)
1751
1752   (defadvice server-process-filter (after post-mode-message first activate)
1753     "If the buffer is in post mode, overwrite the server-edit
1754       message with a post-save-current-buffer-and-exit message."
1755     (if (eq major-mode 'post-mode)
1756         (message
1757          (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
1758                       ; This is also needed to see the magic message.  Set to a higher
1759                       ; number if you have a faster computer or read slower than me.
1760   '(font-lock-verbose 1000)
1761   ;(setq-default server-temp-file-regexp "mutt\(-\|ng-\)")
1762   ; (add-hook 'server-switch-hook 
1763   ;     (function (lambda()
1764   ;             (cond ((string-match "Post" mode-name)
1765   ;                (post-goto-body)))
1766   ;             set-buffer-file-coding-system 'utf-8
1767   ;             )))
1768   ; 
1769
1770   (add-hook 'post-mode-hook
1771         (auto-fill-mode nil)
1772         )
1773   ; abbrev mode settings
1774   ; load abbreviations from 
1775   (setq abbrev-file-name       
1776         "~/.emacs_abbrev_def")
1777
1778   ; read the abbrev file if it exists
1779   (if (file-exists-p abbrev-file-name)
1780       (quietly-read-abbrev-file))
1781
1782   ; for now, use abbrev mode everywhere
1783   (setq default-abbrev-mode t)
1784
1785
1786   (defun insert-function-documentation ()
1787     "Insert function documentation"
1788     (interactive)
1789     (insert-file-contents "/home/don/lib/templates/perl_function_documentation" nil))
1790   (global-set-key "\M-f" 'insert-function-documentation)
1791
1792   (eval-after-load "lilypond-mode" 
1793     '(progn
1794        (load-library "lyqi-mode")
1795        (define-key LilyPond-mode-map "\C-cq" 'lyqi-mode)))
1796
1797   (autoload 'spamassassin-mode "spamassassin-mode" nil t)
1798
1799   (desktop-load-default)
1800   (desktop-read)
1801   '(icomplete-mode on)
1802   (custom-set-faces
1803    ;; custom-set-faces was added by Custom.
1804    ;; If you edit it by hand, you could mess it up, so be careful.
1805    ;; Your init file should contain only one such instance.
1806    ;; If there is more than one, they won't work right.
1807    '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
1808
1809
1810   (put 'upcase-region 'disabled nil)
1811   (put 'downcase-region 'disabled nil)
1812   (put 'narrow-to-region 'disabled nil)
1813
1814   ; (defun turn-on-flyspell ()
1815   ;    "Force flyspell-mode on using a positive arg.  For use in hooks."
1816   ;    (interactive)
1817   ;    (flyspell-mode 1))
1818
1819
1820    ; Outline-minor-mode key map
1821    (define-prefix-command 'cm-map nil "Outline-")
1822    ; HIDE
1823    (define-key cm-map "q" 'hide-sublevels)    ; Hide everything but the top-level headings
1824    (define-key cm-map "t" 'hide-body)         ; Hide everything but headings (all body lines)
1825    (define-key cm-map "o" 'hide-other)        ; Hide other branches
1826    (define-key cm-map "c" 'hide-entry)        ; Hide this entry's body
1827    (define-key cm-map "l" 'hide-leaves)       ; Hide body lines in this entry and sub-entries
1828    (define-key cm-map "d" 'hide-subtree)      ; Hide everything in this entry and sub-entries
1829    ; SHOW
1830    (define-key cm-map "a" 'show-all)          ; Show (expand) everything
1831    (define-key cm-map "e" 'show-entry)        ; Show this heading's body
1832    (define-key cm-map "i" 'show-children)     ; Show this heading's immediate child sub-headings
1833    (define-key cm-map "k" 'show-branches)     ; Show all sub-headings under this heading
1834    (define-key cm-map "s" 'show-subtree)      ; Show (expand) everything in this heading & below
1835    ; MOVE
1836    (define-key cm-map "u" 'outline-up-heading)                ; Up
1837    (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
1838    (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
1839    (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
1840    (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
1841    (global-set-key "\M-o" cm-map)
1842
1843
1844   ; debian stuff
1845   (setq-default debian-changelog-mailing-address "don@debian.org")
1846   (setq-default debian-changelog-full-name "Don Armstrong")
1847
1848   ; ediff configuration
1849   ; don't use the multi-window configuration
1850   (setq ediff-window-setup-function 'ediff-setup-windows-plain)
1851
1852   ; fix up css mode to not be silly
1853   ; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1854   (setq cssm-indent-level 4)
1855   (setq cssm-newline-before-closing-bracket t)
1856   (setq cssm-indent-function #'cssm-c-style-indenter)
1857   (setq cssm-mirror-mode nil)
1858
1859   (require 'multi-web-mode)
1860   (setq mweb-default-major-mode 'html-mode)
1861   (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
1862                     (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
1863                     (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
1864   (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
1865   (multi-web-global-mode 1)
1866
1867   ;;; alias the new `flymake-report-status-slim' to
1868   ;;; `flymake-report-status'
1869   (defalias 'flymake-report-status 'flymake-report-status-slim)
1870   (defun flymake-report-status-slim (e-w &optional status)
1871     "Show \"slim\" flymake status in mode line."
1872     (when e-w
1873       (setq flymake-mode-line-e-w e-w))
1874     (when status
1875       (setq flymake-mode-line-status status))
1876     (let* ((mode-line " Φ"))
1877       (when (> (length flymake-mode-line-e-w) 0)
1878         (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
1879       (setq mode-line (concat mode-line flymake-mode-line-status))
1880       (setq flymake-mode-line mode-line)
1881       (force-mode-line-update)))
1882
1883   ; load sql-indent when sql is loaded
1884   (eval-after-load "sql"
1885     '(load-library "sql-indent"))
1886
1887   ; fix up tmux xterm keys
1888   ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
1889   (defun fix-up-tmux-keys ()
1890       "Fix up tmux xterm keys"
1891       (if (getenv "TMUX")
1892           (progn
1893             (let ((x 2) (tkey ""))
1894               (while (<= x 8)
1895                 ;; shift
1896                 (if (= x 2)
1897                     (setq tkey "S-"))
1898                 ;; alt
1899                 (if (= x 3)
1900                     (setq tkey "M-"))
1901                 ;; alt + shift
1902                 (if (= x 4)
1903                     (setq tkey "M-S-"))
1904                 ;; ctrl
1905                 (if (= x 5)
1906                     (setq tkey "C-"))
1907                 ;; ctrl + shift
1908                 (if (= x 6)
1909                     (setq tkey "C-S-"))
1910                 ;; ctrl + alt
1911                 (if (= x 7)
1912                     (setq tkey "C-M-"))
1913                 ;; ctrl + alt + shift
1914                 (if (= x 8)
1915                     (setq tkey "C-M-S-"))
1916
1917                 ;; arrows
1918                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
1919                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
1920                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
1921                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
1922                 ;; home
1923                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
1924                 ;; end
1925                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
1926                 ;; page up
1927                 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
1928                 ;; page down
1929                 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
1930                 ;; insert
1931                 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
1932                 ;; delete
1933                 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
1934                 ;; f1
1935                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
1936                 ;; f2
1937                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
1938                 ;; f3
1939                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
1940                 ;; f4
1941                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
1942                 ;; f5
1943                 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
1944                 ;; f6
1945                 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
1946                 ;; f7
1947                 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
1948                 ;; f8
1949                 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
1950                 ;; f9
1951                 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
1952                 ;; f10
1953                 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
1954                 ;; f11
1955                 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
1956                 ;; f12
1957                 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
1958                 ;; f13
1959                 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
1960                 ;; f14
1961                 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
1962                 ;; f15
1963                 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
1964                 ;; f16
1965                 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
1966                 ;; f17
1967                 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
1968                 ;; f18
1969                 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
1970                 ;; f19
1971                 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
1972                 ;; f20
1973                 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
1974
1975                 (setq x (+ x 1))
1976                 ))
1977             )
1978         )
1979       )
1980   ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
1981
1982   ; procmailmode configuration
1983   (load "procmail_mode")
1984
1985   (load "mode-line-cleaner")
1986
1987   (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
1988     "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
1989     (if (or (buffer-modified-p)
1990             (verify-visited-file-modtime)
1991             (< (* 8 1024 1024) (buffer-size))
1992             (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
1993         ad-do-it
1994       (clear-visited-file-modtime)
1995       (not-modified)))
1996   (ad-activate 'ask-user-about-supersession-threat)
1997
1998   ; apparently things like to step on C-;, so we'll use a hack from
1999   ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
2000
2001   (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
2002
2003   ; use iedit everywhere
2004   (define-key my-keys-minor-mode-map (kbd "C-;") 'mc/mark-all-dwim)
2005
2006   (define-minor-mode my-keys-minor-mode
2007     "A minor mode so that my key settings override annoying major modes."
2008     t " my-keys" 'my-keys-minor-mode-map)
2009
2010   (my-keys-minor-mode 1)
2011   (defun my-minibuffer-setup-hook ()
2012     (my-keys-minor-mode 0))
2013
2014   (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
2015   (defadvice load (after give-my-keybindings-priority)
2016     "Try to ensure that my keybindings always have priority."
2017     (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
2018         (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
2019           (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
2020           (add-to-list 'minor-mode-map-alist mykeys))))
2021   (ad-activate 'load)
2022   (global-set-key "\M- " 'hippie-expand)
2023
2024 #+END_SRC
2025
2026 * END
2027 #+BEGIN_SRC emacs-lisp
2028   (provide 'don-configuration)
2029 #+END_SRC