1 #+PROPERTY: header-args:emacs-lisp :tangle don-configuration.el
5 # if for some reason, things get pear-shaped, we want to be able to
6 # enter the debugger by sending -USR2 to emacs
9 (setq debug-on-event 'siguser2)
13 #+BEGIN_SRC emacs-lisp
14 (add-to-list 'exec-path '"/usr/local/bin")
15 (add-to-list 'exec-path '"~/bin/")
18 #+BEGIN_SRC emacs-lisp
20 (let ((default-directory "~/var/emacs/elpa"))
21 (normal-top-level-add-subdirs-to-load-path))
23 (add-to-list 'load-path '"~/lib/emacs_el/")
24 (let ((default-directory "~/lib/emacs_el/"))
25 (normal-top-level-add-subdirs-to-load-path))
26 (let ((default-directory "~/var/emacs/elpa"))
27 (normal-top-level-add-subdirs-to-load-path))
28 (setq package-user-dir "~/var/emacs/elpa")
30 * Initial startup stuff
31 ** Disable startup screen
32 #+BEGIN_SRC emacs-lisp
33 (setq inhibit-startup-screen t)
36 #+BEGIN_SRC emacs-lisp
37 ; (if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
38 (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
39 (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
42 #+BEGIN_SRC emacs-lisp
43 (setq frame-resize-pixelwise t)
44 (add-to-list 'default-frame-alist '(fullscreen . maximixed))
47 ** package repositories and package manager
48 #+BEGIN_SRC emacs-lisp
49 (require 'use-package)
51 (add-to-list 'gnutls-trustfiles "/etc/ssl/ca-global/ca-certificates.crt")
52 (setq package-enable-at-startup nil)
53 (setq package--init-file-ensured t)
54 (setq package-user-dir "~/var/emacs/elpa")
55 (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
56 ("melpa" . "https://melpa.org/packages/")
57 ("org" . "http://orgmode.org/elpa/")))
58 (setq use-package-verbose (not (bound-and-true-p byte-compile-current-file)))
62 #+BEGIN_SRC emacs-lisp
65 :commands (paradox-upgrade-packages paradox-list-packages)
67 (setq paradox-execute-asynchronously t)
68 (setq paradox-github-token t) ; I don't want to be prompted about this integration
72 #+BEGIN_SRC emacs-lisp
73 ;; Set the custom file to /dev/null and don't bother to load it
74 (setq custom-file "/dev/null")
78 #+BEGIN_SRC emacs-lisp
79 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
80 ;; execute conditional code when loading libraries
81 ; (defmacro with-library (symbol &rest body)
82 ; `(when (require ,symbol nil t)
84 ; (put 'with-library 'lisp-indent-function 1)
88 ** Safe Local Variables
89 #+BEGIN_SRC emacs-lisp
90 (setq safe-local-variable-values
91 (quote ((auto-save-default)
93 (cperl-indent-level . 4)
95 (indent-tabs-mode . f)
96 (vcl-indent-level . 4)
100 #+BEGIN_SRC emacs-lisp
101 (setq global-mark-ring-max 128
105 (defun don/minibuffer-setup-hook ()
106 (setq gc-cons-threshold most-positive-fixnum))
108 (defun don/minibuffer-exit-hook ()
109 (setq gc-cons-threshold 1048576))
111 (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
112 (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
116 #+BEGIN_SRC emacs-lisp
117 (use-package tree-sitter
121 (global-tree-sitter-mode)
123 (use-package tree-sitter-langs
128 (defun dla/python-function-at-point ()
129 "Return a list of function arguments
131 Borrowed from https://xenodium.com/emacs-generate-a-swift-initializer/
134 (cl-assert (seq-contains local-minor-modes 'tree-sitter-mode) "tree-sitter-mode not enabled")
135 (let* ((node (tree-sitter-node-at-point 'function_definition)
141 (error "Not in function"))
144 (cond ((eq 'func_name
147 ; (setq args (append args (list arg)))
149 (setq arg (list (cons 'function (tsc-node-text
153 (setq arg (map-insert arg 'ident (tsc-node-text
157 (setq arg (map-insert arg 'ident_type (tsc-node-text
161 (setq arg (map-insert arg 'ret_type (tsc-node-text
165 (tsc-make-query tree-sitter-language
166 "(function_definition (identifier) @func_name (parameters [(identifier) @ident (typed_parameter (identifier) @ident (type) @ident_type)]) (type)? @ret_type)")
167 (tree-sitter-node-at-point 'function_definition) nil))
169 (setq args (append args (list arg))))
175 #+BEGIN_SRC emacs-lisp
176 (use-package spacemacs-common
177 :ensure spacemacs-theme
179 (load-theme 'spacemacs-dark t)
183 #+BEGIN_SRC emacs-lisp
184 (use-package hippie-exp
185 :bind* (("M-<SPC>" . hippie-expand))
189 #+BEGIN_SRC emacs-lisp
190 (use-package flyspell
192 :delight flyspell-mode 🐝
194 (add-hook 'text-mode-hook 'turn-on-flyspell)
195 (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
196 (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
197 (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
199 (setq ispell-program-name "ispell")
205 #+begin_src emacs-lisp :tangle yes
206 (use-package flycheck
209 :if (version<= "24.4" emacs-version)
210 :commands flycheck-mode
211 :hook ((prog-mode . flycheck-mode)
215 (use-package flycheck-tip
217 :commands 'flycheck-tip-cycle
219 :bind (:map flycheck-mode-map
220 ("C-c C-n" . flycheck-tip-cycle)))
222 (use-package flycheck-package
225 (use-package flycheck-checkpatch
227 :config (flycheck-checkpatch-setup)
228 :config (setq flycheck-checkers (delete 'checkpatch
230 :config (add-to-list 'flycheck-checkers 'checkpatch t))
234 #+begin_src emacs-lisp :tangle yes
240 #+BEGIN_SRC emacs-lisp
245 #+BEGIN_SRC emacs-lisp
246 (use-package eyebrowse
248 :delight eyebrowse-mode
249 :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
251 (setq eyebrowse-wrap-around t)
254 (defun my/eyebrowse-new-window-config ()
258 ;; start at 1 run till 0
259 (let ((j (mod (+ i 1) 10)))
260 (when (and (not done)
261 (not (eyebrowse--window-config-present-p j)))
262 (eyebrowse-switch-to-window-config j)
263 (call-interactively 'eyebrowse-rename-window-config2 j)
268 ;; I don't use latex-preview-pane
269 ;; (require 'latex-preview-pane)
270 ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
271 ;; ;; latex-preview-pane uses window-parameters which are
272 ;; ;; not preserved by eyebrowse, so we close the preview
273 ;; ;; pane before switching, it will be regenerated when we
274 ;; ;; edit the TeX file.
275 ;; (when (lpp/window-containing-preview)
276 ;; (delete-window (lpp/window-containing-preview))))
278 ;; (add-to-list 'eyebrowse-pre-window-switch-hook
279 ;; #'my/close-latex-preview-pane-before-eyebrowse-switch)
281 ;; (my/set-menu-key "[" #'my/eyebrowse-new-window-config)
282 ;; (my/set-menu-key ";" #'eyebrowse-prev-window-config)
283 ;; (my/set-menu-key "'" #'eyebrowse-next-window-config)
284 ;; (my/set-menu-key "]" #'eyebrowse-close-window-config)
285 ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
293 #+BEGIN_SRC emacs-lisp
294 (defun my/vsplit-last-buffer ()
295 "Split the window vertically and display the previous buffer."
297 (split-window-vertically)
299 (switch-to-next-buffer))
301 (defun my/hsplit-last-buffer ()
302 "Split the window horizontally and display the previous buffer."
304 (split-window-horizontally)
306 (switch-to-next-buffer))
308 (bind-key "C-x 2" 'my/vsplit-last-buffer)
309 (bind-key "C-x 3" 'my/hsplit-last-buffer)
311 (setq split-width-threshold 100)
312 (setq split-height-threshold 60)
314 (defun my/split-window-prefer-vertically (window)
315 "If there's only one window (excluding any possibly active
316 minibuffer), then split the current window horizontally."
317 (if (and (one-window-p t)
318 (not (active-minibuffer-window))
319 ( < (frame-width) (frame-height))
321 (let ((split-width-threshold nil))
322 (split-window-sensibly window))
323 (split-window-sensibly window)))
325 (setq split-window-preferred-function #'my/split-window-prefer-vertically)
326 (setq window-combination-resize t)
329 *** Compilation window
331 If there is no compilation window, open one at the bottom, spanning
332 the complete width of the frame. Otherwise, reuse existing window. In
333 the former case, if there was no error the window closes
336 #+BEGIN_SRC emacs-lisp
337 (add-to-list 'display-buffer-alist
338 `(,(rx bos "*compilation*" eos)
339 (display-buffer-reuse-window
340 display-buffer-in-side-window)
341 (reusable-frames . visible)
343 (window-height . 0.4)))
346 #+BEGIN_SRC emacs-lisp
347 (defun my/compilation-exit-autoclose (status code msg)
348 ;; If M-x compile exists with a 0
349 (when (and (eq status 'exit) (zerop code))
350 ;; and delete the *compilation* window
351 (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
352 (when (and (not (window-at-side-p compilation-window 'top))
353 (window-at-side-p compilation-window 'left)
354 (window-at-side-p compilation-window 'right))
355 (delete-window compilation-window))))
356 ;; Always return the anticipated result of compilation-exit-message-function
359 ;; Specify my function (maybe I should have done a lambda function)
360 (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
363 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
364 value, the compilation buffer scrolls automatically to follow the
365 output. If the value is ~first-error~, scrolling stops when the first
366 error appears, leaving point at that error. For any other non-nil
367 value, scrolling continues until there is no more output.
369 #+BEGIN_SRC emacs-lisp
370 (setq compilation-scroll-output 'first-error)
373 ** Mode line cleaning
375 #+BEGIN_SRC emacs-lisp
381 #+BEGIN_SRC emacs-lisp
388 #+BEGIN_SRC emacs-lisp
390 :if (>= emacs-major-version 25)
392 :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
393 ("C-c j j" . avy-goto-word-or-subword-1)
394 ("M-g g" . avy-goto-line))
395 :config (progn (setq avy-background t))
398 *** Ace-link (jumping to links)
399 #+BEGIN_SRC emacs-lisp
400 (use-package ace-link
402 ; bind o in most modes
403 :config (ace-link-setup-default))
405 *** Jumping through edit points (goto-chg)
406 #+BEGIN_SRC emacs-lisp
407 (use-package goto-chg
409 :bind (("C-c j ," . goto-last-change)
410 ("C-c j ." . goto-last-change-reverse))
413 *** Jumping to bookmarks (visible bookmarks, bm)
414 #+BEGIN_SRC emacs-lisp
417 :bind (("C-c j b ." . bm-next)
418 ("C-c j b ," . bm-previous)
419 ("C-c j b SPC" . bm-toggle)))
424 #+BEGIN_SRC emacs-lisp
425 (use-package yasnippet
427 :delight yas-minor-mode
430 (setq yas-verbosity 1)
431 (define-key yas-minor-mode-map (kbd "<tab>") nil)
432 (define-key yas-minor-mode-map (kbd "TAB") nil)
433 (define-key yas-minor-mode-map (kbd "<backtab>") nil)
434 (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
435 "~/lib/emacs_el/yasnippet-snippets/snippets/"))
436 (add-to-list 'hippie-expand-try-functions-list
437 'yas-hippie-try-expand)
443 #+BEGIN_SRC emacs-lisp
444 (use-package auto-yasnippet
446 :bind (("H-w" . aya-create)
451 ** Treemacs: Tree file viewer
452 #+BEGIN_SRC emacs-lisp
453 ;; Provides workspaces with file browsing (tree file viewer)
454 ;; and project management when coupled with `projectile`.
456 (use-package treemacs
460 (setq treemacs-no-png-images t
462 :bind ("C-c t" . treemacs))
465 #+BEGIN_SRC emacs-lisp
466 (use-package lsp-mode
469 :commands (lsp lsp-deferred)
470 :init (setq lsp-keymap-prefix "C-c l")
471 :hook (python-mode . lsp-deferred))
472 ;; Provides visual help in the buffer
473 ;; For example definitions on hover.
474 ;; The `imenu` lets me browse definitions quickly.
479 (setq lsp-ui-sideline-enable nil
481 :hook (lsp-mode . lsp-ui-mode)
482 :bind (:map lsp-ui-mode-map
483 ("C-c i" . lsp-ui-imenu)))
484 ;; Language server for Python
485 ;; Read the docs for the different variables set in the config.
486 (use-package lsp-pyright
490 (setq lsp-clients-python-library-directories '("/usr/" "~/miniconda3/pkgs"))
491 (setq lsp-pyright-disable-language-service nil
492 lsp-pyright-disable-organize-imports nil
493 lsp-pyright-auto-import-completions t
494 lsp-pyright-use-library-code-for-types t
495 lsp-pyright-venv-path "~/miniconda3/envs")
496 :hook ((python-mode . (lambda ()
497 (require 'lsp-pyright) (lsp-deferred)))))
500 #+BEGIN_SRC emacs-lisp
503 :bind (("M-/" . company-complete))
505 (setq company-echo-delay 0 ; remove blinking
506 company-show-numbers t ; show numbers for easy selection
507 company-selection-wrap-around t
508 company-require-match nil
509 company-dabbrev-ignore-case t
510 company-dabbrev-ignore-invisible t
511 company-dabbrev-other-buffers t
512 company-dabbrev-downcase nil
513 company-dabbrev-code-everywhere t
514 company-tooltip-align-annotations t
515 company-minimum-prefix-length 1
516 company-global-modes '(not)
517 company-lighter-base "(C)")
518 (setq company-backends '(company-capf
525 company-irony-c-headers
531 (global-company-mode 1)
532 :bind (:map company-active-map
533 ("C-n" . company-select-next)
534 ("C-p" . company-select-previous)
535 ("M-?" . company-show-doc-buffer)
536 ("M-." . company-show-location)
541 #+BEGIN_SRC emacs-lisp
542 (use-package company-c-headers
545 (defun malb/ede-object-system-include-path ()
546 "Return the system include path for the current buffer."
548 (ede-system-include-path ede-object)))
550 (setq company-c-headers-path-system
551 #'malb/ede-object-system-include-path)))
554 #+BEGIN_SRC emacs-lisp
555 (use-package company-jedi
557 :hook (python-mode . 'jedi:setup)
559 (setq jedi:complete-on-dot t)
563 #+BEGIN_SRC emacs-lisp
564 (use-package company-plsense
569 #+BEGIN_SRC emacs-lisp
570 (use-package company-math
573 #+BEGIN_SRC emacs-lisp
574 (use-package company-auctex
577 (defun company-auctex-labels (command &optional arg &rest ignored)
578 "company-auctex-labels backend"
579 (interactive (list 'interactive))
581 (interactive (company-begin-backend 'company-auctex-labels))
582 (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
583 (candidates (company-auctex-label-candidates arg))))
585 (add-to-list 'company-backends
586 '(company-auctex-macros
587 company-auctex-environments
588 company-math-symbols-unicode
589 company-math-symbols-latex))
591 (add-to-list 'company-backends #'company-auctex-labels)
592 (add-to-list 'company-backends #'company-auctex-bibs)
597 #+BEGIN_SRC emacs-lisp
598 (use-package company-bibtex
604 #+BEGIN_SRC emacs-lisp
605 (use-package company-shell
608 (setq company-shell-modes '(sh-mode shell-mode))
609 (add-to-list 'company-backends 'company-shell)))
614 Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
616 *Note:* Do this at the end of =company-mode= config.
618 #+BEGIN_SRC emacs-lisp
619 (defvar malb/company-mode/enable-yas t
620 "Enable yasnippet for all backends.")
622 (defun malb/company-mode/backend-with-yas (backend)
623 (if (or (not malb/company-mode/enable-yas)
625 (member 'company-yasnippet backend)))
627 (append (if (consp backend) backend (list backend))
628 '(:with company-yasnippet))))
630 (setq company-backends
631 (mapcar #'malb/company-mode/backend-with-yas company-backends))
636 Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
638 #+BEGIN_SRC emacs-lisp
639 (defun malb/toggle-company-ispell ()
642 ((member '(company-ispell :with company-yasnippet) company-backends)
643 (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
644 (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
645 (message "company-ispell disabled"))
647 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
648 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
649 (message "company-ispell enabled!"))))
651 (defun malb/company-ispell-setup ()
652 ;; @see https://github.com/company-mode/company-mode/issues/50
653 (when (boundp 'company-backends)
654 (make-local-variable 'company-backends)
655 (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
656 (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
657 ;; https://github.com/redguardtoo/emacs.d/issues/473
658 (if (and (boundp 'ispell-alternate-dictionary)
659 ispell-alternate-dictionary)
660 (setq company-ispell-dictionary ispell-alternate-dictionary))))
665 1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
667 2. This function then hopefully does what I want:
669 a. if a region is active, just indent
670 b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
671 c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
672 d. otherwise call whatever would have been called otherwise.
674 ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
676 #+BEGIN_SRC emacs-lisp
677 (defun malb/indent-fold-or-complete (&optional arg)
680 ;; if a region is active, indent
682 (indent-region (region-beginning)
684 ;; if the next char is space or eol, but prev char not whitespace
685 ((and (not (active-minibuffer-window))
688 (looking-back "[^[:space:]]")
689 (not (looking-back "^")))
691 (cond (company-mode (company-complete-common))
692 (auto-complete-mode (auto-complete))))
694 ;; no whitespace anywhere
695 ((and (not (active-minibuffer-window))
696 (looking-at "[^[:space:]]")
697 (looking-back "[^[:space:]]")
698 (not (looking-back "^")))
700 ((bound-and-true-p hs-minor-mode)
701 (save-excursion (end-of-line) (hs-toggle-hiding)))
702 ((bound-and-true-p outline-minor-mode)
703 (save-excursion (outline-cycle)))))
705 ;; by default just call whatever was bound
707 (let ((fn (or (if (current-local-map) (lookup-key (current-local-map) (kbd "TAB")))
708 'indent-for-tab-command)))
709 (if (not (called-interactively-p 'any))
711 (setq this-command fn)
712 (call-interactively fn))))))
714 (defun malb/toggle-fold ()
716 (cond ((eq major-mode 'org-mode)
717 (org-force-cycle-archived))
718 ((bound-and-true-p hs-minor-mode)
723 ((bound-and-true-p outline-minor-mode)
727 (bind-key "<tab>" 'malb/indent-fold-or-complete)
728 (bind-key "C-<tab>" 'malb/toggle-fold)
732 #+BEGIN_SRC emacs-lisp
734 (use-package tinyprocmail
735 :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
736 :mode (".procmailrc" . turn-on-tinyprocmail-mode)
741 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
744 :bind (("C-x g" . magit-status)
745 ("C-x C-g" . magit-status))
747 ;; refine diffs always (hilight words)
748 (setq magit-diff-refine-hunk nil)
750 (use-package magit-annex
752 :load-path "~/lib/emacs_el/magit-annex/"
754 (use-package magit-vcsh
759 *** Forge (github/gitlab)
760 #+BEGIN_SRC emacs-lisp
768 #+BEGIN_SRC emacs-lisp
769 (use-package cperl-mode
773 ;; Use c-mode for perl .xs files
774 (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
775 (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
776 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
777 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
778 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
781 cperl-auto-newline nil
782 cperl-auto-newline-after-colon nil
783 cperl-continued-statement-offset 4
784 cperl-brace-offset -1
785 cperl-continued-brace-offset 0
786 cperl-label-offset -4
787 cperl-highlight-variables-indiscriminately t
788 cperl-electric-lbrace-space nil
789 cperl-indent-parens-as-block nil
790 cperl-close-paren-offset -1
791 cperl-tab-always-indent t)
792 ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
797 #+BEGIN_SRC emacs-lisp
798 (use-package markdown-mode
800 :mode (("\\.md\\'" . markdown-mode)
801 ("\\.mdwn\\'" . markdown-mode)
802 ("README\\.md\\'" . gfm-mode)
805 (setq markdown-enable-math t)
806 (setq markdown-follow-wiki-link-on-enter nil)
807 (bind-key "M-." #'markdown-jump markdown-mode-map)
808 (add-hook 'markdown-mode-hook #'flyspell-mode)
809 (add-hook 'markdown-mode-hook #'outline-minor-mode)
810 (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
815 #+BEGIN_SRC emacs-lisp
816 ; load sql-indent when sql is loaded
817 (use-package sql-indent
823 :mode (("\\.sql\\'" . sql-mode))
827 #+BEGIN_SRC emacs-lisp
829 :commands ediff ediff3
832 ;; ediff configuration
833 ;; don't use the multi-window configuration
834 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
837 ** Do the Right Thing Indenting
838 Attempts to automatically identify the right indentation for a file
839 #+BEGIN_SRC emacs-lisp
840 (use-package dtrt-indent
844 ** VCL --editing varnish configuration files
845 #+BEGIN_SRC emacs-lisp
846 (use-package vcl-mode
853 #+BEGIN_SRC emacs-lisp
859 ;; Different scroll margin
860 ;; (setq vertico-scroll-margin 0)
862 ;; Show more candidates
863 ;; (setq vertico-count 20)
865 ;; Grow and shrink the Vertico minibuffer
866 ;; (setq vertico-resize t)
868 ;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
869 ;; (setq vertico-cycle t)
871 (vertico-grid-separator " ")
872 (vertico-grid-lookahead 50)
873 (vertico-multiform-categories
875 (consult-grep buffer)
878 (library reverse indexed)
879 (org-roam-node reverse indexed)
882 (vertico-multiform-commands
883 '(("flyspell-correct-*" grid reverse)
884 (org-refile grid reverse indexed)
885 (consult-yank-pop indexed)
887 (consult-lsp-diagnostics)
890 (vertico-multiform-mode)
891 (define-key vertico-map "\r" #'vertico-directory-enter)
892 (define-key vertico-map "\d" #'vertico-directory-delete-char)
893 (define-key vertico-map "\M-\d" #'vertico-directory-delete-word)
894 (add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)
897 ;; Persist history over Emacs restarts. Vertico sorts by history position.
898 (use-package savehist
904 ** Orderless: advanced completion style
905 #+begin_src emacs-lisp
906 (use-package orderless
909 ;; Configure a custom style dispatcher (see the Consult wiki)
910 ;; (setq orderless-style-dispatchers '(+orderless-dispatch)
911 ;; orderless-component-separator #'orderless-escapable-split-on-space)
912 (setq completion-styles '(orderless basic)
913 completion-category-defaults nil
914 completion-category-overrides '((file (styles partial-completion)))))
916 ** Marginalia: Rich annotations in the minibuffer
917 #+begin_src emacs-lisp
918 (use-package marginalia
920 :bind (("M-A" . marginalia-cycle)
921 :map minibuffer-local-map
922 ("M-A" . marginalia-cycle))
927 ** Embark: Minibuffer actions and context menu
928 #+begin_src emacs-lisp
933 (("C-." . embark-act) ;; pick some comfortable binding
934 ("C-;" . embark-dwim) ;; good alternative: M-.
935 ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
939 ;; Optionally replace the key help with a completing-read interface
940 (setq prefix-help-command #'embark-prefix-help-command)
944 ;; Hide the mode line of the Embark live/completions buffers
945 (add-to-list 'display-buffer-alist
946 '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
948 (window-parameters (mode-line-format . none)))))
950 (use-package embark-consult
953 (embark-collect-mode . consult-preview-at-point-mode))
956 #+begin_src emacs-lisp
958 ;; Replace bindings. Lazily loaded due by `use-package'.
959 :bind (;; C-c bindings (mode-specific-map)
960 ("C-c h" . consult-history)
961 ("C-c m" . consult-mode-command)
962 ("C-c k" . consult-kmacro)
963 ;; C-x bindings (ctl-x-map)
964 ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
965 ("C-x b" . consult-buffer) ;; orig. switch-to-buffer
966 ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
967 ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
968 ("C-x r b" . consult-bookmark) ;; orig. bookmark-jump
969 ; ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer
970 ;; Custom M-# bindings for fast register access
971 ("M-#" . consult-register-load)
972 ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
973 ("C-M-#" . consult-register)
974 ;; Other custom bindings
975 ("M-y" . consult-yank-pop) ;; orig. yank-pop
976 ;; M-g bindings (goto-map)
977 ("M-g e" . consult-compile-error)
978 ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck
979 ("M-g g" . consult-goto-line) ;; orig. goto-line
980 ("M-g M-g" . consult-goto-line) ;; orig. goto-line
981 ("M-g o" . consult-outline) ;; Alternative: consult-org-heading
982 ("M-g m" . consult-mark)
983 ("M-g k" . consult-global-mark)
984 ("M-g i" . consult-imenu)
985 ("M-g I" . consult-imenu-multi)
986 ;; M-s bindings (search-map)
987 ("M-s d" . consult-find)
988 ("M-s D" . consult-locate)
989 ("M-s g" . consult-grep)
990 ("M-s G" . consult-git-grep)
991 ("M-s r" . consult-ripgrep)
992 ("M-s l" . consult-line)
993 ("M-s L" . consult-line-multi)
994 ("M-s k" . consult-keep-lines)
995 ("M-s u" . consult-focus-lines)
996 ;; Isearch integration
997 ("M-s e" . consult-isearch-history)
998 :map isearch-mode-map
999 ("M-e" . consult-isearch-history) ;; orig. isearch-edit-string
1000 ("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string
1001 ("M-s l" . consult-line) ;; needed by consult-line to detect isearch
1002 ("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch
1003 ;; Minibuffer history
1004 :map minibuffer-local-map
1005 ("M-s" . consult-history) ;; orig. next-matching-history-element
1006 ("M-r" . consult-history)) ;; orig. previous-matching-history-element
1008 ;; Enable automatic preview at point in the *Completions* buffer. This is
1009 ;; relevant when you use the default completion UI.
1010 :hook (completion-list-mode . consult-preview-at-point-mode)
1012 ;; The :init configuration is always executed (Not lazy)
1015 ;; Optionally configure the register formatting. This improves the register
1016 ;; preview for `consult-register', `consult-register-load',
1017 ;; `consult-register-store' and the Emacs built-ins.
1018 (setq register-preview-delay 0.5
1019 register-preview-function #'consult-register-format)
1021 ;; Optionally tweak the register preview window.
1022 ;; This adds thin lines, sorting and hides the mode line of the window.
1023 (advice-add #'register-preview :override #'consult-register-window)
1025 ;; Use Consult to select xref locations with preview
1026 (setq xref-show-xrefs-function #'consult-xref
1027 xref-show-definitions-function #'consult-xref)
1029 ;; Configure other variables and modes in the :config section,
1030 ;; after lazily loading the package.
1033 ;; Optionally configure preview. The default value
1034 ;; is 'any, such that any key triggers the preview.
1035 ;; (setq consult-preview-key 'any)
1036 ;; (setq consult-preview-key (kbd "M-."))
1037 ;; (setq consult-preview-key (list (kbd "<S-down>") (kbd "<S-up>")))
1038 ;; For some commands and buffer sources it is useful to configure the
1039 ;; :preview-key on a per-command basis using the `consult-customize' macro.
1041 consult-theme :preview-key '(:debounce 0.2 any)
1042 consult-ripgrep consult-git-grep consult-grep
1043 consult-bookmark consult-recent-file consult-xref
1044 consult--source-bookmark consult--source-file-register
1045 consult--source-recent-file consult--source-project-recent-file
1046 ;; :preview-key (kbd "M-.")
1047 :preview-key '(:debounce 0.4 any))
1049 ;; Optionally configure the narrowing key.
1050 ;; Both < and C-+ work reasonably well.
1051 (setq consult-narrow-key "<") ;; (kbd "C-+")
1053 ;; Optionally make narrowing help available in the minibuffer.
1054 ;; You may want to use `embark-prefix-help-command' or which-key instead.
1055 ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)
1057 ;; By default `consult-project-function' uses `project-root' from project.el.
1058 ;; Optionally configure a different project root function.
1059 ;; There are multiple reasonable alternatives to chose from.
1060 ;;;; 1. project.el (the default)
1061 ;; (setq consult-project-function #'consult--default-project--function)
1062 ;;;; 2. projectile.el (projectile-project-root)
1063 ;; (autoload 'projectile-project-root "projectile")
1064 ;; (setq consult-project-function (lambda (_) (projectile-project-root)))
1065 ;;;; 3. vc.el (vc-root-dir)
1066 ;; (setq consult-project-function (lambda (_) (vc-root-dir)))
1067 ;;;; 4. locate-dominating-file
1068 ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
1071 ** Projectile -- Project management
1072 #+begin_src emacs-lisp
1073 (use-package projectile
1075 :bind (("<f5>" . projectile-compile-project)
1076 ("<f6>" . next-error))
1078 (use-package magit :ensure t)
1079 (projectile-global-mode)))
1083 #+BEGIN_SRC emacs-lisp
1084 (use-package avy-zap
1086 :bind ("M-z" . avy-zap-up-to-char-dwim))
1089 #+BEGIN_SRC emacs-lisp
1091 :bind (("C-c 2" . my/hydra-orgmodes/body)
1092 ("C-c @" . my/hydra-orgmodes/body)
1093 ("C-c #" . my/hydra-outline/body)
1094 ("C-c 3" . my/hydra-outline/body)
1097 (defhydra my/hydra-orgmodes (:color blue :hint nil)
1099 _n_: notes _c_: chaim _w_: wildman _o_: ool
1100 _u_: uddin _s_: steve _r_: refile _f_: fh
1101 _p_: read papers _R_: paper notes
1106 ("n" (find-file "~/projects/org-notes/notes.org"))
1107 ("c" (find-file "~/projects/org-notes/chaim.org"))
1108 ("w" (find-file "~/projects/org-notes/wildman.org"))
1109 ("u" (find-file "~/projects/org-notes/uddin.org"))
1110 ("o" (find-file "~/projects/org-notes/ool.org"))
1111 ("f" (find-file "~/projects/org-notes/fh.org"))
1112 ("s" (find-file "~/projects/org-notes/sndservers.org"))
1113 ("r" (find-file my/org-refile-file))
1114 ("p" (find-file "~/projects/research/papers_to_read.org"))
1115 ("R" (find-file "~/projects/research/paper_notes.org"))
1116 ("h" (find-file "~/projects/org-notes/hpcbio.org"))
1121 ;; from https://github.com/abo-abo/hydra/wiki/Emacs
1122 (defhydra my/hydra-outline (:color pink :hint nil)
1125 ^^^^^^------------------------------------------------------
1126 _q_: sublevels _a_: all _u_: up
1127 _t_: body _e_: entry _n_: next visible
1128 _o_: other _i_: children _p_: previous visible
1129 _c_: entry _k_: branches _f_: forward same level
1130 _l_: leaves _s_: subtree _b_: backward same level
1135 ("q" outline-hide-sublevels) ; Hide everything but the top-level headings
1136 ("t" outline-hide-body) ; Hide everything but headings (all body lines)
1137 ("o" outline-hide-other) ; Hide other branches
1138 ("c" outline-hide-entry) ; Hide this entry's body
1139 ("l" outline-hide-leaves) ; Hide body lines in this entry and sub-entries
1140 ("d" outline-hide-subtree) ; Hide everything in this entry and sub-entries
1142 ("a" outline-show-all) ; Show (expand) everything
1143 ("e" outline-show-entry) ; Show this heading's body
1144 ("i" outline-show-children) ; Show this heading's immediate child sub-headings
1145 ("k" outline-show-branches) ; Show all sub-headings under this heading
1146 ("s" outline-show-subtree) ; Show (expand) everything in this heading & below
1148 ("u" outline-up-heading) ; Up
1149 ("n" outline-next-visible-heading) ; Next
1150 ("p" outline-previous-visible-heading) ; Previous
1151 ("f" outline-forward-same-level) ; Forward - same level
1152 ("b" outline-backward-same-level) ; Backward - same level
1158 #+BEGIN_SRC emacs-lisp
1161 (add-to-list 'tramp-methods '("vcsh"
1162 (tramp-login-program "vcsh")
1166 (tramp-remote-shell "/bin/sh")
1167 (tramp-remote-shell-args
1171 #+BEGIN_SRC emacs-lisp
1175 (setq-default reftex-default-bibliography
1176 '("~/projects/research/references.bib")))
1179 #+BEGIN_SRC emacs-lisp
1181 :config (setq bibtex-user-optional-fields
1182 (quote (("annote" "Personal annotation (ignored)")
1190 #+BEGIN_SRC emacs-lisp
1195 ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1196 ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1197 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1198 ; (autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
1199 ; (autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" nil)
1200 ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1201 ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1202 (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
1203 (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
1204 (add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with AUCTeX LaTeX mode
1205 (add-hook 'latex-mode-hook 'outline-minor-mode) ; with Emacs latex mode
1207 (setq-default reftex-plug-into-AUCTeX t)
1208 ;; support fake section headers
1209 (setq TeX-outline-extra
1213 ("%subsubsection" 4)
1215 ;; add font locking to the headers
1216 (font-lock-add-keywords
1218 '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1219 0 'font-lock-keyword-face t)
1220 ("^%chapter{\\(.*\\)}" 1 'font-latex-sectioning-1-face t)
1221 ("^%section{\\(.*\\)}" 1 'font-latex-sectioning-2-face t)
1222 ("^%subsection{\\(.*\\)}" 1 'font-latex-sectioning-3-face t)
1223 ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1224 ("^%paragraph{\\(.*\\)}" 1 'font-latex-sectioning-5-face t)))
1226 ;; use smart quotes by default instead of `` and ''
1227 ;; taken from http://kieranhealy.org/esk/kjhealy.html
1228 (setq TeX-open-quote "“")
1229 (setq TeX-close-quote "”")
1231 ;; (TeX-add-style-hook
1236 ;; (custom-set-variables
1237 ;; '(font-latex-user-keyword-classes
1240 ;; font-lock-function-name-face 2 (command 1 t))))
1242 (setq-default TeX-parse-self t)
1243 (setq-default TeX-auto-save t)
1244 (setq-default TeX-master nil)
1245 (add-to-list 'LaTeX-font-list
1246 '(?\C-a "\\alert{","}"))
1249 '(TeX-add-style-hook
1252 (if (boundp 'reftex-ref-style-alist)
1254 'reftex-ref-style-alist
1255 '("Cleveref" "cleveref"
1256 (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1257 (reftex-ref-style-activate "Cleveref")
1259 '("cref" TeX-arg-ref)
1260 '("Cref" TeX-arg-ref)
1261 '("cpageref" TeX-arg-ref)
1262 '("Cpageref" TeX-arg-ref)))))
1265 '(add-to-list 'LaTeX-fill-excluded-macros
1268 (use-package font-latex
1270 (setq font-latex-match-reference-keywords
1292 (setq font-latex-fontify-script nil)
1293 (setq font-latex-fontify-sectioning (quote color))
1294 (setq font-latex-script-display (quote (nil)))
1299 #+BEGIN_SRC emacs-lisp
1303 :mode ("\\.R\\'" . ess-r-mode)
1304 :bind (:map ess-mode-map
1305 ("C-c C-R" . dla/ess-region-remote-eval))
1307 (autoload 'ess-r-mode "ess-site" nil t)
1308 (autoload 'R "ess-site" nil t)
1310 ; actually load the rest of ess
1312 (defun ess-change-directory (path)
1313 "Set the current working directory to PATH for both *R* and Emacs."
1314 (interactive "Directory to change to: ")
1316 (when (file-exists-p path)
1317 (ess-command (concat "setwd(\"" path "\")\n"))
1318 ;; use file-name-as-directory to ensure it has trailing /
1319 (setq default-directory (file-name-as-directory path))))
1320 (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1321 ;; outlining support for ess modes
1325 (outline-minor-mode)
1326 (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1327 (defun outline-level ()
1328 (cond ((looking-at "^##### ") 1)
1329 ((looking-at "^#### ") 2)
1330 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1333 (defun dla/ess-region-remote-eval (start end)
1334 "Evaluate region in a remote ESS instance"
1336 (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***") nil nil nil)
1337 (kill-buffer "***essregionremoteeval***"))
1338 ;; Don't restore history or save workspace image
1339 '(inferior-R-args "--no-restore-history --no-save")
1344 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1346 #+BEGIN_SRC emacs-lisp
1347 (use-package rainbow-mode
1348 ;; add ess to the x major mode
1349 :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1350 (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1355 #+BEGIN_SRC emacs-lisp
1356 (use-package yaml-mode
1357 ;; add ess to the x major mode
1358 :mode ("\\.\\(yaml|yml\\)\\'" . yaml-mode)
1363 #+BEGIN_SRC emacs-lisp
1364 (use-package poly-noweb
1369 (use-package poly-markdown
1375 :after (:all polymode poly-markdown poly-noweb)
1376 ; :mode ("\\.Snw" . poly-noweb+r-mode)
1377 ; :mode ("\\.Rnw" . poly-noweb+r-mode)
1378 ; :mode ("\\.Rmd" . poly-markdown+r-mode)
1380 (use-package polymode
1388 #+BEGIN_SRC emacs-lisp
1389 ; this package doesn't really do exactly what we want it to do
1390 ; (use-package outline-magic)
1393 #+BEGIN_SRC emacs-lisp
1394 ;; change the outline mode prefix from C-c @ to C-c C-2
1395 (setq outline-minor-mode-prefix "C-c C-2")
1396 ;;(add-hook 'outline-minor-mode-hook
1397 ;; (lambda () (local-set-key (kbd "C-c C-2")
1398 ;; outline-mode-prefix-map)))
1402 #+BEGIN_SRC emacs-lisp
1403 (use-package writeroom-mode
1405 (defun my/writing-mode ()
1406 "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1411 (visual-line-mode -1)
1413 (visual-fill-column-mode -1)
1415 (visual-line-mode 1)
1417 (visual-fill-column-mode 1)
1422 ** GhostText/Atomic Chrome
1423 #+BEGIN_SRC emacs-lisp
1424 (use-package atomic-chrome
1426 (ignore-errors (atomic-chrome-start-server))
1427 (setq atomic-chrome-buffer-open-style 'full)
1431 #+BEGIN_SRC emacs-lisp
1432 (use-package edit-server
1434 :commands edit-server-start
1435 :init (if after-init-time
1437 (add-hook 'after-init-hook
1438 #'(lambda() (edit-server-start))))
1439 :config (setq edit-server-new-frame-alist
1440 '((name . "Edit with Emacs FRAME")
1446 (menu-bar-lines . t)
1447 (window-system . x)))
1451 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1452 #+BEGIN_SRC emacs-lisp
1453 (use-package multiple-cursors
1454 :bind* (("C-;" . mc/mark-all-dwim)
1455 ("C-<" . mc/mark-previous-like-this)
1456 ("C->" . mc/mark-next-like-this)
1457 ("C-S-c C-S-c" . mc/edit-lines))
1461 #+BEGIN_SRC emacs-lisp
1462 (use-package web-mode
1463 :load-path "/home/don/projects/web-mode/"
1464 :mode ("\\.\\(tx|tmpl\\)\\'" . web-mode)
1466 (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1467 (setq web-mode-enable-engine-detection t)
1468 (setq web-mode-engines-alist
1469 '(("template-toolkit" . "\\.tmpl\\'")))
1472 ** Spamassassin Mode
1473 #+BEGIN_SRC emacs-lisp
1474 (use-package spamassassin-mode
1475 :commands spamassassin-mode
1480 #+BEGIN_SRC emacs-lisp
1481 (use-package password-store
1483 :commands password-store-edit password-store-generate
1485 (defun dla/password-store-edit (entry)
1486 "Edit password for ENTRY which doesn't require it to already exist"
1487 (interactive (list (password-store--completing-read nil)))
1488 (password-store--run-edit entry))
1489 (advice-add 'password-store-edit :override #'dla/password-store-edit)
1493 #+BEGIN_SRC emacs-lisp
1497 ;; fix up css mode to not be silly
1498 ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1499 (setq cssm-indent-level 4)
1500 (setq cssm-newline-before-closing-bracket t)
1501 (setq cssm-indent-function #'cssm-c-style-indenter)
1502 (setq cssm-mirror-mode nil))
1505 #+BEGIN_SRC emacs-lisp
1507 :delight abbrev-mode
1509 ;; load abbreviations from
1510 (setq abbrev-file-name
1511 "~/.emacs_abbrev_def")
1513 ;; read the abbrev file if it exists
1514 (if (file-exists-p abbrev-file-name)
1515 (quietly-read-abbrev-file))
1517 ;; for now, use abbrev mode everywhere
1518 (setq default-abbrev-mode t))
1521 ** Debugging (realgud)
1522 #+BEGIN_SRC emacs-lisp
1523 (use-package realgud
1527 ** Python Programming
1528 #+BEGIN_SRC emacs-lisp
1529 (use-package python-mode
1532 (python-mode . pyenv-mode)
1533 (python-mode . flycheck-mode)
1534 (python-mode . company-mode)
1535 (python-mode . blacken-mode)
1536 (python-mode . yas-minor-mode)
1537 (python-mode . anaconda-mode)
1542 (use-package blacken
1545 (setq-default blacken-fast-unsafe t)
1546 ; (setq-default blacken-line-length 80)
1548 (use-package anaconda-mode
1559 #+begin_src emacs-lisp :tangle yes
1560 (use-package python-black
1564 *** Sphinx Documentation
1565 #+begin_src emacs-lisp :tangle yes
1566 (use-package numpydoc
1569 :bind (:map python-mode-map
1570 ("C-c C-n" . numpydoc-generate)))
1571 (use-package sphinx-doc
1575 (setq sphinx-doc-include-types t)
1577 (use-package python-docstring
1581 (python-mode . python-docstring-mode)
1585 #+BEGIN_SRC emacs-lisp
1586 (use-package go-mode
1593 #+BEGIN_SRC emacs-lisp
1594 (use-package expand-region
1595 :bind (("C-=" . 'er/expand-region))
1600 #+BEGIN_SRC emacs-lisp
1601 (use-package dockerfile-mode
1607 #+BEGIN_SRC emacs-lisp
1608 (use-package beancount
1609 :load-path "~/lib/emacs_el/beancount-mode/"
1611 :mode "\\.beancount\\'"
1618 #+BEGIN_SRC emacs-lisp
1619 (use-package message
1621 :delight (message "✉")
1622 :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1623 :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1624 :hook 'my/message-mode-settings
1625 :hook 'turn-on-flyspell
1626 :bind (:map message-mode-map
1627 ("C-c C-a" . my/post-attach-file))
1628 :delight (message-mode "✉")
1630 (defun my/message-mode-settings ()
1631 (font-lock-add-keywords nil
1632 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1633 (0 'message-multiply-quoted-text-face))
1634 ("^[ \t]*>[ \t]*>.*$"
1635 (0 'message-double-quoted-text-face))))
1638 (defun my/post-attach-file ()
1639 "Prompt for an attachment."
1641 (let ((file (read-file-name "Attach file: " nil nil t nil)))
1642 (my/header-attach-file file "")))
1644 (defun my/header-attach-file (file description)
1645 "Attach a FILE to the current message (works with Mutt).
1646 Argument DESCRIPTION MIME description."
1647 (interactive "fAttach file: \nsDescription: ")
1648 (when (> (length file) 0)
1653 (goto-char (point-min))
1654 (search-forward-regexp "^$")
1655 (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1657 (message (concat "Attached '" file "'."))
1658 (setq post-has-attachment t))))))
1660 (setq mail-yank-prefix "> ")
1661 (setq mail-header-separator "") ; fix broken header detection
1665 #+BEGIN_SRC emacs-lisp
1666 (use-package muttrc-mode
1673 ** Reverting buffers
1674 #+BEGIN_SRC emacs-lisp
1675 (use-package autorevert
1676 :delight auto-revert-mode
1678 (setq global-auto-revert-non-file-buffers t
1679 global-auto-revert-ignore-modes '(pdf-view-mode)
1680 auto-revert-verbose nil)
1681 (global-auto-revert-mode 1))
1684 ** Use-package and load things
1685 #+BEGIN_SRC emacs-lisp
1688 :delight (org-mode "ø")
1689 :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1690 :bind (("C-c l" . org-store-link)
1691 ("C-c a" . org-agenda)
1692 ("C-c b" . org-iswitchb))
1694 ** Agenda Configuration
1695 #+BEGIN_SRC emacs-lisp
1697 (setq-default org-log-done 'time)
1698 (setq-default org-agenda-ndays 5)
1700 (setq org-agenda-sticky t)
1701 (defun dla/show-org-agenda ()
1706 (and (string-match-p
1714 (buffer-name agendabuffer))
1716 (delete-other-windows))
1718 ;; agenda configuration
1719 ;; Do not dim blocked tasks
1720 (setq org-agenda-dim-blocked-tasks nil)
1721 (setq org-agenda-inhibit-startup t)
1722 (setq org-agenda-use-tag-inheritance nil)
1724 ;; Compact the block agenda view
1725 (setq org-agenda-compact-blocks t)
1727 ;; Custom agenda command definitions
1728 (setq org-agenda-custom-commands
1729 (quote (("N" "Notes" tags "NOTE"
1730 ((org-agenda-overriding-header "Notes")
1731 (org-tags-match-list-sublevels t)))
1732 ("h" "Habits" tags-todo "STYLE=\"habit\""
1733 ((org-agenda-overriding-header "Habits")
1734 (org-agenda-sorting-strategy
1735 '(todo-state-down effort-up category-keep))))
1739 ((org-agenda-overriding-header "Tasks to Refile")
1740 (org-tags-match-list-sublevels nil)))
1741 (tags-todo "-CANCELLED/!"
1742 ((org-agenda-overriding-header "Stuck Projects")
1743 (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1744 (org-agenda-sorting-strategy
1746 (tags-todo "-HOLD-CANCELLED/!"
1747 ((org-agenda-overriding-header "Projects")
1748 (org-agenda-skip-function 'bh/skip-non-projects)
1749 (org-tags-match-list-sublevels 'indented)
1750 (org-agenda-sorting-strategy
1752 (tags-todo "-CANCELLED/!NEXT"
1753 ((org-agenda-overriding-header (concat "Project Next Tasks"
1754 (if bh/hide-scheduled-and-waiting-next-tasks
1756 " (including WAITING and SCHEDULED tasks)")))
1757 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1758 (org-tags-match-list-sublevels t)
1759 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1760 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1761 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1762 (org-agenda-sorting-strategy
1763 '(todo-state-down effort-up category-keep))))
1764 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1765 ((org-agenda-overriding-header (concat "Project Subtasks"
1766 (if bh/hide-scheduled-and-waiting-next-tasks
1768 " (including WAITING and SCHEDULED tasks)")))
1769 (org-agenda-skip-function 'bh/skip-non-project-tasks)
1770 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1771 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1772 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1773 (org-agenda-sorting-strategy
1775 (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1776 ((org-agenda-overriding-header (concat "Standalone Tasks"
1777 (if bh/hide-scheduled-and-waiting-next-tasks
1779 " (including WAITING and SCHEDULED tasks)")))
1780 (org-agenda-skip-function 'bh/skip-project-tasks)
1781 (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1782 (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1783 (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1784 (org-agenda-sorting-strategy
1786 (tags-todo "-CANCELLED+WAITING|HOLD/!"
1787 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1788 (org-agenda-skip-function 'bh/skip-stuck-projects)
1789 (org-tags-match-list-sublevels nil)
1790 (org-agenda-todo-ignore-scheduled t)
1791 (org-agenda-todo-ignore-deadlines t)))
1793 ((org-agenda-overriding-header "Tasks to Archive")
1794 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1795 (org-tags-match-list-sublevels nil))))
1798 ; org mode agenda files
1799 (setq org-agenda-files
1801 (file-expand-wildcards "~/projects/org-notes/*.org")
1802 (file-expand-wildcards "~/org-mode/from-mobile.org")
1803 (file-expand-wildcards "~/org-notes-*/*.org")
1806 (setq my/org-refile-file
1808 (lambda (file) (string-match-p (regexp-quote "/refile.org") file))
1811 (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1812 (set-register ?r (cons 'file my/org-refile-file))
1813 (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1814 (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1815 (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1816 (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1817 (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1818 (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1819 (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1820 ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1821 (defun org-agenda-timeline-all (&optional arg)
1824 (dolist (org-agenda-file org-agenda-files)
1825 (insert-file-contents org-agenda-file nil)
1826 (goto-char (point-max))
1828 (write-file "/tmp/timeline.org")
1829 (org-agenda arg "L")))
1830 (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1834 #+BEGIN_SRC emacs-lisp
1835 (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")))
1836 (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1838 (setq org-default-notes-file "~/projects/org-notes/notes.org")
1839 (setq org-id-link-to-org-use-id 'use-existing)
1841 ** Capture Templates
1842 #+BEGIN_SRC emacs-lisp
1843 (setq org-capture-templates ;; mail-specific note template, identified by "m"
1844 `(("m" "Mail" entry (file my/org-refile-file)
1845 "* %?\n\n Source: %u, [[%:link][%:description]]\n %:initial")
1846 ("t" "todo" entry (file my/org-refile-file)
1847 "* TODO %?\n :PROPERTIES:\n :END:\n :LOGBOOK:\n :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1848 ("r" "respond" entry (file my/org-refile-file)
1849 "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1850 ("n" "note" entry (file my/org-refile-file)
1851 "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1852 ("s" "schedule" entry (file my/org-refile-file)
1853 "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1854 ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1855 "* %?\n%U\n" :clock-in t :clock-resume t)
1856 ("w" "org-protocol" entry (file my/org-refile-file)
1857 "* TODO Review %c\n%U\n" :immediate-finish t)
1858 ("M" "Meeting" entry (file my/org-refile-file)
1859 "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1860 ("S" "Seminar" entry (file my/org-refile-file)
1861 "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1862 ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1863 "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1864 ("p" "Phone call" entry (file my/org-refile-file)
1865 "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1866 ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1868 ,(format-time-string "Positions %Y"))
1869 "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1870 ("h" "Habit" entry (file my/org-refile-file)
1871 "* 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")
1875 ;; Remove empty LOGBOOK drawers on clock out
1876 (defun bh/remove-empty-drawer-on-clock-out ()
1879 (beginning-of-line 0)
1880 (org-remove-empty-drawer-at (point))))
1882 (defun my/org-add-id ()
1885 (if (org-current-level)
1894 ** Org mode key bindings
1895 #+BEGIN_SRC emacs-lisp
1896 ;; org mode configuration from http://doc.norang.ca/org-mode.html
1897 ;; Custom Key Bindings
1898 :bind* (("<f9> a" . org-agenda)
1899 ("<f9> I" . bh/punch-in)
1900 ("<f9> O" . bh/punch-out)
1901 ("<f9> SPC" . bh/clock-in-last-task)
1902 ("<f12>" . dla/show-org-agenda)
1903 ;; ("<f5>" . bh/org-todo)
1904 ("<S-f5>" . bh/widen)
1905 ("<f7>" . bh/set-truncate-lines)
1906 ("<f8>" . org-cycle-agenda-files)
1907 ("<f9> <f9>" . dla/show-org-agenda)
1909 ("<f9> c" . calendar)
1910 ("<f9> f" . boxquote-insert-file)
1911 ("<f9> h" . bh/hide-other)
1912 ("<f9> n" . bh/toggle-next-task-display)
1915 ("<f9> r" . boxquote-region)
1916 ("<f9> s" . bh/switch-to-scratch)
1918 ("<f9> t" . bh/insert-inactive-timestamp)
1919 ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1921 ("<f9> v" . visible-mode)
1922 ("<f9> l" . org-toggle-link-display)
1923 ("<f9> SPC" . bh/clock-in-last-task)
1924 ("C-<f9>" . previous-buffer)
1925 ("M-<f9>" . org-toggle-inline-images)
1926 ("C-x n r" . narrow-to-region)
1927 ("C-<f10>" . next-buffer)
1928 ("<f11>" . org-clock-goto)
1929 ("C-<f11>" . org-clock-in)
1930 ("C-s-<f12>" . bh/save-then-publish)
1931 ("C-c c" . org-capture))
1934 ** Utility Functions
1935 #+BEGIN_SRC emacs-lisp
1936 (defun bh/hide-other ()
1939 (org-back-to-heading 'invisible-ok)
1940 (outline-hide-other)
1945 (defun bh/set-truncate-lines ()
1946 "Toggle value of truncate-lines and refresh window display."
1948 (setq truncate-lines (not truncate-lines))
1949 ;; now refresh window display (an idiom from simple.el):
1951 (set-window-start (selected-window)
1952 (window-start (selected-window)))))
1954 (defun bh/switch-to-scratch ()
1956 (switch-to-buffer "*scratch*"))
1958 (setq org-use-fast-todo-selection t)
1959 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1961 ; create function to create headlines in file. This comes from
1962 ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1963 (defun my/org-add-ids-to-headlines-in-file ()
1964 "Add ID properties to all headlines in the current file which
1965 do not already have one."
1969 (goto-char (point-min))
1970 (when (not (re-search-forward "^#\\+OPTIONS:.*auto-id:f" (point-max) t))
1971 (org-map-entries 'org-id-get-create))))
1972 (defun dla/org-update-ids-to-headlines-in-file ()
1973 "Add or replace ID properties to all headlines in the current file
1974 (or narrowed region)."
1977 (org-map-entries '(lambda () (org-id-get-create t))))
1978 ; if we wanted to do this to every buffer, do the following:
1979 (add-hook 'org-mode-hook
1981 (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1984 #+BEGIN_SRC emacs-lisp
1985 (use-package find-lisp
1987 (setq org-agenda-text-search-extra-files
1988 (append '(agenda-archives)
1989 (find-lisp-find-files "~/projects/org-notes" "\.org$")
1990 (find-lisp-find-files "~/projects/org-notes" "\.org_archive$")
1994 #+BEGIN_SRC emacs-lisp
1995 (setq org-todo-keywords
1996 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1997 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1999 (setq org-todo-keyword-faces
2000 (quote (("TODO" :foreground "red" :weight bold)
2001 ("NEXT" :foreground "blue" :weight bold)
2002 ("DONE" :foreground "forest green" :weight bold)
2003 ("WAITING" :foreground "orange" :weight bold)
2004 ("HOLD" :foreground "magenta" :weight bold)
2005 ("CANCELLED" :foreground "forest green" :weight bold)
2006 ("MEETING" :foreground "forest green" :weight bold)
2007 ("PHONE" :foreground "forest green" :weight bold))))
2009 (setq org-todo-state-tags-triggers
2010 (quote (("CANCELLED" ("CANCELLED" . t))
2011 ("WAITING" ("WAITING" . t))
2012 ("HOLD" ("WAITING") ("HOLD" . t))
2013 (done ("WAITING") ("HOLD"))
2014 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
2015 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
2016 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
2020 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
2021 ; add ids on creation of nodes
2022 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
2025 ; resolve clocks after 10 minutes of idle; use xprintidle
2026 ; (setq org-clock-idle-time 10)
2027 ; (setq org-clock-x11idle-program-name "xprintidle")
2029 ; this is from http://doc.norang.ca/org-mode.html#Capture
2030 ; use C-M-r for org mode capture
2031 (global-set-key (kbd "C-M-r") 'org-capture)
2033 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
2034 (setq org-refile-targets (quote ((nil :maxlevel . 9)
2035 (org-agenda-files :maxlevel . 9))))
2037 ; Use full outline paths for refile targets - we file directly with IDO
2038 (setq org-refile-use-outline-path t)
2040 ; Targets complete directly with IDO
2041 (setq org-outline-path-complete-in-steps nil)
2043 ; Allow refile to create parent tasks with confirmation
2044 (setq org-refile-allow-creating-parent-nodes (quote confirm))
2046 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
2047 ; (setq org-completion-use-ido t)
2048 ; (setq ido-everywhere t)
2049 ; (setq ido-max-directory-size 100000)
2050 ; (ido-mode (quote both))
2051 ; ; Use the current window when visiting files and buffers with ido
2052 ; (setq ido-default-file-method 'selected-window)
2053 ; (setq ido-default-buffer-method 'selected-window)
2054 ; ; Use the current window for indirect buffer display
2055 ; (setq org-indirect-buffer-display 'current-window)
2058 ;;;; Refile settings
2059 ; Exclude DONE state tasks from refile targets
2060 (defun bh/verify-refile-target ()
2061 "Exclude todo keywords with a done state from refile targets"
2062 (not (member (nth 2 (org-heading-components)) org-done-keywords)))
2064 (setq org-refile-target-verify-function 'bh/verify-refile-target)
2066 ;; ensure that emacsclient will show just the note to be edited when invoked
2067 ;; from Mutt, and that it will shut down emacsclient once finished;
2068 ;; fallback to legacy behavior when not invoked via org-protocol.
2069 (require 'org-protocol)
2070 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
2071 (setq my-org-protocol-flag nil)
2072 (defadvice org-capture-finalize (after delete-frame-at-end activate)
2073 "Delete frame at remember finalization"
2074 (progn (if my-org-protocol-flag (delete-frame))
2075 (setq my-org-protocol-flag nil)))
2076 (defadvice org-capture-refile (around delete-frame-after-refile activate)
2077 "Delete frame at remember refile"
2078 (if my-org-protocol-flag
2080 (setq my-org-protocol-flag nil)
2085 (defadvice org-capture-kill (after delete-frame-at-end activate)
2086 "Delete frame at remember abort"
2087 (progn (if my-org-protocol-flag (delete-frame))
2088 (setq my-org-protocol-flag nil)))
2089 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
2090 (setq my-org-protocol-flag t))
2092 (defadvice org-insert-todo-heading (after dla/create-id activate)
2093 (unless (org-in-item-p)
2099 (add-to-list 'org-modules 'org-habit)
2101 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
2102 (defun open-mail-in-mutt (message)
2103 "Open a mail message in Mutt, using an external terminal.
2105 Message can be specified either by a path pointing inside a
2106 Maildir, or by Message-ID."
2107 (interactive "MPath or Message-ID: ")
2109 (format "faf xterm -e \"%s %s\""
2110 (substitute-in-file-name "$HOME/bin/mutt_open") message)))
2112 ;; add support for "mutt:ID" links
2113 (org-add-link-type "mutt" 'open-mail-in-mutt)
2115 (defun my-org-mode-setup ()
2116 ; (load-library "reftex")
2117 (and (buffer-file-name)
2118 (file-exists-p (buffer-file-name))
2120 ; (reftex-parse-all)
2121 (reftex-set-cite-format
2122 '((?b . "[[bib:%l][%l-bib]]")
2123 (?n . "[[notes:%l][%l-notes]]")
2125 (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
2127 (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
2128 (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
2129 (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
2130 (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
2132 (add-hook 'org-mode-hook 'my-org-mode-setup)
2134 (defun org-mode-reftex-search ()
2136 (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
2138 (defun open-research-paper (bibtexkey)
2139 "Open a paper by bibtex key"
2140 (interactive "bibtex key: ")
2143 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
2144 (org-add-link-type "papers" 'open-research-paper)
2145 (defun open-research-paper-pdf (bibtexkey)
2146 "Open a paper pdf by bibtex key"
2147 (interactive "bibtex key: ")
2149 (format "%s -p evince_annot %s"
2150 (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
2151 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
2153 (add-to-list 'org-link-abbrev-alist
2155 "~/projects/research/paper_notes.org::#%s"))
2157 ; I pretty much always want hiearchical checkboxes
2158 (setq org-hierachical-checkbox-statistics nil)
2160 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
2161 (add-to-list 'org-structure-template-alist
2162 '("E" "\\begin{equation}\n?\n\\end{equation}"))
2165 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
2166 (defun my-rtcite-export-handler (path desc format)
2167 (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
2168 (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
2169 (match-string 1 path)))
2170 (path (substring path 0 (match-beginning 0))))
2171 (cond ((eq format 'latex)
2173 (equal 0 (search "rtcite:" desc)))
2174 (format "\\cite{%s}" search)
2175 (format "\\cite[%s]{%s}" desc search))))))
2177 (org-add-link-type "rtcite"
2179 'my-rtcite-export-handler)
2183 ** Org Mobile Configuration
2184 #+BEGIN_SRC emacs-lisp
2185 (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
2186 (when (string= system-name "linnode")
2187 (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
2188 (setq-default org-directory "/home/don/org-mode/")
2189 (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
2193 #+BEGIN_SRC emacs-lisp
2194 ;; org mode ical export
2195 (setq org-icalendar-timezone "America/Los_Angeles")
2196 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
2197 ;; we already add the id manually
2198 (setq org-icalendar-store-UID t)
2201 ** General Org Babel Configuration
2202 #+BEGIN_SRC emacs-lisp
2203 ;; org babel support
2204 (org-babel-do-load-languages
2205 'org-babel-load-languages
2212 ;; set the right path to ditaa.jar
2213 (setq org-ditaa-jar-path "/usr/share/ditaa/ditaa.jar")
2214 ;; use graphviz-dot for dot things
2215 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
2216 ;; do not indent begin_src blocks
2217 (setq org-edit-src-content-indentation 0)
2218 ;; org-babel-by-backend
2219 (defmacro org-babel-by-backend (&rest body)
2220 `(case (if (boundp 'backend)
2221 (org-export-backend-name backend)
2224 (defun my/fix-inline-images ()
2225 (when org-inline-image-overlays
2226 (org-redisplay-inline-images)))
2228 (add-hook 'org-babel-after-execute-hook
2229 'my/fix-inline-images)
2232 ** LaTeX configuration
2233 #+BEGIN_SRC emacs-lisp
2234 (use-package ox-extra
2236 (ox-extras-activate '(ignore-headlines)))
2238 (add-to-list 'org-latex-classes
2240 "\\documentclass[11pt,oneside,article]{memoir}\n"
2241 ("\\section{%s}" . "\\section*{%s}")
2242 ("\\subsection{%s}" . "\\subsection*{%s}")
2243 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2244 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2245 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2247 (setq org-beamer-outline-frame-options "")
2248 (add-to-list 'org-latex-classes
2250 "\\documentclass[ignorenonframetext]{beamer}
2251 [NO-DEFAULT-PACKAGES]
2254 ("\\section{%s}" . "\\section*{%s}")
2255 ("\\subsection{%s}" . "\\subsection*{%s}")
2256 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2257 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2258 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2260 (add-to-list 'org-latex-classes
2262 "\\documentclass[11pt,oneside]{memoir}\n"
2263 ("\\chapter{%s}" . "\\chapter*{%s}")
2264 ("\\section{%s}" . "\\section*{%s}")
2265 ("\\subsection{%s}" . "\\subsection*{%s}")
2266 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
2268 (add-to-list 'org-latex-classes
2270 "\\documentclass[11pt]{letter}
2271 [NO-DEFAULT-PACKAGES]
2274 ("\\section{%s}" . "\\section*{%s}")
2275 ("\\subsection{%s}" . "\\subsection*{%s}")
2276 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2277 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2278 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2280 (add-to-list 'org-latex-classes
2282 "\\documentclass{dlacv}
2283 [NO-DEFAULT-PACKAGES]
2286 ("\\section{%s}" . "\\section*{%s}")
2287 ("\\subsection{%s}" . "\\subsection*{%s}")
2288 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2289 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2290 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2293 (add-to-list 'org-latex-classes
2295 "\\documentclass{dlaresume}
2296 [NO-DEFAULT-PACKAGES]
2299 ("\\section{%s}" . "\\section*{%s}")
2300 ("\\subsection{%s}" . "\\subsection*{%s}")
2301 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2302 ("\\paragraph{%s}" . "\\paragraph*{%s}")
2303 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2306 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
2307 ;; but adapted to use latexmk 4.22 or higher.
2308 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
2310 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
2311 (setq org-latex-default-packages-alist
2313 ("" "unicode-math" t)
2315 (setq org-latex-packages-alist
2322 ("" "longtable" nil)
2325 ;; make equations larger
2326 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2328 (defun org-create-formula--latex-header ()
2329 "Return LaTeX header appropriate for previewing a LaTeX snippet."
2330 (let ((info (org-combine-plists (org-export--get-global-options
2331 (org-export-get-backend 'latex))
2332 (org-export--get-inbuffer-options
2333 (org-export-get-backend 'latex)))))
2334 (org-latex-guess-babel-language
2335 (org-latex-guess-inputenc
2336 (org-splice-latex-header
2337 org-format-latex-header
2338 org-latex-default-packages-alist
2340 (plist-get info :latex-header)))
2344 ; support ignoring headers in org mode export to latex
2345 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2346 (defadvice org-latex-headline (around my-latex-skip-headlines
2347 (headline contents info) activate)
2348 (if (member "ignoreheading" (org-element-property :tags headline))
2349 (setq ad-return-value contents)
2352 ;; keep latex logfiles
2354 (setq org-latex-remove-logfiles nil)
2356 ;; Resume clocking task when emacs is restarted
2357 (org-clock-persistence-insinuate)
2359 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2360 (setq org-clock-history-length 23)
2361 ;; Resume clocking task on clock-in if the clock is open
2362 (setq org-clock-in-resume t)
2363 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2364 ;; there are things like PHONE calls
2365 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2366 ;; Separate drawers for clocking and logs
2367 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2368 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2369 (setq org-clock-into-drawer t)
2370 (setq org-log-into-drawer t)
2371 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2372 (setq org-clock-out-remove-zero-time-clocks t)
2373 ;; Clock out when moving task to a done state
2374 (setq org-clock-out-when-done t)
2375 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2376 (setq org-clock-persist t)
2377 ;; Do not prompt to resume an active clock
2378 (setq org-clock-persist-query-resume nil)
2379 ;; Enable auto clock resolution for finding open clocks
2380 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2381 ;; Include current clocking task in clock reports
2382 (setq org-clock-report-include-clocking-task t)
2384 ;; the cache seems to be broken
2385 (setq org-element-use-cache nil)
2387 (defvar bh/keep-clock-running nil)
2389 (defun bh/is-task-p ()
2390 "Any task with a todo keyword and no subtask"
2394 (subtree-end (save-excursion (org-end-of-subtree t)))
2395 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2398 (while (and (not has-subtask)
2399 (< (point) subtree-end)
2400 (re-search-forward "^\*+ " subtree-end t))
2401 (when (member (org-get-todo-state) org-todo-keywords-1)
2402 (setq has-subtask t))))
2403 (and is-a-task (not has-subtask)))))
2404 (defun bh/is-project-p ()
2405 "Any task with a todo keyword subtask"
2409 (subtree-end (save-excursion (org-end-of-subtree t)))
2410 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2413 (while (and (not has-subtask)
2414 (< (point) subtree-end)
2415 (re-search-forward "^\*+ " subtree-end t))
2416 (when (member (org-get-todo-state) org-todo-keywords-1)
2417 (setq has-subtask t))))
2418 (and is-a-task has-subtask))))
2420 (defun bh/is-subproject-p ()
2421 "Any task which is a subtask of another project"
2422 (let ((is-subproject)
2423 (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2425 (while (and (not is-subproject) (org-up-heading-safe))
2426 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2427 (setq is-subproject t))))
2428 (and is-a-task is-subproject)))
2431 (defun bh/clock-in-to-next (kw)
2432 "Switch a task from TODO to NEXT when clocking in.
2433 Skips capture tasks, projects, and subprojects.
2434 Switch projects and subprojects from NEXT back to TODO"
2435 (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2437 ((and (member (org-get-todo-state) (list "TODO"))
2440 ((and (member (org-get-todo-state) (list "NEXT"))
2444 (defun bh/punch-in (arg)
2445 "Start continuous clocking and set the default task to the
2446 selected task. If no task is selected set the Organization task
2447 as the default task."
2449 (setq bh/keep-clock-running t)
2450 (if (equal major-mode 'org-agenda-mode)
2452 ;; We're in the agenda
2454 (let* ((marker (org-get-at-bol 'org-hd-marker))
2455 (tags (org-with-point-at marker (org-get-tags))))
2456 (if (and (eq arg 4) tags)
2457 (org-agenda-clock-in '(16))
2458 (bh/clock-in-organization-task-as-default)))
2460 ;; We are not in the agenda
2464 ; Find the tags on the current task
2465 (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2466 (org-clock-in '(16))
2467 (bh/clock-in-organization-task-as-default)))))
2469 (defun bh/punch-out ()
2471 (setq bh/keep-clock-running nil)
2472 (when (org-clock-is-active)
2474 (org-agenda-remove-restriction-lock))
2476 (defun bh/clock-in-default-task ()
2478 (org-with-point-at org-clock-default-task
2481 (defun bh/clock-in-parent-task ()
2482 "Move point to the parent (project) task if any and clock in"
2483 (let ((parent-task))
2487 (while (and (not parent-task) (org-up-heading-safe))
2488 (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2489 (setq parent-task (point))))
2491 (org-with-point-at parent-task
2493 (when bh/keep-clock-running
2494 (bh/clock-in-default-task)))))))
2496 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2498 (defun bh/clock-in-organization-task-as-default ()
2500 (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2501 (org-clock-in '(16))))
2503 (defun bh/clock-out-maybe ()
2504 (when (and bh/keep-clock-running
2505 (not org-clock-clocking-in)
2506 (marker-buffer org-clock-default-task)
2507 (not org-clock-resolving-clocks-due-to-idleness))
2508 (bh/clock-in-parent-task)))
2510 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2513 (defun bh/clock-in-task-by-id (id)
2514 "Clock in a task by id"
2515 (org-with-point-at (org-id-find id 'marker)
2516 (org-clock-in nil)))
2518 (defun bh/clock-in-last-task (arg)
2519 "Clock in the interrupted task if there is one
2520 Skip the default task and get the next one.
2521 A prefix arg forces clock in of the default task."
2523 (let ((clock-in-to-task
2525 ((eq arg 4) org-clock-default-task)
2526 ((and (org-clock-is-active)
2527 (equal org-clock-default-task (cadr org-clock-history)))
2528 (caddr org-clock-history))
2529 ((org-clock-is-active) (cadr org-clock-history))
2530 ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2531 (t (car org-clock-history)))))
2533 (org-with-point-at clock-in-to-task
2534 (org-clock-in nil))))
2537 (defun org-export-to-ods ()
2539 (let ((csv-file "data.csv"))
2540 (org-table-export csv-file "orgtbl-to-csv")
2541 (org-odt-convert csv-file "ods" 'open)))
2543 ; allow for zero-width-space to be a break in regexp too
2544 ; (setcar org-emphasis-regexp-components " [:space:] \t('\"{")
2545 ; (setcar (nthcdr 1 org-emphasis-regexp-components) " [:space:]- \t.,:!?;'\")}\\")
2546 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2548 ;; support inserting screen shots
2549 (defun my/org-insert-screenshot ()
2550 "Take a screenshot into a time stamped unique-named file in the
2551 same directory as the org-buffer and insert a link to this file."
2553 (defvar my/org-insert-screenshot/filename)
2554 (setq my/org-insert-screenshot/filename
2556 "Screenshot to insert: "
2558 (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2561 (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2562 (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2563 (org-display-inline-images))
2565 (defun my/fix-inline-images ()
2566 (when org-inline-image-overlays
2567 (org-redisplay-inline-images)))
2569 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2571 ;; use xelatex to preview with imagemagick
2572 (add-to-list 'org-preview-latex-process-alist
2573 '(xelateximagemagick
2574 :programs ("xelatex" "convert")
2575 :description "pdf > png"
2576 :message "you need to install xelatex and imagemagick"
2578 :image-input-type "pdf"
2579 :image-output-type "png"
2580 :image-size-adjust (1.0 . 1.0)
2581 :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2582 :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2584 ;; use xelatex by default
2585 (setq org-preview-latex-default-process 'xelateximagemagick)
2587 ; from http://orgmode.org/Changes.html
2588 (defun my/org-repair-property-drawers ()
2589 "Fix properties drawers in current buffer.
2590 Ignore non Org buffers."
2592 (when (eq major-mode 'org-mode)
2593 (org-with-wide-buffer
2594 (goto-char (point-min))
2595 (let ((case-fold-search t)
2596 (inline-re (and (featurep 'org-inlinetask)
2597 (concat (org-inlinetask-outline-regexp)
2601 (unless (and inline-re (org-looking-at-p inline-re))
2603 (let ((end (save-excursion (outline-next-heading) (point))))
2605 (when (org-looking-at-p org-planning-line-re) (forward-line))
2606 (when (and (< (point) end)
2607 (not (org-looking-at-p org-property-drawer-re))
2609 (and (re-search-forward org-property-drawer-re end t)
2610 (eq (org-element-type
2611 (save-match-data (org-element-at-point)))
2613 (insert (delete-and-extract-region
2615 (min (1+ (match-end 0)) end)))
2616 (unless (bolp) (insert "\n"))))))))))))
2620 #+BEGIN_SRC emacs-lisp
2624 (use-package calfw-org
2627 (use-package org-gcal
2628 :if (file-readable-p "~/.hide/org_gcal.el")
2630 :config '((if (file-readable-p "~/.hide/org_gcal.el")
2631 (load-file "~/.hide/org_gcal.el"))
2636 #+BEGIN_SRC emacs-lisp
2640 ;; Show notification 10 minutes before event
2641 (setq appt-message-warning-time 10)
2642 ;; Disable multiple reminders
2643 (setq appt-display-interval appt-message-warning-time)
2644 (setq appt-display-mode-line nil)
2646 ;; add automatic reminders for appointments
2647 (defun my/org-agenda-to-appt ()
2649 (setq appt-time-msg-list nil)
2650 (org-agenda-to-appt))
2651 ;; add reminders when starting emacs
2652 (my/org-agenda-to-appt)
2653 ;; when rebuilding the agenda
2654 (defadvice org-agenda-redo (after org-agenda-redo-add-appts)
2655 "Pressing `r' on the agenda will also add appointments."
2656 (my/org-agenda-to-appt)
2658 ;; when saving all org buffers
2659 (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2660 "Re-add appts after saving all org buffers"
2661 (my/org-agenda-to-appt))
2662 ;; Display appointments as a window manager notification
2663 (setq appt-disp-window-function 'my/appt-display)
2664 (setq appt-delete-window-function (lambda () t))
2666 (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2668 (defun my/appt-display (min-to-app new-time msg)
2669 (if (atom min-to-app)
2670 (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2671 (dolist (i (number-sequence 0 (1- (length min-to-app))))
2672 (start-process "my/appt-notification-app" nil my/appt-notification-app
2673 (nth i min-to-app) (nth i msg))))
2679 ** outshine (outlining) integration
2680 #+BEGIN_SRC emacs-lisp
2681 (use-package outshine
2683 :hook (outline-minor-mode . outshine-hook-function)
2687 #+BEGIN_SRC emacs-lisp
2691 ** Home/End Begining/End of line
2692 #+BEGIN_SRC emacs-lisp
2693 (global-set-key [home] 'move-beginning-of-line)
2694 (global-set-key [end] 'move-end-of-line)
2697 #+BEGIN_SRC emacs-lisp
2698 (global-unset-key "\M-g")
2699 (global-set-key (kbd "M-g l") 'goto-line)
2703 #+BEGIN_SRC emacs-lisp
2704 (use-package debian-changelog-mode
2705 :mode "debian/changelog"
2707 (setq debian-changelog-mailing-address "don@debian.org")
2708 (setq debian-changelog-full-name "Don Armstrong"))
2710 * Misc (uncharacterized)
2711 #+BEGIN_SRC emacs-lisp
2712 (setq calendar-latitude 38.6)
2713 (setq calendar-longitude -121.5)
2714 (setq case-fold-search t)
2715 (setq confirm-kill-emacs (quote y-or-n-p))
2716 (setq cperl-lazy-help-time nil)
2718 ** Turn on fontlock and icomplete
2719 #+BEGIN_SRC emacs-lisp
2720 (global-font-lock-mode 1)
2722 (setq log-edit-keep-buffer t)
2724 ** Set mail User agent
2725 #+BEGIN_SRC emacs-lisp
2726 (setq mail-user-agent (quote sendmail-user-agent))
2727 (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2730 #+BEGIN_SRC emacs-lisp
2731 (setq ps-footer-font-size (quote (8 . 10)))
2732 (setq ps-header-font-size (quote (8 . 10)))
2733 (setq ps-header-title-font-size (quote (10 . 10)))
2734 (setq ps-line-number-color "blue")
2735 (setq ps-print-footer t)
2736 (setq ps-print-footer-frame nil)
2737 (setq ps-print-only-one-header t)
2739 ** Only single spacing on sentences
2740 #+BEGIN_SRC emacs-lisp
2741 (setq sentence-end "[.?!][]\"')]*\\($\\| \\| \\)[
2743 (setq sentence-end-double-space nil)
2744 ; enable matching parenthesis
2746 ** Display paren mode
2747 #+BEGIN_SRC emacs-lisp
2749 (setq show-paren-delay 0.2)
2753 #+BEGIN_SRC emacs-lisp
2754 (setq user-mail-address "don@donarmstrong.com")
2757 ** Use primary selection on unix machines
2758 #+BEGIN_SRC emacs-lisp
2759 ;; switch back to the old primary selection method
2760 (if (or (string-equal system-type "darwin")
2761 (string-equal system-type "windows")
2764 (setq select-enable-clipboard t)
2765 (setq select-enable-primary nil)
2768 (setq select-enable-clipboard nil)
2769 (setq select-enable-primary t)
2771 ; (setq mouse-drag-copy-region t)
2773 ;; tramp configuration
2774 (setq tramp-use-ssh-controlmaster-options nil)
2776 (setq-default c-indent-level 4)
2777 (setq-default c-brace-imaginary-offset 0)
2778 (setq-default c-brace-offset -4)
2779 (setq-default c-argdecl-indent 4)
2780 (setq-default c-label-offset -4)
2781 (setq-default c-continued-statement-offset 4)
2783 (setq-default indent-tabs-mode nil)
2784 (setq-default tab-width 4)
2787 ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2788 ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2789 ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2790 ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2791 ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2794 (defun insert-date ()
2795 "Insert date at point."
2797 (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2798 (global-set-key "\C-[d" 'insert-date)
2800 (defun unfill-paragraph (arg)
2801 "Pull this whole paragraph up onto one line."
2803 (let ((fill-column 10000))
2804 (fill-paragraph arg))
2807 (column-number-mode t)
2810 ** Desktop-save-mode
2811 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2812 emacs, and use a different desktop file to restore history
2813 #+BEGIN_SRC emacs-lisp
2814 (use-package desktop
2817 (setq desktop-base-file-name
2818 (convert-standard-filename
2820 (or (getenv "EMACS_SERVER_NAME")
2824 (setq desktop-base-lock-name
2825 (convert-standard-filename
2826 (concat desktop-base-file-name
2828 (setq desktop-auto-save-timeout 60)
2829 (setq desktop-restore-eager 5)
2830 (setq desktop-lazy-verbose nil)
2831 (desktop-save-mode 1)
2835 ** Misc (Uncharacterized)
2836 #+BEGIN_SRC emacs-lisp
2837 '(icomplete-mode on)
2839 ;; custom-set-faces was added by Custom.
2840 ;; If you edit it by hand, you could mess it up, so be careful.
2841 ;; Your init file should contain only one such instance.
2842 ;; If there is more than one, they won't work right.
2843 '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2846 (put 'upcase-region 'disabled nil)
2847 (put 'downcase-region 'disabled nil)
2848 (put 'narrow-to-region 'disabled nil)
2850 ; (defun turn-on-flyspell ()
2851 ; "Force flyspell-mode on using a positive arg. For use in hooks."
2853 ; (flyspell-mode 1))
2856 ; Outline-minor-mode key map
2857 (define-prefix-command 'cm-map nil "Outline-")
2859 (define-key cm-map "q" 'outline-hide-sublevels) ; Hide everything but the top-level headings
2860 (define-key cm-map "t" 'outline-hide-body) ; Hide everything but headings (all body lines)
2861 (define-key cm-map "o" 'outline-hide-other) ; Hide other branches
2862 (define-key cm-map "c" 'outline-hide-entry) ; Hide this entry's body
2863 (define-key cm-map "l" 'outline-hide-leaves) ; Hide body lines in this entry and sub-entries
2864 (define-key cm-map "d" 'outline-hide-subtree) ; Hide everything in this entry and sub-entries
2866 (define-key cm-map "a" 'outline-show-all) ; Show (expand) everything
2867 (define-key cm-map "e" 'outline-show-entry) ; Show this heading's body
2868 (define-key cm-map "i" 'outline-show-children) ; Show this heading's immediate child sub-headings
2869 (define-key cm-map "k" 'outline-show-branches) ; Show all sub-headings under this heading
2870 (define-key cm-map "s" 'outline-show-subtree) ; Show (expand) everything in this heading & below
2872 (define-key cm-map "u" 'outline-up-heading) ; Up
2873 (define-key cm-map "n" 'outline-next-visible-heading) ; Next
2874 (define-key cm-map "p" 'outline-previous-visible-heading) ; Previous
2875 (define-key cm-map "f" 'outline-forward-same-level) ; Forward - same level
2876 (define-key cm-map "b" 'outline-backward-same-level) ; Backward - same level
2877 (global-set-key "\M-o" cm-map)
2878 ; fix up tmux xterm keys
2879 ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2880 (defun fix-up-tmux-keys ()
2881 "Fix up tmux xterm keys"
2884 (let ((x 2) (tkey ""))
2904 ;; ctrl + alt + shift
2906 (setq tkey "C-M-S-"))
2909 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2910 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2911 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2912 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2914 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2916 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2918 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2920 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2922 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2924 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2926 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2928 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2930 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2932 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2934 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2936 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2938 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2940 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2942 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2944 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2946 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2948 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2950 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2952 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2954 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2956 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2958 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2960 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2962 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2964 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2971 ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2973 (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2974 "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2975 (if (or (buffer-modified-p)
2976 (verify-visited-file-modtime)
2977 (< (* 8 1024 1024) (buffer-size))
2978 (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2980 (clear-visited-file-modtime)
2982 (ad-activate 'ask-user-about-supersession-threat)
2986 #+BEGIN_SRC emacs-lisp
2990 (or (getenv "EMACS_SERVER_NAME")
2992 (unless (server-running-p)
2993 (global-set-key "\C-xp" 'server-edit)
3000 #+BEGIN_SRC emacs-lisp
3001 (provide 'don-configuration)