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