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 'exec-path '"/usr/local/bin")
89 (add-to-list 'exec-path '"~/bin/")
93 #+BEGIN_SRC emacs-lisp
94 (add-to-list 'load-path '"~/lib/emacs_el/")
95 (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
98 #+BEGIN_SRC emacs-lisp
99 ;; Set the custom file to /dev/null and don't bother to load it
100 (setq custom-file "/dev/null")
104 #+BEGIN_SRC emacs-lisp
105 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
106 ;; execute conditional code when loading libraries
107 (defmacro with-library (symbol &rest body)
108 `(when (require ,symbol nil t)
110 (put 'with-library 'lisp-indent-function 1)
114 ** Safe Local Variables
115 #+BEGIN_SRC emacs-lisp
116 (setq safe-local-variable-values
117 (quote ((auto-save-default)
119 (cperl-indent-level . 4)
121 (indent-tabs-mode . f)
122 (vcl-indent-level . 4)
126 #+BEGIN_SRC emacs-lisp
127 (setq global-mark-ring-max 128
131 (defun don/minibuffer-setup-hook ()
132 (setq gc-cons-threshold most-positive-fixnum))
134 (defun don/minibuffer-exit-hook ()
135 (setq gc-cons-threshold 1048576))
137 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
138 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
142 #+BEGIN_SRC emacs-lisp
143 (use-package spacemacs-common
144 :ensure spacemacs-theme
146 (load-theme 'spacemacs-dark t)
150 #+BEGIN_SRC emacs-lisp
151 (use-package hippie-exp
152 :bind* (("M-<SPC>" . hippie-expand))
156 #+BEGIN_SRC emacs-lisp
157 (use-package flyspell
159 :diminish flyspell-mode 🐝
161 (add-hook 'text-mode-hook 'turn-on-flyspell)
162 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
163 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
164 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
166 (setq ispell-program-name "ispell")
171 #+begin_src emacs-lisp :tangle yes
177 #+BEGIN_SRC emacs-lisp
182 #+BEGIN_SRC emacs-lisp
183 (use-package eyebrowse
185 :diminish eyebrowse-mode
186 :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
188 (setq eyebrowse-wrap-around t)
191 (defun my/eyebrowse-new-window-config ()
195 ;; start at 1 run till 0
196 (let ((j (mod (+ i 1) 10)))
197 (when (and (not done)
198 (not (eyebrowse--window-config-present-p j)))
199 (eyebrowse-switch-to-window-config j)
200 (call-interactively 'eyebrowse-rename-window-config2 j)
205 ;; I don't use latex-preview-pane
206 ;; (require 'latex-preview-pane)
207 ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
208 ;; ;; latex-preview-pane uses window-parameters which are
209 ;; ;; not preserved by eyebrowse, so we close the preview
210 ;; ;; pane before switching, it will be regenerated when we
211 ;; ;; edit the TeX file.
212 ;; (when (lpp/window-containing-preview)
213 ;; (delete-window (lpp/window-containing-preview))))
215 ;; (add-to-list 'eyebrowse-pre-window-switch-hook
216 ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
218 ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
219 ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
220 ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
221 ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
222 ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
230 #+BEGIN_SRC emacs-lisp
231 (defun my/vsplit-last-buffer ()
232 "Split the window vertically and display the previous buffer."
234 (split-window-vertically)
236 (switch-to-next-buffer))
238 (defun my/hsplit-last-buffer ()
239 "Split the window horizontally and display the previous buffer."
241 (split-window-horizontally)
243 (switch-to-next-buffer))
245 (bind-key "C-x 2" 'my/vsplit-last-buffer)
246 (bind-key "C-x 3" 'my/hsplit-last-buffer)
248 (setq split-width-threshold 100)
249 (setq split-height-threshold 60)
251 (defun my/split-window-prefer-vertically (window)
252 "If there's only one window (excluding any possibly active
253 minibuffer), then split the current window horizontally."
254 (if (and (one-window-p t)
255 (not (active-minibuffer-window))
256 ( < (frame-width) (frame-height))
258 (let ((split-width-threshold nil))
259 (split-window-sensibly window))
260 (split-window-sensibly window)))
262 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
263 (setq window-combination-resize t)
266 *** Compilation window
268 If there is no compilation window, open one at the bottom, spanning
269 the complete width of the frame. Otherwise, reuse existing window. In
270 the former case, if there was no error the window closes
273 #+BEGIN_SRC emacs-lisp
274 (add-to-list 'display-buffer-alist
275 `(,(rx bos "*compilation*" eos)
276 (display-buffer-reuse-window
277 display-buffer-in-side-window)
278 (reusable-frames . visible)
280 (window-height . 0.4)))
283 #+BEGIN_SRC emacs-lisp
284 (defun my/compilation-exit-autoclose (status code msg)
285 ;; If M-x compile exists with a 0
286 (when (and (eq status 'exit) (zerop code))
287 ;; and delete the *compilation* window
288 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
289 (when (and (not (window-at-side-p compilation-window 'top))
290 (window-at-side-p compilation-window 'left)
291 (window-at-side-p compilation-window 'right))
292 (delete-window compilation-window))))
293 ;; Always return the anticipated result of compilation-exit-message-function
296 ;; Specify my function (maybe I should have done a lambda function)
297 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
300 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
301 value, the compilation buffer scrolls automatically to follow the
302 output. If the value is ~first-error~, scrolling stops when the first
303 error appears, leaving point at that error. For any other non-nil
304 value, scrolling continues until there is no more output.
306 #+BEGIN_SRC emacs-lisp
307 (setq compilation-scroll-output 'first-error)
310 ** Mode line cleaning
312 #+BEGIN_SRC emacs-lisp
313 (use-package diminish
318 #+BEGIN_SRC emacs-lisp
325 #+BEGIN_SRC emacs-lisp
327 :if (>= emacs-major-version 25)
329 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
330 ("C-c j j" . avy-goto-word-or-subword-1)
331 ("M-g g" . avy-goto-line))
332 :config (progn (setq avy-background t))
335 *** Ace-link (jumping to links)
336 #+BEGIN_SRC emacs-lisp
337 (use-package ace-link
339 ; bind o in most modes
340 :config (ace-link-setup-default))
342 *** Jumping through edit points (goto-chg)
343 #+BEGIN_SRC emacs-lisp
344 (use-package goto-chg
346 :bind (("C-c j ," . goto-last-change)
347 ("C-c j ." . goto-last-change-reverse))
350 *** Jumping to bookmarks (visible bookmarks, bm)
351 #+BEGIN_SRC emacs-lisp
354 :bind (("C-c j b ." . bm-next)
355 ("C-c j b ," . bm-previous)
356 ("C-c j b SPC" . bm-toggle)))
361 #+BEGIN_SRC emacs-lisp
362 (use-package yasnippet
364 :diminish yas-minor-mode
367 (setq yas-verbosity 1)
368 (define-key yas-minor-mode-map (kbd "<tab>") nil)
369 (define-key yas-minor-mode-map (kbd "TAB") nil)
370 (define-key yas-minor-mode-map (kbd "<backtab>") nil)
371 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
372 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
373 (add-to-list 'hippie-expand-try-functions-list
374 'yas-hippie-try-expand)
380 #+BEGIN_SRC emacs-lisp
381 (use-package auto-yasnippet
383 :bind (("H-w" . aya-create)
389 #+BEGIN_SRC emacs-lisp
392 :bind (("M-/" . company-complete))
394 (setq company-echo-delay 0 ; remove blinking
395 company-show-numbers t ; show numbers for easy selection
396 company-selection-wrap-around t
397 company-require-match nil
398 company-dabbrev-ignore-case t
399 company-dabbrev-ignore-invisible t
400 company-dabbrev-other-buffers t
401 company-dabbrev-downcase nil
402 company-dabbrev-code-everywhere t
403 company-tooltip-align-annotations t
404 company-minimum-prefix-length 1
405 company-global-modes '(not)
406 company-lighter-base "(C)")
407 (global-company-mode 1)
408 :bind (:map company-active-map
409 ("C-n" . company-select-next)
410 ("C-p" . company-select-previous)
411 ("M-?" . company-show-doc-buffer)
412 ("M-." . company-show-location)
417 #+BEGIN_SRC emacs-lisp
418 (use-package company-c-headers
421 (defun malb/ede-object-system-include-path ()
422 "Return the system include path for the current buffer."
424 (ede-system-include-path ede-object)))
426 (setq company-c-headers-path-system
427 #'malb/ede-object-system-include-path)
429 (add-to-list 'company-backends #'company-c-headers)))
432 #+BEGIN_SRC emacs-lisp
433 (use-package company-anaconda
435 :config (add-to-list 'company-backends #'company-anaconda))
438 #+BEGIN_SRC emacs-lisp
439 (use-package company-plsense
444 #+BEGIN_SRC emacs-lisp
445 (use-package company-math
448 #+BEGIN_SRC emacs-lisp
449 (use-package company-auctex
452 (defun company-auctex-labels (command &optional arg &rest ignored)
453 "company-auctex-labels backend"
454 (interactive (list 'interactive))
456 (interactive (company-begin-backend 'company-auctex-labels))
457 (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
458 (candidates (company-auctex-label-candidates arg))))
460 (add-to-list 'company-backends
461 '(company-auctex-macros
462 company-auctex-environments
463 company-math-symbols-unicode
464 company-math-symbols-latex))
466 (add-to-list 'company-backends #'company-auctex-labels)
467 (add-to-list 'company-backends #'company-auctex-bibs)
471 #+BEGIN_SRC emacs-lisp
472 (use-package company-bibtex
478 #+BEGIN_SRC emacs-lisp
479 (use-package company-shell
482 (setq company-shell-modes '(sh-mode shell-mode))
483 (add-to-list 'company-backends 'company-shell)))
488 Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
490 *Note:* Do this at the end of =company-mode= config.
492 #+BEGIN_SRC emacs-lisp
493 (defvar malb/company-mode/enable-yas t
494 "Enable yasnippet for all backends.")
496 (defun malb/company-mode/backend-with-yas (backend)
497 (if (or (not malb/company-mode/enable-yas)
499 (member 'company-yasnippet backend)))
501 (append (if (consp backend) backend (list backend))
502 '(:with company-yasnippet))))
504 (setq company-backends
505 (mapcar #'malb/company-mode/backend-with-yas company-backends))
510 Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
512 #+BEGIN_SRC emacs-lisp
513 (defun malb/toggle-company-ispell ()
516 ((member '(company-ispell :with company-yasnippet) company-backends)
517 (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
518 (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
519 (message "company-ispell disabled"))
521 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
522 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
523 (message "company-ispell enabled!"))))
525 (defun malb/company-ispell-setup ()
526 ;; @see https://github.com/company-mode/company-mode/issues/50
527 (when (boundp 'company-backends)
528 (make-local-variable 'company-backends)
529 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
530 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
531 ;; https://github.com/redguardtoo/emacs.d/issues/473
532 (if (and (boundp 'ispell-alternate-dictionary)
533 ispell-alternate-dictionary)
534 (setq company-ispell-dictionary ispell-alternate-dictionary))))
539 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
541 2. This function then hopefully does what I want:
543 a. if a region is active, just indent
544 b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
545 c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
546 d. otherwise call whatever would have been called otherwise.
548 ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
550 #+BEGIN_SRC emacs-lisp
551 (defun malb/indent-fold-or-complete (&optional arg)
554 ;; if a region is active, indent
556 (indent-region (region-beginning)
558 ;; if the next char is space or eol, but prev char not whitespace
559 ((and (not (active-minibuffer-window))
562 (looking-back "[^[:space:]]")
563 (not (looking-back "^")))
565 (cond (company-mode (company-complete-common))
566 (auto-complete-mode (auto-complete))))
568 ;; no whitespace anywhere
569 ((and (not (active-minibuffer-window))
570 (looking-at "[^[:space:]]")
571 (looking-back "[^[:space:]]")
572 (not (looking-back "^")))
574 ((bound-and-true-p hs-minor-mode)
575 (save-excursion (end-of-line) (hs-toggle-hiding)))
576 ((bound-and-true-p outline-minor-mode)
577 (save-excursion (outline-cycle)))))
579 ;; by default just call whatever was bound
581 (let ((fn (or (if (current-local-map) (lookup-key (current-local-map) (kbd "TAB")))
582 'indent-for-tab-command)))
583 (if (not (called-interactively-p 'any))
585 (setq this-command fn)
586 (call-interactively fn))))))
588 (defun malb/toggle-fold ()
590 (cond ((eq major-mode 'org-mode)
591 (org-force-cycle-archived))
592 ((bound-and-true-p hs-minor-mode)
597 ((bound-and-true-p outline-minor-mode)
601 (bind-key "<tab>" #'malb/indent-fold-or-complete)
602 (bind-key "C-<tab>" #'malb/toggle-fold)
606 #+BEGIN_SRC emacs-lisp
608 (use-package tinyprocmail
609 :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
610 :mode (".procmailrc" . turn-on-tinyprocmail-mode)
615 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
618 :bind (("C-x g" . magit-status)
619 ("C-x C-g" . magit-status))
621 ;; refine diffs always (hilight words)
622 (setq magit-diff-refine-hunk nil)
624 (use-package magit-annex
626 :load-path "~/lib/emacs_el/magit-annex/"
628 (use-package magit-vcsh
634 #+BEGIN_SRC emacs-lisp
635 (use-package cperl-mode
638 ;; Use c-mode for perl .xs files
639 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
640 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
641 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
642 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
643 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
646 cperl-auto-newline nil
647 cperl-auto-newline-after-colon nil
648 cperl-continued-statement-offset 4
649 cperl-brace-offset -1
650 cperl-continued-brace-offset 0
651 cperl-label-offset -4
652 cperl-highlight-variables-indiscriminately t
653 cperl-electric-lbrace-space nil
654 cperl-indent-parens-as-block nil
655 cperl-close-paren-offset -1
656 cperl-tab-always-indent t)
657 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
662 #+BEGIN_SRC emacs-lisp
663 (use-package markdown-mode
665 :mode (("\\.md\\'" . markdown-mode)
666 ("\\.mdwn\\'" . markdown-mode)
667 ("README\\.md\\'" . gfm-mode)
670 (setq markdown-enable-math t)
671 (setq markdown-follow-wiki-link-on-enter nil)
672 (bind-key "M-." #'markdown-jump markdown-mode-map)
673 (add-hook 'markdown-mode-hook #'flyspell-mode)
674 (add-hook 'markdown-mode-hook #'outline-minor-mode)
675 (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
680 #+BEGIN_SRC emacs-lisp
681 ; load sql-indent when sql is loaded
683 :mode (("\\.sql\\'" . sql-mode))
685 (require sql-indent))
688 #+BEGIN_SRC emacs-lisp
690 :commands ediff ediff3
693 ;; ediff configuration
694 ;; don't use the multi-window configuration
695 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
698 ** Do the Right Thing Indenting
699 Attempts to automatically identify the right indentation for a file
700 #+BEGIN_SRC emacs-lisp
701 (use-package dtrt-indent
705 ** VCL --editing varnish configuration files
706 #+BEGIN_SRC emacs-lisp
707 (use-package vcl-mode
714 #+BEGIN_SRC emacs-lisp
715 (defun malb/helm-omni (&rest arg)
716 ;; just in case someone decides to pass an argument, helm-omni won't fail.
718 (unless helm-source-buffers-list
719 (setq helm-source-buffers-list
720 (helm-make-source "Buffers" 'helm-source-buffers)))
724 (if (projectile-project-p)
725 '(helm-source-projectile-buffers-list
726 helm-source-buffers-list)
727 '(helm-source-buffers-list)) ;; list of all open buffers
729 `(((name . "Virtual Workspace")
730 (candidates . ,(--map (cons (eyebrowse-format-slot it) (car it))
731 (eyebrowse--get 'window-configs)))
732 (action . (lambda (candidate)
733 (eyebrowse-switch-to-window-config candidate)))))
735 (if (projectile-project-p)
736 '(helm-source-projectile-recentf-list
738 '(helm-source-recentf)) ;; all recent files
740 ;; always make some common files easily accessible
741 ;;'(((name . "Common Files")
742 ;; (candidates . malb/common-file-targets)
743 ;; (action . (("Open" . (lambda (x) (find-file (eval x))))))))
745 '(helm-source-files-in-current-dir
747 helm-source-bookmarks
748 helm-source-buffer-not-found ;; ask to create a buffer otherwise
750 "*Helm all the things*"))
754 :bind (("M-x" . helm-M-x)
755 ("C-x C-f" . helm-find-files)
756 ("C-x b" . helm-buffers-list) ; malb/helm-omni)
757 ("C-x C-b" . helm-buffers-list) ; malb/helm-omni)
758 ("C-c <SPC>" . helm-all-mark-rings))
760 (require 'helm-config)
761 (require 'helm-for-files)
762 (require 'helm-bookmark)
765 (define-key global-map [remap find-file] 'helm-find-files)
766 (define-key global-map [remap occur] 'helm-occur)
767 (define-key global-map [remap list-buffers] 'helm-buffers-list)
768 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
769 (unless (boundp 'completion-in-region-function)
770 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
771 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
772 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
777 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
779 #+BEGIN_SRC emacs-lisp
780 (use-package helm-flx
783 ;; these are helm configs, but they kind of fit here nicely
784 (setq helm-M-x-fuzzy-match t
785 helm-bookmark-show-location t
786 helm-buffers-fuzzy-matching t
787 helm-completion-in-region-fuzzy-match t
788 helm-file-cache-fuzzy-match t
789 helm-imenu-fuzzy-match t
790 helm-mode-fuzzy-match t
791 helm-locate-fuzzy-match nil
793 helm-recentf-fuzzy-match nil
794 helm-semantic-fuzzy-match t)
798 #+BEGIN_SRC emacs-lisp
800 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
801 (defun malb/helm-swoop-pre-fill ()
802 (thing-at-point 'symbol))
803 (defvar malb/helm-swoop-ignore-major-mode "List of major modes to ignore for helm-swoop")
804 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
805 paradox-menu-mode doc-view-mode pdf-view-mode
806 mu4e-headers-mode org-mode markdown-mode latex-mode
807 ein:notebook-multilang-mode))
809 (defun malb/swoop-or-search ()
811 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
812 (memq major-mode malb/helm-swoop-ignore-major-mode))
816 (use-package helm-swoop
819 :bind (("C-c o" . helm-multi-swoop-org)
820 ("C-s" . malb/swoop-or-search)
821 ("C-M-s" . helm-multi-swoop-all))
824 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
825 helm-swoop-split-with-multiple-windows nil
826 helm-swoop-split-direction #'split-window-horizontally
827 helm-swoop-split-window-function 'helm-default-display-buffer
828 helm-swoop-speed-or-color t)
830 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
831 (defun malb/helm-swoop-C-s ()
833 (if (boundp 'helm-swoop-pattern)
834 (if (equal helm-swoop-pattern "")
835 (previous-history-element 1)
839 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
840 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
841 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
842 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
843 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
844 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
849 #+BEGIN_SRC emacs-lisp
852 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
853 helm-ag-command-option "--all-text"
854 helm-ag-insert-at-point 'symbol
855 helm-ag-fuzzy-match t
856 helm-ag-use-temp-buffer t
857 helm-ag-use-grep-ignore-list t
858 helm-ag-use-agignore t))
861 #+BEGIN_SRC emacs-lisp
862 (use-package helm-descbinds
864 :bind ("C-h b" . helm-descbinds)
865 :init (fset 'describe-bindings 'helm-descbinds))
869 #+BEGIN_SRC emacs-lisp
870 (use-package helm-c-yasnippet
872 :bind ("C-c h y" . helm-yas-complete)
874 (setq helm-yas-space-match-any-greedy t)))
877 #+BEGIN_SRC emacs-lisp
878 (use-package helm-org-rifle
881 (defun malb/helm-org-rifle-agenda-files (arg)
883 (let ((current-prefix-arg nil))
885 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
886 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
887 (t (helm-org-agenda-files-headings)))))))
890 This can be used to link things pretty quickly if necessary
891 #+BEGIN_SRC emacs-lisp
892 (use-package helm-google
894 :bind ("C-c h g" . helm-google)
896 (progn (add-to-list 'helm-google-actions
897 '("Copy URL" . (lambda (candidate)
899 (replace-regexp-in-string
900 "https://.*q=\\(.*\\)\&sa=.*"
906 (add-to-list 'helm-google-actions
907 '("Org Store Link" . (lambda (candidate)
908 (let ((title (car (split-string candidate "[\n]+")))
910 (replace-regexp-in-string
911 "https://.*q=\\(.*\\)\&sa=.*"
913 (push (list url title) org-stored-links))))
918 ** Projectile -- Project management
919 #+begin_src emacs-lisp
920 (use-package projectile
922 :bind (("<f5>" . projectile-compile-project)
923 ("<f6>" . next-error))
925 (use-package magit :ensure t)
926 (require 'helm-projectile)
929 (setq projectile-make-test-cmd "make check"
930 projectile-switch-project-action 'helm-projectile
931 projectile-mode-line '(:eval (format "»{%s}" (projectile-project-name))))
933 (projectile-global-mode)))
937 #+begin_src emacs-lisp
938 (use-package helm-projectile
941 (defvar malb/helm-source-file-not-found
942 (helm-build-dummy-source
947 'helm-projectile-sources-list
948 malb/helm-source-file-not-found t)
950 (helm-delete-action-from-source
951 "Grep in projects `C-s'"
952 helm-source-projectile-projects)
954 (helm-add-action-to-source
955 "Grep in projects `C-s'"
956 'helm-do-ag helm-source-projectile-projects 4)))
959 #+BEGIN_SRC emacs-lisp
962 :bind ("M-z" . avy-zap-up-to-char-dwim))
965 #+BEGIN_SRC emacs-lisp
967 :bind (("C-c 2" . my/hydra-orgmodes/body)
968 ("C-c @" . my/hydra-orgmodes/body)
969 ("C-c #" . my/hydra-outline/body)
970 ("C-c 3" . my/hydra-outline/body)
973 (defhydra my/hydra-orgmodes (:color blue :hint nil)
975 _n_: notes _c_: chaim _w_: wildman _o_: ool
976 _u_: uddin _s_: steve _r_: refile _f_: fh
977 _p_: read papers _R_: paper notes
982 ("n" (find-file "~/projects/org-notes/notes.org"))
983 ("c" (find-file "~/projects/org-notes/chaim.org"))
984 ("w" (find-file "~/projects/org-notes/wildman.org"))
985 ("u" (find-file "~/projects/org-notes/uddin.org"))
986 ("o" (find-file "~/projects/org-notes/ool.org"))
987 ("f" (find-file "~/projects/org-notes/fh.org"))
988 ("s" (find-file "~/projects/org-notes/sndservers.org"))
989 ("r" (find-file my/org-refile-file))
990 ("p" (find-file "~/projects/research/papers_to_read.org"))
991 ("R" (find-file "~/projects/research/paper_notes.org"))
992 ("h" (find-file "~/projects/org-notes/hpcbio.org"))
997 ;; from https://github.com/abo-abo/hydra/wiki/Emacs
998 (defhydra my/hydra-outline (:color pink :hint nil)
1001 ^^^^^^------------------------------------------------------
1002 _q_: sublevels _a_: all _u_: up
1003 _t_: body _e_: entry _n_: next visible
1004 _o_: other _i_: children _p_: previous visible
1005 _c_: entry _k_: branches _f_: forward same level
1006 _l_: leaves _s_: subtree _b_: backward same level
1011 ("q" outline-hide-sublevels) ; Hide everything but the top-level headings
1012 ("t" outline-hide-body) ; Hide everything but headings (all body lines)
1013 ("o" outline-hide-other) ; Hide other branches
1014 ("c" outline-hide-entry) ; Hide this entry's body
1015 ("l" outline-hide-leaves) ; Hide body lines in this entry and sub-entries
1016 ("d" outline-hide-subtree) ; Hide everything in this entry and sub-entries
1018 ("a" outline-show-all) ; Show (expand) everything
1019 ("e" outline-show-entry) ; Show this heading's body
1020 ("i" outline-show-children) ; Show this heading's immediate child sub-headings
1021 ("k" outline-show-branches) ; Show all sub-headings under this heading
1022 ("s" outline-show-subtree) ; Show (expand) everything in this heading & below
1024 ("u" outline-up-heading) ; Up
1025 ("n" outline-next-visible-heading) ; Next
1026 ("p" outline-previous-visible-heading) ; Previous
1027 ("f" outline-forward-same-level) ; Forward - same level
1028 ("b" outline-backward-same-level) ; Backward - same level
1034 #+BEGIN_SRC emacs-lisp
1037 (add-to-list 'tramp-methods '("vcsh"
1038 (tramp-login-program "vcsh")
1042 (tramp-remote-shell "/bin/sh")
1043 (tramp-remote-shell-args
1047 #+BEGIN_SRC emacs-lisp
1051 (setq-default reftex-default-bibliography
1052 '("~/projects/research/references.bib")))
1055 #+BEGIN_SRC emacs-lisp
1057 :config (setq bibtex-user-optional-fields
1058 (quote (("annote" "Personal annotation (ignored)")
1066 #+BEGIN_SRC emacs-lisp
1071 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1072 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1073 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1074 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
1075 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
1076 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1077 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1078 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
1079 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
1080 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
1081 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
1083 (setq-default reftex-plug-into-AUCTeX t)
1084 ;; support fake section headers
1085 (setq TeX-outline-extra
1089 ("%subsubsection" 4)
1091 ;; add font locking to the headers
1092 (font-lock-add-keywords
1094 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1095 0 'font-lock-keyword-face t)
1096 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
1097 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
1098 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
1099 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1100 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
1102 ;; use smart quotes by default instead of `` and ''
1103 ;; taken from http://kieranhealy.org/esk/kjhealy.html
1104 (setq TeX-open-quote "“")
1105 (setq TeX-close-quote "”")
1107 ;; (TeX-add-style-hook
1112 ;; (custom-set-variables
1113 ;; '(font-latex-user-keyword-classes
1116 ;; font-lock-function-name-face 2 (command 1 t))))
1118 (setq-default TeX-parse-self t)
1119 (setq-default TeX-auto-save t)
1120 (setq-default TeX-master nil)
1121 (add-to-list 'LaTeX-font-list
1122 '(?\C-a "\\alert{","}"))
1125 '(TeX-add-style-hook
1128 (if (boundp 'reftex-ref-style-alist)
1130 'reftex-ref-style-alist
1131 '("Cleveref" "cleveref"
1132 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1133 (reftex-ref-style-activate "Cleveref")
1135 '("cref" TeX-arg-ref)
1136 '("Cref" TeX-arg-ref)
1137 '("cpageref" TeX-arg-ref)
1138 '("Cpageref" TeX-arg-ref)))))
1141 '(add-to-list 'LaTeX-fill-excluded-macros
1144 (use-package font-latex
1146 (setq font-latex-match-reference-keywords
1168 (setq font-latex-fontify-script nil)
1169 (setq font-latex-fontify-sectioning (quote color))
1170 (setq font-latex-script-display (quote (nil)))
1175 #+BEGIN_SRC emacs-lisp
1179 :mode ("\\.R\\'" . ess-r-mode)
1180 :bind (:map ess-mode-map
1181 ("C-c C-R" . dla/ess-region-remote-eval))
1183 (autoload 'ess-r-mode "ess-site" nil t)
1184 (autoload 'R "ess-site" nil t)
1186 ; actually load the rest of ess
1188 (defun ess-change-directory (path)
1189 "Set the current working directory to PATH for both *R* and Emacs."
1190 (interactive "Directory to change to: ")
1192 (when (file-exists-p path)
1193 (ess-command (concat "setwd(\"" path "\")\n"))
1194 ;; use file-name-as-directory to ensure it has trailing /
1195 (setq default-directory (file-name-as-directory path))))
1196 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1197 ;; outlining support for ess modes
1201 (outline-minor-mode)
1202 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1203 (defun outline-level ()
1204 (cond ((looking-at "^##### ") 1)
1205 ((looking-at "^#### ") 2)
1206 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1209 (defun dla/ess-region-remote-eval (start end)
1210 "Evaluate region in a remote ESS instance"
1212 (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***") nil nil nil)
1213 (kill-buffer "***essregionremoteeval***"))
1214 ;; Don't restore history or save workspace image
1215 '(inferior-R-args "--no-restore-history --no-save")
1220 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1222 #+BEGIN_SRC emacs-lisp
1223 (use-package rainbow-mode
1224 ;; add ess to the x major mode
1225 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1226 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1231 #+BEGIN_SRC emacs-lisp
1232 (use-package yaml-mode
1233 ;; add ess to the x major mode
1234 :mode ("\\.\\(yaml|yml\\)\\'" . yaml-mode)
1239 #+BEGIN_SRC emacs-lisp
1240 (use-package poly-noweb
1245 (use-package poly-markdown
1251 :after (:all polymode poly-markdown poly-noweb)
1252 ; :mode ("\\.Snw" . poly-noweb+r-mode)
1253 ; :mode ("\\.Rnw" . poly-noweb+r-mode)
1254 ; :mode ("\\.Rmd" . poly-markdown+r-mode)
1256 (use-package polymode
1264 #+BEGIN_SRC emacs-lisp
1265 (use-package outline-magic)
1268 #+BEGIN_SRC emacs-lisp
1269 ;; change the outline mode prefix from C-c @ to C-c C-2
1270 (setq outline-minor-mode-prefix "C-c C-2")
1271 ;;(add-hook 'outline-minor-mode-hook
1272 ;; (lambda () (local-set-key (kbd "C-c C-2")
1273 ;; outline-mode-prefix-map)))
1277 #+BEGIN_SRC emacs-lisp
1278 (use-package writeroom-mode
1280 (defun my/writing-mode ()
1281 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1286 (visual-line-mode -1)
1288 (visual-fill-column-mode -1)
1290 (visual-line-mode 1)
1292 (visual-fill-column-mode 1)
1297 ** GhostText/Atomic Chrome
1298 #+BEGIN_SRC emacs-lisp
1299 (use-package atomic-chrome
1301 (ignore-errors (atomic-chrome-start-server))
1302 (setq atomic-chrome-buffer-open-style 'full)
1307 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
1309 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1310 #+BEGIN_SRC emacs-lisp
1311 (use-package multiple-cursors
1312 :bind* (("C-;" . mc/mark-all-dwim)
1313 ("C-<" . mc/mark-previous-like-this)
1314 ("C->" . mc/mark-next-like-this)
1315 ("C-S-c C-S-c" . mc/edit-lines))
1319 #+BEGIN_SRC emacs-lisp
1320 (use-package web-mode
1321 :load-path "/home/don/projects/web-mode/"
1322 :mode ("\\.\\(tx|tmpl\\)\\'" . web-mode)
1324 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1325 (setq web-mode-enable-engine-detection t)
1326 (setq web-mode-engines-alist
1327 '(("template-toolkit" . "\\.tmpl\\'")))
1330 ** Spamassassin Mode
1331 #+BEGIN_SRC emacs-lisp
1332 (use-package spamassassin-mode
1333 :commands spamassassin-mode
1338 #+BEGIN_SRC emacs-lisp
1339 (use-package password-store
1341 :commands password-store-edit password-store-generate
1345 #+BEGIN_SRC emacs-lisp
1349 ;; fix up css mode to not be silly
1350 ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1351 (setq cssm-indent-level 4)
1352 (setq cssm-newline-before-closing-bracket t)
1353 (setq cssm-indent-function #'cssm-c-style-indenter)
1354 (setq cssm-mirror-mode nil))
1357 #+BEGIN_SRC emacs-lisp
1359 :diminish abbrev-mode
1361 ;; load abbreviations from
1362 (setq abbrev-file-name
1363 "~/.emacs_abbrev_def")
1365 ;; read the abbrev file if it exists
1366 (if (file-exists-p abbrev-file-name)
1367 (quietly-read-abbrev-file))
1369 ;; for now, use abbrev mode everywhere
1370 (setq default-abbrev-mode t))
1374 #+BEGIN_SRC emacs-lisp
1375 (use-package go-mode
1382 #+BEGIN_SRC emacs-lisp
1383 (use-package expand-region
1384 :bind (("C-=" . 'er/expand-region))
1389 #+BEGIN_SRC emacs-lisp
1390 (use-package dockerfile-mode
1396 #+BEGIN_SRC emacs-lisp
1397 (use-package beancount
1398 :load-path "~/lib/emacs_el/beancount-mode/"
1400 :mode "\\.beancount\\'"
1407 #+BEGIN_SRC emacs-lisp
1408 (use-package message
1410 :diminish (message "✉")
1411 :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1412 :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1413 :hook 'my/message-mode-settings
1414 :hook 'turn-on-flyspell
1415 :bind (:map message-mode-map
1416 ("C-c C-a" . my/post-attach-file))
1417 :delight (message-mode "✉")
1419 (defun my/message-mode-settings ()
1420 (font-lock-add-keywords nil
1421 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1422 (0 'message-multiply-quoted-text-face))
1423 ("^[ \t]*>[ \t]*>.*$"
1424 (0 'message-double-quoted-text-face))))
1427 (defun my/post-attach-file ()
1428 "Prompt for an attachment."
1430 (let ((file (read-file-name "Attach file: " nil nil t nil)))
1431 (my/header-attach-file file "")))
1433 (defun my/header-attach-file (file description)
1434 "Attach a FILE to the current message (works with Mutt).
1435 Argument DESCRIPTION MIME description."
1436 (interactive "fAttach file: \nsDescription: ")
1437 (when (> (length file) 0)
1442 (goto-char (point-min))
1443 (search-forward-regexp "^$")
1444 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1446 (message (concat "Attached '" file "'."))
1447 (setq post-has-attachment t))))))
1449 (setq mail-yank-prefix "> ")
1450 (setq mail-header-separator "") ; fix broken header detection
1454 #+BEGIN_SRC emacs-lisp
1455 (use-package muttrc-mode
1462 ** Reverting buffers
1463 #+BEGIN_SRC emacs-lisp
1464 (use-package autorevert
1465 :diminish auto-revert-mode
1467 (setq global-auto-revert-non-file-buffers t
1468 global-auto-revert-ignore-modes '(pdf-view-mode)
1469 auto-revert-verbose nil)
1470 (global-auto-revert-mode 1))
1473 ** Use-package and load things
1474 #+BEGIN_SRC emacs-lisp
1477 :delight (org-mode "ø")
1478 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1479 :bind (("C-c l" . org-store-link)
1480 ("C-c a" . org-agenda)
1481 ("C-c b" . org-iswitchb))
1483 ** Agenda Configuration
1484 #+BEGIN_SRC emacs-lisp
1486 (setq-default org-log-done 'time)
1487 (setq-default org-agenda-ndays 5)
1489 (setq org-agenda-sticky t)
1490 (defun dla/show-org-agenda ()
1495 (and (string-match-p
1503 (buffer-name agendabuffer))
1505 (delete-other-windows))
1507 ;; agenda configuration
1508 ;; Do not dim blocked tasks
1509 (setq org-agenda-dim-blocked-tasks nil)
1510 (setq org-agenda-inhibit-startup t)
1511 (setq org-agenda-use-tag-inheritance nil)
1513 ;; Compact the block agenda view
1514 (setq org-agenda-compact-blocks t)
1516 ;; Custom agenda command definitions
1517 (setq org-agenda-custom-commands
1518 (quote (("N" "Notes" tags "NOTE"
1519 ((org-agenda-overriding-header "Notes")
1520 (org-tags-match-list-sublevels t)))
1521 ("h" "Habits" tags-todo "STYLE=\"habit\""
1522 ((org-agenda-overriding-header "Habits")
1523 (org-agenda-sorting-strategy
1524 '(todo-state-down effort-up category-keep))))
1528 ((org-agenda-overriding-header "Tasks to Refile")
1529 (org-tags-match-list-sublevels nil)))
1530 (tags-todo "-CANCELLED/!"
1531 ((org-agenda-overriding-header "Stuck Projects")
1532 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1533 (org-agenda-sorting-strategy
1535 (tags-todo "-HOLD-CANCELLED/!"
1536 ((org-agenda-overriding-header "Projects")
1537 (org-agenda-skip-function 'bh/skip-non-projects)
1538 (org-tags-match-list-sublevels 'indented)
1539 (org-agenda-sorting-strategy
1541 (tags-todo "-CANCELLED/!NEXT"
1542 ((org-agenda-overriding-header (concat "Project Next Tasks"
1543 (if bh/hide-scheduled-and-waiting-next-tasks
1545 " (including WAITING and SCHEDULED tasks)")))
1546 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1547 (org-tags-match-list-sublevels t)
1548 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1549 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1550 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1551 (org-agenda-sorting-strategy
1552 '(todo-state-down effort-up category-keep))))
1553 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1554 ((org-agenda-overriding-header (concat "Project Subtasks"
1555 (if bh/hide-scheduled-and-waiting-next-tasks
1557 " (including WAITING and SCHEDULED tasks)")))
1558 (org-agenda-skip-function 'bh/skip-non-project-tasks)
1559 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1560 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1561 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1562 (org-agenda-sorting-strategy
1564 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1565 ((org-agenda-overriding-header (concat "Standalone Tasks"
1566 (if bh/hide-scheduled-and-waiting-next-tasks
1568 " (including WAITING and SCHEDULED tasks)")))
1569 (org-agenda-skip-function 'bh/skip-project-tasks)
1570 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1571 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1572 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1573 (org-agenda-sorting-strategy
1575 (tags-todo "-CANCELLED+WAITING|HOLD/!"
1576 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1577 (org-agenda-skip-function 'bh/skip-stuck-projects)
1578 (org-tags-match-list-sublevels nil)
1579 (org-agenda-todo-ignore-scheduled t)
1580 (org-agenda-todo-ignore-deadlines t)))
1582 ((org-agenda-overriding-header "Tasks to Archive")
1583 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1584 (org-tags-match-list-sublevels nil))))
1587 ; org mode agenda files
1588 (setq org-agenda-files
1590 (file-expand-wildcards "~/projects/org-notes/*.org")
1591 (file-expand-wildcards "~/org-mode/from-mobile.org")
1592 (file-expand-wildcards "~/org-notes-*/*.org")
1595 (setq my/org-refile-file
1597 (lambda (file) (string-match-p (regexp-quote "/refile.org") file))
1600 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1601 (set-register ?r (cons 'file my/org-refile-file))
1602 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1603 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1604 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1605 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1606 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1607 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1608 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1609 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1610 (defun org-agenda-timeline-all (&optional arg)
1613 (dolist (org-agenda-file org-agenda-files)
1614 (insert-file-contents org-agenda-file nil)
1615 (goto-char (point-max))
1617 (write-file "/tmp/timeline.org")
1618 (org-agenda arg "L")))
1619 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1623 #+BEGIN_SRC emacs-lisp
1624 (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")))
1625 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1627 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1628 (setq org-id-link-to-org-use-id 'use-existing)
1630 ** Capture Templates
1631 #+BEGIN_SRC emacs-lisp
1632 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1633 `(("m" "Mail" entry (file my/org-refile-file)
1634 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1635 ("t" "todo" entry (file my/org-refile-file)
1636 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1637 ("r" "respond" entry (file my/org-refile-file)
1638 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1639 ("n" "note" entry (file my/org-refile-file)
1640 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1641 ("s" "schedule" entry (file my/org-refile-file)
1642 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1643 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1644 "* %?\n%U\n" :clock-in t :clock-resume t)
1645 ("w" "org-protocol" entry (file my/org-refile-file)
1646 "* TODO Review %c\n%U\n" :immediate-finish t)
1647 ("M" "Meeting" entry (file my/org-refile-file)
1648 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1649 ("S" "Seminar" entry (file my/org-refile-file)
1650 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1651 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1652 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1653 ("p" "Phone call" entry (file my/org-refile-file)
1654 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1655 ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1657 ,(format-time-string "Positions %Y"))
1658 "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1659 ("h" "Habit" entry (file my/org-refile-file)
1660 "* 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")
1664 ;; Remove empty LOGBOOK drawers on clock out
1665 (defun bh/remove-empty-drawer-on-clock-out ()
1668 (beginning-of-line 0)
1669 (org-remove-empty-drawer-at (point))))
1671 (defun my/org-add-id ()
1674 (if (org-current-level)
1683 ** Org mode key bindings
1684 #+BEGIN_SRC emacs-lisp
1685 ;; org mode configuration from http://doc.norang.ca/org-mode.html
1686 ;; Custom Key Bindings
1687 :bind* (("<f9> a" . org-agenda)
1688 ("<f9> I" . bh/punch-in)
1689 ("<f9> O" . bh/punch-out)
1690 ("<f9> SPC" . bh/clock-in-last-task)
1691 ("<f12>" . dla/show-org-agenda)
1692 ;; ("<f5>" . bh/org-todo)
1693 ("<S-f5>" . bh/widen)
1694 ("<f7>" . bh/set-truncate-lines)
1695 ("<f8>" . org-cycle-agenda-files)
1696 ("<f9> <f9>" . dla/show-org-agenda)
1698 ("<f9> c" . calendar)
1699 ("<f9> f" . boxquote-insert-file)
1700 ("<f9> h" . bh/hide-other)
1701 ("<f9> n" . bh/toggle-next-task-display)
1704 ("<f9> r" . boxquote-region)
1705 ("<f9> s" . bh/switch-to-scratch)
1707 ("<f9> t" . bh/insert-inactive-timestamp)
1708 ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1710 ("<f9> v" . visible-mode)
1711 ("<f9> l" . org-toggle-link-display)
1712 ("<f9> SPC" . bh/clock-in-last-task)
1713 ("C-<f9>" . previous-buffer)
1714 ("M-<f9>" . org-toggle-inline-images)
1715 ("C-x n r" . narrow-to-region)
1716 ("C-<f10>" . next-buffer)
1717 ("<f11>" . org-clock-goto)
1718 ("C-<f11>" . org-clock-in)
1719 ("C-s-<f12>" . bh/save-then-publish)
1720 ("C-c c" . org-capture))
1723 ** Utility Functions
1724 #+BEGIN_SRC emacs-lisp
1725 (defun bh/hide-other ()
1728 (org-back-to-heading 'invisible-ok)
1734 (defun bh/set-truncate-lines ()
1735 "Toggle value of truncate-lines and refresh window display."
1737 (setq truncate-lines (not truncate-lines))
1738 ;; now refresh window display (an idiom from simple.el):
1740 (set-window-start (selected-window)
1741 (window-start (selected-window)))))
1743 (defun bh/switch-to-scratch ()
1745 (switch-to-buffer "*scratch*"))
1747 (setq org-use-fast-todo-selection t)
1748 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1750 ; create function to create headlines in file. This comes from
1751 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1752 (defun my/org-add-ids-to-headlines-in-file ()
1753 "Add ID properties to all headlines in the current file which
1754 do not already have one."
1756 (org-map-entries 'org-id-get-create))
1757 (defun dla/org-update-ids-to-headlines-in-file ()
1758 "Add or replace ID properties to all headlines in the current file
1759 (or narrowed region)."
1761 (org-map-entries '(lambda () (org-id-get-create t))))
1762 ; if we wanted to do this to every buffer, do the following:
1763 ; (add-hook 'org-mode-hook
1765 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1768 #+BEGIN_SRC emacs-lisp
1769 (use-package find-lisp
1771 (setq org-agenda-text-search-extra-files
1772 (append '(agenda-archives)
1773 (find-lisp-find-files "~/projects/org-notes" "\.org$")
1774 (find-lisp-find-files "~/projects/org-notes" "\.org_archive$")
1778 #+BEGIN_SRC emacs-lisp
1779 (setq org-todo-keywords
1780 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1781 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1783 (setq org-todo-keyword-faces
1784 (quote (("TODO" :foreground "red" :weight bold)
1785 ("NEXT" :foreground "blue" :weight bold)
1786 ("DONE" :foreground "forest green" :weight bold)
1787 ("WAITING" :foreground "orange" :weight bold)
1788 ("HOLD" :foreground "magenta" :weight bold)
1789 ("CANCELLED" :foreground "forest green" :weight bold)
1790 ("MEETING" :foreground "forest green" :weight bold)
1791 ("PHONE" :foreground "forest green" :weight bold))))
1793 (setq org-todo-state-tags-triggers
1794 (quote (("CANCELLED" ("CANCELLED" . t))
1795 ("WAITING" ("WAITING" . t))
1796 ("HOLD" ("WAITING") ("HOLD" . t))
1797 (done ("WAITING") ("HOLD"))
1798 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1799 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1800 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1804 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1805 ; add ids on creation of nodes
1806 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1809 ; resolve clocks after 10 minutes of idle; use xprintidle
1810 ; (setq org-clock-idle-time 10)
1811 ; (setq org-clock-x11idle-program-name "xprintidle")
1813 ; this is from http://doc.norang.ca/org-mode.html#Capture
1814 ; use C-M-r for org mode capture
1815 (global-set-key (kbd "C-M-r") 'org-capture)
1817 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1818 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1819 (org-agenda-files :maxlevel . 9))))
1821 ; Use full outline paths for refile targets - we file directly with IDO
1822 (setq org-refile-use-outline-path t)
1824 ; Targets complete directly with IDO
1825 (setq org-outline-path-complete-in-steps nil)
1827 ; Allow refile to create parent tasks with confirmation
1828 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1830 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1831 ; (setq org-completion-use-ido t)
1832 ; (setq ido-everywhere t)
1833 ; (setq ido-max-directory-size 100000)
1834 ; (ido-mode (quote both))
1835 ; ; Use the current window when visiting files and buffers with ido
1836 ; (setq ido-default-file-method 'selected-window)
1837 ; (setq ido-default-buffer-method 'selected-window)
1838 ; ; Use the current window for indirect buffer display
1839 ; (setq org-indirect-buffer-display 'current-window)
1842 ;;;; Refile settings
1843 ; Exclude DONE state tasks from refile targets
1844 (defun bh/verify-refile-target ()
1845 "Exclude todo keywords with a done state from refile targets"
1846 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1848 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1850 ;; ensure that emacsclient will show just the note to be edited when invoked
1851 ;; from Mutt, and that it will shut down emacsclient once finished;
1852 ;; fallback to legacy behavior when not invoked via org-protocol.
1853 (require 'org-protocol)
1854 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1855 (setq my-org-protocol-flag nil)
1856 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1857 "Delete frame at remember finalization"
1858 (progn (if my-org-protocol-flag (delete-frame))
1859 (setq my-org-protocol-flag nil)))
1860 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1861 "Delete frame at remember refile"
1862 (if my-org-protocol-flag
1864 (setq my-org-protocol-flag nil)
1869 (defadvice org-capture-kill (after delete-frame-at-end activate)
1870 "Delete frame at remember abort"
1871 (progn (if my-org-protocol-flag (delete-frame))
1872 (setq my-org-protocol-flag nil)))
1873 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1874 (setq my-org-protocol-flag t))
1876 (defadvice org-insert-todo-heading (after dla/create-id activate)
1877 (unless (org-in-item-p)
1883 (add-to-list 'org-modules 'org-habit)
1885 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1886 (defun open-mail-in-mutt (message)
1887 "Open a mail message in Mutt, using an external terminal.
1889 Message can be specified either by a path pointing inside a
1890 Maildir, or by Message-ID."
1891 (interactive "MPath or Message-ID: ")
1893 (format "faf xterm -e \"%s %s\""
1894 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1896 ;; add support for "mutt:ID" links
1897 (org-add-link-type "mutt" 'open-mail-in-mutt)
1899 (defun my-org-mode-setup ()
1900 ; (load-library "reftex")
1901 (and (buffer-file-name)
1902 (file-exists-p (buffer-file-name))
1904 ; (reftex-parse-all)
1905 (reftex-set-cite-format
1906 '((?b . "[[bib:%l][%l-bib]]")
1907 (?n . "[[notes:%l][%l-notes]]")
1909 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1911 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1912 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1913 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1914 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1916 (add-hook 'org-mode-hook 'my-org-mode-setup)
1918 (defun org-mode-reftex-search ()
1920 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1922 (defun open-research-paper (bibtexkey)
1923 "Open a paper by bibtex key"
1924 (interactive "bibtex key: ")
1927 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1928 (org-add-link-type "papers" 'open-research-paper)
1929 (defun open-research-paper-pdf (bibtexkey)
1930 "Open a paper pdf by bibtex key"
1931 (interactive "bibtex key: ")
1933 (format "%s -p evince_annot %s"
1934 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1935 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1937 (add-to-list 'org-link-abbrev-alist
1939 "~/projects/research/paper_notes.org::#%s"))
1941 ; I pretty much always want hiearchical checkboxes
1942 (setq org-hierachical-checkbox-statistics nil)
1944 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1945 (add-to-list 'org-structure-template-alist
1946 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1949 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1950 (defun my-rtcite-export-handler (path desc format)
1951 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1952 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1953 (match-string 1 path)))
1954 (path (substring path 0 (match-beginning 0))))
1955 (cond ((eq format 'latex)
1957 (equal 0 (search "rtcite:" desc)))
1958 (format "\\cite{%s}" search)
1959 (format "\\cite[%s]{%s}" desc search))))))
1961 (org-add-link-type "rtcite"
1963 'my-rtcite-export-handler)
1967 ** Org Mobile Configuration
1968 #+BEGIN_SRC emacs-lisp
1969 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1970 (when (string= system-name "linnode")
1971 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1972 (setq-default org-directory "/home/don/org-mode/")
1973 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1977 #+BEGIN_SRC emacs-lisp
1978 ;; org mode ical export
1979 (setq org-icalendar-timezone "America/Los_Angeles")
1980 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1981 ;; we already add the id manually
1982 (setq org-icalendar-store-UID t)
1985 ** General Org Babel Configuration
1986 #+BEGIN_SRC emacs-lisp
1987 ;; org babel support
1988 (org-babel-do-load-languages
1989 'org-babel-load-languages
1996 ;; set the right path to ditaa.jar
1997 (setq org-ditaa-jar-path "/usr/share/ditaa/ditaa.jar")
1998 ;; use graphviz-dot for dot things
1999 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
2000 ;; do not indent begin_src blocks
2001 (setq org-edit-src-content-indentation 0)
2002 ;; org-babel-by-backend
2003 (defmacro org-babel-by-backend (&rest body)
2004 `(case (if (boundp 'backend)
2005 (org-export-backend-name backend)
2008 (defun my/fix-inline-images ()
2009 (when org-inline-image-overlays
2010 (org-redisplay-inline-images)))
2012 (add-hook 'org-babel-after-execute-hook
2013 'my/fix-inline-images)
2016 ** LaTeX configuration
2018 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
2020 #+BEGIN_SRC emacs-lisp
2021 (use-package ox-extra
2023 (ox-extras-activate '(ignore-headlines)))
2025 (add-to-list 'org-latex-classes
2027 "\\documentclass[11pt,oneside,article]{memoir}\n"
2028 ("\\section{%s}" . "\\section*{%s}")
2029 ("\\subsection{%s}" . "\\subsection*{%s}")
2030 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2031 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2032 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2034 (setq org-beamer-outline-frame-options "")
2035 (add-to-list 'org-latex-classes
2037 "\\documentclass[ignorenonframetext]{beamer}
2038 [NO-DEFAULT-PACKAGES]
2041 ("\\section{%s}" . "\\section*{%s}")
2042 ("\\subsection{%s}" . "\\subsection*{%s}")
2043 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2044 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2045 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2047 (add-to-list 'org-latex-classes
2049 "\\documentclass[11pt,oneside]{memoir}\n"
2050 ("\\chapter{%s}" . "\\chapter*{%s}")
2051 ("\\section{%s}" . "\\section*{%s}")
2052 ("\\subsection{%s}" . "\\subsection*{%s}")
2053 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
2055 (add-to-list 'org-latex-classes
2057 "\\documentclass[11pt]{letter}
2058 [NO-DEFAULT-PACKAGES]
2061 ("\\section{%s}" . "\\section*{%s}")
2062 ("\\subsection{%s}" . "\\subsection*{%s}")
2063 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2064 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2065 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2067 (add-to-list 'org-latex-classes
2069 "\\documentclass{dlacv}
2070 [NO-DEFAULT-PACKAGES]
2073 ("\\section{%s}" . "\\section*{%s}")
2074 ("\\subsection{%s}" . "\\subsection*{%s}")
2075 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2076 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2077 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2080 (add-to-list 'org-latex-classes
2082 "\\documentclass{dlaresume}
2083 [NO-DEFAULT-PACKAGES]
2086 ("\\section{%s}" . "\\section*{%s}")
2087 ("\\subsection{%s}" . "\\subsection*{%s}")
2088 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2089 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2090 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2093 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
2094 ;; but adapted to use latexmk 4.22 or higher.
2095 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
2097 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
2098 (setq org-latex-default-packages-alist
2100 ("" "unicode-math" t)
2102 (setq org-latex-packages-alist
2109 ("" "longtable" nil)
2112 ;; make equations larger
2113 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2115 (defun org-create-formula--latex-header ()
2116 "Return LaTeX header appropriate for previewing a LaTeX snippet."
2117 (let ((info (org-combine-plists (org-export--get-global-options
2118 (org-export-get-backend 'latex))
2119 (org-export--get-inbuffer-options
2120 (org-export-get-backend 'latex)))))
2121 (org-latex-guess-babel-language
2122 (org-latex-guess-inputenc
2123 (org-splice-latex-header
2124 org-format-latex-header
2125 org-latex-default-packages-alist
2127 (plist-get info :latex-header)))
2131 ; support ignoring headers in org mode export to latex
2132 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2133 (defadvice org-latex-headline (around my-latex-skip-headlines
2134 (headline contents info) activate)
2135 (if (member "ignoreheading" (org-element-property :tags headline))
2136 (setq ad-return-value contents)
2139 ;; keep latex logfiles
2141 (setq org-latex-remove-logfiles nil)
2143 ;; Resume clocking task when emacs is restarted
2144 (org-clock-persistence-insinuate)
2146 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2147 (setq org-clock-history-length 23)
2148 ;; Resume clocking task on clock-in if the clock is open
2149 (setq org-clock-in-resume t)
2150 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2151 ;; there are things like PHONE calls
2152 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2153 ;; Separate drawers for clocking and logs
2154 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2155 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2156 (setq org-clock-into-drawer t)
2157 (setq org-log-into-drawer t)
2158 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2159 (setq org-clock-out-remove-zero-time-clocks t)
2160 ;; Clock out when moving task to a done state
2161 (setq org-clock-out-when-done t)
2162 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2163 (setq org-clock-persist t)
2164 ;; Do not prompt to resume an active clock
2165 (setq org-clock-persist-query-resume nil)
2166 ;; Enable auto clock resolution for finding open clocks
2167 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2168 ;; Include current clocking task in clock reports
2169 (setq org-clock-report-include-clocking-task t)
2171 ;; the cache seems to be broken
2172 (setq org-element-use-cache nil)
2174 (defvar bh/keep-clock-running nil)
2176 (defun bh/is-task-p ()
2177 "Any task with a todo keyword and no subtask"
2181 (subtree-end (save-excursion (org-end-of-subtree t)))
2182 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2185 (while (and (not has-subtask)
2186 (< (point) subtree-end)
2187 (re-search-forward "^\*+ " subtree-end t))
2188 (when (member (org-get-todo-state) org-todo-keywords-1)
2189 (setq has-subtask t))))
2190 (and is-a-task (not has-subtask)))))
2191 (defun bh/is-project-p ()
2192 "Any task with a todo keyword subtask"
2196 (subtree-end (save-excursion (org-end-of-subtree t)))
2197 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2200 (while (and (not has-subtask)
2201 (< (point) subtree-end)
2202 (re-search-forward "^\*+ " subtree-end t))
2203 (when (member (org-get-todo-state) org-todo-keywords-1)
2204 (setq has-subtask t))))
2205 (and is-a-task has-subtask))))
2207 (defun bh/is-subproject-p ()
2208 "Any task which is a subtask of another project"
2209 (let ((is-subproject)
2210 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2212 (while (and (not is-subproject) (org-up-heading-safe))
2213 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2214 (setq is-subproject t))))
2215 (and is-a-task is-subproject)))
2218 (defun bh/clock-in-to-next (kw)
2219 "Switch a task from TODO to NEXT when clocking in.
2220 Skips capture tasks, projects, and subprojects.
2221 Switch projects and subprojects from NEXT back to TODO"
2222 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2224 ((and (member (org-get-todo-state) (list "TODO"))
2227 ((and (member (org-get-todo-state) (list "NEXT"))
2231 (defun bh/punch-in (arg)
2232 "Start continuous clocking and set the default task to the
2233 selected task. If no task is selected set the Organization task
2234 as the default task."
2236 (setq bh/keep-clock-running t)
2237 (if (equal major-mode 'org-agenda-mode)
2239 ;; We're in the agenda
2241 (let* ((marker (org-get-at-bol 'org-hd-marker))
2242 (tags (org-with-point-at marker (org-get-tags-at))))
2243 (if (and (eq arg 4) tags)
2244 (org-agenda-clock-in '(16))
2245 (bh/clock-in-organization-task-as-default)))
2247 ;; We are not in the agenda
2251 ; Find the tags on the current task
2252 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2253 (org-clock-in '(16))
2254 (bh/clock-in-organization-task-as-default)))))
2256 (defun bh/punch-out ()
2258 (setq bh/keep-clock-running nil)
2259 (when (org-clock-is-active)
2261 (org-agenda-remove-restriction-lock))
2263 (defun bh/clock-in-default-task ()
2265 (org-with-point-at org-clock-default-task
2268 (defun bh/clock-in-parent-task ()
2269 "Move point to the parent (project) task if any and clock in"
2270 (let ((parent-task))
2274 (while (and (not parent-task) (org-up-heading-safe))
2275 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2276 (setq parent-task (point))))
2278 (org-with-point-at parent-task
2280 (when bh/keep-clock-running
2281 (bh/clock-in-default-task)))))))
2283 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2285 (defun bh/clock-in-organization-task-as-default ()
2287 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2288 (org-clock-in '(16))))
2290 (defun bh/clock-out-maybe ()
2291 (when (and bh/keep-clock-running
2292 (not org-clock-clocking-in)
2293 (marker-buffer org-clock-default-task)
2294 (not org-clock-resolving-clocks-due-to-idleness))
2295 (bh/clock-in-parent-task)))
2297 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2300 (defun bh/clock-in-task-by-id (id)
2301 "Clock in a task by id"
2302 (org-with-point-at (org-id-find id 'marker)
2303 (org-clock-in nil)))
2305 (defun bh/clock-in-last-task (arg)
2306 "Clock in the interrupted task if there is one
2307 Skip the default task and get the next one.
2308 A prefix arg forces clock in of the default task."
2310 (let ((clock-in-to-task
2312 ((eq arg 4) org-clock-default-task)
2313 ((and (org-clock-is-active)
2314 (equal org-clock-default-task (cadr org-clock-history)))
2315 (caddr org-clock-history))
2316 ((org-clock-is-active) (cadr org-clock-history))
2317 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2318 (t (car org-clock-history)))))
2320 (org-with-point-at clock-in-to-task
2321 (org-clock-in nil))))
2324 (defun org-export-to-ods ()
2326 (let ((csv-file "data.csv"))
2327 (org-table-export csv-file "orgtbl-to-csv")
2328 (org-odt-convert csv-file "ods" 'open)))
2330 ; allow for zero-width-space to be a break in regexp too
2331 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
2332 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
2333 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2335 ;; support inserting screen shots
2336 (defun my/org-insert-screenshot ()
2337 "Take a screenshot into a time stamped unique-named file in the
2338 same directory as the org-buffer and insert a link to this file."
2340 (defvar my/org-insert-screenshot/filename)
2341 (setq my/org-insert-screenshot/filename
2343 "Screenshot to insert: "
2345 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2348 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2349 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2350 (org-display-inline-images))
2352 (defun my/fix-inline-images ()
2353 (when org-inline-image-overlays
2354 (org-redisplay-inline-images)))
2356 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2358 ;; use xelatex to preview with imagemagick
2359 (add-to-list 'org-preview-latex-process-alist
2360 '(xelateximagemagick
2361 :programs ("xelatex" "convert")
2362 :description "pdf > png"
2363 :message "you need to install xelatex and imagemagick"
2365 :image-input-type "pdf"
2366 :image-output-type "png"
2367 :image-size-adjust (1.0 . 1.0)
2368 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2369 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2371 ;; use xelatex by default
2372 (setq org-preview-latex-default-process 'xelateximagemagick)
2374 ; from http://orgmode.org/Changes.html
2375 (defun my/org-repair-property-drawers ()
2376 "Fix properties drawers in current buffer.
2377 Ignore non Org buffers."
2379 (when (eq major-mode 'org-mode)
2380 (org-with-wide-buffer
2381 (goto-char (point-min))
2382 (let ((case-fold-search t)
2383 (inline-re (and (featurep 'org-inlinetask)
2384 (concat (org-inlinetask-outline-regexp)
2388 (unless (and inline-re (org-looking-at-p inline-re))
2390 (let ((end (save-excursion (outline-next-heading) (point))))
2392 (when (org-looking-at-p org-planning-line-re) (forward-line))
2393 (when (and (< (point) end)
2394 (not (org-looking-at-p org-property-drawer-re))
2396 (and (re-search-forward org-property-drawer-re end t)
2397 (eq (org-element-type
2398 (save-match-data (org-element-at-point)))
2400 (insert (delete-and-extract-region
2402 (min (1+ (match-end 0)) end)))
2403 (unless (bolp) (insert "\n"))))))))))))
2407 #+BEGIN_SRC emacs-lisp
2411 (use-package calfw-org
2414 (use-package org-gcal
2415 :if (file-readable-p "~/.hide/org_gcal.el")
2417 :config '((if (file-readable-p "~/.hide/org_gcal.el")
2418 (load-file "~/.hide/org_gcal.el"))
2423 #+BEGIN_SRC emacs-lisp
2427 ;; Show notification 10 minutes before event
2428 (setq appt-message-warning-time 10)
2429 ;; Disable multiple reminders
2430 (setq appt-display-interval appt-message-warning-time)
2431 (setq appt-display-mode-line nil)
2433 ;; add automatic reminders for appointments
2434 (defun my/org-agenda-to-appt ()
2436 (setq appt-time-msg-list nil)
2437 (org-agenda-to-appt))
2438 ;; add reminders when starting emacs
2439 (my/org-agenda-to-appt)
2440 ;; when rebuilding the agenda
2441 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
2442 "Pressing `r' on the agenda will also add appointments."
2443 (my/org-agenda-to-appt)
2445 ;; when saving all org buffers
2446 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2447 "Re-add appts after saving all org buffers"
2448 (my/org-agenda-to-appt))
2449 ;; Display appointments as a window manager notification
2450 (setq appt-disp-window-function 'my/appt-display)
2451 (setq appt-delete-window-function (lambda () t))
2453 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2455 (defun my/appt-display (min-to-app new-time msg)
2456 (if (atom min-to-app)
2457 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2458 (dolist (i (number-sequence 0 (1- (length min-to-app))))
2459 (start-process "my/appt-notification-app" nil my/appt-notification-app
2460 (nth i min-to-app) (nth i msg))))
2466 ** outshine (outlining) integration
2467 #+BEGIN_SRC emacs-lisp
2468 (use-package outshine
2470 :hook (outline-minor-mode . outshine-hook-function)
2474 #+BEGIN_SRC emacs-lisp
2478 ** Home/End Begining/End of line
2479 #+BEGIN_SRC emacs-lisp
2480 (global-set-key [home] 'move-beginning-of-line)
2481 (global-set-key [end] 'move-end-of-line)
2484 #+BEGIN_SRC emacs-lisp
2485 (global-unset-key "\M-g")
2486 (global-set-key (kbd "M-g l") 'goto-line)
2490 #+BEGIN_SRC emacs-lisp
2491 (use-package debian-changelog-mode
2492 :mode "debian/changelog"
2494 (setq debian-changelog-mailing-address "don@debian.org")
2495 (setq debian-changelog-full-name "Don Armstrong"))
2497 * Misc (uncharacterized)
2498 #+BEGIN_SRC emacs-lisp
2499 (setq calendar-latitude 38.6)
2500 (setq calendar-longitude -121.5)
2501 (setq case-fold-search t)
2502 (setq confirm-kill-emacs (quote y-or-n-p))
2503 (setq cperl-lazy-help-time nil)
2505 ** Turn on fontlock and icomplete
2506 #+BEGIN_SRC emacs-lisp
2507 (global-font-lock-mode 1)
2509 (setq log-edit-keep-buffer t)
2511 ** Set mail User agent
2512 #+BEGIN_SRC emacs-lisp
2513 (setq mail-user-agent (quote sendmail-user-agent))
2514 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2517 #+BEGIN_SRC emacs-lisp
2518 (setq ps-footer-font-size (quote (8 . 10)))
2519 (setq ps-header-font-size (quote (8 . 10)))
2520 (setq ps-header-title-font-size (quote (10 . 10)))
2521 (setq ps-line-number-color "blue")
2522 (setq ps-print-footer t)
2523 (setq ps-print-footer-frame nil)
2524 (setq ps-print-only-one-header t)
2526 ** Only single spacing on sentences
2527 #+BEGIN_SRC emacs-lisp
2528 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
2530 (setq sentence-end-double-space nil)
2531 ; enable matching parenthesis
2533 ** Display paren mode
2534 #+BEGIN_SRC emacs-lisp
2536 (setq show-paren-delay 0.2)
2538 (setq user-mail-address "don@donarmstrong.com")
2540 ;; switch back to the old primary selection method
2541 (setq x-select-enable-clipboard nil)
2542 (setq x-select-enable-primary t)
2543 ; (setq mouse-drag-copy-region t)
2545 (fset 'perl-mode 'cperl-mode)
2546 ;;(load-file "cperl-mode.el")
2548 ;; tramp configuration
2549 (setq tramp-use-ssh-controlmaster-options nil)
2551 (setq-default c-indent-level 4)
2552 (setq-default c-brace-imaginary-offset 0)
2553 (setq-default c-brace-offset -4)
2554 (setq-default c-argdecl-indent 4)
2555 (setq-default c-label-offset -4)
2556 (setq-default c-continued-statement-offset 4)
2558 (setq-default indent-tabs-mode nil)
2559 (setq-default tab-width 4)
2562 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2563 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2564 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2565 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2566 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2569 (defun insert-date ()
2570 "Insert date at point."
2572 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2573 (global-set-key "\C-[d" 'insert-date)
2575 (defun unfill-paragraph (arg)
2576 "Pull this whole paragraph up onto one line."
2578 (let ((fill-column 10000))
2579 (fill-paragraph arg))
2582 (column-number-mode t)
2585 ** Desktop-save-mode
2586 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2587 emacs, and use a different desktop file to restore history
2588 #+BEGIN_SRC emacs-lisp
2589 (use-package desktop
2592 (setq desktop-base-file-name
2593 (convert-standard-filename
2595 (or (getenv "EMACS_SERVER_NAME")
2599 (setq desktop-base-lock-name
2600 (convert-standard-filename
2601 (concat desktop-base-file-name
2603 (setq desktop-auto-save-timeout 60)
2604 (setq desktop-restore-eager 5)
2605 (setq desktop-lazy-verbose nil)
2606 (desktop-save-mode 1)
2610 ** Misc (Uncharacterized)
2611 #+BEGIN_SRC emacs-lisp
2612 '(icomplete-mode on)
2614 ;; custom-set-faces was added by Custom.
2615 ;; If you edit it by hand, you could mess it up, so be careful.
2616 ;; Your init file should contain only one such instance.
2617 ;; If there is more than one, they won't work right.
2618 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2621 (put 'upcase-region 'disabled nil)
2622 (put 'downcase-region 'disabled nil)
2623 (put 'narrow-to-region 'disabled nil)
2625 ; (defun turn-on-flyspell ()
2626 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2628 ; (flyspell-mode 1))
2631 ; Outline-minor-mode key map
2632 (define-prefix-command 'cm-map nil "Outline-")
2634 (define-key cm-map "q" 'outline-hide-sublevels) ; Hide everything but the top-level headings
2635 (define-key cm-map "t" 'outline-hide-body) ; Hide everything but headings (all body lines)
2636 (define-key cm-map "o" 'outline-hide-other) ; Hide other branches
2637 (define-key cm-map "c" 'outline-hide-entry) ; Hide this entry's body
2638 (define-key cm-map "l" 'outline-hide-leaves) ; Hide body lines in this entry and sub-entries
2639 (define-key cm-map "d" 'outline-hide-subtree) ; Hide everything in this entry and sub-entries
2641 (define-key cm-map "a" 'outline-show-all) ; Show (expand) everything
2642 (define-key cm-map "e" 'outline-show-entry) ; Show this heading's body
2643 (define-key cm-map "i" 'outline-show-children) ; Show this heading's immediate child sub-headings
2644 (define-key cm-map "k" 'outline-show-branches) ; Show all sub-headings under this heading
2645 (define-key cm-map "s" 'outline-show-subtree) ; Show (expand) everything in this heading & below
2647 (define-key cm-map "u" 'outline-up-heading) ; Up
2648 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2649 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2650 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2651 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2652 (global-set-key "\M-o" cm-map)
2653 ; fix up tmux xterm keys
2654 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2655 (defun fix-up-tmux-keys ()
2656 "Fix up tmux xterm keys"
2659 (let ((x 2) (tkey ""))
2679 ;; ctrl + alt + shift
2681 (setq tkey "C-M-S-"))
2684 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2685 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2686 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2687 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2689 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2691 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2693 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2695 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2697 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2699 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2701 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2703 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2705 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2707 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2709 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2711 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2713 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2715 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2717 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2719 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2721 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2723 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2725 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2727 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2729 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2731 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2733 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2735 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2737 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2739 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2746 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2748 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2749 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2750 (if (or (buffer-modified-p)
2751 (verify-visited-file-modtime)
2752 (< (* 8 1024 1024) (buffer-size))
2753 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2755 (clear-visited-file-modtime)
2757 (ad-activate 'ask-user-about-supersession-threat)
2761 #+BEGIN_SRC emacs-lisp
2765 (or (getenv "EMACS_SERVER_NAME")
2767 (unless (server-running-p)
2768 (global-set-key "\C-xp" 'server-edit)
2775 #+BEGIN_SRC emacs-lisp
2776 (provide 'don-configuration)