1 #+PROPERTY: header-args:emacs-lisp :tangle don-configuration.el
4 # if for some reason, things get pear-shaped, we want to be able to
5 # enter the debugger by sending -USR2 to emacs
8 (setq debug-on-event 'siguser2)
10 * Initial startup stuff
11 ** Disable startup screen
12 #+BEGIN_SRC emacs-lisp
13 (setq inhibit-startup-screen t)
16 #+BEGIN_SRC emacs-lisp
17 ; (if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
18 (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
19 (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
22 #+BEGIN_SRC emacs-lisp
23 (setq frame-resize-pixelwise t)
24 (add-to-list 'default-frame-alist '(fullscreen . maximixed))
27 ** package repositories and package manager
28 Borrowed from https://github.com/nilcons/emacs-use-package-fast/ to
29 load [[https://github.com/jwiegley/use-package/][use-package]] even faster
30 #+BEGIN_SRC emacs-lisp
31 (setq package-enable-at-startup nil)
32 (setq package--init-file-ensured t)
33 (setq package-user-dir "~/var/emacs/elpa")
34 (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
35 ("melpa" . "https://melpa.org/packages/")
36 ("org" . "http://orgmode.org/elpa/") ))
38 (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
39 (mapc #'(lambda (add) (add-to-list 'load-path add))
42 (unless (package-installed-p 'use-package)
43 (package-refresh-contents)
44 (package-install 'use-package))
45 (let ((package-user-dir-real (file-truename package-user-dir)))
46 ;; The reverse is necessary, because outside we mapc
47 ;; add-to-list element-by-element, which reverses.
48 (nreverse (apply #'nconc
49 ;; Only keep package.el provided loadpaths.
50 (mapcar #'(lambda (path)
51 (if (string-prefix-p package-user-dir-real path)
56 ;;; fix up info paths for packages
57 (with-eval-after-load "info"
59 (dolist (dir (directory-files package-user-dir))
60 (let ((fdir (concat (file-name-as-directory package-user-dir) dir)))
61 (unless (or (member dir '("." ".." "archives" "gnupg"))
62 (not (file-directory-p fdir))
63 (not (file-exists-p (concat (file-name-as-directory fdir) "dir"))))
64 (add-to-list 'Info-directory-list fdir)))))
68 (require 'use-package))
73 #+BEGIN_SRC emacs-lisp
76 :commands (paradox-upgrade-packages paradox-list-packages)
77 :config (setq paradox-execute-asynchronously t)
82 #+BEGIN_SRC emacs-lisp
83 (add-to-list 'load-path '"~/lib/emacs_el/")
84 (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
87 #+BEGIN_SRC emacs-lisp
88 ;; Set the custom file to /dev/null and don't bother to load it
89 (setq custom-file "/dev/null")
93 #+BEGIN_SRC emacs-lisp
94 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
95 ;; execute conditional code when loading libraries
96 (defmacro with-library (symbol &rest body)
97 `(when (require ,symbol nil t)
99 (put 'with-library 'lisp-indent-function 1)
103 ** Safe Local Variables
104 #+BEGIN_SRC emacs-lisp
105 (setq safe-local-variable-values
106 (quote ((auto-save-default)
108 (cperl-indent-level . 4)
110 (indent-tabs-mode . f)
114 #+BEGIN_SRC emacs-lisp
115 (setq global-mark-ring-max 128
119 (defun don/minibuffer-setup-hook ()
120 (setq gc-cons-threshold most-positive-fixnum))
122 (defun don/minibuffer-exit-hook ()
123 (setq gc-cons-threshold 1048576))
125 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
126 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
130 #+BEGIN_SRC emacs-lisp
131 (use-package hippie-exp
132 :bind* (("M-<SPC>" . hippie-expand))
136 #+BEGIN_SRC emacs-lisp
137 (use-package flyspell
139 :diminish flyspell-mode 🐝
141 (add-hook 'text-mode-hook 'turn-on-flyspell)
142 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
143 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
144 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
146 (setq ispell-program-name "ispell")
151 #+begin_src emacs-lisp :tangle yes
157 #+BEGIN_SRC emacs-lisp
162 #+BEGIN_SRC emacs-lisp
163 (use-package eyebrowse
165 :diminish eyebrowse-mode
166 :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
168 (setq eyebrowse-wrap-around t)
171 (defun my/eyebrowse-new-window-config ()
175 ;; start at 1 run till 0
176 (let ((j (mod (+ i 1) 10)))
177 (when (and (not done)
178 (not (eyebrowse--window-config-present-p j)))
179 (eyebrowse-switch-to-window-config j)
180 (call-interactively 'eyebrowse-rename-window-config2 j)
185 ;; I don't use latex-preview-pane
186 ;; (require 'latex-preview-pane)
187 ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
188 ;; ;; latex-preview-pane uses window-parameters which are
189 ;; ;; not preserved by eyebrowse, so we close the preview
190 ;; ;; pane before switching, it will be regenerated when we
191 ;; ;; edit the TeX file.
192 ;; (when (lpp/window-containing-preview)
193 ;; (delete-window (lpp/window-containing-preview))))
195 ;; (add-to-list 'eyebrowse-pre-window-switch-hook
196 ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
198 ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
199 ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
200 ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
201 ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
202 ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
210 #+BEGIN_SRC emacs-lisp
211 (defun my/vsplit-last-buffer ()
212 "Split the window vertically and display the previous buffer."
214 (split-window-vertically)
216 (switch-to-next-buffer))
218 (defun my/hsplit-last-buffer ()
219 "Split the window horizontally and display the previous buffer."
221 (split-window-horizontally)
223 (switch-to-next-buffer))
225 (bind-key "C-x 2" 'my/vsplit-last-buffer)
226 (bind-key "C-x 3" 'my/hsplit-last-buffer)
228 (setq split-width-threshold 100)
229 (setq split-height-threshold 60)
231 (defun my/split-window-prefer-vertically (window)
232 "If there's only one window (excluding any possibly active
233 minibuffer), then split the current window horizontally."
234 (if (and (one-window-p t)
235 (not (active-minibuffer-window))
236 ( < (frame-width) (frame-height))
238 (let ((split-width-threshold nil))
239 (split-window-sensibly window))
240 (split-window-sensibly window)))
242 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
243 (setq window-combination-resize t)
246 *** Compilation window
248 If there is no compilation window, open one at the bottom, spanning
249 the complete width of the frame. Otherwise, reuse existing window. In
250 the former case, if there was no error the window closes
253 #+BEGIN_SRC emacs-lisp
254 (add-to-list 'display-buffer-alist
255 `(,(rx bos "*compilation*" eos)
256 (display-buffer-reuse-window
257 display-buffer-in-side-window)
258 (reusable-frames . visible)
260 (window-height . 0.4)))
263 #+BEGIN_SRC emacs-lisp
264 (defun my/compilation-exit-autoclose (status code msg)
265 ;; If M-x compile exists with a 0
266 (when (and (eq status 'exit) (zerop code))
267 ;; and delete the *compilation* window
268 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
269 (when (and (not (window-at-side-p compilation-window 'top))
270 (window-at-side-p compilation-window 'left)
271 (window-at-side-p compilation-window 'right))
272 (delete-window compilation-window))))
273 ;; Always return the anticipated result of compilation-exit-message-function
276 ;; Specify my function (maybe I should have done a lambda function)
277 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
280 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
281 value, the compilation buffer scrolls automatically to follow the
282 output. If the value is ~first-error~, scrolling stops when the first
283 error appears, leaving point at that error. For any other non-nil
284 value, scrolling continues until there is no more output.
286 #+BEGIN_SRC emacs-lisp
287 (setq compilation-scroll-output 'first-error)
290 ** Mode line cleaning
292 #+BEGIN_SRC emacs-lisp
293 (use-package diminish
298 #+BEGIN_SRC emacs-lisp
305 #+BEGIN_SRC emacs-lisp
308 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
309 ("C-c j j" . avy-goto-word-or-subword-1)
310 ("M-g g" . avy-goto-line))
311 :config (progn (setq avy-background t))
314 *** Ace-link (jumping to links)
315 #+BEGIN_SRC emacs-lisp
316 (use-package ace-link
318 ; bind o in most modes
319 :config (ace-link-setup-default))
321 *** Jumping through edit points (goto-chg)
322 #+BEGIN_SRC emacs-lisp
323 (use-package goto-chg
325 :bind (("C-c j ," . goto-last-change)
326 ("C-c j ." . goto-last-change-reverse))
329 *** Jumping to bookmarks (visible bookmarks, bm)
330 #+BEGIN_SRC emacs-lisp
333 :bind (("C-c j b ." . bm-next)
334 ("C-c j b ," . bm-previous)
335 ("C-c j b SPC" . bm-toggle)))
340 #+BEGIN_SRC emacs-lisp
341 (use-package yasnippet
343 :diminish yas-minor-mode
346 (setq yas-verbosity 1)
347 (define-key yas-minor-mode-map (kbd "<tab>") nil)
348 (define-key yas-minor-mode-map (kbd "TAB") nil)
349 (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
350 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
351 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
352 (add-to-list 'hippie-expand-try-functions-list
353 'yas-hippie-try-expand)
359 #+BEGIN_SRC emacs-lisp
360 (use-package auto-yasnippet
361 :bind (("H-w" . aya-create)
367 #+BEGIN_SRC emacs-lisp
370 :bind (("M-/" . company-complete))
372 (setq company-echo-delay 0 ; remove blinking
373 company-show-numbers t ; show numbers for easy selection
374 company-selection-wrap-around t
375 company-require-match nil
376 company-dabbrev-ignore-case t
377 company-dabbrev-ignore-invisible t
378 company-dabbrev-other-buffers t
379 company-dabbrev-downcase nil
380 company-dabbrev-code-everywhere t
381 company-tooltip-align-annotations t
382 company-minimum-prefix-length 1
383 company-global-modes '(not)
384 company-lighter-base "(C)")
385 (global-company-mode 1)
387 (bind-key "C-n" #'company-select-next company-active-map)
388 (bind-key "C-p" #'company-select-previous company-active-map)
389 (bind-key "<tab>" #'company-complete company-active-map)
390 (bind-key "M-?" #'company-show-doc-buffer company-active-map)
391 (bind-key "M-." #'company-show-location company-active-map)
392 (bind-key "M-/" #'company-complete-common org-mode-map)
396 #+BEGIN_SRC emacs-lisp
397 (use-package company-c-headers
400 (defun malb/ede-object-system-include-path ()
401 "Return the system include path for the current buffer."
403 (ede-system-include-path ede-object)))
405 (setq company-c-headers-path-system
406 #'malb/ede-object-system-include-path)
408 (add-to-list 'company-backends #'company-c-headers)))
411 #+BEGIN_SRC emacs-lisp
412 (use-package company-anaconda
414 :config (add-to-list 'company-backends #'company-anaconda))
417 #+BEGIN_SRC emacs-lisp
418 (use-package company-plsense
423 #+BEGIN_SRC emacs-lisp
424 (use-package company-math
427 #+BEGIN_SRC emacs-lisp
428 (use-package company-auctex
431 (defun company-auctex-labels (command &optional arg &rest ignored)
432 "company-auctex-labels backend"
433 (interactive (list 'interactive))
435 (interactive (company-begin-backend 'company-auctex-labels))
436 (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
437 (candidates (company-auctex-label-candidates arg))))
439 (add-to-list 'company-backends
440 '(company-auctex-macros
441 company-auctex-environments
442 company-math-symbols-unicode
443 company-math-symbols-latex))
445 (add-to-list 'company-backends #'company-auctex-labels)
446 (add-to-list 'company-backends #'company-auctex-bibs)
450 #+BEGIN_SRC emacs-lisp
451 (use-package company-bibtex
457 #+BEGIN_SRC emacs-lisp
458 (use-package company-shell
461 (setq company-shell-modes '(sh-mode shell-mode))
462 (add-to-list 'company-backends 'company-shell)))
467 Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
469 *Note:* Do this at the end of =company-mode= config.
471 #+BEGIN_SRC emacs-lisp
472 (defvar malb/company-mode/enable-yas t
473 "Enable yasnippet for all backends.")
475 (defun malb/company-mode/backend-with-yas (backend)
476 (if (or (not malb/company-mode/enable-yas)
478 (member 'company-yasnippet backend)))
480 (append (if (consp backend) backend (list backend))
481 '(:with company-yasnippet))))
483 (setq company-backends
484 (mapcar #'malb/company-mode/backend-with-yas company-backends))
489 Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
491 #+BEGIN_SRC emacs-lisp
492 (defun malb/toggle-company-ispell ()
495 ((member '(company-ispell :with company-yasnippet) company-backends)
496 (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
497 (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
498 (message "company-ispell disabled"))
500 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
501 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
502 (message "company-ispell enabled!"))))
504 (defun malb/company-ispell-setup ()
505 ;; @see https://github.com/company-mode/company-mode/issues/50
506 (when (boundp 'company-backends)
507 (make-local-variable 'company-backends)
508 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
509 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
510 ;; https://github.com/redguardtoo/emacs.d/issues/473
511 (if (and (boundp 'ispell-alternate-dictionary)
512 ispell-alternate-dictionary)
513 (setq company-ispell-dictionary ispell-alternate-dictionary))))
518 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
520 2. This function then hopefully does what I want:
522 a. if a region is active, just indent
523 b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
524 c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
525 d. otherwise call whatever would have been called otherwise.
527 ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
529 #+BEGIN_SRC emacs-lisp
530 (defun malb/indent-fold-or-complete (&optional arg)
533 ;; if a region is active, indent
535 (indent-region (region-beginning)
537 ;; if the next char is space or eol, but prev char not whitespace
538 ((and (not (active-minibuffer-window))
541 (looking-back "[^[:space:]]")
542 (not (looking-back "^")))
544 (cond (company-mode (company-complete-common))
545 (auto-complete-mode (auto-complete))))
547 ;; no whitespace anywhere
548 ((and (not (active-minibuffer-window))
549 (looking-at "[^[:space:]]")
550 (looking-back "[^[:space:]]")
551 (not (looking-back "^")))
553 ((bound-and-true-p hs-minor-mode)
554 (save-excursion (end-of-line) (hs-toggle-hiding)))
555 ((bound-and-true-p outline-minor-mode)
556 (save-excursion (outline-cycle)))))
558 ;; by default just call whatever was bound
560 (let ((fn (or (lookup-key (current-local-map) (kbd "TAB"))
561 'indent-for-tab-command)))
562 (if (not (called-interactively-p 'any))
564 (setq this-command fn)
565 (call-interactively fn))))))
567 (defun malb/toggle-fold ()
569 (cond ((eq major-mode 'org-mode)
570 (org-force-cycle-archived))
571 ((bound-and-true-p hs-minor-mode)
576 ((bound-and-true-p outline-minor-mode)
580 (bind-key "<tab>" #'malb/indent-fold-or-complete)
581 (bind-key "C-<tab>" #'malb/toggle-fold)
585 #+BEGIN_SRC emacs-lisp
587 (use-package tinyprocmail
588 :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
589 :mode (".procmailrc" . turn-on-tinyprocmail-mode)
594 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
597 :bind (("C-x g" . magit-status)
598 ("C-x C-g" . magit-status))
600 ;; refine diffs always (hilight words)
601 (setq magit-diff-refine-hunk nil)
603 (use-package magit-annex
605 :load-path "~/lib/emacs_el/magit-annex/"
607 (use-package magit-vcsh
608 :ensure f ; currently not in melpa, so don't try to install
609 :load-path "~/lib/emacs_el/magit-vcsh/"
614 #+BEGIN_SRC emacs-lisp
615 (use-package cperl-mode
618 ;; Use c-mode for perl .xs files
619 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
620 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
621 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
622 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
623 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
626 cperl-auto-newline nil
627 cperl-auto-newline-after-colon nil
628 cperl-continued-statement-offset 4
629 cperl-brace-offset -1
630 cperl-continued-brace-offset 0
631 cperl-label-offset -4
632 cperl-highlight-variables-indiscriminately t
633 cperl-electric-lbrace-space nil
634 cperl-indent-parens-as-block nil
635 cperl-close-paren-offset -1
636 cperl-tab-always-indent t)
637 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
642 #+BEGIN_SRC emacs-lisp
643 (use-package markdown-mode
645 :mode (("\\.md\\'" . markdown-mode)
646 ("\\.mdwn\\'" . markdown-mode)
647 ("README\\.md\\'" . gfm-mode)
650 (setq markdown-enable-math t)
651 (setq markdown-follow-wiki-link-on-enter nil)
652 (bind-key "M-." #'markdown-jump markdown-mode-map)
653 (add-hook 'markdown-mode-hook #'flyspell-mode)
654 (add-hook 'markdown-mode-hook #'outline-minor-mode)
655 (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
660 #+BEGIN_SRC emacs-lisp
661 ; load sql-indent when sql is loaded
663 :mode (("\\.sql\\'" . sql-mode))
665 (require sql-indent))
668 #+BEGIN_SRC emacs-lisp
670 :commands ediff ediff3
673 ;; ediff configuration
674 ;; don't use the multi-window configuration
675 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
678 ** VCL --editing varnish configuration files
679 #+BEGIN_SRC emacs-lisp
680 (use-package vcl-mode
687 #+BEGIN_SRC emacs-lisp
688 (defun malb/helm-omni (&rest arg)
689 ;; just in case someone decides to pass an argument, helm-omni won't fail.
691 (unless helm-source-buffers-list
692 (setq helm-source-buffers-list
693 (helm-make-source "Buffers" 'helm-source-buffers)))
697 (if (projectile-project-p)
698 '(helm-source-projectile-buffers-list
699 helm-source-buffers-list)
700 '(helm-source-buffers-list)) ;; list of all open buffers
702 `(((name . "Virtual Workspace")
703 (candidates . ,(--map (cons (eyebrowse-format-slot it) (car it))
704 (eyebrowse--get 'window-configs)))
705 (action . (lambda (candidate)
706 (eyebrowse-switch-to-window-config candidate)))))
708 (if (projectile-project-p)
709 '(helm-source-projectile-recentf-list
711 '(helm-source-recentf)) ;; all recent files
713 ;; always make some common files easily accessible
714 ;;'(((name . "Common Files")
715 ;; (candidates . malb/common-file-targets)
716 ;; (action . (("Open" . (lambda (x) (find-file (eval x))))))))
718 '(helm-source-files-in-current-dir
720 helm-source-bookmarks
721 helm-source-buffer-not-found ;; ask to create a buffer otherwise
723 "*Helm all the things*"))
727 :bind (("M-x" . helm-M-x)
728 ("C-x C-f" . helm-find-files)
729 ("C-x b" . helm-buffers-list) ; malb/helm-omni)
730 ("C-x C-b" . helm-buffers-list) ; malb/helm-omni)
731 ("C-c <SPC>" . helm-all-mark-rings))
733 (require 'helm-config)
734 (require 'helm-for-files)
735 (require 'helm-bookmark)
738 (define-key global-map [remap find-file] 'helm-find-files)
739 (define-key global-map [remap occur] 'helm-occur)
740 (define-key global-map [remap list-buffers] 'helm-buffers-list)
741 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
742 (unless (boundp 'completion-in-region-function)
743 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
744 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
745 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
750 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
752 #+BEGIN_SRC emacs-lisp
753 (use-package helm-flx
756 ;; these are helm configs, but they kind of fit here nicely
757 (setq helm-M-x-fuzzy-match t
758 helm-bookmark-show-location t
759 helm-buffers-fuzzy-matching t
760 helm-completion-in-region-fuzzy-match t
761 helm-file-cache-fuzzy-match t
762 helm-imenu-fuzzy-match t
763 helm-mode-fuzzy-match t
764 helm-locate-fuzzy-match nil
766 helm-recentf-fuzzy-match nil
767 helm-semantic-fuzzy-match t)
771 #+BEGIN_SRC emacs-lisp
773 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
774 (defun malb/helm-swoop-pre-fill ()
775 (thing-at-point 'symbol))
776 (defvar malb/helm-swoop-ignore-major-mode "List of major modes to ignore for helm-swoop")
777 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
778 paradox-menu-mode doc-view-mode pdf-view-mode
779 mu4e-headers-mode org-mode markdown-mode latex-mode
780 ein:notebook-multilang-mode))
782 (defun malb/swoop-or-search ()
784 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
785 (memq major-mode malb/helm-swoop-ignore-major-mode))
789 (use-package helm-swoop
792 :bind (("C-c o" . helm-multi-swoop-org)
793 ("C-s" . malb/swoop-or-search)
794 ("C-M-s" . helm-multi-swoop-all))
797 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
798 helm-swoop-split-with-multiple-windows nil
799 helm-swoop-split-direction #'split-window-horizontally
800 helm-swoop-split-window-function 'helm-default-display-buffer
801 helm-swoop-speed-or-color t)
803 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
804 (defun malb/helm-swoop-C-s ()
806 (if (boundp 'helm-swoop-pattern)
807 (if (equal helm-swoop-pattern "")
808 (previous-history-element 1)
812 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
813 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
814 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
815 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
816 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
817 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
822 #+BEGIN_SRC emacs-lisp
825 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
826 helm-ag-command-option "--all-text"
827 helm-ag-insert-at-point 'symbol
828 helm-ag-fuzzy-match t
829 helm-ag-use-temp-buffer t
830 helm-ag-use-grep-ignore-list t
831 helm-ag-use-agignore t))
834 #+BEGIN_SRC emacs-lisp
835 (use-package helm-descbinds
837 :bind ("C-h b" . helm-descbinds)
838 :init (fset 'describe-bindings 'helm-descbinds))
842 #+BEGIN_SRC emacs-lisp
843 (use-package helm-c-yasnippet
845 :bind ("C-c h y" . helm-yas-complete)
847 (setq helm-yas-space-match-any-greedy t)))
850 #+BEGIN_SRC emacs-lisp
851 (use-package helm-org-rifle
854 (defun malb/helm-org-rifle-agenda-files (arg)
856 (let ((current-prefix-arg nil))
858 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
859 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
860 (t (helm-org-agenda-files-headings)))))))
863 This can be used to link things pretty quickly if necessary
864 #+BEGIN_SRC emacs-lisp
865 (use-package helm-google
867 :bind ("C-c h g" . helm-google)
869 (progn (add-to-list 'helm-google-actions
870 '("Copy URL" . (lambda (candidate)
872 (replace-regexp-in-string
873 "https://.*q=\\(.*\\)\&sa=.*"
879 (add-to-list 'helm-google-actions
880 '("Org Store Link" . (lambda (candidate)
881 (let ((title (car (split-string candidate "[\n]+")))
883 (replace-regexp-in-string
884 "https://.*q=\\(.*\\)\&sa=.*"
886 (push (list url title) org-stored-links))))
891 ** Projectile -- Project management
892 #+begin_src emacs-lisp
893 (use-package projectile
895 :bind (("<f5>" . projectile-compile-project)
896 ("<f6>" . next-error))
898 (use-package magit :ensure t)
899 (require 'helm-projectile)
902 (setq projectile-make-test-cmd "make check"
903 projectile-switch-project-action 'helm-projectile
904 projectile-mode-line '(:eval (format "»{%s}" (projectile-project-name))))
906 (projectile-global-mode)))
910 #+begin_src emacs-lisp
911 (use-package helm-projectile
914 (defvar malb/helm-source-file-not-found
915 (helm-build-dummy-source
920 'helm-projectile-sources-list
921 malb/helm-source-file-not-found t)
923 (helm-delete-action-from-source
924 "Grep in projects `C-s'"
925 helm-source-projectile-projects)
927 (helm-add-action-to-source
928 "Grep in projects `C-s'"
929 'helm-do-ag helm-source-projectile-projects 4)))
932 #+BEGIN_SRC emacs-lisp
935 :bind ("M-z" . avy-zap-up-to-char-dwim))
938 #+BEGIN_SRC emacs-lisp
940 :bind (("C-c 2" . my/hydra-orgmodes/body)
941 ("C-c @" . my/hydra-orgmodes/body)
942 ("C-c #" . my/hydra-outline/body)
943 ("C-c 3" . my/hydra-outline/body)
946 (defhydra my/hydra-orgmodes (:color blue :hint nil)
948 _n_: notes _c_: chaim _w_: wildman _o_: ool
949 _u_: uddin _s_: steve _r_: refile _f_: fh
950 _p_: read papers _R_: paper notes
955 ("n" (find-file "~/projects/org-notes/notes.org"))
956 ("c" (find-file "~/projects/org-notes/chaim.org"))
957 ("w" (find-file "~/projects/org-notes/wildman.org"))
958 ("u" (find-file "~/projects/org-notes/uddin.org"))
959 ("o" (find-file "~/projects/org-notes/ool.org"))
960 ("f" (find-file "~/projects/org-notes/fh.org"))
961 ("s" (find-file "~/projects/org-notes/sndservers.org"))
962 ("r" (find-file "~/projects/org-notes/refile.org"))
963 ("p" (find-file "~/projects/research/papers_to_read.org"))
964 ("R" (find-file "~/projects/research/paper_notes.org"))
965 ("h" (find-file "~/projects/org-notes/hpcbio.org"))
970 ;; from https://github.com/abo-abo/hydra/wiki/Emacs
971 (defhydra my/hydra-outline (:color pink :hint nil)
974 ^^^^^^------------------------------------------------------
975 _q_: sublevels _a_: all _u_: up
976 _t_: body _e_: entry _n_: next visible
977 _o_: other _i_: children _p_: previous visible
978 _c_: entry _k_: branches _f_: forward same level
979 _l_: leaves _s_: subtree _b_: backward same level
984 ("q" outline-hide-sublevels) ; Hide everything but the top-level headings
985 ("t" outline-hide-body) ; Hide everything but headings (all body lines)
986 ("o" outline-hide-other) ; Hide other branches
987 ("c" outline-hide-entry) ; Hide this entry's body
988 ("l" outline-hide-leaves) ; Hide body lines in this entry and sub-entries
989 ("d" outline-hide-subtree) ; Hide everything in this entry and sub-entries
991 ("a" outline-show-all) ; Show (expand) everything
992 ("e" outline-show-entry) ; Show this heading's body
993 ("i" outline-show-children) ; Show this heading's immediate child sub-headings
994 ("k" outline-show-branches) ; Show all sub-headings under this heading
995 ("s" outline-show-subtree) ; Show (expand) everything in this heading & below
997 ("u" outline-up-heading) ; Up
998 ("n" outline-next-visible-heading) ; Next
999 ("p" outline-previous-visible-heading) ; Previous
1000 ("f" outline-forward-same-level) ; Forward - same level
1001 ("b" outline-backward-same-level) ; Backward - same level
1007 #+BEGIN_SRC emacs-lisp
1010 (add-to-list 'tramp-methods '("vcsh"
1011 (tramp-login-program "vcsh")
1015 (tramp-remote-shell "/bin/sh")
1016 (tramp-remote-shell-args
1020 #+BEGIN_SRC emacs-lisp
1024 (setq-default reftex-default-bibliography
1025 '("~/projects/research/references.bib")))
1028 #+BEGIN_SRC emacs-lisp
1030 :config (setq bibtex-user-optional-fields
1031 (quote (("annote" "Personal annotation (ignored)")
1039 #+BEGIN_SRC emacs-lisp
1044 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1045 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1046 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1047 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
1048 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
1049 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1050 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1051 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
1052 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
1053 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
1054 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
1056 (setq-default reftex-plug-into-AUCTeX t)
1057 ;; support fake section headers
1058 (setq TeX-outline-extra
1062 ("%subsubsection" 4)
1064 ;; add font locking to the headers
1065 (font-lock-add-keywords
1067 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1068 0 'font-lock-keyword-face t)
1069 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
1070 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
1071 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
1072 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1073 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
1075 ;; use smart quotes by default instead of `` and ''
1076 ;; taken from http://kieranhealy.org/esk/kjhealy.html
1077 (setq TeX-open-quote "“")
1078 (setq TeX-close-quote "”")
1080 ;; (TeX-add-style-hook
1085 ;; (custom-set-variables
1086 ;; '(font-latex-user-keyword-classes
1089 ;; font-lock-function-name-face 2 (command 1 t))))
1091 (setq-default TeX-parse-self t)
1092 (setq-default TeX-auto-save t)
1093 (setq-default TeX-master nil)
1096 '(TeX-add-style-hook
1099 (if (boundp 'reftex-ref-style-alist)
1101 'reftex-ref-style-alist
1102 '("Cleveref" "cleveref"
1103 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1104 (reftex-ref-style-activate "Cleveref")
1106 '("cref" TeX-arg-ref)
1107 '("Cref" TeX-arg-ref)
1108 '("cpageref" TeX-arg-ref)
1109 '("Cpageref" TeX-arg-ref)))))
1112 '(add-to-list 'LaTeX-fill-excluded-macros
1115 (use-package font-latex
1117 (setq font-latex-match-reference-keywords
1139 (setq font-latex-fontify-script nil)
1140 (setq font-latex-fontify-sectioning (quote color))
1141 (setq font-latex-script-display (quote (nil)))
1146 #+BEGIN_SRC emacs-lisp
1150 :mode ("\\.R\\'" . ess-r-mode)
1151 :bind (:map ess-mode-map
1152 ("C-c C-R" . dla/ess-region-remote-eval))
1154 (autoload 'ess-r-mode "ess-site" nil t)
1155 (autoload 'R "ess-site" nil t)
1157 ; actually load the rest of ess
1159 (defun ess-change-directory (path)
1160 "Set the current working directory to PATH for both *R* and Emacs."
1161 (interactive "Directory to change to: ")
1163 (when (file-exists-p path)
1164 (ess-command (concat "setwd(\"" path "\")\n"))
1165 ;; use file-name-as-directory to ensure it has trailing /
1166 (setq default-directory (file-name-as-directory path))))
1167 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1168 ;; outlining support for ess modes
1172 (outline-minor-mode)
1173 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1174 (defun outline-level ()
1175 (cond ((looking-at "^##### ") 1)
1176 ((looking-at "^#### ") 2)
1177 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1180 (defun dla/ess-region-remote-eval (start end)
1181 "Evaluate region in a remote ESS instance"
1183 (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***"))
1184 kill-buffer "***essregionremoteeval***")
1185 ;; Don't restore history or save workspace image
1186 '(inferior-R-args "--no-restore-history --no-save")
1191 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1193 #+BEGIN_SRC emacs-lisp
1194 (use-package rainbow-mode
1195 ;; add ess to the x major mode
1196 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1197 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1202 #+BEGIN_SRC emacs-lisp
1203 (use-package polymode
1205 (use-package poly-R)
1206 (use-package poly-noweb)
1207 (use-package poly-markdown)
1208 :mode ("\\.Snw" . poly-noweb+r-mode)
1209 :mode ("\\.Rnw" . poly-noweb+r-mode)
1210 :mode ("\\.Rmd" . poly-markdown+r-mode)
1216 #+BEGIN_SRC emacs-lisp
1217 (use-package outline-magic)
1220 #+BEGIN_SRC emacs-lisp
1221 ;; change the outline mode prefix from C-c @ to C-c C-2
1222 (setq outline-minor-mode-prefix "C-c C-2")
1223 ;;(add-hook 'outline-minor-mode-hook
1224 ;; (lambda () (local-set-key (kbd "C-c C-2")
1225 ;; outline-mode-prefix-map)))
1229 #+BEGIN_SRC emacs-lisp
1230 (use-package writeroom-mode
1232 (defun my/writing-mode ()
1233 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1238 (visual-line-mode -1)
1240 (visual-fill-column-mode -1)
1242 (visual-line-mode 1)
1244 (visual-fill-column-mode 1)
1249 ** GhostText/Atomic Chrome
1250 #+BEGIN_SRC emacs-lisp
1251 (use-package atomic-chrome
1253 (ignore-errors (atomic-chrome-start-server))
1254 (setq atomic-chrome-buffer-open-style 'full)
1259 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
1261 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1262 #+BEGIN_SRC emacs-lisp
1263 (use-package multiple-cursors
1264 :bind* (("C-;" . mc/mark-all-dwim)
1265 ("C-<" . mc/mark-previous-like-this)
1266 ("C->" . mc/mark-next-like-this)
1267 ("C-S-c C-S-c" . mc/edit-lines))
1271 #+BEGIN_SRC emacs-lisp
1272 (use-package web-mode
1274 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1275 (setq web-mode-enable-engine-detection t)
1276 (setq web-mode-engines-alist
1277 '(("template-toolkit" . "\\.tmpl\\'")))
1280 ** Spamassassin Mode
1281 #+BEGIN_SRC emacs-lisp
1282 (use-package spamassassin-mode
1283 :commands spamassassin-mode
1288 #+BEGIN_SRC emacs-lisp
1289 (use-package password-store
1291 :commands password-store-edit password-store-generate
1295 #+BEGIN_SRC emacs-lisp
1299 ;; fix up css mode to not be silly
1300 ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1301 (setq cssm-indent-level 4)
1302 (setq cssm-newline-before-closing-bracket t)
1303 (setq cssm-indent-function #'cssm-c-style-indenter)
1304 (setq cssm-mirror-mode nil))
1307 #+BEGIN_SRC emacs-lisp
1309 :diminish abbrev-mode
1311 ;; load abbreviations from
1312 (setq abbrev-file-name
1313 "~/.emacs_abbrev_def")
1315 ;; read the abbrev file if it exists
1316 (if (file-exists-p abbrev-file-name)
1317 (quietly-read-abbrev-file))
1319 ;; for now, use abbrev mode everywhere
1320 (setq default-abbrev-mode t))
1326 #+BEGIN_SRC emacs-lisp
1327 (use-package message
1329 :diminish (message "✉")
1330 :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1331 :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1332 :hook 'my/message-mode-settings
1333 :hook 'turn-on-flyspell
1334 :bind (:map message-mode-map
1335 ("C-c C-a" . my/post-attach-file))
1336 :delight (message-mode "✉")
1338 (defun my/message-mode-settings ()
1339 (font-lock-add-keywords nil
1340 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1341 (0 'message-multiply-quoted-text-face))
1342 ("^[ \t]*>[ \t]*>.*$"
1343 (0 'message-double-quoted-text-face))))
1346 (defun my/post-attach-file ()
1347 "Prompt for an attachment."
1349 (let ((file (read-file-name "Attach file: " nil nil t nil)))
1350 (my/header-attach-file file "")))
1352 (defun my/header-attach-file (file description)
1353 "Attach a FILE to the current message (works with Mutt).
1354 Argument DESCRIPTION MIME description."
1355 (interactive "fAttach file: \nsDescription: ")
1356 (when (> (length file) 0)
1361 (goto-char (point-min))
1362 (search-forward-regexp "^$")
1363 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1365 (message (concat "Attached '" file "'."))
1366 (setq post-has-attachment t))))))
1368 (setq mail-yank-prefix "> ")
1372 #+BEGIN_SRC emacs-lisp
1373 (use-package muttrc-mode
1380 ** Reverting buffers
1381 #+BEGIN_SRC emacs-lisp
1382 (use-package autorevert
1383 :diminish auto-revert-mode
1385 (setq global-auto-revert-non-file-buffers t
1386 global-auto-revert-ignore-modes '(pdf-view-mode)
1387 auto-revert-verbose nil)
1388 (global-auto-revert-mode 1))
1391 ** Use-package and load things
1392 #+BEGIN_SRC emacs-lisp
1395 :delight (org-mode "ø")
1396 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1397 :bind (("C-c l" . org-store-link)
1398 ("C-c a" . org-agenda)
1399 ("C-c b" . org-iswitchb))
1401 ** Agenda Configuration
1402 #+BEGIN_SRC emacs-lisp
1404 (setq-default org-log-done 'time)
1405 (setq-default org-agenda-ndays 5)
1407 ;; agenda configuration
1408 ;; Do not dim blocked tasks
1409 (setq org-agenda-dim-blocked-tasks nil)
1410 (setq org-agenda-inhibit-startup t)
1411 (setq org-agenda-use-tag-inheritance nil)
1413 ;; Compact the block agenda view
1414 (setq org-agenda-compact-blocks t)
1416 ;; Custom agenda command definitions
1417 (setq org-agenda-custom-commands
1418 (quote (("N" "Notes" tags "NOTE"
1419 ((org-agenda-overriding-header "Notes")
1420 (org-tags-match-list-sublevels t)))
1421 ("h" "Habits" tags-todo "STYLE=\"habit\""
1422 ((org-agenda-overriding-header "Habits")
1423 (org-agenda-sorting-strategy
1424 '(todo-state-down effort-up category-keep))))
1428 ((org-agenda-overriding-header "Tasks to Refile")
1429 (org-tags-match-list-sublevels nil)))
1430 (tags-todo "-CANCELLED/!"
1431 ((org-agenda-overriding-header "Stuck Projects")
1432 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1433 (org-agenda-sorting-strategy
1435 (tags-todo "-HOLD-CANCELLED/!"
1436 ((org-agenda-overriding-header "Projects")
1437 (org-agenda-skip-function 'bh/skip-non-projects)
1438 (org-tags-match-list-sublevels 'indented)
1439 (org-agenda-sorting-strategy
1441 (tags-todo "-CANCELLED/!NEXT"
1442 ((org-agenda-overriding-header (concat "Project Next Tasks"
1443 (if bh/hide-scheduled-and-waiting-next-tasks
1445 " (including WAITING and SCHEDULED tasks)")))
1446 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1447 (org-tags-match-list-sublevels t)
1448 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1449 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1450 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1451 (org-agenda-sorting-strategy
1452 '(todo-state-down effort-up category-keep))))
1453 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1454 ((org-agenda-overriding-header (concat "Project Subtasks"
1455 (if bh/hide-scheduled-and-waiting-next-tasks
1457 " (including WAITING and SCHEDULED tasks)")))
1458 (org-agenda-skip-function 'bh/skip-non-project-tasks)
1459 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1460 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1461 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1462 (org-agenda-sorting-strategy
1464 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1465 ((org-agenda-overriding-header (concat "Standalone Tasks"
1466 (if bh/hide-scheduled-and-waiting-next-tasks
1468 " (including WAITING and SCHEDULED tasks)")))
1469 (org-agenda-skip-function 'bh/skip-project-tasks)
1470 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1471 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1472 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1473 (org-agenda-sorting-strategy
1475 (tags-todo "-CANCELLED+WAITING|HOLD/!"
1476 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1477 (org-agenda-skip-function 'bh/skip-stuck-projects)
1478 (org-tags-match-list-sublevels nil)
1479 (org-agenda-todo-ignore-scheduled t)
1480 (org-agenda-todo-ignore-deadlines t)))
1482 ((org-agenda-overriding-header "Tasks to Archive")
1483 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1484 (org-tags-match-list-sublevels nil))))
1487 ; org mode agenda files
1488 (setq org-agenda-files
1489 (quote ("~/projects/org-notes/debbugs.org"
1490 "~/projects/org-notes/notes.org"
1491 "~/projects/org-notes/holidays.org"
1492 "~/projects/org-notes/refile.org"
1493 "~/projects/org-notes/diary.org"
1494 "~/projects/org-notes/ool.org"
1495 "~/projects/org-notes/sndservers.org"
1496 "~/projects/org-notes/chaim.org"
1497 "~/projects/org-notes/wildman.org"
1498 "~/projects/org-notes/uddin.org"
1499 "~/projects/org-notes/reviews.org"
1500 "~/org-mode/from-mobile.org"
1501 "~/projects/org-notes/fh.org")))
1503 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1504 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
1505 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1506 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1507 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1508 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1509 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1510 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1511 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1512 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1513 (defun org-agenda-timeline-all (&optional arg)
1516 (dolist (org-agenda-file org-agenda-files)
1517 (insert-file-contents org-agenda-file nil)
1518 (goto-char (point-max))
1520 (write-file "/tmp/timeline.org")
1521 (org-agenda arg "L")))
1522 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1526 #+BEGIN_SRC emacs-lisp
1527 (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")))
1528 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1530 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1531 (setq org-id-link-to-org-use-id 'use-existing)
1533 ** Capture Templates
1534 #+BEGIN_SRC emacs-lisp
1535 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1536 `(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
1537 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1538 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
1539 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1540 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
1541 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1542 ("n" "note" entry (file "~/projects/org-notes/refile.org")
1543 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1544 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
1545 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1546 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1547 "* %?\n%U\n" :clock-in t :clock-resume t)
1548 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
1549 "* TODO Review %c\n%U\n" :immediate-finish t)
1550 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
1551 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1552 ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
1553 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1554 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1555 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1556 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
1557 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1558 ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1560 ,(format-time-string "Positions %Y"))
1561 "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1562 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
1563 "* 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")
1567 ;; Remove empty LOGBOOK drawers on clock out
1568 (defun bh/remove-empty-drawer-on-clock-out ()
1571 (beginning-of-line 0)
1572 (org-remove-empty-drawer-at (point))))
1574 (defun my/org-add-id ()
1577 (if (org-current-level)
1586 ** Org mode key bindings
1587 #+BEGIN_SRC emacs-lisp
1588 ;; org mode configuration from http://doc.norang.ca/org-mode.html
1589 ;; Custom Key Bindings
1590 :bind* (("<f9> a" . org-agenda)
1591 ("<f9> I" . bh/punch-in)
1592 ("<f9> O" . bh/punch-out)
1593 ("<f9> SPC" . bh/clock-in-last-task)
1594 ("<f12>" . org-agenda)
1595 ;; ("<f5>" . bh/org-todo)
1596 ("<S-f5>" . bh/widen)
1597 ("<f7>" . bh/set-truncate-lines)
1598 ("<f8>" . org-cycle-agenda-files)
1599 ("<f9> <f9>" . org-agenda)
1601 ("<f9> c" . calendar)
1602 ("<f9> f" . boxquote-insert-file)
1603 ("<f9> h" . bh/hide-other)
1604 ("<f9> n" . bh/toggle-next-task-display)
1607 ("<f9> r" . boxquote-region)
1608 ("<f9> s" . bh/switch-to-scratch)
1610 ("<f9> t" . bh/insert-inactive-timestamp)
1611 ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1613 ("<f9> v" . visible-mode)
1614 ("<f9> l" . org-toggle-link-display)
1615 ("<f9> SPC" . bh/clock-in-last-task)
1616 ("C-<f9>" . previous-buffer)
1617 ("M-<f9>" . org-toggle-inline-images)
1618 ("C-x n r" . narrow-to-region)
1619 ("C-<f10>" . next-buffer)
1620 ("<f11>" . org-clock-goto)
1621 ("C-<f11>" . org-clock-in)
1622 ("C-s-<f12>" . bh/save-then-publish)
1623 ("C-c c" . org-capture))
1626 ** Utility Functions
1627 #+BEGIN_SRC emacs-lisp
1628 (defun bh/hide-other ()
1631 (org-back-to-heading 'invisible-ok)
1637 (defun bh/set-truncate-lines ()
1638 "Toggle value of truncate-lines and refresh window display."
1640 (setq truncate-lines (not truncate-lines))
1641 ;; now refresh window display (an idiom from simple.el):
1643 (set-window-start (selected-window)
1644 (window-start (selected-window)))))
1646 (defun bh/switch-to-scratch ()
1648 (switch-to-buffer "*scratch*"))
1650 (setq org-use-fast-todo-selection t)
1651 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1653 ; create function to create headlines in file. This comes from
1654 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1655 (defun my/org-add-ids-to-headlines-in-file ()
1656 "Add ID properties to all headlines in the current file which
1657 do not already have one."
1659 (org-map-entries 'org-id-get-create))
1660 (defun dla/org-update-ids-to-headlines-in-file ()
1661 "Add or replace ID properties to all headlines in the current file
1662 (or narrowed region)."
1664 (org-map-entries '(lambda () (org-id-get-create t))))
1665 ; if we wanted to do this to every buffer, do the following:
1666 ; (add-hook 'org-mode-hook
1668 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1671 #+BEGIN_SRC emacs-lisp
1672 (setq org-todo-keywords
1673 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1674 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1676 (setq org-todo-keyword-faces
1677 (quote (("TODO" :foreground "red" :weight bold)
1678 ("NEXT" :foreground "blue" :weight bold)
1679 ("DONE" :foreground "forest green" :weight bold)
1680 ("WAITING" :foreground "orange" :weight bold)
1681 ("HOLD" :foreground "magenta" :weight bold)
1682 ("CANCELLED" :foreground "forest green" :weight bold)
1683 ("MEETING" :foreground "forest green" :weight bold)
1684 ("PHONE" :foreground "forest green" :weight bold))))
1686 (setq org-todo-state-tags-triggers
1687 (quote (("CANCELLED" ("CANCELLED" . t))
1688 ("WAITING" ("WAITING" . t))
1689 ("HOLD" ("WAITING") ("HOLD" . t))
1690 (done ("WAITING") ("HOLD"))
1691 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1692 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1693 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1697 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1698 ; add ids on creation of nodes
1699 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1702 ; resolve clocks after 10 minutes of idle; use xprintidle
1703 ; (setq org-clock-idle-time 10)
1704 ; (setq org-clock-x11idle-program-name "xprintidle")
1706 ; this is from http://doc.norang.ca/org-mode.html#Capture
1707 ; use C-M-r for org mode capture
1708 (global-set-key (kbd "C-M-r") 'org-capture)
1710 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1711 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1712 (org-agenda-files :maxlevel . 9))))
1714 ; Use full outline paths for refile targets - we file directly with IDO
1715 (setq org-refile-use-outline-path t)
1717 ; Targets complete directly with IDO
1718 (setq org-outline-path-complete-in-steps nil)
1720 ; Allow refile to create parent tasks with confirmation
1721 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1723 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1724 ; (setq org-completion-use-ido t)
1725 ; (setq ido-everywhere t)
1726 ; (setq ido-max-directory-size 100000)
1727 ; (ido-mode (quote both))
1728 ; ; Use the current window when visiting files and buffers with ido
1729 ; (setq ido-default-file-method 'selected-window)
1730 ; (setq ido-default-buffer-method 'selected-window)
1731 ; ; Use the current window for indirect buffer display
1732 ; (setq org-indirect-buffer-display 'current-window)
1735 ;;;; Refile settings
1736 ; Exclude DONE state tasks from refile targets
1737 (defun bh/verify-refile-target ()
1738 "Exclude todo keywords with a done state from refile targets"
1739 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1741 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1743 ;; ensure that emacsclient will show just the note to be edited when invoked
1744 ;; from Mutt, and that it will shut down emacsclient once finished;
1745 ;; fallback to legacy behavior when not invoked via org-protocol.
1746 (require 'org-protocol)
1747 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1748 (setq my-org-protocol-flag nil)
1749 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1750 "Delete frame at remember finalization"
1751 (progn (if my-org-protocol-flag (delete-frame))
1752 (setq my-org-protocol-flag nil)))
1753 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1754 "Delete frame at remember refile"
1755 (if my-org-protocol-flag
1757 (setq my-org-protocol-flag nil)
1762 (defadvice org-capture-kill (after delete-frame-at-end activate)
1763 "Delete frame at remember abort"
1764 (progn (if my-org-protocol-flag (delete-frame))
1765 (setq my-org-protocol-flag nil)))
1766 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1767 (setq my-org-protocol-flag t))
1769 (defadvice org-insert-todo-heading (after dla/create-id activate)
1770 (unless (org-in-item-p)
1776 (add-to-list 'org-modules 'org-habit)
1778 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1779 (defun open-mail-in-mutt (message)
1780 "Open a mail message in Mutt, using an external terminal.
1782 Message can be specified either by a path pointing inside a
1783 Maildir, or by Message-ID."
1784 (interactive "MPath or Message-ID: ")
1786 (format "faf xterm -e \"%s %s\""
1787 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1789 ;; add support for "mutt:ID" links
1790 (org-add-link-type "mutt" 'open-mail-in-mutt)
1792 (defun my-org-mode-setup ()
1793 ; (load-library "reftex")
1794 (and (buffer-file-name)
1795 (file-exists-p (buffer-file-name))
1797 ; (reftex-parse-all)
1798 (reftex-set-cite-format
1799 '((?b . "[[bib:%l][%l-bib]]")
1800 (?n . "[[notes:%l][%l-notes]]")
1802 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1804 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1805 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1806 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1807 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1809 (add-hook 'org-mode-hook 'my-org-mode-setup)
1811 (defun org-mode-reftex-search ()
1813 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1815 (defun open-research-paper (bibtexkey)
1816 "Open a paper by bibtex key"
1817 (interactive "bibtex key: ")
1820 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1821 (org-add-link-type "papers" 'open-research-paper)
1822 (defun open-research-paper-pdf (bibtexkey)
1823 "Open a paper pdf by bibtex key"
1824 (interactive "bibtex key: ")
1826 (format "%s -p evince_annot %s"
1827 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1828 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1830 (add-to-list 'org-link-abbrev-alist
1832 "~/projects/research/paper_notes.org::#%s"))
1834 ; I pretty much always want hiearchical checkboxes
1835 (setq org-hierachical-checkbox-statistics nil)
1837 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1838 (add-to-list 'org-structure-template-alist
1839 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1842 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1843 (defun my-rtcite-export-handler (path desc format)
1844 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1845 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1846 (match-string 1 path)))
1847 (path (substring path 0 (match-beginning 0))))
1848 (cond ((eq format 'latex)
1850 (equal 0 (search "rtcite:" desc)))
1851 (format "\\cite{%s}" search)
1852 (format "\\cite[%s]{%s}" desc search))))))
1854 (org-add-link-type "rtcite"
1856 'my-rtcite-export-handler)
1860 ** Org Mobile Configuration
1861 #+BEGIN_SRC emacs-lisp
1862 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1863 (when (string= system-name "linnode")
1864 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1865 (setq-default org-directory "/home/don/org-mode/")
1866 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1870 #+BEGIN_SRC emacs-lisp
1871 ;; org mode ical export
1872 (setq org-icalendar-timezone "America/Los_Angeles")
1873 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1874 ;; we already add the id manually
1875 (setq org-icalendar-store-UID t)
1878 ** General Org Babel Configuration
1879 #+BEGIN_SRC emacs-lisp
1880 ;; org babel support
1881 (org-babel-do-load-languages
1882 'org-babel-load-languages
1889 ;; use graphviz-dot for dot things
1890 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1891 ;; org-babel-by-backend
1892 (defmacro org-babel-by-backend (&rest body)
1893 `(case (if (boundp 'backend)
1894 (org-export-backend-name backend)
1897 (defun my/fix-inline-images ()
1898 (when org-inline-image-overlays
1899 (org-redisplay-inline-images)))
1901 (add-hook 'org-babel-after-execute-hook
1902 'my/fix-inline-images)
1905 ** LaTeX configuration
1907 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
1909 #+BEGIN_SRC emacs-lisp
1911 (add-to-list 'org-latex-classes
1913 "\\documentclass[11pt,oneside,article]{memoir}\n"
1914 ("\\section{%s}" . "\\section*{%s}")
1915 ("\\subsection{%s}" . "\\subsection*{%s}")
1916 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1917 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1918 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1920 (setq org-beamer-outline-frame-options "")
1921 (add-to-list 'org-latex-classes
1923 "\\documentclass[ignorenonframetext]{beamer}
1924 [NO-DEFAULT-PACKAGES]
1927 ("\\section{%s}" . "\\section*{%s}")
1928 ("\\subsection{%s}" . "\\subsection*{%s}")
1929 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1930 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1931 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1933 (add-to-list 'org-latex-classes
1935 "\\documentclass[11pt,oneside]{memoir}\n"
1936 ("\\chapter{%s}" . "\\chapter*{%s}")
1937 ("\\section{%s}" . "\\section*{%s}")
1938 ("\\subsection{%s}" . "\\subsection*{%s}")
1939 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1941 (add-to-list 'org-latex-classes
1943 "\\documentclass[11pt]{letter}
1944 [NO-DEFAULT-PACKAGES]
1947 ("\\section{%s}" . "\\section*{%s}")
1948 ("\\subsection{%s}" . "\\subsection*{%s}")
1949 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1950 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1951 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1953 (add-to-list 'org-latex-classes
1955 "\\documentclass{dlacv}
1956 [NO-DEFAULT-PACKAGES]
1959 ("\\section{%s}" . "\\section*{%s}")
1960 ("\\subsection{%s}" . "\\subsection*{%s}")
1961 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1962 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1963 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1966 (add-to-list 'org-latex-classes
1968 "\\documentclass{dlaresume}
1969 [NO-DEFAULT-PACKAGES]
1972 ("\\section{%s}" . "\\section*{%s}")
1973 ("\\subsection{%s}" . "\\subsection*{%s}")
1974 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1975 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1976 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1979 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
1980 ;; but adapted to use latexmk 4.22 or higher.
1981 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
1983 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
1984 (setq org-latex-default-packages-alist
1986 ("" "unicode-math" t)
1988 (setq org-latex-packages-alist
1995 ("" "longtable" nil)
1998 ;; make equations larger
1999 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2001 (defun org-create-formula--latex-header ()
2002 "Return LaTeX header appropriate for previewing a LaTeX snippet."
2003 (let ((info (org-combine-plists (org-export--get-global-options
2004 (org-export-get-backend 'latex))
2005 (org-export--get-inbuffer-options
2006 (org-export-get-backend 'latex)))))
2007 (org-latex-guess-babel-language
2008 (org-latex-guess-inputenc
2009 (org-splice-latex-header
2010 org-format-latex-header
2011 org-latex-default-packages-alist
2013 (plist-get info :latex-header)))
2017 ; support ignoring headers in org mode export to latex
2018 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2019 (defadvice org-latex-headline (around my-latex-skip-headlines
2020 (headline contents info) activate)
2021 (if (member "ignoreheading" (org-element-property :tags headline))
2022 (setq ad-return-value contents)
2025 ;; keep latex logfiles
2027 (setq org-latex-remove-logfiles nil)
2029 ;; Resume clocking task when emacs is restarted
2030 (org-clock-persistence-insinuate)
2032 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2033 (setq org-clock-history-length 23)
2034 ;; Resume clocking task on clock-in if the clock is open
2035 (setq org-clock-in-resume t)
2036 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2037 ;; there are things like PHONE calls
2038 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2039 ;; Separate drawers for clocking and logs
2040 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2041 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2042 (setq org-clock-into-drawer t)
2043 (setq org-log-into-drawer t)
2044 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2045 (setq org-clock-out-remove-zero-time-clocks t)
2046 ;; Clock out when moving task to a done state
2047 (setq org-clock-out-when-done t)
2048 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2049 (setq org-clock-persist t)
2050 ;; Do not prompt to resume an active clock
2051 (setq org-clock-persist-query-resume nil)
2052 ;; Enable auto clock resolution for finding open clocks
2053 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2054 ;; Include current clocking task in clock reports
2055 (setq org-clock-report-include-clocking-task t)
2057 ;; the cache seems to be broken
2058 (setq org-element-use-cache nil)
2060 (defvar bh/keep-clock-running nil)
2062 (defun bh/is-task-p ()
2063 "Any task with a todo keyword and no subtask"
2067 (subtree-end (save-excursion (org-end-of-subtree t)))
2068 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2071 (while (and (not has-subtask)
2072 (< (point) subtree-end)
2073 (re-search-forward "^\*+ " subtree-end t))
2074 (when (member (org-get-todo-state) org-todo-keywords-1)
2075 (setq has-subtask t))))
2076 (and is-a-task (not has-subtask)))))
2077 (defun bh/is-project-p ()
2078 "Any task with a todo keyword subtask"
2082 (subtree-end (save-excursion (org-end-of-subtree t)))
2083 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2086 (while (and (not has-subtask)
2087 (< (point) subtree-end)
2088 (re-search-forward "^\*+ " subtree-end t))
2089 (when (member (org-get-todo-state) org-todo-keywords-1)
2090 (setq has-subtask t))))
2091 (and is-a-task has-subtask))))
2093 (defun bh/is-subproject-p ()
2094 "Any task which is a subtask of another project"
2095 (let ((is-subproject)
2096 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2098 (while (and (not is-subproject) (org-up-heading-safe))
2099 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2100 (setq is-subproject t))))
2101 (and is-a-task is-subproject)))
2104 (defun bh/clock-in-to-next (kw)
2105 "Switch a task from TODO to NEXT when clocking in.
2106 Skips capture tasks, projects, and subprojects.
2107 Switch projects and subprojects from NEXT back to TODO"
2108 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2110 ((and (member (org-get-todo-state) (list "TODO"))
2113 ((and (member (org-get-todo-state) (list "NEXT"))
2117 (defun bh/punch-in (arg)
2118 "Start continuous clocking and set the default task to the
2119 selected task. If no task is selected set the Organization task
2120 as the default task."
2122 (setq bh/keep-clock-running t)
2123 (if (equal major-mode 'org-agenda-mode)
2125 ;; We're in the agenda
2127 (let* ((marker (org-get-at-bol 'org-hd-marker))
2128 (tags (org-with-point-at marker (org-get-tags-at))))
2129 (if (and (eq arg 4) tags)
2130 (org-agenda-clock-in '(16))
2131 (bh/clock-in-organization-task-as-default)))
2133 ;; We are not in the agenda
2137 ; Find the tags on the current task
2138 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2139 (org-clock-in '(16))
2140 (bh/clock-in-organization-task-as-default)))))
2142 (defun bh/punch-out ()
2144 (setq bh/keep-clock-running nil)
2145 (when (org-clock-is-active)
2147 (org-agenda-remove-restriction-lock))
2149 (defun bh/clock-in-default-task ()
2151 (org-with-point-at org-clock-default-task
2154 (defun bh/clock-in-parent-task ()
2155 "Move point to the parent (project) task if any and clock in"
2156 (let ((parent-task))
2160 (while (and (not parent-task) (org-up-heading-safe))
2161 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2162 (setq parent-task (point))))
2164 (org-with-point-at parent-task
2166 (when bh/keep-clock-running
2167 (bh/clock-in-default-task)))))))
2169 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2171 (defun bh/clock-in-organization-task-as-default ()
2173 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2174 (org-clock-in '(16))))
2176 (defun bh/clock-out-maybe ()
2177 (when (and bh/keep-clock-running
2178 (not org-clock-clocking-in)
2179 (marker-buffer org-clock-default-task)
2180 (not org-clock-resolving-clocks-due-to-idleness))
2181 (bh/clock-in-parent-task)))
2183 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2186 (defun bh/clock-in-task-by-id (id)
2187 "Clock in a task by id"
2188 (org-with-point-at (org-id-find id 'marker)
2189 (org-clock-in nil)))
2191 (defun bh/clock-in-last-task (arg)
2192 "Clock in the interrupted task if there is one
2193 Skip the default task and get the next one.
2194 A prefix arg forces clock in of the default task."
2196 (let ((clock-in-to-task
2198 ((eq arg 4) org-clock-default-task)
2199 ((and (org-clock-is-active)
2200 (equal org-clock-default-task (cadr org-clock-history)))
2201 (caddr org-clock-history))
2202 ((org-clock-is-active) (cadr org-clock-history))
2203 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2204 (t (car org-clock-history)))))
2206 (org-with-point-at clock-in-to-task
2207 (org-clock-in nil))))
2210 (defun org-export-to-ods ()
2212 (let ((csv-file "data.csv"))
2213 (org-table-export csv-file "orgtbl-to-csv")
2214 (org-odt-convert csv-file "ods" 'open)))
2216 ; allow for zero-width-space to be a break in regexp too
2217 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
2218 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
2219 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2221 ;; support inserting screen shots
2222 (defun my/org-insert-screenshot ()
2223 "Take a screenshot into a time stamped unique-named file in the
2224 same directory as the org-buffer and insert a link to this file."
2226 (defvar my/org-insert-screenshot/filename)
2227 (setq my/org-insert-screenshot/filename
2229 "Screenshot to insert: "
2231 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2234 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2235 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2236 (org-display-inline-images))
2238 (defun my/fix-inline-images ()
2239 (when org-inline-image-overlays
2240 (org-redisplay-inline-images)))
2242 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2244 ;; use xelatex to preview with imagemagick
2245 (add-to-list 'org-preview-latex-process-alist
2246 '(xelateximagemagick
2247 :programs ("xelatex" "convert")
2248 :description "pdf > png"
2249 :message "you need to install xelatex and imagemagick"
2251 :image-input-type "pdf"
2252 :image-output-type "png"
2253 :image-size-adjust (1.0 . 1.0)
2254 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2255 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2257 ;; use xelatex by default
2258 (setq org-preview-latex-default-process 'xelateximagemagick)
2260 ; from http://orgmode.org/Changes.html
2261 (defun my/org-repair-property-drawers ()
2262 "Fix properties drawers in current buffer.
2263 Ignore non Org buffers."
2265 (when (eq major-mode 'org-mode)
2266 (org-with-wide-buffer
2267 (goto-char (point-min))
2268 (let ((case-fold-search t)
2269 (inline-re (and (featurep 'org-inlinetask)
2270 (concat (org-inlinetask-outline-regexp)
2274 (unless (and inline-re (org-looking-at-p inline-re))
2276 (let ((end (save-excursion (outline-next-heading) (point))))
2278 (when (org-looking-at-p org-planning-line-re) (forward-line))
2279 (when (and (< (point) end)
2280 (not (org-looking-at-p org-property-drawer-re))
2282 (and (re-search-forward org-property-drawer-re end t)
2283 (eq (org-element-type
2284 (save-match-data (org-element-at-point)))
2286 (insert (delete-and-extract-region
2288 (min (1+ (match-end 0)) end)))
2289 (unless (bolp) (insert "\n"))))))))))))
2293 #+BEGIN_SRC emacs-lisp
2297 (use-package calfw-org
2300 (use-package org-gcal
2302 :config '((if (file-readable-p "~/.hide/org_gcal.el")
2303 (load-file "~/.hide/org_gcal.el"))
2308 #+BEGIN_SRC emacs-lisp
2312 ;; Show notification 10 minutes before event
2313 (setq appt-message-warning-time 10)
2314 ;; Disable multiple reminders
2315 (setq appt-display-interval appt-message-warning-time)
2316 (setq appt-display-mode-line nil)
2318 ;; add automatic reminders for appointments
2319 (defun my/org-agenda-to-appt ()
2321 (setq appt-time-msg-list nil)
2322 (org-agenda-to-appt))
2323 ;; add reminders when starting emacs
2324 (my/org-agenda-to-appt)
2325 ;; when rebuilding the agenda
2326 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
2327 "Pressing `r' on the agenda will also add appointments."
2328 (my/org-agenda-to-appt)
2330 ;; when saving all org buffers
2331 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2332 "Re-add appts after saving all org buffers"
2333 (my/org-agenda-to-appt))
2334 ;; Display appointments as a window manager notification
2335 (setq appt-disp-window-function 'my/appt-display)
2336 (setq appt-delete-window-function (lambda () t))
2338 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2340 (defun my/appt-display (min-to-app new-time msg)
2341 (if (atom min-to-app)
2342 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2343 (dolist (i (number-sequence 0 (1- (length min-to-app))))
2344 (start-process "my/appt-notification-app" nil my/appt-notification-app
2345 (nth i min-to-app) (nth i msg))))
2352 #+BEGIN_SRC emacs-lisp
2357 #+BEGIN_SRC emacs-lisp
2358 (global-unset-key "\M-g")
2359 (global-set-key (kbd "M-g l") 'goto-line)
2363 #+BEGIN_SRC emacs-lisp
2364 (use-package debian-changelog-mode
2365 :mode "debian/changelog"
2367 (setq debian-changelog-mailing-address "don@debian.org")
2368 (setq debian-changelog-full-name "Don Armstrong"))
2370 * Misc (uncharacterized)
2371 #+BEGIN_SRC emacs-lisp
2372 (setq calendar-latitude 38.6)
2373 (setq calendar-longitude -121.5)
2374 (setq case-fold-search t)
2375 (setq confirm-kill-emacs (quote y-or-n-p))
2376 (setq cperl-lazy-help-time nil)
2377 (global-font-lock-mode 1)
2379 (setq log-edit-keep-buffer t)
2380 (setq mail-user-agent (quote sendmail-user-agent))
2381 (setq markdown-enable-math t)
2382 (setq markdown-follow-wiki-link-on-enter nil)
2383 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2384 (setq ps-footer-font-size (quote (8 . 10)))
2385 (setq ps-header-font-size (quote (8 . 10)))
2386 (setq ps-header-title-font-size (quote (10 . 10)))
2387 (setq ps-line-number-color "blue")
2388 (setq ps-print-footer t)
2389 (setq ps-print-footer-frame nil)
2390 (setq ps-print-only-one-header t)
2391 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
2393 (setq sentence-end-double-space nil)
2394 ; enable matching parenthesis
2397 (setq user-mail-address "don@donarmstrong.com")
2398 (setq vc-delete-logbuf-window nil)
2399 (setq vc-follow-symlinks t)
2401 ;; use git before SVN; use CVS earlier, because I have CVS
2402 ;; repositories inside of git directories
2403 (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
2405 ;; switch back to the old primary selection method
2406 (setq x-select-enable-clipboard nil)
2407 (setq x-select-enable-primary t)
2408 ; (setq mouse-drag-copy-region t)
2410 (fset 'perl-mode 'cperl-mode)
2411 ;;(load-file "cperl-mode.el")
2413 ;; tramp configuration
2414 (setq tramp-use-ssh-controlmaster-options nil)
2416 (setq-default c-indent-level 4)
2417 (setq-default c-brace-imaginary-offset 0)
2418 (setq-default c-brace-offset -4)
2419 (setq-default c-argdecl-indent 4)
2420 (setq-default c-label-offset -4)
2421 (setq-default c-continued-statement-offset 4)
2423 (setq-default indent-tabs-mode nil)
2424 (setq-default tab-width 4)
2427 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2428 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2429 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2430 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2431 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2434 (defun insert-date ()
2435 "Insert date at point."
2437 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2438 (global-set-key "\C-[d" 'insert-date)
2440 (defun unfill-paragraph (arg)
2441 "Pull this whole paragraph up onto one line."
2443 (let ((fill-column 10000))
2444 (fill-paragraph arg))
2447 (column-number-mode t)
2450 ** Desktop-save-mode
2451 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2452 emacs, and use a different desktop file to restore history
2453 #+BEGIN_SRC emacs-lisp
2454 (use-package desktop
2457 (setq desktop-base-file-name
2458 (convert-standard-filename
2460 (or (getenv "EMACS_SERVER_NAME")
2464 (setq desktop-base-lock-name
2465 (convert-standard-filename
2466 (concat desktop-base-file-name
2468 (setq desktop-auto-save-timeout 60)
2469 (setq desktop-restore-eager 5)
2470 (setq desktop-lazy-verbose nil)
2471 (desktop-save-mode 1)
2475 ** Misc (Uncharacterized)
2476 #+BEGIN_SRC emacs-lisp
2477 '(icomplete-mode on)
2479 ;; custom-set-faces was added by Custom.
2480 ;; If you edit it by hand, you could mess it up, so be careful.
2481 ;; Your init file should contain only one such instance.
2482 ;; If there is more than one, they won't work right.
2483 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2486 (put 'upcase-region 'disabled nil)
2487 (put 'downcase-region 'disabled nil)
2488 (put 'narrow-to-region 'disabled nil)
2490 ; (defun turn-on-flyspell ()
2491 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2493 ; (flyspell-mode 1))
2496 ; Outline-minor-mode key map
2497 (define-prefix-command 'cm-map nil "Outline-")
2499 (define-key cm-map "q" 'outline-hide-sublevels) ; Hide everything but the top-level headings
2500 (define-key cm-map "t" 'outline-hide-body) ; Hide everything but headings (all body lines)
2501 (define-key cm-map "o" 'outline-hide-other) ; Hide other branches
2502 (define-key cm-map "c" 'outline-hide-entry) ; Hide this entry's body
2503 (define-key cm-map "l" 'outline-hide-leaves) ; Hide body lines in this entry and sub-entries
2504 (define-key cm-map "d" 'outline-hide-subtree) ; Hide everything in this entry and sub-entries
2506 (define-key cm-map "a" 'outline-show-all) ; Show (expand) everything
2507 (define-key cm-map "e" 'outline-show-entry) ; Show this heading's body
2508 (define-key cm-map "i" 'outline-show-children) ; Show this heading's immediate child sub-headings
2509 (define-key cm-map "k" 'outline-show-branches) ; Show all sub-headings under this heading
2510 (define-key cm-map "s" 'outline-show-subtree) ; Show (expand) everything in this heading & below
2512 (define-key cm-map "u" 'outline-up-heading) ; Up
2513 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2514 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2515 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2516 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2517 (global-set-key "\M-o" cm-map)
2518 ; fix up tmux xterm keys
2519 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2520 (defun fix-up-tmux-keys ()
2521 "Fix up tmux xterm keys"
2524 (let ((x 2) (tkey ""))
2544 ;; ctrl + alt + shift
2546 (setq tkey "C-M-S-"))
2549 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2550 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2551 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2552 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2554 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2556 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2558 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2560 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2562 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2564 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2566 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2568 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2570 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2572 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2574 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2576 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2578 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2580 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2582 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2584 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2586 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2588 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2590 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2592 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2594 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2596 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2598 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2600 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2602 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2604 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2611 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2613 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2614 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2615 (if (or (buffer-modified-p)
2616 (verify-visited-file-modtime)
2617 (< (* 8 1024 1024) (buffer-size))
2618 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2620 (clear-visited-file-modtime)
2622 (ad-activate 'ask-user-about-supersession-threat)
2626 #+BEGIN_SRC emacs-lisp
2630 (or (getenv "EMACS_SERVER_NAME")
2632 (unless (server-running-p)
2633 (global-set-key "\C-xp" 'server-edit)
2640 #+BEGIN_SRC emacs-lisp
2641 (provide 'don-configuration)