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)
115 (vcl-indent-level . 4)
119 #+BEGIN_SRC emacs-lisp
120 (setq global-mark-ring-max 128
124 (defun don/minibuffer-setup-hook ()
125 (setq gc-cons-threshold most-positive-fixnum))
127 (defun don/minibuffer-exit-hook ()
128 (setq gc-cons-threshold 1048576))
130 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
131 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
135 #+BEGIN_SRC emacs-lisp
136 (use-package hippie-exp
137 :bind* (("M-<SPC>" . hippie-expand))
141 #+BEGIN_SRC emacs-lisp
142 (use-package flyspell
144 :diminish flyspell-mode 🐝
146 (add-hook 'text-mode-hook 'turn-on-flyspell)
147 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
148 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
149 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
151 (setq ispell-program-name "ispell")
156 #+begin_src emacs-lisp :tangle yes
162 #+BEGIN_SRC emacs-lisp
167 #+BEGIN_SRC emacs-lisp
168 (use-package eyebrowse
170 :diminish eyebrowse-mode
171 :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
173 (setq eyebrowse-wrap-around t)
176 (defun my/eyebrowse-new-window-config ()
180 ;; start at 1 run till 0
181 (let ((j (mod (+ i 1) 10)))
182 (when (and (not done)
183 (not (eyebrowse--window-config-present-p j)))
184 (eyebrowse-switch-to-window-config j)
185 (call-interactively 'eyebrowse-rename-window-config2 j)
190 ;; I don't use latex-preview-pane
191 ;; (require 'latex-preview-pane)
192 ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
193 ;; ;; latex-preview-pane uses window-parameters which are
194 ;; ;; not preserved by eyebrowse, so we close the preview
195 ;; ;; pane before switching, it will be regenerated when we
196 ;; ;; edit the TeX file.
197 ;; (when (lpp/window-containing-preview)
198 ;; (delete-window (lpp/window-containing-preview))))
200 ;; (add-to-list 'eyebrowse-pre-window-switch-hook
201 ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
203 ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
204 ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
205 ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
206 ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
207 ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
215 #+BEGIN_SRC emacs-lisp
216 (defun my/vsplit-last-buffer ()
217 "Split the window vertically and display the previous buffer."
219 (split-window-vertically)
221 (switch-to-next-buffer))
223 (defun my/hsplit-last-buffer ()
224 "Split the window horizontally and display the previous buffer."
226 (split-window-horizontally)
228 (switch-to-next-buffer))
230 (bind-key "C-x 2" 'my/vsplit-last-buffer)
231 (bind-key "C-x 3" 'my/hsplit-last-buffer)
233 (setq split-width-threshold 100)
234 (setq split-height-threshold 60)
236 (defun my/split-window-prefer-vertically (window)
237 "If there's only one window (excluding any possibly active
238 minibuffer), then split the current window horizontally."
239 (if (and (one-window-p t)
240 (not (active-minibuffer-window))
241 ( < (frame-width) (frame-height))
243 (let ((split-width-threshold nil))
244 (split-window-sensibly window))
245 (split-window-sensibly window)))
247 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
248 (setq window-combination-resize t)
251 *** Compilation window
253 If there is no compilation window, open one at the bottom, spanning
254 the complete width of the frame. Otherwise, reuse existing window. In
255 the former case, if there was no error the window closes
258 #+BEGIN_SRC emacs-lisp
259 (add-to-list 'display-buffer-alist
260 `(,(rx bos "*compilation*" eos)
261 (display-buffer-reuse-window
262 display-buffer-in-side-window)
263 (reusable-frames . visible)
265 (window-height . 0.4)))
268 #+BEGIN_SRC emacs-lisp
269 (defun my/compilation-exit-autoclose (status code msg)
270 ;; If M-x compile exists with a 0
271 (when (and (eq status 'exit) (zerop code))
272 ;; and delete the *compilation* window
273 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
274 (when (and (not (window-at-side-p compilation-window 'top))
275 (window-at-side-p compilation-window 'left)
276 (window-at-side-p compilation-window 'right))
277 (delete-window compilation-window))))
278 ;; Always return the anticipated result of compilation-exit-message-function
281 ;; Specify my function (maybe I should have done a lambda function)
282 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
285 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
286 value, the compilation buffer scrolls automatically to follow the
287 output. If the value is ~first-error~, scrolling stops when the first
288 error appears, leaving point at that error. For any other non-nil
289 value, scrolling continues until there is no more output.
291 #+BEGIN_SRC emacs-lisp
292 (setq compilation-scroll-output 'first-error)
295 ** Mode line cleaning
297 #+BEGIN_SRC emacs-lisp
298 (use-package diminish
303 #+BEGIN_SRC emacs-lisp
310 #+BEGIN_SRC emacs-lisp
313 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
314 ("C-c j j" . avy-goto-word-or-subword-1)
315 ("M-g g" . avy-goto-line))
316 :config (progn (setq avy-background t))
319 *** Ace-link (jumping to links)
320 #+BEGIN_SRC emacs-lisp
321 (use-package ace-link
323 ; bind o in most modes
324 :config (ace-link-setup-default))
326 *** Jumping through edit points (goto-chg)
327 #+BEGIN_SRC emacs-lisp
328 (use-package goto-chg
330 :bind (("C-c j ," . goto-last-change)
331 ("C-c j ." . goto-last-change-reverse))
334 *** Jumping to bookmarks (visible bookmarks, bm)
335 #+BEGIN_SRC emacs-lisp
338 :bind (("C-c j b ." . bm-next)
339 ("C-c j b ," . bm-previous)
340 ("C-c j b SPC" . bm-toggle)))
345 #+BEGIN_SRC emacs-lisp
346 (use-package yasnippet
348 :diminish yas-minor-mode
351 (setq yas-verbosity 1)
352 (define-key yas-minor-mode-map (kbd "<tab>") nil)
353 (define-key yas-minor-mode-map (kbd "TAB") nil)
354 (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
355 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
356 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
357 (add-to-list 'hippie-expand-try-functions-list
358 'yas-hippie-try-expand)
364 #+BEGIN_SRC emacs-lisp
365 (use-package auto-yasnippet
367 :bind (("H-w" . aya-create)
373 #+BEGIN_SRC emacs-lisp
376 :bind (("M-/" . company-complete))
378 (setq company-echo-delay 0 ; remove blinking
379 company-show-numbers t ; show numbers for easy selection
380 company-selection-wrap-around t
381 company-require-match nil
382 company-dabbrev-ignore-case t
383 company-dabbrev-ignore-invisible t
384 company-dabbrev-other-buffers t
385 company-dabbrev-downcase nil
386 company-dabbrev-code-everywhere t
387 company-tooltip-align-annotations t
388 company-minimum-prefix-length 1
389 company-global-modes '(not)
390 company-lighter-base "(C)")
391 (global-company-mode 1)
393 (bind-key "C-n" #'company-select-next company-active-map)
394 (bind-key "C-p" #'company-select-previous company-active-map)
395 ; (bind-key "<tab>" #'company-complete company-active-map)
396 (bind-key "M-?" #'company-show-doc-buffer company-active-map)
397 (bind-key "M-." #'company-show-location company-active-map)
398 (bind-key "M-/" #'company-complete-common org-mode-map)
402 #+BEGIN_SRC emacs-lisp
403 (use-package company-c-headers
406 (defun malb/ede-object-system-include-path ()
407 "Return the system include path for the current buffer."
409 (ede-system-include-path ede-object)))
411 (setq company-c-headers-path-system
412 #'malb/ede-object-system-include-path)
414 (add-to-list 'company-backends #'company-c-headers)))
417 #+BEGIN_SRC emacs-lisp
418 (use-package company-anaconda
420 :config (add-to-list 'company-backends #'company-anaconda))
423 #+BEGIN_SRC emacs-lisp
424 (use-package company-plsense
429 #+BEGIN_SRC emacs-lisp
430 (use-package company-math
433 #+BEGIN_SRC emacs-lisp
434 (use-package company-auctex
437 (defun company-auctex-labels (command &optional arg &rest ignored)
438 "company-auctex-labels backend"
439 (interactive (list 'interactive))
441 (interactive (company-begin-backend 'company-auctex-labels))
442 (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
443 (candidates (company-auctex-label-candidates arg))))
445 (add-to-list 'company-backends
446 '(company-auctex-macros
447 company-auctex-environments
448 company-math-symbols-unicode
449 company-math-symbols-latex))
451 (add-to-list 'company-backends #'company-auctex-labels)
452 (add-to-list 'company-backends #'company-auctex-bibs)
456 #+BEGIN_SRC emacs-lisp
457 (use-package company-bibtex
463 #+BEGIN_SRC emacs-lisp
464 (use-package company-shell
467 (setq company-shell-modes '(sh-mode shell-mode))
468 (add-to-list 'company-backends 'company-shell)))
473 Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
475 *Note:* Do this at the end of =company-mode= config.
477 #+BEGIN_SRC emacs-lisp
478 (defvar malb/company-mode/enable-yas t
479 "Enable yasnippet for all backends.")
481 (defun malb/company-mode/backend-with-yas (backend)
482 (if (or (not malb/company-mode/enable-yas)
484 (member 'company-yasnippet backend)))
486 (append (if (consp backend) backend (list backend))
487 '(:with company-yasnippet))))
489 (setq company-backends
490 (mapcar #'malb/company-mode/backend-with-yas company-backends))
495 Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
497 #+BEGIN_SRC emacs-lisp
498 (defun malb/toggle-company-ispell ()
501 ((member '(company-ispell :with company-yasnippet) company-backends)
502 (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
503 (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
504 (message "company-ispell disabled"))
506 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
507 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
508 (message "company-ispell enabled!"))))
510 (defun malb/company-ispell-setup ()
511 ;; @see https://github.com/company-mode/company-mode/issues/50
512 (when (boundp 'company-backends)
513 (make-local-variable 'company-backends)
514 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
515 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
516 ;; https://github.com/redguardtoo/emacs.d/issues/473
517 (if (and (boundp 'ispell-alternate-dictionary)
518 ispell-alternate-dictionary)
519 (setq company-ispell-dictionary ispell-alternate-dictionary))))
524 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
526 2. This function then hopefully does what I want:
528 a. if a region is active, just indent
529 b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
530 c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
531 d. otherwise call whatever would have been called otherwise.
533 ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
535 #+BEGIN_SRC emacs-lisp
536 (defun malb/indent-fold-or-complete (&optional arg)
539 ;; if a region is active, indent
541 (indent-region (region-beginning)
543 ;; if the next char is space or eol, but prev char not whitespace
544 ((and (not (active-minibuffer-window))
547 (looking-back "[^[:space:]]")
548 (not (looking-back "^")))
550 (cond (company-mode (company-complete-common))
551 (auto-complete-mode (auto-complete))))
553 ;; no whitespace anywhere
554 ((and (not (active-minibuffer-window))
555 (looking-at "[^[:space:]]")
556 (looking-back "[^[:space:]]")
557 (not (looking-back "^")))
559 ((bound-and-true-p hs-minor-mode)
560 (save-excursion (end-of-line) (hs-toggle-hiding)))
561 ((bound-and-true-p outline-minor-mode)
562 (save-excursion (outline-cycle)))))
564 ;; by default just call whatever was bound
566 (let ((fn (or (lookup-key (current-local-map) (kbd "TAB"))
567 'indent-for-tab-command)))
568 (if (not (called-interactively-p 'any))
570 (setq this-command fn)
571 (call-interactively fn))))))
573 (defun malb/toggle-fold ()
575 (cond ((eq major-mode 'org-mode)
576 (org-force-cycle-archived))
577 ((bound-and-true-p hs-minor-mode)
582 ((bound-and-true-p outline-minor-mode)
586 (bind-key "<tab>" #'malb/indent-fold-or-complete)
587 (bind-key "C-<tab>" #'malb/toggle-fold)
591 #+BEGIN_SRC emacs-lisp
593 (use-package tinyprocmail
594 :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
595 :mode (".procmailrc" . turn-on-tinyprocmail-mode)
600 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
603 :bind (("C-x g" . magit-status)
604 ("C-x C-g" . magit-status))
606 ;; refine diffs always (hilight words)
607 (setq magit-diff-refine-hunk nil)
609 (use-package magit-annex
611 :load-path "~/lib/emacs_el/magit-annex/"
613 (use-package magit-vcsh
614 :ensure f ; currently not in melpa, so don't try to install
615 :load-path "~/lib/emacs_el/magit-vcsh/"
620 #+BEGIN_SRC emacs-lisp
621 (use-package cperl-mode
624 ;; Use c-mode for perl .xs files
625 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
626 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
627 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
628 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
629 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
632 cperl-auto-newline nil
633 cperl-auto-newline-after-colon nil
634 cperl-continued-statement-offset 4
635 cperl-brace-offset -1
636 cperl-continued-brace-offset 0
637 cperl-label-offset -4
638 cperl-highlight-variables-indiscriminately t
639 cperl-electric-lbrace-space nil
640 cperl-indent-parens-as-block nil
641 cperl-close-paren-offset -1
642 cperl-tab-always-indent t)
643 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
648 #+BEGIN_SRC emacs-lisp
649 (use-package markdown-mode
651 :mode (("\\.md\\'" . markdown-mode)
652 ("\\.mdwn\\'" . markdown-mode)
653 ("README\\.md\\'" . gfm-mode)
656 (setq markdown-enable-math t)
657 (setq markdown-follow-wiki-link-on-enter nil)
658 (bind-key "M-." #'markdown-jump markdown-mode-map)
659 (add-hook 'markdown-mode-hook #'flyspell-mode)
660 (add-hook 'markdown-mode-hook #'outline-minor-mode)
661 (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
666 #+BEGIN_SRC emacs-lisp
667 ; load sql-indent when sql is loaded
669 :mode (("\\.sql\\'" . sql-mode))
671 (require sql-indent))
674 #+BEGIN_SRC emacs-lisp
676 :commands ediff ediff3
679 ;; ediff configuration
680 ;; don't use the multi-window configuration
681 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
684 ** VCL --editing varnish configuration files
685 #+BEGIN_SRC emacs-lisp
686 (use-package vcl-mode
693 #+BEGIN_SRC emacs-lisp
694 (defun malb/helm-omni (&rest arg)
695 ;; just in case someone decides to pass an argument, helm-omni won't fail.
697 (unless helm-source-buffers-list
698 (setq helm-source-buffers-list
699 (helm-make-source "Buffers" 'helm-source-buffers)))
703 (if (projectile-project-p)
704 '(helm-source-projectile-buffers-list
705 helm-source-buffers-list)
706 '(helm-source-buffers-list)) ;; list of all open buffers
708 `(((name . "Virtual Workspace")
709 (candidates . ,(--map (cons (eyebrowse-format-slot it) (car it))
710 (eyebrowse--get 'window-configs)))
711 (action . (lambda (candidate)
712 (eyebrowse-switch-to-window-config candidate)))))
714 (if (projectile-project-p)
715 '(helm-source-projectile-recentf-list
717 '(helm-source-recentf)) ;; all recent files
719 ;; always make some common files easily accessible
720 ;;'(((name . "Common Files")
721 ;; (candidates . malb/common-file-targets)
722 ;; (action . (("Open" . (lambda (x) (find-file (eval x))))))))
724 '(helm-source-files-in-current-dir
726 helm-source-bookmarks
727 helm-source-buffer-not-found ;; ask to create a buffer otherwise
729 "*Helm all the things*"))
733 :bind (("M-x" . helm-M-x)
734 ("C-x C-f" . helm-find-files)
735 ("C-x b" . helm-buffers-list) ; malb/helm-omni)
736 ("C-x C-b" . helm-buffers-list) ; malb/helm-omni)
737 ("C-c <SPC>" . helm-all-mark-rings))
739 (require 'helm-config)
740 (require 'helm-for-files)
741 (require 'helm-bookmark)
744 (define-key global-map [remap find-file] 'helm-find-files)
745 (define-key global-map [remap occur] 'helm-occur)
746 (define-key global-map [remap list-buffers] 'helm-buffers-list)
747 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
748 (unless (boundp 'completion-in-region-function)
749 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
750 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
751 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
756 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
758 #+BEGIN_SRC emacs-lisp
759 (use-package helm-flx
762 ;; these are helm configs, but they kind of fit here nicely
763 (setq helm-M-x-fuzzy-match t
764 helm-bookmark-show-location t
765 helm-buffers-fuzzy-matching t
766 helm-completion-in-region-fuzzy-match t
767 helm-file-cache-fuzzy-match t
768 helm-imenu-fuzzy-match t
769 helm-mode-fuzzy-match t
770 helm-locate-fuzzy-match nil
772 helm-recentf-fuzzy-match nil
773 helm-semantic-fuzzy-match t)
777 #+BEGIN_SRC emacs-lisp
779 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
780 (defun malb/helm-swoop-pre-fill ()
781 (thing-at-point 'symbol))
782 (defvar malb/helm-swoop-ignore-major-mode "List of major modes to ignore for helm-swoop")
783 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
784 paradox-menu-mode doc-view-mode pdf-view-mode
785 mu4e-headers-mode org-mode markdown-mode latex-mode
786 ein:notebook-multilang-mode))
788 (defun malb/swoop-or-search ()
790 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
791 (memq major-mode malb/helm-swoop-ignore-major-mode))
795 (use-package helm-swoop
798 :bind (("C-c o" . helm-multi-swoop-org)
799 ("C-s" . malb/swoop-or-search)
800 ("C-M-s" . helm-multi-swoop-all))
803 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
804 helm-swoop-split-with-multiple-windows nil
805 helm-swoop-split-direction #'split-window-horizontally
806 helm-swoop-split-window-function 'helm-default-display-buffer
807 helm-swoop-speed-or-color t)
809 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
810 (defun malb/helm-swoop-C-s ()
812 (if (boundp 'helm-swoop-pattern)
813 (if (equal helm-swoop-pattern "")
814 (previous-history-element 1)
818 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
819 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
820 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
821 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
822 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
823 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
828 #+BEGIN_SRC emacs-lisp
831 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
832 helm-ag-command-option "--all-text"
833 helm-ag-insert-at-point 'symbol
834 helm-ag-fuzzy-match t
835 helm-ag-use-temp-buffer t
836 helm-ag-use-grep-ignore-list t
837 helm-ag-use-agignore t))
840 #+BEGIN_SRC emacs-lisp
841 (use-package helm-descbinds
843 :bind ("C-h b" . helm-descbinds)
844 :init (fset 'describe-bindings 'helm-descbinds))
848 #+BEGIN_SRC emacs-lisp
849 (use-package helm-c-yasnippet
851 :bind ("C-c h y" . helm-yas-complete)
853 (setq helm-yas-space-match-any-greedy t)))
856 #+BEGIN_SRC emacs-lisp
857 (use-package helm-org-rifle
860 (defun malb/helm-org-rifle-agenda-files (arg)
862 (let ((current-prefix-arg nil))
864 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
865 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
866 (t (helm-org-agenda-files-headings)))))))
869 This can be used to link things pretty quickly if necessary
870 #+BEGIN_SRC emacs-lisp
871 (use-package helm-google
873 :bind ("C-c h g" . helm-google)
875 (progn (add-to-list 'helm-google-actions
876 '("Copy URL" . (lambda (candidate)
878 (replace-regexp-in-string
879 "https://.*q=\\(.*\\)\&sa=.*"
885 (add-to-list 'helm-google-actions
886 '("Org Store Link" . (lambda (candidate)
887 (let ((title (car (split-string candidate "[\n]+")))
889 (replace-regexp-in-string
890 "https://.*q=\\(.*\\)\&sa=.*"
892 (push (list url title) org-stored-links))))
897 ** Projectile -- Project management
898 #+begin_src emacs-lisp
899 (use-package projectile
901 :bind (("<f5>" . projectile-compile-project)
902 ("<f6>" . next-error))
904 (use-package magit :ensure t)
905 (require 'helm-projectile)
908 (setq projectile-make-test-cmd "make check"
909 projectile-switch-project-action 'helm-projectile
910 projectile-mode-line '(:eval (format "»{%s}" (projectile-project-name))))
912 (projectile-global-mode)))
916 #+begin_src emacs-lisp
917 (use-package helm-projectile
920 (defvar malb/helm-source-file-not-found
921 (helm-build-dummy-source
926 'helm-projectile-sources-list
927 malb/helm-source-file-not-found t)
929 (helm-delete-action-from-source
930 "Grep in projects `C-s'"
931 helm-source-projectile-projects)
933 (helm-add-action-to-source
934 "Grep in projects `C-s'"
935 'helm-do-ag helm-source-projectile-projects 4)))
938 #+BEGIN_SRC emacs-lisp
941 :bind ("M-z" . avy-zap-up-to-char-dwim))
944 #+BEGIN_SRC emacs-lisp
946 :bind (("C-c 2" . my/hydra-orgmodes/body)
947 ("C-c @" . my/hydra-orgmodes/body)
948 ("C-c #" . my/hydra-outline/body)
949 ("C-c 3" . my/hydra-outline/body)
952 (defhydra my/hydra-orgmodes (:color blue :hint nil)
954 _n_: notes _c_: chaim _w_: wildman _o_: ool
955 _u_: uddin _s_: steve _r_: refile _f_: fh
956 _p_: read papers _R_: paper notes
961 ("n" (find-file "~/projects/org-notes/notes.org"))
962 ("c" (find-file "~/projects/org-notes/chaim.org"))
963 ("w" (find-file "~/projects/org-notes/wildman.org"))
964 ("u" (find-file "~/projects/org-notes/uddin.org"))
965 ("o" (find-file "~/projects/org-notes/ool.org"))
966 ("f" (find-file "~/projects/org-notes/fh.org"))
967 ("s" (find-file "~/projects/org-notes/sndservers.org"))
968 ("r" (find-file "~/projects/org-notes/refile.org"))
969 ("p" (find-file "~/projects/research/papers_to_read.org"))
970 ("R" (find-file "~/projects/research/paper_notes.org"))
971 ("h" (find-file "~/projects/org-notes/hpcbio.org"))
976 ;; from https://github.com/abo-abo/hydra/wiki/Emacs
977 (defhydra my/hydra-outline (:color pink :hint nil)
980 ^^^^^^------------------------------------------------------
981 _q_: sublevels _a_: all _u_: up
982 _t_: body _e_: entry _n_: next visible
983 _o_: other _i_: children _p_: previous visible
984 _c_: entry _k_: branches _f_: forward same level
985 _l_: leaves _s_: subtree _b_: backward same level
990 ("q" outline-hide-sublevels) ; Hide everything but the top-level headings
991 ("t" outline-hide-body) ; Hide everything but headings (all body lines)
992 ("o" outline-hide-other) ; Hide other branches
993 ("c" outline-hide-entry) ; Hide this entry's body
994 ("l" outline-hide-leaves) ; Hide body lines in this entry and sub-entries
995 ("d" outline-hide-subtree) ; Hide everything in this entry and sub-entries
997 ("a" outline-show-all) ; Show (expand) everything
998 ("e" outline-show-entry) ; Show this heading's body
999 ("i" outline-show-children) ; Show this heading's immediate child sub-headings
1000 ("k" outline-show-branches) ; Show all sub-headings under this heading
1001 ("s" outline-show-subtree) ; Show (expand) everything in this heading & below
1003 ("u" outline-up-heading) ; Up
1004 ("n" outline-next-visible-heading) ; Next
1005 ("p" outline-previous-visible-heading) ; Previous
1006 ("f" outline-forward-same-level) ; Forward - same level
1007 ("b" outline-backward-same-level) ; Backward - same level
1013 #+BEGIN_SRC emacs-lisp
1016 (add-to-list 'tramp-methods '("vcsh"
1017 (tramp-login-program "vcsh")
1021 (tramp-remote-shell "/bin/sh")
1022 (tramp-remote-shell-args
1026 #+BEGIN_SRC emacs-lisp
1030 (setq-default reftex-default-bibliography
1031 '("~/projects/research/references.bib")))
1034 #+BEGIN_SRC emacs-lisp
1036 :config (setq bibtex-user-optional-fields
1037 (quote (("annote" "Personal annotation (ignored)")
1045 #+BEGIN_SRC emacs-lisp
1050 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1051 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1052 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1053 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
1054 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
1055 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1056 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1057 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
1058 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
1059 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
1060 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
1062 (setq-default reftex-plug-into-AUCTeX t)
1063 ;; support fake section headers
1064 (setq TeX-outline-extra
1068 ("%subsubsection" 4)
1070 ;; add font locking to the headers
1071 (font-lock-add-keywords
1073 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1074 0 'font-lock-keyword-face t)
1075 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
1076 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
1077 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
1078 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1079 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
1081 ;; use smart quotes by default instead of `` and ''
1082 ;; taken from http://kieranhealy.org/esk/kjhealy.html
1083 (setq TeX-open-quote "“")
1084 (setq TeX-close-quote "”")
1086 ;; (TeX-add-style-hook
1091 ;; (custom-set-variables
1092 ;; '(font-latex-user-keyword-classes
1095 ;; font-lock-function-name-face 2 (command 1 t))))
1097 (setq-default TeX-parse-self t)
1098 (setq-default TeX-auto-save t)
1099 (setq-default TeX-master nil)
1102 '(TeX-add-style-hook
1105 (if (boundp 'reftex-ref-style-alist)
1107 'reftex-ref-style-alist
1108 '("Cleveref" "cleveref"
1109 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1110 (reftex-ref-style-activate "Cleveref")
1112 '("cref" TeX-arg-ref)
1113 '("Cref" TeX-arg-ref)
1114 '("cpageref" TeX-arg-ref)
1115 '("Cpageref" TeX-arg-ref)))))
1118 '(add-to-list 'LaTeX-fill-excluded-macros
1121 (use-package font-latex
1123 (setq font-latex-match-reference-keywords
1145 (setq font-latex-fontify-script nil)
1146 (setq font-latex-fontify-sectioning (quote color))
1147 (setq font-latex-script-display (quote (nil)))
1152 #+BEGIN_SRC emacs-lisp
1156 :mode ("\\.R\\'" . ess-r-mode)
1157 :bind (:map ess-mode-map
1158 ("C-c C-R" . dla/ess-region-remote-eval))
1160 (autoload 'ess-r-mode "ess-site" nil t)
1161 (autoload 'R "ess-site" nil t)
1163 ; actually load the rest of ess
1165 (defun ess-change-directory (path)
1166 "Set the current working directory to PATH for both *R* and Emacs."
1167 (interactive "Directory to change to: ")
1169 (when (file-exists-p path)
1170 (ess-command (concat "setwd(\"" path "\")\n"))
1171 ;; use file-name-as-directory to ensure it has trailing /
1172 (setq default-directory (file-name-as-directory path))))
1173 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1174 ;; outlining support for ess modes
1178 (outline-minor-mode)
1179 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1180 (defun outline-level ()
1181 (cond ((looking-at "^##### ") 1)
1182 ((looking-at "^#### ") 2)
1183 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1186 (defun dla/ess-region-remote-eval (start end)
1187 "Evaluate region in a remote ESS instance"
1189 (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***"))
1190 kill-buffer "***essregionremoteeval***")
1191 ;; Don't restore history or save workspace image
1192 '(inferior-R-args "--no-restore-history --no-save")
1197 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1199 #+BEGIN_SRC emacs-lisp
1200 (use-package rainbow-mode
1201 ;; add ess to the x major mode
1202 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1203 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1208 #+BEGIN_SRC emacs-lisp
1209 (use-package polymode
1211 (use-package poly-R)
1212 (use-package poly-noweb)
1213 (use-package poly-markdown)
1214 :mode ("\\.Snw" . poly-noweb+r-mode)
1215 :mode ("\\.Rnw" . poly-noweb+r-mode)
1216 :mode ("\\.Rmd" . poly-markdown+r-mode)
1222 #+BEGIN_SRC emacs-lisp
1223 (use-package outline-magic)
1226 #+BEGIN_SRC emacs-lisp
1227 ;; change the outline mode prefix from C-c @ to C-c C-2
1228 (setq outline-minor-mode-prefix "C-c C-2")
1229 ;;(add-hook 'outline-minor-mode-hook
1230 ;; (lambda () (local-set-key (kbd "C-c C-2")
1231 ;; outline-mode-prefix-map)))
1235 #+BEGIN_SRC emacs-lisp
1236 (use-package writeroom-mode
1238 (defun my/writing-mode ()
1239 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1244 (visual-line-mode -1)
1246 (visual-fill-column-mode -1)
1248 (visual-line-mode 1)
1250 (visual-fill-column-mode 1)
1255 ** GhostText/Atomic Chrome
1256 #+BEGIN_SRC emacs-lisp
1257 (use-package atomic-chrome
1259 (ignore-errors (atomic-chrome-start-server))
1260 (setq atomic-chrome-buffer-open-style 'full)
1265 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
1267 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1268 #+BEGIN_SRC emacs-lisp
1269 (use-package multiple-cursors
1270 :bind* (("C-;" . mc/mark-all-dwim)
1271 ("C-<" . mc/mark-previous-like-this)
1272 ("C->" . mc/mark-next-like-this)
1273 ("C-S-c C-S-c" . mc/edit-lines))
1277 #+BEGIN_SRC emacs-lisp
1278 (use-package web-mode
1280 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1281 (setq web-mode-enable-engine-detection t)
1282 (setq web-mode-engines-alist
1283 '(("template-toolkit" . "\\.tmpl\\'")))
1286 ** Spamassassin Mode
1287 #+BEGIN_SRC emacs-lisp
1288 (use-package spamassassin-mode
1289 :commands spamassassin-mode
1294 #+BEGIN_SRC emacs-lisp
1295 (use-package password-store
1297 :commands password-store-edit password-store-generate
1301 #+BEGIN_SRC emacs-lisp
1305 ;; fix up css mode to not be silly
1306 ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1307 (setq cssm-indent-level 4)
1308 (setq cssm-newline-before-closing-bracket t)
1309 (setq cssm-indent-function #'cssm-c-style-indenter)
1310 (setq cssm-mirror-mode nil))
1313 #+BEGIN_SRC emacs-lisp
1315 :diminish abbrev-mode
1317 ;; load abbreviations from
1318 (setq abbrev-file-name
1319 "~/.emacs_abbrev_def")
1321 ;; read the abbrev file if it exists
1322 (if (file-exists-p abbrev-file-name)
1323 (quietly-read-abbrev-file))
1325 ;; for now, use abbrev mode everywhere
1326 (setq default-abbrev-mode t))
1332 #+BEGIN_SRC emacs-lisp
1333 (use-package message
1335 :diminish (message "✉")
1336 :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1337 :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1338 :hook 'my/message-mode-settings
1339 :hook 'turn-on-flyspell
1340 :bind (:map message-mode-map
1341 ("C-c C-a" . my/post-attach-file))
1342 :delight (message-mode "✉")
1344 (defun my/message-mode-settings ()
1345 (font-lock-add-keywords nil
1346 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1347 (0 'message-multiply-quoted-text-face))
1348 ("^[ \t]*>[ \t]*>.*$"
1349 (0 'message-double-quoted-text-face))))
1352 (defun my/post-attach-file ()
1353 "Prompt for an attachment."
1355 (let ((file (read-file-name "Attach file: " nil nil t nil)))
1356 (my/header-attach-file file "")))
1358 (defun my/header-attach-file (file description)
1359 "Attach a FILE to the current message (works with Mutt).
1360 Argument DESCRIPTION MIME description."
1361 (interactive "fAttach file: \nsDescription: ")
1362 (when (> (length file) 0)
1367 (goto-char (point-min))
1368 (search-forward-regexp "^$")
1369 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1371 (message (concat "Attached '" file "'."))
1372 (setq post-has-attachment t))))))
1374 (setq mail-yank-prefix "> ")
1378 #+BEGIN_SRC emacs-lisp
1379 (use-package muttrc-mode
1386 ** Reverting buffers
1387 #+BEGIN_SRC emacs-lisp
1388 (use-package autorevert
1389 :diminish auto-revert-mode
1391 (setq global-auto-revert-non-file-buffers t
1392 global-auto-revert-ignore-modes '(pdf-view-mode)
1393 auto-revert-verbose nil)
1394 (global-auto-revert-mode 1))
1397 ** Use-package and load things
1398 #+BEGIN_SRC emacs-lisp
1401 :delight (org-mode "ø")
1402 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1403 :bind (("C-c l" . org-store-link)
1404 ("C-c a" . org-agenda)
1405 ("C-c b" . org-iswitchb))
1407 ** Agenda Configuration
1408 #+BEGIN_SRC emacs-lisp
1410 (setq-default org-log-done 'time)
1411 (setq-default org-agenda-ndays 5)
1413 (setq org-agenda-sticky t)
1414 (defun dla/show-org-agenda ()
1419 (and (string-match-p
1427 (buffer-name agendabuffer))
1429 (delete-other-windows))
1431 ;; agenda configuration
1432 ;; Do not dim blocked tasks
1433 (setq org-agenda-dim-blocked-tasks nil)
1434 (setq org-agenda-inhibit-startup t)
1435 (setq org-agenda-use-tag-inheritance nil)
1437 ;; Compact the block agenda view
1438 (setq org-agenda-compact-blocks t)
1440 ;; Custom agenda command definitions
1441 (setq org-agenda-custom-commands
1442 (quote (("N" "Notes" tags "NOTE"
1443 ((org-agenda-overriding-header "Notes")
1444 (org-tags-match-list-sublevels t)))
1445 ("h" "Habits" tags-todo "STYLE=\"habit\""
1446 ((org-agenda-overriding-header "Habits")
1447 (org-agenda-sorting-strategy
1448 '(todo-state-down effort-up category-keep))))
1452 ((org-agenda-overriding-header "Tasks to Refile")
1453 (org-tags-match-list-sublevels nil)))
1454 (tags-todo "-CANCELLED/!"
1455 ((org-agenda-overriding-header "Stuck Projects")
1456 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1457 (org-agenda-sorting-strategy
1459 (tags-todo "-HOLD-CANCELLED/!"
1460 ((org-agenda-overriding-header "Projects")
1461 (org-agenda-skip-function 'bh/skip-non-projects)
1462 (org-tags-match-list-sublevels 'indented)
1463 (org-agenda-sorting-strategy
1465 (tags-todo "-CANCELLED/!NEXT"
1466 ((org-agenda-overriding-header (concat "Project Next Tasks"
1467 (if bh/hide-scheduled-and-waiting-next-tasks
1469 " (including WAITING and SCHEDULED tasks)")))
1470 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1471 (org-tags-match-list-sublevels t)
1472 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1473 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1474 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1475 (org-agenda-sorting-strategy
1476 '(todo-state-down effort-up category-keep))))
1477 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1478 ((org-agenda-overriding-header (concat "Project Subtasks"
1479 (if bh/hide-scheduled-and-waiting-next-tasks
1481 " (including WAITING and SCHEDULED tasks)")))
1482 (org-agenda-skip-function 'bh/skip-non-project-tasks)
1483 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1484 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1485 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1486 (org-agenda-sorting-strategy
1488 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1489 ((org-agenda-overriding-header (concat "Standalone Tasks"
1490 (if bh/hide-scheduled-and-waiting-next-tasks
1492 " (including WAITING and SCHEDULED tasks)")))
1493 (org-agenda-skip-function 'bh/skip-project-tasks)
1494 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1495 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1496 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1497 (org-agenda-sorting-strategy
1499 (tags-todo "-CANCELLED+WAITING|HOLD/!"
1500 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1501 (org-agenda-skip-function 'bh/skip-stuck-projects)
1502 (org-tags-match-list-sublevels nil)
1503 (org-agenda-todo-ignore-scheduled t)
1504 (org-agenda-todo-ignore-deadlines t)))
1506 ((org-agenda-overriding-header "Tasks to Archive")
1507 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1508 (org-tags-match-list-sublevels nil))))
1511 ; org mode agenda files
1512 (setq org-agenda-files
1513 (quote ("~/projects/org-notes/debbugs.org"
1514 "~/projects/org-notes/notes.org"
1515 "~/projects/org-notes/holidays.org"
1516 "~/projects/org-notes/refile.org"
1517 "~/projects/org-notes/diary.org"
1518 "~/projects/org-notes/ool.org"
1519 "~/projects/org-notes/sndservers.org"
1520 "~/projects/org-notes/chaim.org"
1521 "~/projects/org-notes/wildman.org"
1522 "~/projects/org-notes/uddin.org"
1523 "~/projects/org-notes/reviews.org"
1524 "~/projects/org-notes/laurel.org"
1525 "~/projects/org-notes/from-calendar.org"
1526 "~/org-mode/from-mobile.org"
1527 "~/projects/org-notes/fh.org")))
1529 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1530 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
1531 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1532 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1533 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1534 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1535 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1536 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1537 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1538 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1539 (defun org-agenda-timeline-all (&optional arg)
1542 (dolist (org-agenda-file org-agenda-files)
1543 (insert-file-contents org-agenda-file nil)
1544 (goto-char (point-max))
1546 (write-file "/tmp/timeline.org")
1547 (org-agenda arg "L")))
1548 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1552 #+BEGIN_SRC emacs-lisp
1553 (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")))
1554 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1556 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1557 (setq org-id-link-to-org-use-id 'use-existing)
1559 ** Capture Templates
1560 #+BEGIN_SRC emacs-lisp
1561 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1562 `(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
1563 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1564 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
1565 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1566 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
1567 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1568 ("n" "note" entry (file "~/projects/org-notes/refile.org")
1569 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1570 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
1571 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1572 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1573 "* %?\n%U\n" :clock-in t :clock-resume t)
1574 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
1575 "* TODO Review %c\n%U\n" :immediate-finish t)
1576 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
1577 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1578 ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
1579 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1580 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1581 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1582 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
1583 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1584 ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1586 ,(format-time-string "Positions %Y"))
1587 "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1588 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
1589 "* 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")
1593 ;; Remove empty LOGBOOK drawers on clock out
1594 (defun bh/remove-empty-drawer-on-clock-out ()
1597 (beginning-of-line 0)
1598 (org-remove-empty-drawer-at (point))))
1600 (defun my/org-add-id ()
1603 (if (org-current-level)
1612 ** Org mode key bindings
1613 #+BEGIN_SRC emacs-lisp
1614 ;; org mode configuration from http://doc.norang.ca/org-mode.html
1615 ;; Custom Key Bindings
1616 :bind* (("<f9> a" . org-agenda)
1617 ("<f9> I" . bh/punch-in)
1618 ("<f9> O" . bh/punch-out)
1619 ("<f9> SPC" . bh/clock-in-last-task)
1620 ("<f12>" . dla/show-org-agenda)
1621 ;; ("<f5>" . bh/org-todo)
1622 ("<S-f5>" . bh/widen)
1623 ("<f7>" . bh/set-truncate-lines)
1624 ("<f8>" . org-cycle-agenda-files)
1625 ("<f9> <f9>" . dla/show-org-agenda)
1627 ("<f9> c" . calendar)
1628 ("<f9> f" . boxquote-insert-file)
1629 ("<f9> h" . bh/hide-other)
1630 ("<f9> n" . bh/toggle-next-task-display)
1633 ("<f9> r" . boxquote-region)
1634 ("<f9> s" . bh/switch-to-scratch)
1636 ("<f9> t" . bh/insert-inactive-timestamp)
1637 ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1639 ("<f9> v" . visible-mode)
1640 ("<f9> l" . org-toggle-link-display)
1641 ("<f9> SPC" . bh/clock-in-last-task)
1642 ("C-<f9>" . previous-buffer)
1643 ("M-<f9>" . org-toggle-inline-images)
1644 ("C-x n r" . narrow-to-region)
1645 ("C-<f10>" . next-buffer)
1646 ("<f11>" . org-clock-goto)
1647 ("C-<f11>" . org-clock-in)
1648 ("C-s-<f12>" . bh/save-then-publish)
1649 ("C-c c" . org-capture))
1652 ** Utility Functions
1653 #+BEGIN_SRC emacs-lisp
1654 (defun bh/hide-other ()
1657 (org-back-to-heading 'invisible-ok)
1663 (defun bh/set-truncate-lines ()
1664 "Toggle value of truncate-lines and refresh window display."
1666 (setq truncate-lines (not truncate-lines))
1667 ;; now refresh window display (an idiom from simple.el):
1669 (set-window-start (selected-window)
1670 (window-start (selected-window)))))
1672 (defun bh/switch-to-scratch ()
1674 (switch-to-buffer "*scratch*"))
1676 (setq org-use-fast-todo-selection t)
1677 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1679 ; create function to create headlines in file. This comes from
1680 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1681 (defun my/org-add-ids-to-headlines-in-file ()
1682 "Add ID properties to all headlines in the current file which
1683 do not already have one."
1685 (org-map-entries 'org-id-get-create))
1686 (defun dla/org-update-ids-to-headlines-in-file ()
1687 "Add or replace ID properties to all headlines in the current file
1688 (or narrowed region)."
1690 (org-map-entries '(lambda () (org-id-get-create t))))
1691 ; if we wanted to do this to every buffer, do the following:
1692 ; (add-hook 'org-mode-hook
1694 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1697 #+BEGIN_SRC emacs-lisp
1698 (setq org-todo-keywords
1699 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1700 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1702 (setq org-todo-keyword-faces
1703 (quote (("TODO" :foreground "red" :weight bold)
1704 ("NEXT" :foreground "blue" :weight bold)
1705 ("DONE" :foreground "forest green" :weight bold)
1706 ("WAITING" :foreground "orange" :weight bold)
1707 ("HOLD" :foreground "magenta" :weight bold)
1708 ("CANCELLED" :foreground "forest green" :weight bold)
1709 ("MEETING" :foreground "forest green" :weight bold)
1710 ("PHONE" :foreground "forest green" :weight bold))))
1712 (setq org-todo-state-tags-triggers
1713 (quote (("CANCELLED" ("CANCELLED" . t))
1714 ("WAITING" ("WAITING" . t))
1715 ("HOLD" ("WAITING") ("HOLD" . t))
1716 (done ("WAITING") ("HOLD"))
1717 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1718 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1719 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1723 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1724 ; add ids on creation of nodes
1725 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1728 ; resolve clocks after 10 minutes of idle; use xprintidle
1729 ; (setq org-clock-idle-time 10)
1730 ; (setq org-clock-x11idle-program-name "xprintidle")
1732 ; this is from http://doc.norang.ca/org-mode.html#Capture
1733 ; use C-M-r for org mode capture
1734 (global-set-key (kbd "C-M-r") 'org-capture)
1736 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1737 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1738 (org-agenda-files :maxlevel . 9))))
1740 ; Use full outline paths for refile targets - we file directly with IDO
1741 (setq org-refile-use-outline-path t)
1743 ; Targets complete directly with IDO
1744 (setq org-outline-path-complete-in-steps nil)
1746 ; Allow refile to create parent tasks with confirmation
1747 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1749 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1750 ; (setq org-completion-use-ido t)
1751 ; (setq ido-everywhere t)
1752 ; (setq ido-max-directory-size 100000)
1753 ; (ido-mode (quote both))
1754 ; ; Use the current window when visiting files and buffers with ido
1755 ; (setq ido-default-file-method 'selected-window)
1756 ; (setq ido-default-buffer-method 'selected-window)
1757 ; ; Use the current window for indirect buffer display
1758 ; (setq org-indirect-buffer-display 'current-window)
1761 ;;;; Refile settings
1762 ; Exclude DONE state tasks from refile targets
1763 (defun bh/verify-refile-target ()
1764 "Exclude todo keywords with a done state from refile targets"
1765 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1767 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1769 ;; ensure that emacsclient will show just the note to be edited when invoked
1770 ;; from Mutt, and that it will shut down emacsclient once finished;
1771 ;; fallback to legacy behavior when not invoked via org-protocol.
1772 (require 'org-protocol)
1773 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1774 (setq my-org-protocol-flag nil)
1775 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1776 "Delete frame at remember finalization"
1777 (progn (if my-org-protocol-flag (delete-frame))
1778 (setq my-org-protocol-flag nil)))
1779 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1780 "Delete frame at remember refile"
1781 (if my-org-protocol-flag
1783 (setq my-org-protocol-flag nil)
1788 (defadvice org-capture-kill (after delete-frame-at-end activate)
1789 "Delete frame at remember abort"
1790 (progn (if my-org-protocol-flag (delete-frame))
1791 (setq my-org-protocol-flag nil)))
1792 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1793 (setq my-org-protocol-flag t))
1795 (defadvice org-insert-todo-heading (after dla/create-id activate)
1796 (unless (org-in-item-p)
1802 (add-to-list 'org-modules 'org-habit)
1804 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1805 (defun open-mail-in-mutt (message)
1806 "Open a mail message in Mutt, using an external terminal.
1808 Message can be specified either by a path pointing inside a
1809 Maildir, or by Message-ID."
1810 (interactive "MPath or Message-ID: ")
1812 (format "faf xterm -e \"%s %s\""
1813 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1815 ;; add support for "mutt:ID" links
1816 (org-add-link-type "mutt" 'open-mail-in-mutt)
1818 (defun my-org-mode-setup ()
1819 ; (load-library "reftex")
1820 (and (buffer-file-name)
1821 (file-exists-p (buffer-file-name))
1823 ; (reftex-parse-all)
1824 (reftex-set-cite-format
1825 '((?b . "[[bib:%l][%l-bib]]")
1826 (?n . "[[notes:%l][%l-notes]]")
1828 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1830 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1831 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1832 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1833 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1835 (add-hook 'org-mode-hook 'my-org-mode-setup)
1837 (defun org-mode-reftex-search ()
1839 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1841 (defun open-research-paper (bibtexkey)
1842 "Open a paper by bibtex key"
1843 (interactive "bibtex key: ")
1846 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1847 (org-add-link-type "papers" 'open-research-paper)
1848 (defun open-research-paper-pdf (bibtexkey)
1849 "Open a paper pdf by bibtex key"
1850 (interactive "bibtex key: ")
1852 (format "%s -p evince_annot %s"
1853 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1854 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1856 (add-to-list 'org-link-abbrev-alist
1858 "~/projects/research/paper_notes.org::#%s"))
1860 ; I pretty much always want hiearchical checkboxes
1861 (setq org-hierachical-checkbox-statistics nil)
1863 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1864 (add-to-list 'org-structure-template-alist
1865 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1868 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1869 (defun my-rtcite-export-handler (path desc format)
1870 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1871 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1872 (match-string 1 path)))
1873 (path (substring path 0 (match-beginning 0))))
1874 (cond ((eq format 'latex)
1876 (equal 0 (search "rtcite:" desc)))
1877 (format "\\cite{%s}" search)
1878 (format "\\cite[%s]{%s}" desc search))))))
1880 (org-add-link-type "rtcite"
1882 'my-rtcite-export-handler)
1886 ** Org Mobile Configuration
1887 #+BEGIN_SRC emacs-lisp
1888 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1889 (when (string= system-name "linnode")
1890 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1891 (setq-default org-directory "/home/don/org-mode/")
1892 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1896 #+BEGIN_SRC emacs-lisp
1897 ;; org mode ical export
1898 (setq org-icalendar-timezone "America/Los_Angeles")
1899 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1900 ;; we already add the id manually
1901 (setq org-icalendar-store-UID t)
1904 ** General Org Babel Configuration
1905 #+BEGIN_SRC emacs-lisp
1906 ;; org babel support
1907 (org-babel-do-load-languages
1908 'org-babel-load-languages
1915 ;; use graphviz-dot for dot things
1916 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1917 ;; do not indent begin_src blocks
1918 (setq org-edit-src-content-indentation 0)
1919 ;; org-babel-by-backend
1920 (defmacro org-babel-by-backend (&rest body)
1921 `(case (if (boundp 'backend)
1922 (org-export-backend-name backend)
1925 (defun my/fix-inline-images ()
1926 (when org-inline-image-overlays
1927 (org-redisplay-inline-images)))
1929 (add-hook 'org-babel-after-execute-hook
1930 'my/fix-inline-images)
1933 ** LaTeX configuration
1935 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
1937 #+BEGIN_SRC emacs-lisp
1939 (add-to-list 'org-latex-classes
1941 "\\documentclass[11pt,oneside,article]{memoir}\n"
1942 ("\\section{%s}" . "\\section*{%s}")
1943 ("\\subsection{%s}" . "\\subsection*{%s}")
1944 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1945 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1946 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1948 (setq org-beamer-outline-frame-options "")
1949 (add-to-list 'org-latex-classes
1951 "\\documentclass[ignorenonframetext]{beamer}
1952 [NO-DEFAULT-PACKAGES]
1955 ("\\section{%s}" . "\\section*{%s}")
1956 ("\\subsection{%s}" . "\\subsection*{%s}")
1957 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1958 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1959 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1961 (add-to-list 'org-latex-classes
1963 "\\documentclass[11pt,oneside]{memoir}\n"
1964 ("\\chapter{%s}" . "\\chapter*{%s}")
1965 ("\\section{%s}" . "\\section*{%s}")
1966 ("\\subsection{%s}" . "\\subsection*{%s}")
1967 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1969 (add-to-list 'org-latex-classes
1971 "\\documentclass[11pt]{letter}
1972 [NO-DEFAULT-PACKAGES]
1975 ("\\section{%s}" . "\\section*{%s}")
1976 ("\\subsection{%s}" . "\\subsection*{%s}")
1977 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1978 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1979 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1981 (add-to-list 'org-latex-classes
1983 "\\documentclass{dlacv}
1984 [NO-DEFAULT-PACKAGES]
1987 ("\\section{%s}" . "\\section*{%s}")
1988 ("\\subsection{%s}" . "\\subsection*{%s}")
1989 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1990 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1991 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1994 (add-to-list 'org-latex-classes
1996 "\\documentclass{dlaresume}
1997 [NO-DEFAULT-PACKAGES]
2000 ("\\section{%s}" . "\\section*{%s}")
2001 ("\\subsection{%s}" . "\\subsection*{%s}")
2002 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2003 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2004 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2007 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
2008 ;; but adapted to use latexmk 4.22 or higher.
2009 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
2011 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
2012 (setq org-latex-default-packages-alist
2014 ("" "unicode-math" t)
2016 (setq org-latex-packages-alist
2023 ("" "longtable" nil)
2026 ;; make equations larger
2027 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2029 (defun org-create-formula--latex-header ()
2030 "Return LaTeX header appropriate for previewing a LaTeX snippet."
2031 (let ((info (org-combine-plists (org-export--get-global-options
2032 (org-export-get-backend 'latex))
2033 (org-export--get-inbuffer-options
2034 (org-export-get-backend 'latex)))))
2035 (org-latex-guess-babel-language
2036 (org-latex-guess-inputenc
2037 (org-splice-latex-header
2038 org-format-latex-header
2039 org-latex-default-packages-alist
2041 (plist-get info :latex-header)))
2045 ; support ignoring headers in org mode export to latex
2046 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2047 (defadvice org-latex-headline (around my-latex-skip-headlines
2048 (headline contents info) activate)
2049 (if (member "ignoreheading" (org-element-property :tags headline))
2050 (setq ad-return-value contents)
2053 ;; keep latex logfiles
2055 (setq org-latex-remove-logfiles nil)
2057 ;; Resume clocking task when emacs is restarted
2058 (org-clock-persistence-insinuate)
2060 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2061 (setq org-clock-history-length 23)
2062 ;; Resume clocking task on clock-in if the clock is open
2063 (setq org-clock-in-resume t)
2064 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2065 ;; there are things like PHONE calls
2066 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2067 ;; Separate drawers for clocking and logs
2068 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2069 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2070 (setq org-clock-into-drawer t)
2071 (setq org-log-into-drawer t)
2072 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2073 (setq org-clock-out-remove-zero-time-clocks t)
2074 ;; Clock out when moving task to a done state
2075 (setq org-clock-out-when-done t)
2076 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2077 (setq org-clock-persist t)
2078 ;; Do not prompt to resume an active clock
2079 (setq org-clock-persist-query-resume nil)
2080 ;; Enable auto clock resolution for finding open clocks
2081 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2082 ;; Include current clocking task in clock reports
2083 (setq org-clock-report-include-clocking-task t)
2085 ;; the cache seems to be broken
2086 (setq org-element-use-cache nil)
2088 (defvar bh/keep-clock-running nil)
2090 (defun bh/is-task-p ()
2091 "Any task with a todo keyword and no subtask"
2095 (subtree-end (save-excursion (org-end-of-subtree t)))
2096 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2099 (while (and (not has-subtask)
2100 (< (point) subtree-end)
2101 (re-search-forward "^\*+ " subtree-end t))
2102 (when (member (org-get-todo-state) org-todo-keywords-1)
2103 (setq has-subtask t))))
2104 (and is-a-task (not has-subtask)))))
2105 (defun bh/is-project-p ()
2106 "Any task with a todo keyword subtask"
2110 (subtree-end (save-excursion (org-end-of-subtree t)))
2111 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2114 (while (and (not has-subtask)
2115 (< (point) subtree-end)
2116 (re-search-forward "^\*+ " subtree-end t))
2117 (when (member (org-get-todo-state) org-todo-keywords-1)
2118 (setq has-subtask t))))
2119 (and is-a-task has-subtask))))
2121 (defun bh/is-subproject-p ()
2122 "Any task which is a subtask of another project"
2123 (let ((is-subproject)
2124 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2126 (while (and (not is-subproject) (org-up-heading-safe))
2127 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2128 (setq is-subproject t))))
2129 (and is-a-task is-subproject)))
2132 (defun bh/clock-in-to-next (kw)
2133 "Switch a task from TODO to NEXT when clocking in.
2134 Skips capture tasks, projects, and subprojects.
2135 Switch projects and subprojects from NEXT back to TODO"
2136 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2138 ((and (member (org-get-todo-state) (list "TODO"))
2141 ((and (member (org-get-todo-state) (list "NEXT"))
2145 (defun bh/punch-in (arg)
2146 "Start continuous clocking and set the default task to the
2147 selected task. If no task is selected set the Organization task
2148 as the default task."
2150 (setq bh/keep-clock-running t)
2151 (if (equal major-mode 'org-agenda-mode)
2153 ;; We're in the agenda
2155 (let* ((marker (org-get-at-bol 'org-hd-marker))
2156 (tags (org-with-point-at marker (org-get-tags-at))))
2157 (if (and (eq arg 4) tags)
2158 (org-agenda-clock-in '(16))
2159 (bh/clock-in-organization-task-as-default)))
2161 ;; We are not in the agenda
2165 ; Find the tags on the current task
2166 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2167 (org-clock-in '(16))
2168 (bh/clock-in-organization-task-as-default)))))
2170 (defun bh/punch-out ()
2172 (setq bh/keep-clock-running nil)
2173 (when (org-clock-is-active)
2175 (org-agenda-remove-restriction-lock))
2177 (defun bh/clock-in-default-task ()
2179 (org-with-point-at org-clock-default-task
2182 (defun bh/clock-in-parent-task ()
2183 "Move point to the parent (project) task if any and clock in"
2184 (let ((parent-task))
2188 (while (and (not parent-task) (org-up-heading-safe))
2189 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2190 (setq parent-task (point))))
2192 (org-with-point-at parent-task
2194 (when bh/keep-clock-running
2195 (bh/clock-in-default-task)))))))
2197 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2199 (defun bh/clock-in-organization-task-as-default ()
2201 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2202 (org-clock-in '(16))))
2204 (defun bh/clock-out-maybe ()
2205 (when (and bh/keep-clock-running
2206 (not org-clock-clocking-in)
2207 (marker-buffer org-clock-default-task)
2208 (not org-clock-resolving-clocks-due-to-idleness))
2209 (bh/clock-in-parent-task)))
2211 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2214 (defun bh/clock-in-task-by-id (id)
2215 "Clock in a task by id"
2216 (org-with-point-at (org-id-find id 'marker)
2217 (org-clock-in nil)))
2219 (defun bh/clock-in-last-task (arg)
2220 "Clock in the interrupted task if there is one
2221 Skip the default task and get the next one.
2222 A prefix arg forces clock in of the default task."
2224 (let ((clock-in-to-task
2226 ((eq arg 4) org-clock-default-task)
2227 ((and (org-clock-is-active)
2228 (equal org-clock-default-task (cadr org-clock-history)))
2229 (caddr org-clock-history))
2230 ((org-clock-is-active) (cadr org-clock-history))
2231 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2232 (t (car org-clock-history)))))
2234 (org-with-point-at clock-in-to-task
2235 (org-clock-in nil))))
2238 (defun org-export-to-ods ()
2240 (let ((csv-file "data.csv"))
2241 (org-table-export csv-file "orgtbl-to-csv")
2242 (org-odt-convert csv-file "ods" 'open)))
2244 ; allow for zero-width-space to be a break in regexp too
2245 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
2246 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
2247 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2249 ;; support inserting screen shots
2250 (defun my/org-insert-screenshot ()
2251 "Take a screenshot into a time stamped unique-named file in the
2252 same directory as the org-buffer and insert a link to this file."
2254 (defvar my/org-insert-screenshot/filename)
2255 (setq my/org-insert-screenshot/filename
2257 "Screenshot to insert: "
2259 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2262 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2263 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2264 (org-display-inline-images))
2266 (defun my/fix-inline-images ()
2267 (when org-inline-image-overlays
2268 (org-redisplay-inline-images)))
2270 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2272 ;; use xelatex to preview with imagemagick
2273 (add-to-list 'org-preview-latex-process-alist
2274 '(xelateximagemagick
2275 :programs ("xelatex" "convert")
2276 :description "pdf > png"
2277 :message "you need to install xelatex and imagemagick"
2279 :image-input-type "pdf"
2280 :image-output-type "png"
2281 :image-size-adjust (1.0 . 1.0)
2282 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2283 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2285 ;; use xelatex by default
2286 (setq org-preview-latex-default-process 'xelateximagemagick)
2288 ; from http://orgmode.org/Changes.html
2289 (defun my/org-repair-property-drawers ()
2290 "Fix properties drawers in current buffer.
2291 Ignore non Org buffers."
2293 (when (eq major-mode 'org-mode)
2294 (org-with-wide-buffer
2295 (goto-char (point-min))
2296 (let ((case-fold-search t)
2297 (inline-re (and (featurep 'org-inlinetask)
2298 (concat (org-inlinetask-outline-regexp)
2302 (unless (and inline-re (org-looking-at-p inline-re))
2304 (let ((end (save-excursion (outline-next-heading) (point))))
2306 (when (org-looking-at-p org-planning-line-re) (forward-line))
2307 (when (and (< (point) end)
2308 (not (org-looking-at-p org-property-drawer-re))
2310 (and (re-search-forward org-property-drawer-re end t)
2311 (eq (org-element-type
2312 (save-match-data (org-element-at-point)))
2314 (insert (delete-and-extract-region
2316 (min (1+ (match-end 0)) end)))
2317 (unless (bolp) (insert "\n"))))))))))))
2321 #+BEGIN_SRC emacs-lisp
2325 (use-package calfw-org
2328 (use-package org-gcal
2330 :config '((if (file-readable-p "~/.hide/org_gcal.el")
2331 (load-file "~/.hide/org_gcal.el"))
2336 #+BEGIN_SRC emacs-lisp
2340 ;; Show notification 10 minutes before event
2341 (setq appt-message-warning-time 10)
2342 ;; Disable multiple reminders
2343 (setq appt-display-interval appt-message-warning-time)
2344 (setq appt-display-mode-line nil)
2346 ;; add automatic reminders for appointments
2347 (defun my/org-agenda-to-appt ()
2349 (setq appt-time-msg-list nil)
2350 (org-agenda-to-appt))
2351 ;; add reminders when starting emacs
2352 (my/org-agenda-to-appt)
2353 ;; when rebuilding the agenda
2354 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
2355 "Pressing `r' on the agenda will also add appointments."
2356 (my/org-agenda-to-appt)
2358 ;; when saving all org buffers
2359 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2360 "Re-add appts after saving all org buffers"
2361 (my/org-agenda-to-appt))
2362 ;; Display appointments as a window manager notification
2363 (setq appt-disp-window-function 'my/appt-display)
2364 (setq appt-delete-window-function (lambda () t))
2366 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2368 (defun my/appt-display (min-to-app new-time msg)
2369 (if (atom min-to-app)
2370 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2371 (dolist (i (number-sequence 0 (1- (length min-to-app))))
2372 (start-process "my/appt-notification-app" nil my/appt-notification-app
2373 (nth i min-to-app) (nth i msg))))
2380 #+BEGIN_SRC emacs-lisp
2385 #+BEGIN_SRC emacs-lisp
2386 (global-unset-key "\M-g")
2387 (global-set-key (kbd "M-g l") 'goto-line)
2391 #+BEGIN_SRC emacs-lisp
2392 (use-package debian-changelog-mode
2393 :mode "debian/changelog"
2395 (setq debian-changelog-mailing-address "don@debian.org")
2396 (setq debian-changelog-full-name "Don Armstrong"))
2398 * Misc (uncharacterized)
2399 #+BEGIN_SRC emacs-lisp
2400 (setq calendar-latitude 38.6)
2401 (setq calendar-longitude -121.5)
2402 (setq case-fold-search t)
2403 (setq confirm-kill-emacs (quote y-or-n-p))
2404 (setq cperl-lazy-help-time nil)
2405 (global-font-lock-mode 1)
2407 (setq log-edit-keep-buffer t)
2408 (setq mail-user-agent (quote sendmail-user-agent))
2409 (setq markdown-enable-math t)
2410 (setq markdown-follow-wiki-link-on-enter nil)
2411 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2412 (setq ps-footer-font-size (quote (8 . 10)))
2413 (setq ps-header-font-size (quote (8 . 10)))
2414 (setq ps-header-title-font-size (quote (10 . 10)))
2415 (setq ps-line-number-color "blue")
2416 (setq ps-print-footer t)
2417 (setq ps-print-footer-frame nil)
2418 (setq ps-print-only-one-header t)
2419 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
2421 (setq sentence-end-double-space nil)
2422 ; enable matching parenthesis
2425 (setq user-mail-address "don@donarmstrong.com")
2426 (setq vc-delete-logbuf-window nil)
2427 (setq vc-follow-symlinks t)
2429 ;; use git before SVN; use CVS earlier, because I have CVS
2430 ;; repositories inside of git directories
2431 (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
2433 ;; switch back to the old primary selection method
2434 (setq x-select-enable-clipboard nil)
2435 (setq x-select-enable-primary t)
2436 ; (setq mouse-drag-copy-region t)
2438 (fset 'perl-mode 'cperl-mode)
2439 ;;(load-file "cperl-mode.el")
2441 ;; tramp configuration
2442 (setq tramp-use-ssh-controlmaster-options nil)
2444 (setq-default c-indent-level 4)
2445 (setq-default c-brace-imaginary-offset 0)
2446 (setq-default c-brace-offset -4)
2447 (setq-default c-argdecl-indent 4)
2448 (setq-default c-label-offset -4)
2449 (setq-default c-continued-statement-offset 4)
2451 (setq-default indent-tabs-mode nil)
2452 (setq-default tab-width 4)
2455 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2456 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2457 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2458 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2459 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2462 (defun insert-date ()
2463 "Insert date at point."
2465 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2466 (global-set-key "\C-[d" 'insert-date)
2468 (defun unfill-paragraph (arg)
2469 "Pull this whole paragraph up onto one line."
2471 (let ((fill-column 10000))
2472 (fill-paragraph arg))
2475 (column-number-mode t)
2478 ** Desktop-save-mode
2479 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2480 emacs, and use a different desktop file to restore history
2481 #+BEGIN_SRC emacs-lisp
2482 (use-package desktop
2485 (setq desktop-base-file-name
2486 (convert-standard-filename
2488 (or (getenv "EMACS_SERVER_NAME")
2492 (setq desktop-base-lock-name
2493 (convert-standard-filename
2494 (concat desktop-base-file-name
2496 (setq desktop-auto-save-timeout 60)
2497 (setq desktop-restore-eager 5)
2498 (setq desktop-lazy-verbose nil)
2499 (desktop-save-mode 1)
2503 ** Misc (Uncharacterized)
2504 #+BEGIN_SRC emacs-lisp
2505 '(icomplete-mode on)
2507 ;; custom-set-faces was added by Custom.
2508 ;; If you edit it by hand, you could mess it up, so be careful.
2509 ;; Your init file should contain only one such instance.
2510 ;; If there is more than one, they won't work right.
2511 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2514 (put 'upcase-region 'disabled nil)
2515 (put 'downcase-region 'disabled nil)
2516 (put 'narrow-to-region 'disabled nil)
2518 ; (defun turn-on-flyspell ()
2519 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2521 ; (flyspell-mode 1))
2524 ; Outline-minor-mode key map
2525 (define-prefix-command 'cm-map nil "Outline-")
2527 (define-key cm-map "q" 'outline-hide-sublevels) ; Hide everything but the top-level headings
2528 (define-key cm-map "t" 'outline-hide-body) ; Hide everything but headings (all body lines)
2529 (define-key cm-map "o" 'outline-hide-other) ; Hide other branches
2530 (define-key cm-map "c" 'outline-hide-entry) ; Hide this entry's body
2531 (define-key cm-map "l" 'outline-hide-leaves) ; Hide body lines in this entry and sub-entries
2532 (define-key cm-map "d" 'outline-hide-subtree) ; Hide everything in this entry and sub-entries
2534 (define-key cm-map "a" 'outline-show-all) ; Show (expand) everything
2535 (define-key cm-map "e" 'outline-show-entry) ; Show this heading's body
2536 (define-key cm-map "i" 'outline-show-children) ; Show this heading's immediate child sub-headings
2537 (define-key cm-map "k" 'outline-show-branches) ; Show all sub-headings under this heading
2538 (define-key cm-map "s" 'outline-show-subtree) ; Show (expand) everything in this heading & below
2540 (define-key cm-map "u" 'outline-up-heading) ; Up
2541 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2542 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2543 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2544 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2545 (global-set-key "\M-o" cm-map)
2546 ; fix up tmux xterm keys
2547 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2548 (defun fix-up-tmux-keys ()
2549 "Fix up tmux xterm keys"
2552 (let ((x 2) (tkey ""))
2572 ;; ctrl + alt + shift
2574 (setq tkey "C-M-S-"))
2577 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2578 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2579 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2580 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2582 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2584 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2586 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2588 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2590 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2592 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2594 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2596 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2598 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2600 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2602 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2604 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2606 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2608 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2610 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2612 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2614 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2616 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2618 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2620 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2622 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2624 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2626 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2628 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2630 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2632 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2639 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2641 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2642 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2643 (if (or (buffer-modified-p)
2644 (verify-visited-file-modtime)
2645 (< (* 8 1024 1024) (buffer-size))
2646 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2648 (clear-visited-file-modtime)
2650 (ad-activate 'ask-user-about-supersession-threat)
2654 #+BEGIN_SRC emacs-lisp
2658 (or (getenv "EMACS_SERVER_NAME")
2660 (unless (server-running-p)
2661 (global-set-key "\C-xp" 'server-edit)
2668 #+BEGIN_SRC emacs-lisp
2669 (provide 'don-configuration)