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
32 ;; add /etc/ssl/ca-global/ca-certificates.crt so that we can
33 ;; download packages when we're on Debian hosts which chop down the
34 ;; list of available certificates
35 (add-to-list 'gnutls-trustfiles "/etc/ssl/ca-global/ca-certificates.crt")
36 (setq package-enable-at-startup nil)
37 (setq package--init-file-ensured t)
38 (setq package-user-dir "~/var/emacs/elpa")
39 (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
40 ("melpa" . "https://melpa.org/packages/")
41 ("org" . "http://orgmode.org/elpa/")))
42 (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
43 (mapc #'(lambda (add) (add-to-list 'load-path add))
46 (unless (package-installed-p 'use-package)
47 (package-refresh-contents)
48 (package-install 'use-package))
49 (let ((package-user-dir-real (file-truename package-user-dir)))
50 ;; The reverse is necessary, because outside we mapc
51 ;; add-to-list element-by-element, which reverses.
52 (nreverse (apply #'nconc
53 ;; Only keep package.el provided loadpaths.
54 (mapcar #'(lambda (path)
55 (if (string-prefix-p package-user-dir-real path)
60 ;;; fix up info paths for packages
61 (with-eval-after-load "info"
63 (dolist (dir (directory-files package-user-dir))
64 (let ((fdir (concat (file-name-as-directory package-user-dir) dir)))
65 (unless (or (member dir '("." ".." "archives" "gnupg"))
66 (not (file-directory-p fdir))
67 (not (file-exists-p (concat (file-name-as-directory fdir) "dir"))))
68 (add-to-list 'Info-directory-list fdir)))))
72 (require 'use-package))
77 #+BEGIN_SRC emacs-lisp
80 :commands (paradox-upgrade-packages paradox-list-packages)
81 :config (setq paradox-execute-asynchronously t)
86 #+BEGIN_SRC emacs-lisp
87 (add-to-list 'load-path '"~/lib/emacs_el/")
88 (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
91 #+BEGIN_SRC emacs-lisp
92 ;; Set the custom file to /dev/null and don't bother to load it
93 (setq custom-file "/dev/null")
97 #+BEGIN_SRC emacs-lisp
98 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
99 ;; execute conditional code when loading libraries
100 (defmacro with-library (symbol &rest body)
101 `(when (require ,symbol nil t)
103 (put 'with-library 'lisp-indent-function 1)
107 ** Safe Local Variables
108 #+BEGIN_SRC emacs-lisp
109 (setq safe-local-variable-values
110 (quote ((auto-save-default)
112 (cperl-indent-level . 4)
114 (indent-tabs-mode . f)
118 #+BEGIN_SRC emacs-lisp
119 (setq global-mark-ring-max 128
123 (defun don/minibuffer-setup-hook ()
124 (setq gc-cons-threshold most-positive-fixnum))
126 (defun don/minibuffer-exit-hook ()
127 (setq gc-cons-threshold 1048576))
129 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
130 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
134 #+BEGIN_SRC emacs-lisp
135 (use-package hippie-exp
136 :bind* (("M-<SPC>" . hippie-expand))
140 #+BEGIN_SRC emacs-lisp
141 (use-package flyspell
143 :diminish flyspell-mode 🐝
145 (add-hook 'text-mode-hook 'turn-on-flyspell)
146 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
147 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
148 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
150 (setq ispell-program-name "ispell")
155 #+begin_src emacs-lisp :tangle yes
161 #+BEGIN_SRC emacs-lisp
166 #+BEGIN_SRC emacs-lisp
167 (use-package eyebrowse
169 :diminish eyebrowse-mode
170 :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
172 (setq eyebrowse-wrap-around t)
175 (defun my/eyebrowse-new-window-config ()
179 ;; start at 1 run till 0
180 (let ((j (mod (+ i 1) 10)))
181 (when (and (not done)
182 (not (eyebrowse--window-config-present-p j)))
183 (eyebrowse-switch-to-window-config j)
184 (call-interactively 'eyebrowse-rename-window-config2 j)
189 ;; I don't use latex-preview-pane
190 ;; (require 'latex-preview-pane)
191 ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
192 ;; ;; latex-preview-pane uses window-parameters which are
193 ;; ;; not preserved by eyebrowse, so we close the preview
194 ;; ;; pane before switching, it will be regenerated when we
195 ;; ;; edit the TeX file.
196 ;; (when (lpp/window-containing-preview)
197 ;; (delete-window (lpp/window-containing-preview))))
199 ;; (add-to-list 'eyebrowse-pre-window-switch-hook
200 ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
202 ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
203 ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
204 ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
205 ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
206 ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
214 #+BEGIN_SRC emacs-lisp
215 (defun my/vsplit-last-buffer ()
216 "Split the window vertically and display the previous buffer."
218 (split-window-vertically)
220 (switch-to-next-buffer))
222 (defun my/hsplit-last-buffer ()
223 "Split the window horizontally and display the previous buffer."
225 (split-window-horizontally)
227 (switch-to-next-buffer))
229 (bind-key "C-x 2" 'my/vsplit-last-buffer)
230 (bind-key "C-x 3" 'my/hsplit-last-buffer)
232 (setq split-width-threshold 100)
233 (setq split-height-threshold 60)
235 (defun my/split-window-prefer-vertically (window)
236 "If there's only one window (excluding any possibly active
237 minibuffer), then split the current window horizontally."
238 (if (and (one-window-p t)
239 (not (active-minibuffer-window))
240 ( < (frame-width) (frame-height))
242 (let ((split-width-threshold nil))
243 (split-window-sensibly window))
244 (split-window-sensibly window)))
246 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
247 (setq window-combination-resize t)
250 *** Compilation window
252 If there is no compilation window, open one at the bottom, spanning
253 the complete width of the frame. Otherwise, reuse existing window. In
254 the former case, if there was no error the window closes
257 #+BEGIN_SRC emacs-lisp
258 (add-to-list 'display-buffer-alist
259 `(,(rx bos "*compilation*" eos)
260 (display-buffer-reuse-window
261 display-buffer-in-side-window)
262 (reusable-frames . visible)
264 (window-height . 0.4)))
267 #+BEGIN_SRC emacs-lisp
268 (defun my/compilation-exit-autoclose (status code msg)
269 ;; If M-x compile exists with a 0
270 (when (and (eq status 'exit) (zerop code))
271 ;; and delete the *compilation* window
272 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
273 (when (and (not (window-at-side-p compilation-window 'top))
274 (window-at-side-p compilation-window 'left)
275 (window-at-side-p compilation-window 'right))
276 (delete-window compilation-window))))
277 ;; Always return the anticipated result of compilation-exit-message-function
280 ;; Specify my function (maybe I should have done a lambda function)
281 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
284 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
285 value, the compilation buffer scrolls automatically to follow the
286 output. If the value is ~first-error~, scrolling stops when the first
287 error appears, leaving point at that error. For any other non-nil
288 value, scrolling continues until there is no more output.
290 #+BEGIN_SRC emacs-lisp
291 (setq compilation-scroll-output 'first-error)
294 ** Mode line cleaning
296 #+BEGIN_SRC emacs-lisp
297 (use-package diminish
302 #+BEGIN_SRC emacs-lisp
309 #+BEGIN_SRC emacs-lisp
312 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
313 ("C-c j j" . avy-goto-word-or-subword-1)
314 ("M-g g" . avy-goto-line))
315 :config (progn (setq avy-background t))
318 *** Ace-link (jumping to links)
319 #+BEGIN_SRC emacs-lisp
320 (use-package ace-link
322 ; bind o in most modes
323 :config (ace-link-setup-default))
325 *** Jumping through edit points (goto-chg)
326 #+BEGIN_SRC emacs-lisp
327 (use-package goto-chg
329 :bind (("C-c j ," . goto-last-change)
330 ("C-c j ." . goto-last-change-reverse))
333 *** Jumping to bookmarks (visible bookmarks, bm)
334 #+BEGIN_SRC emacs-lisp
337 :bind (("C-c j b ." . bm-next)
338 ("C-c j b ," . bm-previous)
339 ("C-c j b SPC" . bm-toggle)))
344 #+BEGIN_SRC emacs-lisp
345 (use-package yasnippet
347 :diminish yas-minor-mode
350 (setq yas-verbosity 1)
351 (define-key yas-minor-mode-map (kbd "<tab>") nil)
352 (define-key yas-minor-mode-map (kbd "TAB") nil)
353 (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
354 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
355 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
356 (add-to-list 'hippie-expand-try-functions-list
357 'yas-hippie-try-expand)
363 #+BEGIN_SRC emacs-lisp
364 (use-package auto-yasnippet
366 :bind (("H-w" . aya-create)
372 #+BEGIN_SRC emacs-lisp
375 :bind (("M-/" . company-complete))
377 (setq company-echo-delay 0 ; remove blinking
378 company-show-numbers t ; show numbers for easy selection
379 company-selection-wrap-around t
380 company-require-match nil
381 company-dabbrev-ignore-case t
382 company-dabbrev-ignore-invisible t
383 company-dabbrev-other-buffers t
384 company-dabbrev-downcase nil
385 company-dabbrev-code-everywhere t
386 company-tooltip-align-annotations t
387 company-minimum-prefix-length 1
388 company-global-modes '(not)
389 company-lighter-base "(C)")
390 (global-company-mode 1)
392 (bind-key "C-n" #'company-select-next company-active-map)
393 (bind-key "C-p" #'company-select-previous company-active-map)
394 ; (bind-key "<tab>" #'company-complete company-active-map)
395 (bind-key "M-?" #'company-show-doc-buffer company-active-map)
396 (bind-key "M-." #'company-show-location company-active-map)
397 (bind-key "M-/" #'company-complete-common org-mode-map)
401 #+BEGIN_SRC emacs-lisp
402 (use-package company-c-headers
405 (defun malb/ede-object-system-include-path ()
406 "Return the system include path for the current buffer."
408 (ede-system-include-path ede-object)))
410 (setq company-c-headers-path-system
411 #'malb/ede-object-system-include-path)
413 (add-to-list 'company-backends #'company-c-headers)))
416 #+BEGIN_SRC emacs-lisp
417 (use-package company-anaconda
419 :config (add-to-list 'company-backends #'company-anaconda))
422 #+BEGIN_SRC emacs-lisp
423 (use-package company-plsense
428 #+BEGIN_SRC emacs-lisp
429 (use-package company-math
432 #+BEGIN_SRC emacs-lisp
433 (use-package company-auctex
436 (defun company-auctex-labels (command &optional arg &rest ignored)
437 "company-auctex-labels backend"
438 (interactive (list 'interactive))
440 (interactive (company-begin-backend 'company-auctex-labels))
441 (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
442 (candidates (company-auctex-label-candidates arg))))
444 (add-to-list 'company-backends
445 '(company-auctex-macros
446 company-auctex-environments
447 company-math-symbols-unicode
448 company-math-symbols-latex))
450 (add-to-list 'company-backends #'company-auctex-labels)
451 (add-to-list 'company-backends #'company-auctex-bibs)
455 #+BEGIN_SRC emacs-lisp
456 (use-package company-bibtex
462 #+BEGIN_SRC emacs-lisp
463 (use-package company-shell
466 (setq company-shell-modes '(sh-mode shell-mode))
467 (add-to-list 'company-backends 'company-shell)))
472 Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
474 *Note:* Do this at the end of =company-mode= config.
476 #+BEGIN_SRC emacs-lisp
477 (defvar malb/company-mode/enable-yas t
478 "Enable yasnippet for all backends.")
480 (defun malb/company-mode/backend-with-yas (backend)
481 (if (or (not malb/company-mode/enable-yas)
483 (member 'company-yasnippet backend)))
485 (append (if (consp backend) backend (list backend))
486 '(:with company-yasnippet))))
488 (setq company-backends
489 (mapcar #'malb/company-mode/backend-with-yas company-backends))
494 Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
496 #+BEGIN_SRC emacs-lisp
497 (defun malb/toggle-company-ispell ()
500 ((member '(company-ispell :with company-yasnippet) company-backends)
501 (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
502 (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
503 (message "company-ispell disabled"))
505 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
506 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
507 (message "company-ispell enabled!"))))
509 (defun malb/company-ispell-setup ()
510 ;; @see https://github.com/company-mode/company-mode/issues/50
511 (when (boundp 'company-backends)
512 (make-local-variable 'company-backends)
513 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
514 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
515 ;; https://github.com/redguardtoo/emacs.d/issues/473
516 (if (and (boundp 'ispell-alternate-dictionary)
517 ispell-alternate-dictionary)
518 (setq company-ispell-dictionary ispell-alternate-dictionary))))
523 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
525 2. This function then hopefully does what I want:
527 a. if a region is active, just indent
528 b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
529 c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
530 d. otherwise call whatever would have been called otherwise.
532 ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
534 #+BEGIN_SRC emacs-lisp
535 (defun malb/indent-fold-or-complete (&optional arg)
538 ;; if a region is active, indent
540 (indent-region (region-beginning)
542 ;; if the next char is space or eol, but prev char not whitespace
543 ((and (not (active-minibuffer-window))
546 (looking-back "[^[:space:]]")
547 (not (looking-back "^")))
549 (cond (company-mode (company-complete-common))
550 (auto-complete-mode (auto-complete))))
552 ;; no whitespace anywhere
553 ((and (not (active-minibuffer-window))
554 (looking-at "[^[:space:]]")
555 (looking-back "[^[:space:]]")
556 (not (looking-back "^")))
558 ((bound-and-true-p hs-minor-mode)
559 (save-excursion (end-of-line) (hs-toggle-hiding)))
560 ((bound-and-true-p outline-minor-mode)
561 (save-excursion (outline-cycle)))))
563 ;; by default just call whatever was bound
565 (let ((fn (or (lookup-key (current-local-map) (kbd "TAB"))
566 'indent-for-tab-command)))
567 (if (not (called-interactively-p 'any))
569 (setq this-command fn)
570 (call-interactively fn))))))
572 (defun malb/toggle-fold ()
574 (cond ((eq major-mode 'org-mode)
575 (org-force-cycle-archived))
576 ((bound-and-true-p hs-minor-mode)
581 ((bound-and-true-p outline-minor-mode)
585 (bind-key "<tab>" #'malb/indent-fold-or-complete)
586 (bind-key "C-<tab>" #'malb/toggle-fold)
590 #+BEGIN_SRC emacs-lisp
592 (use-package tinyprocmail
593 :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
594 :mode (".procmailrc" . turn-on-tinyprocmail-mode)
599 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
602 :bind (("C-x g" . magit-status)
603 ("C-x C-g" . magit-status))
605 ;; refine diffs always (hilight words)
606 (setq magit-diff-refine-hunk nil)
608 (use-package magit-annex
610 :load-path "~/lib/emacs_el/magit-annex/"
612 (use-package magit-vcsh
613 :ensure f ; currently not in melpa, so don't try to install
614 :load-path "~/lib/emacs_el/magit-vcsh/"
619 #+BEGIN_SRC emacs-lisp
620 (use-package cperl-mode
623 ;; Use c-mode for perl .xs files
624 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
625 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
626 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
627 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
628 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
631 cperl-auto-newline nil
632 cperl-auto-newline-after-colon nil
633 cperl-continued-statement-offset 4
634 cperl-brace-offset -1
635 cperl-continued-brace-offset 0
636 cperl-label-offset -4
637 cperl-highlight-variables-indiscriminately t
638 cperl-electric-lbrace-space nil
639 cperl-indent-parens-as-block nil
640 cperl-close-paren-offset -1
641 cperl-tab-always-indent t)
642 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
647 #+BEGIN_SRC emacs-lisp
648 (use-package markdown-mode
650 :mode (("\\.md\\'" . markdown-mode)
651 ("\\.mdwn\\'" . markdown-mode)
652 ("README\\.md\\'" . gfm-mode)
655 (setq markdown-enable-math t)
656 (setq markdown-follow-wiki-link-on-enter nil)
657 (bind-key "M-." #'markdown-jump markdown-mode-map)
658 (add-hook 'markdown-mode-hook #'flyspell-mode)
659 (add-hook 'markdown-mode-hook #'outline-minor-mode)
660 (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
665 #+BEGIN_SRC emacs-lisp
666 ; load sql-indent when sql is loaded
668 :mode (("\\.sql\\'" . sql-mode))
670 (require sql-indent))
673 #+BEGIN_SRC emacs-lisp
675 :commands ediff ediff3
678 ;; ediff configuration
679 ;; don't use the multi-window configuration
680 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
683 ** VCL --editing varnish configuration files
684 #+BEGIN_SRC emacs-lisp
685 (use-package vcl-mode
692 #+BEGIN_SRC emacs-lisp
693 (defun malb/helm-omni (&rest arg)
694 ;; just in case someone decides to pass an argument, helm-omni won't fail.
696 (unless helm-source-buffers-list
697 (setq helm-source-buffers-list
698 (helm-make-source "Buffers" 'helm-source-buffers)))
702 (if (projectile-project-p)
703 '(helm-source-projectile-buffers-list
704 helm-source-buffers-list)
705 '(helm-source-buffers-list)) ;; list of all open buffers
707 `(((name . "Virtual Workspace")
708 (candidates . ,(--map (cons (eyebrowse-format-slot it) (car it))
709 (eyebrowse--get 'window-configs)))
710 (action . (lambda (candidate)
711 (eyebrowse-switch-to-window-config candidate)))))
713 (if (projectile-project-p)
714 '(helm-source-projectile-recentf-list
716 '(helm-source-recentf)) ;; all recent files
718 ;; always make some common files easily accessible
719 ;;'(((name . "Common Files")
720 ;; (candidates . malb/common-file-targets)
721 ;; (action . (("Open" . (lambda (x) (find-file (eval x))))))))
723 '(helm-source-files-in-current-dir
725 helm-source-bookmarks
726 helm-source-buffer-not-found ;; ask to create a buffer otherwise
728 "*Helm all the things*"))
732 :bind (("M-x" . helm-M-x)
733 ("C-x C-f" . helm-find-files)
734 ("C-x b" . helm-buffers-list) ; malb/helm-omni)
735 ("C-x C-b" . helm-buffers-list) ; malb/helm-omni)
736 ("C-c <SPC>" . helm-all-mark-rings))
738 (require 'helm-config)
739 (require 'helm-for-files)
740 (require 'helm-bookmark)
743 (define-key global-map [remap find-file] 'helm-find-files)
744 (define-key global-map [remap occur] 'helm-occur)
745 (define-key global-map [remap list-buffers] 'helm-buffers-list)
746 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
747 (unless (boundp 'completion-in-region-function)
748 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
749 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
750 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
755 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
757 #+BEGIN_SRC emacs-lisp
758 (use-package helm-flx
761 ;; these are helm configs, but they kind of fit here nicely
762 (setq helm-M-x-fuzzy-match t
763 helm-bookmark-show-location t
764 helm-buffers-fuzzy-matching t
765 helm-completion-in-region-fuzzy-match t
766 helm-file-cache-fuzzy-match t
767 helm-imenu-fuzzy-match t
768 helm-mode-fuzzy-match t
769 helm-locate-fuzzy-match nil
771 helm-recentf-fuzzy-match nil
772 helm-semantic-fuzzy-match t)
776 #+BEGIN_SRC emacs-lisp
778 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
779 (defun malb/helm-swoop-pre-fill ()
780 (thing-at-point 'symbol))
781 (defvar malb/helm-swoop-ignore-major-mode "List of major modes to ignore for helm-swoop")
782 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
783 paradox-menu-mode doc-view-mode pdf-view-mode
784 mu4e-headers-mode org-mode markdown-mode latex-mode
785 ein:notebook-multilang-mode))
787 (defun malb/swoop-or-search ()
789 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
790 (memq major-mode malb/helm-swoop-ignore-major-mode))
794 (use-package helm-swoop
797 :bind (("C-c o" . helm-multi-swoop-org)
798 ("C-s" . malb/swoop-or-search)
799 ("C-M-s" . helm-multi-swoop-all))
802 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
803 helm-swoop-split-with-multiple-windows nil
804 helm-swoop-split-direction #'split-window-horizontally
805 helm-swoop-split-window-function 'helm-default-display-buffer
806 helm-swoop-speed-or-color t)
808 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
809 (defun malb/helm-swoop-C-s ()
811 (if (boundp 'helm-swoop-pattern)
812 (if (equal helm-swoop-pattern "")
813 (previous-history-element 1)
817 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
818 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
819 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
820 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
821 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
822 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
827 #+BEGIN_SRC emacs-lisp
830 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
831 helm-ag-command-option "--all-text"
832 helm-ag-insert-at-point 'symbol
833 helm-ag-fuzzy-match t
834 helm-ag-use-temp-buffer t
835 helm-ag-use-grep-ignore-list t
836 helm-ag-use-agignore t))
839 #+BEGIN_SRC emacs-lisp
840 (use-package helm-descbinds
842 :bind ("C-h b" . helm-descbinds)
843 :init (fset 'describe-bindings 'helm-descbinds))
847 #+BEGIN_SRC emacs-lisp
848 (use-package helm-c-yasnippet
850 :bind ("C-c h y" . helm-yas-complete)
852 (setq helm-yas-space-match-any-greedy t)))
855 #+BEGIN_SRC emacs-lisp
856 (use-package helm-org-rifle
859 (defun malb/helm-org-rifle-agenda-files (arg)
861 (let ((current-prefix-arg nil))
863 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
864 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
865 (t (helm-org-agenda-files-headings)))))))
868 This can be used to link things pretty quickly if necessary
869 #+BEGIN_SRC emacs-lisp
870 (use-package helm-google
872 :bind ("C-c h g" . helm-google)
874 (progn (add-to-list 'helm-google-actions
875 '("Copy URL" . (lambda (candidate)
877 (replace-regexp-in-string
878 "https://.*q=\\(.*\\)\&sa=.*"
884 (add-to-list 'helm-google-actions
885 '("Org Store Link" . (lambda (candidate)
886 (let ((title (car (split-string candidate "[\n]+")))
888 (replace-regexp-in-string
889 "https://.*q=\\(.*\\)\&sa=.*"
891 (push (list url title) org-stored-links))))
896 ** Projectile -- Project management
897 #+begin_src emacs-lisp
898 (use-package projectile
900 :bind (("<f5>" . projectile-compile-project)
901 ("<f6>" . next-error))
903 (use-package magit :ensure t)
904 (require 'helm-projectile)
907 (setq projectile-make-test-cmd "make check"
908 projectile-switch-project-action 'helm-projectile
909 projectile-mode-line '(:eval (format "»{%s}" (projectile-project-name))))
911 (projectile-global-mode)))
915 #+begin_src emacs-lisp
916 (use-package helm-projectile
919 (defvar malb/helm-source-file-not-found
920 (helm-build-dummy-source
925 'helm-projectile-sources-list
926 malb/helm-source-file-not-found t)
928 (helm-delete-action-from-source
929 "Grep in projects `C-s'"
930 helm-source-projectile-projects)
932 (helm-add-action-to-source
933 "Grep in projects `C-s'"
934 'helm-do-ag helm-source-projectile-projects 4)))
937 #+BEGIN_SRC emacs-lisp
940 :bind ("M-z" . avy-zap-up-to-char-dwim))
943 #+BEGIN_SRC emacs-lisp
945 :bind (("C-c 2" . my/hydra-orgmodes/body)
946 ("C-c @" . my/hydra-orgmodes/body)
947 ("C-c #" . my/hydra-outline/body)
948 ("C-c 3" . my/hydra-outline/body)
951 (defhydra my/hydra-orgmodes (:color blue :hint nil)
953 _n_: notes _c_: chaim _w_: wildman _o_: ool
954 _u_: uddin _s_: steve _r_: refile _f_: fh
955 _p_: read papers _R_: paper notes
960 ("n" (find-file "~/projects/org-notes/notes.org"))
961 ("c" (find-file "~/projects/org-notes/chaim.org"))
962 ("w" (find-file "~/projects/org-notes/wildman.org"))
963 ("u" (find-file "~/projects/org-notes/uddin.org"))
964 ("o" (find-file "~/projects/org-notes/ool.org"))
965 ("f" (find-file "~/projects/org-notes/fh.org"))
966 ("s" (find-file "~/projects/org-notes/sndservers.org"))
967 ("r" (find-file "~/projects/org-notes/refile.org"))
968 ("p" (find-file "~/projects/research/papers_to_read.org"))
969 ("R" (find-file "~/projects/research/paper_notes.org"))
970 ("h" (find-file "~/projects/org-notes/hpcbio.org"))
975 ;; from https://github.com/abo-abo/hydra/wiki/Emacs
976 (defhydra my/hydra-outline (:color pink :hint nil)
979 ^^^^^^------------------------------------------------------
980 _q_: sublevels _a_: all _u_: up
981 _t_: body _e_: entry _n_: next visible
982 _o_: other _i_: children _p_: previous visible
983 _c_: entry _k_: branches _f_: forward same level
984 _l_: leaves _s_: subtree _b_: backward same level
989 ("q" outline-hide-sublevels) ; Hide everything but the top-level headings
990 ("t" outline-hide-body) ; Hide everything but headings (all body lines)
991 ("o" outline-hide-other) ; Hide other branches
992 ("c" outline-hide-entry) ; Hide this entry's body
993 ("l" outline-hide-leaves) ; Hide body lines in this entry and sub-entries
994 ("d" outline-hide-subtree) ; Hide everything in this entry and sub-entries
996 ("a" outline-show-all) ; Show (expand) everything
997 ("e" outline-show-entry) ; Show this heading's body
998 ("i" outline-show-children) ; Show this heading's immediate child sub-headings
999 ("k" outline-show-branches) ; Show all sub-headings under this heading
1000 ("s" outline-show-subtree) ; Show (expand) everything in this heading & below
1002 ("u" outline-up-heading) ; Up
1003 ("n" outline-next-visible-heading) ; Next
1004 ("p" outline-previous-visible-heading) ; Previous
1005 ("f" outline-forward-same-level) ; Forward - same level
1006 ("b" outline-backward-same-level) ; Backward - same level
1012 #+BEGIN_SRC emacs-lisp
1015 (add-to-list 'tramp-methods '("vcsh"
1016 (tramp-login-program "vcsh")
1020 (tramp-remote-shell "/bin/sh")
1021 (tramp-remote-shell-args
1025 #+BEGIN_SRC emacs-lisp
1029 (setq-default reftex-default-bibliography
1030 '("~/projects/research/references.bib")))
1033 #+BEGIN_SRC emacs-lisp
1035 :config (setq bibtex-user-optional-fields
1036 (quote (("annote" "Personal annotation (ignored)")
1044 #+BEGIN_SRC emacs-lisp
1049 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1050 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1051 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1052 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
1053 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
1054 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1055 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1056 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
1057 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
1058 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
1059 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
1061 (setq-default reftex-plug-into-AUCTeX t)
1062 ;; support fake section headers
1063 (setq TeX-outline-extra
1067 ("%subsubsection" 4)
1069 ;; add font locking to the headers
1070 (font-lock-add-keywords
1072 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1073 0 'font-lock-keyword-face t)
1074 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
1075 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
1076 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
1077 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1078 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
1080 ;; use smart quotes by default instead of `` and ''
1081 ;; taken from http://kieranhealy.org/esk/kjhealy.html
1082 (setq TeX-open-quote "“")
1083 (setq TeX-close-quote "”")
1085 ;; (TeX-add-style-hook
1090 ;; (custom-set-variables
1091 ;; '(font-latex-user-keyword-classes
1094 ;; font-lock-function-name-face 2 (command 1 t))))
1096 (setq-default TeX-parse-self t)
1097 (setq-default TeX-auto-save t)
1098 (setq-default TeX-master nil)
1101 '(TeX-add-style-hook
1104 (if (boundp 'reftex-ref-style-alist)
1106 'reftex-ref-style-alist
1107 '("Cleveref" "cleveref"
1108 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1109 (reftex-ref-style-activate "Cleveref")
1111 '("cref" TeX-arg-ref)
1112 '("Cref" TeX-arg-ref)
1113 '("cpageref" TeX-arg-ref)
1114 '("Cpageref" TeX-arg-ref)))))
1117 '(add-to-list 'LaTeX-fill-excluded-macros
1120 (use-package font-latex
1122 (setq font-latex-match-reference-keywords
1144 (setq font-latex-fontify-script nil)
1145 (setq font-latex-fontify-sectioning (quote color))
1146 (setq font-latex-script-display (quote (nil)))
1151 #+BEGIN_SRC emacs-lisp
1155 :mode ("\\.R\\'" . ess-r-mode)
1156 :bind (:map ess-mode-map
1157 ("C-c C-R" . dla/ess-region-remote-eval))
1159 (autoload 'ess-r-mode "ess-site" nil t)
1160 (autoload 'R "ess-site" nil t)
1162 ; actually load the rest of ess
1164 (defun ess-change-directory (path)
1165 "Set the current working directory to PATH for both *R* and Emacs."
1166 (interactive "Directory to change to: ")
1168 (when (file-exists-p path)
1169 (ess-command (concat "setwd(\"" path "\")\n"))
1170 ;; use file-name-as-directory to ensure it has trailing /
1171 (setq default-directory (file-name-as-directory path))))
1172 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1173 ;; outlining support for ess modes
1177 (outline-minor-mode)
1178 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1179 (defun outline-level ()
1180 (cond ((looking-at "^##### ") 1)
1181 ((looking-at "^#### ") 2)
1182 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1185 (defun dla/ess-region-remote-eval (start end)
1186 "Evaluate region in a remote ESS instance"
1188 (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***"))
1189 kill-buffer "***essregionremoteeval***")
1190 ;; Don't restore history or save workspace image
1191 '(inferior-R-args "--no-restore-history --no-save")
1196 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1198 #+BEGIN_SRC emacs-lisp
1199 (use-package rainbow-mode
1200 ;; add ess to the x major mode
1201 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1202 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1207 #+BEGIN_SRC emacs-lisp
1208 (use-package polymode
1210 (use-package poly-R)
1211 (use-package poly-noweb)
1212 (use-package poly-markdown)
1213 :mode ("\\.Snw" . poly-noweb+r-mode)
1214 :mode ("\\.Rnw" . poly-noweb+r-mode)
1215 :mode ("\\.Rmd" . poly-markdown+r-mode)
1221 #+BEGIN_SRC emacs-lisp
1222 (use-package outline-magic)
1225 #+BEGIN_SRC emacs-lisp
1226 ;; change the outline mode prefix from C-c @ to C-c C-2
1227 (setq outline-minor-mode-prefix "C-c C-2")
1228 ;;(add-hook 'outline-minor-mode-hook
1229 ;; (lambda () (local-set-key (kbd "C-c C-2")
1230 ;; outline-mode-prefix-map)))
1234 #+BEGIN_SRC emacs-lisp
1235 (use-package writeroom-mode
1237 (defun my/writing-mode ()
1238 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1243 (visual-line-mode -1)
1245 (visual-fill-column-mode -1)
1247 (visual-line-mode 1)
1249 (visual-fill-column-mode 1)
1254 ** GhostText/Atomic Chrome
1255 #+BEGIN_SRC emacs-lisp
1256 (use-package atomic-chrome
1258 (ignore-errors (atomic-chrome-start-server))
1259 (setq atomic-chrome-buffer-open-style 'full)
1264 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
1266 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1267 #+BEGIN_SRC emacs-lisp
1268 (use-package multiple-cursors
1269 :bind* (("C-;" . mc/mark-all-dwim)
1270 ("C-<" . mc/mark-previous-like-this)
1271 ("C->" . mc/mark-next-like-this)
1272 ("C-S-c C-S-c" . mc/edit-lines))
1276 #+BEGIN_SRC emacs-lisp
1277 (use-package web-mode
1279 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1280 (setq web-mode-enable-engine-detection t)
1281 (setq web-mode-engines-alist
1282 '(("template-toolkit" . "\\.tmpl\\'")))
1285 ** Spamassassin Mode
1286 #+BEGIN_SRC emacs-lisp
1287 (use-package spamassassin-mode
1288 :commands spamassassin-mode
1293 #+BEGIN_SRC emacs-lisp
1294 (use-package password-store
1296 :commands password-store-edit password-store-generate
1300 #+BEGIN_SRC emacs-lisp
1304 ;; fix up css mode to not be silly
1305 ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1306 (setq cssm-indent-level 4)
1307 (setq cssm-newline-before-closing-bracket t)
1308 (setq cssm-indent-function #'cssm-c-style-indenter)
1309 (setq cssm-mirror-mode nil))
1312 #+BEGIN_SRC emacs-lisp
1314 :diminish abbrev-mode
1316 ;; load abbreviations from
1317 (setq abbrev-file-name
1318 "~/.emacs_abbrev_def")
1320 ;; read the abbrev file if it exists
1321 (if (file-exists-p abbrev-file-name)
1322 (quietly-read-abbrev-file))
1324 ;; for now, use abbrev mode everywhere
1325 (setq default-abbrev-mode t))
1331 #+BEGIN_SRC emacs-lisp
1332 (use-package message
1334 :diminish (message "✉")
1335 :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1336 :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1337 :hook 'my/message-mode-settings
1338 :hook 'turn-on-flyspell
1339 :bind (:map message-mode-map
1340 ("C-c C-a" . my/post-attach-file))
1341 :delight (message-mode "✉")
1343 (defun my/message-mode-settings ()
1344 (font-lock-add-keywords nil
1345 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1346 (0 'message-multiply-quoted-text-face))
1347 ("^[ \t]*>[ \t]*>.*$"
1348 (0 'message-double-quoted-text-face))))
1351 (defun my/post-attach-file ()
1352 "Prompt for an attachment."
1354 (let ((file (read-file-name "Attach file: " nil nil t nil)))
1355 (my/header-attach-file file "")))
1357 (defun my/header-attach-file (file description)
1358 "Attach a FILE to the current message (works with Mutt).
1359 Argument DESCRIPTION MIME description."
1360 (interactive "fAttach file: \nsDescription: ")
1361 (when (> (length file) 0)
1366 (goto-char (point-min))
1367 (search-forward-regexp "^$")
1368 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1370 (message (concat "Attached '" file "'."))
1371 (setq post-has-attachment t))))))
1373 (setq mail-yank-prefix "> ")
1377 #+BEGIN_SRC emacs-lisp
1378 (use-package muttrc-mode
1385 ** Reverting buffers
1386 #+BEGIN_SRC emacs-lisp
1387 (use-package autorevert
1388 :diminish auto-revert-mode
1390 (setq global-auto-revert-non-file-buffers t
1391 global-auto-revert-ignore-modes '(pdf-view-mode)
1392 auto-revert-verbose nil)
1393 (global-auto-revert-mode 1))
1396 ** Use-package and load things
1397 #+BEGIN_SRC emacs-lisp
1400 :delight (org-mode "ø")
1401 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1402 :bind (("C-c l" . org-store-link)
1403 ("C-c a" . org-agenda)
1404 ("C-c b" . org-iswitchb))
1406 ** Agenda Configuration
1407 #+BEGIN_SRC emacs-lisp
1409 (setq-default org-log-done 'time)
1410 (setq-default org-agenda-ndays 5)
1412 (setq org-agenda-sticky t)
1413 (defun dla/show-org-agenda ()
1418 (and (string-match-p
1426 (buffer-name agendabuffer))
1428 (delete-other-windows))
1430 ;; agenda configuration
1431 ;; Do not dim blocked tasks
1432 (setq org-agenda-dim-blocked-tasks nil)
1433 (setq org-agenda-inhibit-startup t)
1434 (setq org-agenda-use-tag-inheritance nil)
1436 ;; Compact the block agenda view
1437 (setq org-agenda-compact-blocks t)
1439 ;; Custom agenda command definitions
1440 (setq org-agenda-custom-commands
1441 (quote (("N" "Notes" tags "NOTE"
1442 ((org-agenda-overriding-header "Notes")
1443 (org-tags-match-list-sublevels t)))
1444 ("h" "Habits" tags-todo "STYLE=\"habit\""
1445 ((org-agenda-overriding-header "Habits")
1446 (org-agenda-sorting-strategy
1447 '(todo-state-down effort-up category-keep))))
1451 ((org-agenda-overriding-header "Tasks to Refile")
1452 (org-tags-match-list-sublevels nil)))
1453 (tags-todo "-CANCELLED/!"
1454 ((org-agenda-overriding-header "Stuck Projects")
1455 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1456 (org-agenda-sorting-strategy
1458 (tags-todo "-HOLD-CANCELLED/!"
1459 ((org-agenda-overriding-header "Projects")
1460 (org-agenda-skip-function 'bh/skip-non-projects)
1461 (org-tags-match-list-sublevels 'indented)
1462 (org-agenda-sorting-strategy
1464 (tags-todo "-CANCELLED/!NEXT"
1465 ((org-agenda-overriding-header (concat "Project Next Tasks"
1466 (if bh/hide-scheduled-and-waiting-next-tasks
1468 " (including WAITING and SCHEDULED tasks)")))
1469 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1470 (org-tags-match-list-sublevels t)
1471 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1472 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1473 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1474 (org-agenda-sorting-strategy
1475 '(todo-state-down effort-up category-keep))))
1476 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1477 ((org-agenda-overriding-header (concat "Project Subtasks"
1478 (if bh/hide-scheduled-and-waiting-next-tasks
1480 " (including WAITING and SCHEDULED tasks)")))
1481 (org-agenda-skip-function 'bh/skip-non-project-tasks)
1482 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1483 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1484 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1485 (org-agenda-sorting-strategy
1487 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1488 ((org-agenda-overriding-header (concat "Standalone Tasks"
1489 (if bh/hide-scheduled-and-waiting-next-tasks
1491 " (including WAITING and SCHEDULED tasks)")))
1492 (org-agenda-skip-function 'bh/skip-project-tasks)
1493 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1494 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1495 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1496 (org-agenda-sorting-strategy
1498 (tags-todo "-CANCELLED+WAITING|HOLD/!"
1499 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1500 (org-agenda-skip-function 'bh/skip-stuck-projects)
1501 (org-tags-match-list-sublevels nil)
1502 (org-agenda-todo-ignore-scheduled t)
1503 (org-agenda-todo-ignore-deadlines t)))
1505 ((org-agenda-overriding-header "Tasks to Archive")
1506 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1507 (org-tags-match-list-sublevels nil))))
1510 ; org mode agenda files
1511 (setq org-agenda-files
1512 (quote ("~/projects/org-notes/debbugs.org"
1513 "~/projects/org-notes/notes.org"
1514 "~/projects/org-notes/holidays.org"
1515 "~/projects/org-notes/refile.org"
1516 "~/projects/org-notes/diary.org"
1517 "~/projects/org-notes/ool.org"
1518 "~/projects/org-notes/sndservers.org"
1519 "~/projects/org-notes/chaim.org"
1520 "~/projects/org-notes/wildman.org"
1521 "~/projects/org-notes/uddin.org"
1522 "~/projects/org-notes/reviews.org"
1523 "~/projects/org-notes/laurel.org"
1524 "~/projects/org-notes/from-calendar.org"
1525 "~/org-mode/from-mobile.org"
1526 "~/projects/org-notes/fh.org")))
1528 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1529 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
1530 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1531 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1532 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1533 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1534 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1535 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1536 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1537 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1538 (defun org-agenda-timeline-all (&optional arg)
1541 (dolist (org-agenda-file org-agenda-files)
1542 (insert-file-contents org-agenda-file nil)
1543 (goto-char (point-max))
1545 (write-file "/tmp/timeline.org")
1546 (org-agenda arg "L")))
1547 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1551 #+BEGIN_SRC emacs-lisp
1552 (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")))
1553 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1555 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1556 (setq org-id-link-to-org-use-id 'use-existing)
1558 ** Capture Templates
1559 #+BEGIN_SRC emacs-lisp
1560 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1561 `(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
1562 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1563 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
1564 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1565 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
1566 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1567 ("n" "note" entry (file "~/projects/org-notes/refile.org")
1568 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1569 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
1570 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1571 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1572 "* %?\n%U\n" :clock-in t :clock-resume t)
1573 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
1574 "* TODO Review %c\n%U\n" :immediate-finish t)
1575 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
1576 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1577 ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
1578 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1579 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1580 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1581 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
1582 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1583 ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1585 ,(format-time-string "Positions %Y"))
1586 "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1587 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
1588 "* 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")
1592 ;; Remove empty LOGBOOK drawers on clock out
1593 (defun bh/remove-empty-drawer-on-clock-out ()
1596 (beginning-of-line 0)
1597 (org-remove-empty-drawer-at (point))))
1599 (defun my/org-add-id ()
1602 (if (org-current-level)
1611 ** Org mode key bindings
1612 #+BEGIN_SRC emacs-lisp
1613 ;; org mode configuration from http://doc.norang.ca/org-mode.html
1614 ;; Custom Key Bindings
1615 :bind* (("<f9> a" . org-agenda)
1616 ("<f9> I" . bh/punch-in)
1617 ("<f9> O" . bh/punch-out)
1618 ("<f9> SPC" . bh/clock-in-last-task)
1619 ("<f12>" . dla/show-org-agenda)
1620 ;; ("<f5>" . bh/org-todo)
1621 ("<S-f5>" . bh/widen)
1622 ("<f7>" . bh/set-truncate-lines)
1623 ("<f8>" . org-cycle-agenda-files)
1624 ("<f9> <f9>" . dla/show-org-agenda)
1626 ("<f9> c" . calendar)
1627 ("<f9> f" . boxquote-insert-file)
1628 ("<f9> h" . bh/hide-other)
1629 ("<f9> n" . bh/toggle-next-task-display)
1632 ("<f9> r" . boxquote-region)
1633 ("<f9> s" . bh/switch-to-scratch)
1635 ("<f9> t" . bh/insert-inactive-timestamp)
1636 ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1638 ("<f9> v" . visible-mode)
1639 ("<f9> l" . org-toggle-link-display)
1640 ("<f9> SPC" . bh/clock-in-last-task)
1641 ("C-<f9>" . previous-buffer)
1642 ("M-<f9>" . org-toggle-inline-images)
1643 ("C-x n r" . narrow-to-region)
1644 ("C-<f10>" . next-buffer)
1645 ("<f11>" . org-clock-goto)
1646 ("C-<f11>" . org-clock-in)
1647 ("C-s-<f12>" . bh/save-then-publish)
1648 ("C-c c" . org-capture))
1651 ** Utility Functions
1652 #+BEGIN_SRC emacs-lisp
1653 (defun bh/hide-other ()
1656 (org-back-to-heading 'invisible-ok)
1662 (defun bh/set-truncate-lines ()
1663 "Toggle value of truncate-lines and refresh window display."
1665 (setq truncate-lines (not truncate-lines))
1666 ;; now refresh window display (an idiom from simple.el):
1668 (set-window-start (selected-window)
1669 (window-start (selected-window)))))
1671 (defun bh/switch-to-scratch ()
1673 (switch-to-buffer "*scratch*"))
1675 (setq org-use-fast-todo-selection t)
1676 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1678 ; create function to create headlines in file. This comes from
1679 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1680 (defun my/org-add-ids-to-headlines-in-file ()
1681 "Add ID properties to all headlines in the current file which
1682 do not already have one."
1684 (org-map-entries 'org-id-get-create))
1685 (defun dla/org-update-ids-to-headlines-in-file ()
1686 "Add or replace ID properties to all headlines in the current file
1687 (or narrowed region)."
1689 (org-map-entries '(lambda () (org-id-get-create t))))
1690 ; if we wanted to do this to every buffer, do the following:
1691 ; (add-hook 'org-mode-hook
1693 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1696 #+BEGIN_SRC emacs-lisp
1697 (setq org-todo-keywords
1698 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1699 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1701 (setq org-todo-keyword-faces
1702 (quote (("TODO" :foreground "red" :weight bold)
1703 ("NEXT" :foreground "blue" :weight bold)
1704 ("DONE" :foreground "forest green" :weight bold)
1705 ("WAITING" :foreground "orange" :weight bold)
1706 ("HOLD" :foreground "magenta" :weight bold)
1707 ("CANCELLED" :foreground "forest green" :weight bold)
1708 ("MEETING" :foreground "forest green" :weight bold)
1709 ("PHONE" :foreground "forest green" :weight bold))))
1711 (setq org-todo-state-tags-triggers
1712 (quote (("CANCELLED" ("CANCELLED" . t))
1713 ("WAITING" ("WAITING" . t))
1714 ("HOLD" ("WAITING") ("HOLD" . t))
1715 (done ("WAITING") ("HOLD"))
1716 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1717 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1718 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1722 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1723 ; add ids on creation of nodes
1724 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1727 ; resolve clocks after 10 minutes of idle; use xprintidle
1728 ; (setq org-clock-idle-time 10)
1729 ; (setq org-clock-x11idle-program-name "xprintidle")
1731 ; this is from http://doc.norang.ca/org-mode.html#Capture
1732 ; use C-M-r for org mode capture
1733 (global-set-key (kbd "C-M-r") 'org-capture)
1735 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1736 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1737 (org-agenda-files :maxlevel . 9))))
1739 ; Use full outline paths for refile targets - we file directly with IDO
1740 (setq org-refile-use-outline-path t)
1742 ; Targets complete directly with IDO
1743 (setq org-outline-path-complete-in-steps nil)
1745 ; Allow refile to create parent tasks with confirmation
1746 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1748 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1749 ; (setq org-completion-use-ido t)
1750 ; (setq ido-everywhere t)
1751 ; (setq ido-max-directory-size 100000)
1752 ; (ido-mode (quote both))
1753 ; ; Use the current window when visiting files and buffers with ido
1754 ; (setq ido-default-file-method 'selected-window)
1755 ; (setq ido-default-buffer-method 'selected-window)
1756 ; ; Use the current window for indirect buffer display
1757 ; (setq org-indirect-buffer-display 'current-window)
1760 ;;;; Refile settings
1761 ; Exclude DONE state tasks from refile targets
1762 (defun bh/verify-refile-target ()
1763 "Exclude todo keywords with a done state from refile targets"
1764 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1766 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1768 ;; ensure that emacsclient will show just the note to be edited when invoked
1769 ;; from Mutt, and that it will shut down emacsclient once finished;
1770 ;; fallback to legacy behavior when not invoked via org-protocol.
1771 (require 'org-protocol)
1772 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1773 (setq my-org-protocol-flag nil)
1774 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1775 "Delete frame at remember finalization"
1776 (progn (if my-org-protocol-flag (delete-frame))
1777 (setq my-org-protocol-flag nil)))
1778 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1779 "Delete frame at remember refile"
1780 (if my-org-protocol-flag
1782 (setq my-org-protocol-flag nil)
1787 (defadvice org-capture-kill (after delete-frame-at-end activate)
1788 "Delete frame at remember abort"
1789 (progn (if my-org-protocol-flag (delete-frame))
1790 (setq my-org-protocol-flag nil)))
1791 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1792 (setq my-org-protocol-flag t))
1794 (defadvice org-insert-todo-heading (after dla/create-id activate)
1795 (unless (org-in-item-p)
1801 (add-to-list 'org-modules 'org-habit)
1803 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1804 (defun open-mail-in-mutt (message)
1805 "Open a mail message in Mutt, using an external terminal.
1807 Message can be specified either by a path pointing inside a
1808 Maildir, or by Message-ID."
1809 (interactive "MPath or Message-ID: ")
1811 (format "faf xterm -e \"%s %s\""
1812 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1814 ;; add support for "mutt:ID" links
1815 (org-add-link-type "mutt" 'open-mail-in-mutt)
1817 (defun my-org-mode-setup ()
1818 ; (load-library "reftex")
1819 (and (buffer-file-name)
1820 (file-exists-p (buffer-file-name))
1822 ; (reftex-parse-all)
1823 (reftex-set-cite-format
1824 '((?b . "[[bib:%l][%l-bib]]")
1825 (?n . "[[notes:%l][%l-notes]]")
1827 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1829 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1830 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1831 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1832 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1834 (add-hook 'org-mode-hook 'my-org-mode-setup)
1836 (defun org-mode-reftex-search ()
1838 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1840 (defun open-research-paper (bibtexkey)
1841 "Open a paper by bibtex key"
1842 (interactive "bibtex key: ")
1845 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1846 (org-add-link-type "papers" 'open-research-paper)
1847 (defun open-research-paper-pdf (bibtexkey)
1848 "Open a paper pdf by bibtex key"
1849 (interactive "bibtex key: ")
1851 (format "%s -p evince_annot %s"
1852 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1853 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1855 (add-to-list 'org-link-abbrev-alist
1857 "~/projects/research/paper_notes.org::#%s"))
1859 ; I pretty much always want hiearchical checkboxes
1860 (setq org-hierachical-checkbox-statistics nil)
1862 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1863 (add-to-list 'org-structure-template-alist
1864 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1867 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1868 (defun my-rtcite-export-handler (path desc format)
1869 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1870 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1871 (match-string 1 path)))
1872 (path (substring path 0 (match-beginning 0))))
1873 (cond ((eq format 'latex)
1875 (equal 0 (search "rtcite:" desc)))
1876 (format "\\cite{%s}" search)
1877 (format "\\cite[%s]{%s}" desc search))))))
1879 (org-add-link-type "rtcite"
1881 'my-rtcite-export-handler)
1885 ** Org Mobile Configuration
1886 #+BEGIN_SRC emacs-lisp
1887 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1888 (when (string= system-name "linnode")
1889 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1890 (setq-default org-directory "/home/don/org-mode/")
1891 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1895 #+BEGIN_SRC emacs-lisp
1896 ;; org mode ical export
1897 (setq org-icalendar-timezone "America/Los_Angeles")
1898 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1899 ;; we already add the id manually
1900 (setq org-icalendar-store-UID t)
1903 ** General Org Babel Configuration
1904 #+BEGIN_SRC emacs-lisp
1905 ;; org babel support
1906 (org-babel-do-load-languages
1907 'org-babel-load-languages
1914 ;; use graphviz-dot for dot things
1915 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1916 ;; do not indent begin_src blocks
1917 (setq org-edit-src-content-indentation 0)
1918 ;; org-babel-by-backend
1919 (defmacro org-babel-by-backend (&rest body)
1920 `(case (if (boundp 'backend)
1921 (org-export-backend-name backend)
1924 (defun my/fix-inline-images ()
1925 (when org-inline-image-overlays
1926 (org-redisplay-inline-images)))
1928 (add-hook 'org-babel-after-execute-hook
1929 'my/fix-inline-images)
1932 ** LaTeX configuration
1934 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
1936 #+BEGIN_SRC emacs-lisp
1938 (add-to-list 'org-latex-classes
1940 "\\documentclass[11pt,oneside,article]{memoir}\n"
1941 ("\\section{%s}" . "\\section*{%s}")
1942 ("\\subsection{%s}" . "\\subsection*{%s}")
1943 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1944 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1945 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1947 (setq org-beamer-outline-frame-options "")
1948 (add-to-list 'org-latex-classes
1950 "\\documentclass[ignorenonframetext]{beamer}
1951 [NO-DEFAULT-PACKAGES]
1954 ("\\section{%s}" . "\\section*{%s}")
1955 ("\\subsection{%s}" . "\\subsection*{%s}")
1956 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1957 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1958 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1960 (add-to-list 'org-latex-classes
1962 "\\documentclass[11pt,oneside]{memoir}\n"
1963 ("\\chapter{%s}" . "\\chapter*{%s}")
1964 ("\\section{%s}" . "\\section*{%s}")
1965 ("\\subsection{%s}" . "\\subsection*{%s}")
1966 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1968 (add-to-list 'org-latex-classes
1970 "\\documentclass[11pt]{letter}
1971 [NO-DEFAULT-PACKAGES]
1974 ("\\section{%s}" . "\\section*{%s}")
1975 ("\\subsection{%s}" . "\\subsection*{%s}")
1976 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1977 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1978 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1980 (add-to-list 'org-latex-classes
1982 "\\documentclass{dlacv}
1983 [NO-DEFAULT-PACKAGES]
1986 ("\\section{%s}" . "\\section*{%s}")
1987 ("\\subsection{%s}" . "\\subsection*{%s}")
1988 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1989 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1990 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1993 (add-to-list 'org-latex-classes
1995 "\\documentclass{dlaresume}
1996 [NO-DEFAULT-PACKAGES]
1999 ("\\section{%s}" . "\\section*{%s}")
2000 ("\\subsection{%s}" . "\\subsection*{%s}")
2001 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2002 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2003 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2006 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
2007 ;; but adapted to use latexmk 4.22 or higher.
2008 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
2010 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
2011 (setq org-latex-default-packages-alist
2013 ("" "unicode-math" t)
2015 (setq org-latex-packages-alist
2022 ("" "longtable" nil)
2025 ;; make equations larger
2026 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2028 (defun org-create-formula--latex-header ()
2029 "Return LaTeX header appropriate for previewing a LaTeX snippet."
2030 (let ((info (org-combine-plists (org-export--get-global-options
2031 (org-export-get-backend 'latex))
2032 (org-export--get-inbuffer-options
2033 (org-export-get-backend 'latex)))))
2034 (org-latex-guess-babel-language
2035 (org-latex-guess-inputenc
2036 (org-splice-latex-header
2037 org-format-latex-header
2038 org-latex-default-packages-alist
2040 (plist-get info :latex-header)))
2044 ; support ignoring headers in org mode export to latex
2045 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2046 (defadvice org-latex-headline (around my-latex-skip-headlines
2047 (headline contents info) activate)
2048 (if (member "ignoreheading" (org-element-property :tags headline))
2049 (setq ad-return-value contents)
2052 ;; keep latex logfiles
2054 (setq org-latex-remove-logfiles nil)
2056 ;; Resume clocking task when emacs is restarted
2057 (org-clock-persistence-insinuate)
2059 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2060 (setq org-clock-history-length 23)
2061 ;; Resume clocking task on clock-in if the clock is open
2062 (setq org-clock-in-resume t)
2063 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2064 ;; there are things like PHONE calls
2065 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2066 ;; Separate drawers for clocking and logs
2067 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2068 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2069 (setq org-clock-into-drawer t)
2070 (setq org-log-into-drawer t)
2071 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2072 (setq org-clock-out-remove-zero-time-clocks t)
2073 ;; Clock out when moving task to a done state
2074 (setq org-clock-out-when-done t)
2075 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2076 (setq org-clock-persist t)
2077 ;; Do not prompt to resume an active clock
2078 (setq org-clock-persist-query-resume nil)
2079 ;; Enable auto clock resolution for finding open clocks
2080 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2081 ;; Include current clocking task in clock reports
2082 (setq org-clock-report-include-clocking-task t)
2084 ;; the cache seems to be broken
2085 (setq org-element-use-cache nil)
2087 (defvar bh/keep-clock-running nil)
2089 (defun bh/is-task-p ()
2090 "Any task with a todo keyword and no subtask"
2094 (subtree-end (save-excursion (org-end-of-subtree t)))
2095 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2098 (while (and (not has-subtask)
2099 (< (point) subtree-end)
2100 (re-search-forward "^\*+ " subtree-end t))
2101 (when (member (org-get-todo-state) org-todo-keywords-1)
2102 (setq has-subtask t))))
2103 (and is-a-task (not has-subtask)))))
2104 (defun bh/is-project-p ()
2105 "Any task with a todo keyword subtask"
2109 (subtree-end (save-excursion (org-end-of-subtree t)))
2110 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2113 (while (and (not has-subtask)
2114 (< (point) subtree-end)
2115 (re-search-forward "^\*+ " subtree-end t))
2116 (when (member (org-get-todo-state) org-todo-keywords-1)
2117 (setq has-subtask t))))
2118 (and is-a-task has-subtask))))
2120 (defun bh/is-subproject-p ()
2121 "Any task which is a subtask of another project"
2122 (let ((is-subproject)
2123 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2125 (while (and (not is-subproject) (org-up-heading-safe))
2126 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2127 (setq is-subproject t))))
2128 (and is-a-task is-subproject)))
2131 (defun bh/clock-in-to-next (kw)
2132 "Switch a task from TODO to NEXT when clocking in.
2133 Skips capture tasks, projects, and subprojects.
2134 Switch projects and subprojects from NEXT back to TODO"
2135 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2137 ((and (member (org-get-todo-state) (list "TODO"))
2140 ((and (member (org-get-todo-state) (list "NEXT"))
2144 (defun bh/punch-in (arg)
2145 "Start continuous clocking and set the default task to the
2146 selected task. If no task is selected set the Organization task
2147 as the default task."
2149 (setq bh/keep-clock-running t)
2150 (if (equal major-mode 'org-agenda-mode)
2152 ;; We're in the agenda
2154 (let* ((marker (org-get-at-bol 'org-hd-marker))
2155 (tags (org-with-point-at marker (org-get-tags-at))))
2156 (if (and (eq arg 4) tags)
2157 (org-agenda-clock-in '(16))
2158 (bh/clock-in-organization-task-as-default)))
2160 ;; We are not in the agenda
2164 ; Find the tags on the current task
2165 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2166 (org-clock-in '(16))
2167 (bh/clock-in-organization-task-as-default)))))
2169 (defun bh/punch-out ()
2171 (setq bh/keep-clock-running nil)
2172 (when (org-clock-is-active)
2174 (org-agenda-remove-restriction-lock))
2176 (defun bh/clock-in-default-task ()
2178 (org-with-point-at org-clock-default-task
2181 (defun bh/clock-in-parent-task ()
2182 "Move point to the parent (project) task if any and clock in"
2183 (let ((parent-task))
2187 (while (and (not parent-task) (org-up-heading-safe))
2188 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2189 (setq parent-task (point))))
2191 (org-with-point-at parent-task
2193 (when bh/keep-clock-running
2194 (bh/clock-in-default-task)))))))
2196 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2198 (defun bh/clock-in-organization-task-as-default ()
2200 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2201 (org-clock-in '(16))))
2203 (defun bh/clock-out-maybe ()
2204 (when (and bh/keep-clock-running
2205 (not org-clock-clocking-in)
2206 (marker-buffer org-clock-default-task)
2207 (not org-clock-resolving-clocks-due-to-idleness))
2208 (bh/clock-in-parent-task)))
2210 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2213 (defun bh/clock-in-task-by-id (id)
2214 "Clock in a task by id"
2215 (org-with-point-at (org-id-find id 'marker)
2216 (org-clock-in nil)))
2218 (defun bh/clock-in-last-task (arg)
2219 "Clock in the interrupted task if there is one
2220 Skip the default task and get the next one.
2221 A prefix arg forces clock in of the default task."
2223 (let ((clock-in-to-task
2225 ((eq arg 4) org-clock-default-task)
2226 ((and (org-clock-is-active)
2227 (equal org-clock-default-task (cadr org-clock-history)))
2228 (caddr org-clock-history))
2229 ((org-clock-is-active) (cadr org-clock-history))
2230 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2231 (t (car org-clock-history)))))
2233 (org-with-point-at clock-in-to-task
2234 (org-clock-in nil))))
2237 (defun org-export-to-ods ()
2239 (let ((csv-file "data.csv"))
2240 (org-table-export csv-file "orgtbl-to-csv")
2241 (org-odt-convert csv-file "ods" 'open)))
2243 ; allow for zero-width-space to be a break in regexp too
2244 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
2245 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
2246 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2248 ;; support inserting screen shots
2249 (defun my/org-insert-screenshot ()
2250 "Take a screenshot into a time stamped unique-named file in the
2251 same directory as the org-buffer and insert a link to this file."
2253 (defvar my/org-insert-screenshot/filename)
2254 (setq my/org-insert-screenshot/filename
2256 "Screenshot to insert: "
2258 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2261 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2262 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2263 (org-display-inline-images))
2265 (defun my/fix-inline-images ()
2266 (when org-inline-image-overlays
2267 (org-redisplay-inline-images)))
2269 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2271 ;; use xelatex to preview with imagemagick
2272 (add-to-list 'org-preview-latex-process-alist
2273 '(xelateximagemagick
2274 :programs ("xelatex" "convert")
2275 :description "pdf > png"
2276 :message "you need to install xelatex and imagemagick"
2278 :image-input-type "pdf"
2279 :image-output-type "png"
2280 :image-size-adjust (1.0 . 1.0)
2281 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2282 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2284 ;; use xelatex by default
2285 (setq org-preview-latex-default-process 'xelateximagemagick)
2287 ; from http://orgmode.org/Changes.html
2288 (defun my/org-repair-property-drawers ()
2289 "Fix properties drawers in current buffer.
2290 Ignore non Org buffers."
2292 (when (eq major-mode 'org-mode)
2293 (org-with-wide-buffer
2294 (goto-char (point-min))
2295 (let ((case-fold-search t)
2296 (inline-re (and (featurep 'org-inlinetask)
2297 (concat (org-inlinetask-outline-regexp)
2301 (unless (and inline-re (org-looking-at-p inline-re))
2303 (let ((end (save-excursion (outline-next-heading) (point))))
2305 (when (org-looking-at-p org-planning-line-re) (forward-line))
2306 (when (and (< (point) end)
2307 (not (org-looking-at-p org-property-drawer-re))
2309 (and (re-search-forward org-property-drawer-re end t)
2310 (eq (org-element-type
2311 (save-match-data (org-element-at-point)))
2313 (insert (delete-and-extract-region
2315 (min (1+ (match-end 0)) end)))
2316 (unless (bolp) (insert "\n"))))))))))))
2320 #+BEGIN_SRC emacs-lisp
2324 (use-package calfw-org
2327 (use-package org-gcal
2329 :config '((if (file-readable-p "~/.hide/org_gcal.el")
2330 (load-file "~/.hide/org_gcal.el"))
2335 #+BEGIN_SRC emacs-lisp
2339 ;; Show notification 10 minutes before event
2340 (setq appt-message-warning-time 10)
2341 ;; Disable multiple reminders
2342 (setq appt-display-interval appt-message-warning-time)
2343 (setq appt-display-mode-line nil)
2345 ;; add automatic reminders for appointments
2346 (defun my/org-agenda-to-appt ()
2348 (setq appt-time-msg-list nil)
2349 (org-agenda-to-appt))
2350 ;; add reminders when starting emacs
2351 (my/org-agenda-to-appt)
2352 ;; when rebuilding the agenda
2353 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
2354 "Pressing `r' on the agenda will also add appointments."
2355 (my/org-agenda-to-appt)
2357 ;; when saving all org buffers
2358 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2359 "Re-add appts after saving all org buffers"
2360 (my/org-agenda-to-appt))
2361 ;; Display appointments as a window manager notification
2362 (setq appt-disp-window-function 'my/appt-display)
2363 (setq appt-delete-window-function (lambda () t))
2365 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2367 (defun my/appt-display (min-to-app new-time msg)
2368 (if (atom min-to-app)
2369 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2370 (dolist (i (number-sequence 0 (1- (length min-to-app))))
2371 (start-process "my/appt-notification-app" nil my/appt-notification-app
2372 (nth i min-to-app) (nth i msg))))
2379 #+BEGIN_SRC emacs-lisp
2384 #+BEGIN_SRC emacs-lisp
2385 (global-unset-key "\M-g")
2386 (global-set-key (kbd "M-g l") 'goto-line)
2390 #+BEGIN_SRC emacs-lisp
2391 (use-package debian-changelog-mode
2392 :mode "debian/changelog"
2394 (setq debian-changelog-mailing-address "don@debian.org")
2395 (setq debian-changelog-full-name "Don Armstrong"))
2397 * Misc (uncharacterized)
2398 #+BEGIN_SRC emacs-lisp
2399 (setq calendar-latitude 38.6)
2400 (setq calendar-longitude -121.5)
2401 (setq case-fold-search t)
2402 (setq confirm-kill-emacs (quote y-or-n-p))
2403 (setq cperl-lazy-help-time nil)
2404 (global-font-lock-mode 1)
2406 (setq log-edit-keep-buffer t)
2407 (setq mail-user-agent (quote sendmail-user-agent))
2408 (setq markdown-enable-math t)
2409 (setq markdown-follow-wiki-link-on-enter nil)
2410 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2411 (setq ps-footer-font-size (quote (8 . 10)))
2412 (setq ps-header-font-size (quote (8 . 10)))
2413 (setq ps-header-title-font-size (quote (10 . 10)))
2414 (setq ps-line-number-color "blue")
2415 (setq ps-print-footer t)
2416 (setq ps-print-footer-frame nil)
2417 (setq ps-print-only-one-header t)
2418 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
2420 (setq sentence-end-double-space nil)
2421 ; enable matching parenthesis
2424 (setq user-mail-address "don@donarmstrong.com")
2425 (setq vc-delete-logbuf-window nil)
2426 (setq vc-follow-symlinks t)
2428 ;; use git before SVN; use CVS earlier, because I have CVS
2429 ;; repositories inside of git directories
2430 (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
2432 ;; switch back to the old primary selection method
2433 (setq x-select-enable-clipboard nil)
2434 (setq x-select-enable-primary t)
2435 ; (setq mouse-drag-copy-region t)
2437 (fset 'perl-mode 'cperl-mode)
2438 ;;(load-file "cperl-mode.el")
2440 ;; tramp configuration
2441 (setq tramp-use-ssh-controlmaster-options nil)
2443 (setq-default c-indent-level 4)
2444 (setq-default c-brace-imaginary-offset 0)
2445 (setq-default c-brace-offset -4)
2446 (setq-default c-argdecl-indent 4)
2447 (setq-default c-label-offset -4)
2448 (setq-default c-continued-statement-offset 4)
2450 (setq-default indent-tabs-mode nil)
2451 (setq-default tab-width 4)
2454 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2455 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2456 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2457 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2458 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2461 (defun insert-date ()
2462 "Insert date at point."
2464 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2465 (global-set-key "\C-[d" 'insert-date)
2467 (defun unfill-paragraph (arg)
2468 "Pull this whole paragraph up onto one line."
2470 (let ((fill-column 10000))
2471 (fill-paragraph arg))
2474 (column-number-mode t)
2477 ** Desktop-save-mode
2478 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2479 emacs, and use a different desktop file to restore history
2480 #+BEGIN_SRC emacs-lisp
2481 (use-package desktop
2484 (setq desktop-base-file-name
2485 (convert-standard-filename
2487 (or (getenv "EMACS_SERVER_NAME")
2491 (setq desktop-base-lock-name
2492 (convert-standard-filename
2493 (concat desktop-base-file-name
2495 (setq desktop-auto-save-timeout 60)
2496 (setq desktop-restore-eager 5)
2497 (setq desktop-lazy-verbose nil)
2498 (desktop-save-mode 1)
2502 ** Misc (Uncharacterized)
2503 #+BEGIN_SRC emacs-lisp
2504 '(icomplete-mode on)
2506 ;; custom-set-faces was added by Custom.
2507 ;; If you edit it by hand, you could mess it up, so be careful.
2508 ;; Your init file should contain only one such instance.
2509 ;; If there is more than one, they won't work right.
2510 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2513 (put 'upcase-region 'disabled nil)
2514 (put 'downcase-region 'disabled nil)
2515 (put 'narrow-to-region 'disabled nil)
2517 ; (defun turn-on-flyspell ()
2518 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2520 ; (flyspell-mode 1))
2523 ; Outline-minor-mode key map
2524 (define-prefix-command 'cm-map nil "Outline-")
2526 (define-key cm-map "q" 'outline-hide-sublevels) ; Hide everything but the top-level headings
2527 (define-key cm-map "t" 'outline-hide-body) ; Hide everything but headings (all body lines)
2528 (define-key cm-map "o" 'outline-hide-other) ; Hide other branches
2529 (define-key cm-map "c" 'outline-hide-entry) ; Hide this entry's body
2530 (define-key cm-map "l" 'outline-hide-leaves) ; Hide body lines in this entry and sub-entries
2531 (define-key cm-map "d" 'outline-hide-subtree) ; Hide everything in this entry and sub-entries
2533 (define-key cm-map "a" 'outline-show-all) ; Show (expand) everything
2534 (define-key cm-map "e" 'outline-show-entry) ; Show this heading's body
2535 (define-key cm-map "i" 'outline-show-children) ; Show this heading's immediate child sub-headings
2536 (define-key cm-map "k" 'outline-show-branches) ; Show all sub-headings under this heading
2537 (define-key cm-map "s" 'outline-show-subtree) ; Show (expand) everything in this heading & below
2539 (define-key cm-map "u" 'outline-up-heading) ; Up
2540 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2541 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2542 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2543 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2544 (global-set-key "\M-o" cm-map)
2545 ; fix up tmux xterm keys
2546 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2547 (defun fix-up-tmux-keys ()
2548 "Fix up tmux xterm keys"
2551 (let ((x 2) (tkey ""))
2571 ;; ctrl + alt + shift
2573 (setq tkey "C-M-S-"))
2576 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2577 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2578 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2579 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2581 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2583 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2585 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2587 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2589 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2591 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2593 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2595 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2597 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2599 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2601 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2603 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2605 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2607 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2609 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2611 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2613 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2615 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2617 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2619 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2621 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2623 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2625 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2627 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2629 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2631 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2638 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2640 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2641 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2642 (if (or (buffer-modified-p)
2643 (verify-visited-file-modtime)
2644 (< (* 8 1024 1024) (buffer-size))
2645 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2647 (clear-visited-file-modtime)
2649 (ad-activate 'ask-user-about-supersession-threat)
2653 #+BEGIN_SRC emacs-lisp
2657 (or (getenv "EMACS_SERVER_NAME")
2659 (unless (server-running-p)
2660 (global-set-key "\C-xp" 'server-edit)
2667 #+BEGIN_SRC emacs-lisp
2668 (provide 'don-configuration)