]> git.donarmstrong.com Git - lib.git/blob - emacs_el/configuration/don-configuration.org
turn off paradox github integration
[lib.git] / emacs_el / configuration / don-configuration.org
1 #+PROPERTY: header-args:emacs-lisp :tangle don-configuration.el
2 * Load debugger
3
4 # if for some reason, things get pear-shaped, we want to be able to
5 # enter the debugger by sending -USR2 to emacs
6
7 #+BEGIN_SRC emacs-lisp
8 (setq debug-on-event 'siguser2)
9 #+END_SRC
10 * Initial startup stuff
11 ** Disable startup screen
12 #+BEGIN_SRC emacs-lisp
13   (setq inhibit-startup-screen t)
14 #+END_SRC
15 ** Disable cluter
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))
20 #+END_SRC
21 ** Fullscreen
22 #+BEGIN_SRC emacs-lisp
23   (setq frame-resize-pixelwise t)
24   (add-to-list 'default-frame-alist '(fullscreen . maximixed))
25 #+END_SRC
26 * Package management
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
31   (eval-and-compile
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
35     (require 'gnutls)
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))
45     (eval-when-compile
46       (package-initialize)
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)
57                          (list path)
58                        nil))
59                      load-path))))))
60
61   ;;; fix up info paths for packages
62   (with-eval-after-load "info"
63     (info-initialize)
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)))))
70
71
72   (eval-when-compile
73     (require 'use-package))
74   (require 'bind-key)
75   (require 'diminish)
76 #+END_SRC
77 ** Paradox
78 #+BEGIN_SRC emacs-lisp
79   (use-package paradox
80     :ensure paradox
81     :commands (paradox-upgrade-packages paradox-list-packages)
82     :config
83     (setq paradox-execute-asynchronously t)
84     (setq paradox-github-token t) ; I don't want to be prompted about this integration
85     )
86 #+END_SRC
87 * Paths
88 ** Update PATH
89 #+BEGIN_SRC emacs-lisp
90   (add-to-list 'exec-path '"/usr/local/bin")
91   (add-to-list 'exec-path '"~/bin/")
92 #+END_SRC
93 ** Add library paths
94
95 #+BEGIN_SRC emacs-lisp
96   (add-to-list 'load-path '"~/lib/emacs_el/")
97   (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
98 #+END_SRC
99 * Disable custom-vars
100 #+BEGIN_SRC emacs-lisp
101   ;; Set the custom file to /dev/null and don't bother to load it
102   (setq custom-file "/dev/null")
103 #+END_SRC
104 * Misc functions
105 ** with-library
106 #+BEGIN_SRC emacs-lisp
107 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
108 ;; execute conditional code when loading libraries
109 (defmacro with-library (symbol &rest body)
110   `(when (require ,symbol nil t)
111      ,@body))
112 (put 'with-library 'lisp-indent-function 1)
113 #+END_SRC
114
115 * Variables
116 ** Safe Local Variables
117 #+BEGIN_SRC emacs-lisp
118 (setq safe-local-variable-values
119       (quote ((auto-save-default)
120               (make-backup-files)
121               (cperl-indent-level . 4)
122               (indent-level . 4)
123               (indent-tabs-mode . f)
124               (vcl-indent-level . 4)
125               )))
126 #+END_SRC
127 * Memory
128 #+BEGIN_SRC emacs-lisp
129   (setq global-mark-ring-max 128
130         mark-ring-max 128
131         kill-ring-max 128)
132
133   (defun don/minibuffer-setup-hook ()
134     (setq gc-cons-threshold most-positive-fixnum))
135
136   (defun don/minibuffer-exit-hook ()
137     (setq gc-cons-threshold 1048576))
138
139   (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
140   (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
141 #+END_SRC
142 * Modules
143 ** Spacemacs theme
144 #+BEGIN_SRC emacs-lisp
145 (use-package spacemacs-common
146   :ensure spacemacs-theme
147   :config
148   (load-theme 'spacemacs-dark t)
149   )
150 #+END_SRC
151 ** Hippie Expand
152 #+BEGIN_SRC emacs-lisp
153   (use-package hippie-exp
154     :bind* (("M-<SPC>" . hippie-expand))
155     )
156 #+END_SRC
157 ** Flyspell 🐝 
158 #+BEGIN_SRC emacs-lisp
159   (use-package flyspell
160     :ensure t
161     :diminish flyspell-mode 🐝
162     :config
163     (add-hook 'text-mode-hook 'turn-on-flyspell)
164     (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
165     (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
166     (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
167     :init
168     (setq ispell-program-name "ispell")
169     )
170
171 #+END_SRC
172 ** Flymake
173 #+begin_src emacs-lisp :tangle yes
174   (use-package flymake
175     :diminish "Φ")
176 #+end_src
177
178 ** Winnermode
179 #+BEGIN_SRC emacs-lisp
180   (winner-mode 1)
181 #+END_SRC
182 ** Eyebrowse
183
184 #+BEGIN_SRC emacs-lisp
185   (use-package eyebrowse
186     :ensure t
187     :diminish eyebrowse-mode
188     :init (setq eyebrowse-keymap-prefix (kbd "C-c e"))
189     :config (progn
190               (setq eyebrowse-wrap-around t)
191               (eyebrowse-mode t)
192
193               (defun my/eyebrowse-new-window-config ()
194                 (interactive)
195                 (let ((done nil))
196                   (dotimes (i 10)
197                     ;; start at 1 run till 0
198                     (let ((j (mod (+ i 1) 10)))
199                       (when (and (not done)
200                                  (not (eyebrowse--window-config-present-p j)))
201                         (eyebrowse-switch-to-window-config j)
202                         (call-interactively 'eyebrowse-rename-window-config2 j)
203                         (setq done t)
204                         ))
205                     )))
206
207               ;; I don't use latex-preview-pane
208               ;; (require 'latex-preview-pane)
209               ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
210               ;;   ;; latex-preview-pane uses window-parameters which are
211               ;;   ;; not preserved by eyebrowse, so we close the preview
212               ;;   ;; pane before switching, it will be regenerated when we
213               ;;   ;; edit the TeX file.
214               ;;   (when (lpp/window-containing-preview)
215               ;;     (delete-window (lpp/window-containing-preview))))
216
217               ;; (add-to-list 'eyebrowse-pre-window-switch-hook
218               ;;              #'my/close-latex-preview-pane-before-eyebrowse-switch)
219
220               ;; (my/set-menu-key "["  #'my/eyebrowse-new-window-config)
221               ;; (my/set-menu-key ";"  #'eyebrowse-prev-window-config)
222               ;; (my/set-menu-key "'"  #'eyebrowse-next-window-config)
223               ;; (my/set-menu-key "]"  #'eyebrowse-close-window-config)
224               ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
225               )
226     )
227 #+END_SRC
228
229 ** Window handling
230
231 *** Splitting
232 #+BEGIN_SRC emacs-lisp
233   (defun my/vsplit-last-buffer ()
234     "Split the window vertically and display the previous buffer."
235     (interactive)
236     (split-window-vertically)
237     (other-window 1 nil)
238     (switch-to-next-buffer))
239
240   (defun my/hsplit-last-buffer ()
241     "Split the window horizontally and display the previous buffer."
242     (interactive)
243     (split-window-horizontally)
244     (other-window 1 nil)
245     (switch-to-next-buffer))
246
247   (bind-key "C-x 2" 'my/vsplit-last-buffer)
248   (bind-key "C-x 3" 'my/hsplit-last-buffer)
249
250   (setq split-width-threshold  100)
251   (setq split-height-threshold 60)
252
253   (defun my/split-window-prefer-vertically (window)
254     "If there's only one window (excluding any possibly active
255            minibuffer), then split the current window horizontally."
256     (if (and (one-window-p t)
257              (not (active-minibuffer-window))
258              ( < (frame-width) (frame-height))
259              )
260         (let ((split-width-threshold nil))
261           (split-window-sensibly window))
262       (split-window-sensibly window)))
263
264   (setq split-window-preferred-function #'my/split-window-prefer-vertically)
265   (setq window-combination-resize t)
266 #+END_SRC
267
268 *** Compilation window
269
270 If there is no compilation window, open one at the bottom, spanning
271 the complete width of the frame. Otherwise, reuse existing window. In
272 the former case, if there was no error the window closes
273 automatically.
274
275 #+BEGIN_SRC emacs-lisp
276   (add-to-list 'display-buffer-alist
277                `(,(rx bos "*compilation*" eos)
278                  (display-buffer-reuse-window
279                   display-buffer-in-side-window)
280                  (reusable-frames . visible)
281                  (side            . bottom)
282                  (window-height   . 0.4)))
283 #+END_SRC
284
285 #+BEGIN_SRC emacs-lisp
286   (defun my/compilation-exit-autoclose (status code msg)
287     ;; If M-x compile exists with a 0
288     (when (and (eq status 'exit) (zerop code))
289       ;; and delete the *compilation* window
290       (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
291         (when (and (not (window-at-side-p compilation-window 'top))
292                    (window-at-side-p compilation-window 'left)
293                    (window-at-side-p compilation-window 'right))
294           (delete-window compilation-window))))
295     ;; Always return the anticipated result of compilation-exit-message-function
296     (cons msg code))
297
298   ;; Specify my function (maybe I should have done a lambda function)
299   (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
300 #+END_SRC
301
302 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
303 value, the compilation buffer scrolls automatically to follow the
304 output. If the value is ~first-error~, scrolling stops when the first
305 error appears, leaving point at that error. For any other non-nil
306 value, scrolling continues until there is no more output.
307
308 #+BEGIN_SRC emacs-lisp
309   (setq compilation-scroll-output 'first-error)
310 #+END_SRC
311
312 ** Mode line cleaning
313 *** Diminish
314 #+BEGIN_SRC emacs-lisp
315   (use-package diminish
316     :ensure t)
317 #+END_SRC
318
319 *** Delight 
320 #+BEGIN_SRC emacs-lisp
321   (use-package delight
322     :ensure t)
323 #+END_SRC
324
325 ** Jumping
326 *** Avy
327 #+BEGIN_SRC emacs-lisp
328   (use-package avy
329     :if (>= emacs-major-version 25)
330     :ensure t
331     :bind (("C-c C-<SPC>" . avy-goto-word-or-subword-1)
332            ("C-c j j" . avy-goto-word-or-subword-1)
333            ("M-g g" . avy-goto-line))
334     :config (progn (setq avy-background t))
335     )
336 #+END_SRC
337 *** Ace-link (jumping to links)
338 #+BEGIN_SRC emacs-lisp
339   (use-package ace-link
340     :ensure t
341     ; bind o in most modes
342     :config (ace-link-setup-default))
343 #+END_SRC
344 *** Jumping through edit points (goto-chg)
345 #+BEGIN_SRC emacs-lisp
346   (use-package goto-chg
347     :ensure t
348     :bind (("C-c j ," . goto-last-change)
349            ("C-c j ." . goto-last-change-reverse))
350     )
351 #+END_SRC
352 *** Jumping to bookmarks (visible bookmarks, bm)
353 #+BEGIN_SRC emacs-lisp
354   (use-package bm
355     :ensure t
356     :bind (("C-c j b ." . bm-next)
357            ("C-c j b ," . bm-previous)
358            ("C-c j b SPC" . bm-toggle)))
359 #+END_SRC
360
361 ** Snippets
362 *** Yasnippet
363 #+BEGIN_SRC emacs-lisp
364 (use-package yasnippet
365   :ensure t
366   :diminish yas-minor-mode
367   :config (progn
368             (yas-global-mode)
369             (setq yas-verbosity 1)
370             (define-key yas-minor-mode-map (kbd "<tab>") nil)
371             (define-key yas-minor-mode-map (kbd "TAB") nil)
372             (define-key yas-minor-mode-map (kbd "<backtab>") nil)
373             (setq yas-snippet-dirs '("~/lib/emacs_el/snippets/"
374                                      "~/lib/emacs_el/yasnippet-snippets/snippets/"))
375             (add-to-list 'hippie-expand-try-functions-list
376                              'yas-hippie-try-expand)
377             (yas-reload-all)
378             )
379   )
380 #+END_SRC
381 *** Auto-YASnippet
382 #+BEGIN_SRC emacs-lisp
383   (use-package auto-yasnippet
384     :ensure t
385     :bind (("H-w" . aya-create)
386            ("H-y" . aya-expand)
387            )
388     )
389 #+END_SRC
390 ** Company
391 #+BEGIN_SRC emacs-lisp
392 (use-package company
393   :ensure t
394   :bind (("M-/" . company-complete))
395   :config
396   (setq company-echo-delay 0     ; remove blinking
397         company-show-numbers t   ; show numbers for easy selection
398         company-selection-wrap-around t
399         company-require-match nil
400         company-dabbrev-ignore-case t
401         company-dabbrev-ignore-invisible t
402         company-dabbrev-other-buffers t
403         company-dabbrev-downcase nil
404         company-dabbrev-code-everywhere t
405         company-tooltip-align-annotations t
406         company-minimum-prefix-length 1
407         company-global-modes '(not)
408         company-lighter-base "(C)")
409   (global-company-mode 1)
410   :bind (:map company-active-map
411               ("C-n" . company-select-next)
412               ("C-p" . company-select-previous)
413               ("M-?" . company-show-doc-buffer)
414               ("M-." . company-show-location)
415               )
416   )
417 #+END_SRC
418 *** C/C++
419 #+BEGIN_SRC emacs-lisp
420   (use-package company-c-headers
421     :ensure t
422     :config (progn
423               (defun malb/ede-object-system-include-path ()
424                 "Return the system include path for the current buffer."
425                 (when ede-object
426                   (ede-system-include-path ede-object)))
427
428               (setq company-c-headers-path-system
429                     #'malb/ede-object-system-include-path)
430
431               (add-to-list 'company-backends #'company-c-headers)))
432 #+END_SRC
433 *** Python
434 #+BEGIN_SRC emacs-lisp
435 (use-package company-anaconda
436   :ensure t
437   :config (add-to-list 'company-backends #'company-anaconda))
438 #+END_SRC
439 *** Perl
440 #+BEGIN_SRC emacs-lisp
441   (use-package company-plsense
442     :ensure t
443     )
444 #+END_SRC
445 *** LaTeX
446 #+BEGIN_SRC emacs-lisp
447   (use-package company-math
448     :ensure t)
449 #+END_SRC
450 #+BEGIN_SRC emacs-lisp
451   (use-package company-auctex
452     :ensure t
453     :config (progn
454               (defun company-auctex-labels (command &optional arg &rest ignored)
455                 "company-auctex-labels backend"
456                 (interactive (list 'interactive))
457                 (case command
458                   (interactive (company-begin-backend 'company-auctex-labels))
459                   (prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
460                   (candidates (company-auctex-label-candidates arg))))
461
462               (add-to-list 'company-backends
463                            '(company-auctex-macros
464                              company-auctex-environments
465                              company-math-symbols-unicode
466                              company-math-symbols-latex))
467
468               (add-to-list 'company-backends #'company-auctex-labels)
469               (add-to-list 'company-backends #'company-auctex-bibs)
470               )
471     )
472 #+END_SRC
473 #+BEGIN_SRC emacs-lisp
474   (use-package company-bibtex
475     :ensure t
476     )
477 #+END_SRC
478 *** Shell
479
480  #+BEGIN_SRC emacs-lisp
481    (use-package company-shell
482      :ensure t
483      :config (progn
484                (setq company-shell-modes '(sh-mode shell-mode))
485                (add-to-list 'company-backends 'company-shell)))
486  #+END_SRC
487
488 *** YaSnippet
489
490  Add YasSippet support for all company backends. ([[https://github.com/syl20bnr/spacemacs/pull/179][source]])
491
492  *Note:* Do this at the end of =company-mode= config.
493
494  #+BEGIN_SRC emacs-lisp
495    (defvar malb/company-mode/enable-yas t
496      "Enable yasnippet for all backends.")
497
498    (defun malb/company-mode/backend-with-yas (backend)
499      (if (or (not malb/company-mode/enable-yas)
500              (and (listp backend)
501                   (member 'company-yasnippet backend)))
502          backend
503        (append (if (consp backend) backend (list backend))
504                '(:with company-yasnippet))))
505
506    (setq company-backends
507          (mapcar #'malb/company-mode/backend-with-yas company-backends))
508  #+END_SRC
509
510 *** All the words
511
512  Enable/disable company completion from ispell dictionaries ([[https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-company.el][source]])
513
514  #+BEGIN_SRC emacs-lisp
515    (defun malb/toggle-company-ispell ()
516      (interactive)
517      (cond
518       ((member '(company-ispell :with company-yasnippet) company-backends)
519        (setq company-backends (delete '(company-ispell :with company-yasnippet) company-backends))
520        (add-to-list 'company-backends '(company-dabbrev :with company-yasnippet) t)
521        (message "company-ispell disabled"))
522       (t
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        (message "company-ispell enabled!"))))
526
527    (defun malb/company-ispell-setup ()
528      ;; @see https://github.com/company-mode/company-mode/issues/50
529      (when (boundp 'company-backends)
530        (make-local-variable 'company-backends)
531        (setq company-backends (delete '(company-dabbrev :with company-yasnippet) company-backends))
532        (add-to-list 'company-backends '(company-ispell :with company-yasnippet) t)
533        ;; https://github.com/redguardtoo/emacs.d/issues/473
534        (if (and (boundp 'ispell-alternate-dictionary)
535                 ispell-alternate-dictionary)
536            (setq company-ispell-dictionary ispell-alternate-dictionary))))
537  #+END_SRC
538
539 *** Tab DWIM
540
541  1. =yas-expand= is run first and does what it has to, then it calls =malb/indent-fold-or-complete=.
542
543  2. This function then hopefully does what I want:
544
545     a. if a region is active, just indent
546     b. if we’re looking at a space after a non-whitespace character, we try some company-expansion
547     c. If =hs-minor-mode= or =outline-minor-mode= is active, try those next
548     d. otherwise call whatever would have been called otherwise.
549
550  ([[http://emacs.stackexchange.com/q/21182/8930][source]], [[http://emacs.stackexchange.com/q/7908/8930][source]])
551
552 #+BEGIN_SRC emacs-lisp
553 (defun malb/indent-fold-or-complete (&optional arg)
554   (interactive "P")
555   (cond
556    ;; if a region is active, indent
557    ((use-region-p)
558     (indent-region (region-beginning)
559                    (region-end)))
560    ;; if the next char is space or eol, but prev char not whitespace
561    ((and (not (active-minibuffer-window))
562          (or (looking-at " ")
563              (looking-at "$"))
564          (looking-back "[^[:space:]]")
565          (not (looking-back "^")))
566
567     (cond (company-mode (company-complete-common))
568           (auto-complete-mode (auto-complete))))
569
570    ;; no whitespace anywhere
571    ((and (not (active-minibuffer-window))
572          (looking-at "[^[:space:]]")
573          (looking-back "[^[:space:]]")
574          (not (looking-back "^")))
575     (cond
576      ((bound-and-true-p hs-minor-mode)
577       (save-excursion (end-of-line) (hs-toggle-hiding)))
578      ((bound-and-true-p outline-minor-mode)
579       (save-excursion (outline-cycle)))))
580
581    ;; by default just call whatever was bound
582    (t
583     (let ((fn (or (if (current-local-map) (lookup-key (current-local-map) (kbd "TAB")))
584                   'indent-for-tab-command)))
585       (if (not (called-interactively-p 'any))
586           (fn arg)
587         (setq this-command fn)
588         (call-interactively fn))))))
589
590 (defun malb/toggle-fold ()
591   (interactive)
592   (cond ((eq major-mode 'org-mode)
593          (org-force-cycle-archived))
594         ((bound-and-true-p hs-minor-mode)
595          (save-excursion
596            (end-of-line)
597            (hs-toggle-hiding)))
598
599         ((bound-and-true-p outline-minor-mode)
600          (save-excursion
601            (outline-cycle)))))
602
603 (bind-key "<tab>" #'malb/indent-fold-or-complete)
604 (bind-key "C-<tab>" #'malb/toggle-fold)
605 #+END_SRC
606 ** Tinyprocmail
607
608 #+BEGIN_SRC emacs-lisp
609   ;; load tinyprocmail
610   (use-package tinyprocmail
611     :load-path "~/lib/emacs_el/tiny-tools/lisp/tiny"
612     :mode (".procmailrc" . turn-on-tinyprocmail-mode)
613     )
614 #+END_SRC
615
616 ** Magit
617 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
618   (use-package magit
619     :ensure t
620     :bind (("C-x g" . magit-status)
621            ("C-x C-g" . magit-status))
622     :config
623     ;; refine diffs always (hilight words)
624     (setq magit-diff-refine-hunk nil)
625     )
626   (use-package magit-annex
627     :ensure t
628     :load-path "~/lib/emacs_el/magit-annex/"
629     )
630   (use-package magit-vcsh
631     :ensure t
632     )
633 #+END_SRC
634
635 ** Perl
636 #+BEGIN_SRC emacs-lisp
637   (use-package cperl-mode
638     :config
639     (progn
640       ;; Use c-mode for perl .xs files
641       (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
642       (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
643       (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
644       (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
645       (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
646       (setq cperl-hairy t
647             cperl-indent-level 4
648             cperl-auto-newline nil
649             cperl-auto-newline-after-colon nil
650             cperl-continued-statement-offset 4
651             cperl-brace-offset -1
652             cperl-continued-brace-offset 0
653             cperl-label-offset -4
654             cperl-highlight-variables-indiscriminately t
655             cperl-electric-lbrace-space nil
656             cperl-indent-parens-as-block nil
657             cperl-close-paren-offset -1
658             cperl-tab-always-indent t)
659       ;;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
660   ))
661 #+END_SRC
662
663 ** Markdown mode
664 #+BEGIN_SRC emacs-lisp
665   (use-package markdown-mode
666     :ensure t
667     :mode (("\\.md\\'" . markdown-mode)
668            ("\\.mdwn\\'" . markdown-mode)
669            ("README\\.md\\'" . gfm-mode)
670            )
671     :config
672     (setq markdown-enable-math t)
673     (setq markdown-follow-wiki-link-on-enter nil)
674     (bind-key "M-." #'markdown-jump markdown-mode-map)
675     (add-hook 'markdown-mode-hook #'flyspell-mode)
676     (add-hook 'markdown-mode-hook #'outline-minor-mode)
677     (bind-key "C-<tab>" #'outline-cycle markdown-mode-map)
678   )
679
680 #+END_SRC
681 ** SQL mode
682 #+BEGIN_SRC emacs-lisp
683   ; load sql-indent when sql is loaded
684 (use-package sql
685   :mode (("\\.sql\\'" . sql-mode))
686   :config
687   (require sql-indent))
688 #+END_SRC
689 ** Ediff
690 #+BEGIN_SRC emacs-lisp
691   (use-package ediff
692     :commands ediff ediff3
693     :ensure f
694     :config
695     ;; ediff configuration
696     ;; don't use the multi-window configuration
697     (setq ediff-window-setup-function 'ediff-setup-windows-plain)
698   )
699 #+END_SRC
700 ** Do the Right Thing Indenting
701 Attempts to automatically identify the right indentation for a file
702 #+BEGIN_SRC emacs-lisp
703 (use-package dtrt-indent
704   :ensure t
705 )  
706 #+END_SRC
707 ** VCL --editing varnish configuration files
708 #+BEGIN_SRC emacs-lisp
709   (use-package vcl-mode
710     :ensure t
711     :mode "\\.vcl\\'"
712     )
713   
714 #+END_SRC
715 ** Helm
716 #+BEGIN_SRC emacs-lisp
717   (defun malb/helm-omni (&rest arg)
718     ;; just in case someone decides to pass an argument, helm-omni won't fail.
719     (interactive)
720     (unless helm-source-buffers-list
721       (setq helm-source-buffers-list
722             (helm-make-source "Buffers" 'helm-source-buffers)))
723     (helm-other-buffer
724      (append
725
726      (if (projectile-project-p)
727           '(helm-source-projectile-buffers-list
728             helm-source-buffers-list)
729         '(helm-source-buffers-list)) ;; list of all open buffers
730
731       `(((name . "Virtual Workspace")
732          (candidates . ,(--map (cons (eyebrowse-format-slot it) (car it))
733                                (eyebrowse--get 'window-configs)))
734          (action . (lambda (candidate)
735                      (eyebrowse-switch-to-window-config candidate)))))
736
737       (if (projectile-project-p)
738           '(helm-source-projectile-recentf-list
739             helm-source-recentf)
740         '(helm-source-recentf)) ;; all recent files
741
742       ;; always make some common files easily accessible
743       ;;'(((name . "Common Files")
744        ;;  (candidates . malb/common-file-targets)
745         ;; (action . (("Open" . (lambda (x) (find-file (eval x))))))))
746
747       '(helm-source-files-in-current-dir
748         helm-source-locate
749         helm-source-bookmarks
750         helm-source-buffer-not-found ;; ask to create a buffer otherwise
751         ))
752      "*Helm all the things*"))
753   (use-package helm
754     :ensure helm
755     :diminish helm-mode
756     :bind (("M-x" . helm-M-x)
757            ("C-x C-f" . helm-find-files)
758            ("C-x b" . helm-buffers-list) ; malb/helm-omni)
759            ("C-x C-b" . helm-buffers-list) ; malb/helm-omni)
760            ("C-c <SPC>" . helm-all-mark-rings))
761     :config
762     (require 'helm-config)
763     (require 'helm-for-files)
764     (require 'helm-bookmark)
765
766     (helm-mode 1)
767     (define-key global-map [remap find-file] 'helm-find-files)
768     (define-key global-map [remap occur] 'helm-occur)
769     (define-key global-map [remap list-buffers] 'helm-buffers-list)
770     (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
771     (unless (boundp 'completion-in-region-function)
772       (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
773       (define-key emacs-lisp-mode-map       [remap completion-at-point] 'helm-lisp-completion-at-point))
774     (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
775   )
776 #+END_SRC
777 *** Helm Flx
778
779  [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
780
781  #+BEGIN_SRC emacs-lisp
782  (use-package helm-flx
783    :ensure t
784    :config (progn
785              ;; these are helm configs, but they kind of fit here nicely
786              (setq helm-M-x-fuzzy-match                  t
787                    helm-bookmark-show-location           t
788                    helm-buffers-fuzzy-matching           t
789                    helm-completion-in-region-fuzzy-match t
790                    helm-file-cache-fuzzy-match           t
791                    helm-imenu-fuzzy-match                t
792                    helm-mode-fuzzy-match                 t
793                    helm-locate-fuzzy-match               nil
794                    helm-quick-update                     t
795                    helm-recentf-fuzzy-match              nil
796                    helm-semantic-fuzzy-match             t)
797              (helm-flx-mode +1)))
798  #+END_SRC
799 *** Helm Swoop
800 #+BEGIN_SRC emacs-lisp
801
802   ;;; stolen from https://github.com/malb/emacs.d/blob/master/malb.org
803   (defun malb/helm-swoop-pre-fill ()
804     (thing-at-point 'symbol))
805     (defvar malb/helm-swoop-ignore-major-mode "List of major modes to ignore for helm-swoop")
806     (setq malb/helm-swoop-ignore-major-mode '(dired-mode
807           paradox-menu-mode doc-view-mode pdf-view-mode
808           mu4e-headers-mode org-mode markdown-mode latex-mode
809           ein:notebook-multilang-mode))
810
811     (defun malb/swoop-or-search ()
812       (interactive)
813       (if (or (> (buffer-size) 1048576) ;; helm-swoop can be slow on big buffers
814               (memq major-mode malb/helm-swoop-ignore-major-mode))
815           (isearch-forward)
816         (helm-swoop)))
817
818     (use-package helm-swoop
819       :ensure t
820       :commands helm-swoop
821       :bind (("C-c o" . helm-multi-swoop-org)
822              ("C-s" . malb/swoop-or-search)
823              ("C-M-s" . helm-multi-swoop-all))
824       :config (progn
825
826                 (setq helm-swoop-pre-input-function  #'malb/helm-swoop-pre-fill
827                       helm-swoop-split-with-multiple-windows nil
828                       helm-swoop-split-direction #'split-window-horizontally
829                       helm-swoop-split-window-function 'helm-default-display-buffer
830                       helm-swoop-speed-or-color t)
831
832                 ;; https://emacs.stackexchange.com/questions/28790/helm-swoop-how-to-make-it-behave-more-like-isearch
833                 (defun malb/helm-swoop-C-s ()
834                   (interactive)
835                   (if (boundp 'helm-swoop-pattern)
836                       (if (equal helm-swoop-pattern "")
837                           (previous-history-element 1)
838                         (helm-next-line))
839                     (helm-next-line)))
840
841                 (bind-key "C-S-s" #'helm-swoop-from-isearch isearch-mode-map)
842                 (bind-key "C-S-s" #'helm-multi-swoop-all-from-helm-swoop helm-swoop-map)
843                 (bind-key "C-r"   #'helm-previous-line helm-swoop-map)
844                 (bind-key "C-s"   #'malb/helm-swoop-C-s helm-swoop-map)
845                 (bind-key "C-r"   #'helm-previous-line helm-multi-swoop-map)
846                 (bind-key "C-s"   #'malb/helm-swoop-C-s helm-multi-swoop-map))
847       )
848
849 #+END_SRC
850 *** Helm Ag
851 #+BEGIN_SRC emacs-lisp
852 (use-package helm-ag
853   :ensure t
854   :config (setq helm-ag-base-command "ag --nocolor --nogroup"
855                 helm-ag-command-option "--all-text"
856                 helm-ag-insert-at-point 'symbol
857                 helm-ag-fuzzy-match t
858                 helm-ag-use-temp-buffer t
859                 helm-ag-use-grep-ignore-list t
860                 helm-ag-use-agignore t))
861 #+END_SRC
862 *** Helm Descbinds
863 #+BEGIN_SRC emacs-lisp
864   (use-package helm-descbinds
865     :ensure t
866     :bind ("C-h b" . helm-descbinds)
867     :init (fset 'describe-bindings 'helm-descbinds))
868 #+END_SRC
869
870 *** Helm YaSnippet
871 #+BEGIN_SRC emacs-lisp
872   (use-package helm-c-yasnippet
873     :ensure t
874     :bind ("C-c h y" .  helm-yas-complete)
875     :config (progn
876               (setq helm-yas-space-match-any-greedy t)))
877 #+END_SRC
878 *** Helm Org Rifle
879 #+BEGIN_SRC emacs-lisp
880   (use-package helm-org-rifle
881     :ensure t
882     :config (progn
883               (defun malb/helm-org-rifle-agenda-files (arg)
884                 (interactive "p")
885                 (let ((current-prefix-arg nil))
886                   (cond
887                    ((equal arg 4) (call-interactively #'helm-org-rifle-agenda-files nil))
888                    ((equal arg 16) (helm-org-rifle-occur-agenda-files))
889                    (t (helm-org-agenda-files-headings)))))))
890 #+END_SRC
891 *** Helm Google
892 This can be used to link things pretty quickly if necessary
893 #+BEGIN_SRC emacs-lisp
894   (use-package helm-google
895     :ensure t
896     :bind ("C-c h g" . helm-google)
897     :config
898     (progn (add-to-list 'helm-google-actions
899                         '("Copy URL" . (lambda (candidate)
900                                          (let ((url
901                                                 (replace-regexp-in-string
902                                                  "https://.*q=\\(.*\\)\&sa=.*"
903                                                  "\\1" candidate)))
904                                            (kill-new url))))
905                         t
906                         )
907          
908            (add-to-list 'helm-google-actions
909                         '("Org Store Link" . (lambda (candidate)
910                                                (let ((title (car (split-string candidate "[\n]+")))
911                                                      (url
912                                                       (replace-regexp-in-string
913                                                        "https://.*q=\\(.*\\)\&sa=.*"
914                                                        "\\1" candidate)))
915                                                  (push (list url title) org-stored-links))))
916                         t)
917            ))
918 #+END_SRC
919
920 ** Projectile -- Project management
921 #+begin_src emacs-lisp
922   (use-package projectile
923     :ensure t
924     :bind (("<f5>" . projectile-compile-project)
925            ("<f6>" . next-error))
926     :config (progn
927               (use-package magit :ensure t)
928               (require 'helm-projectile)
929               (helm-projectile-on)
930
931               (setq projectile-make-test-cmd "make check"
932                     projectile-switch-project-action 'helm-projectile
933                     projectile-mode-line  '(:eval (format "»{%s}" (projectile-project-name))))
934
935               (projectile-global-mode)))
936 #+end_src
937
938 *** helm integration
939 #+begin_src emacs-lisp
940   (use-package helm-projectile
941     :ensure t
942     :config (progn
943               (defvar malb/helm-source-file-not-found
944                 (helm-build-dummy-source
945                     "Create file"
946                   :action 'find-file))
947
948               (add-to-list
949                'helm-projectile-sources-list
950                malb/helm-source-file-not-found t)
951
952               (helm-delete-action-from-source
953                "Grep in projects `C-s'"
954                helm-source-projectile-projects)
955
956               (helm-add-action-to-source
957                "Grep in projects `C-s'"
958                'helm-do-ag helm-source-projectile-projects 4)))
959 #+end_src
960 ** Zap to char
961 #+BEGIN_SRC emacs-lisp
962   (use-package avy-zap
963     :ensure t
964     :bind ("M-z" . avy-zap-up-to-char-dwim))
965 #+END_SRC
966 ** Hydra
967 #+BEGIN_SRC emacs-lisp
968   (use-package hydra
969     :bind (("C-c 2" . my/hydra-orgmodes/body)
970            ("C-c @" . my/hydra-orgmodes/body)
971            ("C-c #" . my/hydra-outline/body)
972            ("C-c 3" . my/hydra-outline/body)
973            )
974     :config
975     (defhydra my/hydra-orgmodes (:color blue :hint nil)
976     "
977   _n_: notes _c_: chaim _w_: wildman _o_: ool
978   _u_: uddin _s_: steve _r_: refile  _f_: fh    
979   _p_: read papers      _R_: paper notes
980   _h_: hpcbio
981   _q_: quit
982   _z_: quit
983   "
984     ("n" (find-file "~/projects/org-notes/notes.org"))
985     ("c" (find-file "~/projects/org-notes/chaim.org"))
986     ("w" (find-file "~/projects/org-notes/wildman.org"))
987     ("u" (find-file "~/projects/org-notes/uddin.org"))
988     ("o" (find-file "~/projects/org-notes/ool.org"))
989     ("f" (find-file "~/projects/org-notes/fh.org"))
990     ("s" (find-file "~/projects/org-notes/sndservers.org"))
991     ("r" (find-file my/org-refile-file))
992     ("p" (find-file "~/projects/research/papers_to_read.org"))
993     ("R" (find-file "~/projects/research/paper_notes.org"))
994     ("h" (find-file "~/projects/org-notes/hpcbio.org"))
995     ("q" nil "quit")
996     ("z" nil "quit")
997     )
998
999     ;; from https://github.com/abo-abo/hydra/wiki/Emacs
1000     (defhydra my/hydra-outline (:color pink :hint nil)
1001     "
1002   ^Hide^             ^Show^           ^Move
1003   ^^^^^^------------------------------------------------------
1004   _q_: sublevels     _a_: all         _u_: up
1005   _t_: body          _e_: entry       _n_: next visible
1006   _o_: other         _i_: children    _p_: previous visible
1007   _c_: entry         _k_: branches    _f_: forward same level
1008   _l_: leaves        _s_: subtree     _b_: backward same level
1009   _d_: subtree
1010
1011   "
1012     ;; Hide
1013     ("q" outline-hide-sublevels)    ; Hide everything but the top-level headings
1014     ("t" outline-hide-body)         ; Hide everything but headings (all body lines)
1015     ("o" outline-hide-other)        ; Hide other branches
1016     ("c" outline-hide-entry)        ; Hide this entry's body
1017     ("l" outline-hide-leaves)       ; Hide body lines in this entry and sub-entries
1018     ("d" outline-hide-subtree)      ; Hide everything in this entry and sub-entries
1019     ;; Show
1020     ("a" outline-show-all)          ; Show (expand) everything
1021     ("e" outline-show-entry)        ; Show this heading's body
1022     ("i" outline-show-children)     ; Show this heading's immediate child sub-headings
1023     ("k" outline-show-branches)     ; Show all sub-headings under this heading
1024     ("s" outline-show-subtree)      ; Show (expand) everything in this heading & below
1025     ;; Move
1026     ("u" outline-up-heading)                ; Up
1027     ("n" outline-next-visible-heading)      ; Next
1028     ("p" outline-previous-visible-heading)  ; Previous
1029     ("f" outline-forward-same-level)        ; Forward - same level
1030     ("b" outline-backward-same-level)       ; Backward - same level
1031     ("z" nil "leave"))
1032   )
1033 #+END_SRC
1034
1035 ** Tramp
1036 #+BEGIN_SRC emacs-lisp
1037   (use-package tramp
1038     :config
1039     (add-to-list 'tramp-methods '("vcsh"
1040                                   (tramp-login-program "vcsh")
1041                                   (tramp-login-args
1042                                    (("enter")
1043                                     ("%h")))
1044                                   (tramp-remote-shell "/bin/sh")
1045                                   (tramp-remote-shell-args
1046                                    ("-c")))))
1047 #+END_SRC
1048 ** Reftex
1049 #+BEGIN_SRC emacs-lisp
1050   (use-package reftex
1051     :ensure t
1052     :config
1053     (setq-default reftex-default-bibliography
1054                     '("~/projects/research/references.bib")))
1055 #+END_SRC
1056 ** BibTex
1057 #+BEGIN_SRC emacs-lisp
1058   (use-package bibtex
1059     :config (setq bibtex-user-optional-fields
1060                   (quote (("annote" "Personal annotation (ignored)")
1061                           ("abstract" "")
1062                   ("pmid" "")
1063                   ("doi" ""))))
1064     )
1065
1066 #+END_SRC
1067 ** LaTeX
1068 #+BEGIN_SRC emacs-lisp
1069 (use-package tex
1070   :defer t
1071   :ensure auctex
1072   :config
1073   ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
1074   ;; REFTEX (much enhanced management of cross-ref, labels, etc)
1075   ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
1076   ; (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
1077   ; (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
1078   ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
1079   ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
1080   (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
1081   (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
1082   (add-hook 'LaTeX-mode-hook 'outline-minor-mode)   ; with AUCTeX LaTeX mode
1083   (add-hook 'latex-mode-hook 'outline-minor-mode)   ; with Emacs latex mode
1084
1085   (setq-default reftex-plug-into-AUCTeX t)
1086   ;; support fake section headers
1087   (setq TeX-outline-extra
1088         '(("%chapter" 1)
1089           ("%section" 2)
1090           ("%subsection" 3)
1091           ("%subsubsection" 4)
1092           ("%paragraph" 5)))
1093   ;; add font locking to the headers
1094   (font-lock-add-keywords
1095    'latex-mode
1096    '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
1097       0 'font-lock-keyword-face t)
1098      ("^%chapter{\\(.*\\)}"       1 'font-latex-sectioning-1-face t)
1099      ("^%section{\\(.*\\)}"       1 'font-latex-sectioning-2-face t)
1100      ("^%subsection{\\(.*\\)}"    1 'font-latex-sectioning-3-face t)
1101      ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
1102      ("^%paragraph{\\(.*\\)}"     1 'font-latex-sectioning-5-face t)))
1103
1104   ;; use smart quotes by default instead of `` and ''
1105   ;; taken from http://kieranhealy.org/esk/kjhealy.html
1106   (setq TeX-open-quote "“")
1107   (setq TeX-close-quote "”")
1108
1109   ;; (TeX-add-style-hook
1110   ;;  "latex"
1111   ;;  (lambda ()
1112   ;;    (TeX-add-symbols
1113   ;;     '("DLA" 1))))
1114   ;; (custom-set-variables
1115   ;;  '(font-latex-user-keyword-classes 
1116   ;;    '(("fixme" 
1117   ;;       ("DLA" "RZ")
1118   ;;       font-lock-function-name-face 2 (command 1 t))))
1119   ;; ) 
1120   (setq-default TeX-parse-self t)
1121   (setq-default TeX-auto-save t)
1122   (setq-default TeX-master nil)
1123   (add-to-list 'LaTeX-font-list
1124                '(?\C-a "\\alert{","}"))
1125   (eval-after-load
1126       "latex"
1127     '(TeX-add-style-hook
1128       "cleveref"
1129       (lambda ()
1130         (if (boundp 'reftex-ref-style-alist)
1131             (add-to-list
1132              'reftex-ref-style-alist
1133              '("Cleveref" "cleveref"
1134                (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
1135         (reftex-ref-style-activate "Cleveref")
1136         (TeX-add-symbols
1137          '("cref" TeX-arg-ref)
1138          '("Cref" TeX-arg-ref)
1139          '("cpageref" TeX-arg-ref)
1140          '("Cpageref" TeX-arg-ref)))))
1141   (eval-after-load
1142       "latex"
1143     '(add-to-list 'LaTeX-fill-excluded-macros
1144                   '("Sexpr")))
1145
1146   (use-package font-latex
1147     :config
1148     (setq font-latex-match-reference-keywords
1149           '(
1150             ("fref" "{")
1151             ("Fref" "{")
1152             ("citep" "{")
1153             ("citet" "{")
1154             ("acs" "{")
1155             ("acsp" "{")
1156             ("ac" "{")
1157             ("acp" "{")
1158             ("acl" "{")
1159             ("aclp" "{")
1160             ("acsu" "{")
1161             ("aclu" "{")
1162             ("acused" "{")
1163             ("DLA" "{")
1164             ("RZ" "{")
1165             ("OM" "{")
1166             ("DL" "{")
1167             ("fixme" "{"))
1168           )
1169     )
1170   (setq font-latex-fontify-script nil)
1171   (setq font-latex-fontify-sectioning (quote color))
1172   (setq font-latex-script-display (quote (nil)))
1173 )
1174
1175 #+END_SRC
1176 ** ESS
1177 #+BEGIN_SRC emacs-lisp
1178   (use-package ess
1179     :ensure t
1180     :commands R
1181     :mode ("\\.R\\'" . ess-r-mode)
1182     :bind (:map ess-mode-map
1183                 ("C-c C-R" . dla/ess-region-remote-eval))
1184     :init
1185     (autoload 'ess-r-mode "ess-site" nil t)
1186     (autoload 'R "ess-site" nil t)
1187     :config
1188     ; actually load the rest of ess
1189     (require 'ess-site)
1190     (defun ess-change-directory (path)
1191       "Set the current working directory to PATH for both *R* and Emacs."
1192       (interactive "Directory to change to: ")
1193     
1194       (when (file-exists-p path)
1195         (ess-command (concat "setwd(\"" path "\")\n"))
1196         ;; use file-name-as-directory to ensure it has trailing /
1197         (setq default-directory (file-name-as-directory path))))
1198     (add-hook 'ess-mode-hook 'flyspell-prog-mode)
1199     ;; outlining support for ess modes
1200     (add-hook
1201      'ess-mode-hook
1202      '(lambda ()
1203         (outline-minor-mode)
1204         (setq outline-regexp "\\(^#\\{4,5\\} \\)\\|\\(^[a-zA-Z0-9_\.]+ ?<- ?function\\)")
1205         (defun outline-level ()
1206           (cond ((looking-at "^##### ") 1)
1207                 ((looking-at "^#### ") 2)
1208                 ((looking-at "^[a-zA-Z0-9_\.]+ ?<- ?function(.*{") 3)
1209                 (t 1000)))
1210         ))
1211     (defun dla/ess-region-remote-eval (start end)
1212       "Evaluate region in a remote ESS instance"
1213       (interactive "r")
1214       (shell-command-on-region start end "eval_r" (get-buffer-create "***essregionremoteeval***") nil nil nil)
1215       (kill-buffer "***essregionremoteeval***"))
1216     ;; Don't restore history or save workspace image
1217     '(inferior-R-args "--no-restore-history --no-save")
1218     )
1219 #+END_SRC
1220
1221 ** Rainbowmode
1222 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
1223
1224 #+BEGIN_SRC emacs-lisp
1225   (use-package rainbow-mode
1226     ;; add ess to the x major mode
1227     :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
1228     (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
1229   )
1230 #+END_SRC
1231
1232 ** YAML Mode
1233 #+BEGIN_SRC emacs-lisp
1234   (use-package yaml-mode
1235     ;; add ess to the x major mode
1236     :mode ("\\.\\(yaml|yml\\)\\'" . yaml-mode)
1237   )
1238 #+END_SRC
1239
1240 ** Polymode
1241 #+BEGIN_SRC emacs-lisp
1242 (use-package poly-noweb
1243   :ensure t
1244   :after polymode
1245
1246   )
1247 (use-package poly-markdown
1248   :ensure t
1249   :after polymode
1250   )
1251 (use-package poly-R
1252   :ensure t
1253   :after (:all polymode poly-markdown poly-noweb)
1254   ; :mode ("\\.Snw" . poly-noweb+r-mode)
1255   ; :mode ("\\.Rnw" . poly-noweb+r-mode)
1256   ; :mode ("\\.Rmd" . poly-markdown+r-mode)
1257   )
1258 (use-package polymode
1259   :ensure t
1260   )
1261
1262 #+END_SRC
1263
1264 ** Outlining
1265 *** Outline magic
1266 #+BEGIN_SRC emacs-lisp
1267   (use-package outline-magic)
1268 #+END_SRC
1269 *** Outline mode
1270 #+BEGIN_SRC emacs-lisp
1271 ;; change the outline mode prefix from C-c @ to C-c C-2
1272 (setq outline-minor-mode-prefix "C-c C-2")
1273 ;;(add-hook 'outline-minor-mode-hook
1274 ;;          (lambda () (local-set-key (kbd "C-c C-2")
1275 ;;                                    outline-mode-prefix-map)))
1276
1277 #+END_SRC
1278 ** Writeroom Mode
1279 #+BEGIN_SRC emacs-lisp
1280   (use-package writeroom-mode
1281     :config
1282     (defun my/writing-mode ()
1283       "Start my writing mode; enable visual-line-mode and auto-fill-mode"
1284       (interactive)
1285       (if writeroom-mode
1286           (progn
1287             (writeroom-mode -1)
1288             (visual-line-mode -1)
1289             (auto-fill-mode -1)
1290             (visual-fill-column-mode -1)
1291             )
1292         (visual-line-mode 1)
1293         (auto-fill-mode 1)
1294         (visual-fill-column-mode 1)
1295         (writeroom-mode 1))
1296       )
1297     )
1298 #+END_SRC
1299 ** GhostText/Atomic Chrome
1300 #+BEGIN_SRC emacs-lisp
1301   (use-package atomic-chrome
1302     :config
1303     (ignore-errors (atomic-chrome-start-server))
1304     (setq atomic-chrome-buffer-open-style 'full)
1305     )
1306 #+END_SRC
1307 ** Edit Server
1308 #+BEGIN_SRC emacs-lisp
1309   (use-package edit-server
1310     :ensure t
1311     :commands edit-server-start
1312     :init (if after-init-time
1313               (edit-server-start)
1314             (add-hook 'after-init-hook
1315                       #'(lambda() (edit-server-start))))
1316     :config (setq edit-server-new-frame-alist
1317                   '((name . "Edit with Emacs FRAME")
1318                     (top . 200)
1319                     (left . 200)
1320                     (width . 80)
1321                     (height . 25)
1322                     (minibuffer . t)
1323                     (menu-bar-lines . t)
1324                     (window-system . x)))
1325     )
1326 #+END_SRC
1327 ** Multiple Cursors
1328    :PROPERTIES:
1329    :ID:       6fcf218b-a762-4c37-9339-a8202ddeb544
1330    :END:
1331 [[https://github.com/magnars/multiple-cursors.el][Multiple Cursors]]
1332 #+BEGIN_SRC emacs-lisp
1333   (use-package multiple-cursors
1334     :bind* (("C-;" . mc/mark-all-dwim)
1335             ("C-<" . mc/mark-previous-like-this)
1336             ("C->" . mc/mark-next-like-this)
1337             ("C-S-c C-S-c" . mc/edit-lines))
1338     )
1339 #+END_SRC
1340 ** Web Mode
1341 #+BEGIN_SRC emacs-lisp
1342   (use-package web-mode
1343     :load-path "/home/don/projects/web-mode/"
1344     :mode ("\\.\\(tx|tmpl\\)\\'" . web-mode)
1345     :config
1346     (add-to-list 'auto-mode-alist '("\\.tmpl\\'" . web-mode))
1347     (setq web-mode-enable-engine-detection t)
1348     (setq web-mode-engines-alist
1349           '(("template-toolkit" . "\\.tmpl\\'")))
1350     )
1351 #+END_SRC
1352 ** Spamassassin Mode
1353 #+BEGIN_SRC emacs-lisp
1354   (use-package spamassassin-mode
1355     :commands spamassassin-mode
1356     :ensure f
1357     )
1358 #+END_SRC
1359 ** Password Store
1360 #+BEGIN_SRC emacs-lisp
1361   (use-package password-store
1362     :ensure f
1363     :commands password-store-edit password-store-generate
1364     )
1365 #+END_SRC
1366 ** CSS mode
1367 #+BEGIN_SRC emacs-lisp
1368   (use-package css
1369     :mode "\\.css'"
1370     :config
1371     ;; fix up css mode to not be silly
1372     ;; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
1373     (setq cssm-indent-level 4)
1374     (setq cssm-newline-before-closing-bracket t)
1375     (setq cssm-indent-function #'cssm-c-style-indenter)
1376     (setq cssm-mirror-mode nil))
1377 #+END_SRC
1378 ** Abbrev Mode
1379 #+BEGIN_SRC emacs-lisp
1380   (use-package abbrev
1381     :diminish abbrev-mode
1382     :config
1383     ;; load abbreviations from 
1384     (setq abbrev-file-name       
1385           "~/.emacs_abbrev_def")
1386
1387     ;; read the abbrev file if it exists
1388     (if (file-exists-p abbrev-file-name)
1389         (quietly-read-abbrev-file))
1390
1391     ;; for now, use abbrev mode everywhere
1392     (setq default-abbrev-mode t))
1393 #+END_SRC
1394
1395 ** Python Programming
1396 #+BEGIN_SRC emacs-lisp
1397   (use-package elpy
1398     :ensure t
1399     :init
1400     (elpy-enable)
1401     )
1402 #+END_SRC
1403
1404 ** Go language
1405 #+BEGIN_SRC emacs-lisp
1406 (use-package go-mode
1407              :diminish "go"
1408              :mode "\\.go"
1409              )
1410 #+END_SRC
1411
1412 ** Expand region
1413 #+BEGIN_SRC emacs-lisp
1414 (use-package expand-region
1415   :bind (("C-=" . 'er/expand-region))
1416   )
1417 #+END_SRC
1418
1419 ** Dockerfile
1420 #+BEGIN_SRC emacs-lisp
1421 (use-package dockerfile-mode
1422   :mode "Dockerfile"
1423   )
1424 #+END_SRC
1425
1426 ** Beancount
1427 #+BEGIN_SRC emacs-lisp
1428 (use-package beancount
1429   :load-path "~/lib/emacs_el/beancount-mode/"
1430   :ensure f
1431   :mode "\\.beancount\\'"
1432   
1433   )
1434 #+END_SRC
1435 * Email
1436 ** Mutt
1437 *** Message-mode
1438 #+BEGIN_SRC emacs-lisp
1439 (use-package message
1440   :ensure f
1441   :diminish (message "✉")
1442   :mode ("muttng-[a-z0-9]+-[0-9]+-" . message-mode)
1443   :mode ("mutt-[a-z0-9]+-[0-9]+-" . message-mode)
1444   :hook 'my/message-mode-settings
1445   :hook 'turn-on-flyspell
1446   :bind (:map message-mode-map
1447       ("C-c C-a" . my/post-attach-file))
1448   :delight (message-mode "✉")
1449   :config
1450   (defun my/message-mode-settings ()
1451     (font-lock-add-keywords nil
1452                 '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
1453                (0 'message-multiply-quoted-text-face))
1454               ("^[ \t]*>[ \t]*>.*$"
1455                (0 'message-double-quoted-text-face))))
1456     )
1457
1458   (defun my/post-attach-file ()
1459     "Prompt for an attachment."
1460     (interactive)
1461     (let ((file (read-file-name "Attach file: " nil nil t nil)))
1462       (my/header-attach-file file "")))
1463
1464   (defun my/header-attach-file (file description)
1465     "Attach a FILE to the current message (works with Mutt).
1466   Argument DESCRIPTION MIME description."
1467     (interactive "fAttach file: \nsDescription: ")
1468     (when (> (length file) 0)
1469   (save-excursion
1470     (save-match-data
1471       (save-restriction
1472         (widen)
1473         (goto-char (point-min))
1474         (search-forward-regexp "^$")
1475         (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
1476                 description "\n"))
1477         (message (concat "Attached '" file "'."))
1478         (setq post-has-attachment t))))))
1479
1480   (setq mail-yank-prefix "> ")
1481   (setq mail-header-separator "") ; fix broken header detection
1482 )
1483 #+END_SRC
1484 *** Muttrc mode
1485 #+BEGIN_SRC emacs-lisp
1486   (use-package muttrc-mode
1487     :mode "muttngrc"
1488     :mode "muttrc"
1489   )
1490
1491 #+END_SRC
1492 * Base emacs
1493 ** Reverting buffers
1494 #+BEGIN_SRC emacs-lisp
1495   (use-package autorevert
1496     :diminish auto-revert-mode
1497     :config
1498     (setq global-auto-revert-non-file-buffers t
1499           global-auto-revert-ignore-modes '(pdf-view-mode)
1500           auto-revert-verbose nil)
1501     (global-auto-revert-mode 1))
1502 #+END_SRC
1503 * Org Mode
1504 ** Use-package and load things
1505 #+BEGIN_SRC emacs-lisp
1506
1507   (use-package org
1508     :delight (org-mode "ø")
1509     :mode ("\\.\\(org\\|org_archive\\|txt\\)\\'" . org-mode)
1510     :bind (("C-c l"  . org-store-link)
1511            ("C-c a"  . org-agenda)
1512            ("C-c b"  . org-iswitchb))
1513 #+END_SRC
1514 ** Agenda Configuration
1515 #+BEGIN_SRC emacs-lisp
1516   :config
1517   (setq-default org-log-done 'time)
1518   (setq-default org-agenda-ndays 5)
1519
1520   (setq org-agenda-sticky t)
1521   (defun dla/show-org-agenda ()
1522     (interactive)
1523     (let (agendabuffer
1524           '(delq nil 
1525                 (mapcar (lambda (x)
1526                           (and (string-match-p
1527                                 "\*Org Agenda.*\*"
1528                                 (buffer-name x))
1529                                x)
1530                           )
1531                         (buffer-list))))
1532       (if agendabuffer
1533           (switch-to-buffer
1534            (buffer-name agendabuffer))
1535         (org-agenda-list)))
1536       (delete-other-windows))
1537
1538   ;; agenda configuration
1539   ;; Do not dim blocked tasks
1540   (setq org-agenda-dim-blocked-tasks nil)
1541   (setq org-agenda-inhibit-startup t)
1542   (setq org-agenda-use-tag-inheritance nil)
1543
1544   ;; Compact the block agenda view
1545   (setq org-agenda-compact-blocks t)
1546
1547   ;; Custom agenda command definitions
1548   (setq org-agenda-custom-commands
1549         (quote (("N" "Notes" tags "NOTE"
1550                  ((org-agenda-overriding-header "Notes")
1551                   (org-tags-match-list-sublevels t)))
1552                 ("h" "Habits" tags-todo "STYLE=\"habit\""
1553                  ((org-agenda-overriding-header "Habits")
1554                   (org-agenda-sorting-strategy
1555                    '(todo-state-down effort-up category-keep))))
1556                 (" " "Agenda"
1557                  ((agenda "" nil)
1558                   (tags "REFILE"
1559                         ((org-agenda-overriding-header "Tasks to Refile")
1560                          (org-tags-match-list-sublevels nil)))
1561                   (tags-todo "-CANCELLED/!"
1562                              ((org-agenda-overriding-header "Stuck Projects")
1563                               (org-agenda-skip-function 'bh/skip-non-stuck-projects)
1564                               (org-agenda-sorting-strategy
1565                                '(category-keep))))
1566                   (tags-todo "-HOLD-CANCELLED/!"
1567                              ((org-agenda-overriding-header "Projects")
1568                               (org-agenda-skip-function 'bh/skip-non-projects)
1569                               (org-tags-match-list-sublevels 'indented)
1570                               (org-agenda-sorting-strategy
1571                                '(category-keep))))
1572                   (tags-todo "-CANCELLED/!NEXT"
1573                              ((org-agenda-overriding-header (concat "Project Next Tasks"
1574                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
1575                                                                         ""
1576                                                                       " (including WAITING and SCHEDULED tasks)")))
1577                               (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
1578                               (org-tags-match-list-sublevels t)
1579                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1580                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1581                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1582                               (org-agenda-sorting-strategy
1583                                '(todo-state-down effort-up category-keep))))
1584                   (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1585                              ((org-agenda-overriding-header (concat "Project Subtasks"
1586                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
1587                                                                         ""
1588                                                                       " (including WAITING and SCHEDULED tasks)")))
1589                               (org-agenda-skip-function 'bh/skip-non-project-tasks)
1590                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1591                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1592                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1593                               (org-agenda-sorting-strategy
1594                                '(category-keep))))
1595                   (tags-todo "-REFILE-CANCELLED-WAITING-HOLD/!"
1596                              ((org-agenda-overriding-header (concat "Standalone Tasks"
1597                                                                     (if bh/hide-scheduled-and-waiting-next-tasks
1598                                                                         ""
1599                                                                       " (including WAITING and SCHEDULED tasks)")))
1600                               (org-agenda-skip-function 'bh/skip-project-tasks)
1601                               (org-agenda-todo-ignore-scheduled bh/hide-scheduled-and-waiting-next-tasks)
1602                               (org-agenda-todo-ignore-deadlines bh/hide-scheduled-and-waiting-next-tasks)
1603                               (org-agenda-todo-ignore-with-date bh/hide-scheduled-and-waiting-next-tasks)
1604                               (org-agenda-sorting-strategy
1605                                '(category-keep))))
1606                   (tags-todo "-CANCELLED+WAITING|HOLD/!"
1607                              ((org-agenda-overriding-header "Waiting and Postponed Tasks")
1608                               (org-agenda-skip-function 'bh/skip-stuck-projects)
1609                               (org-tags-match-list-sublevels nil)
1610                               (org-agenda-todo-ignore-scheduled t)
1611                               (org-agenda-todo-ignore-deadlines t)))
1612                   (tags "-REFILE/"
1613                         ((org-agenda-overriding-header "Tasks to Archive")
1614                          (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
1615                          (org-tags-match-list-sublevels nil))))
1616                  nil))))
1617
1618   ; org mode agenda files
1619   (setq org-agenda-files
1620         (append
1621         (file-expand-wildcards "~/projects/org-notes/*.org")
1622         (file-expand-wildcards "~/org-mode/from-mobile.org")
1623         (file-expand-wildcards "~/org-notes-*/*.org")
1624         )
1625   )
1626   (setq my/org-refile-file
1627         (car (seq-filter
1628               (lambda (file) (string-match-p (regexp-quote "/refile.org") file))
1629               org-agenda-files)))
1630
1631   (set-register ?n (cons 'file "~/projects/org-notes/notes.org"))
1632   (set-register ?r (cons 'file my/org-refile-file))
1633   (set-register ?o (cons 'file "~/projects/org-notes/ool.org"))
1634   (set-register ?s (cons 'file "~/projects/org-notes/sndservers.org"))
1635   (set-register ?c (cons 'file "~/projects/org-notes/chaim.org"))
1636   (set-register ?w (cons 'file "~/projects/org-notes/wildman.org"))
1637   (set-register ?u (cons 'file "~/projects/org-notes/uddin.org"))
1638   (set-register ?R (cons 'file "~/projects/reviews/reviews.org"))
1639   (set-register ?d (cons 'file "~/projects/org-notes/diary.org"))
1640   ; from https://emacs.stackexchange.com/questions/909/how-can-i-have-an-agenda-timeline-view-of-multiple-files
1641   (defun org-agenda-timeline-all (&optional arg)
1642     (interactive "P")
1643     (with-temp-buffer
1644       (dolist (org-agenda-file org-agenda-files)
1645         (insert-file-contents org-agenda-file nil)
1646         (goto-char (point-max))
1647         (newline))
1648       (write-file "/tmp/timeline.org")
1649       (org-agenda arg "L")))
1650   (define-key org-mode-map (kbd "C-c t") 'org-agenda-timeline-all)
1651
1652 #+END_SRC
1653 ** General config
1654 #+BEGIN_SRC emacs-lisp
1655   (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")))
1656   (setq org-columns-default-format "%40ITEM(Task) %6Effort{:} %CLOCKSUM %PRIORITY %TODO %13SCHEDULED %13DEADLINE %TAGS")
1657
1658   (setq org-default-notes-file "~/projects/org-notes/notes.org")
1659   (setq org-id-link-to-org-use-id 'use-existing)
1660 #+END_SRC
1661 ** Capture Templates
1662 #+BEGIN_SRC emacs-lisp
1663   (setq org-capture-templates  ;; mail-specific note template, identified by "m"
1664         `(("m" "Mail" entry (file my/org-refile-file)
1665            "* %?\n\n  Source: %u, [[%:link][%:description]]\n  %:initial")
1666           ("t" "todo" entry (file my/org-refile-file)
1667            "* TODO %?\n  :PROPERTIES:\n  :END:\n  :LOGBOOK:\n  :END:\n%U\n%a\n" :clock-in t :clock-resume t)
1668           ("r" "respond" entry (file my/org-refile-file)
1669            "* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n" :clock-in t :clock-resume t :immediate-finish t)
1670           ("n" "note" entry (file my/org-refile-file)
1671            "* %? :NOTE:\n%U\n%a\n" :clock-in t :clock-resume t)
1672           ("s" "schedule" entry (file my/org-refile-file)
1673            "* %? :cal:\n%^{scheduled:}t\n%U\n%a\n" :clock-in t :clock-resume t)
1674           ("j" "Journal" entry (file+datetree "~/projects/org-notes/diary.org")
1675            "* %?\n%U\n" :clock-in t :clock-resume t)
1676           ("w" "org-protocol" entry (file my/org-refile-file)
1677            "* TODO Review %c\n%U\n" :immediate-finish t)
1678           ("M" "Meeting" entry (file my/org-refile-file)
1679            "* MEETING with %? :MEETING:\n%U" :clock-in t :clock-resume t)
1680           ("S" "Seminar" entry (file my/org-refile-file)
1681            "* SEMINAR notes %? :SEMINAR:\n%U" :clock-in t :clock-resume t)
1682           ("P" "Paper to read" entry (file+headline "~/projects/research/papers_to_read.org" "Refile")
1683            "* TODO Get/Read %? \n%U" :clock-in t :clock-resume t)
1684           ("p" "Phone call" entry (file my/org-refile-file)
1685            "* PHONE %? :PHONE:\n%U" :clock-in t :clock-resume t)
1686            ("J" "job" entry (file+olp "~/projects/org-notes/notes.org"
1687                                        "Jobs"
1688                                        ,(format-time-string "Positions %Y"))
1689            "* TODO Apply for %? :job:\nSCHEDULED: <%<%Y-%m-%d>>\n%U\n%x\n" :clock-in t :clock-resume t)
1690           ("h" "Habit" entry (file my/org-refile-file)
1691            "* 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")
1692           )
1693         )
1694
1695   ;; Remove empty LOGBOOK drawers on clock out
1696   (defun bh/remove-empty-drawer-on-clock-out ()
1697     (interactive)
1698     (save-excursion
1699       (beginning-of-line 0)
1700       (org-remove-empty-drawer-at (point))))
1701
1702   (defun my/org-add-id ()
1703     (interactive)
1704     (save-excursion
1705       (if (org-current-level)
1706           ()
1707         (forward-char 1)
1708         )
1709       (org-id-get-create)
1710       )
1711   )
1712
1713 #+END_SRC
1714 ** Org mode key bindings
1715 #+BEGIN_SRC emacs-lisp
1716   ;; org mode configuration from http://doc.norang.ca/org-mode.html
1717   ;; Custom Key Bindings
1718   :bind* (("<f9> a" . org-agenda)
1719           ("<f9> I" . bh/punch-in)
1720           ("<f9> O" . bh/punch-out)
1721           ("<f9> SPC" . bh/clock-in-last-task)
1722           ("<f12>" . dla/show-org-agenda)
1723           ;; ("<f5>" . bh/org-todo)
1724           ("<S-f5>" . bh/widen)
1725           ("<f7>" . bh/set-truncate-lines)
1726           ("<f8>" . org-cycle-agenda-files)
1727           ("<f9> <f9>" . dla/show-org-agenda)
1728           ("<f9> b" . bbdb)
1729           ("<f9> c" . calendar)
1730           ("<f9> f" . boxquote-insert-file)
1731           ("<f9> h" . bh/hide-other)
1732           ("<f9> n" . bh/toggle-next-task-display)
1733           ("<f9> w" . widen)
1734
1735           ("<f9> r" . boxquote-region)
1736           ("<f9> s" . bh/switch-to-scratch)
1737
1738           ("<f9> t" . bh/insert-inactive-timestamp)
1739           ("<f9> T" . bh/toggle-insert-inactive-timestamp)
1740
1741           ("<f9> v" . visible-mode)
1742           ("<f9> l" . org-toggle-link-display)
1743           ("<f9> SPC" . bh/clock-in-last-task)
1744           ("C-<f9>" . previous-buffer)
1745           ("M-<f9>" . org-toggle-inline-images)
1746           ("C-x n r" . narrow-to-region)
1747           ("C-<f10>" . next-buffer)
1748           ("<f11>" . org-clock-goto)
1749           ("C-<f11>" . org-clock-in)
1750           ("C-s-<f12>" . bh/save-then-publish)
1751           ("C-c c" . org-capture))
1752   :config
1753 #+END_SRC
1754 ** Utility Functions
1755 #+BEGIN_SRC emacs-lisp
1756   (defun bh/hide-other ()
1757     (interactive)
1758     (save-excursion
1759       (org-back-to-heading 'invisible-ok)
1760       (outline-hide-other)
1761       (org-cycle)
1762       (org-cycle)
1763       (org-cycle)))
1764
1765   (defun bh/set-truncate-lines ()
1766     "Toggle value of truncate-lines and refresh window display."
1767     (interactive)
1768     (setq truncate-lines (not truncate-lines))
1769     ;; now refresh window display (an idiom from simple.el):
1770     (save-excursion
1771       (set-window-start (selected-window)
1772                         (window-start (selected-window)))))
1773
1774   (defun bh/switch-to-scratch ()
1775     (interactive)
1776     (switch-to-buffer "*scratch*"))
1777
1778   (setq org-use-fast-todo-selection t)
1779   (setq org-treat-S-cursor-todo-selection-as-state-change nil)
1780
1781   ; create function to create headlines in file. This comes from
1782   ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
1783   (defun my/org-add-ids-to-headlines-in-file ()
1784     "Add ID properties to all headlines in the current file which
1785   do not already have one."
1786     (interactive)
1787     (org-map-entries 'org-id-get-create))
1788   (defun dla/org-update-ids-to-headlines-in-file ()
1789     "Add or replace ID properties to all headlines in the current file 
1790   (or narrowed region)."
1791     (interactive)
1792     (org-map-entries '(lambda () (org-id-get-create t))))
1793   ; if we wanted to do this to every buffer, do the following:
1794   ; (add-hook 'org-mode-hook
1795   ;           (lambda ()
1796   ;             (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
1797 #+END_SRC
1798 ** Org ID locations
1799 #+BEGIN_SRC emacs-lisp
1800 (use-package find-lisp
1801   :ensure t)
1802 (setq org-agenda-text-search-extra-files
1803       (append '(agenda-archives)
1804               (find-lisp-find-files "~/projects/org-notes" "\.org$")
1805               (find-lisp-find-files "~/projects/org-notes" "\.org_archive$")
1806               ))
1807 #+END_SRC
1808 ** Keywords (TODO)
1809 #+BEGIN_SRC emacs-lisp
1810 (setq org-todo-keywords
1811       (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
1812               (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
1813
1814 (setq org-todo-keyword-faces
1815       (quote (("TODO" :foreground "red" :weight bold)
1816               ("NEXT" :foreground "blue" :weight bold)
1817               ("DONE" :foreground "forest green" :weight bold)
1818               ("WAITING" :foreground "orange" :weight bold)
1819               ("HOLD" :foreground "magenta" :weight bold)
1820               ("CANCELLED" :foreground "forest green" :weight bold)
1821               ("MEETING" :foreground "forest green" :weight bold)
1822               ("PHONE" :foreground "forest green" :weight bold))))
1823
1824 (setq org-todo-state-tags-triggers
1825       (quote (("CANCELLED" ("CANCELLED" . t))
1826               ("WAITING" ("WAITING" . t))
1827               ("HOLD" ("WAITING") ("HOLD" . t))
1828               (done ("WAITING") ("HOLD"))
1829               ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
1830               ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
1831               ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
1832
1833
1834
1835 ; (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
1836 ; add ids on creation of nodes
1837 (add-hook 'org-capture-prepare-finalize-hook 'my/org-add-id)
1838
1839
1840 ; resolve clocks after 10 minutes of idle; use xprintidle
1841 ; (setq org-clock-idle-time 10)
1842 ; (setq org-clock-x11idle-program-name "xprintidle")
1843
1844 ; this is from http://doc.norang.ca/org-mode.html#Capture
1845 ; use C-M-r for org mode capture
1846 (global-set-key (kbd "C-M-r") 'org-capture)
1847
1848 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
1849 (setq org-refile-targets (quote ((nil :maxlevel . 9)
1850                                  (org-agenda-files :maxlevel . 9))))
1851
1852 ; Use full outline paths for refile targets - we file directly with IDO
1853 (setq org-refile-use-outline-path t)
1854
1855 ; Targets complete directly with IDO
1856 (setq org-outline-path-complete-in-steps nil)
1857
1858 ; Allow refile to create parent tasks with confirmation
1859 (setq org-refile-allow-creating-parent-nodes (quote confirm))
1860
1861 ; ; Use IDO for both buffer and file completion and ido-everywhere to t
1862 ; (setq org-completion-use-ido t)
1863 ; (setq ido-everywhere t)
1864 ; (setq ido-max-directory-size 100000)
1865 ; (ido-mode (quote both))
1866 ; ; Use the current window when visiting files and buffers with ido
1867 ; (setq ido-default-file-method 'selected-window)
1868 ; (setq ido-default-buffer-method 'selected-window)
1869 ; ; Use the current window for indirect buffer display
1870 ; (setq org-indirect-buffer-display 'current-window)
1871
1872
1873 ;;;; Refile settings
1874 ; Exclude DONE state tasks from refile targets
1875 (defun bh/verify-refile-target ()
1876   "Exclude todo keywords with a done state from refile targets"
1877   (not (member (nth 2 (org-heading-components)) org-done-keywords)))
1878
1879 (setq org-refile-target-verify-function 'bh/verify-refile-target)
1880
1881 ;; ensure that emacsclient will show just the note to be edited when invoked
1882 ;; from Mutt, and that it will shut down emacsclient once finished;
1883 ;; fallback to legacy behavior when not invoked via org-protocol.
1884 (require 'org-protocol)
1885 ; (add-hook 'org-capture-mode-hook 'delete-other-windows)
1886 (setq my-org-protocol-flag nil)
1887 (defadvice org-capture-finalize (after delete-frame-at-end activate)
1888   "Delete frame at remember finalization"
1889   (progn (if my-org-protocol-flag (delete-frame))
1890          (setq my-org-protocol-flag nil)))
1891 (defadvice org-capture-refile (around delete-frame-after-refile activate)
1892   "Delete frame at remember refile"
1893   (if my-org-protocol-flag
1894       (progn
1895         (setq my-org-protocol-flag nil)
1896         ad-do-it
1897         (delete-frame))
1898     ad-do-it)
1899   )
1900 (defadvice org-capture-kill (after delete-frame-at-end activate)
1901   "Delete frame at remember abort"
1902   (progn (if my-org-protocol-flag (delete-frame))
1903          (setq my-org-protocol-flag nil)))
1904 (defadvice org-protocol-capture (before set-org-protocol-flag activate)
1905   (setq my-org-protocol-flag t))
1906
1907 (defadvice org-insert-todo-heading (after dla/create-id activate)
1908   (unless (org-in-item-p)
1909     (org-id-get-create)
1910     )
1911   )
1912
1913 ;; org modules
1914 (add-to-list 'org-modules 'org-habit)
1915
1916 ; this comes from http://upsilon.cc/~zack/blog/posts/2010/02/integrating_Mutt_with_Org-mode/
1917 (defun open-mail-in-mutt (message)
1918   "Open a mail message in Mutt, using an external terminal.
1919
1920 Message can be specified either by a path pointing inside a
1921 Maildir, or by Message-ID."
1922   (interactive "MPath or Message-ID: ")
1923   (shell-command
1924    (format "faf xterm -e \"%s %s\""
1925        (substitute-in-file-name "$HOME/bin/mutt_open") message)))
1926
1927 ;; add support for "mutt:ID" links
1928 (org-add-link-type "mutt" 'open-mail-in-mutt)
1929
1930 (defun my-org-mode-setup ()
1931   ; (load-library "reftex")
1932   (and (buffer-file-name)
1933        (file-exists-p (buffer-file-name))
1934        (progn
1935          ; (reftex-parse-all)
1936          (reftex-set-cite-format
1937           '((?b . "[[bib:%l][%l-bib]]")
1938             (?n . "[[notes:%l][%l-notes]]")
1939             (?c . "\\cite{%l}")
1940             (?h . "*** %t\n:PROPERTIES:\n:Custom_ID: %l\n:END:\n[[papers:%l][%l xoj]] [[papers-pdf:%l][pdf]]")))
1941          ))
1942   (define-key org-mode-map (kbd "C-c )") 'reftex-citation)
1943   (define-key org-mode-map (kbd "C-c [") 'reftex-citation)
1944   (define-key org-mode-map (kbd "C-c (") 'org-mode-reftex-search)
1945   (define-key org-mode-map (kbd "C-c 0") 'reftex-view-crossref)
1946   )
1947 (add-hook 'org-mode-hook 'my-org-mode-setup)
1948
1949 (defun org-mode-reftex-search ()
1950   (interactive)
1951   (org-open-link-from-string (format "[[notes:%s]]" (first (reftex-citation t)))))
1952
1953 (defun open-research-paper (bibtexkey)
1954   "Open a paper by bibtex key"
1955   (interactive "bibtex key: ")
1956   (shell-command
1957    (format "%s %s"
1958        (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1959 (org-add-link-type "papers" 'open-research-paper)
1960 (defun open-research-paper-pdf (bibtexkey)
1961   "Open a paper pdf by bibtex key"
1962   (interactive "bibtex key: ")
1963   (shell-command
1964    (format "%s -p evince_annot %s"
1965        (substitute-in-file-name "$HOME/bin/bibtex_to_paper") bibtexkey)))
1966 (org-add-link-type "papers-pdf" 'open-research-paper-pdf)
1967
1968 (add-to-list 'org-link-abbrev-alist
1969              '("notes" .
1970                "~/projects/research/paper_notes.org::#%s"))
1971
1972 ; I pretty much always want hiearchical checkboxes
1973 (setq org-hierachical-checkbox-statistics nil)
1974
1975 ;; Add \begin{equation}\end{equation} templates to the org mode easy templates
1976 (add-to-list 'org-structure-template-alist
1977              '("E" "\\begin{equation}\n?\n\\end{equation}"))
1978
1979  ;; stolen from
1980 ;; http://www-public.it-sudparis.eu/~berger_o/weblog/2012/03/23/how-to-manage-and-export-bibliographic-notesrefs-in-org-mode/
1981 (defun my-rtcite-export-handler (path desc format)
1982   (message "my-rtcite-export-handler is called : path = %s, desc = %s, format = %s" path desc format)
1983   (let* ((search (when (string-match "::#?\\(.+\\)\\'" path)
1984                    (match-string 1 path)))
1985          (path (substring path 0 (match-beginning 0))))
1986     (cond ((eq format 'latex)
1987            (if (or (not desc) 
1988                    (equal 0 (search "rtcite:" desc)))
1989                (format "\\cite{%s}" search)
1990              (format "\\cite[%s]{%s}" desc search))))))
1991
1992 (org-add-link-type "rtcite" 
1993                    'org-bibtex-open
1994                    'my-rtcite-export-handler)
1995
1996
1997 #+END_SRC
1998 ** Org Mobile Configuration
1999 #+BEGIN_SRC emacs-lisp
2000   (setq-default org-mobile-directory "/linnode.donarmstrong.com:/sites/dav.donarmstrong.com/root/org/")
2001   (when (string= system-name "linnode")
2002     (setq-default org-mobile-directory "/sites/dav.donarmstrong.com/root/org/"))
2003   (setq-default org-directory "/home/don/org-mode/")
2004   (setq-default org-mobile-inbox-for-pull "/home/don/org-mode/from-mobile.org")
2005
2006 #+END_SRC
2007 ** Org iCal Support
2008 #+BEGIN_SRC emacs-lisp
2009   ;; org mode ical export
2010   (setq org-icalendar-timezone "America/Los_Angeles")
2011   (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
2012   ;; we already add the id manually
2013   (setq org-icalendar-store-UID t)
2014
2015 #+END_SRC
2016 ** General Org Babel Configuration
2017 #+BEGIN_SRC emacs-lisp
2018 ;; org babel support
2019 (org-babel-do-load-languages
2020  'org-babel-load-languages
2021  '((emacs-lisp . t )
2022    (R . t)
2023    (latex . t)
2024    (ditaa . t)
2025    (dot . t)
2026    ))
2027 ;; set the right path to ditaa.jar
2028 (setq org-ditaa-jar-path "/usr/share/ditaa/ditaa.jar")
2029 ;; use graphviz-dot for dot things
2030 (add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))
2031 ;; do not indent begin_src blocks
2032 (setq org-edit-src-content-indentation 0)
2033 ;; org-babel-by-backend
2034 (defmacro org-babel-by-backend (&rest body)
2035    `(case (if (boundp 'backend) 
2036               (org-export-backend-name backend)
2037             nil) ,@body))
2038
2039 (defun my/fix-inline-images ()
2040   (when org-inline-image-overlays
2041     (org-redisplay-inline-images)))
2042
2043 (add-hook 'org-babel-after-execute-hook
2044            'my/fix-inline-images)
2045
2046 #+END_SRC
2047 ** LaTeX configuration
2048    :PROPERTIES:
2049    :ID:       7135ba17-6a50-4eed-84ca-b90afa5b12f8
2050    :END:
2051 #+BEGIN_SRC emacs-lisp
2052 (use-package ox-extra
2053   :config
2054   (ox-extras-activate '(ignore-headlines)))
2055 (require 'ox-latex)
2056 (add-to-list 'org-latex-classes
2057          '("memarticle"
2058        "\\documentclass[11pt,oneside,article]{memoir}\n"
2059        ("\\section{%s}" . "\\section*{%s}")
2060        ("\\subsection{%s}" . "\\subsection*{%s}")
2061        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2062        ("\\paragraph{%s}" . "\\paragraph*{%s}")
2063        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2064
2065 (setq org-beamer-outline-frame-options "")
2066 (add-to-list 'org-latex-classes
2067          '("beamer"
2068        "\\documentclass[ignorenonframetext]{beamer}
2069 [NO-DEFAULT-PACKAGES]
2070 [PACKAGES]
2071 [EXTRA]"
2072        ("\\section{%s}" . "\\section*{%s}")
2073        ("\\subsection{%s}" . "\\subsection*{%s}")
2074        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2075        ("\\paragraph{%s}" . "\\paragraph*{%s}")
2076        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2077
2078 (add-to-list 'org-latex-classes
2079          '("membook"
2080        "\\documentclass[11pt,oneside]{memoir}\n"
2081        ("\\chapter{%s}" . "\\chapter*{%s}")
2082        ("\\section{%s}" . "\\section*{%s}")
2083        ("\\subsection{%s}" . "\\subsection*{%s}")
2084        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
2085
2086 (add-to-list 'org-latex-classes
2087          '("letter"
2088        "\\documentclass[11pt]{letter}
2089 [NO-DEFAULT-PACKAGES]
2090 [PACKAGES]
2091 [EXTRA]"
2092    ("\\section{%s}" . "\\section*{%s}")
2093        ("\\subsection{%s}" . "\\subsection*{%s}")
2094        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2095        ("\\paragraph{%s}" . "\\paragraph*{%s}")
2096        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2097
2098 (add-to-list 'org-latex-classes
2099          '("dlacv"
2100        "\\documentclass{dlacv}
2101 [NO-DEFAULT-PACKAGES]
2102 [NO-PACKAGES]
2103 [NO-EXTRA]"
2104        ("\\section{%s}" . "\\section*{%s}")
2105        ("\\subsection{%s}" . "\\subsection*{%s}")
2106        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2107        ("\\paragraph{%s}" . "\\paragraph*{%s}")
2108        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2109
2110
2111 (add-to-list 'org-latex-classes
2112          '("dlaresume"
2113        "\\documentclass{dlaresume}
2114 [NO-DEFAULT-PACKAGES]
2115 [NO-PACKAGES]
2116 [NO-EXTRA]"
2117        ("\\section{%s}" . "\\section*{%s}")
2118        ("\\subsection{%s}" . "\\subsection*{%s}")
2119        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
2120        ("\\paragraph{%s}" . "\\paragraph*{%s}")
2121        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
2122
2123
2124 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
2125 ;; but adapted to use latexmk 4.22 or higher.  
2126 (setq org-latex-pdf-process '("latexmk -f -pdflatex=xelatex -bibtex -use-make -pdf %f"))
2127
2128 ;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
2129 (setq org-latex-default-packages-alist
2130   '(("" "amsmath" t)
2131     ("" "unicode-math" t)
2132     ))
2133 (setq org-latex-packages-alist
2134   '(("" "graphicx" t)
2135     ("" "fontspec" t)
2136     ("" "xunicode" t)
2137     ("" "hyperref" t)
2138     ("" "url" t)
2139     ("" "rotating" t)
2140     ("" "longtable" nil)
2141     ("" "float" )))
2142
2143 ;; make equations larger
2144 (setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
2145
2146 (defun org-create-formula--latex-header ()
2147   "Return LaTeX header appropriate for previewing a LaTeX snippet."
2148   (let ((info (org-combine-plists (org-export--get-global-options
2149            (org-export-get-backend 'latex))
2150           (org-export--get-inbuffer-options
2151            (org-export-get-backend 'latex)))))
2152     (org-latex-guess-babel-language
2153      (org-latex-guess-inputenc
2154   (org-splice-latex-header
2155    org-format-latex-header
2156    org-latex-default-packages-alist
2157    nil t
2158    (plist-get info :latex-header)))
2159      info)))
2160
2161
2162 ; support ignoring headers in org mode export to latex
2163 ; from http://article.gmane.org/gmane.emacs.orgmode/67692
2164 (defadvice org-latex-headline (around my-latex-skip-headlines
2165                   (headline contents info) activate)
2166   (if (member "ignoreheading" (org-element-property :tags headline))
2167   (setq ad-return-value contents)
2168     ad-do-it))
2169
2170 ;; keep latex logfiles
2171
2172 (setq org-latex-remove-logfiles nil)
2173
2174 ;; Resume clocking task when emacs is restarted
2175 (org-clock-persistence-insinuate)
2176 ;;
2177 ;; Show lot of clocking history so it's easy to pick items off the C-F11 list
2178 (setq org-clock-history-length 23)
2179 ;; Resume clocking task on clock-in if the clock is open
2180 (setq org-clock-in-resume t)
2181 ;; Change tasks to NEXT when clocking in; this avoids clocking in when
2182 ;; there are things like PHONE calls
2183 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2184 ;; Separate drawers for clocking and logs
2185 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2186 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2187 (setq org-clock-into-drawer t)
2188 (setq org-log-into-drawer t)
2189 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2190 (setq org-clock-out-remove-zero-time-clocks t)
2191 ;; Clock out when moving task to a done state
2192 (setq org-clock-out-when-done t)
2193 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2194 (setq org-clock-persist t)
2195 ;; Do not prompt to resume an active clock
2196 (setq org-clock-persist-query-resume nil)
2197 ;; Enable auto clock resolution for finding open clocks
2198 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2199 ;; Include current clocking task in clock reports
2200 (setq org-clock-report-include-clocking-task t)
2201
2202 ;; the cache seems to be broken
2203 (setq org-element-use-cache nil)
2204
2205 (defvar bh/keep-clock-running nil)
2206
2207 (defun bh/is-task-p ()
2208   "Any task with a todo keyword and no subtask"
2209   (save-restriction
2210     (widen)
2211     (let ((has-subtask)
2212           (subtree-end (save-excursion (org-end-of-subtree t)))
2213           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2214       (save-excursion
2215         (forward-line 1)
2216         (while (and (not has-subtask)
2217                     (< (point) subtree-end)
2218                     (re-search-forward "^\*+ " subtree-end t))
2219           (when (member (org-get-todo-state) org-todo-keywords-1)
2220             (setq has-subtask t))))
2221       (and is-a-task (not has-subtask)))))
2222 (defun bh/is-project-p ()
2223   "Any task with a todo keyword subtask"
2224   (save-restriction
2225     (widen)
2226     (let ((has-subtask)
2227           (subtree-end (save-excursion (org-end-of-subtree t)))
2228           (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2229       (save-excursion
2230         (forward-line 1)
2231         (while (and (not has-subtask)
2232                     (< (point) subtree-end)
2233                     (re-search-forward "^\*+ " subtree-end t))
2234           (when (member (org-get-todo-state) org-todo-keywords-1)
2235             (setq has-subtask t))))
2236       (and is-a-task has-subtask))))
2237
2238 (defun bh/is-subproject-p ()
2239   "Any task which is a subtask of another project"
2240   (let ((is-subproject)
2241         (is-a-task (member (nth 2 (org-heading-components)) org-todo-keywords-1)))
2242     (save-excursion
2243       (while (and (not is-subproject) (org-up-heading-safe))
2244         (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2245           (setq is-subproject t))))
2246     (and is-a-task is-subproject)))
2247
2248
2249 (defun bh/clock-in-to-next (kw)
2250   "Switch a task from TODO to NEXT when clocking in.
2251 Skips capture tasks, projects, and subprojects.
2252 Switch projects and subprojects from NEXT back to TODO"
2253   (when (not (and (boundp 'org-capture-mode) org-capture-mode))
2254     (cond
2255      ((and (member (org-get-todo-state) (list "TODO"))
2256        (bh/is-task-p))
2257   "NEXT")
2258      ((and (member (org-get-todo-state) (list "NEXT"))
2259        (bh/is-project-p))
2260   "TODO"))))
2261
2262 (defun bh/punch-in (arg)
2263   "Start continuous clocking and set the default task to the
2264 selected task.  If no task is selected set the Organization task
2265 as the default task."
2266   (interactive "p")
2267   (setq bh/keep-clock-running t)
2268   (if (equal major-mode 'org-agenda-mode)
2269   ;;
2270   ;; We're in the agenda
2271   ;;
2272   (let* ((marker (org-get-at-bol 'org-hd-marker))
2273          (tags (org-with-point-at marker (org-get-tags-at))))
2274     (if (and (eq arg 4) tags)
2275         (org-agenda-clock-in '(16))
2276       (bh/clock-in-organization-task-as-default)))
2277     ;;
2278     ;; We are not in the agenda
2279     ;;
2280     (save-restriction
2281   (widen)
2282   ; Find the tags on the current task
2283   (if (and (equal major-mode 'org-mode) (not (org-before-first-heading-p)) (eq arg 4))
2284       (org-clock-in '(16))
2285     (bh/clock-in-organization-task-as-default)))))
2286
2287 (defun bh/punch-out ()
2288   (interactive)
2289   (setq bh/keep-clock-running nil)
2290   (when (org-clock-is-active)
2291     (org-clock-out))
2292   (org-agenda-remove-restriction-lock))
2293
2294 (defun bh/clock-in-default-task ()
2295   (save-excursion
2296     (org-with-point-at org-clock-default-task
2297   (org-clock-in))))
2298
2299 (defun bh/clock-in-parent-task ()
2300   "Move point to the parent (project) task if any and clock in"
2301   (let ((parent-task))
2302     (save-excursion
2303   (save-restriction
2304     (widen)
2305     (while (and (not parent-task) (org-up-heading-safe))
2306       (when (member (nth 2 (org-heading-components)) org-todo-keywords-1)
2307         (setq parent-task (point))))
2308     (if parent-task
2309         (org-with-point-at parent-task
2310       (org-clock-in))
2311       (when bh/keep-clock-running
2312         (bh/clock-in-default-task)))))))
2313
2314 (defvar bh/organization-task-id "e22cb8bf-07c7-408b-8f60-ff3aadac95e4")
2315
2316 (defun bh/clock-in-organization-task-as-default ()
2317   (interactive)
2318   (org-with-point-at (org-id-find bh/organization-task-id 'marker)
2319     (org-clock-in '(16))))
2320
2321 (defun bh/clock-out-maybe ()
2322   (when (and bh/keep-clock-running
2323          (not org-clock-clocking-in)
2324          (marker-buffer org-clock-default-task)
2325          (not org-clock-resolving-clocks-due-to-idleness))
2326     (bh/clock-in-parent-task)))
2327
2328 ; (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2329
2330 (require 'org-id)
2331 (defun bh/clock-in-task-by-id (id)
2332   "Clock in a task by id"
2333   (org-with-point-at (org-id-find id 'marker)
2334     (org-clock-in nil)))
2335
2336 (defun bh/clock-in-last-task (arg)
2337   "Clock in the interrupted task if there is one
2338 Skip the default task and get the next one.
2339 A prefix arg forces clock in of the default task."
2340   (interactive "p")
2341   (let ((clock-in-to-task
2342      (cond
2343       ((eq arg 4) org-clock-default-task)
2344       ((and (org-clock-is-active)
2345         (equal org-clock-default-task (cadr org-clock-history)))
2346        (caddr org-clock-history))
2347       ((org-clock-is-active) (cadr org-clock-history))
2348       ((equal org-clock-default-task (car org-clock-history)) (cadr org-clock-history))
2349       (t (car org-clock-history)))))
2350     (widen)
2351     (org-with-point-at clock-in-to-task
2352   (org-clock-in nil))))
2353
2354
2355 (defun org-export-to-ods ()
2356   (interactive)
2357   (let ((csv-file "data.csv"))
2358     (org-table-export csv-file "orgtbl-to-csv")
2359     (org-odt-convert csv-file "ods" 'open)))
2360
2361 ; allow for zero-width-space to be a break in regexp too
2362 ; (setcar org-emphasis-regexp-components "​ [:space:] \t('\"{")
2363 ; (setcar (nthcdr 1 org-emphasis-regexp-components) "​ [:space:]- \t.,:!?;'\")}\\")
2364 ; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
2365
2366 ;; support inserting screen shots
2367 (defun my/org-insert-screenshot ()
2368   "Take a screenshot into a time stamped unique-named file in the
2369 same directory as the org-buffer and insert a link to this file."
2370   (interactive)
2371   (defvar my/org-insert-screenshot/filename)
2372   (setq my/org-insert-screenshot/filename
2373     (read-file-name
2374      "Screenshot to insert: "
2375      nil
2376      (concat (buffer-file-name) "_" (format-time-string "%Y%m%d_%H%M%S") ".png")
2377      )
2378     )
2379   (call-process "import" nil nil nil my/org-insert-screenshot/filename)
2380   (insert (concat "[[" my/org-insert-screenshot/filename "]]"))
2381   (org-display-inline-images))
2382
2383 (defun my/fix-inline-images ()
2384   (when org-inline-image-overlays
2385     (org-redisplay-inline-images)))
2386
2387 (add-hook 'org-babel-after-execute-hook 'my/fix-inline-images)
2388
2389 ;; use xelatex to preview with imagemagick
2390 (add-to-list 'org-preview-latex-process-alist
2391          '(xelateximagemagick
2392       :programs ("xelatex" "convert")
2393       :description "pdf > png"
2394       :message "you need to install xelatex and imagemagick"
2395       :use-xcolor t
2396       :image-input-type "pdf"
2397       :image-output-type "png"
2398       :image-size-adjust (1.0 . 1.0)
2399       :latex-compiler ("xelatex -interaction nonstopmode -output-directory %o %f")
2400       :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
2401          )
2402 ;; use xelatex by default
2403 (setq org-preview-latex-default-process 'xelateximagemagick)
2404
2405 ; from http://orgmode.org/Changes.html
2406 (defun my/org-repair-property-drawers ()
2407   "Fix properties drawers in current buffer.
2408  Ignore non Org buffers."
2409   (interactive)
2410   (when (eq major-mode 'org-mode)
2411     (org-with-wide-buffer
2412      (goto-char (point-min))
2413      (let ((case-fold-search t)
2414        (inline-re (and (featurep 'org-inlinetask)
2415                (concat (org-inlinetask-outline-regexp)
2416                    "END[ \t]*$"))))
2417    (org-map-entries
2418     (lambda ()
2419       (unless (and inline-re (org-looking-at-p inline-re))
2420         (save-excursion
2421       (let ((end (save-excursion (outline-next-heading) (point))))
2422         (forward-line)
2423         (when (org-looking-at-p org-planning-line-re) (forward-line))
2424         (when (and (< (point) end)
2425                (not (org-looking-at-p org-property-drawer-re))
2426                (save-excursion
2427                  (and (re-search-forward org-property-drawer-re end t)
2428                   (eq (org-element-type
2429                    (save-match-data (org-element-at-point)))
2430                   'drawer))))
2431           (insert (delete-and-extract-region
2432                (match-beginning 0)
2433                (min (1+ (match-end 0)) end)))
2434           (unless (bolp) (insert "\n"))))))))))))
2435
2436 #+END_SRC
2437 ** Org-Gcal
2438 #+BEGIN_SRC emacs-lisp
2439 (use-package calfw
2440   :ensure f
2441   )
2442 (use-package calfw-org
2443   :ensure f
2444   )
2445 (use-package org-gcal
2446   :if (file-readable-p "~/.hide/org_gcal.el")
2447   :ensure f
2448   :config '((if (file-readable-p "~/.hide/org_gcal.el")
2449                 (load-file "~/.hide/org_gcal.el"))
2450             )
2451   )
2452 #+END_SRC
2453 ** appt integration
2454 #+BEGIN_SRC emacs-lisp
2455   (use-package appt
2456     :ensure f
2457     :config
2458     ;; Show notification 10 minutes before event
2459     (setq appt-message-warning-time 10)
2460     ;; Disable multiple reminders
2461     (setq appt-display-interval appt-message-warning-time)
2462     (setq appt-display-mode-line nil)
2463
2464     ;; add automatic reminders for appointments
2465     (defun my/org-agenda-to-appt ()
2466       (interactive)
2467       (setq appt-time-msg-list nil)
2468       (org-agenda-to-appt))
2469     ;; add reminders when starting emacs
2470     (my/org-agenda-to-appt)
2471     ;; when rebuilding the agenda
2472     (defadvice  org-agenda-redo (after org-agenda-redo-add-appts)
2473       "Pressing `r' on the agenda will also add appointments."
2474       (my/org-agenda-to-appt)
2475       )
2476     ;; when saving all org buffers
2477     (defadvice org-save-all-org-buffers (after org-save-all-org-buffers-add-appts)
2478       "Re-add appts after saving all org buffers"
2479       (my/org-agenda-to-appt))
2480     ;; Display appointments as a window manager notification
2481     (setq appt-disp-window-function 'my/appt-display)
2482     (setq appt-delete-window-function (lambda () t))
2483
2484     (setq my/appt-notification-app (concat (getenv "HOME") "/bin/appt_notification"))
2485
2486     (defun my/appt-display (min-to-app new-time msg)
2487       (if (atom min-to-app)
2488       (start-process "my/appt-notification-app" nil my/appt-notification-app min-to-app msg)
2489     (dolist (i (number-sequence 0 (1- (length min-to-app))))
2490       (start-process "my/appt-notification-app" nil my/appt-notification-app
2491                      (nth i min-to-app) (nth i msg))))
2492       )
2493     )
2494
2495
2496 #+END_SRC
2497 ** outshine (outlining) integration
2498 #+BEGIN_SRC emacs-lisp
2499 (use-package outshine
2500   :ensure t
2501   :hook (outline-minor-mode . outshine-hook-function)
2502 )
2503 #+END_SRC
2504 ** End use-package
2505 #+BEGIN_SRC emacs-lisp
2506   )
2507 #+END_SRC
2508 * Keybindings
2509 ** Home/End Begining/End of line
2510 #+BEGIN_SRC emacs-lisp
2511   (global-set-key [home] 'move-beginning-of-line)
2512   (global-set-key [end] 'move-end-of-line)
2513 #+END_SRC
2514 ** Goto line
2515 #+BEGIN_SRC emacs-lisp
2516   (global-unset-key "\M-g")
2517   (global-set-key (kbd "M-g l") 'goto-line)
2518 #+END_SRC
2519 * Debian
2520 ** debian-changelog
2521 #+BEGIN_SRC emacs-lisp
2522   (use-package debian-changelog-mode
2523     :mode "debian/changelog"
2524     :config
2525     (setq debian-changelog-mailing-address "don@debian.org")
2526     (setq debian-changelog-full-name "Don Armstrong"))
2527 #+END_SRC
2528 * Misc (uncharacterized)
2529 #+BEGIN_SRC emacs-lisp
2530   (setq calendar-latitude 38.6)
2531   (setq calendar-longitude -121.5)
2532   (setq case-fold-search t)
2533   (setq confirm-kill-emacs (quote y-or-n-p))
2534   (setq cperl-lazy-help-time nil)
2535 #+END_SRC
2536 ** Turn on fontlock and icomplete
2537 #+BEGIN_SRC emacs-lisp
2538   (global-font-lock-mode 1)
2539   (icomplete-mode 1)
2540   (setq log-edit-keep-buffer t)
2541 #+END_SRC
2542 ** Set mail User agent
2543 #+BEGIN_SRC emacs-lisp
2544   (setq mail-user-agent (quote sendmail-user-agent))
2545   (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
2546 #+END_SRC
2547 ** PS Printing
2548 #+BEGIN_SRC emacs-lisp
2549   (setq ps-footer-font-size (quote (8 . 10)))
2550   (setq ps-header-font-size (quote (8 . 10)))
2551   (setq ps-header-title-font-size (quote (10 . 10)))
2552   (setq ps-line-number-color "blue")
2553   (setq ps-print-footer t)
2554   (setq ps-print-footer-frame nil)
2555   (setq ps-print-only-one-header t)
2556 #+END_SRC
2557 ** Only single spacing on sentences
2558 #+BEGIN_SRC emacs-lisp
2559   (setq sentence-end "[.?!][]\"')]*\\($\\|   \\| \\)[    
2560   ]*")
2561   (setq sentence-end-double-space nil)
2562   ; enable matching parenthesis
2563 #+END_SRC
2564 ** Display paren mode
2565 #+BEGIN_SRC emacs-lisp
2566   (show-paren-mode 1)
2567   (setq show-paren-delay 0.2)
2568
2569 #+END_SRC
2570 ** My Username
2571 #+BEGIN_SRC emacs-lisp
2572   (setq user-mail-address "don@donarmstrong.com")
2573
2574 #+END_SRC
2575 ** Use primary selection on unix machines
2576 #+BEGIN_SRC emacs-lisp
2577   ;; switch back to the old primary selection method
2578   (if (or (string-equal system-type "darwin")
2579           (string-equal system-type "windows")
2580           )
2581       (progn
2582         (setq x-select-enable-clipboard t)
2583         (setq x-select-enable-primary nil)
2584         )
2585     (progn
2586       (setq x-select-enable-clipboard nil)
2587       (setq x-select-enable-primary t)
2588       ))
2589   ; (setq mouse-drag-copy-region t)
2590
2591   (fset 'perl-mode 'cperl-mode)
2592   ;;(load-file "cperl-mode.el")
2593
2594   ;; tramp configuration
2595   (setq tramp-use-ssh-controlmaster-options nil)
2596
2597   (setq-default c-indent-level 4)
2598   (setq-default c-brace-imaginary-offset 0)
2599   (setq-default c-brace-offset -4)
2600   (setq-default c-argdecl-indent 4)
2601   (setq-default c-label-offset -4)
2602   (setq-default c-continued-statement-offset 4)
2603   ; tabs are annoying
2604   (setq-default indent-tabs-mode nil)
2605   (setq-default tab-width 4)
2606
2607
2608   ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
2609   ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
2610   ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
2611   ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
2612   ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
2613
2614
2615   (defun insert-date ()
2616     "Insert date at point."
2617     (interactive)
2618     (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
2619   (global-set-key "\C-[d" 'insert-date)
2620
2621   (defun unfill-paragraph (arg)
2622     "Pull this whole paragraph up onto one line."
2623     (interactive "*p")
2624     (let ((fill-column 10000))
2625       (fill-paragraph arg))
2626     )
2627
2628   (column-number-mode t)
2629  
2630 #+END_SRC
2631 ** Desktop-save-mode
2632 If the envvar EMACS_SERVER_NAME is set, consider this a separate
2633 emacs, and use a different desktop file to restore history
2634 #+BEGIN_SRC emacs-lisp
2635   (use-package desktop
2636     :demand
2637     :config
2638     (setq desktop-base-file-name
2639           (convert-standard-filename
2640            (concat ".emacs"
2641                    (or (getenv "EMACS_SERVER_NAME")
2642                        "")
2643                    ".desktop")
2644            ))
2645     (setq desktop-base-lock-name
2646           (convert-standard-filename
2647            (concat desktop-base-file-name
2648                    ".lock")))
2649     (setq desktop-auto-save-timeout 60)
2650     (setq desktop-restore-eager 5)
2651     (setq desktop-lazy-verbose nil)
2652     (desktop-save-mode 1)
2653     ; (desktop-read)
2654   )
2655 #+END_SRC
2656 ** Misc (Uncharacterized)
2657 #+BEGIN_SRC emacs-lisp
2658   '(icomplete-mode on)
2659   (custom-set-faces
2660    ;; custom-set-faces was added by Custom.
2661    ;; If you edit it by hand, you could mess it up, so be careful.
2662    ;; Your init file should contain only one such instance.
2663    ;; If there is more than one, they won't work right.
2664    '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
2665
2666
2667   (put 'upcase-region 'disabled nil)
2668   (put 'downcase-region 'disabled nil)
2669   (put 'narrow-to-region 'disabled nil)
2670
2671   ; (defun turn-on-flyspell ()
2672   ;    "Force flyspell-mode on using a positive arg.  For use in hooks."
2673   ;    (interactive)
2674   ;    (flyspell-mode 1))
2675
2676
2677    ; Outline-minor-mode key map
2678    (define-prefix-command 'cm-map nil "Outline-")
2679    ; HIDE
2680    (define-key cm-map "q" 'outline-hide-sublevels)    ; Hide everything but the top-level headings
2681    (define-key cm-map "t" 'outline-hide-body)         ; Hide everything but headings (all body lines)
2682    (define-key cm-map "o" 'outline-hide-other)        ; Hide other branches
2683    (define-key cm-map "c" 'outline-hide-entry)        ; Hide this entry's body
2684    (define-key cm-map "l" 'outline-hide-leaves)       ; Hide body lines in this entry and sub-entries
2685    (define-key cm-map "d" 'outline-hide-subtree)      ; Hide everything in this entry and sub-entries
2686    ; SHOW
2687    (define-key cm-map "a" 'outline-show-all)          ; Show (expand) everything
2688    (define-key cm-map "e" 'outline-show-entry)        ; Show this heading's body
2689    (define-key cm-map "i" 'outline-show-children)     ; Show this heading's immediate child sub-headings
2690    (define-key cm-map "k" 'outline-show-branches)     ; Show all sub-headings under this heading
2691    (define-key cm-map "s" 'outline-show-subtree)      ; Show (expand) everything in this heading & below
2692    ; MOVE
2693    (define-key cm-map "u" 'outline-up-heading)                ; Up
2694    (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
2695    (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
2696    (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
2697    (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
2698    (global-set-key "\M-o" cm-map)
2699   ; fix up tmux xterm keys
2700   ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
2701   (defun fix-up-tmux-keys ()
2702       "Fix up tmux xterm keys"
2703       (if (getenv "TMUX")
2704           (progn
2705             (let ((x 2) (tkey ""))
2706               (while (<= x 8)
2707                 ;; shift
2708                 (if (= x 2)
2709                     (setq tkey "S-"))
2710                 ;; alt
2711                 (if (= x 3)
2712                     (setq tkey "M-"))
2713                 ;; alt + shift
2714                 (if (= x 4)
2715                     (setq tkey "M-S-"))
2716                 ;; ctrl
2717                 (if (= x 5)
2718                     (setq tkey "C-"))
2719                 ;; ctrl + shift
2720                 (if (= x 6)
2721                     (setq tkey "C-S-"))
2722                 ;; ctrl + alt
2723                 (if (= x 7)
2724                     (setq tkey "C-M-"))
2725                 ;; ctrl + alt + shift
2726                 (if (= x 8)
2727                     (setq tkey "C-M-S-"))
2728
2729                 ;; arrows
2730                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
2731                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
2732                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
2733                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
2734                 ;; home
2735                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
2736                 ;; end
2737                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
2738                 ;; page up
2739                 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
2740                 ;; page down
2741                 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
2742                 ;; insert
2743                 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2744                 ;; delete
2745                 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
2746                 ;; f1
2747                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
2748                 ;; f2
2749                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
2750                 ;; f3
2751                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
2752                 ;; f4
2753                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
2754                 ;; f5
2755                 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
2756                 ;; f6
2757                 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
2758                 ;; f7
2759                 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
2760                 ;; f8
2761                 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
2762                 ;; f9
2763                 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
2764                 ;; f10
2765                 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
2766                 ;; f11
2767                 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
2768                 ;; f12
2769                 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
2770                 ;; f13
2771                 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
2772                 ;; f14
2773                 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
2774                 ;; f15
2775                 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
2776                 ;; f16
2777                 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
2778                 ;; f17
2779                 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
2780                 ;; f18
2781                 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
2782                 ;; f19
2783                 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
2784                 ;; f20
2785                 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
2786
2787                 (setq x (+ x 1))
2788                 ))
2789             )
2790         )
2791       )
2792   ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
2793
2794   (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
2795     "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
2796     (if (or (buffer-modified-p)
2797             (verify-visited-file-modtime)
2798             (< (* 8 1024 1024) (buffer-size))
2799             (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
2800         ad-do-it
2801       (clear-visited-file-modtime)
2802       (not-modified)))
2803   (ad-activate 'ask-user-about-supersession-threat)
2804 #+END_SRC
2805
2806 * Start Server
2807 #+BEGIN_SRC emacs-lisp
2808   (use-package server
2809     :config
2810     (setq server-name
2811           (or (getenv "EMACS_SERVER_NAME")
2812               "server"))
2813     (unless (server-running-p)
2814       (global-set-key "\C-xp" 'server-edit)
2815       (server-start)))
2816 #+END_SRC
2817
2818
2819
2820 * END
2821 #+BEGIN_SRC emacs-lisp
2822   (provide 'don-configuration)
2823 #+END_SRC