1 #+PROPERTY: header-args:emacs-lisp :tangle don-configuration.el
4 # if for some reason, things get pear-shaped, we want to be able to
5 # enter the debugger by sending -USR2 to emacs
8 (setq debug-on-event 'siguser2)
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")
20 ** package repositories and package manager
21 Borrowed from https://github.com/nilcons/emacs-use-package-fast/ to
22 load use-package even faster
23 #+BEGIN_SRC emacs-lisp
24 (setq package-enable-at-startup nil)
25 (setq package--init-file-ensured t)
27 (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
28 (mapc #'(lambda (add) (add-to-list 'load-path add))
31 (unless (package-installed-p 'use-package)
32 (package-refresh-contents)
33 (package-install 'use-package))
34 (setq use-package-always-ensure t)
35 (let ((package-user-dir-real (file-truename package-user-dir)))
36 ;; The reverse is necessary, because outside we mapc
37 ;; add-to-list element-by-element, which reverses.
38 (nreverse (apply #'nconc
39 ;; Only keep package.el provided loadpaths.
40 (mapcar #'(lambda (path)
41 (if (string-prefix-p package-user-dir-real path)
46 (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
47 ("melpa" . "https://melpa.org/packages/")
48 ("org" . "http://orgmode.org/elpa/") ))
50 ** [[https://github.com/jwiegley/use-package/][use-package]]
51 #+BEGIN_SRC emacs-lisp
54 (unless (package-installed-p 'use-package)
55 (package-refresh-contents)
56 (package-install 'use-package))
57 (require 'use-package))
60 #+BEGIN_SRC emacs-lisp
66 #+BEGIN_SRC emacs-lisp
67 ;; Set the custom file to /dev/null and don't bother to load it
68 (setq custom-file "/dev/null")
72 #+BEGIN_SRC emacs-lisp
73 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
74 ;; execute conditional code when loading libraries
75 (defmacro with-library (symbol &rest body)
76 `(when (require ,symbol nil t)
78 (put 'with-library 'lisp-indent-function 1)
82 ** Safe Local Variables
83 #+BEGIN_SRC emacs-lisp
84 (setq safe-local-variable-values
85 (quote ((auto-save-default)
87 (cperl-indent-level . 4)
89 (indent-tabs-mode . f)
93 #+BEGIN_SRC emacs-lisp
94 (setq global-mark-ring-max 128
98 (defun don/minibuffer-setup-hook ()
99 (setq gc-cons-threshold most-positive-fixnum))
101 (defun don/minibuffer-exit-hook ()
102 (setq gc-cons-threshold 1048576))
104 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
105 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
109 #+BEGIN_SRC emacs-lisp
110 (use-package flyspell
112 :diminish flyspell-mode 🐝
114 (add-hook 'text-mode-hook 'turn-on-flyspell)
115 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
116 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
117 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
119 (setq ispell-program-name "ispell")
124 #+BEGIN_SRC emacs-lisp
129 #+BEGIN_SRC emacs-lisp
130 ;; (use-package eyebrowse
132 ;; :diminish eyebrowse-mode
133 ;; :init (setq eyebrowse-keymap-prefix (kbd "C-c C-\\"))
135 ;; (setq eyebrowse-wrap-around t)
136 ;; (eyebrowse-mode t)
138 ;; (defun my/eyebrowse-new-window-config ()
142 ;; ;; start at 1 run till 0
143 ;; (let ((j (mod (+ i 1) 10)))
144 ;; (when (and (not done)
145 ;; (not (eyebrowse--window-config-present-p j)))
146 ;; (eyebrowse-switch-to-window-config j)
147 ;; (call-interactively 'eyebrowse-rename-window-config2 j)
152 ;; ;; I don't use latex-preview-pane
153 ;; ;; (require 'latex-preview-pane)
154 ;; ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
155 ;; ;; ;; latex-preview-pane uses window-parameters which are
156 ;; ;; ;; not preserved by eyebrowse, so we close the preview
157 ;; ;; ;; pane before switching, it will be regenerated when we
158 ;; ;; ;; edit the TeX file.
159 ;; ;; (when (lpp/window-containing-preview)
160 ;; ;; (delete-window (lpp/window-containing-preview))))
162 ;; ;; (add-to-list 'eyebrowse-pre-window-switch-hook
163 ;; ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
165 ;; ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
166 ;; ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
167 ;; ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
168 ;; ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
169 ;; ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
177 #+BEGIN_SRC emacs-lisp
178 (defun my/vsplit-last-buffer ()
179 "Split the window vertically and display the previous buffer."
181 (split-window-vertically)
183 (switch-to-next-buffer))
185 (defun my/hsplit-last-buffer ()
186 "Split the window horizontally and display the previous buffer."
188 (split-window-horizontally)
190 (switch-to-next-buffer))
192 (bind-key "C-x 2" 'my/vsplit-last-buffer)
193 (bind-key "C-x 3" 'my/hsplit-last-buffer)
195 (setq split-width-threshold 100)
196 (setq split-height-threshold 60)
198 (defun my/split-window-prefer-vertically (window)
199 "If there's only one window (excluding any possibly active
200 minibuffer), then split the current window horizontally."
201 (if (and (one-window-p t)
202 (not (active-minibuffer-window))
203 ( < (frame-width) (frame-height))
205 (let ((split-width-threshold nil))
206 (split-window-sensibly window))
207 (split-window-sensibly window)))
209 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
210 (setq window-combination-resize t)
213 *** Compilation window
215 If there is no compilation window, open one at the bottom, spanning
216 the complete width of the frame. Otherwise, reuse existing window. In
217 the former case, if there was no error the window closes
220 #+BEGIN_SRC emacs-lisp
221 (add-to-list 'display-buffer-alist
222 `(,(rx bos "*compilation*" eos)
223 (display-buffer-reuse-window
224 display-buffer-in-side-window)
225 (reusable-frames . visible)
227 (window-height . 0.4)))
230 #+BEGIN_SRC emacs-lisp
231 (defun my/compilation-exit-autoclose (status code msg)
232 ;; If M-x compile exists with a 0
233 (when (and (eq status 'exit) (zerop code))
234 ;; and delete the *compilation* window
235 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
236 (when (and (not (window-at-side-p compilation-window 'top))
237 (window-at-side-p compilation-window 'left)
238 (window-at-side-p compilation-window 'right))
239 (delete-window compilation-window))))
240 ;; Always return the anticipated result of compilation-exit-message-function
243 ;; Specify my function (maybe I should have done a lambda function)
244 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
247 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
248 value, the compilation buffer scrolls automatically to follow the
249 output. If the value is ~first-error~, scrolling stops when the first
250 error appears, leaving point at that error. For any other non-nil
251 value, scrolling continues until there is no more output.
253 #+BEGIN_SRC emacs-lisp
254 (setq compilation-scroll-output 'first-error)
257 ** Mode line cleaning
259 #+BEGIN_SRC emacs-lisp
260 (use-package diminish
265 #+BEGIN_SRC emacs-lisp
272 #+BEGIN_SRC emacs-lisp
275 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
276 ("C-c j j" . avy-goto-word-or-subword-1)
277 ("M-g g" . avy-goto-line))
278 :config (progn (setq avy-background t))
281 *** Ace-link (jumping to links)
282 #+BEGIN_SRC emacs-lisp
283 (use-package ace-link
285 ; bind o in most modes
286 :config (ace-link-setup-default))
288 *** Jumping through edit points (goto-chg)
289 #+BEGIN_SRC emacs-lisp
290 (use-package goto-chg
292 :bind (("C-c j ," . goto-last-change)
293 ("C-c j ." . goto-last-change-reverse))
296 *** Jumping to bookmarks (visible bookmarks, bm)
297 #+BEGIN_SRC emacs-lisp
300 :bind (("C-c j b ." . bm-next)
301 ("C-c j b ," . bm-previous)
302 ("C-c j b SPC" . bm-toggle)))
307 #+BEGIN_SRC emacs-lisp
308 (use-package yasnippet
310 :diminish yas-minor-mode
313 (setq yas-verbosity 1)
314 (define-key yas-minor-mode-map (kbd "<tab>") nil)
315 (define-key yas-minor-mode-map (kbd "TAB") nil)
316 (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
317 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
318 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
319 (add-to-list 'hippie-expand-try-functions-list
320 'yas-hippie-try-expand)
325 #+BEGIN_SRC emacs-lisp
326 (use-package auto-yasnippet
327 :bind (("H-w" . aya-create)
334 #+BEGIN_SRC emacs-lisp
336 (use-package tinyprocmail
338 :config (with-library 'tinyprocmail
339 ;; (setq tinyprocmail--procmail-version "v3.22")
340 (add-hook 'tinyprocmail--load-hook 'tinyprocmail-install))
345 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
348 :bind (("C-x g" . magit-status)
349 ("C-x C-g" . magit-status))
351 ;; don't verify where we are pushing
352 (setq magit-push-always-verify nil)
353 ;; refine diffs always (hilight words)
354 (setq magit-diff-refine-hunk nil)
357 (append '("~/lib/emacs_el/magit-annex")
361 (append '("~/lib/emacs_el/magit-vcsh")
364 (use-package magit-annex
367 (use-package magit-vcsh
368 :ensure f ; currently not in melpa, so don't try to install
373 #+BEGIN_SRC emacs-lisp
374 (use-package cperl-mode
377 ;; Use c-mode for perl .xs files
378 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
379 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
380 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
381 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
382 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
385 cperl-auto-newline nil
386 cperl-auto-newline-after-colon nil
387 cperl-continued-statement-offset 4
388 cperl-brace-offset -1
389 cperl-continued-brace-offset 0
390 cperl-label-offset -4
391 cperl-highlight-variables-indiscriminately t
392 cperl-electric-lbrace-space nil
393 cperl-indent-parens-as-block nil
394 cperl-close-paren-offset -1
395 cperl-tab-always-indent t)
396 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
401 #+BEGIN_SRC emacs-lisp
406 (define-key global-map [remap find-file] 'helm-find-files)
407 (define-key global-map [remap occur] 'helm-occur)
408 (define-key global-map [remap list-buffers] 'helm-buffers-list)
409 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
410 (global-set-key (kbd "M-x") 'helm-M-x)
411 (unless (boundp 'completion-in-region-function)
412 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
413 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
414 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
419 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
421 #+BEGIN_SRC emacs-lisp
422 (use-package helm-flx
425 ;; these are helm configs, but they kind of fit here nicely
426 (setq helm-M-x-fuzzy-match t
427 helm-bookmark-show-location t
428 helm-buffers-fuzzy-matching t
429 helm-completion-in-region-fuzzy-match t
430 helm-file-cache-fuzzy-match t
431 helm-imenu-fuzzy-match t
432 helm-mode-fuzzy-match t
433 helm-locate-fuzzy-match nil
435 helm-recentf-fuzzy-match nil
436 helm-semantic-fuzzy-match t)
440 #+BEGIN_SRC emacs-lisp
442 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
443 (defun malb/helm-swoop-pre-fill ()
444 (thing-at-point 'symbol))
445 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
446 paradox-menu-mode doc-view-mode pdf-view-mode
447 mu4e-headers-mode org-mode markdown-mode latex-mode
448 ein:notebook-multilang-mode))
450 (defun malb/swoop-or-search ()
452 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
453 (memq major-mode malb/helm-swoop-ignore-major-mode))
457 (use-package helm-swoop
459 :bind (("C-c o" . helm-multi-swoop-org)
460 ("C-s" . malb/swoop-or-search)
461 ("C-M-s" . helm-multi-swoop-all))
464 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
465 helm-swoop-split-with-multiple-windows nil
466 helm-swoop-split-direction #'split-window-horizontally
467 helm-swoop-split-window-function 'helm-default-display-buffer
468 helm-swoop-speed-or-color t)
470 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
471 (defun malb/helm-swoop-C-s ()
473 (if (boundp 'helm-swoop-pattern)
474 (if (equal helm-swoop-pattern "")
475 (previous-history-element 1)
479 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
480 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
481 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
482 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
483 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
484 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
489 #+BEGIN_SRC emacs-lisp
492 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
493 helm-ag-command-option "--all-text"
494 helm-ag-insert-at-point 'symbol
495 helm-ag-fuzzy-match t
496 helm-ag-use-temp-buffer t
497 helm-ag-use-grep-ignore-list t
498 helm-ag-use-agignore t))
501 #+BEGIN_SRC emacs-lisp
502 (use-package helm-descbinds
504 :bind ("C-h b" . helm-descbinds)
505 :init (fset 'describe-bindings 'helm-descbinds))
509 #+BEGIN_SRC emacs-lisp
510 (use-package helm-c-yasnippet
512 :bind ("C-c h y" . helm-yas-complete)
514 (setq helm-yas-space-match-any-greedy t)))
517 #+BEGIN_SRC emacs-lisp
518 (use-package helm-org-rifle
521 (defun malb/helm-org-rifle-agenda-files (arg)
523 (let ((current-prefix-arg nil))
525 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
526 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
527 (t (helm-org-agenda-files-headings)))))))
530 This can be used to link things pretty quickly if necessary
531 #+BEGIN_SRC emacs-lisp
532 (use-package helm-google
534 :bind ("C-c h g" . helm-google)
536 (progn (add-to-list 'helm-google-actions
537 '("Copy URL" . (lambda (candidate)
539 (replace-regexp-in-string
540 "https://.*q=\\(.*\\)\&sa=.*"
546 (add-to-list 'helm-google-actions
547 '("Org Store Link" . (lambda (candidate)
548 (let ((title (car (split-string candidate "[\n]+")))
550 (replace-regexp-in-string
551 "https://.*q=\\(.*\\)\&sa=.*"
553 (push (list url title) org-stored-links))))
558 #+BEGIN_SRC emacs-lisp
561 :bind ("M-z" . avy-zap-up-to-char-dwim))
564 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
569 #+BEGIN_SRC emacs-lisp
570 (add-to-list 'tramp-methods '("vcsh"
571 (tramp-login-program "vcsh")
575 (tramp-remote-shell "/bin/sh")
576 (tramp-remote-shell-args
580 #+BEGIN_SRC emacs-lisp
584 (setq-default reftex-default-bibliography
585 '("~/projects/research/references.bib")))
588 #+BEGIN_SRC emacs-lisp
590 :config (setq bibtex-user-optional-fields
591 (quote (("annote" "Personal annotation (ignored)")
599 #+BEGIN_SRC emacs-lisp
604 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
605 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
606 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
607 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
608 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
609 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
610 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
611 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
612 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
613 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
614 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
616 (setq-default reftex-plug-into-AUCTeX t)
617 ;; support fake section headers
618 (setq TeX-outline-extra
624 ;; add font locking to the headers
625 (font-lock-add-keywords
627 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
628 0 'font-lock-keyword-face t)
629 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
630 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
631 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
632 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
633 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
635 ;; use smart quotes by default instead of `` and ''
636 ;; taken from http://kieranhealy.org/esk/kjhealy.html
637 (setq TeX-open-quote "“")
638 (setq TeX-close-quote "”")
640 ;; (TeX-add-style-hook
645 ;; (custom-set-variables
646 ;; '(font-latex-user-keyword-classes
649 ;; font-lock-function-name-face 2 (command 1 t))))
651 (setq-default TeX-parse-self t)
652 (setq-default TeX-auto-save t)
653 (setq-default TeX-master nil)
659 (if (boundp 'reftex-ref-style-alist)
661 'reftex-ref-style-alist
662 '("Cleveref" "cleveref"
663 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
664 (reftex-ref-style-activate "Cleveref")
666 '("cref" TeX-arg-ref)
667 '("Cref" TeX-arg-ref)
668 '("cpageref" TeX-arg-ref)
669 '("Cpageref" TeX-arg-ref)))))
672 '(add-to-list 'LaTeX-fill-excluded-macros
675 (use-package font-latex
677 (setq font-latex-match-reference-keywords
699 (setq font-latex-fontify-script nil)
700 (setq font-latex-fontify-sectioning (quote color))
701 (setq font-latex-script-display (quote (nil)))
706 #+BEGIN_SRC emacs-lisp
710 (defun ess-change-directory (path)
711 "Set the current working directory to PATH for both *R* and Emacs."
712 (interactive "DDirectory to change to: ")
714 (when (file-exists-p path)
715 (ess-command (concat "setwd(\"" path "\")\n"))
716 ;; use file-name-as-directory to ensure it has trailing /
717 (setq default-directory (file-name-as-directory path))))
718 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
719 ;; outlining support for ess modes
724 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
725 (defun outline-level ()
726 (cond ((looking-at "^##### ") 1)
727 ((looking-at "^#### ") 2)
728 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
731 (add-hook 'ess-mode-hook
733 (local-set-key (kbd "C-c C-R")
734 'dla/ess-region-remote-eval)))
736 ;; Don't restore history or save workspace image
737 '(inferior-R-args "--no-restore-history --no-save")
742 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
744 #+BEGIN_SRC emacs-lisp
745 (use-package rainbow-mode
746 ;; add ess to the x major mode
747 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
748 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
753 #+BEGIN_SRC emacs-lisp
754 (use-package polymode
757 (use-package poly-noweb)
758 (use-package poly-markdown)
759 :mode ("\\.Snw" . poly-noweb+r-mode)
760 :mode ("\\.Rnw" . poly-noweb+r-mode)
761 :mode ("\\.Rmd" . poly-markdown+r-mode)
767 #+BEGIN_SRC emacs-lisp
768 (use-package outline-magic)
771 #+BEGIN_SRC emacs-lisp
772 (use-package writeroom-mode
774 (defun my/writing-mode ()
775 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
780 (visual-line-mode -1)
782 (visual-fill-column-mode -1)
786 (visual-fill-column-mode 1)
791 ** GhostText/Atomic Chrome
792 #+BEGIN_SRC emacs-lisp
793 (use-package atomic-chrome
795 (ignore-errors (atomic-chrome-start-server))
796 (setq atomic-chrome-buffer-open-style 'full)
801 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
803 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
804 #+BEGIN_SRC emacs-lisp
805 (use-package multiple-cursors
806 :bind (("C-;" . mc/mark-all-dwim)
807 ("C-<" . mc/mark-previous-like-this)
808 ("C->" . mc/mark-next-like-this)
809 ("C-S-c C-S-c" . mc/edit-lines))
813 #+BEGIN_SRC emacs-lisp
814 (use-package web-mode
816 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
817 (setq web-mode-enable-engine-detection t)
818 (setq web-mode-engines-alist
819 '(("template-toolkit" . "\\.tmpl\\'")))
824 #+BEGIN_SRC emacs-lisp
827 (setq post-email-address "don@donarmstrong.com")
828 (setq post-kill-quoted-sig nil)
829 (setq post-mail-message "mutt\\(ng\\|\\)-[a-z0-9]+-[0-9]+-.*")
830 (setq post-uses-fill-mode nil)
835 #+BEGIN_SRC emacs-lisp
838 :mode "muttng-[a-z0-9]+-[0-9]+-"
839 :mode "mutt-[a-z0-9]+-[0-9]+-"
840 :hook 'my/message-mode-settings
841 :hook 'turn-on-flyspell
842 :bind (:map message-mode-map
843 ("C-c C-a" . my/post-attach-file))
845 (defun my/message-mode-settings ()
846 (font-lock-add-keywords nil
847 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
848 (0 'message-multiply-quoted-text-face))
849 ("^[ \t]*>[ \t]*>.*$"
850 (0 'message-double-quoted-text-face))))
853 (defun my/post-attach-file ()
854 "Prompt for an attachment."
856 (let ((file (read-file-name "Attach file: " nil nil t nil))
857 (description (string-read "Description: ")))
858 (my/header-attach-file file description)))
860 (defun my/header-attach-file (file description)
861 "Attach a FILE to the current message (works with Mutt).
862 Argument DESCRIPTION MIME description."
863 (interactive "fAttach file: \nsDescription: ")
864 (when (> (length file) 0)
869 (goto-char (point-min))
870 (search-forward-regexp "^$")
871 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
873 (message (concat "Attached '" file "'."))
874 (setq post-has-attachment t))))))
876 (setq mail-yank-prefix "> ")
880 #+BEGIN_SRC emacs-lisp
881 (use-package muttrc-mode
889 #+BEGIN_SRC emacs-lisp
890 (setq global-auto-revert-non-file-buffers t
891 global-auto-revert-ignore-modes '(pdf-view-mode)
892 auto-revert-verbose nil)
893 (global-auto-revert-mode 1)
896 ** Use-package and load things
897 #+BEGIN_SRC emacs-lisp
903 ** Agenda Configuration
904 #+BEGIN_SRC emacs-lisp
905 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
906 :bind (("C-c l" . org-store-link)
907 ("C-c a" . org-agenda)
908 ("C-c b" . org-iswitchb))
910 (setq-default org-log-done 'time)
911 (setq-default org-agenda-ndays 5)
913 ;; agenda configuration
914 ;; Do not dim blocked tasks
915 (setq org-agenda-dim-blocked-tasks nil)
916 (setq org-agenda-inhibit-startup t)
917 (setq org-agenda-use-tag-inheritance nil)
919 ;; Compact the block agenda view
920 (setq org-agenda-compact-blocks t)
922 ;; Custom agenda command definitions
923 (setq org-agenda-custom-commands
924 (quote (("N" "Notes" tags "NOTE"
925 ((org-agenda-overriding-header "Notes")
926 (org-tags-match-list-sublevels t)))
927 ("h" "Habits" tags-todo "STYLE=\"habit\""
928 ((org-agenda-overriding-header "Habits")
929 (org-agenda-sorting-strategy
930 '(todo-state-down effort-up category-keep))))
934 ((org-agenda-overriding-header "Tasks to Refile")
935 (org-tags-match-list-sublevels nil)))
936 (tags-todo "-CANCELLED/!"
937 ((org-agenda-overriding-header "Stuck Projects")
938 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
939 (org-agenda-sorting-strategy
941 (tags-todo "-HOLD-CANCELLED/!"
942 ((org-agenda-overriding-header "Projects")
943 (org-agenda-skip-function 'bh/skip-non-projects)
944 (org-tags-match-list-sublevels 'indented)
945 (org-agenda-sorting-strategy
947 (tags-todo "-CANCELLED/!NEXT"
948 ((org-agenda-overriding-header (concat "Project Next Tasks"
949 (if bh/hide-scheduled-and-waiting-next-tasks
951 " (including WAITING and SCHEDULED tasks)")))
952 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
953 (org-tags-match-list-sublevels t)
954 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
955 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
956 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
957 (org-agenda-sorting-strategy
958 '(todo-state-down effort-up category-keep))))
959 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
960 ((org-agenda-overriding-header (concat "Project Subtasks"
961 (if bh/hide-scheduled-and-waiting-next-tasks
963 " (including WAITING and SCHEDULED tasks)")))
964 (org-agenda-skip-function 'bh/skip-non-project-tasks)
965 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
966 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
967 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
968 (org-agenda-sorting-strategy
970 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
971 ((org-agenda-overriding-header (concat "Standalone Tasks"
972 (if bh/hide-scheduled-and-waiting-next-tasks
974 " (including WAITING and SCHEDULED tasks)")))
975 (org-agenda-skip-function 'bh/skip-project-tasks)
976 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
977 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
978 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
979 (org-agenda-sorting-strategy
981 (tags-todo "-CANCELLED+WAITING|HOLD/!"
982 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
983 (org-agenda-skip-function 'bh/skip-stuck-projects)
984 (org-tags-match-list-sublevels nil)
985 (org-agenda-todo-ignore-scheduled t)
986 (org-agenda-todo-ignore-deadlines t)))
988 ((org-agenda-overriding-header "Tasks to Archive")
989 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
990 (org-tags-match-list-sublevels nil))))
993 ; org mode agenda files
994 (setq org-agenda-files
995 (quote ("~/projects/org-notes/debbugs.org"
996 "~/projects/org-notes/notes.org"
997 "~/projects/org-notes/holidays.org"
998 "~/projects/org-notes/refile.org"
999 "~/projects/org-notes/diary.org"
1000 "~/projects/org-notes/ool.org"
1001 "~/projects/org-notes/sndservers.org"
1002 "~/projects/org-notes/chaim.org"
1003 "~/projects/org-notes/wildman.org"
1004 "~/projects/org-notes/uddin.org"
1005 "~/projects/org-notes/reviews.org"
1006 "~/org-mode/from-mobile.org"
1007 "~/projects/org-notes/fh.org")))
1009 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1010 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
1011 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1012 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1013 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1014 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1015 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1016 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1017 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1018 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1019 (defun org-agenda-timeline-all (&optional arg)
1022 (dolist (org-agenda-file org-agenda-files)
1023 (insert-file-contents org-agenda-file nil)
1026 (write-file "/tmp/timeline.org")
1027 (org-agenda arg "L")))
1028 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1032 #+BEGIN_SRC emacs-lisp
1033 (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")))
1034 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1036 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1037 (setq org-id-link-to-org-use-id 'use-existing)
1039 ** Capture Templates
1040 #+BEGIN_SRC emacs-lisp
1041 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1042 '(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
1043 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1044 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
1045 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1046 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
1047 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1048 ("n" "note" entry (file "~/projects/org-notes/refile.org")
1049 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1050 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
1051 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1052 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1053 "* %?\n%U\n" :clock-in t :clock-resume t)
1054 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
1055 "* TODO Review %c\n%U\n" :immediate-finish t)
1056 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
1057 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1058 ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
1059 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1060 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1061 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1062 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
1063 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1064 ("J" "job" entry (file "~/projects/org-notes/refile.org")
1065 "* 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)
1066 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
1067 "* 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")
1071 ;; Remove empty LOGBOOK drawers on clock out
1072 (defun bh/remove-empty-drawer-on-clock-out ()
1075 (beginning-of-line 0)
1076 (org-remove-empty-drawer-at (point))))
1078 (defun my/org-add-id ()
1081 (if (org-current-level)
1090 ** Org mode key bindings
1091 #+BEGIN_SRC emacs-lisp
1092 ; org mode configuration from http://doc.norang.ca/org-mode.html
1093 ;; Custom Key Bindings
1094 (global-set-key (kbd "<f12>") 'org-agenda)
1095 (global-set-key (kbd "<f5>") 'bh/org-todo)
1096 (global-set-key (kbd "<S-f5>") 'bh/widen)
1097 (global-set-key (kbd "<f7>") 'bh/set-truncate-lines)
1098 (global-set-key (kbd "<f8>") 'org-cycle-agenda-files)
1099 (global-set-key (kbd "<f9> <f9>") 'bh/show-org-agenda)
1100 (global-set-key (kbd "<f9> b") 'bbdb)
1101 (global-set-key (kbd "<f9> c") 'calendar)
1102 (global-set-key (kbd "<f9> f") 'boxquote-insert-file)
1103 (global-set-key (kbd "<f9> h") 'bh/hide-other)
1104 (global-set-key (kbd "<f9> n") 'bh/toggle-next-task-display)
1105 (global-set-key (kbd "<f9> w") 'widen)
1107 ; change the outline mode prefix from C-c @ to C-c C-2
1108 (setq outline-minor-mode-prefix "C-c C-2")
1109 ;(add-hook 'outline-minor-mode-hook
1110 ; (lambda () (local-set-key (kbd "C-c C-2")
1111 ; outline-mode-prefix-map)))
1113 (global-set-key (kbd "<f9> I") 'bh/punch-in)
1114 (global-set-key (kbd "<f9> O") 'bh/punch-out)
1116 (global-set-key (kbd "<f9> o") 'bh/make-org-scratch)
1118 (global-set-key (kbd "<f9> r") 'boxquote-region)
1119 (global-set-key (kbd "<f9> s") 'bh/switch-to-scratch)
1121 (global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
1122 (global-set-key (kbd "<f9> T") 'bh/toggle-insert-inactive-timestamp)
1124 (global-set-key (kbd "<f9> v") 'visible-mode)
1125 (global-set-key (kbd "<f9> l") 'org-toggle-link-display)
1126 (global-set-key (kbd "<f9> SPC") 'bh/clock-in-last-task)
1127 (global-set-key (kbd "C-<f9>") 'previous-buffer)
1128 (global-set-key (kbd "M-<f9>") 'org-toggle-inline-images)
1129 (global-set-key (kbd "C-x n r") 'narrow-to-region)
1130 (global-set-key (kbd "C-<f10>") 'next-buffer)
1131 (global-set-key (kbd "<f11>") 'org-clock-goto)
1132 (global-set-key (kbd "C-<f11>") 'org-clock-in)
1133 (global-set-key (kbd "C-s-<f12>") 'bh/save-then-publish)
1134 (global-set-key (kbd "C-c c") 'org-capture)
1137 ** Utility Functions
1138 #+BEGIN_SRC emacs-lisp
1139 (defun bh/hide-other ()
1142 (org-back-to-heading 'invisible-ok)
1148 (defun bh/set-truncate-lines ()
1149 "Toggle value of truncate-lines and refresh window display."
1151 (setq truncate-lines (not truncate-lines))
1152 ;; now refresh window display (an idiom from simple.el):
1154 (set-window-start (selected-window)
1155 (window-start (selected-window)))))
1157 (defun bh/make-org-scratch ()
1159 (find-file "/tmp/publish/scratch.org")
1160 (gnus-make-directory "/tmp/publish"))
1162 (defun bh/switch-to-scratch ()
1164 (switch-to-buffer "*scratch*"))
1166 (setq org-use-fast-todo-selection t)
1167 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1169 ; create function to create headlines in file. This comes from
1170 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1171 (defun my/org-add-ids-to-headlines-in-file ()
1172 "Add ID properties to all headlines in the current file which
1173 do not already have one."
1175 (org-map-entries 'org-id-get-create))
1176 ; if we wanted to do this to every buffer, do the following:
1177 ; (add-hook 'org-mode-hook
1179 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1182 #+BEGIN_SRC emacs-lisp
1183 (setq org-todo-keywords
1184 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1185 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1187 (setq org-todo-keyword-faces
1188 (quote (("TODO" :foreground "red" :weight bold)
1189 ("NEXT" :foreground "blue" :weight bold)
1190 ("DONE" :foreground "forest green" :weight bold)
1191 ("WAITING" :foreground "orange" :weight bold)
1192 ("HOLD" :foreground "magenta" :weight bold)
1193 ("CANCELLED" :foreground "forest green" :weight bold)
1194 ("MEETING" :foreground "forest green" :weight bold)
1195 ("PHONE" :foreground "forest green" :weight bold))))
1197 (setq org-todo-state-tags-triggers
1198 (quote (("CANCELLED" ("CANCELLED" . t))
1199 ("WAITING" ("WAITING" . t))
1200 ("HOLD" ("WAITING") ("HOLD" . t))
1201 (done ("WAITING") ("HOLD"))
1202 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1203 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1204 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1208 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1209 ; add ids on creation of nodes
1210 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1213 ; resolve clocks after 10 minutes of idle; use xprintidle
1214 ; (setq org-clock-idle-time 10)
1215 ; (setq org-clock-x11idle-program-name "xprintidle")
1217 ; this is from http://doc.norang.ca/org-mode.html#Capture
1218 ; use C-M-r for org mode capture
1219 (global-set-key (kbd "C-M-r") 'org-capture)
1221 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1222 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1223 (org-agenda-files :maxlevel . 9))))
1225 ; Use full outline paths for refile targets - we file directly with IDO
1226 (setq org-refile-use-outline-path t)
1228 ; Targets complete directly with IDO
1229 (setq org-outline-path-complete-in-steps nil)
1231 ; Allow refile to create parent tasks with confirmation
1232 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1234 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1235 ; (setq org-completion-use-ido t)
1236 ; (setq ido-everywhere t)
1237 ; (setq ido-max-directory-size 100000)
1238 ; (ido-mode (quote both))
1239 ; ; Use the current window when visiting files and buffers with ido
1240 ; (setq ido-default-file-method 'selected-window)
1241 ; (setq ido-default-buffer-method 'selected-window)
1242 ; ; Use the current window for indirect buffer display
1243 ; (setq org-indirect-buffer-display 'current-window)
1246 ;;;; Refile settings
1247 ; Exclude DONE state tasks from refile targets
1248 (defun bh/verify-refile-target ()
1249 "Exclude todo keywords with a done state from refile targets"
1250 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1252 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1254 ;; ensure that emacsclient will show just the note to be edited when invoked
1255 ;; from Mutt, and that it will shut down emacsclient once finished;
1256 ;; fallback to legacy behavior when not invoked via org-protocol.
1257 (require 'org-protocol)
1258 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1259 (setq my-org-protocol-flag nil)
1260 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1261 "Delete frame at remember finalization"
1262 (progn (if my-org-protocol-flag (delete-frame))
1263 (setq my-org-protocol-flag nil)))
1264 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1265 "Delete frame at remember refile"
1266 (if my-org-protocol-flag
1268 (setq my-org-protocol-flag nil)
1273 (defadvice org-capture-kill (after delete-frame-at-end activate)
1274 "Delete frame at remember abort"
1275 (progn (if my-org-protocol-flag (delete-frame))
1276 (setq my-org-protocol-flag nil)))
1277 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1278 (setq my-org-protocol-flag t))
1280 (defadvice org-insert-todo-heading (after dla/create-id activate)
1285 (add-to-list 'org-modules 'org-habit)
1287 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1288 (defun open-mail-in-mutt (message)
1289 "Open a mail message in Mutt, using an external terminal.
1291 Message can be specified either by a path pointing inside a
1292 Maildir, or by Message-ID."
1293 (interactive "MPath or Message-ID: ")
1295 (format "faf xterm -e \"%s %s\""
1296 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1298 ;; add support for "mutt:ID" links
1299 (org-add-link-type "mutt" 'open-mail-in-mutt)
1301 (defun my-org-mode-setup ()
1302 ; (load-library "reftex")
1303 (and (buffer-file-name)
1304 (file-exists-p (buffer-file-name))
1306 ; (reftex-parse-all)
1307 (reftex-set-cite-format
1308 '((?b . "[[bib:%l][%l-bib]]")
1309 (?n . "[[notes:%l][%l-notes]]")
1311 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1313 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1314 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1315 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1316 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1318 (add-hook 'org-mode-hook 'my-org-mode-setup)
1320 (defun org-mode-reftex-search ()
1322 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1324 (defun open-research-paper (bibtexkey)
1325 "Open a paper by bibtex key"
1326 (interactive "bibtex key: ")
1329 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1330 (org-add-link-type "papers" 'open-research-paper)
1331 (defun open-research-paper-pdf (bibtexkey)
1332 "Open a paper pdf by bibtex key"
1333 (interactive "bibtex key: ")
1335 (format "%s -p evince_annot %s"
1336 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1337 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1339 (add-to-list 'org-link-abbrev-alist
1341 "~/projects/research/paper_notes.org::#%s"))
1343 ; I pretty much always want hiearchical checkboxes
1344 (setq org-hierachical-checkbox-statistics nil)
1346 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1347 (add-to-list 'org-structure-template-alist
1348 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1351 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1352 (defun my-rtcite-export-handler (path desc format)
1353 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1354 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1355 (match-string 1 path)))
1356 (path (substring path 0 (match-beginning 0))))
1357 (cond ((eq format 'latex)
1359 (equal 0 (search "rtcite:" desc)))
1360 (format "\\cite{%s}" search)
1361 (format "\\cite[%s]{%s}" desc search))))))
1363 (org-add-link-type "rtcite"
1365 'my-rtcite-export-handler)
1369 ** Org Mobile Configuration
1370 #+BEGIN_SRC emacs-lisp
1371 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1372 (when (string= system-name "linnode")
1373 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1374 (setq-default org-directory "/home/don/org-mode/")
1375 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1379 #+BEGIN_SRC emacs-lisp
1380 ;; org mode ical export
1381 (setq org-icalendar-timezone "America/Los_Angeles")
1382 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1383 ;; we already add the id manually
1384 (setq org-icalendar-store-UID t)
1387 ** General Org Babel Configuration
1388 #+BEGIN_SRC emacs-lisp
1389 ;; org babel support
1390 (org-babel-do-load-languages
1391 'org-babel-load-languages
1398 ;; use graphviz-dot for dot things
1399 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1400 ;; org-babel-by-backend
1401 (defmacro org-babel-by-backend (&rest body)
1402 `(case (if (boundp 'backend)
1403 (org-export-backend-name backend)
1406 (defun my/fix-inline-images ()
1407 (when org-inline-image-overlays
1408 (org-redisplay-inline-images)))
1410 (add-hook 'org-babel-after-execute-hook
1411 'my/fix-inline-images)
1414 ** LaTeX configuration
1416 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
1418 #+BEGIN_SRC emacs-lisp
1420 (add-to-list 'org-latex-classes
1422 "\\documentclass[11pt,oneside,article]{memoir}\n"
1423 ("\\section{%s}" . "\\section*{%s}")
1424 ("\\subsection{%s}" . "\\subsection*{%s}")
1425 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1426 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1427 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1429 (setq org-beamer-outline-frame-options "")
1430 (add-to-list 'org-latex-classes
1432 "\\documentclass[ignorenonframetext]{beamer}
1433 [NO-DEFAULT-PACKAGES]
1436 ("\\section{%s}" . "\\section*{%s}")
1437 ("\\subsection{%s}" . "\\subsection*{%s}")
1438 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1439 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1440 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1442 (add-to-list 'org-latex-classes
1444 "\\documentclass[11pt,oneside]{memoir}\n"
1445 ("\\chapter{%s}" . "\\chapter*{%s}")
1446 ("\\section{%s}" . "\\section*{%s}")
1447 ("\\subsection{%s}" . "\\subsection*{%s}")
1448 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1450 (add-to-list 'org-latex-classes
1452 "\\documentclass[11pt]{letter}
1453 [NO-DEFAULT-PACKAGES]
1456 ("\\section{%s}" . "\\section*{%s}")
1457 ("\\subsection{%s}" . "\\subsection*{%s}")
1458 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1459 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1460 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1462 (add-to-list 'org-latex-classes
1464 "\\documentclass{dlacv}
1465 [NO-DEFAULT-PACKAGES]
1468 ("\\section{%s}" . "\\section*{%s}")
1469 ("\\subsection{%s}" . "\\subsection*{%s}")
1470 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1471 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1472 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1475 (add-to-list 'org-latex-classes
1477 "\\documentclass{dlaresume}
1478 [NO-DEFAULT-PACKAGES]
1481 ("\\section{%s}" . "\\section*{%s}")
1482 ("\\subsection{%s}" . "\\subsection*{%s}")
1483 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1484 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1485 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1488 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
1489 ;; but adapted to use latexmk 4.22 or higher.
1490 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
1492 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
1493 (setq org-latex-default-packages-alist
1495 ("" "unicode-math" t)
1497 (setq org-latex-packages-alist
1504 ("" "longtable" nil)
1507 ;; make equations larger
1508 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
1510 (defun org-create-formula--latex-header ()
1511 "Return LaTeX header appropriate for previewing a LaTeX snippet."
1512 (let ((info (org-combine-plists (org-export--get-global-options
1513 (org-export-get-backend 'latex))
1514 (org-export--get-inbuffer-options
1515 (org-export-get-backend 'latex)))))
1516 (org-latex-guess-babel-language
1517 (org-latex-guess-inputenc
1518 (org-splice-latex-header
1519 org-format-latex-header
1520 org-latex-default-packages-alist
1522 (plist-get info :latex-header)))
1526 ; support ignoring headers in org mode export to latex
1527 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
1528 (defadvice org-latex-headline (around my-latex-skip-headlines
1529 (headline contents info) activate)
1530 (if (member "ignoreheading" (org-element-property :tags headline))
1531 (setq ad-return-value contents)
1534 ;; keep latex logfiles
1536 (setq org-latex-remove-logfiles nil)
1538 ;; Resume clocking task when emacs is restarted
1539 (org-clock-persistence-insinuate)
1541 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
1542 (setq org-clock-history-length 23)
1543 ;; Resume clocking task on clock-in if the clock is open
1544 (setq org-clock-in-resume t)
1545 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
1546 ;; there are things like PHONE calls
1547 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
1548 ;; Separate drawers for clocking and logs
1549 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
1550 ;; Save clock data and state changes and notes in the LOGBOOK drawer
1551 (setq org-clock-into-drawer t)
1552 (setq org-log-into-drawer t)
1553 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
1554 (setq org-clock-out-remove-zero-time-clocks t)
1555 ;; Clock out when moving task to a done state
1556 (setq org-clock-out-when-done t)
1557 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
1558 (setq org-clock-persist t)
1559 ;; Do not prompt to resume an active clock
1560 (setq org-clock-persist-query-resume nil)
1561 ;; Enable auto clock resolution for finding open clocks
1562 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
1563 ;; Include current clocking task in clock reports
1564 (setq org-clock-report-include-clocking-task t)
1566 ;; the cache seems to be broken
1567 (setq org-element-use-cache nil)
1569 (defvar bh/keep-clock-running nil)
1571 (defun bh/is-task-p ()
1572 "Any task with a todo keyword and no subtask"
1576 (subtree-end (save-excursion (org-end-of-subtree t)))
1577 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1580 (while (and (not has-subtask)
1581 (< (point) subtree-end)
1582 (re-search-forward "^\*+ " subtree-end t))
1583 (when (member (org-get-todo-state) org-todo-keywords-1)
1584 (setq has-subtask t))))
1585 (and is-a-task (not has-subtask)))))
1586 (defun bh/is-project-p ()
1587 "Any task with a todo keyword subtask"
1591 (subtree-end (save-excursion (org-end-of-subtree t)))
1592 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1595 (while (and (not has-subtask)
1596 (< (point) subtree-end)
1597 (re-search-forward "^\*+ " subtree-end t))
1598 (when (member (org-get-todo-state) org-todo-keywords-1)
1599 (setq has-subtask t))))
1600 (and is-a-task has-subtask))))
1602 (defun bh/is-subproject-p ()
1603 "Any task which is a subtask of another project"
1604 (let ((is-subproject)
1605 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1607 (while (and (not is-subproject) (org-up-heading-safe))
1608 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1609 (setq is-subproject t))))
1610 (and is-a-task is-subproject)))
1613 (defun bh/clock-in-to-next (kw)
1614 "Switch a task from TODO to NEXT when clocking in.
1615 Skips capture tasks, projects, and subprojects.
1616 Switch projects and subprojects from NEXT back to TODO"
1617 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
1619 ((and (member (org-get-todo-state) (list "TODO"))
1622 ((and (member (org-get-todo-state) (list "NEXT"))
1626 (defun bh/punch-in (arg)
1627 "Start continuous clocking and set the default task to the
1628 selected task. If no task is selected set the Organization task
1629 as the default task."
1631 (setq bh/keep-clock-running t)
1632 (if (equal major-mode 'org-agenda-mode)
1634 ;; We're in the agenda
1636 (let* ((marker (org-get-at-bol 'org-hd-marker))
1637 (tags (org-with-point-at marker (org-get-tags-at))))
1638 (if (and (eq arg 4) tags)
1639 (org-agenda-clock-in '(16))
1640 (bh/clock-in-organization-task-as-default)))
1642 ;; We are not in the agenda
1646 ; Find the tags on the current task
1647 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
1648 (org-clock-in '(16))
1649 (bh/clock-in-organization-task-as-default)))))
1651 (defun bh/punch-out ()
1653 (setq bh/keep-clock-running nil)
1654 (when (org-clock-is-active)
1656 (org-agenda-remove-restriction-lock))
1658 (defun bh/clock-in-default-task ()
1660 (org-with-point-at org-clock-default-task
1663 (defun bh/clock-in-parent-task ()
1664 "Move point to the parent (project) task if any and clock in"
1665 (let ((parent-task))
1669 (while (and (not parent-task) (org-up-heading-safe))
1670 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1671 (setq parent-task (point))))
1673 (org-with-point-at parent-task
1675 (when bh/keep-clock-running
1676 (bh/clock-in-default-task)))))))
1678 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
1680 (defun bh/clock-in-organization-task-as-default ()
1682 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
1683 (org-clock-in '(16))))
1685 (defun bh/clock-out-maybe ()
1686 (when (and bh/keep-clock-running
1687 (not org-clock-clocking-in)
1688 (marker-buffer org-clock-default-task)
1689 (not org-clock-resolving-clocks-due-to-idleness))
1690 (bh/clock-in-parent-task)))
1692 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
1695 (defun bh/clock-in-task-by-id (id)
1696 "Clock in a task by id"
1697 (org-with-point-at (org-id-find id 'marker)
1698 (org-clock-in nil)))
1700 (defun bh/clock-in-last-task (arg)
1701 "Clock in the interrupted task if there is one
1702 Skip the default task and get the next one.
1703 A prefix arg forces clock in of the default task."
1705 (let ((clock-in-to-task
1707 ((eq arg 4) org-clock-default-task)
1708 ((and (org-clock-is-active)
1709 (equal org-clock-default-task (cadr org-clock-history)))
1710 (caddr org-clock-history))
1711 ((org-clock-is-active) (cadr org-clock-history))
1712 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
1713 (t (car org-clock-history)))))
1715 (org-with-point-at clock-in-to-task
1716 (org-clock-in nil))))
1719 (defun org-export-to-ods ()
1721 (let ((csv-file "data.csv"))
1722 (org-table-export csv-file "orgtbl-to-csv")
1723 (org-odt-convert csv-file "ods" 'open)))
1725 ; allow for zero-width-space to be a break in regexp too
1726 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
1727 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
1728 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
1730 ;; support inserting screen shots
1731 (defun my/org-insert-screenshot ()
1732 "Take a screenshot into a time stamped unique-named file in the
1733 same directory as the org-buffer and insert a link to this file."
1735 (defvar my/org-insert-screenshot/filename)
1736 (setq my/org-insert-screenshot/filename
1738 "Screenshot to insert: "
1740 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
1743 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
1744 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
1745 (org-display-inline-images))
1747 (defun my/fix-inline-images ()
1748 (when org-inline-image-overlays
1749 (org-redisplay-inline-images)))
1751 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
1753 ;; use xelatex to preview with imagemagick
1754 (add-to-list 'org-preview-latex-process-alist
1755 '(xelateximagemagick
1756 :programs ("xelatex" "convert")
1757 :description "pdf > png"
1758 :message "you need to install xelatex and imagemagick"
1760 :image-input-type "pdf"
1761 :image-output-type "png"
1762 :image-size-adjust (1.0 . 1.0)
1763 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
1764 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
1766 ;; use xelatex by default
1767 (setq org-preview-latex-default-process 'xelateximagemagick)
1769 ; from http://orgmode.org/Changes.html
1770 (defun my/org-repair-property-drawers ()
1771 "Fix properties drawers in current buffer.
1772 Ignore non Org buffers."
1774 (when (eq major-mode 'org-mode)
1775 (org-with-wide-buffer
1776 (goto-char (point-min))
1777 (let ((case-fold-search t)
1778 (inline-re (and (featurep 'org-inlinetask)
1779 (concat (org-inlinetask-outline-regexp)
1783 (unless (and inline-re (org-looking-at-p inline-re))
1785 (let ((end (save-excursion (outline-next-heading) (point))))
1787 (when (org-looking-at-p org-planning-line-re) (forward-line))
1788 (when (and (< (point) end)
1789 (not (org-looking-at-p org-property-drawer-re))
1791 (and (re-search-forward org-property-drawer-re end t)
1792 (eq (org-element-type
1793 (save-match-data (org-element-at-point)))
1795 (insert (delete-and-extract-region
1797 (min (1+ (match-end 0)) end)))
1798 (unless (bolp) (insert "\n"))))))))))))
1802 #+BEGIN_SRC emacs-lisp
1806 (use-package calfw-org
1809 (use-package org-gcal
1811 :config '((if (file-readable-p "~/.hide/org_gcal.el")
1812 (load-file "~/.hide/org_gcal.el"))
1817 #+BEGIN_SRC emacs-lisp
1820 ;; Show notification 10 minutes before event
1821 (setq appt-message-warning-time 10)
1822 ;; Disable multiple reminders
1823 (setq appt-display-interval appt-message-warning-time)
1824 (setq appt-display-mode-line nil)
1826 ;; add automatic reminders for appointments
1827 (defun my/org-agenda-to-appt ()
1829 (setq appt-time-msg-list nil)
1830 (org-agenda-to-appt))
1831 ;; add reminders when starting emacs
1832 (my/org-agenda-to-appt)
1833 ;; when rebuilding the agenda
1834 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
1835 "Pressing `r' on the agenda will also add appointments."
1836 (my/org-agenda-to-appt)
1838 ;; when saving all org buffers
1839 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
1840 "Re-add appts after saving all org buffers"
1841 (my/org-agenda-to-appt))
1842 ;; Display appointments as a window manager notification
1843 (setq appt-disp-window-function 'my/appt-display)
1844 (setq appt-delete-window-function (lambda () t))
1846 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
1848 (defun my/appt-display (min-to-app new-time msg)
1849 (if (atom min-to-app)
1850 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
1851 (dolist (i (number-sequence 0 (1- (length min-to-app))))
1852 (start-process "my/appt-notification-app" nil my/appt-notification-app
1853 (nth i min-to-app) (nth i msg))))
1860 #+BEGIN_SRC emacs-lisp
1864 ** Override other things
1865 #+BEGIN_SRC emacs-lisp
1866 ; apparently things like to step on C-;, so we'll use a hack from
1867 ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
1869 (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
1872 (define-key my-keys-minor-mode-map (kbd "C-;") 'mc/mark-all-dwim)
1873 ;; use outline mode keybindings everywhere
1874 ;; (define-key my-keys-minor-mode-map (kbd "C-;") 'my/mydra-outline/body)
1876 (define-minor-mode my-keys-minor-mode
1877 "A minor mode so that my key settings override annoying major modes."
1878 t " my-keys" 'my-keys-minor-mode-map)
1880 (my-keys-minor-mode 1)
1881 (defun my-minibuffer-setup-hook ()
1882 (my-keys-minor-mode 0))
1884 (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
1885 (defadvice load (after give-my-keybindings-priority)
1886 "Try to ensure that my keybindings always have priority."
1887 (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
1888 (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
1889 (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
1890 (add-to-list 'minor-mode-map-alist mykeys))))
1894 #+BEGIN_SRC emacs-lisp
1895 (global-unset-key "\M-g")
1896 (global-set-key (kbd "M-g l") 'goto-line)
1900 #+BEGIN_SRC emacs-lisp
1901 (use-package debian-changelog
1902 :mode "debian/changelog"
1904 (setq debian-changelog-mailing-address "don@debian.org")
1905 (setq debian-changelog-full-name "Don Armstrong"))
1907 * Misc (uncharacterized)
1908 #+BEGIN_SRC emacs-lisp
1909 (setq calendar-latitude 38.6)
1910 (setq calendar-longitude -121.5)
1911 (setq case-fold-search t)
1912 (setq confirm-kill-emacs (quote y-or-n-p))
1913 (setq cperl-lazy-help-time nil)
1915 (setq display-time-24hr-format t)
1916 (setq display-time-day-and-date t)
1917 (display-time-mode 1)
1918 (global-font-lock-mode 1)
1920 (setq log-edit-keep-buffer t)
1921 (setq mail-user-agent (quote sendmail-user-agent))
1922 (setq markdown-enable-math t)
1923 (setq markdown-follow-wiki-link-on-enter nil)
1924 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
1925 (setq ps-footer-font-size (quote (8 . 10)))
1926 (setq ps-header-font-size (quote (8 . 10)))
1927 (setq ps-header-title-font-size (quote (10 . 10)))
1928 (setq ps-line-number-color "blue")
1929 (setq ps-print-footer t)
1930 (setq ps-print-footer-frame nil)
1931 (setq ps-print-only-one-header t)
1932 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
1934 (setq sentence-end-double-space nil)
1935 ; enable matching parenthesis
1938 (setq user-mail-address "don@donarmstrong.com")
1939 (setq vc-delete-logbuf-window nil)
1940 (setq vc-follow-symlinks t)
1942 ;; use git before SVN; use CVS earlier, because I have CVS
1943 ;; repositories inside of git directories
1944 (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
1946 ;; switch back to the old primary selection method
1947 (setq x-select-enable-clipboard nil)
1948 (setq x-select-enable-primary t)
1949 ; (setq mouse-drag-copy-region t)
1951 (fset 'perl-mode 'cperl-mode)
1952 ;;(load-file "cperl-mode.el")
1956 (global-set-key "\C-xp" 'server-edit)
1958 (setq-default auto-mode-alist (cons '("\.wml$" .
1959 (lambda () (html-mode) (auto-fill-mode)))
1963 ; use markdown mode for mdwn files
1964 (add-to-list 'auto-mode-alist '("\\.mdwn$" . markdown-mode))
1965 (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
1968 ;; tramp configuration
1969 (setq tramp-use-ssh-controlmaster-options nil)
1971 ;; self-insert-command hack.
1972 ;; Without this, "if<SP>" expands to
1975 ;; which really should be,
1981 ;(load-library "php-mode")
1983 (setq-default c-indent-level 4)
1984 (setq-default c-brace-imaginary-offset 0)
1985 (setq-default c-brace-offset -4)
1986 (setq-default c-argdecl-indent 4)
1987 (setq-default c-label-offset -4)
1988 (setq-default c-continued-statement-offset 4)
1990 (setq-default indent-tabs-mode nil)
1991 (setq-default tab-width 4)
1994 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
1995 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
1996 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
1997 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
1998 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2001 (defun insert-date ()
2002 "Insert date at point."
2004 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2005 (global-set-key "\C-[d" 'insert-date)
2007 (defun unfill-paragraph (arg)
2008 "Pull this whole paragraph up onto one line."
2010 (let ((fill-column 10000))
2011 (fill-paragraph arg))
2014 (column-number-mode t)
2016 ; (require 'mode-compile)
2018 (defadvice server-process-filter (after post-mode-message first activate)
2019 "If the buffer is in post mode, overwrite the server-edit
2020 message with a post-save-current-buffer-and-exit message."
2021 (if (eq major-mode 'post-mode)
2023 (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
2024 ; This is also needed to see the magic message. Set to a higher
2025 ; number if you have a faster computer or read slower than me.
2026 '(font-lock-verbose 1000)
2027 ;(setq-default server-temp-file-regexp "mutt\(-\|ng-\)")
2028 ; (add-hook 'server-switch-hook
2029 ; (function (lambda()
2030 ; (cond ((string-match "Post" mode-name)
2031 ; (post-goto-body)))
2032 ; set-buffer-file-coding-system 'utf-8
2036 (add-hook 'post-mode-hook
2037 (auto-fill-mode nil)
2039 ; abbrev mode settings
2040 ; load abbreviations from
2041 (setq abbrev-file-name
2042 "~/.emacs_abbrev_def")
2044 ; read the abbrev file if it exists
2045 (if (file-exists-p abbrev-file-name)
2046 (quietly-read-abbrev-file))
2048 ; for now, use abbrev mode everywhere
2049 (setq default-abbrev-mode t)
2052 (defun insert-function-documentation ()
2053 "Insert function documentation"
2055 (insert-file-contents "/home/don/lib/templates/perl_function_documentation" nil))
2056 (global-set-key "\M-f" 'insert-function-documentation)
2058 (eval-after-load "lilypond-mode"
2060 (load-library "lyqi-mode")
2061 (define-key LilyPond-mode-map "\C-cq" 'lyqi-mode)))
2063 (autoload 'spamassassin-mode "spamassassin-mode" nil t)
2065 (desktop-load-default)
2067 '(icomplete-mode on)
2069 ;; custom-set-faces was added by Custom.
2070 ;; If you edit it by hand, you could mess it up, so be careful.
2071 ;; Your init file should contain only one such instance.
2072 ;; If there is more than one, they won't work right.
2073 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2076 (put 'upcase-region 'disabled nil)
2077 (put 'downcase-region 'disabled nil)
2078 (put 'narrow-to-region 'disabled nil)
2080 ; (defun turn-on-flyspell ()
2081 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2083 ; (flyspell-mode 1))
2086 ; Outline-minor-mode key map
2087 (define-prefix-command 'cm-map nil "Outline-")
2089 (define-key cm-map "q" 'hide-sublevels) ; Hide everything but the top-level headings
2090 (define-key cm-map "t" 'hide-body) ; Hide everything but headings (all body lines)
2091 (define-key cm-map "o" 'hide-other) ; Hide other branches
2092 (define-key cm-map "c" 'hide-entry) ; Hide this entry's body
2093 (define-key cm-map "l" 'hide-leaves) ; Hide body lines in this entry and sub-entries
2094 (define-key cm-map "d" 'hide-subtree) ; Hide everything in this entry and sub-entries
2096 (define-key cm-map "a" 'show-all) ; Show (expand) everything
2097 (define-key cm-map "e" 'show-entry) ; Show this heading's body
2098 (define-key cm-map "i" 'show-children) ; Show this heading's immediate child sub-headings
2099 (define-key cm-map "k" 'show-branches) ; Show all sub-headings under this heading
2100 (define-key cm-map "s" 'show-subtree) ; Show (expand) everything in this heading & below
2102 (define-key cm-map "u" 'outline-up-heading) ; Up
2103 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2104 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2105 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2106 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2107 (global-set-key "\M-o" cm-map)
2109 ; ediff configuration
2110 ; don't use the multi-window configuration
2111 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
2113 ; fix up css mode to not be silly
2114 ; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
2115 (setq cssm-indent-level 4)
2116 (setq cssm-newline-before-closing-bracket t)
2117 (setq cssm-indent-function #'cssm-c-style-indenter)
2118 (setq cssm-mirror-mode nil)
2120 (require 'multi-web-mode)
2121 (setq mweb-default-major-mode 'html-mode)
2122 (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
2123 (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
2124 (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
2125 (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
2126 (multi-web-global-mode 1)
2128 ;;; alias the new `flymake-report-status-slim' to
2129 ;;; `flymake-report-status'
2130 (defalias 'flymake-report-status 'flymake-report-status-slim)
2131 (defun flymake-report-status-slim (e-w &optional status)
2132 "Show \"slim\" flymake status in mode line."
2134 (setq flymake-mode-line-e-w e-w))
2136 (setq flymake-mode-line-status status))
2137 (let* ((mode-line " Φ"))
2138 (when (> (length flymake-mode-line-e-w) 0)
2139 (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
2140 (setq mode-line (concat mode-line flymake-mode-line-status))
2141 (setq flymake-mode-line mode-line)
2142 (force-mode-line-update)))
2144 ; load sql-indent when sql is loaded
2145 (eval-after-load "sql"
2146 '(load-library "sql-indent"))
2148 ; fix up tmux xterm keys
2149 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2150 (defun fix-up-tmux-keys ()
2151 "Fix up tmux xterm keys"
2154 (let ((x 2) (tkey ""))
2174 ;; ctrl + alt + shift
2176 (setq tkey "C-M-S-"))
2179 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2180 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2181 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2182 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2184 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2186 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2188 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2190 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2192 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2194 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2196 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2198 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2200 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2202 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2204 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2206 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2208 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2210 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2212 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2214 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2216 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2218 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2220 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2222 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2224 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2226 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2228 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2230 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2232 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2234 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2241 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2243 ; procmailmode configuration
2244 (load "procmail_mode")
2246 (load "mode-line-cleaner")
2248 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2249 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2250 (if (or (buffer-modified-p)
2251 (verify-visited-file-modtime)
2252 (< (* 8 1024 1024) (buffer-size))
2253 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2255 (clear-visited-file-modtime)
2257 (ad-activate 'ask-user-about-supersession-threat)
2259 ; apparently things like to step on C-;, so we'll use a hack from
2260 ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
2262 (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
2264 ; use iedit everywhere
2265 (define-key my-keys-minor-mode-map (kbd "C-;") 'mc/mark-all-dwim)
2267 (define-minor-mode my-keys-minor-mode
2268 "A minor mode so that my key settings override annoying major modes."
2269 t " my-keys" 'my-keys-minor-mode-map)
2271 (my-keys-minor-mode 1)
2272 (defun my-minibuffer-setup-hook ()
2273 (my-keys-minor-mode 0))
2275 (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
2276 (defadvice load (after give-my-keybindings-priority)
2277 "Try to ensure that my keybindings always have priority."
2278 (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
2279 (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
2280 (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
2281 (add-to-list 'minor-mode-map-alist mykeys))))
2283 (global-set-key "\M- " 'hippie-expand)
2288 #+BEGIN_SRC emacs-lisp
2289 (unless (server-running-p)
2296 #+BEGIN_SRC emacs-lisp
2297 (provide 'don-configuration)