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)
10 * Initial startup stuff
11 ** Disable startup screen
12 #+BEGIN_SRC emacs-lisp
13 (setq inhibit-startup-screen t)
16 #+BEGIN_SRC emacs-lisp
17 ; (if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
18 (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
19 (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
22 #+BEGIN_SRC emacs-lisp
23 (setq frame-resize-pixelwise t)
24 (add-to-list 'default-frame-alist '(fullscreen . maximixed))
27 ** package repositories and package manager
28 Borrowed from https://github.com/nilcons/emacs-use-package-fast/ to
29 load [[https://github.com/jwiegley/use-package/][use-package]] even faster
30 #+BEGIN_SRC emacs-lisp
31 (setq package-enable-at-startup nil)
32 (setq package--init-file-ensured t)
34 (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
35 (mapc #'(lambda (add) (add-to-list 'load-path add))
38 (unless (package-installed-p 'use-package)
39 (package-refresh-contents)
40 (package-install 'use-package))
41 (let ((package-user-dir-real (file-truename package-user-dir)))
42 ;; The reverse is necessary, because outside we mapc
43 ;; add-to-list element-by-element, which reverses.
44 (nreverse (apply #'nconc
45 ;; Only keep package.el provided loadpaths.
46 (mapcar #'(lambda (path)
47 (if (string-prefix-p package-user-dir-real path)
52 (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
53 ("melpa" . "https://melpa.org/packages/")
54 ("org" . "http://orgmode.org/elpa/") ))
55 (require 'use-package)
60 #+BEGIN_SRC emacs-lisp
63 :commands (paradox-upgrade-packages paradox-list-packages)
64 :config (setq paradox-execute-asynchronously t)
69 #+BEGIN_SRC emacs-lisp
70 (add-to-list 'load-path '"~/lib/emacs_el/")
71 (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
74 #+BEGIN_SRC emacs-lisp
75 ;; Set the custom file to /dev/null and don't bother to load it
76 (setq custom-file "/dev/null")
80 #+BEGIN_SRC emacs-lisp
81 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
82 ;; execute conditional code when loading libraries
83 (defmacro with-library (symbol &rest body)
84 `(when (require ,symbol nil t)
86 (put 'with-library 'lisp-indent-function 1)
90 ** Safe Local Variables
91 #+BEGIN_SRC emacs-lisp
92 (setq safe-local-variable-values
93 (quote ((auto-save-default)
95 (cperl-indent-level . 4)
97 (indent-tabs-mode . f)
101 #+BEGIN_SRC emacs-lisp
102 (setq global-mark-ring-max 128
106 (defun don/minibuffer-setup-hook ()
107 (setq gc-cons-threshold most-positive-fixnum))
109 (defun don/minibuffer-exit-hook ()
110 (setq gc-cons-threshold 1048576))
112 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
113 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
117 #+BEGIN_SRC emacs-lisp
118 (use-package flyspell
120 :diminish flyspell-mode 🐝
122 (add-hook 'text-mode-hook 'turn-on-flyspell)
123 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
124 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
125 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
127 (setq ispell-program-name "ispell")
132 #+BEGIN_SRC emacs-lisp
137 #+BEGIN_SRC emacs-lisp
138 ;; (use-package eyebrowse
140 ;; :diminish eyebrowse-mode
141 ;; :init (setq eyebrowse-keymap-prefix (kbd "C-c C-\\"))
143 ;; (setq eyebrowse-wrap-around t)
144 ;; (eyebrowse-mode t)
146 ;; (defun my/eyebrowse-new-window-config ()
150 ;; ;; start at 1 run till 0
151 ;; (let ((j (mod (+ i 1) 10)))
152 ;; (when (and (not done)
153 ;; (not (eyebrowse--window-config-present-p j)))
154 ;; (eyebrowse-switch-to-window-config j)
155 ;; (call-interactively 'eyebrowse-rename-window-config2 j)
160 ;; ;; I don't use latex-preview-pane
161 ;; ;; (require 'latex-preview-pane)
162 ;; ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
163 ;; ;; ;; latex-preview-pane uses window-parameters which are
164 ;; ;; ;; not preserved by eyebrowse, so we close the preview
165 ;; ;; ;; pane before switching, it will be regenerated when we
166 ;; ;; ;; edit the TeX file.
167 ;; ;; (when (lpp/window-containing-preview)
168 ;; ;; (delete-window (lpp/window-containing-preview))))
170 ;; ;; (add-to-list 'eyebrowse-pre-window-switch-hook
171 ;; ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
173 ;; ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
174 ;; ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
175 ;; ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
176 ;; ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
177 ;; ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
185 #+BEGIN_SRC emacs-lisp
186 (defun my/vsplit-last-buffer ()
187 "Split the window vertically and display the previous buffer."
189 (split-window-vertically)
191 (switch-to-next-buffer))
193 (defun my/hsplit-last-buffer ()
194 "Split the window horizontally and display the previous buffer."
196 (split-window-horizontally)
198 (switch-to-next-buffer))
200 (bind-key "C-x 2" 'my/vsplit-last-buffer)
201 (bind-key "C-x 3" 'my/hsplit-last-buffer)
203 (setq split-width-threshold 100)
204 (setq split-height-threshold 60)
206 (defun my/split-window-prefer-vertically (window)
207 "If there's only one window (excluding any possibly active
208 minibuffer), then split the current window horizontally."
209 (if (and (one-window-p t)
210 (not (active-minibuffer-window))
211 ( < (frame-width) (frame-height))
213 (let ((split-width-threshold nil))
214 (split-window-sensibly window))
215 (split-window-sensibly window)))
217 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
218 (setq window-combination-resize t)
221 *** Compilation window
223 If there is no compilation window, open one at the bottom, spanning
224 the complete width of the frame. Otherwise, reuse existing window. In
225 the former case, if there was no error the window closes
228 #+BEGIN_SRC emacs-lisp
229 (add-to-list 'display-buffer-alist
230 `(,(rx bos "*compilation*" eos)
231 (display-buffer-reuse-window
232 display-buffer-in-side-window)
233 (reusable-frames . visible)
235 (window-height . 0.4)))
238 #+BEGIN_SRC emacs-lisp
239 (defun my/compilation-exit-autoclose (status code msg)
240 ;; If M-x compile exists with a 0
241 (when (and (eq status 'exit) (zerop code))
242 ;; and delete the *compilation* window
243 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
244 (when (and (not (window-at-side-p compilation-window 'top))
245 (window-at-side-p compilation-window 'left)
246 (window-at-side-p compilation-window 'right))
247 (delete-window compilation-window))))
248 ;; Always return the anticipated result of compilation-exit-message-function
251 ;; Specify my function (maybe I should have done a lambda function)
252 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
255 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
256 value, the compilation buffer scrolls automatically to follow the
257 output. If the value is ~first-error~, scrolling stops when the first
258 error appears, leaving point at that error. For any other non-nil
259 value, scrolling continues until there is no more output.
261 #+BEGIN_SRC emacs-lisp
262 (setq compilation-scroll-output 'first-error)
265 ** Mode line cleaning
267 #+BEGIN_SRC emacs-lisp
268 (use-package diminish
273 #+BEGIN_SRC emacs-lisp
280 #+BEGIN_SRC emacs-lisp
283 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
284 ("C-c j j" . avy-goto-word-or-subword-1)
285 ("M-g g" . avy-goto-line))
286 :config (progn (setq avy-background t))
289 *** Ace-link (jumping to links)
290 #+BEGIN_SRC emacs-lisp
291 (use-package ace-link
293 ; bind o in most modes
294 :config (ace-link-setup-default))
296 *** Jumping through edit points (goto-chg)
297 #+BEGIN_SRC emacs-lisp
298 (use-package goto-chg
300 :bind (("C-c j ," . goto-last-change)
301 ("C-c j ." . goto-last-change-reverse))
304 *** Jumping to bookmarks (visible bookmarks, bm)
305 #+BEGIN_SRC emacs-lisp
308 :bind (("C-c j b ." . bm-next)
309 ("C-c j b ," . bm-previous)
310 ("C-c j b SPC" . bm-toggle)))
315 #+BEGIN_SRC emacs-lisp
316 (use-package yasnippet
318 :diminish yas-minor-mode
321 (setq yas-verbosity 1)
322 (define-key yas-minor-mode-map (kbd "<tab>") nil)
323 (define-key yas-minor-mode-map (kbd "TAB") nil)
324 (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
325 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
326 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
327 (add-to-list 'hippie-expand-try-functions-list
328 'yas-hippie-try-expand)
333 #+BEGIN_SRC emacs-lisp
334 (use-package auto-yasnippet
335 :bind (("H-w" . aya-create)
342 #+BEGIN_SRC emacs-lisp
344 (use-package tinyprocmail
346 :config (with-library 'tinyprocmail
347 ;; (setq tinyprocmail--procmail-version "v3.22")
348 (add-hook 'tinyprocmail--load-hook 'tinyprocmail-install))
353 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
356 :bind (("C-x g" . magit-status)
357 ("C-x C-g" . magit-status))
359 ;; don't verify where we are pushing
360 (setq magit-push-always-verify nil)
361 ;; refine diffs always (hilight words)
362 (setq magit-diff-refine-hunk nil)
365 (append '("~/lib/emacs_el/magit-annex")
369 (append '("~/lib/emacs_el/magit-vcsh")
372 (use-package magit-annex
375 (use-package magit-vcsh
376 :ensure f ; currently not in melpa, so don't try to install
381 #+BEGIN_SRC emacs-lisp
382 (use-package cperl-mode
385 ;; Use c-mode for perl .xs files
386 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
387 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
388 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
389 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
390 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
393 cperl-auto-newline nil
394 cperl-auto-newline-after-colon nil
395 cperl-continued-statement-offset 4
396 cperl-brace-offset -1
397 cperl-continued-brace-offset 0
398 cperl-label-offset -4
399 cperl-highlight-variables-indiscriminately t
400 cperl-electric-lbrace-space nil
401 cperl-indent-parens-as-block nil
402 cperl-close-paren-offset -1
403 cperl-tab-always-indent t)
404 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
409 #+BEGIN_SRC emacs-lisp
414 (define-key global-map [remap find-file] 'helm-find-files)
415 (define-key global-map [remap occur] 'helm-occur)
416 (define-key global-map [remap list-buffers] 'helm-buffers-list)
417 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
418 (global-set-key (kbd "M-x") 'helm-M-x)
419 (unless (boundp 'completion-in-region-function)
420 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
421 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
422 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
427 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
429 #+BEGIN_SRC emacs-lisp
430 (use-package helm-flx
433 ;; these are helm configs, but they kind of fit here nicely
434 (setq helm-M-x-fuzzy-match t
435 helm-bookmark-show-location t
436 helm-buffers-fuzzy-matching t
437 helm-completion-in-region-fuzzy-match t
438 helm-file-cache-fuzzy-match t
439 helm-imenu-fuzzy-match t
440 helm-mode-fuzzy-match t
441 helm-locate-fuzzy-match nil
443 helm-recentf-fuzzy-match nil
444 helm-semantic-fuzzy-match t)
448 #+BEGIN_SRC emacs-lisp
450 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
451 (defun malb/helm-swoop-pre-fill ()
452 (thing-at-point 'symbol))
453 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
454 paradox-menu-mode doc-view-mode pdf-view-mode
455 mu4e-headers-mode org-mode markdown-mode latex-mode
456 ein:notebook-multilang-mode))
458 (defun malb/swoop-or-search ()
460 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
461 (memq major-mode malb/helm-swoop-ignore-major-mode))
465 (use-package helm-swoop
467 :bind (("C-c o" . helm-multi-swoop-org)
468 ("C-s" . malb/swoop-or-search)
469 ("C-M-s" . helm-multi-swoop-all))
472 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
473 helm-swoop-split-with-multiple-windows nil
474 helm-swoop-split-direction #'split-window-horizontally
475 helm-swoop-split-window-function 'helm-default-display-buffer
476 helm-swoop-speed-or-color t)
478 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
479 (defun malb/helm-swoop-C-s ()
481 (if (boundp 'helm-swoop-pattern)
482 (if (equal helm-swoop-pattern "")
483 (previous-history-element 1)
487 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
488 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
489 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
490 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
491 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
492 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
497 #+BEGIN_SRC emacs-lisp
500 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
501 helm-ag-command-option "--all-text"
502 helm-ag-insert-at-point 'symbol
503 helm-ag-fuzzy-match t
504 helm-ag-use-temp-buffer t
505 helm-ag-use-grep-ignore-list t
506 helm-ag-use-agignore t))
509 #+BEGIN_SRC emacs-lisp
510 (use-package helm-descbinds
512 :bind ("C-h b" . helm-descbinds)
513 :init (fset 'describe-bindings 'helm-descbinds))
517 #+BEGIN_SRC emacs-lisp
518 (use-package helm-c-yasnippet
520 :bind ("C-c h y" . helm-yas-complete)
522 (setq helm-yas-space-match-any-greedy t)))
525 #+BEGIN_SRC emacs-lisp
526 (use-package helm-org-rifle
529 (defun malb/helm-org-rifle-agenda-files (arg)
531 (let ((current-prefix-arg nil))
533 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
534 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
535 (t (helm-org-agenda-files-headings)))))))
538 This can be used to link things pretty quickly if necessary
539 #+BEGIN_SRC emacs-lisp
540 (use-package helm-google
542 :bind ("C-c h g" . helm-google)
544 (progn (add-to-list 'helm-google-actions
545 '("Copy URL" . (lambda (candidate)
547 (replace-regexp-in-string
548 "https://.*q=\\(.*\\)\&sa=.*"
554 (add-to-list 'helm-google-actions
555 '("Org Store Link" . (lambda (candidate)
556 (let ((title (car (split-string candidate "[\n]+")))
558 (replace-regexp-in-string
559 "https://.*q=\\(.*\\)\&sa=.*"
561 (push (list url title) org-stored-links))))
566 #+BEGIN_SRC emacs-lisp
569 :bind ("M-z" . avy-zap-up-to-char-dwim))
572 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
577 #+BEGIN_SRC emacs-lisp
578 (add-to-list 'tramp-methods '("vcsh"
579 (tramp-login-program "vcsh")
583 (tramp-remote-shell "/bin/sh")
584 (tramp-remote-shell-args
588 #+BEGIN_SRC emacs-lisp
592 (setq-default reftex-default-bibliography
593 '("~/projects/research/references.bib")))
596 #+BEGIN_SRC emacs-lisp
598 :config (setq bibtex-user-optional-fields
599 (quote (("annote" "Personal annotation (ignored)")
607 #+BEGIN_SRC emacs-lisp
612 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
613 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
614 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
615 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
616 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
617 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
618 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
619 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
620 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
621 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
622 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
624 (setq-default reftex-plug-into-AUCTeX t)
625 ;; support fake section headers
626 (setq TeX-outline-extra
632 ;; add font locking to the headers
633 (font-lock-add-keywords
635 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
636 0 'font-lock-keyword-face t)
637 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
638 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
639 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
640 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
641 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
643 ;; use smart quotes by default instead of `` and ''
644 ;; taken from http://kieranhealy.org/esk/kjhealy.html
645 (setq TeX-open-quote "“")
646 (setq TeX-close-quote "”")
648 ;; (TeX-add-style-hook
653 ;; (custom-set-variables
654 ;; '(font-latex-user-keyword-classes
657 ;; font-lock-function-name-face 2 (command 1 t))))
659 (setq-default TeX-parse-self t)
660 (setq-default TeX-auto-save t)
661 (setq-default TeX-master nil)
667 (if (boundp 'reftex-ref-style-alist)
669 'reftex-ref-style-alist
670 '("Cleveref" "cleveref"
671 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
672 (reftex-ref-style-activate "Cleveref")
674 '("cref" TeX-arg-ref)
675 '("Cref" TeX-arg-ref)
676 '("cpageref" TeX-arg-ref)
677 '("Cpageref" TeX-arg-ref)))))
680 '(add-to-list 'LaTeX-fill-excluded-macros
683 (use-package font-latex
685 (setq font-latex-match-reference-keywords
707 (setq font-latex-fontify-script nil)
708 (setq font-latex-fontify-sectioning (quote color))
709 (setq font-latex-script-display (quote (nil)))
714 #+BEGIN_SRC emacs-lisp
718 (defun ess-change-directory (path)
719 "Set the current working directory to PATH for both *R* and Emacs."
720 (interactive "DDirectory to change to: ")
722 (when (file-exists-p path)
723 (ess-command (concat "setwd(\"" path "\")\n"))
724 ;; use file-name-as-directory to ensure it has trailing /
725 (setq default-directory (file-name-as-directory path))))
726 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
727 ;; outlining support for ess modes
732 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
733 (defun outline-level ()
734 (cond ((looking-at "^##### ") 1)
735 ((looking-at "^#### ") 2)
736 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
739 (add-hook 'ess-mode-hook
741 (local-set-key (kbd "C-c C-R")
742 'dla/ess-region-remote-eval)))
744 ;; Don't restore history or save workspace image
745 '(inferior-R-args "--no-restore-history --no-save")
750 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
752 #+BEGIN_SRC emacs-lisp
753 (use-package rainbow-mode
754 ;; add ess to the x major mode
755 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
756 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
761 #+BEGIN_SRC emacs-lisp
762 (use-package polymode
765 (use-package poly-noweb)
766 (use-package poly-markdown)
767 :mode ("\\.Snw" . poly-noweb+r-mode)
768 :mode ("\\.Rnw" . poly-noweb+r-mode)
769 :mode ("\\.Rmd" . poly-markdown+r-mode)
775 #+BEGIN_SRC emacs-lisp
776 (use-package outline-magic)
779 #+BEGIN_SRC emacs-lisp
780 (use-package writeroom-mode
782 (defun my/writing-mode ()
783 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
788 (visual-line-mode -1)
790 (visual-fill-column-mode -1)
794 (visual-fill-column-mode 1)
799 ** GhostText/Atomic Chrome
800 #+BEGIN_SRC emacs-lisp
801 (use-package atomic-chrome
803 (ignore-errors (atomic-chrome-start-server))
804 (setq atomic-chrome-buffer-open-style 'full)
809 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
811 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
812 #+BEGIN_SRC emacs-lisp
813 (use-package multiple-cursors
814 :bind (("C-;" . mc/mark-all-dwim)
815 ("C-<" . mc/mark-previous-like-this)
816 ("C->" . mc/mark-next-like-this)
817 ("C-S-c C-S-c" . mc/edit-lines))
821 #+BEGIN_SRC emacs-lisp
822 (use-package web-mode
824 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
825 (setq web-mode-enable-engine-detection t)
826 (setq web-mode-engines-alist
827 '(("template-toolkit" . "\\.tmpl\\'")))
832 #+BEGIN_SRC emacs-lisp
835 (setq post-email-address "don@donarmstrong.com")
836 (setq post-kill-quoted-sig nil)
837 (setq post-mail-message "mutt\\(ng\\|\\)-[a-z0-9]+-[0-9]+-.*")
838 (setq post-uses-fill-mode nil)
843 #+BEGIN_SRC emacs-lisp
846 :mode "muttng-[a-z0-9]+-[0-9]+-"
847 :mode "mutt-[a-z0-9]+-[0-9]+-"
848 :hook 'my/message-mode-settings
849 :hook 'turn-on-flyspell
850 :bind (:map message-mode-map
851 ("C-c C-a" . my/post-attach-file))
853 (defun my/message-mode-settings ()
854 (font-lock-add-keywords nil
855 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
856 (0 'message-multiply-quoted-text-face))
857 ("^[ \t]*>[ \t]*>.*$"
858 (0 'message-double-quoted-text-face))))
861 (defun my/post-attach-file ()
862 "Prompt for an attachment."
864 (let ((file (read-file-name "Attach file: " nil nil t nil))
865 (description (string-read "Description: ")))
866 (my/header-attach-file file description)))
868 (defun my/header-attach-file (file description)
869 "Attach a FILE to the current message (works with Mutt).
870 Argument DESCRIPTION MIME description."
871 (interactive "fAttach file: \nsDescription: ")
872 (when (> (length file) 0)
877 (goto-char (point-min))
878 (search-forward-regexp "^$")
879 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
881 (message (concat "Attached '" file "'."))
882 (setq post-has-attachment t))))))
884 (setq mail-yank-prefix "> ")
888 #+BEGIN_SRC emacs-lisp
889 (use-package muttrc-mode
897 #+BEGIN_SRC emacs-lisp
898 (setq global-auto-revert-non-file-buffers t
899 global-auto-revert-ignore-modes '(pdf-view-mode)
900 auto-revert-verbose nil)
901 (global-auto-revert-mode 1)
904 ** Use-package and load things
905 #+BEGIN_SRC emacs-lisp
911 ** Agenda Configuration
912 #+BEGIN_SRC emacs-lisp
913 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
914 :bind (("C-c l" . org-store-link)
915 ("C-c a" . org-agenda)
916 ("C-c b" . org-iswitchb))
918 (setq-default org-log-done 'time)
919 (setq-default org-agenda-ndays 5)
921 ;; agenda configuration
922 ;; Do not dim blocked tasks
923 (setq org-agenda-dim-blocked-tasks nil)
924 (setq org-agenda-inhibit-startup t)
925 (setq org-agenda-use-tag-inheritance nil)
927 ;; Compact the block agenda view
928 (setq org-agenda-compact-blocks t)
930 ;; Custom agenda command definitions
931 (setq org-agenda-custom-commands
932 (quote (("N" "Notes" tags "NOTE"
933 ((org-agenda-overriding-header "Notes")
934 (org-tags-match-list-sublevels t)))
935 ("h" "Habits" tags-todo "STYLE=\"habit\""
936 ((org-agenda-overriding-header "Habits")
937 (org-agenda-sorting-strategy
938 '(todo-state-down effort-up category-keep))))
942 ((org-agenda-overriding-header "Tasks to Refile")
943 (org-tags-match-list-sublevels nil)))
944 (tags-todo "-CANCELLED/!"
945 ((org-agenda-overriding-header "Stuck Projects")
946 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
947 (org-agenda-sorting-strategy
949 (tags-todo "-HOLD-CANCELLED/!"
950 ((org-agenda-overriding-header "Projects")
951 (org-agenda-skip-function 'bh/skip-non-projects)
952 (org-tags-match-list-sublevels 'indented)
953 (org-agenda-sorting-strategy
955 (tags-todo "-CANCELLED/!NEXT"
956 ((org-agenda-overriding-header (concat "Project Next Tasks"
957 (if bh/hide-scheduled-and-waiting-next-tasks
959 " (including WAITING and SCHEDULED tasks)")))
960 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
961 (org-tags-match-list-sublevels t)
962 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
963 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
964 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
965 (org-agenda-sorting-strategy
966 '(todo-state-down effort-up category-keep))))
967 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
968 ((org-agenda-overriding-header (concat "Project Subtasks"
969 (if bh/hide-scheduled-and-waiting-next-tasks
971 " (including WAITING and SCHEDULED tasks)")))
972 (org-agenda-skip-function 'bh/skip-non-project-tasks)
973 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
974 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
975 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
976 (org-agenda-sorting-strategy
978 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
979 ((org-agenda-overriding-header (concat "Standalone Tasks"
980 (if bh/hide-scheduled-and-waiting-next-tasks
982 " (including WAITING and SCHEDULED tasks)")))
983 (org-agenda-skip-function 'bh/skip-project-tasks)
984 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
985 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
986 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
987 (org-agenda-sorting-strategy
989 (tags-todo "-CANCELLED+WAITING|HOLD/!"
990 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
991 (org-agenda-skip-function 'bh/skip-stuck-projects)
992 (org-tags-match-list-sublevels nil)
993 (org-agenda-todo-ignore-scheduled t)
994 (org-agenda-todo-ignore-deadlines t)))
996 ((org-agenda-overriding-header "Tasks to Archive")
997 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
998 (org-tags-match-list-sublevels nil))))
1001 ; org mode agenda files
1002 (setq org-agenda-files
1003 (quote ("~/projects/org-notes/debbugs.org"
1004 "~/projects/org-notes/notes.org"
1005 "~/projects/org-notes/holidays.org"
1006 "~/projects/org-notes/refile.org"
1007 "~/projects/org-notes/diary.org"
1008 "~/projects/org-notes/ool.org"
1009 "~/projects/org-notes/sndservers.org"
1010 "~/projects/org-notes/chaim.org"
1011 "~/projects/org-notes/wildman.org"
1012 "~/projects/org-notes/uddin.org"
1013 "~/projects/org-notes/reviews.org"
1014 "~/org-mode/from-mobile.org"
1015 "~/projects/org-notes/fh.org")))
1017 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1018 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
1019 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1020 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1021 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1022 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1023 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1024 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1025 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1026 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1027 (defun org-agenda-timeline-all (&optional arg)
1030 (dolist (org-agenda-file org-agenda-files)
1031 (insert-file-contents org-agenda-file nil)
1034 (write-file "/tmp/timeline.org")
1035 (org-agenda arg "L")))
1036 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1040 #+BEGIN_SRC emacs-lisp
1041 (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")))
1042 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1044 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1045 (setq org-id-link-to-org-use-id 'use-existing)
1047 ** Capture Templates
1048 #+BEGIN_SRC emacs-lisp
1049 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1050 '(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
1051 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1052 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
1053 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1054 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
1055 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1056 ("n" "note" entry (file "~/projects/org-notes/refile.org")
1057 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1058 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
1059 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1060 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1061 "* %?\n%U\n" :clock-in t :clock-resume t)
1062 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
1063 "* TODO Review %c\n%U\n" :immediate-finish t)
1064 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
1065 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1066 ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
1067 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1068 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1069 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1070 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
1071 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1072 ("J" "job" entry (file "~/projects/org-notes/refile.org")
1073 "* 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)
1074 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
1075 "* 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")
1079 ;; Remove empty LOGBOOK drawers on clock out
1080 (defun bh/remove-empty-drawer-on-clock-out ()
1083 (beginning-of-line 0)
1084 (org-remove-empty-drawer-at (point))))
1086 (defun my/org-add-id ()
1089 (if (org-current-level)
1098 ** Org mode key bindings
1099 #+BEGIN_SRC emacs-lisp
1100 ; org mode configuration from http://doc.norang.ca/org-mode.html
1101 ;; Custom Key Bindings
1102 (global-set-key (kbd "<f12>") 'org-agenda)
1103 (global-set-key (kbd "<f5>") 'bh/org-todo)
1104 (global-set-key (kbd "<S-f5>") 'bh/widen)
1105 (global-set-key (kbd "<f7>") 'bh/set-truncate-lines)
1106 (global-set-key (kbd "<f8>") 'org-cycle-agenda-files)
1107 (global-set-key (kbd "<f9> <f9>") 'bh/show-org-agenda)
1108 (global-set-key (kbd "<f9> b") 'bbdb)
1109 (global-set-key (kbd "<f9> c") 'calendar)
1110 (global-set-key (kbd "<f9> f") 'boxquote-insert-file)
1111 (global-set-key (kbd "<f9> h") 'bh/hide-other)
1112 (global-set-key (kbd "<f9> n") 'bh/toggle-next-task-display)
1113 (global-set-key (kbd "<f9> w") 'widen)
1115 ; change the outline mode prefix from C-c @ to C-c C-2
1116 (setq outline-minor-mode-prefix "C-c C-2")
1117 ;(add-hook 'outline-minor-mode-hook
1118 ; (lambda () (local-set-key (kbd "C-c C-2")
1119 ; outline-mode-prefix-map)))
1121 (global-set-key (kbd "<f9> I") 'bh/punch-in)
1122 (global-set-key (kbd "<f9> O") 'bh/punch-out)
1124 (global-set-key (kbd "<f9> o") 'bh/make-org-scratch)
1126 (global-set-key (kbd "<f9> r") 'boxquote-region)
1127 (global-set-key (kbd "<f9> s") 'bh/switch-to-scratch)
1129 (global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
1130 (global-set-key (kbd "<f9> T") 'bh/toggle-insert-inactive-timestamp)
1132 (global-set-key (kbd "<f9> v") 'visible-mode)
1133 (global-set-key (kbd "<f9> l") 'org-toggle-link-display)
1134 (global-set-key (kbd "<f9> SPC") 'bh/clock-in-last-task)
1135 (global-set-key (kbd "C-<f9>") 'previous-buffer)
1136 (global-set-key (kbd "M-<f9>") 'org-toggle-inline-images)
1137 (global-set-key (kbd "C-x n r") 'narrow-to-region)
1138 (global-set-key (kbd "C-<f10>") 'next-buffer)
1139 (global-set-key (kbd "<f11>") 'org-clock-goto)
1140 (global-set-key (kbd "C-<f11>") 'org-clock-in)
1141 (global-set-key (kbd "C-s-<f12>") 'bh/save-then-publish)
1142 (global-set-key (kbd "C-c c") 'org-capture)
1145 ** Utility Functions
1146 #+BEGIN_SRC emacs-lisp
1147 (defun bh/hide-other ()
1150 (org-back-to-heading 'invisible-ok)
1156 (defun bh/set-truncate-lines ()
1157 "Toggle value of truncate-lines and refresh window display."
1159 (setq truncate-lines (not truncate-lines))
1160 ;; now refresh window display (an idiom from simple.el):
1162 (set-window-start (selected-window)
1163 (window-start (selected-window)))))
1165 (defun bh/make-org-scratch ()
1167 (find-file "/tmp/publish/scratch.org")
1168 (gnus-make-directory "/tmp/publish"))
1170 (defun bh/switch-to-scratch ()
1172 (switch-to-buffer "*scratch*"))
1174 (setq org-use-fast-todo-selection t)
1175 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1177 ; create function to create headlines in file. This comes from
1178 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1179 (defun my/org-add-ids-to-headlines-in-file ()
1180 "Add ID properties to all headlines in the current file which
1181 do not already have one."
1183 (org-map-entries 'org-id-get-create))
1184 ; if we wanted to do this to every buffer, do the following:
1185 ; (add-hook 'org-mode-hook
1187 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1190 #+BEGIN_SRC emacs-lisp
1191 (setq org-todo-keywords
1192 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1193 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1195 (setq org-todo-keyword-faces
1196 (quote (("TODO" :foreground "red" :weight bold)
1197 ("NEXT" :foreground "blue" :weight bold)
1198 ("DONE" :foreground "forest green" :weight bold)
1199 ("WAITING" :foreground "orange" :weight bold)
1200 ("HOLD" :foreground "magenta" :weight bold)
1201 ("CANCELLED" :foreground "forest green" :weight bold)
1202 ("MEETING" :foreground "forest green" :weight bold)
1203 ("PHONE" :foreground "forest green" :weight bold))))
1205 (setq org-todo-state-tags-triggers
1206 (quote (("CANCELLED" ("CANCELLED" . t))
1207 ("WAITING" ("WAITING" . t))
1208 ("HOLD" ("WAITING") ("HOLD" . t))
1209 (done ("WAITING") ("HOLD"))
1210 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1211 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1212 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1216 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1217 ; add ids on creation of nodes
1218 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1221 ; resolve clocks after 10 minutes of idle; use xprintidle
1222 ; (setq org-clock-idle-time 10)
1223 ; (setq org-clock-x11idle-program-name "xprintidle")
1225 ; this is from http://doc.norang.ca/org-mode.html#Capture
1226 ; use C-M-r for org mode capture
1227 (global-set-key (kbd "C-M-r") 'org-capture)
1229 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1230 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1231 (org-agenda-files :maxlevel . 9))))
1233 ; Use full outline paths for refile targets - we file directly with IDO
1234 (setq org-refile-use-outline-path t)
1236 ; Targets complete directly with IDO
1237 (setq org-outline-path-complete-in-steps nil)
1239 ; Allow refile to create parent tasks with confirmation
1240 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1242 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1243 ; (setq org-completion-use-ido t)
1244 ; (setq ido-everywhere t)
1245 ; (setq ido-max-directory-size 100000)
1246 ; (ido-mode (quote both))
1247 ; ; Use the current window when visiting files and buffers with ido
1248 ; (setq ido-default-file-method 'selected-window)
1249 ; (setq ido-default-buffer-method 'selected-window)
1250 ; ; Use the current window for indirect buffer display
1251 ; (setq org-indirect-buffer-display 'current-window)
1254 ;;;; Refile settings
1255 ; Exclude DONE state tasks from refile targets
1256 (defun bh/verify-refile-target ()
1257 "Exclude todo keywords with a done state from refile targets"
1258 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1260 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1262 ;; ensure that emacsclient will show just the note to be edited when invoked
1263 ;; from Mutt, and that it will shut down emacsclient once finished;
1264 ;; fallback to legacy behavior when not invoked via org-protocol.
1265 (require 'org-protocol)
1266 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1267 (setq my-org-protocol-flag nil)
1268 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1269 "Delete frame at remember finalization"
1270 (progn (if my-org-protocol-flag (delete-frame))
1271 (setq my-org-protocol-flag nil)))
1272 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1273 "Delete frame at remember refile"
1274 (if my-org-protocol-flag
1276 (setq my-org-protocol-flag nil)
1281 (defadvice org-capture-kill (after delete-frame-at-end activate)
1282 "Delete frame at remember abort"
1283 (progn (if my-org-protocol-flag (delete-frame))
1284 (setq my-org-protocol-flag nil)))
1285 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1286 (setq my-org-protocol-flag t))
1288 (defadvice org-insert-todo-heading (after dla/create-id activate)
1293 (add-to-list 'org-modules 'org-habit)
1295 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1296 (defun open-mail-in-mutt (message)
1297 "Open a mail message in Mutt, using an external terminal.
1299 Message can be specified either by a path pointing inside a
1300 Maildir, or by Message-ID."
1301 (interactive "MPath or Message-ID: ")
1303 (format "faf xterm -e \"%s %s\""
1304 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1306 ;; add support for "mutt:ID" links
1307 (org-add-link-type "mutt" 'open-mail-in-mutt)
1309 (defun my-org-mode-setup ()
1310 ; (load-library "reftex")
1311 (and (buffer-file-name)
1312 (file-exists-p (buffer-file-name))
1314 ; (reftex-parse-all)
1315 (reftex-set-cite-format
1316 '((?b . "[[bib:%l][%l-bib]]")
1317 (?n . "[[notes:%l][%l-notes]]")
1319 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1321 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1322 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1323 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1324 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1326 (add-hook 'org-mode-hook 'my-org-mode-setup)
1328 (defun org-mode-reftex-search ()
1330 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1332 (defun open-research-paper (bibtexkey)
1333 "Open a paper by bibtex key"
1334 (interactive "bibtex key: ")
1337 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1338 (org-add-link-type "papers" 'open-research-paper)
1339 (defun open-research-paper-pdf (bibtexkey)
1340 "Open a paper pdf by bibtex key"
1341 (interactive "bibtex key: ")
1343 (format "%s -p evince_annot %s"
1344 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1345 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1347 (add-to-list 'org-link-abbrev-alist
1349 "~/projects/research/paper_notes.org::#%s"))
1351 ; I pretty much always want hiearchical checkboxes
1352 (setq org-hierachical-checkbox-statistics nil)
1354 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1355 (add-to-list 'org-structure-template-alist
1356 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1359 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1360 (defun my-rtcite-export-handler (path desc format)
1361 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1362 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1363 (match-string 1 path)))
1364 (path (substring path 0 (match-beginning 0))))
1365 (cond ((eq format 'latex)
1367 (equal 0 (search "rtcite:" desc)))
1368 (format "\\cite{%s}" search)
1369 (format "\\cite[%s]{%s}" desc search))))))
1371 (org-add-link-type "rtcite"
1373 'my-rtcite-export-handler)
1377 ** Org Mobile Configuration
1378 #+BEGIN_SRC emacs-lisp
1379 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1380 (when (string= system-name "linnode")
1381 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1382 (setq-default org-directory "/home/don/org-mode/")
1383 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1387 #+BEGIN_SRC emacs-lisp
1388 ;; org mode ical export
1389 (setq org-icalendar-timezone "America/Los_Angeles")
1390 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1391 ;; we already add the id manually
1392 (setq org-icalendar-store-UID t)
1395 ** General Org Babel Configuration
1396 #+BEGIN_SRC emacs-lisp
1397 ;; org babel support
1398 (org-babel-do-load-languages
1399 'org-babel-load-languages
1406 ;; use graphviz-dot for dot things
1407 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1408 ;; org-babel-by-backend
1409 (defmacro org-babel-by-backend (&rest body)
1410 `(case (if (boundp 'backend)
1411 (org-export-backend-name backend)
1414 (defun my/fix-inline-images ()
1415 (when org-inline-image-overlays
1416 (org-redisplay-inline-images)))
1418 (add-hook 'org-babel-after-execute-hook
1419 'my/fix-inline-images)
1422 ** LaTeX configuration
1424 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
1426 #+BEGIN_SRC emacs-lisp
1428 (add-to-list 'org-latex-classes
1430 "\\documentclass[11pt,oneside,article]{memoir}\n"
1431 ("\\section{%s}" . "\\section*{%s}")
1432 ("\\subsection{%s}" . "\\subsection*{%s}")
1433 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1434 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1435 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1437 (setq org-beamer-outline-frame-options "")
1438 (add-to-list 'org-latex-classes
1440 "\\documentclass[ignorenonframetext]{beamer}
1441 [NO-DEFAULT-PACKAGES]
1444 ("\\section{%s}" . "\\section*{%s}")
1445 ("\\subsection{%s}" . "\\subsection*{%s}")
1446 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1447 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1448 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1450 (add-to-list 'org-latex-classes
1452 "\\documentclass[11pt,oneside]{memoir}\n"
1453 ("\\chapter{%s}" . "\\chapter*{%s}")
1454 ("\\section{%s}" . "\\section*{%s}")
1455 ("\\subsection{%s}" . "\\subsection*{%s}")
1456 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1458 (add-to-list 'org-latex-classes
1460 "\\documentclass[11pt]{letter}
1461 [NO-DEFAULT-PACKAGES]
1464 ("\\section{%s}" . "\\section*{%s}")
1465 ("\\subsection{%s}" . "\\subsection*{%s}")
1466 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1467 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1468 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1470 (add-to-list 'org-latex-classes
1472 "\\documentclass{dlacv}
1473 [NO-DEFAULT-PACKAGES]
1476 ("\\section{%s}" . "\\section*{%s}")
1477 ("\\subsection{%s}" . "\\subsection*{%s}")
1478 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1479 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1480 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1483 (add-to-list 'org-latex-classes
1485 "\\documentclass{dlaresume}
1486 [NO-DEFAULT-PACKAGES]
1489 ("\\section{%s}" . "\\section*{%s}")
1490 ("\\subsection{%s}" . "\\subsection*{%s}")
1491 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1492 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1493 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1496 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
1497 ;; but adapted to use latexmk 4.22 or higher.
1498 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
1500 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
1501 (setq org-latex-default-packages-alist
1503 ("" "unicode-math" t)
1505 (setq org-latex-packages-alist
1512 ("" "longtable" nil)
1515 ;; make equations larger
1516 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
1518 (defun org-create-formula--latex-header ()
1519 "Return LaTeX header appropriate for previewing a LaTeX snippet."
1520 (let ((info (org-combine-plists (org-export--get-global-options
1521 (org-export-get-backend 'latex))
1522 (org-export--get-inbuffer-options
1523 (org-export-get-backend 'latex)))))
1524 (org-latex-guess-babel-language
1525 (org-latex-guess-inputenc
1526 (org-splice-latex-header
1527 org-format-latex-header
1528 org-latex-default-packages-alist
1530 (plist-get info :latex-header)))
1534 ; support ignoring headers in org mode export to latex
1535 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
1536 (defadvice org-latex-headline (around my-latex-skip-headlines
1537 (headline contents info) activate)
1538 (if (member "ignoreheading" (org-element-property :tags headline))
1539 (setq ad-return-value contents)
1542 ;; keep latex logfiles
1544 (setq org-latex-remove-logfiles nil)
1546 ;; Resume clocking task when emacs is restarted
1547 (org-clock-persistence-insinuate)
1549 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
1550 (setq org-clock-history-length 23)
1551 ;; Resume clocking task on clock-in if the clock is open
1552 (setq org-clock-in-resume t)
1553 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
1554 ;; there are things like PHONE calls
1555 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
1556 ;; Separate drawers for clocking and logs
1557 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
1558 ;; Save clock data and state changes and notes in the LOGBOOK drawer
1559 (setq org-clock-into-drawer t)
1560 (setq org-log-into-drawer t)
1561 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
1562 (setq org-clock-out-remove-zero-time-clocks t)
1563 ;; Clock out when moving task to a done state
1564 (setq org-clock-out-when-done t)
1565 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
1566 (setq org-clock-persist t)
1567 ;; Do not prompt to resume an active clock
1568 (setq org-clock-persist-query-resume nil)
1569 ;; Enable auto clock resolution for finding open clocks
1570 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
1571 ;; Include current clocking task in clock reports
1572 (setq org-clock-report-include-clocking-task t)
1574 ;; the cache seems to be broken
1575 (setq org-element-use-cache nil)
1577 (defvar bh/keep-clock-running nil)
1579 (defun bh/is-task-p ()
1580 "Any task with a todo keyword and no subtask"
1584 (subtree-end (save-excursion (org-end-of-subtree t)))
1585 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1588 (while (and (not has-subtask)
1589 (< (point) subtree-end)
1590 (re-search-forward "^\*+ " subtree-end t))
1591 (when (member (org-get-todo-state) org-todo-keywords-1)
1592 (setq has-subtask t))))
1593 (and is-a-task (not has-subtask)))))
1594 (defun bh/is-project-p ()
1595 "Any task with a todo keyword subtask"
1599 (subtree-end (save-excursion (org-end-of-subtree t)))
1600 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1603 (while (and (not has-subtask)
1604 (< (point) subtree-end)
1605 (re-search-forward "^\*+ " subtree-end t))
1606 (when (member (org-get-todo-state) org-todo-keywords-1)
1607 (setq has-subtask t))))
1608 (and is-a-task has-subtask))))
1610 (defun bh/is-subproject-p ()
1611 "Any task which is a subtask of another project"
1612 (let ((is-subproject)
1613 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
1615 (while (and (not is-subproject) (org-up-heading-safe))
1616 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1617 (setq is-subproject t))))
1618 (and is-a-task is-subproject)))
1621 (defun bh/clock-in-to-next (kw)
1622 "Switch a task from TODO to NEXT when clocking in.
1623 Skips capture tasks, projects, and subprojects.
1624 Switch projects and subprojects from NEXT back to TODO"
1625 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
1627 ((and (member (org-get-todo-state) (list "TODO"))
1630 ((and (member (org-get-todo-state) (list "NEXT"))
1634 (defun bh/punch-in (arg)
1635 "Start continuous clocking and set the default task to the
1636 selected task. If no task is selected set the Organization task
1637 as the default task."
1639 (setq bh/keep-clock-running t)
1640 (if (equal major-mode 'org-agenda-mode)
1642 ;; We're in the agenda
1644 (let* ((marker (org-get-at-bol 'org-hd-marker))
1645 (tags (org-with-point-at marker (org-get-tags-at))))
1646 (if (and (eq arg 4) tags)
1647 (org-agenda-clock-in '(16))
1648 (bh/clock-in-organization-task-as-default)))
1650 ;; We are not in the agenda
1654 ; Find the tags on the current task
1655 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
1656 (org-clock-in '(16))
1657 (bh/clock-in-organization-task-as-default)))))
1659 (defun bh/punch-out ()
1661 (setq bh/keep-clock-running nil)
1662 (when (org-clock-is-active)
1664 (org-agenda-remove-restriction-lock))
1666 (defun bh/clock-in-default-task ()
1668 (org-with-point-at org-clock-default-task
1671 (defun bh/clock-in-parent-task ()
1672 "Move point to the parent (project) task if any and clock in"
1673 (let ((parent-task))
1677 (while (and (not parent-task) (org-up-heading-safe))
1678 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
1679 (setq parent-task (point))))
1681 (org-with-point-at parent-task
1683 (when bh/keep-clock-running
1684 (bh/clock-in-default-task)))))))
1686 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
1688 (defun bh/clock-in-organization-task-as-default ()
1690 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
1691 (org-clock-in '(16))))
1693 (defun bh/clock-out-maybe ()
1694 (when (and bh/keep-clock-running
1695 (not org-clock-clocking-in)
1696 (marker-buffer org-clock-default-task)
1697 (not org-clock-resolving-clocks-due-to-idleness))
1698 (bh/clock-in-parent-task)))
1700 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
1703 (defun bh/clock-in-task-by-id (id)
1704 "Clock in a task by id"
1705 (org-with-point-at (org-id-find id 'marker)
1706 (org-clock-in nil)))
1708 (defun bh/clock-in-last-task (arg)
1709 "Clock in the interrupted task if there is one
1710 Skip the default task and get the next one.
1711 A prefix arg forces clock in of the default task."
1713 (let ((clock-in-to-task
1715 ((eq arg 4) org-clock-default-task)
1716 ((and (org-clock-is-active)
1717 (equal org-clock-default-task (cadr org-clock-history)))
1718 (caddr org-clock-history))
1719 ((org-clock-is-active) (cadr org-clock-history))
1720 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
1721 (t (car org-clock-history)))))
1723 (org-with-point-at clock-in-to-task
1724 (org-clock-in nil))))
1727 (defun org-export-to-ods ()
1729 (let ((csv-file "data.csv"))
1730 (org-table-export csv-file "orgtbl-to-csv")
1731 (org-odt-convert csv-file "ods" 'open)))
1733 ; allow for zero-width-space to be a break in regexp too
1734 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
1735 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
1736 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
1738 ;; support inserting screen shots
1739 (defun my/org-insert-screenshot ()
1740 "Take a screenshot into a time stamped unique-named file in the
1741 same directory as the org-buffer and insert a link to this file."
1743 (defvar my/org-insert-screenshot/filename)
1744 (setq my/org-insert-screenshot/filename
1746 "Screenshot to insert: "
1748 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
1751 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
1752 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
1753 (org-display-inline-images))
1755 (defun my/fix-inline-images ()
1756 (when org-inline-image-overlays
1757 (org-redisplay-inline-images)))
1759 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
1761 ;; use xelatex to preview with imagemagick
1762 (add-to-list 'org-preview-latex-process-alist
1763 '(xelateximagemagick
1764 :programs ("xelatex" "convert")
1765 :description "pdf > png"
1766 :message "you need to install xelatex and imagemagick"
1768 :image-input-type "pdf"
1769 :image-output-type "png"
1770 :image-size-adjust (1.0 . 1.0)
1771 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
1772 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
1774 ;; use xelatex by default
1775 (setq org-preview-latex-default-process 'xelateximagemagick)
1777 ; from http://orgmode.org/Changes.html
1778 (defun my/org-repair-property-drawers ()
1779 "Fix properties drawers in current buffer.
1780 Ignore non Org buffers."
1782 (when (eq major-mode 'org-mode)
1783 (org-with-wide-buffer
1784 (goto-char (point-min))
1785 (let ((case-fold-search t)
1786 (inline-re (and (featurep 'org-inlinetask)
1787 (concat (org-inlinetask-outline-regexp)
1791 (unless (and inline-re (org-looking-at-p inline-re))
1793 (let ((end (save-excursion (outline-next-heading) (point))))
1795 (when (org-looking-at-p org-planning-line-re) (forward-line))
1796 (when (and (< (point) end)
1797 (not (org-looking-at-p org-property-drawer-re))
1799 (and (re-search-forward org-property-drawer-re end t)
1800 (eq (org-element-type
1801 (save-match-data (org-element-at-point)))
1803 (insert (delete-and-extract-region
1805 (min (1+ (match-end 0)) end)))
1806 (unless (bolp) (insert "\n"))))))))))))
1810 #+BEGIN_SRC emacs-lisp
1814 (use-package calfw-org
1817 (use-package org-gcal
1819 :config '((if (file-readable-p "~/.hide/org_gcal.el")
1820 (load-file "~/.hide/org_gcal.el"))
1825 #+BEGIN_SRC emacs-lisp
1828 ;; Show notification 10 minutes before event
1829 (setq appt-message-warning-time 10)
1830 ;; Disable multiple reminders
1831 (setq appt-display-interval appt-message-warning-time)
1832 (setq appt-display-mode-line nil)
1834 ;; add automatic reminders for appointments
1835 (defun my/org-agenda-to-appt ()
1837 (setq appt-time-msg-list nil)
1838 (org-agenda-to-appt))
1839 ;; add reminders when starting emacs
1840 (my/org-agenda-to-appt)
1841 ;; when rebuilding the agenda
1842 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
1843 "Pressing `r' on the agenda will also add appointments."
1844 (my/org-agenda-to-appt)
1846 ;; when saving all org buffers
1847 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
1848 "Re-add appts after saving all org buffers"
1849 (my/org-agenda-to-appt))
1850 ;; Display appointments as a window manager notification
1851 (setq appt-disp-window-function 'my/appt-display)
1852 (setq appt-delete-window-function (lambda () t))
1854 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
1856 (defun my/appt-display (min-to-app new-time msg)
1857 (if (atom min-to-app)
1858 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
1859 (dolist (i (number-sequence 0 (1- (length min-to-app))))
1860 (start-process "my/appt-notification-app" nil my/appt-notification-app
1861 (nth i min-to-app) (nth i msg))))
1868 #+BEGIN_SRC emacs-lisp
1872 ** Override other things
1873 #+BEGIN_SRC emacs-lisp
1874 ; apparently things like to step on C-;, so we'll use a hack from
1875 ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
1877 (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
1880 (define-key my-keys-minor-mode-map (kbd "C-;") 'mc/mark-all-dwim)
1881 ;; use outline mode keybindings everywhere
1882 ;; (define-key my-keys-minor-mode-map (kbd "C-;") 'my/mydra-outline/body)
1884 (define-minor-mode my-keys-minor-mode
1885 "A minor mode so that my key settings override annoying major modes."
1886 t " my-keys" 'my-keys-minor-mode-map)
1888 (my-keys-minor-mode 1)
1889 (defun my-minibuffer-setup-hook ()
1890 (my-keys-minor-mode 0))
1892 (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
1893 (defadvice load (after give-my-keybindings-priority)
1894 "Try to ensure that my keybindings always have priority."
1895 (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
1896 (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
1897 (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
1898 (add-to-list 'minor-mode-map-alist mykeys))))
1902 #+BEGIN_SRC emacs-lisp
1903 (global-unset-key "\M-g")
1904 (global-set-key (kbd "M-g l") 'goto-line)
1908 #+BEGIN_SRC emacs-lisp
1909 (use-package debian-changelog
1910 :mode "debian/changelog"
1912 (setq debian-changelog-mailing-address "don@debian.org")
1913 (setq debian-changelog-full-name "Don Armstrong"))
1915 * Misc (uncharacterized)
1916 #+BEGIN_SRC emacs-lisp
1917 (setq calendar-latitude 38.6)
1918 (setq calendar-longitude -121.5)
1919 (setq case-fold-search t)
1920 (setq confirm-kill-emacs (quote y-or-n-p))
1921 (setq cperl-lazy-help-time nil)
1923 (setq display-time-24hr-format t)
1924 (setq display-time-day-and-date t)
1925 (display-time-mode 1)
1926 (global-font-lock-mode 1)
1928 (setq log-edit-keep-buffer t)
1929 (setq mail-user-agent (quote sendmail-user-agent))
1930 (setq markdown-enable-math t)
1931 (setq markdown-follow-wiki-link-on-enter nil)
1932 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
1933 (setq ps-footer-font-size (quote (8 . 10)))
1934 (setq ps-header-font-size (quote (8 . 10)))
1935 (setq ps-header-title-font-size (quote (10 . 10)))
1936 (setq ps-line-number-color "blue")
1937 (setq ps-print-footer t)
1938 (setq ps-print-footer-frame nil)
1939 (setq ps-print-only-one-header t)
1940 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
1942 (setq sentence-end-double-space nil)
1943 ; enable matching parenthesis
1946 (setq user-mail-address "don@donarmstrong.com")
1947 (setq vc-delete-logbuf-window nil)
1948 (setq vc-follow-symlinks t)
1950 ;; use git before SVN; use CVS earlier, because I have CVS
1951 ;; repositories inside of git directories
1952 (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
1954 ;; switch back to the old primary selection method
1955 (setq x-select-enable-clipboard nil)
1956 (setq x-select-enable-primary t)
1957 ; (setq mouse-drag-copy-region t)
1959 (fset 'perl-mode 'cperl-mode)
1960 ;;(load-file "cperl-mode.el")
1964 (global-set-key "\C-xp" 'server-edit)
1966 (setq-default auto-mode-alist (cons '("\.wml$" .
1967 (lambda () (html-mode) (auto-fill-mode)))
1971 ; use markdown mode for mdwn files
1972 (add-to-list 'auto-mode-alist '("\\.mdwn$" . markdown-mode))
1973 (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
1976 ;; tramp configuration
1977 (setq tramp-use-ssh-controlmaster-options nil)
1979 ;; self-insert-command hack.
1980 ;; Without this, "if<SP>" expands to
1983 ;; which really should be,
1989 ;(load-library "php-mode")
1991 (setq-default c-indent-level 4)
1992 (setq-default c-brace-imaginary-offset 0)
1993 (setq-default c-brace-offset -4)
1994 (setq-default c-argdecl-indent 4)
1995 (setq-default c-label-offset -4)
1996 (setq-default c-continued-statement-offset 4)
1998 (setq-default indent-tabs-mode nil)
1999 (setq-default tab-width 4)
2002 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2003 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2004 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2005 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2006 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2009 (defun insert-date ()
2010 "Insert date at point."
2012 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2013 (global-set-key "\C-[d" 'insert-date)
2015 (defun unfill-paragraph (arg)
2016 "Pull this whole paragraph up onto one line."
2018 (let ((fill-column 10000))
2019 (fill-paragraph arg))
2022 (column-number-mode t)
2024 ; (require 'mode-compile)
2026 (defadvice server-process-filter (after post-mode-message first activate)
2027 "If the buffer is in post mode, overwrite the server-edit
2028 message with a post-save-current-buffer-and-exit message."
2029 (if (eq major-mode 'post-mode)
2031 (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
2032 ; This is also needed to see the magic message. Set to a higher
2033 ; number if you have a faster computer or read slower than me.
2034 '(font-lock-verbose 1000)
2035 ;(setq-default server-temp-file-regexp "mutt\(-\|ng-\)")
2036 ; (add-hook 'server-switch-hook
2037 ; (function (lambda()
2038 ; (cond ((string-match "Post" mode-name)
2039 ; (post-goto-body)))
2040 ; set-buffer-file-coding-system 'utf-8
2044 (add-hook 'post-mode-hook
2045 (auto-fill-mode nil)
2047 ; abbrev mode settings
2048 ; load abbreviations from
2049 (setq abbrev-file-name
2050 "~/.emacs_abbrev_def")
2052 ; read the abbrev file if it exists
2053 (if (file-exists-p abbrev-file-name)
2054 (quietly-read-abbrev-file))
2056 ; for now, use abbrev mode everywhere
2057 (setq default-abbrev-mode t)
2060 (defun insert-function-documentation ()
2061 "Insert function documentation"
2063 (insert-file-contents "/home/don/lib/templates/perl_function_documentation" nil))
2064 (global-set-key "\M-f" 'insert-function-documentation)
2066 (eval-after-load "lilypond-mode"
2068 (load-library "lyqi-mode")
2069 (define-key LilyPond-mode-map "\C-cq" 'lyqi-mode)))
2071 (autoload 'spamassassin-mode "spamassassin-mode" nil t)
2073 (desktop-load-default)
2075 '(icomplete-mode on)
2077 ;; custom-set-faces was added by Custom.
2078 ;; If you edit it by hand, you could mess it up, so be careful.
2079 ;; Your init file should contain only one such instance.
2080 ;; If there is more than one, they won't work right.
2081 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2084 (put 'upcase-region 'disabled nil)
2085 (put 'downcase-region 'disabled nil)
2086 (put 'narrow-to-region 'disabled nil)
2088 ; (defun turn-on-flyspell ()
2089 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2091 ; (flyspell-mode 1))
2094 ; Outline-minor-mode key map
2095 (define-prefix-command 'cm-map nil "Outline-")
2097 (define-key cm-map "q" 'hide-sublevels) ; Hide everything but the top-level headings
2098 (define-key cm-map "t" 'hide-body) ; Hide everything but headings (all body lines)
2099 (define-key cm-map "o" 'hide-other) ; Hide other branches
2100 (define-key cm-map "c" 'hide-entry) ; Hide this entry's body
2101 (define-key cm-map "l" 'hide-leaves) ; Hide body lines in this entry and sub-entries
2102 (define-key cm-map "d" 'hide-subtree) ; Hide everything in this entry and sub-entries
2104 (define-key cm-map "a" 'show-all) ; Show (expand) everything
2105 (define-key cm-map "e" 'show-entry) ; Show this heading's body
2106 (define-key cm-map "i" 'show-children) ; Show this heading's immediate child sub-headings
2107 (define-key cm-map "k" 'show-branches) ; Show all sub-headings under this heading
2108 (define-key cm-map "s" 'show-subtree) ; Show (expand) everything in this heading & below
2110 (define-key cm-map "u" 'outline-up-heading) ; Up
2111 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2112 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2113 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2114 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2115 (global-set-key "\M-o" cm-map)
2117 ; ediff configuration
2118 ; don't use the multi-window configuration
2119 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
2121 ; fix up css mode to not be silly
2122 ; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
2123 (setq cssm-indent-level 4)
2124 (setq cssm-newline-before-closing-bracket t)
2125 (setq cssm-indent-function #'cssm-c-style-indenter)
2126 (setq cssm-mirror-mode nil)
2128 (require 'multi-web-mode)
2129 (setq mweb-default-major-mode 'html-mode)
2130 (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
2131 (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
2132 (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
2133 (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
2134 (multi-web-global-mode 1)
2136 ;;; alias the new `flymake-report-status-slim' to
2137 ;;; `flymake-report-status'
2138 (defalias 'flymake-report-status 'flymake-report-status-slim)
2139 (defun flymake-report-status-slim (e-w &optional status)
2140 "Show \"slim\" flymake status in mode line."
2142 (setq flymake-mode-line-e-w e-w))
2144 (setq flymake-mode-line-status status))
2145 (let* ((mode-line " Φ"))
2146 (when (> (length flymake-mode-line-e-w) 0)
2147 (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
2148 (setq mode-line (concat mode-line flymake-mode-line-status))
2149 (setq flymake-mode-line mode-line)
2150 (force-mode-line-update)))
2152 ; load sql-indent when sql is loaded
2153 (eval-after-load "sql"
2154 '(load-library "sql-indent"))
2156 ; fix up tmux xterm keys
2157 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2158 (defun fix-up-tmux-keys ()
2159 "Fix up tmux xterm keys"
2162 (let ((x 2) (tkey ""))
2182 ;; ctrl + alt + shift
2184 (setq tkey "C-M-S-"))
2187 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2188 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2189 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2190 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2192 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2194 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2196 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2198 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2200 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2202 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2204 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2206 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2208 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2210 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2212 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2214 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2216 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2218 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2220 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2222 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2224 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2226 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2228 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2230 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2232 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2234 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2236 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2238 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2240 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2242 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2249 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2251 ; procmailmode configuration
2252 (load "procmail_mode")
2254 (load "mode-line-cleaner")
2256 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2257 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2258 (if (or (buffer-modified-p)
2259 (verify-visited-file-modtime)
2260 (< (* 8 1024 1024) (buffer-size))
2261 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2263 (clear-visited-file-modtime)
2265 (ad-activate 'ask-user-about-supersession-threat)
2267 ; apparently things like to step on C-;, so we'll use a hack from
2268 ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
2270 (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
2272 ; use iedit everywhere
2273 (define-key my-keys-minor-mode-map (kbd "C-;") 'mc/mark-all-dwim)
2275 (define-minor-mode my-keys-minor-mode
2276 "A minor mode so that my key settings override annoying major modes."
2277 t " my-keys" 'my-keys-minor-mode-map)
2279 (my-keys-minor-mode 1)
2280 (defun my-minibuffer-setup-hook ()
2281 (my-keys-minor-mode 0))
2283 (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
2284 (defadvice load (after give-my-keybindings-priority)
2285 "Try to ensure that my keybindings always have priority."
2286 (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
2287 (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
2288 (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
2289 (add-to-list 'minor-mode-map-alist mykeys))))
2291 (global-set-key "\M- " 'hippie-expand)
2296 #+BEGIN_SRC emacs-lisp
2297 (unless (server-running-p)
2304 #+BEGIN_SRC emacs-lisp
2305 (provide 'don-configuration)