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 (setq package-enable-at-startup nil)
33 (setq package--init-file-ensured t)
34 (setq package-user-dir "~/var/emacs/elpa")
35 (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
36 ("melpa" . "https://melpa.org/packages/")
37 ("org" . "http://orgmode.org/elpa/")))
38 (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
39 (mapc #'(lambda (add) (add-to-list 'load-path add))
42 (unless (package-installed-p 'use-package)
43 (package-refresh-contents)
44 (package-install 'use-package))
45 (let ((package-user-dir-real (file-truename package-user-dir)))
46 ;; The reverse is necessary, because outside we mapc
47 ;; add-to-list element-by-element, which reverses.
48 (nreverse (apply #'nconc
49 ;; Only keep package.el provided loadpaths.
50 (mapcar #'(lambda (path)
51 (if (string-prefix-p package-user-dir-real path)
56 ;;; fix up info paths for packages
57 (with-eval-after-load "info"
59 (dolist (dir (directory-files package-user-dir))
60 (let ((fdir (concat (file-name-as-directory package-user-dir) dir)))
61 (unless (or (member dir '("." ".." "archives" "gnupg"))
62 (not (file-directory-p fdir))
63 (not (file-exists-p (concat (file-name-as-directory fdir) "dir"))))
64 (add-to-list 'Info-directory-list fdir)))))
68 (require 'use-package))
73 #+BEGIN_SRC emacs-lisp
76 :commands (paradox-upgrade-packages paradox-list-packages)
77 :config (setq paradox-execute-asynchronously t)
82 #+BEGIN_SRC emacs-lisp
83 (add-to-list 'load-path '"~/lib/emacs_el/")
84 (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
87 #+BEGIN_SRC emacs-lisp
88 ;; Set the custom file to /dev/null and don't bother to load it
89 (setq custom-file "/dev/null")
93 #+BEGIN_SRC emacs-lisp
94 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
95 ;; execute conditional code when loading libraries
96 (defmacro with-library (symbol &rest body)
97 `(when (require ,symbol nil t)
99 (put 'with-library 'lisp-indent-function 1)
103 ** Safe Local Variables
104 #+BEGIN_SRC emacs-lisp
105 (setq safe-local-variable-values
106 (quote ((auto-save-default)
108 (cperl-indent-level . 4)
110 (indent-tabs-mode . f)
114 #+BEGIN_SRC emacs-lisp
115 (setq global-mark-ring-max 128
119 (defun don/minibuffer-setup-hook ()
120 (setq gc-cons-threshold most-positive-fixnum))
122 (defun don/minibuffer-exit-hook ()
123 (setq gc-cons-threshold 1048576))
125 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
126 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
130 #+BEGIN_SRC emacs-lisp
131 (use-package hippie-exp
132 :bind* (("M-<SPC>" . hippie-expand))
136 #+BEGIN_SRC emacs-lisp
137 (use-package flyspell
139 :diminish flyspell-mode 🐝
141 (add-hook 'text-mode-hook 'turn-on-flyspell)
142 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
143 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
144 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
146 (setq ispell-program-name "ispell")
151 #+begin_src emacs-lisp :tangle yes
157 #+BEGIN_SRC emacs-lisp
162 #+BEGIN_SRC emacs-lisp
163 (use-package eyebrowse
165 :diminish eyebrowse-mode
166 :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
168 (setq eyebrowse-wrap-around t)
171 (defun my/eyebrowse-new-window-config ()
175 ;; start at 1 run till 0
176 (let ((j (mod (+ i 1) 10)))
177 (when (and (not done)
178 (not (eyebrowse--window-config-present-p j)))
179 (eyebrowse-switch-to-window-config j)
180 (call-interactively 'eyebrowse-rename-window-config2 j)
185 ;; I don't use latex-preview-pane
186 ;; (require 'latex-preview-pane)
187 ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
188 ;; ;; latex-preview-pane uses window-parameters which are
189 ;; ;; not preserved by eyebrowse, so we close the preview
190 ;; ;; pane before switching, it will be regenerated when we
191 ;; ;; edit the TeX file.
192 ;; (when (lpp/window-containing-preview)
193 ;; (delete-window (lpp/window-containing-preview))))
195 ;; (add-to-list 'eyebrowse-pre-window-switch-hook
196 ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
198 ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
199 ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
200 ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
201 ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
202 ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
210 #+BEGIN_SRC emacs-lisp
211 (defun my/vsplit-last-buffer ()
212 "Split the window vertically and display the previous buffer."
214 (split-window-vertically)
216 (switch-to-next-buffer))
218 (defun my/hsplit-last-buffer ()
219 "Split the window horizontally and display the previous buffer."
221 (split-window-horizontally)
223 (switch-to-next-buffer))
225 (bind-key "C-x 2" 'my/vsplit-last-buffer)
226 (bind-key "C-x 3" 'my/hsplit-last-buffer)
228 (setq split-width-threshold 100)
229 (setq split-height-threshold 60)
231 (defun my/split-window-prefer-vertically (window)
232 "If there's only one window (excluding any possibly active
233 minibuffer), then split the current window horizontally."
234 (if (and (one-window-p t)
235 (not (active-minibuffer-window))
236 ( < (frame-width) (frame-height))
238 (let ((split-width-threshold nil))
239 (split-window-sensibly window))
240 (split-window-sensibly window)))
242 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
243 (setq window-combination-resize t)
246 *** Compilation window
248 If there is no compilation window, open one at the bottom, spanning
249 the complete width of the frame. Otherwise, reuse existing window. In
250 the former case, if there was no error the window closes
253 #+BEGIN_SRC emacs-lisp
254 (add-to-list 'display-buffer-alist
255 `(,(rx bos "*compilation*" eos)
256 (display-buffer-reuse-window
257 display-buffer-in-side-window)
258 (reusable-frames . visible)
260 (window-height . 0.4)))
263 #+BEGIN_SRC emacs-lisp
264 (defun my/compilation-exit-autoclose (status code msg)
265 ;; If M-x compile exists with a 0
266 (when (and (eq status 'exit) (zerop code))
267 ;; and delete the *compilation* window
268 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
269 (when (and (not (window-at-side-p compilation-window 'top))
270 (window-at-side-p compilation-window 'left)
271 (window-at-side-p compilation-window 'right))
272 (delete-window compilation-window))))
273 ;; Always return the anticipated result of compilation-exit-message-function
276 ;; Specify my function (maybe I should have done a lambda function)
277 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
280 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
281 value, the compilation buffer scrolls automatically to follow the
282 output. If the value is ~first-error~, scrolling stops when the first
283 error appears, leaving point at that error. For any other non-nil
284 value, scrolling continues until there is no more output.
286 #+BEGIN_SRC emacs-lisp
287 (setq compilation-scroll-output 'first-error)
290 ** Mode line cleaning
292 #+BEGIN_SRC emacs-lisp
293 (use-package diminish
298 #+BEGIN_SRC emacs-lisp
305 #+BEGIN_SRC emacs-lisp
308 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
309 ("C-c j j" . avy-goto-word-or-subword-1)
310 ("M-g g" . avy-goto-line))
311 :config (progn (setq avy-background t))
314 *** Ace-link (jumping to links)
315 #+BEGIN_SRC emacs-lisp
316 (use-package ace-link
318 ; bind o in most modes
319 :config (ace-link-setup-default))
321 *** Jumping through edit points (goto-chg)
322 #+BEGIN_SRC emacs-lisp
323 (use-package goto-chg
325 :bind (("C-c j ," . goto-last-change)
326 ("C-c j ." . goto-last-change-reverse))
329 *** Jumping to bookmarks (visible bookmarks, bm)
330 #+BEGIN_SRC emacs-lisp
333 :bind (("C-c j b ." . bm-next)
334 ("C-c j b ," . bm-previous)
335 ("C-c j b SPC" . bm-toggle)))
340 #+BEGIN_SRC emacs-lisp
341 (use-package yasnippet
343 :diminish yas-minor-mode
346 (setq yas-verbosity 1)
347 (define-key yas-minor-mode-map (kbd "<tab>") nil)
348 (define-key yas-minor-mode-map (kbd "TAB") nil)
349 (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
350 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
351 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
352 (add-to-list 'hippie-expand-try-functions-list
353 'yas-hippie-try-expand)
359 #+BEGIN_SRC emacs-lisp
360 (use-package auto-yasnippet
362 :bind (("H-w" . aya-create)
368 #+BEGIN_SRC emacs-lisp
371 :bind (("M-/" . company-complete))
373 (setq company-echo-delay 0 ; remove blinking
374 company-show-numbers t ; show numbers for easy selection
375 company-selection-wrap-around t
376 company-require-match nil
377 company-dabbrev-ignore-case t
378 company-dabbrev-ignore-invisible t
379 company-dabbrev-other-buffers t
380 company-dabbrev-downcase nil
381 company-dabbrev-code-everywhere t
382 company-tooltip-align-annotations t
383 company-minimum-prefix-length 1
384 company-global-modes '(not)
385 company-lighter-base "(C)")
386 (global-company-mode 1)
388 (bind-key "C-n" #'company-select-next company-active-map)
389 (bind-key "C-p" #'company-select-previous company-active-map)
390 ; (bind-key "<tab>" #'company-complete company-active-map)
391 (bind-key "M-?" #'company-show-doc-buffer company-active-map)
392 (bind-key "M-." #'company-show-location company-active-map)
393 (bind-key "M-/" #'company-complete-common org-mode-map)
397 #+BEGIN_SRC emacs-lisp
398 (use-package company-c-headers
401 (defun malb/ede-object-system-include-path ()
402 "Return the system include path for the current buffer."
404 (ede-system-include-path ede-object)))
406 (setq company-c-headers-path-system
407 #'malb/ede-object-system-include-path)
409 (add-to-list 'company-backends #'company-c-headers)))
412 #+BEGIN_SRC emacs-lisp
413 (use-package company-anaconda
415 :config (add-to-list 'company-backends #'company-anaconda))
418 #+BEGIN_SRC emacs-lisp
419 (use-package company-plsense
424 #+BEGIN_SRC emacs-lisp
425 (use-package company-math
428 #+BEGIN_SRC emacs-lisp
429 (use-package company-auctex
432 (defun company-auctex-labels (command &optional arg &rest ignored)
433 "company-auctex-labels backend"
434 (interactive (list 'interactive))
436 (interactive (company-begin-backend 'company-auctex-labels))
437 (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
438 (candidates (company-auctex-label-candidates arg))))
440 (add-to-list 'company-backends
441 '(company-auctex-macros
442 company-auctex-environments
443 company-math-symbols-unicode
444 company-math-symbols-latex))
446 (add-to-list 'company-backends #'company-auctex-labels)
447 (add-to-list 'company-backends #'company-auctex-bibs)
451 #+BEGIN_SRC emacs-lisp
452 (use-package company-bibtex
458 #+BEGIN_SRC emacs-lisp
459 (use-package company-shell
462 (setq company-shell-modes '(sh-mode shell-mode))
463 (add-to-list 'company-backends 'company-shell)))
468 Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
470 *Note:* Do this at the end of =company-mode= config.
472 #+BEGIN_SRC emacs-lisp
473 (defvar malb/company-mode/enable-yas t
474 "Enable yasnippet for all backends.")
476 (defun malb/company-mode/backend-with-yas (backend)
477 (if (or (not malb/company-mode/enable-yas)
479 (member 'company-yasnippet backend)))
481 (append (if (consp backend) backend (list backend))
482 '(:with company-yasnippet))))
484 (setq company-backends
485 (mapcar #'malb/company-mode/backend-with-yas company-backends))
490 Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
492 #+BEGIN_SRC emacs-lisp
493 (defun malb/toggle-company-ispell ()
496 ((member '(company-ispell :with company-yasnippet) company-backends)
497 (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
498 (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
499 (message "company-ispell disabled"))
501 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
502 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
503 (message "company-ispell enabled!"))))
505 (defun malb/company-ispell-setup ()
506 ;; @see https://github.com/company-mode/company-mode/issues/50
507 (when (boundp 'company-backends)
508 (make-local-variable 'company-backends)
509 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
510 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
511 ;; https://github.com/redguardtoo/emacs.d/issues/473
512 (if (and (boundp 'ispell-alternate-dictionary)
513 ispell-alternate-dictionary)
514 (setq company-ispell-dictionary ispell-alternate-dictionary))))
519 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
521 2. This function then hopefully does what I want:
523 a. if a region is active, just indent
524 b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
525 c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
526 d. otherwise call whatever would have been called otherwise.
528 ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
530 #+BEGIN_SRC emacs-lisp
531 (defun malb/indent-fold-or-complete (&optional arg)
534 ;; if a region is active, indent
536 (indent-region (region-beginning)
538 ;; if the next char is space or eol, but prev char not whitespace
539 ((and (not (active-minibuffer-window))
542 (looking-back "[^[:space:]]")
543 (not (looking-back "^")))
545 (cond (company-mode (company-complete-common))
546 (auto-complete-mode (auto-complete))))
548 ;; no whitespace anywhere
549 ((and (not (active-minibuffer-window))
550 (looking-at "[^[:space:]]")
551 (looking-back "[^[:space:]]")
552 (not (looking-back "^")))
554 ((bound-and-true-p hs-minor-mode)
555 (save-excursion (end-of-line) (hs-toggle-hiding)))
556 ((bound-and-true-p outline-minor-mode)
557 (save-excursion (outline-cycle)))))
559 ;; by default just call whatever was bound
561 (let ((fn (or (lookup-key (current-local-map) (kbd "TAB"))
562 'indent-for-tab-command)))
563 (if (not (called-interactively-p 'any))
565 (setq this-command fn)
566 (call-interactively fn))))))
568 (defun malb/toggle-fold ()
570 (cond ((eq major-mode 'org-mode)
571 (org-force-cycle-archived))
572 ((bound-and-true-p hs-minor-mode)
577 ((bound-and-true-p outline-minor-mode)
581 (bind-key "<tab>" #'malb/indent-fold-or-complete)
582 (bind-key "C-<tab>" #'malb/toggle-fold)
586 #+BEGIN_SRC emacs-lisp
588 (use-package tinyprocmail
589 :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
590 :mode (".procmailrc" . turn-on-tinyprocmail-mode)
595 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
598 :bind (("C-x g" . magit-status)
599 ("C-x C-g" . magit-status))
601 ;; refine diffs always (hilight words)
602 (setq magit-diff-refine-hunk nil)
604 (use-package magit-annex
606 :load-path "~/lib/emacs_el/magit-annex/"
608 (use-package magit-vcsh
609 :ensure f ; currently not in melpa, so don't try to install
610 :load-path "~/lib/emacs_el/magit-vcsh/"
615 #+BEGIN_SRC emacs-lisp
616 (use-package cperl-mode
619 ;; Use c-mode for perl .xs files
620 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
621 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
622 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
623 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
624 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
627 cperl-auto-newline nil
628 cperl-auto-newline-after-colon nil
629 cperl-continued-statement-offset 4
630 cperl-brace-offset -1
631 cperl-continued-brace-offset 0
632 cperl-label-offset -4
633 cperl-highlight-variables-indiscriminately t
634 cperl-electric-lbrace-space nil
635 cperl-indent-parens-as-block nil
636 cperl-close-paren-offset -1
637 cperl-tab-always-indent t)
638 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
643 #+BEGIN_SRC emacs-lisp
644 (use-package markdown-mode
646 :mode (("\\.md\\'" . markdown-mode)
647 ("\\.mdwn\\'" . markdown-mode)
648 ("README\\.md\\'" . gfm-mode)
651 (setq markdown-enable-math t)
652 (setq markdown-follow-wiki-link-on-enter nil)
653 (bind-key "M-." #'markdown-jump markdown-mode-map)
654 (add-hook 'markdown-mode-hook #'flyspell-mode)
655 (add-hook 'markdown-mode-hook #'outline-minor-mode)
656 (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
661 #+BEGIN_SRC emacs-lisp
662 ; load sql-indent when sql is loaded
664 :mode (("\\.sql\\'" . sql-mode))
666 (require sql-indent))
669 #+BEGIN_SRC emacs-lisp
671 :commands ediff ediff3
674 ;; ediff configuration
675 ;; don't use the multi-window configuration
676 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
679 ** VCL --editing varnish configuration files
680 #+BEGIN_SRC emacs-lisp
681 (use-package vcl-mode
688 #+BEGIN_SRC emacs-lisp
689 (defun malb/helm-omni (&rest arg)
690 ;; just in case someone decides to pass an argument, helm-omni won't fail.
692 (unless helm-source-buffers-list
693 (setq helm-source-buffers-list
694 (helm-make-source "Buffers" 'helm-source-buffers)))
698 (if (projectile-project-p)
699 '(helm-source-projectile-buffers-list
700 helm-source-buffers-list)
701 '(helm-source-buffers-list)) ;; list of all open buffers
703 `(((name . "Virtual Workspace")
704 (candidates . ,(--map (cons (eyebrowse-format-slot it) (car it))
705 (eyebrowse--get 'window-configs)))
706 (action . (lambda (candidate)
707 (eyebrowse-switch-to-window-config candidate)))))
709 (if (projectile-project-p)
710 '(helm-source-projectile-recentf-list
712 '(helm-source-recentf)) ;; all recent files
714 ;; always make some common files easily accessible
715 ;;'(((name . "Common Files")
716 ;; (candidates . malb/common-file-targets)
717 ;; (action . (("Open" . (lambda (x) (find-file (eval x))))))))
719 '(helm-source-files-in-current-dir
721 helm-source-bookmarks
722 helm-source-buffer-not-found ;; ask to create a buffer otherwise
724 "*Helm all the things*"))
728 :bind (("M-x" . helm-M-x)
729 ("C-x C-f" . helm-find-files)
730 ("C-x b" . helm-buffers-list) ; malb/helm-omni)
731 ("C-x C-b" . helm-buffers-list) ; malb/helm-omni)
732 ("C-c <SPC>" . helm-all-mark-rings))
734 (require 'helm-config)
735 (require 'helm-for-files)
736 (require 'helm-bookmark)
739 (define-key global-map [remap find-file] 'helm-find-files)
740 (define-key global-map [remap occur] 'helm-occur)
741 (define-key global-map [remap list-buffers] 'helm-buffers-list)
742 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
743 (unless (boundp 'completion-in-region-function)
744 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
745 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
746 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
751 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
753 #+BEGIN_SRC emacs-lisp
754 (use-package helm-flx
757 ;; these are helm configs, but they kind of fit here nicely
758 (setq helm-M-x-fuzzy-match t
759 helm-bookmark-show-location t
760 helm-buffers-fuzzy-matching t
761 helm-completion-in-region-fuzzy-match t
762 helm-file-cache-fuzzy-match t
763 helm-imenu-fuzzy-match t
764 helm-mode-fuzzy-match t
765 helm-locate-fuzzy-match nil
767 helm-recentf-fuzzy-match nil
768 helm-semantic-fuzzy-match t)
772 #+BEGIN_SRC emacs-lisp
774 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
775 (defun malb/helm-swoop-pre-fill ()
776 (thing-at-point 'symbol))
777 (defvar malb/helm-swoop-ignore-major-mode "List of major modes to ignore for helm-swoop")
778 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
779 paradox-menu-mode doc-view-mode pdf-view-mode
780 mu4e-headers-mode org-mode markdown-mode latex-mode
781 ein:notebook-multilang-mode))
783 (defun malb/swoop-or-search ()
785 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
786 (memq major-mode malb/helm-swoop-ignore-major-mode))
790 (use-package helm-swoop
793 :bind (("C-c o" . helm-multi-swoop-org)
794 ("C-s" . malb/swoop-or-search)
795 ("C-M-s" . helm-multi-swoop-all))
798 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
799 helm-swoop-split-with-multiple-windows nil
800 helm-swoop-split-direction #'split-window-horizontally
801 helm-swoop-split-window-function 'helm-default-display-buffer
802 helm-swoop-speed-or-color t)
804 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
805 (defun malb/helm-swoop-C-s ()
807 (if (boundp 'helm-swoop-pattern)
808 (if (equal helm-swoop-pattern "")
809 (previous-history-element 1)
813 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
814 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
815 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
816 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
817 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
818 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
823 #+BEGIN_SRC emacs-lisp
826 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
827 helm-ag-command-option "--all-text"
828 helm-ag-insert-at-point 'symbol
829 helm-ag-fuzzy-match t
830 helm-ag-use-temp-buffer t
831 helm-ag-use-grep-ignore-list t
832 helm-ag-use-agignore t))
835 #+BEGIN_SRC emacs-lisp
836 (use-package helm-descbinds
838 :bind ("C-h b" . helm-descbinds)
839 :init (fset 'describe-bindings 'helm-descbinds))
843 #+BEGIN_SRC emacs-lisp
844 (use-package helm-c-yasnippet
846 :bind ("C-c h y" . helm-yas-complete)
848 (setq helm-yas-space-match-any-greedy t)))
851 #+BEGIN_SRC emacs-lisp
852 (use-package helm-org-rifle
855 (defun malb/helm-org-rifle-agenda-files (arg)
857 (let ((current-prefix-arg nil))
859 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
860 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
861 (t (helm-org-agenda-files-headings)))))))
864 This can be used to link things pretty quickly if necessary
865 #+BEGIN_SRC emacs-lisp
866 (use-package helm-google
868 :bind ("C-c h g" . helm-google)
870 (progn (add-to-list 'helm-google-actions
871 '("Copy URL" . (lambda (candidate)
873 (replace-regexp-in-string
874 "https://.*q=\\(.*\\)\&sa=.*"
880 (add-to-list 'helm-google-actions
881 '("Org Store Link" . (lambda (candidate)
882 (let ((title (car (split-string candidate "[\n]+")))
884 (replace-regexp-in-string
885 "https://.*q=\\(.*\\)\&sa=.*"
887 (push (list url title) org-stored-links))))
892 ** Projectile -- Project management
893 #+begin_src emacs-lisp
894 (use-package projectile
896 :bind (("<f5>" . projectile-compile-project)
897 ("<f6>" . next-error))
899 (use-package magit :ensure t)
900 (require 'helm-projectile)
903 (setq projectile-make-test-cmd "make check"
904 projectile-switch-project-action 'helm-projectile
905 projectile-mode-line '(:eval (format "»{%s}" (projectile-project-name))))
907 (projectile-global-mode)))
911 #+begin_src emacs-lisp
912 (use-package helm-projectile
915 (defvar malb/helm-source-file-not-found
916 (helm-build-dummy-source
921 'helm-projectile-sources-list
922 malb/helm-source-file-not-found t)
924 (helm-delete-action-from-source
925 "Grep in projects `C-s'"
926 helm-source-projectile-projects)
928 (helm-add-action-to-source
929 "Grep in projects `C-s'"
930 'helm-do-ag helm-source-projectile-projects 4)))
933 #+BEGIN_SRC emacs-lisp
936 :bind ("M-z" . avy-zap-up-to-char-dwim))
939 #+BEGIN_SRC emacs-lisp
941 :bind (("C-c 2" . my/hydra-orgmodes/body)
942 ("C-c @" . my/hydra-orgmodes/body)
943 ("C-c #" . my/hydra-outline/body)
944 ("C-c 3" . my/hydra-outline/body)
947 (defhydra my/hydra-orgmodes (:color blue :hint nil)
949 _n_: notes _c_: chaim _w_: wildman _o_: ool
950 _u_: uddin _s_: steve _r_: refile _f_: fh
951 _p_: read papers _R_: paper notes
956 ("n" (find-file "~/projects/org-notes/notes.org"))
957 ("c" (find-file "~/projects/org-notes/chaim.org"))
958 ("w" (find-file "~/projects/org-notes/wildman.org"))
959 ("u" (find-file "~/projects/org-notes/uddin.org"))
960 ("o" (find-file "~/projects/org-notes/ool.org"))
961 ("f" (find-file "~/projects/org-notes/fh.org"))
962 ("s" (find-file "~/projects/org-notes/sndservers.org"))
963 ("r" (find-file "~/projects/org-notes/refile.org"))
964 ("p" (find-file "~/projects/research/papers_to_read.org"))
965 ("R" (find-file "~/projects/research/paper_notes.org"))
966 ("h" (find-file "~/projects/org-notes/hpcbio.org"))
971 ;; from https://github.com/abo-abo/hydra/wiki/Emacs
972 (defhydra my/hydra-outline (:color pink :hint nil)
975 ^^^^^^------------------------------------------------------
976 _q_: sublevels _a_: all _u_: up
977 _t_: body _e_: entry _n_: next visible
978 _o_: other _i_: children _p_: previous visible
979 _c_: entry _k_: branches _f_: forward same level
980 _l_: leaves _s_: subtree _b_: backward same level
985 ("q" outline-hide-sublevels) ; Hide everything but the top-level headings
986 ("t" outline-hide-body) ; Hide everything but headings (all body lines)
987 ("o" outline-hide-other) ; Hide other branches
988 ("c" outline-hide-entry) ; Hide this entry's body
989 ("l" outline-hide-leaves) ; Hide body lines in this entry and sub-entries
990 ("d" outline-hide-subtree) ; Hide everything in this entry and sub-entries
992 ("a" outline-show-all) ; Show (expand) everything
993 ("e" outline-show-entry) ; Show this heading's body
994 ("i" outline-show-children) ; Show this heading's immediate child sub-headings
995 ("k" outline-show-branches) ; Show all sub-headings under this heading
996 ("s" outline-show-subtree) ; Show (expand) everything in this heading & below
998 ("u" outline-up-heading) ; Up
999 ("n" outline-next-visible-heading) ; Next
1000 ("p" outline-previous-visible-heading) ; Previous
1001 ("f" outline-forward-same-level) ; Forward - same level
1002 ("b" outline-backward-same-level) ; Backward - same level
1008 #+BEGIN_SRC emacs-lisp
1011 (add-to-list 'tramp-methods '("vcsh"
1012 (tramp-login-program "vcsh")
1016 (tramp-remote-shell "/bin/sh")
1017 (tramp-remote-shell-args
1021 #+BEGIN_SRC emacs-lisp
1025 (setq-default reftex-default-bibliography
1026 '("~/projects/research/references.bib")))
1029 #+BEGIN_SRC emacs-lisp
1031 :config (setq bibtex-user-optional-fields
1032 (quote (("annote" "Personal annotation (ignored)")
1040 #+BEGIN_SRC emacs-lisp
1045 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1046 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1047 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1048 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
1049 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
1050 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1051 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1052 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
1053 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
1054 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
1055 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
1057 (setq-default reftex-plug-into-AUCTeX t)
1058 ;; support fake section headers
1059 (setq TeX-outline-extra
1063 ("%subsubsection" 4)
1065 ;; add font locking to the headers
1066 (font-lock-add-keywords
1068 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1069 0 'font-lock-keyword-face t)
1070 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
1071 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
1072 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
1073 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1074 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
1076 ;; use smart quotes by default instead of `` and ''
1077 ;; taken from http://kieranhealy.org/esk/kjhealy.html
1078 (setq TeX-open-quote "“")
1079 (setq TeX-close-quote "”")
1081 ;; (TeX-add-style-hook
1086 ;; (custom-set-variables
1087 ;; '(font-latex-user-keyword-classes
1090 ;; font-lock-function-name-face 2 (command 1 t))))
1092 (setq-default TeX-parse-self t)
1093 (setq-default TeX-auto-save t)
1094 (setq-default TeX-master nil)
1097 '(TeX-add-style-hook
1100 (if (boundp 'reftex-ref-style-alist)
1102 'reftex-ref-style-alist
1103 '("Cleveref" "cleveref"
1104 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1105 (reftex-ref-style-activate "Cleveref")
1107 '("cref" TeX-arg-ref)
1108 '("Cref" TeX-arg-ref)
1109 '("cpageref" TeX-arg-ref)
1110 '("Cpageref" TeX-arg-ref)))))
1113 '(add-to-list 'LaTeX-fill-excluded-macros
1116 (use-package font-latex
1118 (setq font-latex-match-reference-keywords
1140 (setq font-latex-fontify-script nil)
1141 (setq font-latex-fontify-sectioning (quote color))
1142 (setq font-latex-script-display (quote (nil)))
1147 #+BEGIN_SRC emacs-lisp
1151 :mode ("\\.R\\'" . ess-r-mode)
1152 :bind (:map ess-mode-map
1153 ("C-c C-R" . dla/ess-region-remote-eval))
1155 (autoload 'ess-r-mode "ess-site" nil t)
1156 (autoload 'R "ess-site" nil t)
1158 ; actually load the rest of ess
1160 (defun ess-change-directory (path)
1161 "Set the current working directory to PATH for both *R* and Emacs."
1162 (interactive "Directory to change to: ")
1164 (when (file-exists-p path)
1165 (ess-command (concat "setwd(\"" path "\")\n"))
1166 ;; use file-name-as-directory to ensure it has trailing /
1167 (setq default-directory (file-name-as-directory path))))
1168 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1169 ;; outlining support for ess modes
1173 (outline-minor-mode)
1174 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1175 (defun outline-level ()
1176 (cond ((looking-at "^##### ") 1)
1177 ((looking-at "^#### ") 2)
1178 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1181 (defun dla/ess-region-remote-eval (start end)
1182 "Evaluate region in a remote ESS instance"
1184 (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***"))
1185 kill-buffer "***essregionremoteeval***")
1186 ;; Don't restore history or save workspace image
1187 '(inferior-R-args "--no-restore-history --no-save")
1192 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1194 #+BEGIN_SRC emacs-lisp
1195 (use-package rainbow-mode
1196 ;; add ess to the x major mode
1197 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1198 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1203 #+BEGIN_SRC emacs-lisp
1204 (use-package polymode
1206 (use-package poly-R)
1207 (use-package poly-noweb)
1208 (use-package poly-markdown)
1209 :mode ("\\.Snw" . poly-noweb+r-mode)
1210 :mode ("\\.Rnw" . poly-noweb+r-mode)
1211 :mode ("\\.Rmd" . poly-markdown+r-mode)
1217 #+BEGIN_SRC emacs-lisp
1218 (use-package outline-magic)
1221 #+BEGIN_SRC emacs-lisp
1222 ;; change the outline mode prefix from C-c @ to C-c C-2
1223 (setq outline-minor-mode-prefix "C-c C-2")
1224 ;;(add-hook 'outline-minor-mode-hook
1225 ;; (lambda () (local-set-key (kbd "C-c C-2")
1226 ;; outline-mode-prefix-map)))
1230 #+BEGIN_SRC emacs-lisp
1231 (use-package writeroom-mode
1233 (defun my/writing-mode ()
1234 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1239 (visual-line-mode -1)
1241 (visual-fill-column-mode -1)
1243 (visual-line-mode 1)
1245 (visual-fill-column-mode 1)
1250 ** GhostText/Atomic Chrome
1251 #+BEGIN_SRC emacs-lisp
1252 (use-package atomic-chrome
1254 (ignore-errors (atomic-chrome-start-server))
1255 (setq atomic-chrome-buffer-open-style 'full)
1260 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
1262 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1263 #+BEGIN_SRC emacs-lisp
1264 (use-package multiple-cursors
1265 :bind* (("C-;" . mc/mark-all-dwim)
1266 ("C-<" . mc/mark-previous-like-this)
1267 ("C->" . mc/mark-next-like-this)
1268 ("C-S-c C-S-c" . mc/edit-lines))
1272 #+BEGIN_SRC emacs-lisp
1273 (use-package web-mode
1275 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1276 (setq web-mode-enable-engine-detection t)
1277 (setq web-mode-engines-alist
1278 '(("template-toolkit" . "\\.tmpl\\'")))
1281 ** Spamassassin Mode
1282 #+BEGIN_SRC emacs-lisp
1283 (use-package spamassassin-mode
1284 :commands spamassassin-mode
1289 #+BEGIN_SRC emacs-lisp
1290 (use-package password-store
1292 :commands password-store-edit password-store-generate
1296 #+BEGIN_SRC emacs-lisp
1300 ;; fix up css mode to not be silly
1301 ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1302 (setq cssm-indent-level 4)
1303 (setq cssm-newline-before-closing-bracket t)
1304 (setq cssm-indent-function #'cssm-c-style-indenter)
1305 (setq cssm-mirror-mode nil))
1308 #+BEGIN_SRC emacs-lisp
1310 :diminish abbrev-mode
1312 ;; load abbreviations from
1313 (setq abbrev-file-name
1314 "~/.emacs_abbrev_def")
1316 ;; read the abbrev file if it exists
1317 (if (file-exists-p abbrev-file-name)
1318 (quietly-read-abbrev-file))
1320 ;; for now, use abbrev mode everywhere
1321 (setq default-abbrev-mode t))
1327 #+BEGIN_SRC emacs-lisp
1328 (use-package message
1330 :diminish (message "✉")
1331 :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1332 :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1333 :hook 'my/message-mode-settings
1334 :hook 'turn-on-flyspell
1335 :bind (:map message-mode-map
1336 ("C-c C-a" . my/post-attach-file))
1337 :delight (message-mode "✉")
1339 (defun my/message-mode-settings ()
1340 (font-lock-add-keywords nil
1341 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1342 (0 'message-multiply-quoted-text-face))
1343 ("^[ \t]*>[ \t]*>.*$"
1344 (0 'message-double-quoted-text-face))))
1347 (defun my/post-attach-file ()
1348 "Prompt for an attachment."
1350 (let ((file (read-file-name "Attach file: " nil nil t nil)))
1351 (my/header-attach-file file "")))
1353 (defun my/header-attach-file (file description)
1354 "Attach a FILE to the current message (works with Mutt).
1355 Argument DESCRIPTION MIME description."
1356 (interactive "fAttach file: \nsDescription: ")
1357 (when (> (length file) 0)
1362 (goto-char (point-min))
1363 (search-forward-regexp "^$")
1364 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1366 (message (concat "Attached '" file "'."))
1367 (setq post-has-attachment t))))))
1369 (setq mail-yank-prefix "> ")
1373 #+BEGIN_SRC emacs-lisp
1374 (use-package muttrc-mode
1381 ** Reverting buffers
1382 #+BEGIN_SRC emacs-lisp
1383 (use-package autorevert
1384 :diminish auto-revert-mode
1386 (setq global-auto-revert-non-file-buffers t
1387 global-auto-revert-ignore-modes '(pdf-view-mode)
1388 auto-revert-verbose nil)
1389 (global-auto-revert-mode 1))
1392 ** Use-package and load things
1393 #+BEGIN_SRC emacs-lisp
1396 :delight (org-mode "ø")
1397 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1398 :bind (("C-c l" . org-store-link)
1399 ("C-c a" . org-agenda)
1400 ("C-c b" . org-iswitchb))
1402 ** Agenda Configuration
1403 #+BEGIN_SRC emacs-lisp
1405 (setq-default org-log-done 'time)
1406 (setq-default org-agenda-ndays 5)
1408 (setq org-agenda-sticky t)
1409 (defun dla/show-org-agenda ()
1414 (and (string-match-p
1422 (buffer-name agendabuffer))
1424 (delete-other-windows))
1426 ;; agenda configuration
1427 ;; Do not dim blocked tasks
1428 (setq org-agenda-dim-blocked-tasks nil)
1429 (setq org-agenda-inhibit-startup t)
1430 (setq org-agenda-use-tag-inheritance nil)
1432 ;; Compact the block agenda view
1433 (setq org-agenda-compact-blocks t)
1435 ;; Custom agenda command definitions
1436 (setq org-agenda-custom-commands
1437 (quote (("N" "Notes" tags "NOTE"
1438 ((org-agenda-overriding-header "Notes")
1439 (org-tags-match-list-sublevels t)))
1440 ("h" "Habits" tags-todo "STYLE=\"habit\""
1441 ((org-agenda-overriding-header "Habits")
1442 (org-agenda-sorting-strategy
1443 '(todo-state-down effort-up category-keep))))
1447 ((org-agenda-overriding-header "Tasks to Refile")
1448 (org-tags-match-list-sublevels nil)))
1449 (tags-todo "-CANCELLED/!"
1450 ((org-agenda-overriding-header "Stuck Projects")
1451 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1452 (org-agenda-sorting-strategy
1454 (tags-todo "-HOLD-CANCELLED/!"
1455 ((org-agenda-overriding-header "Projects")
1456 (org-agenda-skip-function 'bh/skip-non-projects)
1457 (org-tags-match-list-sublevels 'indented)
1458 (org-agenda-sorting-strategy
1460 (tags-todo "-CANCELLED/!NEXT"
1461 ((org-agenda-overriding-header (concat "Project Next Tasks"
1462 (if bh/hide-scheduled-and-waiting-next-tasks
1464 " (including WAITING and SCHEDULED tasks)")))
1465 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1466 (org-tags-match-list-sublevels t)
1467 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1468 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1469 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1470 (org-agenda-sorting-strategy
1471 '(todo-state-down effort-up category-keep))))
1472 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1473 ((org-agenda-overriding-header (concat "Project Subtasks"
1474 (if bh/hide-scheduled-and-waiting-next-tasks
1476 " (including WAITING and SCHEDULED tasks)")))
1477 (org-agenda-skip-function 'bh/skip-non-project-tasks)
1478 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1479 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1480 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1481 (org-agenda-sorting-strategy
1483 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1484 ((org-agenda-overriding-header (concat "Standalone Tasks"
1485 (if bh/hide-scheduled-and-waiting-next-tasks
1487 " (including WAITING and SCHEDULED tasks)")))
1488 (org-agenda-skip-function 'bh/skip-project-tasks)
1489 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1490 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1491 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1492 (org-agenda-sorting-strategy
1494 (tags-todo "-CANCELLED+WAITING|HOLD/!"
1495 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1496 (org-agenda-skip-function 'bh/skip-stuck-projects)
1497 (org-tags-match-list-sublevels nil)
1498 (org-agenda-todo-ignore-scheduled t)
1499 (org-agenda-todo-ignore-deadlines t)))
1501 ((org-agenda-overriding-header "Tasks to Archive")
1502 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1503 (org-tags-match-list-sublevels nil))))
1506 ; org mode agenda files
1507 (setq org-agenda-files
1508 (quote ("~/projects/org-notes/debbugs.org"
1509 "~/projects/org-notes/notes.org"
1510 "~/projects/org-notes/holidays.org"
1511 "~/projects/org-notes/refile.org"
1512 "~/projects/org-notes/diary.org"
1513 "~/projects/org-notes/ool.org"
1514 "~/projects/org-notes/sndservers.org"
1515 "~/projects/org-notes/chaim.org"
1516 "~/projects/org-notes/wildman.org"
1517 "~/projects/org-notes/uddin.org"
1518 "~/projects/org-notes/reviews.org"
1519 "~/projects/org-notes/laurel.org"
1520 "~/projects/org-notes/from-calendar.org"
1521 "~/org-mode/from-mobile.org"
1522 "~/projects/org-notes/fh.org")))
1524 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1525 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
1526 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1527 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1528 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1529 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1530 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1531 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1532 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1533 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1534 (defun org-agenda-timeline-all (&optional arg)
1537 (dolist (org-agenda-file org-agenda-files)
1538 (insert-file-contents org-agenda-file nil)
1539 (goto-char (point-max))
1541 (write-file "/tmp/timeline.org")
1542 (org-agenda arg "L")))
1543 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1547 #+BEGIN_SRC emacs-lisp
1548 (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")))
1549 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1551 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1552 (setq org-id-link-to-org-use-id 'use-existing)
1554 ** Capture Templates
1555 #+BEGIN_SRC emacs-lisp
1556 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1557 `(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
1558 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1559 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
1560 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1561 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
1562 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1563 ("n" "note" entry (file "~/projects/org-notes/refile.org")
1564 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1565 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
1566 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1567 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1568 "* %?\n%U\n" :clock-in t :clock-resume t)
1569 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
1570 "* TODO Review %c\n%U\n" :immediate-finish t)
1571 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
1572 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1573 ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
1574 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1575 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1576 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1577 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
1578 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1579 ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1581 ,(format-time-string "Positions %Y"))
1582 "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1583 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
1584 "* 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")
1588 ;; Remove empty LOGBOOK drawers on clock out
1589 (defun bh/remove-empty-drawer-on-clock-out ()
1592 (beginning-of-line 0)
1593 (org-remove-empty-drawer-at (point))))
1595 (defun my/org-add-id ()
1598 (if (org-current-level)
1607 ** Org mode key bindings
1608 #+BEGIN_SRC emacs-lisp
1609 ;; org mode configuration from http://doc.norang.ca/org-mode.html
1610 ;; Custom Key Bindings
1611 :bind* (("<f9> a" . org-agenda)
1612 ("<f9> I" . bh/punch-in)
1613 ("<f9> O" . bh/punch-out)
1614 ("<f9> SPC" . bh/clock-in-last-task)
1615 ("<f12>" . org-agenda)
1616 ;; ("<f5>" . bh/org-todo)
1617 ("<S-f5>" . bh/widen)
1618 ("<f7>" . bh/set-truncate-lines)
1619 ("<f8>" . org-cycle-agenda-files)
1620 ("<f9> <f9>" . org-agenda)
1622 ("<f9> c" . calendar)
1623 ("<f9> f" . boxquote-insert-file)
1624 ("<f9> h" . bh/hide-other)
1625 ("<f9> n" . bh/toggle-next-task-display)
1628 ("<f9> r" . boxquote-region)
1629 ("<f9> s" . bh/switch-to-scratch)
1631 ("<f9> t" . bh/insert-inactive-timestamp)
1632 ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1634 ("<f9> v" . visible-mode)
1635 ("<f9> l" . org-toggle-link-display)
1636 ("<f9> SPC" . bh/clock-in-last-task)
1637 ("C-<f9>" . previous-buffer)
1638 ("M-<f9>" . org-toggle-inline-images)
1639 ("C-x n r" . narrow-to-region)
1640 ("C-<f10>" . next-buffer)
1641 ("<f11>" . org-clock-goto)
1642 ("C-<f11>" . org-clock-in)
1643 ("C-s-<f12>" . bh/save-then-publish)
1644 ("C-c c" . org-capture))
1647 ** Utility Functions
1648 #+BEGIN_SRC emacs-lisp
1649 (defun bh/hide-other ()
1652 (org-back-to-heading 'invisible-ok)
1658 (defun bh/set-truncate-lines ()
1659 "Toggle value of truncate-lines and refresh window display."
1661 (setq truncate-lines (not truncate-lines))
1662 ;; now refresh window display (an idiom from simple.el):
1664 (set-window-start (selected-window)
1665 (window-start (selected-window)))))
1667 (defun bh/switch-to-scratch ()
1669 (switch-to-buffer "*scratch*"))
1671 (setq org-use-fast-todo-selection t)
1672 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1674 ; create function to create headlines in file. This comes from
1675 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1676 (defun my/org-add-ids-to-headlines-in-file ()
1677 "Add ID properties to all headlines in the current file which
1678 do not already have one."
1680 (org-map-entries 'org-id-get-create))
1681 (defun dla/org-update-ids-to-headlines-in-file ()
1682 "Add or replace ID properties to all headlines in the current file
1683 (or narrowed region)."
1685 (org-map-entries '(lambda () (org-id-get-create t))))
1686 ; if we wanted to do this to every buffer, do the following:
1687 ; (add-hook 'org-mode-hook
1689 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1692 #+BEGIN_SRC emacs-lisp
1693 (setq org-todo-keywords
1694 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1695 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1697 (setq org-todo-keyword-faces
1698 (quote (("TODO" :foreground "red" :weight bold)
1699 ("NEXT" :foreground "blue" :weight bold)
1700 ("DONE" :foreground "forest green" :weight bold)
1701 ("WAITING" :foreground "orange" :weight bold)
1702 ("HOLD" :foreground "magenta" :weight bold)
1703 ("CANCELLED" :foreground "forest green" :weight bold)
1704 ("MEETING" :foreground "forest green" :weight bold)
1705 ("PHONE" :foreground "forest green" :weight bold))))
1707 (setq org-todo-state-tags-triggers
1708 (quote (("CANCELLED" ("CANCELLED" . t))
1709 ("WAITING" ("WAITING" . t))
1710 ("HOLD" ("WAITING") ("HOLD" . t))
1711 (done ("WAITING") ("HOLD"))
1712 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1713 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1714 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1718 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1719 ; add ids on creation of nodes
1720 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1723 ; resolve clocks after 10 minutes of idle; use xprintidle
1724 ; (setq org-clock-idle-time 10)
1725 ; (setq org-clock-x11idle-program-name "xprintidle")
1727 ; this is from http://doc.norang.ca/org-mode.html#Capture
1728 ; use C-M-r for org mode capture
1729 (global-set-key (kbd "C-M-r") 'org-capture)
1731 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1732 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1733 (org-agenda-files :maxlevel . 9))))
1735 ; Use full outline paths for refile targets - we file directly with IDO
1736 (setq org-refile-use-outline-path t)
1738 ; Targets complete directly with IDO
1739 (setq org-outline-path-complete-in-steps nil)
1741 ; Allow refile to create parent tasks with confirmation
1742 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1744 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1745 ; (setq org-completion-use-ido t)
1746 ; (setq ido-everywhere t)
1747 ; (setq ido-max-directory-size 100000)
1748 ; (ido-mode (quote both))
1749 ; ; Use the current window when visiting files and buffers with ido
1750 ; (setq ido-default-file-method 'selected-window)
1751 ; (setq ido-default-buffer-method 'selected-window)
1752 ; ; Use the current window for indirect buffer display
1753 ; (setq org-indirect-buffer-display 'current-window)
1756 ;;;; Refile settings
1757 ; Exclude DONE state tasks from refile targets
1758 (defun bh/verify-refile-target ()
1759 "Exclude todo keywords with a done state from refile targets"
1760 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1762 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1764 ;; ensure that emacsclient will show just the note to be edited when invoked
1765 ;; from Mutt, and that it will shut down emacsclient once finished;
1766 ;; fallback to legacy behavior when not invoked via org-protocol.
1767 (require 'org-protocol)
1768 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1769 (setq my-org-protocol-flag nil)
1770 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1771 "Delete frame at remember finalization"
1772 (progn (if my-org-protocol-flag (delete-frame))
1773 (setq my-org-protocol-flag nil)))
1774 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1775 "Delete frame at remember refile"
1776 (if my-org-protocol-flag
1778 (setq my-org-protocol-flag nil)
1783 (defadvice org-capture-kill (after delete-frame-at-end activate)
1784 "Delete frame at remember abort"
1785 (progn (if my-org-protocol-flag (delete-frame))
1786 (setq my-org-protocol-flag nil)))
1787 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1788 (setq my-org-protocol-flag t))
1790 (defadvice org-insert-todo-heading (after dla/create-id activate)
1791 (unless (org-in-item-p)
1797 (add-to-list 'org-modules 'org-habit)
1799 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1800 (defun open-mail-in-mutt (message)
1801 "Open a mail message in Mutt, using an external terminal.
1803 Message can be specified either by a path pointing inside a
1804 Maildir, or by Message-ID."
1805 (interactive "MPath or Message-ID: ")
1807 (format "faf xterm -e \"%s %s\""
1808 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1810 ;; add support for "mutt:ID" links
1811 (org-add-link-type "mutt" 'open-mail-in-mutt)
1813 (defun my-org-mode-setup ()
1814 ; (load-library "reftex")
1815 (and (buffer-file-name)
1816 (file-exists-p (buffer-file-name))
1818 ; (reftex-parse-all)
1819 (reftex-set-cite-format
1820 '((?b . "[[bib:%l][%l-bib]]")
1821 (?n . "[[notes:%l][%l-notes]]")
1823 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1825 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1826 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1827 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1828 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1830 (add-hook 'org-mode-hook 'my-org-mode-setup)
1832 (defun org-mode-reftex-search ()
1834 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1836 (defun open-research-paper (bibtexkey)
1837 "Open a paper by bibtex key"
1838 (interactive "bibtex key: ")
1841 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1842 (org-add-link-type "papers" 'open-research-paper)
1843 (defun open-research-paper-pdf (bibtexkey)
1844 "Open a paper pdf by bibtex key"
1845 (interactive "bibtex key: ")
1847 (format "%s -p evince_annot %s"
1848 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1849 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1851 (add-to-list 'org-link-abbrev-alist
1853 "~/projects/research/paper_notes.org::#%s"))
1855 ; I pretty much always want hiearchical checkboxes
1856 (setq org-hierachical-checkbox-statistics nil)
1858 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1859 (add-to-list 'org-structure-template-alist
1860 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1863 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1864 (defun my-rtcite-export-handler (path desc format)
1865 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1866 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1867 (match-string 1 path)))
1868 (path (substring path 0 (match-beginning 0))))
1869 (cond ((eq format 'latex)
1871 (equal 0 (search "rtcite:" desc)))
1872 (format "\\cite{%s}" search)
1873 (format "\\cite[%s]{%s}" desc search))))))
1875 (org-add-link-type "rtcite"
1877 'my-rtcite-export-handler)
1881 ** Org Mobile Configuration
1882 #+BEGIN_SRC emacs-lisp
1883 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1884 (when (string= system-name "linnode")
1885 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1886 (setq-default org-directory "/home/don/org-mode/")
1887 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1891 #+BEGIN_SRC emacs-lisp
1892 ;; org mode ical export
1893 (setq org-icalendar-timezone "America/Los_Angeles")
1894 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1895 ;; we already add the id manually
1896 (setq org-icalendar-store-UID t)
1899 ** General Org Babel Configuration
1900 #+BEGIN_SRC emacs-lisp
1901 ;; org babel support
1902 (org-babel-do-load-languages
1903 'org-babel-load-languages
1910 ;; use graphviz-dot for dot things
1911 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1912 ;; org-babel-by-backend
1913 (defmacro org-babel-by-backend (&rest body)
1914 `(case (if (boundp 'backend)
1915 (org-export-backend-name backend)
1918 (defun my/fix-inline-images ()
1919 (when org-inline-image-overlays
1920 (org-redisplay-inline-images)))
1922 (add-hook 'org-babel-after-execute-hook
1923 'my/fix-inline-images)
1926 ** LaTeX configuration
1928 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
1930 #+BEGIN_SRC emacs-lisp
1932 (add-to-list 'org-latex-classes
1934 "\\documentclass[11pt,oneside,article]{memoir}\n"
1935 ("\\section{%s}" . "\\section*{%s}")
1936 ("\\subsection{%s}" . "\\subsection*{%s}")
1937 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1938 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1939 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1941 (setq org-beamer-outline-frame-options "")
1942 (add-to-list 'org-latex-classes
1944 "\\documentclass[ignorenonframetext]{beamer}
1945 [NO-DEFAULT-PACKAGES]
1948 ("\\section{%s}" . "\\section*{%s}")
1949 ("\\subsection{%s}" . "\\subsection*{%s}")
1950 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1951 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1952 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1954 (add-to-list 'org-latex-classes
1956 "\\documentclass[11pt,oneside]{memoir}\n"
1957 ("\\chapter{%s}" . "\\chapter*{%s}")
1958 ("\\section{%s}" . "\\section*{%s}")
1959 ("\\subsection{%s}" . "\\subsection*{%s}")
1960 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
1962 (add-to-list 'org-latex-classes
1964 "\\documentclass[11pt]{letter}
1965 [NO-DEFAULT-PACKAGES]
1968 ("\\section{%s}" . "\\section*{%s}")
1969 ("\\subsection{%s}" . "\\subsection*{%s}")
1970 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1971 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1972 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1974 (add-to-list 'org-latex-classes
1976 "\\documentclass{dlacv}
1977 [NO-DEFAULT-PACKAGES]
1980 ("\\section{%s}" . "\\section*{%s}")
1981 ("\\subsection{%s}" . "\\subsection*{%s}")
1982 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1983 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1984 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1987 (add-to-list 'org-latex-classes
1989 "\\documentclass{dlaresume}
1990 [NO-DEFAULT-PACKAGES]
1993 ("\\section{%s}" . "\\section*{%s}")
1994 ("\\subsection{%s}" . "\\subsection*{%s}")
1995 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1996 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1997 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2000 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
2001 ;; but adapted to use latexmk 4.22 or higher.
2002 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
2004 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
2005 (setq org-latex-default-packages-alist
2007 ("" "unicode-math" t)
2009 (setq org-latex-packages-alist
2016 ("" "longtable" nil)
2019 ;; make equations larger
2020 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2022 (defun org-create-formula--latex-header ()
2023 "Return LaTeX header appropriate for previewing a LaTeX snippet."
2024 (let ((info (org-combine-plists (org-export--get-global-options
2025 (org-export-get-backend 'latex))
2026 (org-export--get-inbuffer-options
2027 (org-export-get-backend 'latex)))))
2028 (org-latex-guess-babel-language
2029 (org-latex-guess-inputenc
2030 (org-splice-latex-header
2031 org-format-latex-header
2032 org-latex-default-packages-alist
2034 (plist-get info :latex-header)))
2038 ; support ignoring headers in org mode export to latex
2039 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2040 (defadvice org-latex-headline (around my-latex-skip-headlines
2041 (headline contents info) activate)
2042 (if (member "ignoreheading" (org-element-property :tags headline))
2043 (setq ad-return-value contents)
2046 ;; keep latex logfiles
2048 (setq org-latex-remove-logfiles nil)
2050 ;; Resume clocking task when emacs is restarted
2051 (org-clock-persistence-insinuate)
2053 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2054 (setq org-clock-history-length 23)
2055 ;; Resume clocking task on clock-in if the clock is open
2056 (setq org-clock-in-resume t)
2057 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2058 ;; there are things like PHONE calls
2059 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2060 ;; Separate drawers for clocking and logs
2061 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2062 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2063 (setq org-clock-into-drawer t)
2064 (setq org-log-into-drawer t)
2065 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2066 (setq org-clock-out-remove-zero-time-clocks t)
2067 ;; Clock out when moving task to a done state
2068 (setq org-clock-out-when-done t)
2069 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2070 (setq org-clock-persist t)
2071 ;; Do not prompt to resume an active clock
2072 (setq org-clock-persist-query-resume nil)
2073 ;; Enable auto clock resolution for finding open clocks
2074 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2075 ;; Include current clocking task in clock reports
2076 (setq org-clock-report-include-clocking-task t)
2078 ;; the cache seems to be broken
2079 (setq org-element-use-cache nil)
2081 (defvar bh/keep-clock-running nil)
2083 (defun bh/is-task-p ()
2084 "Any task with a todo keyword and no subtask"
2088 (subtree-end (save-excursion (org-end-of-subtree t)))
2089 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2092 (while (and (not has-subtask)
2093 (< (point) subtree-end)
2094 (re-search-forward "^\*+ " subtree-end t))
2095 (when (member (org-get-todo-state) org-todo-keywords-1)
2096 (setq has-subtask t))))
2097 (and is-a-task (not has-subtask)))))
2098 (defun bh/is-project-p ()
2099 "Any task with a todo keyword subtask"
2103 (subtree-end (save-excursion (org-end-of-subtree t)))
2104 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2107 (while (and (not has-subtask)
2108 (< (point) subtree-end)
2109 (re-search-forward "^\*+ " subtree-end t))
2110 (when (member (org-get-todo-state) org-todo-keywords-1)
2111 (setq has-subtask t))))
2112 (and is-a-task has-subtask))))
2114 (defun bh/is-subproject-p ()
2115 "Any task which is a subtask of another project"
2116 (let ((is-subproject)
2117 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2119 (while (and (not is-subproject) (org-up-heading-safe))
2120 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2121 (setq is-subproject t))))
2122 (and is-a-task is-subproject)))
2125 (defun bh/clock-in-to-next (kw)
2126 "Switch a task from TODO to NEXT when clocking in.
2127 Skips capture tasks, projects, and subprojects.
2128 Switch projects and subprojects from NEXT back to TODO"
2129 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2131 ((and (member (org-get-todo-state) (list "TODO"))
2134 ((and (member (org-get-todo-state) (list "NEXT"))
2138 (defun bh/punch-in (arg)
2139 "Start continuous clocking and set the default task to the
2140 selected task. If no task is selected set the Organization task
2141 as the default task."
2143 (setq bh/keep-clock-running t)
2144 (if (equal major-mode 'org-agenda-mode)
2146 ;; We're in the agenda
2148 (let* ((marker (org-get-at-bol 'org-hd-marker))
2149 (tags (org-with-point-at marker (org-get-tags-at))))
2150 (if (and (eq arg 4) tags)
2151 (org-agenda-clock-in '(16))
2152 (bh/clock-in-organization-task-as-default)))
2154 ;; We are not in the agenda
2158 ; Find the tags on the current task
2159 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2160 (org-clock-in '(16))
2161 (bh/clock-in-organization-task-as-default)))))
2163 (defun bh/punch-out ()
2165 (setq bh/keep-clock-running nil)
2166 (when (org-clock-is-active)
2168 (org-agenda-remove-restriction-lock))
2170 (defun bh/clock-in-default-task ()
2172 (org-with-point-at org-clock-default-task
2175 (defun bh/clock-in-parent-task ()
2176 "Move point to the parent (project) task if any and clock in"
2177 (let ((parent-task))
2181 (while (and (not parent-task) (org-up-heading-safe))
2182 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2183 (setq parent-task (point))))
2185 (org-with-point-at parent-task
2187 (when bh/keep-clock-running
2188 (bh/clock-in-default-task)))))))
2190 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2192 (defun bh/clock-in-organization-task-as-default ()
2194 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2195 (org-clock-in '(16))))
2197 (defun bh/clock-out-maybe ()
2198 (when (and bh/keep-clock-running
2199 (not org-clock-clocking-in)
2200 (marker-buffer org-clock-default-task)
2201 (not org-clock-resolving-clocks-due-to-idleness))
2202 (bh/clock-in-parent-task)))
2204 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2207 (defun bh/clock-in-task-by-id (id)
2208 "Clock in a task by id"
2209 (org-with-point-at (org-id-find id 'marker)
2210 (org-clock-in nil)))
2212 (defun bh/clock-in-last-task (arg)
2213 "Clock in the interrupted task if there is one
2214 Skip the default task and get the next one.
2215 A prefix arg forces clock in of the default task."
2217 (let ((clock-in-to-task
2219 ((eq arg 4) org-clock-default-task)
2220 ((and (org-clock-is-active)
2221 (equal org-clock-default-task (cadr org-clock-history)))
2222 (caddr org-clock-history))
2223 ((org-clock-is-active) (cadr org-clock-history))
2224 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2225 (t (car org-clock-history)))))
2227 (org-with-point-at clock-in-to-task
2228 (org-clock-in nil))))
2231 (defun org-export-to-ods ()
2233 (let ((csv-file "data.csv"))
2234 (org-table-export csv-file "orgtbl-to-csv")
2235 (org-odt-convert csv-file "ods" 'open)))
2237 ; allow for zero-width-space to be a break in regexp too
2238 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
2239 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
2240 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2242 ;; support inserting screen shots
2243 (defun my/org-insert-screenshot ()
2244 "Take a screenshot into a time stamped unique-named file in the
2245 same directory as the org-buffer and insert a link to this file."
2247 (defvar my/org-insert-screenshot/filename)
2248 (setq my/org-insert-screenshot/filename
2250 "Screenshot to insert: "
2252 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2255 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2256 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2257 (org-display-inline-images))
2259 (defun my/fix-inline-images ()
2260 (when org-inline-image-overlays
2261 (org-redisplay-inline-images)))
2263 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2265 ;; use xelatex to preview with imagemagick
2266 (add-to-list 'org-preview-latex-process-alist
2267 '(xelateximagemagick
2268 :programs ("xelatex" "convert")
2269 :description "pdf > png"
2270 :message "you need to install xelatex and imagemagick"
2272 :image-input-type "pdf"
2273 :image-output-type "png"
2274 :image-size-adjust (1.0 . 1.0)
2275 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2276 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2278 ;; use xelatex by default
2279 (setq org-preview-latex-default-process 'xelateximagemagick)
2281 ; from http://orgmode.org/Changes.html
2282 (defun my/org-repair-property-drawers ()
2283 "Fix properties drawers in current buffer.
2284 Ignore non Org buffers."
2286 (when (eq major-mode 'org-mode)
2287 (org-with-wide-buffer
2288 (goto-char (point-min))
2289 (let ((case-fold-search t)
2290 (inline-re (and (featurep 'org-inlinetask)
2291 (concat (org-inlinetask-outline-regexp)
2295 (unless (and inline-re (org-looking-at-p inline-re))
2297 (let ((end (save-excursion (outline-next-heading) (point))))
2299 (when (org-looking-at-p org-planning-line-re) (forward-line))
2300 (when (and (< (point) end)
2301 (not (org-looking-at-p org-property-drawer-re))
2303 (and (re-search-forward org-property-drawer-re end t)
2304 (eq (org-element-type
2305 (save-match-data (org-element-at-point)))
2307 (insert (delete-and-extract-region
2309 (min (1+ (match-end 0)) end)))
2310 (unless (bolp) (insert "\n"))))))))))))
2314 #+BEGIN_SRC emacs-lisp
2318 (use-package calfw-org
2321 (use-package org-gcal
2323 :config '((if (file-readable-p "~/.hide/org_gcal.el")
2324 (load-file "~/.hide/org_gcal.el"))
2329 #+BEGIN_SRC emacs-lisp
2333 ;; Show notification 10 minutes before event
2334 (setq appt-message-warning-time 10)
2335 ;; Disable multiple reminders
2336 (setq appt-display-interval appt-message-warning-time)
2337 (setq appt-display-mode-line nil)
2339 ;; add automatic reminders for appointments
2340 (defun my/org-agenda-to-appt ()
2342 (setq appt-time-msg-list nil)
2343 (org-agenda-to-appt))
2344 ;; add reminders when starting emacs
2345 (my/org-agenda-to-appt)
2346 ;; when rebuilding the agenda
2347 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
2348 "Pressing `r' on the agenda will also add appointments."
2349 (my/org-agenda-to-appt)
2351 ;; when saving all org buffers
2352 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2353 "Re-add appts after saving all org buffers"
2354 (my/org-agenda-to-appt))
2355 ;; Display appointments as a window manager notification
2356 (setq appt-disp-window-function 'my/appt-display)
2357 (setq appt-delete-window-function (lambda () t))
2359 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2361 (defun my/appt-display (min-to-app new-time msg)
2362 (if (atom min-to-app)
2363 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2364 (dolist (i (number-sequence 0 (1- (length min-to-app))))
2365 (start-process "my/appt-notification-app" nil my/appt-notification-app
2366 (nth i min-to-app) (nth i msg))))
2373 #+BEGIN_SRC emacs-lisp
2378 #+BEGIN_SRC emacs-lisp
2379 (global-unset-key "\M-g")
2380 (global-set-key (kbd "M-g l") 'goto-line)
2384 #+BEGIN_SRC emacs-lisp
2385 (use-package debian-changelog-mode
2386 :mode "debian/changelog"
2388 (setq debian-changelog-mailing-address "don@debian.org")
2389 (setq debian-changelog-full-name "Don Armstrong"))
2391 * Misc (uncharacterized)
2392 #+BEGIN_SRC emacs-lisp
2393 (setq calendar-latitude 38.6)
2394 (setq calendar-longitude -121.5)
2395 (setq case-fold-search t)
2396 (setq confirm-kill-emacs (quote y-or-n-p))
2397 (setq cperl-lazy-help-time nil)
2398 (global-font-lock-mode 1)
2400 (setq log-edit-keep-buffer t)
2401 (setq mail-user-agent (quote sendmail-user-agent))
2402 (setq markdown-enable-math t)
2403 (setq markdown-follow-wiki-link-on-enter nil)
2404 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2405 (setq ps-footer-font-size (quote (8 . 10)))
2406 (setq ps-header-font-size (quote (8 . 10)))
2407 (setq ps-header-title-font-size (quote (10 . 10)))
2408 (setq ps-line-number-color "blue")
2409 (setq ps-print-footer t)
2410 (setq ps-print-footer-frame nil)
2411 (setq ps-print-only-one-header t)
2412 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
2414 (setq sentence-end-double-space nil)
2415 ; enable matching parenthesis
2418 (setq user-mail-address "don@donarmstrong.com")
2419 (setq vc-delete-logbuf-window nil)
2420 (setq vc-follow-symlinks t)
2422 ;; use git before SVN; use CVS earlier, because I have CVS
2423 ;; repositories inside of git directories
2424 (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
2426 ;; switch back to the old primary selection method
2427 (setq x-select-enable-clipboard nil)
2428 (setq x-select-enable-primary t)
2429 ; (setq mouse-drag-copy-region t)
2431 (fset 'perl-mode 'cperl-mode)
2432 ;;(load-file "cperl-mode.el")
2434 ;; tramp configuration
2435 (setq tramp-use-ssh-controlmaster-options nil)
2437 (setq-default c-indent-level 4)
2438 (setq-default c-brace-imaginary-offset 0)
2439 (setq-default c-brace-offset -4)
2440 (setq-default c-argdecl-indent 4)
2441 (setq-default c-label-offset -4)
2442 (setq-default c-continued-statement-offset 4)
2444 (setq-default indent-tabs-mode nil)
2445 (setq-default tab-width 4)
2448 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2449 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2450 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2451 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2452 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2455 (defun insert-date ()
2456 "Insert date at point."
2458 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2459 (global-set-key "\C-[d" 'insert-date)
2461 (defun unfill-paragraph (arg)
2462 "Pull this whole paragraph up onto one line."
2464 (let ((fill-column 10000))
2465 (fill-paragraph arg))
2468 (column-number-mode t)
2471 ** Desktop-save-mode
2472 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2473 emacs, and use a different desktop file to restore history
2474 #+BEGIN_SRC emacs-lisp
2475 (use-package desktop
2478 (setq desktop-base-file-name
2479 (convert-standard-filename
2481 (or (getenv "EMACS_SERVER_NAME")
2485 (setq desktop-base-lock-name
2486 (convert-standard-filename
2487 (concat desktop-base-file-name
2489 (setq desktop-auto-save-timeout 60)
2490 (setq desktop-restore-eager 5)
2491 (setq desktop-lazy-verbose nil)
2492 (desktop-save-mode 1)
2496 ** Misc (Uncharacterized)
2497 #+BEGIN_SRC emacs-lisp
2498 '(icomplete-mode on)
2500 ;; custom-set-faces was added by Custom.
2501 ;; If you edit it by hand, you could mess it up, so be careful.
2502 ;; Your init file should contain only one such instance.
2503 ;; If there is more than one, they won't work right.
2504 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2507 (put 'upcase-region 'disabled nil)
2508 (put 'downcase-region 'disabled nil)
2509 (put 'narrow-to-region 'disabled nil)
2511 ; (defun turn-on-flyspell ()
2512 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2514 ; (flyspell-mode 1))
2517 ; Outline-minor-mode key map
2518 (define-prefix-command 'cm-map nil "Outline-")
2520 (define-key cm-map "q" 'outline-hide-sublevels) ; Hide everything but the top-level headings
2521 (define-key cm-map "t" 'outline-hide-body) ; Hide everything but headings (all body lines)
2522 (define-key cm-map "o" 'outline-hide-other) ; Hide other branches
2523 (define-key cm-map "c" 'outline-hide-entry) ; Hide this entry's body
2524 (define-key cm-map "l" 'outline-hide-leaves) ; Hide body lines in this entry and sub-entries
2525 (define-key cm-map "d" 'outline-hide-subtree) ; Hide everything in this entry and sub-entries
2527 (define-key cm-map "a" 'outline-show-all) ; Show (expand) everything
2528 (define-key cm-map "e" 'outline-show-entry) ; Show this heading's body
2529 (define-key cm-map "i" 'outline-show-children) ; Show this heading's immediate child sub-headings
2530 (define-key cm-map "k" 'outline-show-branches) ; Show all sub-headings under this heading
2531 (define-key cm-map "s" 'outline-show-subtree) ; Show (expand) everything in this heading & below
2533 (define-key cm-map "u" 'outline-up-heading) ; Up
2534 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2535 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2536 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2537 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2538 (global-set-key "\M-o" cm-map)
2539 ; fix up tmux xterm keys
2540 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2541 (defun fix-up-tmux-keys ()
2542 "Fix up tmux xterm keys"
2545 (let ((x 2) (tkey ""))
2565 ;; ctrl + alt + shift
2567 (setq tkey "C-M-S-"))
2570 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2571 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2572 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2573 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2575 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2577 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2579 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2581 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2583 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2585 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2587 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2589 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2591 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2593 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2595 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2597 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2599 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2601 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2603 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2605 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2607 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2609 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2611 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2613 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2615 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2617 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2619 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2621 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2623 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2625 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2632 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2634 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2635 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2636 (if (or (buffer-modified-p)
2637 (verify-visited-file-modtime)
2638 (< (* 8 1024 1024) (buffer-size))
2639 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2641 (clear-visited-file-modtime)
2643 (ad-activate 'ask-user-about-supersession-threat)
2647 #+BEGIN_SRC emacs-lisp
2651 (or (getenv "EMACS_SERVER_NAME")
2653 (unless (server-running-p)
2654 (global-set-key "\C-xp" 'server-edit)
2661 #+BEGIN_SRC emacs-lisp
2662 (provide 'don-configuration)