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
36 (add-to-list 'gnutls-trustfiles "/etc/ssl/ca-global/ca-certificates.crt")
37 (setq package-enable-at-startup nil)
38 (setq package--init-file-ensured t)
39 (setq package-user-dir "~/var/emacs/elpa")
40 (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
41 ("melpa" . "https://melpa.org/packages/")
42 ("org" . "http://orgmode.org/elpa/")))
43 (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
44 (mapc #'(lambda (add) (add-to-list 'load-path add))
47 (unless (package-installed-p 'use-package)
48 (package-refresh-contents)
49 (package-install 'use-package))
50 (let ((package-user-dir-real (file-truename package-user-dir)))
51 ;; The reverse is necessary, because outside we mapc
52 ;; add-to-list element-by-element, which reverses.
53 (nreverse (apply #'nconc
54 ;; Only keep package.el provided loadpaths.
55 (mapcar #'(lambda (path)
56 (if (string-prefix-p package-user-dir-real path)
61 ;;; fix up info paths for packages
62 (with-eval-after-load "info"
64 (dolist (dir (directory-files package-user-dir))
65 (let ((fdir (concat (file-name-as-directory package-user-dir) dir)))
66 (unless (or (member dir '("." ".." "archives" "gnupg"))
67 (not (file-directory-p fdir))
68 (not (file-exists-p (concat (file-name-as-directory fdir) "dir"))))
69 (add-to-list 'Info-directory-list fdir)))))
73 (require 'use-package))
78 #+BEGIN_SRC emacs-lisp
81 :commands (paradox-upgrade-packages paradox-list-packages)
82 :config (setq paradox-execute-asynchronously t)
87 #+BEGIN_SRC emacs-lisp
88 (add-to-list 'load-path '"~/lib/emacs_el/")
89 (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
92 #+BEGIN_SRC emacs-lisp
93 ;; Set the custom file to /dev/null and don't bother to load it
94 (setq custom-file "/dev/null")
98 #+BEGIN_SRC emacs-lisp
99 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
100 ;; execute conditional code when loading libraries
101 (defmacro with-library (symbol &rest body)
102 `(when (require ,symbol nil t)
104 (put 'with-library 'lisp-indent-function 1)
108 ** Safe Local Variables
109 #+BEGIN_SRC emacs-lisp
110 (setq safe-local-variable-values
111 (quote ((auto-save-default)
113 (cperl-indent-level . 4)
115 (indent-tabs-mode . f)
116 (vcl-indent-level . 4)
120 #+BEGIN_SRC emacs-lisp
121 (setq global-mark-ring-max 128
125 (defun don/minibuffer-setup-hook ()
126 (setq gc-cons-threshold most-positive-fixnum))
128 (defun don/minibuffer-exit-hook ()
129 (setq gc-cons-threshold 1048576))
131 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
132 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
136 #+BEGIN_SRC emacs-lisp
137 (use-package spacemacs-common
138 :ensure spacemacs-theme
140 (load-theme 'spacemacs-dark t)
144 #+BEGIN_SRC emacs-lisp
145 (use-package hippie-exp
146 :bind* (("M-<SPC>" . hippie-expand))
150 #+BEGIN_SRC emacs-lisp
151 (use-package flyspell
153 :diminish flyspell-mode 🐝
155 (add-hook 'text-mode-hook 'turn-on-flyspell)
156 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
157 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
158 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
160 (setq ispell-program-name "ispell")
165 #+begin_src emacs-lisp :tangle yes
171 #+BEGIN_SRC emacs-lisp
176 #+BEGIN_SRC emacs-lisp
177 (use-package eyebrowse
179 :diminish eyebrowse-mode
180 :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
182 (setq eyebrowse-wrap-around t)
185 (defun my/eyebrowse-new-window-config ()
189 ;; start at 1 run till 0
190 (let ((j (mod (+ i 1) 10)))
191 (when (and (not done)
192 (not (eyebrowse--window-config-present-p j)))
193 (eyebrowse-switch-to-window-config j)
194 (call-interactively 'eyebrowse-rename-window-config2 j)
199 ;; I don't use latex-preview-pane
200 ;; (require 'latex-preview-pane)
201 ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
202 ;; ;; latex-preview-pane uses window-parameters which are
203 ;; ;; not preserved by eyebrowse, so we close the preview
204 ;; ;; pane before switching, it will be regenerated when we
205 ;; ;; edit the TeX file.
206 ;; (when (lpp/window-containing-preview)
207 ;; (delete-window (lpp/window-containing-preview))))
209 ;; (add-to-list 'eyebrowse-pre-window-switch-hook
210 ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
212 ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
213 ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
214 ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
215 ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
216 ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
224 #+BEGIN_SRC emacs-lisp
225 (defun my/vsplit-last-buffer ()
226 "Split the window vertically and display the previous buffer."
228 (split-window-vertically)
230 (switch-to-next-buffer))
232 (defun my/hsplit-last-buffer ()
233 "Split the window horizontally and display the previous buffer."
235 (split-window-horizontally)
237 (switch-to-next-buffer))
239 (bind-key "C-x 2" 'my/vsplit-last-buffer)
240 (bind-key "C-x 3" 'my/hsplit-last-buffer)
242 (setq split-width-threshold 100)
243 (setq split-height-threshold 60)
245 (defun my/split-window-prefer-vertically (window)
246 "If there's only one window (excluding any possibly active
247 minibuffer), then split the current window horizontally."
248 (if (and (one-window-p t)
249 (not (active-minibuffer-window))
250 ( < (frame-width) (frame-height))
252 (let ((split-width-threshold nil))
253 (split-window-sensibly window))
254 (split-window-sensibly window)))
256 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
257 (setq window-combination-resize t)
260 *** Compilation window
262 If there is no compilation window, open one at the bottom, spanning
263 the complete width of the frame. Otherwise, reuse existing window. In
264 the former case, if there was no error the window closes
267 #+BEGIN_SRC emacs-lisp
268 (add-to-list 'display-buffer-alist
269 `(,(rx bos "*compilation*" eos)
270 (display-buffer-reuse-window
271 display-buffer-in-side-window)
272 (reusable-frames . visible)
274 (window-height . 0.4)))
277 #+BEGIN_SRC emacs-lisp
278 (defun my/compilation-exit-autoclose (status code msg)
279 ;; If M-x compile exists with a 0
280 (when (and (eq status 'exit) (zerop code))
281 ;; and delete the *compilation* window
282 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
283 (when (and (not (window-at-side-p compilation-window 'top))
284 (window-at-side-p compilation-window 'left)
285 (window-at-side-p compilation-window 'right))
286 (delete-window compilation-window))))
287 ;; Always return the anticipated result of compilation-exit-message-function
290 ;; Specify my function (maybe I should have done a lambda function)
291 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
294 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
295 value, the compilation buffer scrolls automatically to follow the
296 output. If the value is ~first-error~, scrolling stops when the first
297 error appears, leaving point at that error. For any other non-nil
298 value, scrolling continues until there is no more output.
300 #+BEGIN_SRC emacs-lisp
301 (setq compilation-scroll-output 'first-error)
304 ** Mode line cleaning
306 #+BEGIN_SRC emacs-lisp
307 (use-package diminish
312 #+BEGIN_SRC emacs-lisp
319 #+BEGIN_SRC emacs-lisp
321 :if (>= emacs-major-version 25)
323 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
324 ("C-c j j" . avy-goto-word-or-subword-1)
325 ("M-g g" . avy-goto-line))
326 :config (progn (setq avy-background t))
329 *** Ace-link (jumping to links)
330 #+BEGIN_SRC emacs-lisp
331 (use-package ace-link
333 ; bind o in most modes
334 :config (ace-link-setup-default))
336 *** Jumping through edit points (goto-chg)
337 #+BEGIN_SRC emacs-lisp
338 (use-package goto-chg
340 :bind (("C-c j ," . goto-last-change)
341 ("C-c j ." . goto-last-change-reverse))
344 *** Jumping to bookmarks (visible bookmarks, bm)
345 #+BEGIN_SRC emacs-lisp
348 :bind (("C-c j b ." . bm-next)
349 ("C-c j b ," . bm-previous)
350 ("C-c j b SPC" . bm-toggle)))
355 #+BEGIN_SRC emacs-lisp
356 (use-package yasnippet
358 :diminish yas-minor-mode
361 (setq yas-verbosity 1)
362 (define-key yas-minor-mode-map (kbd "<tab>") nil)
363 (define-key yas-minor-mode-map (kbd "TAB") nil)
364 (define-key yas-minor-mode-map (kbd "<backtab>") nil)
365 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
366 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
367 (add-to-list 'hippie-expand-try-functions-list
368 'yas-hippie-try-expand)
374 #+BEGIN_SRC emacs-lisp
375 (use-package auto-yasnippet
377 :bind (("H-w" . aya-create)
383 #+BEGIN_SRC emacs-lisp
386 :bind (("M-/" . company-complete))
388 (setq company-echo-delay 0 ; remove blinking
389 company-show-numbers t ; show numbers for easy selection
390 company-selection-wrap-around t
391 company-require-match nil
392 company-dabbrev-ignore-case t
393 company-dabbrev-ignore-invisible t
394 company-dabbrev-other-buffers t
395 company-dabbrev-downcase nil
396 company-dabbrev-code-everywhere t
397 company-tooltip-align-annotations t
398 company-minimum-prefix-length 1
399 company-global-modes '(not)
400 company-lighter-base "(C)")
401 (global-company-mode 1)
402 :bind (:map company-active-map
403 ("C-n" . company-select-next)
404 ("C-p" . company-select-previous)
405 ("M-?" . company-show-doc-buffer)
406 ("M-." . company-show-location)
411 #+BEGIN_SRC emacs-lisp
412 (use-package company-c-headers
415 (defun malb/ede-object-system-include-path ()
416 "Return the system include path for the current buffer."
418 (ede-system-include-path ede-object)))
420 (setq company-c-headers-path-system
421 #'malb/ede-object-system-include-path)
423 (add-to-list 'company-backends #'company-c-headers)))
426 #+BEGIN_SRC emacs-lisp
427 (use-package company-anaconda
429 :config (add-to-list 'company-backends #'company-anaconda))
432 #+BEGIN_SRC emacs-lisp
433 (use-package company-plsense
438 #+BEGIN_SRC emacs-lisp
439 (use-package company-math
442 #+BEGIN_SRC emacs-lisp
443 (use-package company-auctex
446 (defun company-auctex-labels (command &optional arg &rest ignored)
447 "company-auctex-labels backend"
448 (interactive (list 'interactive))
450 (interactive (company-begin-backend 'company-auctex-labels))
451 (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
452 (candidates (company-auctex-label-candidates arg))))
454 (add-to-list 'company-backends
455 '(company-auctex-macros
456 company-auctex-environments
457 company-math-symbols-unicode
458 company-math-symbols-latex))
460 (add-to-list 'company-backends #'company-auctex-labels)
461 (add-to-list 'company-backends #'company-auctex-bibs)
465 #+BEGIN_SRC emacs-lisp
466 (use-package company-bibtex
472 #+BEGIN_SRC emacs-lisp
473 (use-package company-shell
476 (setq company-shell-modes '(sh-mode shell-mode))
477 (add-to-list 'company-backends 'company-shell)))
482 Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
484 *Note:* Do this at the end of =company-mode= config.
486 #+BEGIN_SRC emacs-lisp
487 (defvar malb/company-mode/enable-yas t
488 "Enable yasnippet for all backends.")
490 (defun malb/company-mode/backend-with-yas (backend)
491 (if (or (not malb/company-mode/enable-yas)
493 (member 'company-yasnippet backend)))
495 (append (if (consp backend) backend (list backend))
496 '(:with company-yasnippet))))
498 (setq company-backends
499 (mapcar #'malb/company-mode/backend-with-yas company-backends))
504 Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
506 #+BEGIN_SRC emacs-lisp
507 (defun malb/toggle-company-ispell ()
510 ((member '(company-ispell :with company-yasnippet) company-backends)
511 (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
512 (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
513 (message "company-ispell disabled"))
515 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
516 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
517 (message "company-ispell enabled!"))))
519 (defun malb/company-ispell-setup ()
520 ;; @see https://github.com/company-mode/company-mode/issues/50
521 (when (boundp 'company-backends)
522 (make-local-variable 'company-backends)
523 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
524 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
525 ;; https://github.com/redguardtoo/emacs.d/issues/473
526 (if (and (boundp 'ispell-alternate-dictionary)
527 ispell-alternate-dictionary)
528 (setq company-ispell-dictionary ispell-alternate-dictionary))))
533 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
535 2. This function then hopefully does what I want:
537 a. if a region is active, just indent
538 b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
539 c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
540 d. otherwise call whatever would have been called otherwise.
542 ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
544 #+BEGIN_SRC emacs-lisp
545 (defun malb/indent-fold-or-complete (&optional arg)
548 ;; if a region is active, indent
550 (indent-region (region-beginning)
552 ;; if the next char is space or eol, but prev char not whitespace
553 ((and (not (active-minibuffer-window))
556 (looking-back "[^[:space:]]")
557 (not (looking-back "^")))
559 (cond (company-mode (company-complete-common))
560 (auto-complete-mode (auto-complete))))
562 ;; no whitespace anywhere
563 ((and (not (active-minibuffer-window))
564 (looking-at "[^[:space:]]")
565 (looking-back "[^[:space:]]")
566 (not (looking-back "^")))
568 ((bound-and-true-p hs-minor-mode)
569 (save-excursion (end-of-line) (hs-toggle-hiding)))
570 ((bound-and-true-p outline-minor-mode)
571 (save-excursion (outline-cycle)))))
573 ;; by default just call whatever was bound
575 (let ((fn (or (if (current-local-map) (lookup-key (current-local-map) (kbd "TAB")))
576 'indent-for-tab-command)))
577 (if (not (called-interactively-p 'any))
579 (setq this-command fn)
580 (call-interactively fn))))))
582 (defun malb/toggle-fold ()
584 (cond ((eq major-mode 'org-mode)
585 (org-force-cycle-archived))
586 ((bound-and-true-p hs-minor-mode)
591 ((bound-and-true-p outline-minor-mode)
595 (bind-key "<tab>" #'malb/indent-fold-or-complete)
596 (bind-key "C-<tab>" #'malb/toggle-fold)
600 #+BEGIN_SRC emacs-lisp
602 (use-package tinyprocmail
603 :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
604 :mode (".procmailrc" . turn-on-tinyprocmail-mode)
609 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
612 :bind (("C-x g" . magit-status)
613 ("C-x C-g" . magit-status))
615 ;; refine diffs always (hilight words)
616 (setq magit-diff-refine-hunk nil)
618 (use-package magit-annex
620 :load-path "~/lib/emacs_el/magit-annex/"
622 (use-package magit-vcsh
628 #+BEGIN_SRC emacs-lisp
629 (use-package cperl-mode
632 ;; Use c-mode for perl .xs files
633 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
634 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
635 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
636 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
637 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
640 cperl-auto-newline nil
641 cperl-auto-newline-after-colon nil
642 cperl-continued-statement-offset 4
643 cperl-brace-offset -1
644 cperl-continued-brace-offset 0
645 cperl-label-offset -4
646 cperl-highlight-variables-indiscriminately t
647 cperl-electric-lbrace-space nil
648 cperl-indent-parens-as-block nil
649 cperl-close-paren-offset -1
650 cperl-tab-always-indent t)
651 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
656 #+BEGIN_SRC emacs-lisp
657 (use-package markdown-mode
659 :mode (("\\.md\\'" . markdown-mode)
660 ("\\.mdwn\\'" . markdown-mode)
661 ("README\\.md\\'" . gfm-mode)
664 (setq markdown-enable-math t)
665 (setq markdown-follow-wiki-link-on-enter nil)
666 (bind-key "M-." #'markdown-jump markdown-mode-map)
667 (add-hook 'markdown-mode-hook #'flyspell-mode)
668 (add-hook 'markdown-mode-hook #'outline-minor-mode)
669 (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
674 #+BEGIN_SRC emacs-lisp
675 ; load sql-indent when sql is loaded
677 :mode (("\\.sql\\'" . sql-mode))
679 (require sql-indent))
682 #+BEGIN_SRC emacs-lisp
684 :commands ediff ediff3
687 ;; ediff configuration
688 ;; don't use the multi-window configuration
689 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
692 ** Do the Right Thing Indenting
693 Attempts to automatically identify the right indentation for a file
694 #+BEGIN_SRC emacs-lisp
695 (use-package dtrt-indent
699 ** VCL --editing varnish configuration files
700 #+BEGIN_SRC emacs-lisp
701 (use-package vcl-mode
708 #+BEGIN_SRC emacs-lisp
709 (defun malb/helm-omni (&rest arg)
710 ;; just in case someone decides to pass an argument, helm-omni won't fail.
712 (unless helm-source-buffers-list
713 (setq helm-source-buffers-list
714 (helm-make-source "Buffers" 'helm-source-buffers)))
718 (if (projectile-project-p)
719 '(helm-source-projectile-buffers-list
720 helm-source-buffers-list)
721 '(helm-source-buffers-list)) ;; list of all open buffers
723 `(((name . "Virtual Workspace")
724 (candidates . ,(--map (cons (eyebrowse-format-slot it) (car it))
725 (eyebrowse--get 'window-configs)))
726 (action . (lambda (candidate)
727 (eyebrowse-switch-to-window-config candidate)))))
729 (if (projectile-project-p)
730 '(helm-source-projectile-recentf-list
732 '(helm-source-recentf)) ;; all recent files
734 ;; always make some common files easily accessible
735 ;;'(((name . "Common Files")
736 ;; (candidates . malb/common-file-targets)
737 ;; (action . (("Open" . (lambda (x) (find-file (eval x))))))))
739 '(helm-source-files-in-current-dir
741 helm-source-bookmarks
742 helm-source-buffer-not-found ;; ask to create a buffer otherwise
744 "*Helm all the things*"))
748 :bind (("M-x" . helm-M-x)
749 ("C-x C-f" . helm-find-files)
750 ("C-x b" . helm-buffers-list) ; malb/helm-omni)
751 ("C-x C-b" . helm-buffers-list) ; malb/helm-omni)
752 ("C-c <SPC>" . helm-all-mark-rings))
754 (require 'helm-config)
755 (require 'helm-for-files)
756 (require 'helm-bookmark)
759 (define-key global-map [remap find-file] 'helm-find-files)
760 (define-key global-map [remap occur] 'helm-occur)
761 (define-key global-map [remap list-buffers] 'helm-buffers-list)
762 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
763 (unless (boundp 'completion-in-region-function)
764 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
765 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
766 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
771 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
773 #+BEGIN_SRC emacs-lisp
774 (use-package helm-flx
777 ;; these are helm configs, but they kind of fit here nicely
778 (setq helm-M-x-fuzzy-match t
779 helm-bookmark-show-location t
780 helm-buffers-fuzzy-matching t
781 helm-completion-in-region-fuzzy-match t
782 helm-file-cache-fuzzy-match t
783 helm-imenu-fuzzy-match t
784 helm-mode-fuzzy-match t
785 helm-locate-fuzzy-match nil
787 helm-recentf-fuzzy-match nil
788 helm-semantic-fuzzy-match t)
792 #+BEGIN_SRC emacs-lisp
794 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
795 (defun malb/helm-swoop-pre-fill ()
796 (thing-at-point 'symbol))
797 (defvar malb/helm-swoop-ignore-major-mode "List of major modes to ignore for helm-swoop")
798 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
799 paradox-menu-mode doc-view-mode pdf-view-mode
800 mu4e-headers-mode org-mode markdown-mode latex-mode
801 ein:notebook-multilang-mode))
803 (defun malb/swoop-or-search ()
805 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
806 (memq major-mode malb/helm-swoop-ignore-major-mode))
810 (use-package helm-swoop
813 :bind (("C-c o" . helm-multi-swoop-org)
814 ("C-s" . malb/swoop-or-search)
815 ("C-M-s" . helm-multi-swoop-all))
818 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
819 helm-swoop-split-with-multiple-windows nil
820 helm-swoop-split-direction #'split-window-horizontally
821 helm-swoop-split-window-function 'helm-default-display-buffer
822 helm-swoop-speed-or-color t)
824 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
825 (defun malb/helm-swoop-C-s ()
827 (if (boundp 'helm-swoop-pattern)
828 (if (equal helm-swoop-pattern "")
829 (previous-history-element 1)
833 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
834 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
835 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
836 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
837 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
838 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
843 #+BEGIN_SRC emacs-lisp
846 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
847 helm-ag-command-option "--all-text"
848 helm-ag-insert-at-point 'symbol
849 helm-ag-fuzzy-match t
850 helm-ag-use-temp-buffer t
851 helm-ag-use-grep-ignore-list t
852 helm-ag-use-agignore t))
855 #+BEGIN_SRC emacs-lisp
856 (use-package helm-descbinds
858 :bind ("C-h b" . helm-descbinds)
859 :init (fset 'describe-bindings 'helm-descbinds))
863 #+BEGIN_SRC emacs-lisp
864 (use-package helm-c-yasnippet
866 :bind ("C-c h y" . helm-yas-complete)
868 (setq helm-yas-space-match-any-greedy t)))
871 #+BEGIN_SRC emacs-lisp
872 (use-package helm-org-rifle
875 (defun malb/helm-org-rifle-agenda-files (arg)
877 (let ((current-prefix-arg nil))
879 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
880 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
881 (t (helm-org-agenda-files-headings)))))))
884 This can be used to link things pretty quickly if necessary
885 #+BEGIN_SRC emacs-lisp
886 (use-package helm-google
888 :bind ("C-c h g" . helm-google)
890 (progn (add-to-list 'helm-google-actions
891 '("Copy URL" . (lambda (candidate)
893 (replace-regexp-in-string
894 "https://.*q=\\(.*\\)\&sa=.*"
900 (add-to-list 'helm-google-actions
901 '("Org Store Link" . (lambda (candidate)
902 (let ((title (car (split-string candidate "[\n]+")))
904 (replace-regexp-in-string
905 "https://.*q=\\(.*\\)\&sa=.*"
907 (push (list url title) org-stored-links))))
912 ** Projectile -- Project management
913 #+begin_src emacs-lisp
914 (use-package projectile
916 :bind (("<f5>" . projectile-compile-project)
917 ("<f6>" . next-error))
919 (use-package magit :ensure t)
920 (require 'helm-projectile)
923 (setq projectile-make-test-cmd "make check"
924 projectile-switch-project-action 'helm-projectile
925 projectile-mode-line '(:eval (format "»{%s}" (projectile-project-name))))
927 (projectile-global-mode)))
931 #+begin_src emacs-lisp
932 (use-package helm-projectile
935 (defvar malb/helm-source-file-not-found
936 (helm-build-dummy-source
941 'helm-projectile-sources-list
942 malb/helm-source-file-not-found t)
944 (helm-delete-action-from-source
945 "Grep in projects `C-s'"
946 helm-source-projectile-projects)
948 (helm-add-action-to-source
949 "Grep in projects `C-s'"
950 'helm-do-ag helm-source-projectile-projects 4)))
953 #+BEGIN_SRC emacs-lisp
956 :bind ("M-z" . avy-zap-up-to-char-dwim))
959 #+BEGIN_SRC emacs-lisp
961 :bind (("C-c 2" . my/hydra-orgmodes/body)
962 ("C-c @" . my/hydra-orgmodes/body)
963 ("C-c #" . my/hydra-outline/body)
964 ("C-c 3" . my/hydra-outline/body)
967 (defhydra my/hydra-orgmodes (:color blue :hint nil)
969 _n_: notes _c_: chaim _w_: wildman _o_: ool
970 _u_: uddin _s_: steve _r_: refile _f_: fh
971 _p_: read papers _R_: paper notes
976 ("n" (find-file "~/projects/org-notes/notes.org"))
977 ("c" (find-file "~/projects/org-notes/chaim.org"))
978 ("w" (find-file "~/projects/org-notes/wildman.org"))
979 ("u" (find-file "~/projects/org-notes/uddin.org"))
980 ("o" (find-file "~/projects/org-notes/ool.org"))
981 ("f" (find-file "~/projects/org-notes/fh.org"))
982 ("s" (find-file "~/projects/org-notes/sndservers.org"))
983 ("r" (find-file my/org-refile-file))
984 ("p" (find-file "~/projects/research/papers_to_read.org"))
985 ("R" (find-file "~/projects/research/paper_notes.org"))
986 ("h" (find-file "~/projects/org-notes/hpcbio.org"))
991 ;; from https://github.com/abo-abo/hydra/wiki/Emacs
992 (defhydra my/hydra-outline (:color pink :hint nil)
995 ^^^^^^------------------------------------------------------
996 _q_: sublevels _a_: all _u_: up
997 _t_: body _e_: entry _n_: next visible
998 _o_: other _i_: children _p_: previous visible
999 _c_: entry _k_: branches _f_: forward same level
1000 _l_: leaves _s_: subtree _b_: backward same level
1005 ("q" outline-hide-sublevels) ; Hide everything but the top-level headings
1006 ("t" outline-hide-body) ; Hide everything but headings (all body lines)
1007 ("o" outline-hide-other) ; Hide other branches
1008 ("c" outline-hide-entry) ; Hide this entry's body
1009 ("l" outline-hide-leaves) ; Hide body lines in this entry and sub-entries
1010 ("d" outline-hide-subtree) ; Hide everything in this entry and sub-entries
1012 ("a" outline-show-all) ; Show (expand) everything
1013 ("e" outline-show-entry) ; Show this heading's body
1014 ("i" outline-show-children) ; Show this heading's immediate child sub-headings
1015 ("k" outline-show-branches) ; Show all sub-headings under this heading
1016 ("s" outline-show-subtree) ; Show (expand) everything in this heading & below
1018 ("u" outline-up-heading) ; Up
1019 ("n" outline-next-visible-heading) ; Next
1020 ("p" outline-previous-visible-heading) ; Previous
1021 ("f" outline-forward-same-level) ; Forward - same level
1022 ("b" outline-backward-same-level) ; Backward - same level
1028 #+BEGIN_SRC emacs-lisp
1031 (add-to-list 'tramp-methods '("vcsh"
1032 (tramp-login-program "vcsh")
1036 (tramp-remote-shell "/bin/sh")
1037 (tramp-remote-shell-args
1041 #+BEGIN_SRC emacs-lisp
1045 (setq-default reftex-default-bibliography
1046 '("~/projects/research/references.bib")))
1049 #+BEGIN_SRC emacs-lisp
1051 :config (setq bibtex-user-optional-fields
1052 (quote (("annote" "Personal annotation (ignored)")
1060 #+BEGIN_SRC emacs-lisp
1065 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1066 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1067 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1068 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
1069 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
1070 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1071 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1072 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
1073 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
1074 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
1075 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
1077 (setq-default reftex-plug-into-AUCTeX t)
1078 ;; support fake section headers
1079 (setq TeX-outline-extra
1083 ("%subsubsection" 4)
1085 ;; add font locking to the headers
1086 (font-lock-add-keywords
1088 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1089 0 'font-lock-keyword-face t)
1090 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
1091 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
1092 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
1093 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1094 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
1096 ;; use smart quotes by default instead of `` and ''
1097 ;; taken from http://kieranhealy.org/esk/kjhealy.html
1098 (setq TeX-open-quote "“")
1099 (setq TeX-close-quote "”")
1101 ;; (TeX-add-style-hook
1106 ;; (custom-set-variables
1107 ;; '(font-latex-user-keyword-classes
1110 ;; font-lock-function-name-face 2 (command 1 t))))
1112 (setq-default TeX-parse-self t)
1113 (setq-default TeX-auto-save t)
1114 (setq-default TeX-master nil)
1115 (add-to-list 'LaTeX-font-list
1116 '(?\C-a "\\alert{","}"))
1119 '(TeX-add-style-hook
1122 (if (boundp 'reftex-ref-style-alist)
1124 'reftex-ref-style-alist
1125 '("Cleveref" "cleveref"
1126 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1127 (reftex-ref-style-activate "Cleveref")
1129 '("cref" TeX-arg-ref)
1130 '("Cref" TeX-arg-ref)
1131 '("cpageref" TeX-arg-ref)
1132 '("Cpageref" TeX-arg-ref)))))
1135 '(add-to-list 'LaTeX-fill-excluded-macros
1138 (use-package font-latex
1140 (setq font-latex-match-reference-keywords
1162 (setq font-latex-fontify-script nil)
1163 (setq font-latex-fontify-sectioning (quote color))
1164 (setq font-latex-script-display (quote (nil)))
1169 #+BEGIN_SRC emacs-lisp
1173 :mode ("\\.R\\'" . ess-r-mode)
1174 :bind (:map ess-mode-map
1175 ("C-c C-R" . dla/ess-region-remote-eval))
1177 (autoload 'ess-r-mode "ess-site" nil t)
1178 (autoload 'R "ess-site" nil t)
1180 ; actually load the rest of ess
1182 (defun ess-change-directory (path)
1183 "Set the current working directory to PATH for both *R* and Emacs."
1184 (interactive "Directory to change to: ")
1186 (when (file-exists-p path)
1187 (ess-command (concat "setwd(\"" path "\")\n"))
1188 ;; use file-name-as-directory to ensure it has trailing /
1189 (setq default-directory (file-name-as-directory path))))
1190 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1191 ;; outlining support for ess modes
1195 (outline-minor-mode)
1196 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1197 (defun outline-level ()
1198 (cond ((looking-at "^##### ") 1)
1199 ((looking-at "^#### ") 2)
1200 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1203 (defun dla/ess-region-remote-eval (start end)
1204 "Evaluate region in a remote ESS instance"
1206 (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***"))
1207 kill-buffer "***essregionremoteeval***")
1208 ;; Don't restore history or save workspace image
1209 '(inferior-R-args "--no-restore-history --no-save")
1214 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1216 #+BEGIN_SRC emacs-lisp
1217 (use-package rainbow-mode
1218 ;; add ess to the x major mode
1219 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1220 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1225 #+BEGIN_SRC emacs-lisp
1226 (use-package poly-noweb
1231 (use-package poly-markdown
1237 :after (:all polymode poly-markdown poly-noweb)
1238 ; :mode ("\\.Snw" . poly-noweb+r-mode)
1239 ; :mode ("\\.Rnw" . poly-noweb+r-mode)
1240 ; :mode ("\\.Rmd" . poly-markdown+r-mode)
1242 (use-package polymode
1250 #+BEGIN_SRC emacs-lisp
1251 (use-package outline-magic)
1254 #+BEGIN_SRC emacs-lisp
1255 ;; change the outline mode prefix from C-c @ to C-c C-2
1256 (setq outline-minor-mode-prefix "C-c C-2")
1257 ;;(add-hook 'outline-minor-mode-hook
1258 ;; (lambda () (local-set-key (kbd "C-c C-2")
1259 ;; outline-mode-prefix-map)))
1263 #+BEGIN_SRC emacs-lisp
1264 (use-package writeroom-mode
1266 (defun my/writing-mode ()
1267 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1272 (visual-line-mode -1)
1274 (visual-fill-column-mode -1)
1276 (visual-line-mode 1)
1278 (visual-fill-column-mode 1)
1283 ** GhostText/Atomic Chrome
1284 #+BEGIN_SRC emacs-lisp
1285 (use-package atomic-chrome
1287 (ignore-errors (atomic-chrome-start-server))
1288 (setq atomic-chrome-buffer-open-style 'full)
1293 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
1295 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1296 #+BEGIN_SRC emacs-lisp
1297 (use-package multiple-cursors
1298 :bind* (("C-;" . mc/mark-all-dwim)
1299 ("C-<" . mc/mark-previous-like-this)
1300 ("C->" . mc/mark-next-like-this)
1301 ("C-S-c C-S-c" . mc/edit-lines))
1305 #+BEGIN_SRC emacs-lisp
1306 (use-package web-mode
1307 :load-path "/home/don/projects/web-mode/"
1308 :mode ("\\.\\(tx|tmpl\\)\\'" . web-mode)
1310 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1311 (setq web-mode-enable-engine-detection t)
1312 (setq web-mode-engines-alist
1313 '(("template-toolkit" . "\\.tmpl\\'")))
1316 ** Spamassassin Mode
1317 #+BEGIN_SRC emacs-lisp
1318 (use-package spamassassin-mode
1319 :commands spamassassin-mode
1324 #+BEGIN_SRC emacs-lisp
1325 (use-package password-store
1327 :commands password-store-edit password-store-generate
1331 #+BEGIN_SRC emacs-lisp
1335 ;; fix up css mode to not be silly
1336 ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1337 (setq cssm-indent-level 4)
1338 (setq cssm-newline-before-closing-bracket t)
1339 (setq cssm-indent-function #'cssm-c-style-indenter)
1340 (setq cssm-mirror-mode nil))
1343 #+BEGIN_SRC emacs-lisp
1345 :diminish abbrev-mode
1347 ;; load abbreviations from
1348 (setq abbrev-file-name
1349 "~/.emacs_abbrev_def")
1351 ;; read the abbrev file if it exists
1352 (if (file-exists-p abbrev-file-name)
1353 (quietly-read-abbrev-file))
1355 ;; for now, use abbrev mode everywhere
1356 (setq default-abbrev-mode t))
1360 #+BEGIN_SRC emacs-lisp
1361 (use-package go-mode
1368 #+BEGIN_SRC emacs-lisp
1369 (use-package expand-region
1370 :bind (("C-=" . 'er/expand-region))
1375 #+BEGIN_SRC emacs-lisp
1376 (use-package dockerfile-mode
1382 #+BEGIN_SRC emacs-lisp
1383 (use-package beancount
1384 :load-path "~/lib/emacs_el/beancount-mode/"
1386 :mode "\\.beancount\\'"
1393 #+BEGIN_SRC emacs-lisp
1394 (use-package message
1396 :diminish (message "✉")
1397 :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1398 :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1399 :hook 'my/message-mode-settings
1400 :hook 'turn-on-flyspell
1401 :bind (:map message-mode-map
1402 ("C-c C-a" . my/post-attach-file))
1403 :delight (message-mode "✉")
1405 (defun my/message-mode-settings ()
1406 (font-lock-add-keywords nil
1407 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1408 (0 'message-multiply-quoted-text-face))
1409 ("^[ \t]*>[ \t]*>.*$"
1410 (0 'message-double-quoted-text-face))))
1413 (defun my/post-attach-file ()
1414 "Prompt for an attachment."
1416 (let ((file (read-file-name "Attach file: " nil nil t nil)))
1417 (my/header-attach-file file "")))
1419 (defun my/header-attach-file (file description)
1420 "Attach a FILE to the current message (works with Mutt).
1421 Argument DESCRIPTION MIME description."
1422 (interactive "fAttach file: \nsDescription: ")
1423 (when (> (length file) 0)
1428 (goto-char (point-min))
1429 (search-forward-regexp "^$")
1430 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1432 (message (concat "Attached '" file "'."))
1433 (setq post-has-attachment t))))))
1435 (setq mail-yank-prefix "> ")
1436 (setq mail-header-separator "") ; fix broken header detection
1440 #+BEGIN_SRC emacs-lisp
1441 (use-package muttrc-mode
1448 ** Reverting buffers
1449 #+BEGIN_SRC emacs-lisp
1450 (use-package autorevert
1451 :diminish auto-revert-mode
1453 (setq global-auto-revert-non-file-buffers t
1454 global-auto-revert-ignore-modes '(pdf-view-mode)
1455 auto-revert-verbose nil)
1456 (global-auto-revert-mode 1))
1459 ** Use-package and load things
1460 #+BEGIN_SRC emacs-lisp
1463 :delight (org-mode "ø")
1464 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1465 :bind (("C-c l" . org-store-link)
1466 ("C-c a" . org-agenda)
1467 ("C-c b" . org-iswitchb))
1469 ** Agenda Configuration
1470 #+BEGIN_SRC emacs-lisp
1472 (setq-default org-log-done 'time)
1473 (setq-default org-agenda-ndays 5)
1475 (setq org-agenda-sticky t)
1476 (defun dla/show-org-agenda ()
1481 (and (string-match-p
1489 (buffer-name agendabuffer))
1491 (delete-other-windows))
1493 ;; agenda configuration
1494 ;; Do not dim blocked tasks
1495 (setq org-agenda-dim-blocked-tasks nil)
1496 (setq org-agenda-inhibit-startup t)
1497 (setq org-agenda-use-tag-inheritance nil)
1499 ;; Compact the block agenda view
1500 (setq org-agenda-compact-blocks t)
1502 ;; Custom agenda command definitions
1503 (setq org-agenda-custom-commands
1504 (quote (("N" "Notes" tags "NOTE"
1505 ((org-agenda-overriding-header "Notes")
1506 (org-tags-match-list-sublevels t)))
1507 ("h" "Habits" tags-todo "STYLE=\"habit\""
1508 ((org-agenda-overriding-header "Habits")
1509 (org-agenda-sorting-strategy
1510 '(todo-state-down effort-up category-keep))))
1514 ((org-agenda-overriding-header "Tasks to Refile")
1515 (org-tags-match-list-sublevels nil)))
1516 (tags-todo "-CANCELLED/!"
1517 ((org-agenda-overriding-header "Stuck Projects")
1518 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1519 (org-agenda-sorting-strategy
1521 (tags-todo "-HOLD-CANCELLED/!"
1522 ((org-agenda-overriding-header "Projects")
1523 (org-agenda-skip-function 'bh/skip-non-projects)
1524 (org-tags-match-list-sublevels 'indented)
1525 (org-agenda-sorting-strategy
1527 (tags-todo "-CANCELLED/!NEXT"
1528 ((org-agenda-overriding-header (concat "Project Next Tasks"
1529 (if bh/hide-scheduled-and-waiting-next-tasks
1531 " (including WAITING and SCHEDULED tasks)")))
1532 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1533 (org-tags-match-list-sublevels t)
1534 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1535 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1536 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1537 (org-agenda-sorting-strategy
1538 '(todo-state-down effort-up category-keep))))
1539 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1540 ((org-agenda-overriding-header (concat "Project Subtasks"
1541 (if bh/hide-scheduled-and-waiting-next-tasks
1543 " (including WAITING and SCHEDULED tasks)")))
1544 (org-agenda-skip-function 'bh/skip-non-project-tasks)
1545 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1546 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1547 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1548 (org-agenda-sorting-strategy
1550 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1551 ((org-agenda-overriding-header (concat "Standalone Tasks"
1552 (if bh/hide-scheduled-and-waiting-next-tasks
1554 " (including WAITING and SCHEDULED tasks)")))
1555 (org-agenda-skip-function 'bh/skip-project-tasks)
1556 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1557 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1558 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1559 (org-agenda-sorting-strategy
1561 (tags-todo "-CANCELLED+WAITING|HOLD/!"
1562 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1563 (org-agenda-skip-function 'bh/skip-stuck-projects)
1564 (org-tags-match-list-sublevels nil)
1565 (org-agenda-todo-ignore-scheduled t)
1566 (org-agenda-todo-ignore-deadlines t)))
1568 ((org-agenda-overriding-header "Tasks to Archive")
1569 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1570 (org-tags-match-list-sublevels nil))))
1573 ; org mode agenda files
1574 (setq org-agenda-files
1576 (file-expand-wildcards "~/projects/org-notes/*.org")
1577 (file-expand-wildcards "~/org-mode/from-mobile.org")
1578 (file-expand-wildcards "~/org-notes-*/*.org")
1581 (setq my/org-refile-file
1583 (lambda (file) (string-match-p (regexp-quote "/refile.org") file))
1586 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1587 (set-register ?r (cons 'file my/org-refile-file))
1588 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1589 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1590 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1591 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1592 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1593 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1594 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1595 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1596 (defun org-agenda-timeline-all (&optional arg)
1599 (dolist (org-agenda-file org-agenda-files)
1600 (insert-file-contents org-agenda-file nil)
1601 (goto-char (point-max))
1603 (write-file "/tmp/timeline.org")
1604 (org-agenda arg "L")))
1605 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1609 #+BEGIN_SRC emacs-lisp
1610 (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")))
1611 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1613 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1614 (setq org-id-link-to-org-use-id 'use-existing)
1616 ** Capture Templates
1617 #+BEGIN_SRC emacs-lisp
1618 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1619 `(("m" "Mail" entry (file my/org-refile-file)
1620 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1621 ("t" "todo" entry (file my/org-refile-file)
1622 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1623 ("r" "respond" entry (file my/org-refile-file)
1624 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1625 ("n" "note" entry (file my/org-refile-file)
1626 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1627 ("s" "schedule" entry (file my/org-refile-file)
1628 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1629 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1630 "* %?\n%U\n" :clock-in t :clock-resume t)
1631 ("w" "org-protocol" entry (file my/org-refile-file)
1632 "* TODO Review %c\n%U\n" :immediate-finish t)
1633 ("M" "Meeting" entry (file my/org-refile-file)
1634 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1635 ("S" "Seminar" entry (file my/org-refile-file)
1636 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1637 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1638 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1639 ("p" "Phone call" entry (file my/org-refile-file)
1640 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1641 ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1643 ,(format-time-string "Positions %Y"))
1644 "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1645 ("h" "Habit" entry (file my/org-refile-file)
1646 "* 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")
1650 ;; Remove empty LOGBOOK drawers on clock out
1651 (defun bh/remove-empty-drawer-on-clock-out ()
1654 (beginning-of-line 0)
1655 (org-remove-empty-drawer-at (point))))
1657 (defun my/org-add-id ()
1660 (if (org-current-level)
1669 ** Org mode key bindings
1670 #+BEGIN_SRC emacs-lisp
1671 ;; org mode configuration from http://doc.norang.ca/org-mode.html
1672 ;; Custom Key Bindings
1673 :bind* (("<f9> a" . org-agenda)
1674 ("<f9> I" . bh/punch-in)
1675 ("<f9> O" . bh/punch-out)
1676 ("<f9> SPC" . bh/clock-in-last-task)
1677 ("<f12>" . dla/show-org-agenda)
1678 ;; ("<f5>" . bh/org-todo)
1679 ("<S-f5>" . bh/widen)
1680 ("<f7>" . bh/set-truncate-lines)
1681 ("<f8>" . org-cycle-agenda-files)
1682 ("<f9> <f9>" . dla/show-org-agenda)
1684 ("<f9> c" . calendar)
1685 ("<f9> f" . boxquote-insert-file)
1686 ("<f9> h" . bh/hide-other)
1687 ("<f9> n" . bh/toggle-next-task-display)
1690 ("<f9> r" . boxquote-region)
1691 ("<f9> s" . bh/switch-to-scratch)
1693 ("<f9> t" . bh/insert-inactive-timestamp)
1694 ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1696 ("<f9> v" . visible-mode)
1697 ("<f9> l" . org-toggle-link-display)
1698 ("<f9> SPC" . bh/clock-in-last-task)
1699 ("C-<f9>" . previous-buffer)
1700 ("M-<f9>" . org-toggle-inline-images)
1701 ("C-x n r" . narrow-to-region)
1702 ("C-<f10>" . next-buffer)
1703 ("<f11>" . org-clock-goto)
1704 ("C-<f11>" . org-clock-in)
1705 ("C-s-<f12>" . bh/save-then-publish)
1706 ("C-c c" . org-capture))
1709 ** Utility Functions
1710 #+BEGIN_SRC emacs-lisp
1711 (defun bh/hide-other ()
1714 (org-back-to-heading 'invisible-ok)
1720 (defun bh/set-truncate-lines ()
1721 "Toggle value of truncate-lines and refresh window display."
1723 (setq truncate-lines (not truncate-lines))
1724 ;; now refresh window display (an idiom from simple.el):
1726 (set-window-start (selected-window)
1727 (window-start (selected-window)))))
1729 (defun bh/switch-to-scratch ()
1731 (switch-to-buffer "*scratch*"))
1733 (setq org-use-fast-todo-selection t)
1734 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1736 ; create function to create headlines in file. This comes from
1737 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1738 (defun my/org-add-ids-to-headlines-in-file ()
1739 "Add ID properties to all headlines in the current file which
1740 do not already have one."
1742 (org-map-entries 'org-id-get-create))
1743 (defun dla/org-update-ids-to-headlines-in-file ()
1744 "Add or replace ID properties to all headlines in the current file
1745 (or narrowed region)."
1747 (org-map-entries '(lambda () (org-id-get-create t))))
1748 ; if we wanted to do this to every buffer, do the following:
1749 ; (add-hook 'org-mode-hook
1751 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1754 #+BEGIN_SRC emacs-lisp
1755 (use-package find-lisp
1757 (setq org-agenda-text-search-extra-files
1758 (append '(agenda-archives)
1759 (find-lisp-find-files "~/projects/org-notes" "\.org$")
1760 (find-lisp-find-files "~/projects/org-notes" "\.org_archive$")
1764 #+BEGIN_SRC emacs-lisp
1765 (setq org-todo-keywords
1766 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1767 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1769 (setq org-todo-keyword-faces
1770 (quote (("TODO" :foreground "red" :weight bold)
1771 ("NEXT" :foreground "blue" :weight bold)
1772 ("DONE" :foreground "forest green" :weight bold)
1773 ("WAITING" :foreground "orange" :weight bold)
1774 ("HOLD" :foreground "magenta" :weight bold)
1775 ("CANCELLED" :foreground "forest green" :weight bold)
1776 ("MEETING" :foreground "forest green" :weight bold)
1777 ("PHONE" :foreground "forest green" :weight bold))))
1779 (setq org-todo-state-tags-triggers
1780 (quote (("CANCELLED" ("CANCELLED" . t))
1781 ("WAITING" ("WAITING" . t))
1782 ("HOLD" ("WAITING") ("HOLD" . t))
1783 (done ("WAITING") ("HOLD"))
1784 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1785 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1786 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1790 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1791 ; add ids on creation of nodes
1792 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1795 ; resolve clocks after 10 minutes of idle; use xprintidle
1796 ; (setq org-clock-idle-time 10)
1797 ; (setq org-clock-x11idle-program-name "xprintidle")
1799 ; this is from http://doc.norang.ca/org-mode.html#Capture
1800 ; use C-M-r for org mode capture
1801 (global-set-key (kbd "C-M-r") 'org-capture)
1803 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1804 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1805 (org-agenda-files :maxlevel . 9))))
1807 ; Use full outline paths for refile targets - we file directly with IDO
1808 (setq org-refile-use-outline-path t)
1810 ; Targets complete directly with IDO
1811 (setq org-outline-path-complete-in-steps nil)
1813 ; Allow refile to create parent tasks with confirmation
1814 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1816 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1817 ; (setq org-completion-use-ido t)
1818 ; (setq ido-everywhere t)
1819 ; (setq ido-max-directory-size 100000)
1820 ; (ido-mode (quote both))
1821 ; ; Use the current window when visiting files and buffers with ido
1822 ; (setq ido-default-file-method 'selected-window)
1823 ; (setq ido-default-buffer-method 'selected-window)
1824 ; ; Use the current window for indirect buffer display
1825 ; (setq org-indirect-buffer-display 'current-window)
1828 ;;;; Refile settings
1829 ; Exclude DONE state tasks from refile targets
1830 (defun bh/verify-refile-target ()
1831 "Exclude todo keywords with a done state from refile targets"
1832 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1834 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1836 ;; ensure that emacsclient will show just the note to be edited when invoked
1837 ;; from Mutt, and that it will shut down emacsclient once finished;
1838 ;; fallback to legacy behavior when not invoked via org-protocol.
1839 (require 'org-protocol)
1840 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1841 (setq my-org-protocol-flag nil)
1842 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1843 "Delete frame at remember finalization"
1844 (progn (if my-org-protocol-flag (delete-frame))
1845 (setq my-org-protocol-flag nil)))
1846 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1847 "Delete frame at remember refile"
1848 (if my-org-protocol-flag
1850 (setq my-org-protocol-flag nil)
1855 (defadvice org-capture-kill (after delete-frame-at-end activate)
1856 "Delete frame at remember abort"
1857 (progn (if my-org-protocol-flag (delete-frame))
1858 (setq my-org-protocol-flag nil)))
1859 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1860 (setq my-org-protocol-flag t))
1862 (defadvice org-insert-todo-heading (after dla/create-id activate)
1863 (unless (org-in-item-p)
1869 (add-to-list 'org-modules 'org-habit)
1871 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1872 (defun open-mail-in-mutt (message)
1873 "Open a mail message in Mutt, using an external terminal.
1875 Message can be specified either by a path pointing inside a
1876 Maildir, or by Message-ID."
1877 (interactive "MPath or Message-ID: ")
1879 (format "faf xterm -e \"%s %s\""
1880 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1882 ;; add support for "mutt:ID" links
1883 (org-add-link-type "mutt" 'open-mail-in-mutt)
1885 (defun my-org-mode-setup ()
1886 ; (load-library "reftex")
1887 (and (buffer-file-name)
1888 (file-exists-p (buffer-file-name))
1890 ; (reftex-parse-all)
1891 (reftex-set-cite-format
1892 '((?b . "[[bib:%l][%l-bib]]")
1893 (?n . "[[notes:%l][%l-notes]]")
1895 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1897 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1898 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1899 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1900 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1902 (add-hook 'org-mode-hook 'my-org-mode-setup)
1904 (defun org-mode-reftex-search ()
1906 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1908 (defun open-research-paper (bibtexkey)
1909 "Open a paper by bibtex key"
1910 (interactive "bibtex key: ")
1913 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1914 (org-add-link-type "papers" 'open-research-paper)
1915 (defun open-research-paper-pdf (bibtexkey)
1916 "Open a paper pdf by bibtex key"
1917 (interactive "bibtex key: ")
1919 (format "%s -p evince_annot %s"
1920 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1921 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1923 (add-to-list 'org-link-abbrev-alist
1925 "~/projects/research/paper_notes.org::#%s"))
1927 ; I pretty much always want hiearchical checkboxes
1928 (setq org-hierachical-checkbox-statistics nil)
1930 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1931 (add-to-list 'org-structure-template-alist
1932 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1935 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1936 (defun my-rtcite-export-handler (path desc format)
1937 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1938 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1939 (match-string 1 path)))
1940 (path (substring path 0 (match-beginning 0))))
1941 (cond ((eq format 'latex)
1943 (equal 0 (search "rtcite:" desc)))
1944 (format "\\cite{%s}" search)
1945 (format "\\cite[%s]{%s}" desc search))))))
1947 (org-add-link-type "rtcite"
1949 'my-rtcite-export-handler)
1953 ** Org Mobile Configuration
1954 #+BEGIN_SRC emacs-lisp
1955 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1956 (when (string= system-name "linnode")
1957 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1958 (setq-default org-directory "/home/don/org-mode/")
1959 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1963 #+BEGIN_SRC emacs-lisp
1964 ;; org mode ical export
1965 (setq org-icalendar-timezone "America/Los_Angeles")
1966 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1967 ;; we already add the id manually
1968 (setq org-icalendar-store-UID t)
1971 ** General Org Babel Configuration
1972 #+BEGIN_SRC emacs-lisp
1973 ;; org babel support
1974 (org-babel-do-load-languages
1975 'org-babel-load-languages
1982 ;; set the right path to ditaa.jar
1983 (setq org-ditaa-jar-path "/usr/share/ditaa/ditaa.jar")
1984 ;; use graphviz-dot for dot things
1985 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1986 ;; do not indent begin_src blocks
1987 (setq org-edit-src-content-indentation 0)
1988 ;; org-babel-by-backend
1989 (defmacro org-babel-by-backend (&rest body)
1990 `(case (if (boundp 'backend)
1991 (org-export-backend-name backend)
1994 (defun my/fix-inline-images ()
1995 (when org-inline-image-overlays
1996 (org-redisplay-inline-images)))
1998 (add-hook 'org-babel-after-execute-hook
1999 'my/fix-inline-images)
2002 ** LaTeX configuration
2004 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
2006 #+BEGIN_SRC emacs-lisp
2007 (use-package ox-extra
2009 (ox-extras-activate '(ignore-headlines)))
2011 (add-to-list 'org-latex-classes
2013 "\\documentclass[11pt,oneside,article]{memoir}\n"
2014 ("\\section{%s}" . "\\section*{%s}")
2015 ("\\subsection{%s}" . "\\subsection*{%s}")
2016 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2017 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2018 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2020 (setq org-beamer-outline-frame-options "")
2021 (add-to-list 'org-latex-classes
2023 "\\documentclass[ignorenonframetext]{beamer}
2024 [NO-DEFAULT-PACKAGES]
2027 ("\\section{%s}" . "\\section*{%s}")
2028 ("\\subsection{%s}" . "\\subsection*{%s}")
2029 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2030 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2031 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2033 (add-to-list 'org-latex-classes
2035 "\\documentclass[11pt,oneside]{memoir}\n"
2036 ("\\chapter{%s}" . "\\chapter*{%s}")
2037 ("\\section{%s}" . "\\section*{%s}")
2038 ("\\subsection{%s}" . "\\subsection*{%s}")
2039 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
2041 (add-to-list 'org-latex-classes
2043 "\\documentclass[11pt]{letter}
2044 [NO-DEFAULT-PACKAGES]
2047 ("\\section{%s}" . "\\section*{%s}")
2048 ("\\subsection{%s}" . "\\subsection*{%s}")
2049 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2050 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2051 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2053 (add-to-list 'org-latex-classes
2055 "\\documentclass{dlacv}
2056 [NO-DEFAULT-PACKAGES]
2059 ("\\section{%s}" . "\\section*{%s}")
2060 ("\\subsection{%s}" . "\\subsection*{%s}")
2061 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2062 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2063 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2066 (add-to-list 'org-latex-classes
2068 "\\documentclass{dlaresume}
2069 [NO-DEFAULT-PACKAGES]
2072 ("\\section{%s}" . "\\section*{%s}")
2073 ("\\subsection{%s}" . "\\subsection*{%s}")
2074 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2075 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2076 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2079 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
2080 ;; but adapted to use latexmk 4.22 or higher.
2081 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
2083 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
2084 (setq org-latex-default-packages-alist
2086 ("" "unicode-math" t)
2088 (setq org-latex-packages-alist
2095 ("" "longtable" nil)
2098 ;; make equations larger
2099 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2101 (defun org-create-formula--latex-header ()
2102 "Return LaTeX header appropriate for previewing a LaTeX snippet."
2103 (let ((info (org-combine-plists (org-export--get-global-options
2104 (org-export-get-backend 'latex))
2105 (org-export--get-inbuffer-options
2106 (org-export-get-backend 'latex)))))
2107 (org-latex-guess-babel-language
2108 (org-latex-guess-inputenc
2109 (org-splice-latex-header
2110 org-format-latex-header
2111 org-latex-default-packages-alist
2113 (plist-get info :latex-header)))
2117 ; support ignoring headers in org mode export to latex
2118 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2119 (defadvice org-latex-headline (around my-latex-skip-headlines
2120 (headline contents info) activate)
2121 (if (member "ignoreheading" (org-element-property :tags headline))
2122 (setq ad-return-value contents)
2125 ;; keep latex logfiles
2127 (setq org-latex-remove-logfiles nil)
2129 ;; Resume clocking task when emacs is restarted
2130 (org-clock-persistence-insinuate)
2132 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2133 (setq org-clock-history-length 23)
2134 ;; Resume clocking task on clock-in if the clock is open
2135 (setq org-clock-in-resume t)
2136 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2137 ;; there are things like PHONE calls
2138 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2139 ;; Separate drawers for clocking and logs
2140 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2141 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2142 (setq org-clock-into-drawer t)
2143 (setq org-log-into-drawer t)
2144 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2145 (setq org-clock-out-remove-zero-time-clocks t)
2146 ;; Clock out when moving task to a done state
2147 (setq org-clock-out-when-done t)
2148 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2149 (setq org-clock-persist t)
2150 ;; Do not prompt to resume an active clock
2151 (setq org-clock-persist-query-resume nil)
2152 ;; Enable auto clock resolution for finding open clocks
2153 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2154 ;; Include current clocking task in clock reports
2155 (setq org-clock-report-include-clocking-task t)
2157 ;; the cache seems to be broken
2158 (setq org-element-use-cache nil)
2160 (defvar bh/keep-clock-running nil)
2162 (defun bh/is-task-p ()
2163 "Any task with a todo keyword and no subtask"
2167 (subtree-end (save-excursion (org-end-of-subtree t)))
2168 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2171 (while (and (not has-subtask)
2172 (< (point) subtree-end)
2173 (re-search-forward "^\*+ " subtree-end t))
2174 (when (member (org-get-todo-state) org-todo-keywords-1)
2175 (setq has-subtask t))))
2176 (and is-a-task (not has-subtask)))))
2177 (defun bh/is-project-p ()
2178 "Any task with a todo keyword subtask"
2182 (subtree-end (save-excursion (org-end-of-subtree t)))
2183 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2186 (while (and (not has-subtask)
2187 (< (point) subtree-end)
2188 (re-search-forward "^\*+ " subtree-end t))
2189 (when (member (org-get-todo-state) org-todo-keywords-1)
2190 (setq has-subtask t))))
2191 (and is-a-task has-subtask))))
2193 (defun bh/is-subproject-p ()
2194 "Any task which is a subtask of another project"
2195 (let ((is-subproject)
2196 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2198 (while (and (not is-subproject) (org-up-heading-safe))
2199 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2200 (setq is-subproject t))))
2201 (and is-a-task is-subproject)))
2204 (defun bh/clock-in-to-next (kw)
2205 "Switch a task from TODO to NEXT when clocking in.
2206 Skips capture tasks, projects, and subprojects.
2207 Switch projects and subprojects from NEXT back to TODO"
2208 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2210 ((and (member (org-get-todo-state) (list "TODO"))
2213 ((and (member (org-get-todo-state) (list "NEXT"))
2217 (defun bh/punch-in (arg)
2218 "Start continuous clocking and set the default task to the
2219 selected task. If no task is selected set the Organization task
2220 as the default task."
2222 (setq bh/keep-clock-running t)
2223 (if (equal major-mode 'org-agenda-mode)
2225 ;; We're in the agenda
2227 (let* ((marker (org-get-at-bol 'org-hd-marker))
2228 (tags (org-with-point-at marker (org-get-tags-at))))
2229 (if (and (eq arg 4) tags)
2230 (org-agenda-clock-in '(16))
2231 (bh/clock-in-organization-task-as-default)))
2233 ;; We are not in the agenda
2237 ; Find the tags on the current task
2238 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2239 (org-clock-in '(16))
2240 (bh/clock-in-organization-task-as-default)))))
2242 (defun bh/punch-out ()
2244 (setq bh/keep-clock-running nil)
2245 (when (org-clock-is-active)
2247 (org-agenda-remove-restriction-lock))
2249 (defun bh/clock-in-default-task ()
2251 (org-with-point-at org-clock-default-task
2254 (defun bh/clock-in-parent-task ()
2255 "Move point to the parent (project) task if any and clock in"
2256 (let ((parent-task))
2260 (while (and (not parent-task) (org-up-heading-safe))
2261 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2262 (setq parent-task (point))))
2264 (org-with-point-at parent-task
2266 (when bh/keep-clock-running
2267 (bh/clock-in-default-task)))))))
2269 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2271 (defun bh/clock-in-organization-task-as-default ()
2273 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2274 (org-clock-in '(16))))
2276 (defun bh/clock-out-maybe ()
2277 (when (and bh/keep-clock-running
2278 (not org-clock-clocking-in)
2279 (marker-buffer org-clock-default-task)
2280 (not org-clock-resolving-clocks-due-to-idleness))
2281 (bh/clock-in-parent-task)))
2283 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2286 (defun bh/clock-in-task-by-id (id)
2287 "Clock in a task by id"
2288 (org-with-point-at (org-id-find id 'marker)
2289 (org-clock-in nil)))
2291 (defun bh/clock-in-last-task (arg)
2292 "Clock in the interrupted task if there is one
2293 Skip the default task and get the next one.
2294 A prefix arg forces clock in of the default task."
2296 (let ((clock-in-to-task
2298 ((eq arg 4) org-clock-default-task)
2299 ((and (org-clock-is-active)
2300 (equal org-clock-default-task (cadr org-clock-history)))
2301 (caddr org-clock-history))
2302 ((org-clock-is-active) (cadr org-clock-history))
2303 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2304 (t (car org-clock-history)))))
2306 (org-with-point-at clock-in-to-task
2307 (org-clock-in nil))))
2310 (defun org-export-to-ods ()
2312 (let ((csv-file "data.csv"))
2313 (org-table-export csv-file "orgtbl-to-csv")
2314 (org-odt-convert csv-file "ods" 'open)))
2316 ; allow for zero-width-space to be a break in regexp too
2317 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
2318 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
2319 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2321 ;; support inserting screen shots
2322 (defun my/org-insert-screenshot ()
2323 "Take a screenshot into a time stamped unique-named file in the
2324 same directory as the org-buffer and insert a link to this file."
2326 (defvar my/org-insert-screenshot/filename)
2327 (setq my/org-insert-screenshot/filename
2329 "Screenshot to insert: "
2331 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2334 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2335 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2336 (org-display-inline-images))
2338 (defun my/fix-inline-images ()
2339 (when org-inline-image-overlays
2340 (org-redisplay-inline-images)))
2342 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2344 ;; use xelatex to preview with imagemagick
2345 (add-to-list 'org-preview-latex-process-alist
2346 '(xelateximagemagick
2347 :programs ("xelatex" "convert")
2348 :description "pdf > png"
2349 :message "you need to install xelatex and imagemagick"
2351 :image-input-type "pdf"
2352 :image-output-type "png"
2353 :image-size-adjust (1.0 . 1.0)
2354 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2355 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2357 ;; use xelatex by default
2358 (setq org-preview-latex-default-process 'xelateximagemagick)
2360 ; from http://orgmode.org/Changes.html
2361 (defun my/org-repair-property-drawers ()
2362 "Fix properties drawers in current buffer.
2363 Ignore non Org buffers."
2365 (when (eq major-mode 'org-mode)
2366 (org-with-wide-buffer
2367 (goto-char (point-min))
2368 (let ((case-fold-search t)
2369 (inline-re (and (featurep 'org-inlinetask)
2370 (concat (org-inlinetask-outline-regexp)
2374 (unless (and inline-re (org-looking-at-p inline-re))
2376 (let ((end (save-excursion (outline-next-heading) (point))))
2378 (when (org-looking-at-p org-planning-line-re) (forward-line))
2379 (when (and (< (point) end)
2380 (not (org-looking-at-p org-property-drawer-re))
2382 (and (re-search-forward org-property-drawer-re end t)
2383 (eq (org-element-type
2384 (save-match-data (org-element-at-point)))
2386 (insert (delete-and-extract-region
2388 (min (1+ (match-end 0)) end)))
2389 (unless (bolp) (insert "\n"))))))))))))
2393 #+BEGIN_SRC emacs-lisp
2397 (use-package calfw-org
2400 (use-package org-gcal
2401 :if (file-readable-p "~/.hide/org_gcal.el")
2403 :config '((if (file-readable-p "~/.hide/org_gcal.el")
2404 (load-file "~/.hide/org_gcal.el"))
2409 #+BEGIN_SRC emacs-lisp
2413 ;; Show notification 10 minutes before event
2414 (setq appt-message-warning-time 10)
2415 ;; Disable multiple reminders
2416 (setq appt-display-interval appt-message-warning-time)
2417 (setq appt-display-mode-line nil)
2419 ;; add automatic reminders for appointments
2420 (defun my/org-agenda-to-appt ()
2422 (setq appt-time-msg-list nil)
2423 (org-agenda-to-appt))
2424 ;; add reminders when starting emacs
2425 (my/org-agenda-to-appt)
2426 ;; when rebuilding the agenda
2427 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
2428 "Pressing `r' on the agenda will also add appointments."
2429 (my/org-agenda-to-appt)
2431 ;; when saving all org buffers
2432 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2433 "Re-add appts after saving all org buffers"
2434 (my/org-agenda-to-appt))
2435 ;; Display appointments as a window manager notification
2436 (setq appt-disp-window-function 'my/appt-display)
2437 (setq appt-delete-window-function (lambda () t))
2439 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2441 (defun my/appt-display (min-to-app new-time msg)
2442 (if (atom min-to-app)
2443 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2444 (dolist (i (number-sequence 0 (1- (length min-to-app))))
2445 (start-process "my/appt-notification-app" nil my/appt-notification-app
2446 (nth i min-to-app) (nth i msg))))
2452 ** outshine (outlining) integration
2453 #+BEGIN_SRC emacs-lisp
2454 (use-package outshine
2456 :hook (outline-minor-mode . outshine-hook-function)
2460 #+BEGIN_SRC emacs-lisp
2465 #+BEGIN_SRC emacs-lisp
2466 (global-unset-key "\M-g")
2467 (global-set-key (kbd "M-g l") 'goto-line)
2471 #+BEGIN_SRC emacs-lisp
2472 (use-package debian-changelog-mode
2473 :mode "debian/changelog"
2475 (setq debian-changelog-mailing-address "don@debian.org")
2476 (setq debian-changelog-full-name "Don Armstrong"))
2478 * Misc (uncharacterized)
2479 #+BEGIN_SRC emacs-lisp
2480 (setq calendar-latitude 38.6)
2481 (setq calendar-longitude -121.5)
2482 (setq case-fold-search t)
2483 (setq confirm-kill-emacs (quote y-or-n-p))
2484 (setq cperl-lazy-help-time nil)
2486 ** Turn on fontlock and icomplete
2487 #+BEGIN_SRC emacs-lisp
2488 (global-font-lock-mode 1)
2490 (setq log-edit-keep-buffer t)
2492 ** Set mail User agent
2493 #+BEGIN_SRC emacs-lisp
2494 (setq mail-user-agent (quote sendmail-user-agent))
2495 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2498 #+BEGIN_SRC emacs-lisp
2499 (setq ps-footer-font-size (quote (8 . 10)))
2500 (setq ps-header-font-size (quote (8 . 10)))
2501 (setq ps-header-title-font-size (quote (10 . 10)))
2502 (setq ps-line-number-color "blue")
2503 (setq ps-print-footer t)
2504 (setq ps-print-footer-frame nil)
2505 (setq ps-print-only-one-header t)
2507 ** Only single spacing on sentences
2508 #+BEGIN_SRC emacs-lisp
2509 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
2511 (setq sentence-end-double-space nil)
2512 ; enable matching parenthesis
2514 ** Display paren mode
2515 #+BEGIN_SRC emacs-lisp
2517 (setq show-paren-delay 0.2)
2519 (setq user-mail-address "don@donarmstrong.com")
2521 ;; switch back to the old primary selection method
2522 (setq x-select-enable-clipboard nil)
2523 (setq x-select-enable-primary t)
2524 ; (setq mouse-drag-copy-region t)
2526 (fset 'perl-mode 'cperl-mode)
2527 ;;(load-file "cperl-mode.el")
2529 ;; tramp configuration
2530 (setq tramp-use-ssh-controlmaster-options nil)
2532 (setq-default c-indent-level 4)
2533 (setq-default c-brace-imaginary-offset 0)
2534 (setq-default c-brace-offset -4)
2535 (setq-default c-argdecl-indent 4)
2536 (setq-default c-label-offset -4)
2537 (setq-default c-continued-statement-offset 4)
2539 (setq-default indent-tabs-mode nil)
2540 (setq-default tab-width 4)
2543 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2544 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2545 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2546 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2547 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2550 (defun insert-date ()
2551 "Insert date at point."
2553 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2554 (global-set-key "\C-[d" 'insert-date)
2556 (defun unfill-paragraph (arg)
2557 "Pull this whole paragraph up onto one line."
2559 (let ((fill-column 10000))
2560 (fill-paragraph arg))
2563 (column-number-mode t)
2566 ** Desktop-save-mode
2567 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2568 emacs, and use a different desktop file to restore history
2569 #+BEGIN_SRC emacs-lisp
2570 (use-package desktop
2573 (setq desktop-base-file-name
2574 (convert-standard-filename
2576 (or (getenv "EMACS_SERVER_NAME")
2580 (setq desktop-base-lock-name
2581 (convert-standard-filename
2582 (concat desktop-base-file-name
2584 (setq desktop-auto-save-timeout 60)
2585 (setq desktop-restore-eager 5)
2586 (setq desktop-lazy-verbose nil)
2587 (desktop-save-mode 1)
2591 ** Misc (Uncharacterized)
2592 #+BEGIN_SRC emacs-lisp
2593 '(icomplete-mode on)
2595 ;; custom-set-faces was added by Custom.
2596 ;; If you edit it by hand, you could mess it up, so be careful.
2597 ;; Your init file should contain only one such instance.
2598 ;; If there is more than one, they won't work right.
2599 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2602 (put 'upcase-region 'disabled nil)
2603 (put 'downcase-region 'disabled nil)
2604 (put 'narrow-to-region 'disabled nil)
2606 ; (defun turn-on-flyspell ()
2607 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2609 ; (flyspell-mode 1))
2612 ; Outline-minor-mode key map
2613 (define-prefix-command 'cm-map nil "Outline-")
2615 (define-key cm-map "q" 'outline-hide-sublevels) ; Hide everything but the top-level headings
2616 (define-key cm-map "t" 'outline-hide-body) ; Hide everything but headings (all body lines)
2617 (define-key cm-map "o" 'outline-hide-other) ; Hide other branches
2618 (define-key cm-map "c" 'outline-hide-entry) ; Hide this entry's body
2619 (define-key cm-map "l" 'outline-hide-leaves) ; Hide body lines in this entry and sub-entries
2620 (define-key cm-map "d" 'outline-hide-subtree) ; Hide everything in this entry and sub-entries
2622 (define-key cm-map "a" 'outline-show-all) ; Show (expand) everything
2623 (define-key cm-map "e" 'outline-show-entry) ; Show this heading's body
2624 (define-key cm-map "i" 'outline-show-children) ; Show this heading's immediate child sub-headings
2625 (define-key cm-map "k" 'outline-show-branches) ; Show all sub-headings under this heading
2626 (define-key cm-map "s" 'outline-show-subtree) ; Show (expand) everything in this heading & below
2628 (define-key cm-map "u" 'outline-up-heading) ; Up
2629 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2630 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2631 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2632 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2633 (global-set-key "\M-o" cm-map)
2634 ; fix up tmux xterm keys
2635 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2636 (defun fix-up-tmux-keys ()
2637 "Fix up tmux xterm keys"
2640 (let ((x 2) (tkey ""))
2660 ;; ctrl + alt + shift
2662 (setq tkey "C-M-S-"))
2665 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2666 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2667 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2668 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2670 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2672 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2674 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2676 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2678 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2680 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2682 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2684 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2686 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2688 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2690 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2692 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2694 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2696 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2698 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2700 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2702 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2704 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2706 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2708 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2710 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2712 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2714 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2716 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2718 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2720 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2727 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2729 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2730 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2731 (if (or (buffer-modified-p)
2732 (verify-visited-file-modtime)
2733 (< (* 8 1024 1024) (buffer-size))
2734 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2736 (clear-visited-file-modtime)
2738 (ad-activate 'ask-user-about-supersession-threat)
2742 #+BEGIN_SRC emacs-lisp
2746 (or (getenv "EMACS_SERVER_NAME")
2748 (unless (server-running-p)
2749 (global-set-key "\C-xp" 'server-edit)
2756 #+BEGIN_SRC emacs-lisp
2757 (provide 'don-configuration)