1 #+PROPERTY: header-args:emacs-lisp :tangle don-configuration.el
4 # if for some reason, things get pear-shaped, we want to be able to
5 # enter the debugger by sending -USR2 to emacs
8 (setq debug-on-event 'siguser2)
10 * Initial startup stuff
11 ** Disable startup screen
12 #+BEGIN_SRC emacs-lisp
13 (setq inhibit-startup-screen t)
16 #+BEGIN_SRC emacs-lisp
17 ; (if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
18 (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
19 (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
22 #+BEGIN_SRC emacs-lisp
23 (setq frame-resize-pixelwise t)
24 (add-to-list 'default-frame-alist '(fullscreen . maximixed))
27 ** package repositories and package manager
28 Borrowed from https://github.com/nilcons/emacs-use-package-fast/ to
29 load [[https://github.com/jwiegley/use-package/][use-package]] even faster
30 #+BEGIN_SRC emacs-lisp
32 ;; add /etc/ssl/ca-global/ca-certificates.crt so that we can
33 ;; download packages when we're on Debian hosts which chop down the
34 ;; list of available certificates
36 (add-to-list 'gnutls-trustfiles "/etc/ssl/ca-global/ca-certificates.crt")
37 (setq package-enable-at-startup nil)
38 (setq package--init-file-ensured t)
39 (setq package-user-dir "~/var/emacs/elpa")
40 (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
41 ("melpa" . "https://melpa.org/packages/")
42 ("org" . "http://orgmode.org/elpa/")))
43 (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
44 (mapc #'(lambda (add) (add-to-list 'load-path add))
47 (unless (package-installed-p 'use-package)
48 (package-refresh-contents)
49 (package-install 'use-package))
50 (let ((package-user-dir-real (file-truename package-user-dir)))
51 ;; The reverse is necessary, because outside we mapc
52 ;; add-to-list element-by-element, which reverses.
53 (nreverse (apply #'nconc
54 ;; Only keep package.el provided loadpaths.
55 (mapcar #'(lambda (path)
56 (if (string-prefix-p package-user-dir-real path)
61 ;;; fix up info paths for packages
62 (with-eval-after-load "info"
64 (dolist (dir (directory-files package-user-dir))
65 (let ((fdir (concat (file-name-as-directory package-user-dir) dir)))
66 (unless (or (member dir '("." ".." "archives" "gnupg"))
67 (not (file-directory-p fdir))
68 (not (file-exists-p (concat (file-name-as-directory fdir) "dir"))))
69 (add-to-list 'Info-directory-list fdir)))))
73 (require 'use-package))
78 #+BEGIN_SRC emacs-lisp
81 :commands (paradox-upgrade-packages paradox-list-packages)
82 :config (setq paradox-execute-asynchronously t)
87 #+BEGIN_SRC emacs-lisp
88 (add-to-list 'load-path '"~/lib/emacs_el/")
89 (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
92 #+BEGIN_SRC emacs-lisp
93 ;; Set the custom file to /dev/null and don't bother to load it
94 (setq custom-file "/dev/null")
98 #+BEGIN_SRC emacs-lisp
99 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
100 ;; execute conditional code when loading libraries
101 (defmacro with-library (symbol &rest body)
102 `(when (require ,symbol nil t)
104 (put 'with-library 'lisp-indent-function 1)
108 ** Safe Local Variables
109 #+BEGIN_SRC emacs-lisp
110 (setq safe-local-variable-values
111 (quote ((auto-save-default)
113 (cperl-indent-level . 4)
115 (indent-tabs-mode . f)
116 (vcl-indent-level . 4)
120 #+BEGIN_SRC emacs-lisp
121 (setq global-mark-ring-max 128
125 (defun don/minibuffer-setup-hook ()
126 (setq gc-cons-threshold most-positive-fixnum))
128 (defun don/minibuffer-exit-hook ()
129 (setq gc-cons-threshold 1048576))
131 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
132 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
136 #+BEGIN_SRC emacs-lisp
137 (use-package spacemacs-theme
140 (load-theme 'spacemacs-dark)
144 #+BEGIN_SRC emacs-lisp
145 (use-package hippie-exp
146 :bind* (("M-<SPC>" . hippie-expand))
150 #+BEGIN_SRC emacs-lisp
151 (use-package flyspell
153 :diminish flyspell-mode 🐝
155 (add-hook 'text-mode-hook 'turn-on-flyspell)
156 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
157 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
158 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
160 (setq ispell-program-name "ispell")
165 #+begin_src emacs-lisp :tangle yes
171 #+BEGIN_SRC emacs-lisp
176 #+BEGIN_SRC emacs-lisp
177 (use-package eyebrowse
179 :diminish eyebrowse-mode
180 :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
182 (setq eyebrowse-wrap-around t)
185 (defun my/eyebrowse-new-window-config ()
189 ;; start at 1 run till 0
190 (let ((j (mod (+ i 1) 10)))
191 (when (and (not done)
192 (not (eyebrowse--window-config-present-p j)))
193 (eyebrowse-switch-to-window-config j)
194 (call-interactively 'eyebrowse-rename-window-config2 j)
199 ;; I don't use latex-preview-pane
200 ;; (require 'latex-preview-pane)
201 ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
202 ;; ;; latex-preview-pane uses window-parameters which are
203 ;; ;; not preserved by eyebrowse, so we close the preview
204 ;; ;; pane before switching, it will be regenerated when we
205 ;; ;; edit the TeX file.
206 ;; (when (lpp/window-containing-preview)
207 ;; (delete-window (lpp/window-containing-preview))))
209 ;; (add-to-list 'eyebrowse-pre-window-switch-hook
210 ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
212 ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
213 ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
214 ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
215 ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
216 ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
224 #+BEGIN_SRC emacs-lisp
225 (defun my/vsplit-last-buffer ()
226 "Split the window vertically and display the previous buffer."
228 (split-window-vertically)
230 (switch-to-next-buffer))
232 (defun my/hsplit-last-buffer ()
233 "Split the window horizontally and display the previous buffer."
235 (split-window-horizontally)
237 (switch-to-next-buffer))
239 (bind-key "C-x 2" 'my/vsplit-last-buffer)
240 (bind-key "C-x 3" 'my/hsplit-last-buffer)
242 (setq split-width-threshold 100)
243 (setq split-height-threshold 60)
245 (defun my/split-window-prefer-vertically (window)
246 "If there's only one window (excluding any possibly active
247 minibuffer), then split the current window horizontally."
248 (if (and (one-window-p t)
249 (not (active-minibuffer-window))
250 ( < (frame-width) (frame-height))
252 (let ((split-width-threshold nil))
253 (split-window-sensibly window))
254 (split-window-sensibly window)))
256 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
257 (setq window-combination-resize t)
260 *** Compilation window
262 If there is no compilation window, open one at the bottom, spanning
263 the complete width of the frame. Otherwise, reuse existing window. In
264 the former case, if there was no error the window closes
267 #+BEGIN_SRC emacs-lisp
268 (add-to-list 'display-buffer-alist
269 `(,(rx bos "*compilation*" eos)
270 (display-buffer-reuse-window
271 display-buffer-in-side-window)
272 (reusable-frames . visible)
274 (window-height . 0.4)))
277 #+BEGIN_SRC emacs-lisp
278 (defun my/compilation-exit-autoclose (status code msg)
279 ;; If M-x compile exists with a 0
280 (when (and (eq status 'exit) (zerop code))
281 ;; and delete the *compilation* window
282 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
283 (when (and (not (window-at-side-p compilation-window 'top))
284 (window-at-side-p compilation-window 'left)
285 (window-at-side-p compilation-window 'right))
286 (delete-window compilation-window))))
287 ;; Always return the anticipated result of compilation-exit-message-function
290 ;; Specify my function (maybe I should have done a lambda function)
291 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
294 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
295 value, the compilation buffer scrolls automatically to follow the
296 output. If the value is ~first-error~, scrolling stops when the first
297 error appears, leaving point at that error. For any other non-nil
298 value, scrolling continues until there is no more output.
300 #+BEGIN_SRC emacs-lisp
301 (setq compilation-scroll-output 'first-error)
304 ** Mode line cleaning
306 #+BEGIN_SRC emacs-lisp
307 (use-package diminish
312 #+BEGIN_SRC emacs-lisp
319 #+BEGIN_SRC emacs-lisp
321 :if (>= emacs-major-version 25)
323 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
324 ("C-c j j" . avy-goto-word-or-subword-1)
325 ("M-g g" . avy-goto-line))
326 :config (progn (setq avy-background t))
329 *** Ace-link (jumping to links)
330 #+BEGIN_SRC emacs-lisp
331 (use-package ace-link
333 ; bind o in most modes
334 :config (ace-link-setup-default))
336 *** Jumping through edit points (goto-chg)
337 #+BEGIN_SRC emacs-lisp
338 (use-package goto-chg
340 :bind (("C-c j ," . goto-last-change)
341 ("C-c j ." . goto-last-change-reverse))
344 *** Jumping to bookmarks (visible bookmarks, bm)
345 #+BEGIN_SRC emacs-lisp
348 :bind (("C-c j b ." . bm-next)
349 ("C-c j b ," . bm-previous)
350 ("C-c j b SPC" . bm-toggle)))
355 #+BEGIN_SRC emacs-lisp
356 (use-package yasnippet
358 :diminish yas-minor-mode
361 (setq yas-verbosity 1)
362 (define-key yas-minor-mode-map (kbd "<tab>") nil)
363 (define-key yas-minor-mode-map (kbd "TAB") nil)
364 (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
365 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
366 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
367 (add-to-list 'hippie-expand-try-functions-list
368 'yas-hippie-try-expand)
374 #+BEGIN_SRC emacs-lisp
375 (use-package auto-yasnippet
377 :bind (("H-w" . aya-create)
383 #+BEGIN_SRC emacs-lisp
386 :bind (("M-/" . company-complete))
388 (setq company-echo-delay 0 ; remove blinking
389 company-show-numbers t ; show numbers for easy selection
390 company-selection-wrap-around t
391 company-require-match nil
392 company-dabbrev-ignore-case t
393 company-dabbrev-ignore-invisible t
394 company-dabbrev-other-buffers t
395 company-dabbrev-downcase nil
396 company-dabbrev-code-everywhere t
397 company-tooltip-align-annotations t
398 company-minimum-prefix-length 1
399 company-global-modes '(not)
400 company-lighter-base "(C)")
401 (global-company-mode 1)
402 :bind (:map company-active-map
403 ("C-n" . company-select-next)
404 ("C-p" . company-select-previous)
405 ("M-?" . company-show-doc-buffer)
406 ("M-." . company-show-location)
411 #+BEGIN_SRC emacs-lisp
412 (use-package company-c-headers
415 (defun malb/ede-object-system-include-path ()
416 "Return the system include path for the current buffer."
418 (ede-system-include-path ede-object)))
420 (setq company-c-headers-path-system
421 #'malb/ede-object-system-include-path)
423 (add-to-list 'company-backends #'company-c-headers)))
426 #+BEGIN_SRC emacs-lisp
427 (use-package company-anaconda
429 :config (add-to-list 'company-backends #'company-anaconda))
432 #+BEGIN_SRC emacs-lisp
433 (use-package company-plsense
438 #+BEGIN_SRC emacs-lisp
439 (use-package company-math
442 #+BEGIN_SRC emacs-lisp
443 (use-package company-auctex
446 (defun company-auctex-labels (command &optional arg &rest ignored)
447 "company-auctex-labels backend"
448 (interactive (list 'interactive))
450 (interactive (company-begin-backend 'company-auctex-labels))
451 (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
452 (candidates (company-auctex-label-candidates arg))))
454 (add-to-list 'company-backends
455 '(company-auctex-macros
456 company-auctex-environments
457 company-math-symbols-unicode
458 company-math-symbols-latex))
460 (add-to-list 'company-backends #'company-auctex-labels)
461 (add-to-list 'company-backends #'company-auctex-bibs)
465 #+BEGIN_SRC emacs-lisp
466 (use-package company-bibtex
472 #+BEGIN_SRC emacs-lisp
473 (use-package company-shell
476 (setq company-shell-modes '(sh-mode shell-mode))
477 (add-to-list 'company-backends 'company-shell)))
482 Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
484 *Note:* Do this at the end of =company-mode= config.
486 #+BEGIN_SRC emacs-lisp
487 (defvar malb/company-mode/enable-yas t
488 "Enable yasnippet for all backends.")
490 (defun malb/company-mode/backend-with-yas (backend)
491 (if (or (not malb/company-mode/enable-yas)
493 (member 'company-yasnippet backend)))
495 (append (if (consp backend) backend (list backend))
496 '(:with company-yasnippet))))
498 (setq company-backends
499 (mapcar #'malb/company-mode/backend-with-yas company-backends))
504 Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
506 #+BEGIN_SRC emacs-lisp
507 (defun malb/toggle-company-ispell ()
510 ((member '(company-ispell :with company-yasnippet) company-backends)
511 (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
512 (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
513 (message "company-ispell disabled"))
515 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
516 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
517 (message "company-ispell enabled!"))))
519 (defun malb/company-ispell-setup ()
520 ;; @see https://github.com/company-mode/company-mode/issues/50
521 (when (boundp 'company-backends)
522 (make-local-variable 'company-backends)
523 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
524 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
525 ;; https://github.com/redguardtoo/emacs.d/issues/473
526 (if (and (boundp 'ispell-alternate-dictionary)
527 ispell-alternate-dictionary)
528 (setq company-ispell-dictionary ispell-alternate-dictionary))))
533 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
535 2. This function then hopefully does what I want:
537 a. if a region is active, just indent
538 b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
539 c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
540 d. otherwise call whatever would have been called otherwise.
542 ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
544 #+BEGIN_SRC emacs-lisp
545 (defun malb/indent-fold-or-complete (&optional arg)
548 ;; if a region is active, indent
550 (indent-region (region-beginning)
552 ;; if the next char is space or eol, but prev char not whitespace
553 ((and (not (active-minibuffer-window))
556 (looking-back "[^[:space:]]")
557 (not (looking-back "^")))
559 (cond (company-mode (company-complete-common))
560 (auto-complete-mode (auto-complete))))
562 ;; no whitespace anywhere
563 ((and (not (active-minibuffer-window))
564 (looking-at "[^[:space:]]")
565 (looking-back "[^[:space:]]")
566 (not (looking-back "^")))
568 ((bound-and-true-p hs-minor-mode)
569 (save-excursion (end-of-line) (hs-toggle-hiding)))
570 ((bound-and-true-p outline-minor-mode)
571 (save-excursion (outline-cycle)))))
573 ;; by default just call whatever was bound
575 (let ((fn (or (lookup-key (current-local-map) (kbd "TAB"))
576 'indent-for-tab-command)))
577 (if (not (called-interactively-p 'any))
579 (setq this-command fn)
580 (call-interactively fn))))))
582 (defun malb/toggle-fold ()
584 (cond ((eq major-mode 'org-mode)
585 (org-force-cycle-archived))
586 ((bound-and-true-p hs-minor-mode)
591 ((bound-and-true-p outline-minor-mode)
595 (bind-key "<tab>" #'malb/indent-fold-or-complete)
596 (bind-key "C-<tab>" #'malb/toggle-fold)
600 #+BEGIN_SRC emacs-lisp
602 (use-package tinyprocmail
603 :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
604 :mode (".procmailrc" . turn-on-tinyprocmail-mode)
609 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
612 :bind (("C-x g" . magit-status)
613 ("C-x C-g" . magit-status))
615 ;; refine diffs always (hilight words)
616 (setq magit-diff-refine-hunk nil)
618 (use-package magit-annex
620 :load-path "~/lib/emacs_el/magit-annex/"
622 (use-package magit-vcsh
623 :ensure f ; currently not in melpa, so don't try to install
624 :load-path "~/lib/emacs_el/magit-vcsh/"
629 #+BEGIN_SRC emacs-lisp
630 (use-package cperl-mode
633 ;; Use c-mode for perl .xs files
634 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
635 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
636 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
637 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
638 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
641 cperl-auto-newline nil
642 cperl-auto-newline-after-colon nil
643 cperl-continued-statement-offset 4
644 cperl-brace-offset -1
645 cperl-continued-brace-offset 0
646 cperl-label-offset -4
647 cperl-highlight-variables-indiscriminately t
648 cperl-electric-lbrace-space nil
649 cperl-indent-parens-as-block nil
650 cperl-close-paren-offset -1
651 cperl-tab-always-indent t)
652 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
657 #+BEGIN_SRC emacs-lisp
658 (use-package markdown-mode
660 :mode (("\\.md\\'" . markdown-mode)
661 ("\\.mdwn\\'" . markdown-mode)
662 ("README\\.md\\'" . gfm-mode)
665 (setq markdown-enable-math t)
666 (setq markdown-follow-wiki-link-on-enter nil)
667 (bind-key "M-." #'markdown-jump markdown-mode-map)
668 (add-hook 'markdown-mode-hook #'flyspell-mode)
669 (add-hook 'markdown-mode-hook #'outline-minor-mode)
670 (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
675 #+BEGIN_SRC emacs-lisp
676 ; load sql-indent when sql is loaded
678 :mode (("\\.sql\\'" . sql-mode))
680 (require sql-indent))
683 #+BEGIN_SRC emacs-lisp
685 :commands ediff ediff3
688 ;; ediff configuration
689 ;; don't use the multi-window configuration
690 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
693 ** Do the Right Thing Indenting
694 Attempts to automatically identify the right indentation for a file
695 #+BEGIN_SRC emacs-lisp
696 (use-package dtrt-indent
700 ** VCL --editing varnish configuration files
701 #+BEGIN_SRC emacs-lisp
702 (use-package vcl-mode
709 #+BEGIN_SRC emacs-lisp
710 (defun malb/helm-omni (&rest arg)
711 ;; just in case someone decides to pass an argument, helm-omni won't fail.
713 (unless helm-source-buffers-list
714 (setq helm-source-buffers-list
715 (helm-make-source "Buffers" 'helm-source-buffers)))
719 (if (projectile-project-p)
720 '(helm-source-projectile-buffers-list
721 helm-source-buffers-list)
722 '(helm-source-buffers-list)) ;; list of all open buffers
724 `(((name . "Virtual Workspace")
725 (candidates . ,(--map (cons (eyebrowse-format-slot it) (car it))
726 (eyebrowse--get 'window-configs)))
727 (action . (lambda (candidate)
728 (eyebrowse-switch-to-window-config candidate)))))
730 (if (projectile-project-p)
731 '(helm-source-projectile-recentf-list
733 '(helm-source-recentf)) ;; all recent files
735 ;; always make some common files easily accessible
736 ;;'(((name . "Common Files")
737 ;; (candidates . malb/common-file-targets)
738 ;; (action . (("Open" . (lambda (x) (find-file (eval x))))))))
740 '(helm-source-files-in-current-dir
742 helm-source-bookmarks
743 helm-source-buffer-not-found ;; ask to create a buffer otherwise
745 "*Helm all the things*"))
749 :bind (("M-x" . helm-M-x)
750 ("C-x C-f" . helm-find-files)
751 ("C-x b" . helm-buffers-list) ; malb/helm-omni)
752 ("C-x C-b" . helm-buffers-list) ; malb/helm-omni)
753 ("C-c <SPC>" . helm-all-mark-rings))
755 (require 'helm-config)
756 (require 'helm-for-files)
757 (require 'helm-bookmark)
760 (define-key global-map [remap find-file] 'helm-find-files)
761 (define-key global-map [remap occur] 'helm-occur)
762 (define-key global-map [remap list-buffers] 'helm-buffers-list)
763 (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
764 (unless (boundp 'completion-in-region-function)
765 (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
766 (define-key emacs-lisp-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point))
767 (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
772 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
774 #+BEGIN_SRC emacs-lisp
775 (use-package helm-flx
778 ;; these are helm configs, but they kind of fit here nicely
779 (setq helm-M-x-fuzzy-match t
780 helm-bookmark-show-location t
781 helm-buffers-fuzzy-matching t
782 helm-completion-in-region-fuzzy-match t
783 helm-file-cache-fuzzy-match t
784 helm-imenu-fuzzy-match t
785 helm-mode-fuzzy-match t
786 helm-locate-fuzzy-match nil
788 helm-recentf-fuzzy-match nil
789 helm-semantic-fuzzy-match t)
793 #+BEGIN_SRC emacs-lisp
795 ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
796 (defun malb/helm-swoop-pre-fill ()
797 (thing-at-point 'symbol))
798 (defvar malb/helm-swoop-ignore-major-mode "List of major modes to ignore for helm-swoop")
799 (setq malb/helm-swoop-ignore-major-mode '(dired-mode
800 paradox-menu-mode doc-view-mode pdf-view-mode
801 mu4e-headers-mode org-mode markdown-mode latex-mode
802 ein:notebook-multilang-mode))
804 (defun malb/swoop-or-search ()
806 (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
807 (memq major-mode malb/helm-swoop-ignore-major-mode))
811 (use-package helm-swoop
814 :bind (("C-c o" . helm-multi-swoop-org)
815 ("C-s" . malb/swoop-or-search)
816 ("C-M-s" . helm-multi-swoop-all))
819 (setq helm-swoop-pre-input-function #'malb/helm-swoop-pre-fill
820 helm-swoop-split-with-multiple-windows nil
821 helm-swoop-split-direction #'split-window-horizontally
822 helm-swoop-split-window-function 'helm-default-display-buffer
823 helm-swoop-speed-or-color t)
825 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
826 (defun malb/helm-swoop-C-s ()
828 (if (boundp 'helm-swoop-pattern)
829 (if (equal helm-swoop-pattern "")
830 (previous-history-element 1)
834 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
835 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
836 (bind-key "C-r" #'helm-previous-line helm-swoop-map)
837 (bind-key "C-s" #'malb/helm-swoop-C-s helm-swoop-map)
838 (bind-key "C-r" #'helm-previous-line helm-multi-swoop-map)
839 (bind-key "C-s" #'malb/helm-swoop-C-s helm-multi-swoop-map))
844 #+BEGIN_SRC emacs-lisp
847 :config (setq helm-ag-base-command "ag --nocolor --nogroup"
848 helm-ag-command-option "--all-text"
849 helm-ag-insert-at-point 'symbol
850 helm-ag-fuzzy-match t
851 helm-ag-use-temp-buffer t
852 helm-ag-use-grep-ignore-list t
853 helm-ag-use-agignore t))
856 #+BEGIN_SRC emacs-lisp
857 (use-package helm-descbinds
859 :bind ("C-h b" . helm-descbinds)
860 :init (fset 'describe-bindings 'helm-descbinds))
864 #+BEGIN_SRC emacs-lisp
865 (use-package helm-c-yasnippet
867 :bind ("C-c h y" . helm-yas-complete)
869 (setq helm-yas-space-match-any-greedy t)))
872 #+BEGIN_SRC emacs-lisp
873 (use-package helm-org-rifle
876 (defun malb/helm-org-rifle-agenda-files (arg)
878 (let ((current-prefix-arg nil))
880 ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
881 ((equal arg 16) (helm-org-rifle-occur-agenda-files))
882 (t (helm-org-agenda-files-headings)))))))
885 This can be used to link things pretty quickly if necessary
886 #+BEGIN_SRC emacs-lisp
887 (use-package helm-google
889 :bind ("C-c h g" . helm-google)
891 (progn (add-to-list 'helm-google-actions
892 '("Copy URL" . (lambda (candidate)
894 (replace-regexp-in-string
895 "https://.*q=\\(.*\\)\&sa=.*"
901 (add-to-list 'helm-google-actions
902 '("Org Store Link" . (lambda (candidate)
903 (let ((title (car (split-string candidate "[\n]+")))
905 (replace-regexp-in-string
906 "https://.*q=\\(.*\\)\&sa=.*"
908 (push (list url title) org-stored-links))))
913 ** Projectile -- Project management
914 #+begin_src emacs-lisp
915 (use-package projectile
917 :bind (("<f5>" . projectile-compile-project)
918 ("<f6>" . next-error))
920 (use-package magit :ensure t)
921 (require 'helm-projectile)
924 (setq projectile-make-test-cmd "make check"
925 projectile-switch-project-action 'helm-projectile
926 projectile-mode-line '(:eval (format "»{%s}" (projectile-project-name))))
928 (projectile-global-mode)))
932 #+begin_src emacs-lisp
933 (use-package helm-projectile
936 (defvar malb/helm-source-file-not-found
937 (helm-build-dummy-source
942 'helm-projectile-sources-list
943 malb/helm-source-file-not-found t)
945 (helm-delete-action-from-source
946 "Grep in projects `C-s'"
947 helm-source-projectile-projects)
949 (helm-add-action-to-source
950 "Grep in projects `C-s'"
951 'helm-do-ag helm-source-projectile-projects 4)))
954 #+BEGIN_SRC emacs-lisp
957 :bind ("M-z" . avy-zap-up-to-char-dwim))
960 #+BEGIN_SRC emacs-lisp
962 :bind (("C-c 2" . my/hydra-orgmodes/body)
963 ("C-c @" . my/hydra-orgmodes/body)
964 ("C-c #" . my/hydra-outline/body)
965 ("C-c 3" . my/hydra-outline/body)
968 (defhydra my/hydra-orgmodes (:color blue :hint nil)
970 _n_: notes _c_: chaim _w_: wildman _o_: ool
971 _u_: uddin _s_: steve _r_: refile _f_: fh
972 _p_: read papers _R_: paper notes
977 ("n" (find-file "~/projects/org-notes/notes.org"))
978 ("c" (find-file "~/projects/org-notes/chaim.org"))
979 ("w" (find-file "~/projects/org-notes/wildman.org"))
980 ("u" (find-file "~/projects/org-notes/uddin.org"))
981 ("o" (find-file "~/projects/org-notes/ool.org"))
982 ("f" (find-file "~/projects/org-notes/fh.org"))
983 ("s" (find-file "~/projects/org-notes/sndservers.org"))
984 ("r" (find-file "~/projects/org-notes/refile.org"))
985 ("p" (find-file "~/projects/research/papers_to_read.org"))
986 ("R" (find-file "~/projects/research/paper_notes.org"))
987 ("h" (find-file "~/projects/org-notes/hpcbio.org"))
992 ;; from https://github.com/abo-abo/hydra/wiki/Emacs
993 (defhydra my/hydra-outline (:color pink :hint nil)
996 ^^^^^^------------------------------------------------------
997 _q_: sublevels _a_: all _u_: up
998 _t_: body _e_: entry _n_: next visible
999 _o_: other _i_: children _p_: previous visible
1000 _c_: entry _k_: branches _f_: forward same level
1001 _l_: leaves _s_: subtree _b_: backward same level
1006 ("q" outline-hide-sublevels) ; Hide everything but the top-level headings
1007 ("t" outline-hide-body) ; Hide everything but headings (all body lines)
1008 ("o" outline-hide-other) ; Hide other branches
1009 ("c" outline-hide-entry) ; Hide this entry's body
1010 ("l" outline-hide-leaves) ; Hide body lines in this entry and sub-entries
1011 ("d" outline-hide-subtree) ; Hide everything in this entry and sub-entries
1013 ("a" outline-show-all) ; Show (expand) everything
1014 ("e" outline-show-entry) ; Show this heading's body
1015 ("i" outline-show-children) ; Show this heading's immediate child sub-headings
1016 ("k" outline-show-branches) ; Show all sub-headings under this heading
1017 ("s" outline-show-subtree) ; Show (expand) everything in this heading & below
1019 ("u" outline-up-heading) ; Up
1020 ("n" outline-next-visible-heading) ; Next
1021 ("p" outline-previous-visible-heading) ; Previous
1022 ("f" outline-forward-same-level) ; Forward - same level
1023 ("b" outline-backward-same-level) ; Backward - same level
1029 #+BEGIN_SRC emacs-lisp
1032 (add-to-list 'tramp-methods '("vcsh"
1033 (tramp-login-program "vcsh")
1037 (tramp-remote-shell "/bin/sh")
1038 (tramp-remote-shell-args
1042 #+BEGIN_SRC emacs-lisp
1046 (setq-default reftex-default-bibliography
1047 '("~/projects/research/references.bib")))
1050 #+BEGIN_SRC emacs-lisp
1052 :config (setq bibtex-user-optional-fields
1053 (quote (("annote" "Personal annotation (ignored)")
1061 #+BEGIN_SRC emacs-lisp
1066 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1067 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1068 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1069 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
1070 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
1071 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1072 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1073 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
1074 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
1075 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
1076 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
1078 (setq-default reftex-plug-into-AUCTeX t)
1079 ;; support fake section headers
1080 (setq TeX-outline-extra
1084 ("%subsubsection" 4)
1086 ;; add font locking to the headers
1087 (font-lock-add-keywords
1089 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1090 0 'font-lock-keyword-face t)
1091 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
1092 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
1093 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
1094 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1095 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
1097 ;; use smart quotes by default instead of `` and ''
1098 ;; taken from http://kieranhealy.org/esk/kjhealy.html
1099 (setq TeX-open-quote "“")
1100 (setq TeX-close-quote "”")
1102 ;; (TeX-add-style-hook
1107 ;; (custom-set-variables
1108 ;; '(font-latex-user-keyword-classes
1111 ;; font-lock-function-name-face 2 (command 1 t))))
1113 (setq-default TeX-parse-self t)
1114 (setq-default TeX-auto-save t)
1115 (setq-default TeX-master nil)
1118 '(TeX-add-style-hook
1121 (if (boundp 'reftex-ref-style-alist)
1123 'reftex-ref-style-alist
1124 '("Cleveref" "cleveref"
1125 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1126 (reftex-ref-style-activate "Cleveref")
1128 '("cref" TeX-arg-ref)
1129 '("Cref" TeX-arg-ref)
1130 '("cpageref" TeX-arg-ref)
1131 '("Cpageref" TeX-arg-ref)))))
1134 '(add-to-list 'LaTeX-fill-excluded-macros
1137 (use-package font-latex
1139 (setq font-latex-match-reference-keywords
1161 (setq font-latex-fontify-script nil)
1162 (setq font-latex-fontify-sectioning (quote color))
1163 (setq font-latex-script-display (quote (nil)))
1168 #+BEGIN_SRC emacs-lisp
1172 :mode ("\\.R\\'" . ess-r-mode)
1173 :bind (:map ess-mode-map
1174 ("C-c C-R" . dla/ess-region-remote-eval))
1176 (autoload 'ess-r-mode "ess-site" nil t)
1177 (autoload 'R "ess-site" nil t)
1179 ; actually load the rest of ess
1181 (defun ess-change-directory (path)
1182 "Set the current working directory to PATH for both *R* and Emacs."
1183 (interactive "Directory to change to: ")
1185 (when (file-exists-p path)
1186 (ess-command (concat "setwd(\"" path "\")\n"))
1187 ;; use file-name-as-directory to ensure it has trailing /
1188 (setq default-directory (file-name-as-directory path))))
1189 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1190 ;; outlining support for ess modes
1194 (outline-minor-mode)
1195 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1196 (defun outline-level ()
1197 (cond ((looking-at "^##### ") 1)
1198 ((looking-at "^#### ") 2)
1199 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1202 (defun dla/ess-region-remote-eval (start end)
1203 "Evaluate region in a remote ESS instance"
1205 (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***"))
1206 kill-buffer "***essregionremoteeval***")
1207 ;; Don't restore history or save workspace image
1208 '(inferior-R-args "--no-restore-history --no-save")
1213 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1215 #+BEGIN_SRC emacs-lisp
1216 (use-package rainbow-mode
1217 ;; add ess to the x major mode
1218 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1219 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1224 #+BEGIN_SRC emacs-lisp
1229 (use-package poly-noweb
1234 (use-package poly-markdown
1238 (use-package polymode
1240 :mode ("\\.Snw" . poly-noweb+r-mode)
1241 :mode ("\\.Rnw" . poly-noweb+r-mode)
1242 :mode ("\\.Rmd" . poly-markdown+r-mode)
1249 #+BEGIN_SRC emacs-lisp
1250 (use-package outline-magic)
1253 #+BEGIN_SRC emacs-lisp
1254 ;; change the outline mode prefix from C-c @ to C-c C-2
1255 (setq outline-minor-mode-prefix "C-c C-2")
1256 ;;(add-hook 'outline-minor-mode-hook
1257 ;; (lambda () (local-set-key (kbd "C-c C-2")
1258 ;; outline-mode-prefix-map)))
1262 #+BEGIN_SRC emacs-lisp
1263 (use-package writeroom-mode
1265 (defun my/writing-mode ()
1266 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1271 (visual-line-mode -1)
1273 (visual-fill-column-mode -1)
1275 (visual-line-mode 1)
1277 (visual-fill-column-mode 1)
1282 ** GhostText/Atomic Chrome
1283 #+BEGIN_SRC emacs-lisp
1284 (use-package atomic-chrome
1286 (ignore-errors (atomic-chrome-start-server))
1287 (setq atomic-chrome-buffer-open-style 'full)
1292 :ID: 6fcf218b-a762-4c37-9339-a8202ddeb544
1294 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1295 #+BEGIN_SRC emacs-lisp
1296 (use-package multiple-cursors
1297 :bind* (("C-;" . mc/mark-all-dwim)
1298 ("C-<" . mc/mark-previous-like-this)
1299 ("C->" . mc/mark-next-like-this)
1300 ("C-S-c C-S-c" . mc/edit-lines))
1304 #+BEGIN_SRC emacs-lisp
1305 (use-package web-mode
1306 :load-path "/home/don/projects/web-mode/"
1307 :mode ("\\.\\(tx|tmpl\\)\\'" . web-mode)
1309 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1310 (setq web-mode-enable-engine-detection t)
1311 (setq web-mode-engines-alist
1312 '(("template-toolkit" . "\\.tmpl\\'")))
1315 ** Spamassassin Mode
1316 #+BEGIN_SRC emacs-lisp
1317 (use-package spamassassin-mode
1318 :commands spamassassin-mode
1323 #+BEGIN_SRC emacs-lisp
1324 (use-package password-store
1326 :commands password-store-edit password-store-generate
1330 #+BEGIN_SRC emacs-lisp
1334 ;; fix up css mode to not be silly
1335 ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1336 (setq cssm-indent-level 4)
1337 (setq cssm-newline-before-closing-bracket t)
1338 (setq cssm-indent-function #'cssm-c-style-indenter)
1339 (setq cssm-mirror-mode nil))
1342 #+BEGIN_SRC emacs-lisp
1344 :diminish abbrev-mode
1346 ;; load abbreviations from
1347 (setq abbrev-file-name
1348 "~/.emacs_abbrev_def")
1350 ;; read the abbrev file if it exists
1351 (if (file-exists-p abbrev-file-name)
1352 (quietly-read-abbrev-file))
1354 ;; for now, use abbrev mode everywhere
1355 (setq default-abbrev-mode t))
1359 #+BEGIN_SRC emacs-lisp
1360 (use-package go-mode
1369 #+BEGIN_SRC emacs-lisp
1370 (use-package message
1372 :diminish (message "✉")
1373 :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1374 :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1375 :hook 'my/message-mode-settings
1376 :hook 'turn-on-flyspell
1377 :bind (:map message-mode-map
1378 ("C-c C-a" . my/post-attach-file))
1379 :delight (message-mode "✉")
1381 (defun my/message-mode-settings ()
1382 (font-lock-add-keywords nil
1383 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1384 (0 'message-multiply-quoted-text-face))
1385 ("^[ \t]*>[ \t]*>.*$"
1386 (0 'message-double-quoted-text-face))))
1389 (defun my/post-attach-file ()
1390 "Prompt for an attachment."
1392 (let ((file (read-file-name "Attach file: " nil nil t nil)))
1393 (my/header-attach-file file "")))
1395 (defun my/header-attach-file (file description)
1396 "Attach a FILE to the current message (works with Mutt).
1397 Argument DESCRIPTION MIME description."
1398 (interactive "fAttach file: \nsDescription: ")
1399 (when (> (length file) 0)
1404 (goto-char (point-min))
1405 (search-forward-regexp "^$")
1406 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1408 (message (concat "Attached '" file "'."))
1409 (setq post-has-attachment t))))))
1411 (setq mail-yank-prefix "> ")
1415 #+BEGIN_SRC emacs-lisp
1416 (use-package muttrc-mode
1423 ** Reverting buffers
1424 #+BEGIN_SRC emacs-lisp
1425 (use-package autorevert
1426 :diminish auto-revert-mode
1428 (setq global-auto-revert-non-file-buffers t
1429 global-auto-revert-ignore-modes '(pdf-view-mode)
1430 auto-revert-verbose nil)
1431 (global-auto-revert-mode 1))
1434 ** Use-package and load things
1435 #+BEGIN_SRC emacs-lisp
1438 :delight (org-mode "ø")
1439 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1440 :bind (("C-c l" . org-store-link)
1441 ("C-c a" . org-agenda)
1442 ("C-c b" . org-iswitchb))
1444 ** Agenda Configuration
1445 #+BEGIN_SRC emacs-lisp
1447 (setq-default org-log-done 'time)
1448 (setq-default org-agenda-ndays 5)
1450 (setq org-agenda-sticky t)
1451 (defun dla/show-org-agenda ()
1456 (and (string-match-p
1464 (buffer-name agendabuffer))
1466 (delete-other-windows))
1468 ;; agenda configuration
1469 ;; Do not dim blocked tasks
1470 (setq org-agenda-dim-blocked-tasks nil)
1471 (setq org-agenda-inhibit-startup t)
1472 (setq org-agenda-use-tag-inheritance nil)
1474 ;; Compact the block agenda view
1475 (setq org-agenda-compact-blocks t)
1477 ;; Custom agenda command definitions
1478 (setq org-agenda-custom-commands
1479 (quote (("N" "Notes" tags "NOTE"
1480 ((org-agenda-overriding-header "Notes")
1481 (org-tags-match-list-sublevels t)))
1482 ("h" "Habits" tags-todo "STYLE=\"habit\""
1483 ((org-agenda-overriding-header "Habits")
1484 (org-agenda-sorting-strategy
1485 '(todo-state-down effort-up category-keep))))
1489 ((org-agenda-overriding-header "Tasks to Refile")
1490 (org-tags-match-list-sublevels nil)))
1491 (tags-todo "-CANCELLED/!"
1492 ((org-agenda-overriding-header "Stuck Projects")
1493 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1494 (org-agenda-sorting-strategy
1496 (tags-todo "-HOLD-CANCELLED/!"
1497 ((org-agenda-overriding-header "Projects")
1498 (org-agenda-skip-function 'bh/skip-non-projects)
1499 (org-tags-match-list-sublevels 'indented)
1500 (org-agenda-sorting-strategy
1502 (tags-todo "-CANCELLED/!NEXT"
1503 ((org-agenda-overriding-header (concat "Project Next Tasks"
1504 (if bh/hide-scheduled-and-waiting-next-tasks
1506 " (including WAITING and SCHEDULED tasks)")))
1507 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1508 (org-tags-match-list-sublevels t)
1509 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1510 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1511 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1512 (org-agenda-sorting-strategy
1513 '(todo-state-down effort-up category-keep))))
1514 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1515 ((org-agenda-overriding-header (concat "Project Subtasks"
1516 (if bh/hide-scheduled-and-waiting-next-tasks
1518 " (including WAITING and SCHEDULED tasks)")))
1519 (org-agenda-skip-function 'bh/skip-non-project-tasks)
1520 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1521 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1522 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1523 (org-agenda-sorting-strategy
1525 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1526 ((org-agenda-overriding-header (concat "Standalone Tasks"
1527 (if bh/hide-scheduled-and-waiting-next-tasks
1529 " (including WAITING and SCHEDULED tasks)")))
1530 (org-agenda-skip-function 'bh/skip-project-tasks)
1531 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1532 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1533 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1534 (org-agenda-sorting-strategy
1536 (tags-todo "-CANCELLED+WAITING|HOLD/!"
1537 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1538 (org-agenda-skip-function 'bh/skip-stuck-projects)
1539 (org-tags-match-list-sublevels nil)
1540 (org-agenda-todo-ignore-scheduled t)
1541 (org-agenda-todo-ignore-deadlines t)))
1543 ((org-agenda-overriding-header "Tasks to Archive")
1544 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1545 (org-tags-match-list-sublevels nil))))
1548 ; org mode agenda files
1549 (setq org-agenda-files
1550 (quote ("~/projects/org-notes/debbugs.org"
1551 "~/projects/org-notes/notes.org"
1552 "~/projects/org-notes/holidays.org"
1553 "~/projects/org-notes/refile.org"
1554 "~/projects/org-notes/diary.org"
1555 "~/projects/org-notes/ool.org"
1556 "~/projects/org-notes/sndservers.org"
1557 "~/projects/org-notes/chaim.org"
1558 "~/projects/org-notes/wildman.org"
1559 "~/projects/org-notes/uddin.org"
1560 "~/projects/org-notes/reviews.org"
1561 "~/projects/org-notes/laurel.org"
1562 "~/projects/org-notes/from-calendar.org"
1563 "~/org-mode/from-mobile.org"
1564 "~/projects/org-notes/fh.org")))
1566 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1567 (set-register ?r (cons 'file "~/projects/org-notes/refile.org"))
1568 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1569 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1570 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1571 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1572 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1573 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1574 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1575 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1576 (defun org-agenda-timeline-all (&optional arg)
1579 (dolist (org-agenda-file org-agenda-files)
1580 (insert-file-contents org-agenda-file nil)
1581 (goto-char (point-max))
1583 (write-file "/tmp/timeline.org")
1584 (org-agenda arg "L")))
1585 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1589 #+BEGIN_SRC emacs-lisp
1590 (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")))
1591 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1593 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1594 (setq org-id-link-to-org-use-id 'use-existing)
1596 ** Capture Templates
1597 #+BEGIN_SRC emacs-lisp
1598 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1599 `(("m" "Mail" entry (file "~/projects/org-notes/refile.org")
1600 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1601 ("t" "todo" entry (file "~/projects/org-notes/refile.org")
1602 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1603 ("r" "respond" entry (file "~/projects/org-notes/refile.org")
1604 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1605 ("n" "note" entry (file "~/projects/org-notes/refile.org")
1606 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1607 ("s" "schedule" entry (file "~/projects/org-notes/refile.org")
1608 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1609 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1610 "* %?\n%U\n" :clock-in t :clock-resume t)
1611 ("w" "org-protocol" entry (file "~/projects/org-notes/refile.org")
1612 "* TODO Review %c\n%U\n" :immediate-finish t)
1613 ("M" "Meeting" entry (file "~/projects/org-notes/refile.org")
1614 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1615 ("S" "Seminar" entry (file "~/projects/org-notes/refile.org")
1616 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1617 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1618 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1619 ("p" "Phone call" entry (file "~/projects/org-notes/refile.org")
1620 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1621 ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1623 ,(format-time-string "Positions %Y"))
1624 "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1625 ("h" "Habit" entry (file "~/projects/org-notes/refile.org")
1626 "* 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")
1630 ;; Remove empty LOGBOOK drawers on clock out
1631 (defun bh/remove-empty-drawer-on-clock-out ()
1634 (beginning-of-line 0)
1635 (org-remove-empty-drawer-at (point))))
1637 (defun my/org-add-id ()
1640 (if (org-current-level)
1649 ** Org mode key bindings
1650 #+BEGIN_SRC emacs-lisp
1651 ;; org mode configuration from http://doc.norang.ca/org-mode.html
1652 ;; Custom Key Bindings
1653 :bind* (("<f9> a" . org-agenda)
1654 ("<f9> I" . bh/punch-in)
1655 ("<f9> O" . bh/punch-out)
1656 ("<f9> SPC" . bh/clock-in-last-task)
1657 ("<f12>" . dla/show-org-agenda)
1658 ;; ("<f5>" . bh/org-todo)
1659 ("<S-f5>" . bh/widen)
1660 ("<f7>" . bh/set-truncate-lines)
1661 ("<f8>" . org-cycle-agenda-files)
1662 ("<f9> <f9>" . dla/show-org-agenda)
1664 ("<f9> c" . calendar)
1665 ("<f9> f" . boxquote-insert-file)
1666 ("<f9> h" . bh/hide-other)
1667 ("<f9> n" . bh/toggle-next-task-display)
1670 ("<f9> r" . boxquote-region)
1671 ("<f9> s" . bh/switch-to-scratch)
1673 ("<f9> t" . bh/insert-inactive-timestamp)
1674 ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1676 ("<f9> v" . visible-mode)
1677 ("<f9> l" . org-toggle-link-display)
1678 ("<f9> SPC" . bh/clock-in-last-task)
1679 ("C-<f9>" . previous-buffer)
1680 ("M-<f9>" . org-toggle-inline-images)
1681 ("C-x n r" . narrow-to-region)
1682 ("C-<f10>" . next-buffer)
1683 ("<f11>" . org-clock-goto)
1684 ("C-<f11>" . org-clock-in)
1685 ("C-s-<f12>" . bh/save-then-publish)
1686 ("C-c c" . org-capture))
1689 ** Utility Functions
1690 #+BEGIN_SRC emacs-lisp
1691 (defun bh/hide-other ()
1694 (org-back-to-heading 'invisible-ok)
1700 (defun bh/set-truncate-lines ()
1701 "Toggle value of truncate-lines and refresh window display."
1703 (setq truncate-lines (not truncate-lines))
1704 ;; now refresh window display (an idiom from simple.el):
1706 (set-window-start (selected-window)
1707 (window-start (selected-window)))))
1709 (defun bh/switch-to-scratch ()
1711 (switch-to-buffer "*scratch*"))
1713 (setq org-use-fast-todo-selection t)
1714 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1716 ; create function to create headlines in file. This comes from
1717 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1718 (defun my/org-add-ids-to-headlines-in-file ()
1719 "Add ID properties to all headlines in the current file which
1720 do not already have one."
1722 (org-map-entries 'org-id-get-create))
1723 (defun dla/org-update-ids-to-headlines-in-file ()
1724 "Add or replace ID properties to all headlines in the current file
1725 (or narrowed region)."
1727 (org-map-entries '(lambda () (org-id-get-create t))))
1728 ; if we wanted to do this to every buffer, do the following:
1729 ; (add-hook 'org-mode-hook
1731 ; (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1734 #+BEGIN_SRC emacs-lisp
1735 (use-package find-lisp
1737 (setq org-agenda-text-search-extra-files
1738 (append '(agenda-archives)
1739 (find-lisp-find-files "~/projects/org-notes" "\.org$")
1740 (find-lisp-find-files "~/projects/org-notes" "\.org_archive$")
1744 #+BEGIN_SRC emacs-lisp
1745 (setq org-todo-keywords
1746 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1747 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1749 (setq org-todo-keyword-faces
1750 (quote (("TODO" :foreground "red" :weight bold)
1751 ("NEXT" :foreground "blue" :weight bold)
1752 ("DONE" :foreground "forest green" :weight bold)
1753 ("WAITING" :foreground "orange" :weight bold)
1754 ("HOLD" :foreground "magenta" :weight bold)
1755 ("CANCELLED" :foreground "forest green" :weight bold)
1756 ("MEETING" :foreground "forest green" :weight bold)
1757 ("PHONE" :foreground "forest green" :weight bold))))
1759 (setq org-todo-state-tags-triggers
1760 (quote (("CANCELLED" ("CANCELLED" . t))
1761 ("WAITING" ("WAITING" . t))
1762 ("HOLD" ("WAITING") ("HOLD" . t))
1763 (done ("WAITING") ("HOLD"))
1764 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1765 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1766 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1770 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1771 ; add ids on creation of nodes
1772 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1775 ; resolve clocks after 10 minutes of idle; use xprintidle
1776 ; (setq org-clock-idle-time 10)
1777 ; (setq org-clock-x11idle-program-name "xprintidle")
1779 ; this is from http://doc.norang.ca/org-mode.html#Capture
1780 ; use C-M-r for org mode capture
1781 (global-set-key (kbd "C-M-r") 'org-capture)
1783 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1784 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1785 (org-agenda-files :maxlevel . 9))))
1787 ; Use full outline paths for refile targets - we file directly with IDO
1788 (setq org-refile-use-outline-path t)
1790 ; Targets complete directly with IDO
1791 (setq org-outline-path-complete-in-steps nil)
1793 ; Allow refile to create parent tasks with confirmation
1794 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1796 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1797 ; (setq org-completion-use-ido t)
1798 ; (setq ido-everywhere t)
1799 ; (setq ido-max-directory-size 100000)
1800 ; (ido-mode (quote both))
1801 ; ; Use the current window when visiting files and buffers with ido
1802 ; (setq ido-default-file-method 'selected-window)
1803 ; (setq ido-default-buffer-method 'selected-window)
1804 ; ; Use the current window for indirect buffer display
1805 ; (setq org-indirect-buffer-display 'current-window)
1808 ;;;; Refile settings
1809 ; Exclude DONE state tasks from refile targets
1810 (defun bh/verify-refile-target ()
1811 "Exclude todo keywords with a done state from refile targets"
1812 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1814 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1816 ;; ensure that emacsclient will show just the note to be edited when invoked
1817 ;; from Mutt, and that it will shut down emacsclient once finished;
1818 ;; fallback to legacy behavior when not invoked via org-protocol.
1819 (require 'org-protocol)
1820 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1821 (setq my-org-protocol-flag nil)
1822 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1823 "Delete frame at remember finalization"
1824 (progn (if my-org-protocol-flag (delete-frame))
1825 (setq my-org-protocol-flag nil)))
1826 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1827 "Delete frame at remember refile"
1828 (if my-org-protocol-flag
1830 (setq my-org-protocol-flag nil)
1835 (defadvice org-capture-kill (after delete-frame-at-end activate)
1836 "Delete frame at remember abort"
1837 (progn (if my-org-protocol-flag (delete-frame))
1838 (setq my-org-protocol-flag nil)))
1839 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1840 (setq my-org-protocol-flag t))
1842 (defadvice org-insert-todo-heading (after dla/create-id activate)
1843 (unless (org-in-item-p)
1849 (add-to-list 'org-modules 'org-habit)
1851 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1852 (defun open-mail-in-mutt (message)
1853 "Open a mail message in Mutt, using an external terminal.
1855 Message can be specified either by a path pointing inside a
1856 Maildir, or by Message-ID."
1857 (interactive "MPath or Message-ID: ")
1859 (format "faf xterm -e \"%s %s\""
1860 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1862 ;; add support for "mutt:ID" links
1863 (org-add-link-type "mutt" 'open-mail-in-mutt)
1865 (defun my-org-mode-setup ()
1866 ; (load-library "reftex")
1867 (and (buffer-file-name)
1868 (file-exists-p (buffer-file-name))
1870 ; (reftex-parse-all)
1871 (reftex-set-cite-format
1872 '((?b . "[[bib:%l][%l-bib]]")
1873 (?n . "[[notes:%l][%l-notes]]")
1875 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1877 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1878 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1879 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1880 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1882 (add-hook 'org-mode-hook 'my-org-mode-setup)
1884 (defun org-mode-reftex-search ()
1886 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1888 (defun open-research-paper (bibtexkey)
1889 "Open a paper by bibtex key"
1890 (interactive "bibtex key: ")
1893 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1894 (org-add-link-type "papers" 'open-research-paper)
1895 (defun open-research-paper-pdf (bibtexkey)
1896 "Open a paper pdf by bibtex key"
1897 (interactive "bibtex key: ")
1899 (format "%s -p evince_annot %s"
1900 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1901 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1903 (add-to-list 'org-link-abbrev-alist
1905 "~/projects/research/paper_notes.org::#%s"))
1907 ; I pretty much always want hiearchical checkboxes
1908 (setq org-hierachical-checkbox-statistics nil)
1910 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1911 (add-to-list 'org-structure-template-alist
1912 '("E" "\\begin{equation}\n?\n\\end{equation}"))
1915 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1916 (defun my-rtcite-export-handler (path desc format)
1917 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1918 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1919 (match-string 1 path)))
1920 (path (substring path 0 (match-beginning 0))))
1921 (cond ((eq format 'latex)
1923 (equal 0 (search "rtcite:" desc)))
1924 (format "\\cite{%s}" search)
1925 (format "\\cite[%s]{%s}" desc search))))))
1927 (org-add-link-type "rtcite"
1929 'my-rtcite-export-handler)
1933 ** Org Mobile Configuration
1934 #+BEGIN_SRC emacs-lisp
1935 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
1936 (when (string= system-name "linnode")
1937 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
1938 (setq-default org-directory "/home/don/org-mode/")
1939 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
1943 #+BEGIN_SRC emacs-lisp
1944 ;; org mode ical export
1945 (setq org-icalendar-timezone "America/Los_Angeles")
1946 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
1947 ;; we already add the id manually
1948 (setq org-icalendar-store-UID t)
1951 ** General Org Babel Configuration
1952 #+BEGIN_SRC emacs-lisp
1953 ;; org babel support
1954 (org-babel-do-load-languages
1955 'org-babel-load-languages
1962 ;; set the right path to ditaa.jar
1963 (setq org-ditaa-jar-path "/usr/share/ditaa/ditaa.jar")
1964 ;; use graphviz-dot for dot things
1965 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
1966 ;; do not indent begin_src blocks
1967 (setq org-edit-src-content-indentation 0)
1968 ;; org-babel-by-backend
1969 (defmacro org-babel-by-backend (&rest body)
1970 `(case (if (boundp 'backend)
1971 (org-export-backend-name backend)
1974 (defun my/fix-inline-images ()
1975 (when org-inline-image-overlays
1976 (org-redisplay-inline-images)))
1978 (add-hook 'org-babel-after-execute-hook
1979 'my/fix-inline-images)
1982 ** LaTeX configuration
1984 :ID: 7135ba17-6a50-4eed-84ca-b90afa5b12f8
1986 #+BEGIN_SRC emacs-lisp
1988 (add-to-list 'org-latex-classes
1990 "\\documentclass[11pt,oneside,article]{memoir}\n"
1991 ("\\section{%s}" . "\\section*{%s}")
1992 ("\\subsection{%s}" . "\\subsection*{%s}")
1993 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
1994 ("\\paragraph{%s}" . "\\paragraph*{%s}")
1995 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1997 (setq org-beamer-outline-frame-options "")
1998 (add-to-list 'org-latex-classes
2000 "\\documentclass[ignorenonframetext]{beamer}
2001 [NO-DEFAULT-PACKAGES]
2004 ("\\section{%s}" . "\\section*{%s}")
2005 ("\\subsection{%s}" . "\\subsection*{%s}")
2006 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2007 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2008 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2010 (add-to-list 'org-latex-classes
2012 "\\documentclass[11pt,oneside]{memoir}\n"
2013 ("\\chapter{%s}" . "\\chapter*{%s}")
2014 ("\\section{%s}" . "\\section*{%s}")
2015 ("\\subsection{%s}" . "\\subsection*{%s}")
2016 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
2018 (add-to-list 'org-latex-classes
2020 "\\documentclass[11pt]{letter}
2021 [NO-DEFAULT-PACKAGES]
2024 ("\\section{%s}" . "\\section*{%s}")
2025 ("\\subsection{%s}" . "\\subsection*{%s}")
2026 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2027 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2028 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2030 (add-to-list 'org-latex-classes
2032 "\\documentclass{dlacv}
2033 [NO-DEFAULT-PACKAGES]
2036 ("\\section{%s}" . "\\section*{%s}")
2037 ("\\subsection{%s}" . "\\subsection*{%s}")
2038 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2039 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2040 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2043 (add-to-list 'org-latex-classes
2045 "\\documentclass{dlaresume}
2046 [NO-DEFAULT-PACKAGES]
2049 ("\\section{%s}" . "\\section*{%s}")
2050 ("\\subsection{%s}" . "\\subsection*{%s}")
2051 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2052 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2053 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2056 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
2057 ;; but adapted to use latexmk 4.22 or higher.
2058 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
2060 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
2061 (setq org-latex-default-packages-alist
2063 ("" "unicode-math" t)
2065 (setq org-latex-packages-alist
2072 ("" "longtable" nil)
2075 ;; make equations larger
2076 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2078 (defun org-create-formula--latex-header ()
2079 "Return LaTeX header appropriate for previewing a LaTeX snippet."
2080 (let ((info (org-combine-plists (org-export--get-global-options
2081 (org-export-get-backend 'latex))
2082 (org-export--get-inbuffer-options
2083 (org-export-get-backend 'latex)))))
2084 (org-latex-guess-babel-language
2085 (org-latex-guess-inputenc
2086 (org-splice-latex-header
2087 org-format-latex-header
2088 org-latex-default-packages-alist
2090 (plist-get info :latex-header)))
2094 ; support ignoring headers in org mode export to latex
2095 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2096 (defadvice org-latex-headline (around my-latex-skip-headlines
2097 (headline contents info) activate)
2098 (if (member "ignoreheading" (org-element-property :tags headline))
2099 (setq ad-return-value contents)
2102 ;; keep latex logfiles
2104 (setq org-latex-remove-logfiles nil)
2106 ;; Resume clocking task when emacs is restarted
2107 (org-clock-persistence-insinuate)
2109 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2110 (setq org-clock-history-length 23)
2111 ;; Resume clocking task on clock-in if the clock is open
2112 (setq org-clock-in-resume t)
2113 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2114 ;; there are things like PHONE calls
2115 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2116 ;; Separate drawers for clocking and logs
2117 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2118 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2119 (setq org-clock-into-drawer t)
2120 (setq org-log-into-drawer t)
2121 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2122 (setq org-clock-out-remove-zero-time-clocks t)
2123 ;; Clock out when moving task to a done state
2124 (setq org-clock-out-when-done t)
2125 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2126 (setq org-clock-persist t)
2127 ;; Do not prompt to resume an active clock
2128 (setq org-clock-persist-query-resume nil)
2129 ;; Enable auto clock resolution for finding open clocks
2130 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2131 ;; Include current clocking task in clock reports
2132 (setq org-clock-report-include-clocking-task t)
2134 ;; the cache seems to be broken
2135 (setq org-element-use-cache nil)
2137 (defvar bh/keep-clock-running nil)
2139 (defun bh/is-task-p ()
2140 "Any task with a todo keyword and no subtask"
2144 (subtree-end (save-excursion (org-end-of-subtree t)))
2145 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2148 (while (and (not has-subtask)
2149 (< (point) subtree-end)
2150 (re-search-forward "^\*+ " subtree-end t))
2151 (when (member (org-get-todo-state) org-todo-keywords-1)
2152 (setq has-subtask t))))
2153 (and is-a-task (not has-subtask)))))
2154 (defun bh/is-project-p ()
2155 "Any task with a todo keyword subtask"
2159 (subtree-end (save-excursion (org-end-of-subtree t)))
2160 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2163 (while (and (not has-subtask)
2164 (< (point) subtree-end)
2165 (re-search-forward "^\*+ " subtree-end t))
2166 (when (member (org-get-todo-state) org-todo-keywords-1)
2167 (setq has-subtask t))))
2168 (and is-a-task has-subtask))))
2170 (defun bh/is-subproject-p ()
2171 "Any task which is a subtask of another project"
2172 (let ((is-subproject)
2173 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2175 (while (and (not is-subproject) (org-up-heading-safe))
2176 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2177 (setq is-subproject t))))
2178 (and is-a-task is-subproject)))
2181 (defun bh/clock-in-to-next (kw)
2182 "Switch a task from TODO to NEXT when clocking in.
2183 Skips capture tasks, projects, and subprojects.
2184 Switch projects and subprojects from NEXT back to TODO"
2185 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2187 ((and (member (org-get-todo-state) (list "TODO"))
2190 ((and (member (org-get-todo-state) (list "NEXT"))
2194 (defun bh/punch-in (arg)
2195 "Start continuous clocking and set the default task to the
2196 selected task. If no task is selected set the Organization task
2197 as the default task."
2199 (setq bh/keep-clock-running t)
2200 (if (equal major-mode 'org-agenda-mode)
2202 ;; We're in the agenda
2204 (let* ((marker (org-get-at-bol 'org-hd-marker))
2205 (tags (org-with-point-at marker (org-get-tags-at))))
2206 (if (and (eq arg 4) tags)
2207 (org-agenda-clock-in '(16))
2208 (bh/clock-in-organization-task-as-default)))
2210 ;; We are not in the agenda
2214 ; Find the tags on the current task
2215 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2216 (org-clock-in '(16))
2217 (bh/clock-in-organization-task-as-default)))))
2219 (defun bh/punch-out ()
2221 (setq bh/keep-clock-running nil)
2222 (when (org-clock-is-active)
2224 (org-agenda-remove-restriction-lock))
2226 (defun bh/clock-in-default-task ()
2228 (org-with-point-at org-clock-default-task
2231 (defun bh/clock-in-parent-task ()
2232 "Move point to the parent (project) task if any and clock in"
2233 (let ((parent-task))
2237 (while (and (not parent-task) (org-up-heading-safe))
2238 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2239 (setq parent-task (point))))
2241 (org-with-point-at parent-task
2243 (when bh/keep-clock-running
2244 (bh/clock-in-default-task)))))))
2246 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2248 (defun bh/clock-in-organization-task-as-default ()
2250 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2251 (org-clock-in '(16))))
2253 (defun bh/clock-out-maybe ()
2254 (when (and bh/keep-clock-running
2255 (not org-clock-clocking-in)
2256 (marker-buffer org-clock-default-task)
2257 (not org-clock-resolving-clocks-due-to-idleness))
2258 (bh/clock-in-parent-task)))
2260 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2263 (defun bh/clock-in-task-by-id (id)
2264 "Clock in a task by id"
2265 (org-with-point-at (org-id-find id 'marker)
2266 (org-clock-in nil)))
2268 (defun bh/clock-in-last-task (arg)
2269 "Clock in the interrupted task if there is one
2270 Skip the default task and get the next one.
2271 A prefix arg forces clock in of the default task."
2273 (let ((clock-in-to-task
2275 ((eq arg 4) org-clock-default-task)
2276 ((and (org-clock-is-active)
2277 (equal org-clock-default-task (cadr org-clock-history)))
2278 (caddr org-clock-history))
2279 ((org-clock-is-active) (cadr org-clock-history))
2280 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2281 (t (car org-clock-history)))))
2283 (org-with-point-at clock-in-to-task
2284 (org-clock-in nil))))
2287 (defun org-export-to-ods ()
2289 (let ((csv-file "data.csv"))
2290 (org-table-export csv-file "orgtbl-to-csv")
2291 (org-odt-convert csv-file "ods" 'open)))
2293 ; allow for zero-width-space to be a break in regexp too
2294 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
2295 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
2296 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2298 ;; support inserting screen shots
2299 (defun my/org-insert-screenshot ()
2300 "Take a screenshot into a time stamped unique-named file in the
2301 same directory as the org-buffer and insert a link to this file."
2303 (defvar my/org-insert-screenshot/filename)
2304 (setq my/org-insert-screenshot/filename
2306 "Screenshot to insert: "
2308 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2311 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2312 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2313 (org-display-inline-images))
2315 (defun my/fix-inline-images ()
2316 (when org-inline-image-overlays
2317 (org-redisplay-inline-images)))
2319 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2321 ;; use xelatex to preview with imagemagick
2322 (add-to-list 'org-preview-latex-process-alist
2323 '(xelateximagemagick
2324 :programs ("xelatex" "convert")
2325 :description "pdf > png"
2326 :message "you need to install xelatex and imagemagick"
2328 :image-input-type "pdf"
2329 :image-output-type "png"
2330 :image-size-adjust (1.0 . 1.0)
2331 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2332 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2334 ;; use xelatex by default
2335 (setq org-preview-latex-default-process 'xelateximagemagick)
2337 ; from http://orgmode.org/Changes.html
2338 (defun my/org-repair-property-drawers ()
2339 "Fix properties drawers in current buffer.
2340 Ignore non Org buffers."
2342 (when (eq major-mode 'org-mode)
2343 (org-with-wide-buffer
2344 (goto-char (point-min))
2345 (let ((case-fold-search t)
2346 (inline-re (and (featurep 'org-inlinetask)
2347 (concat (org-inlinetask-outline-regexp)
2351 (unless (and inline-re (org-looking-at-p inline-re))
2353 (let ((end (save-excursion (outline-next-heading) (point))))
2355 (when (org-looking-at-p org-planning-line-re) (forward-line))
2356 (when (and (< (point) end)
2357 (not (org-looking-at-p org-property-drawer-re))
2359 (and (re-search-forward org-property-drawer-re end t)
2360 (eq (org-element-type
2361 (save-match-data (org-element-at-point)))
2363 (insert (delete-and-extract-region
2365 (min (1+ (match-end 0)) end)))
2366 (unless (bolp) (insert "\n"))))))))))))
2370 #+BEGIN_SRC emacs-lisp
2374 (use-package calfw-org
2377 (use-package org-gcal
2378 :if (file-readable-p "~/.hide/org_gcal.el")
2380 :config '((if (file-readable-p "~/.hide/org_gcal.el")
2381 (load-file "~/.hide/org_gcal.el"))
2386 #+BEGIN_SRC emacs-lisp
2390 ;; Show notification 10 minutes before event
2391 (setq appt-message-warning-time 10)
2392 ;; Disable multiple reminders
2393 (setq appt-display-interval appt-message-warning-time)
2394 (setq appt-display-mode-line nil)
2396 ;; add automatic reminders for appointments
2397 (defun my/org-agenda-to-appt ()
2399 (setq appt-time-msg-list nil)
2400 (org-agenda-to-appt))
2401 ;; add reminders when starting emacs
2402 (my/org-agenda-to-appt)
2403 ;; when rebuilding the agenda
2404 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
2405 "Pressing `r' on the agenda will also add appointments."
2406 (my/org-agenda-to-appt)
2408 ;; when saving all org buffers
2409 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2410 "Re-add appts after saving all org buffers"
2411 (my/org-agenda-to-appt))
2412 ;; Display appointments as a window manager notification
2413 (setq appt-disp-window-function 'my/appt-display)
2414 (setq appt-delete-window-function (lambda () t))
2416 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2418 (defun my/appt-display (min-to-app new-time msg)
2419 (if (atom min-to-app)
2420 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2421 (dolist (i (number-sequence 0 (1- (length min-to-app))))
2422 (start-process "my/appt-notification-app" nil my/appt-notification-app
2423 (nth i min-to-app) (nth i msg))))
2430 #+BEGIN_SRC emacs-lisp
2435 #+BEGIN_SRC emacs-lisp
2436 (global-unset-key "\M-g")
2437 (global-set-key (kbd "M-g l") 'goto-line)
2441 #+BEGIN_SRC emacs-lisp
2442 (use-package debian-changelog-mode
2443 :mode "debian/changelog"
2445 (setq debian-changelog-mailing-address "don@debian.org")
2446 (setq debian-changelog-full-name "Don Armstrong"))
2448 * Misc (uncharacterized)
2449 #+BEGIN_SRC emacs-lisp
2450 (setq calendar-latitude 38.6)
2451 (setq calendar-longitude -121.5)
2452 (setq case-fold-search t)
2453 (setq confirm-kill-emacs (quote y-or-n-p))
2454 (setq cperl-lazy-help-time nil)
2455 (global-font-lock-mode 1)
2457 (setq log-edit-keep-buffer t)
2458 (setq mail-user-agent (quote sendmail-user-agent))
2459 (setq markdown-enable-math t)
2460 (setq markdown-follow-wiki-link-on-enter nil)
2461 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2462 (setq ps-footer-font-size (quote (8 . 10)))
2463 (setq ps-header-font-size (quote (8 . 10)))
2464 (setq ps-header-title-font-size (quote (10 . 10)))
2465 (setq ps-line-number-color "blue")
2466 (setq ps-print-footer t)
2467 (setq ps-print-footer-frame nil)
2468 (setq ps-print-only-one-header t)
2469 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
2471 (setq sentence-end-double-space nil)
2472 ; enable matching parenthesis
2475 (setq user-mail-address "don@donarmstrong.com")
2476 (setq vc-delete-logbuf-window nil)
2477 (setq vc-follow-symlinks t)
2479 ;; use git before SVN; use CVS earlier, because I have CVS
2480 ;; repositories inside of git directories
2481 (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
2483 ;; switch back to the old primary selection method
2484 (setq x-select-enable-clipboard nil)
2485 (setq x-select-enable-primary t)
2486 ; (setq mouse-drag-copy-region t)
2488 (fset 'perl-mode 'cperl-mode)
2489 ;;(load-file "cperl-mode.el")
2491 ;; tramp configuration
2492 (setq tramp-use-ssh-controlmaster-options nil)
2494 (setq-default c-indent-level 4)
2495 (setq-default c-brace-imaginary-offset 0)
2496 (setq-default c-brace-offset -4)
2497 (setq-default c-argdecl-indent 4)
2498 (setq-default c-label-offset -4)
2499 (setq-default c-continued-statement-offset 4)
2501 (setq-default indent-tabs-mode nil)
2502 (setq-default tab-width 4)
2505 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2506 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2507 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2508 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2509 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2512 (defun insert-date ()
2513 "Insert date at point."
2515 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2516 (global-set-key "\C-[d" 'insert-date)
2518 (defun unfill-paragraph (arg)
2519 "Pull this whole paragraph up onto one line."
2521 (let ((fill-column 10000))
2522 (fill-paragraph arg))
2525 (column-number-mode t)
2528 ** Desktop-save-mode
2529 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2530 emacs, and use a different desktop file to restore history
2531 #+BEGIN_SRC emacs-lisp
2532 (use-package desktop
2535 (setq desktop-base-file-name
2536 (convert-standard-filename
2538 (or (getenv "EMACS_SERVER_NAME")
2542 (setq desktop-base-lock-name
2543 (convert-standard-filename
2544 (concat desktop-base-file-name
2546 (setq desktop-auto-save-timeout 60)
2547 (setq desktop-restore-eager 5)
2548 (setq desktop-lazy-verbose nil)
2549 (desktop-save-mode 1)
2553 ** Misc (Uncharacterized)
2554 #+BEGIN_SRC emacs-lisp
2555 '(icomplete-mode on)
2557 ;; custom-set-faces was added by Custom.
2558 ;; If you edit it by hand, you could mess it up, so be careful.
2559 ;; Your init file should contain only one such instance.
2560 ;; If there is more than one, they won't work right.
2561 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2564 (put 'upcase-region 'disabled nil)
2565 (put 'downcase-region 'disabled nil)
2566 (put 'narrow-to-region 'disabled nil)
2568 ; (defun turn-on-flyspell ()
2569 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2571 ; (flyspell-mode 1))
2574 ; Outline-minor-mode key map
2575 (define-prefix-command 'cm-map nil "Outline-")
2577 (define-key cm-map "q" 'outline-hide-sublevels) ; Hide everything but the top-level headings
2578 (define-key cm-map "t" 'outline-hide-body) ; Hide everything but headings (all body lines)
2579 (define-key cm-map "o" 'outline-hide-other) ; Hide other branches
2580 (define-key cm-map "c" 'outline-hide-entry) ; Hide this entry's body
2581 (define-key cm-map "l" 'outline-hide-leaves) ; Hide body lines in this entry and sub-entries
2582 (define-key cm-map "d" 'outline-hide-subtree) ; Hide everything in this entry and sub-entries
2584 (define-key cm-map "a" 'outline-show-all) ; Show (expand) everything
2585 (define-key cm-map "e" 'outline-show-entry) ; Show this heading's body
2586 (define-key cm-map "i" 'outline-show-children) ; Show this heading's immediate child sub-headings
2587 (define-key cm-map "k" 'outline-show-branches) ; Show all sub-headings under this heading
2588 (define-key cm-map "s" 'outline-show-subtree) ; Show (expand) everything in this heading & below
2590 (define-key cm-map "u" 'outline-up-heading) ; Up
2591 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2592 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2593 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2594 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2595 (global-set-key "\M-o" cm-map)
2596 ; fix up tmux xterm keys
2597 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2598 (defun fix-up-tmux-keys ()
2599 "Fix up tmux xterm keys"
2602 (let ((x 2) (tkey ""))
2622 ;; ctrl + alt + shift
2624 (setq tkey "C-M-S-"))
2627 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2628 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2629 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2630 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2632 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2634 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2636 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2638 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2640 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2642 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2644 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2646 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2648 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2650 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2652 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2654 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2656 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2658 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2660 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2662 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2664 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2666 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2668 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2670 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2672 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2674 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2676 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2678 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2680 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2682 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2689 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2691 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2692 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2693 (if (or (buffer-modified-p)
2694 (verify-visited-file-modtime)
2695 (< (* 8 1024 1024) (buffer-size))
2696 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2698 (clear-visited-file-modtime)
2700 (ad-activate 'ask-user-about-supersession-threat)
2704 #+BEGIN_SRC emacs-lisp
2708 (or (getenv "EMACS_SERVER_NAME")
2710 (unless (server-running-p)
2711 (global-set-key "\C-xp" 'server-edit)
2718 #+BEGIN_SRC emacs-lisp
2719 (provide 'don-configuration)