]> git.donarmstrong.com Git - lib.git/blob - emacs_el/configuration/don-configuration.org
905861895d8d7322695d3db278d602bc40b4c368
[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 * Add library paths
11
12 #+BEGIN_SRC emacs-lisp
13   (add-to-list 'load-path '"~/lib/emacs_el/")
14   (add-to-list 'load-path '"~/lib/emacs_el/helm")
15   (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/tiny")
16   (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/other")
17   (add-to-list 'load-path '"~/lib/emacs_el/auctex/lisp")
18   (add-to-list 'load-path '"~/lib/emacs_el/auctex")
19   (add-to-list 'load-path '"~/lib/emacs_el/ESS/lisp")
20   (add-to-list 'load-path '"~/lib/emacs_el/org-mode/lisp")
21   (add-to-list 'load-path '"~/lib/emacs_el/auctex-beamer")
22   (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
23   (add-to-list 'load-path '"~/lib/emacs_el/polymode")
24 #+END_SRC
25
26 * Package management
27 ** package repositories and package manager
28 #+BEGIN_SRC emacs-lisp
29   (require 'package)
30   (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
31                            ("melpa" . "https://melpa.org/packages/")
32                            ("org" . "http://orgmode.org/elpa/") ))
33 #+END_SRC
34 ** [[https://github.com/jwiegley/use-package/][use-package]]
35 #+BEGIN_SRC emacs-lisp
36   (require 'use-package)
37   (package-initialize)
38 #+END_SRC
39 ** Paradox
40 #+BEGIN_SRC emacs-lisp
41   (package-initialize)
42   (use-package paradox
43     :ensure paradox
44   )
45 #+END_SRC
46 * Misc functions
47 ** with-library
48 #+BEGIN_SRC emacs-lisp
49 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
50 ;; execute conditional code when loading libraries
51 (defmacro with-library (symbol &rest body)
52   `(when (require ,symbol nil t)
53      ,@body))
54 (put 'with-library 'lisp-indent-function 1)
55 #+END_SRC
56
57
58 * Memory
59 #+BEGIN_SRC emacs-lisp
60   (setq global-mark-ring-max 128
61         mark-ring-max 128
62         kill-ring-max 128)
63
64   (defun don/minibuffer-setup-hook ()
65     (setq gc-cons-threshold most-positive-fixnum))
66
67   (defun don/minibuffer-exit-hook ()
68     (setq gc-cons-threshold 1048576))
69
70   (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
71   (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
72 #+END_SRC
73 * Modules
74 ** Winnermode
75 #+BEGIN_SRC emacs-lisp
76   (winner-mode 1)
77 #+END_SRC
78 ** Eyebrowse
79
80 #+BEGIN_SRC emacs-lisp
81   ;; (use-package eyebrowse
82   ;;   :ensure t
83   ;;   :diminish eyebrowse-mode
84   ;;   :init (setq eyebrowse-keymap-prefix (kbd "C-c C-\\"))
85   ;;   :config (progn
86   ;;             (setq eyebrowse-wrap-around t)
87   ;;             (eyebrowse-mode t)
88   ;; 
89   ;;             (defun my/eyebrowse-new-window-config ()
90   ;;               (interactive)
91   ;;               (let ((done nil))
92   ;;                 (dotimes (i 10)
93   ;;                   ;; start at 1 run till 0
94   ;;                   (let ((j (mod (+ i 1) 10)))
95   ;;                     (when (and (not done)
96   ;;                                (not (eyebrowse--window-config-present-p j)))
97   ;;                       (eyebrowse-switch-to-window-config j)
98   ;;                       (call-interactively 'eyebrowse-rename-window-config2 j)
99   ;;                       (setq done t)
100   ;;                       ))
101   ;;                   )))
102   ;; 
103   ;;             ;; I don't use latex-preview-pane
104   ;;             ;; (require 'latex-preview-pane)
105   ;;             ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
106   ;;             ;;   ;; latex-preview-pane uses window-parameters which are
107   ;;             ;;   ;; not preserved by eyebrowse, so we close the preview
108   ;;             ;;   ;; pane before switching, it will be regenerated when we
109   ;;             ;;   ;; edit the TeX file.
110   ;;             ;;   (when (lpp/window-containing-preview)
111   ;;             ;;     (delete-window (lpp/window-containing-preview))))
112   ;; 
113   ;;             ;; (add-to-list 'eyebrowse-pre-window-switch-hook
114   ;;             ;;              #'my/close-latex-preview-pane-before-eyebrowse-switch)
115   ;; 
116   ;;             ;; (my/set-menu-key "["  #'my/eyebrowse-new-window-config)
117   ;;             ;; (my/set-menu-key ";"  #'eyebrowse-prev-window-config)
118   ;;             ;; (my/set-menu-key "'"  #'eyebrowse-next-window-config)
119   ;;             ;; (my/set-menu-key "]"  #'eyebrowse-close-window-config)
120   ;;             ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
121   ;;             )
122   ;;   )
123 #+END_SRC
124
125 ** Window handling
126
127 *** Splitting
128 #+BEGIN_SRC emacs-lisp
129   (defun my/vsplit-last-buffer ()
130     "Split the window vertically and display the previous buffer."
131     (interactive)
132     (split-window-vertically)
133     (other-window 1 nil)
134     (switch-to-next-buffer))
135
136   (defun my/hsplit-last-buffer ()
137     "Split the window horizontally and display the previous buffer."
138     (interactive)
139     (split-window-horizontally)
140     (other-window 1 nil)
141     (switch-to-next-buffer))
142
143   (bind-key "C-x 2" 'my/vsplit-last-buffer)
144   (bind-key "C-x 3" 'my/hsplit-last-buffer)
145
146   (setq split-width-threshold  100)
147   (setq split-height-threshold 60)
148
149   (defun my/split-window-prefer-horizontally (window)
150     "If there's only one window (excluding any possibly active
151            minibuffer), then split the current window horizontally."
152     (if (and (one-window-p t)
153              (not (active-minibuffer-window))
154              ( > (frame-width) (frame-height))
155              )
156         (let ((split-height-threshold nil))
157           (split-window-sensibly window))
158       (split-window-sensibly window)))
159
160   (setq split-window-preferred-function #'my/split-window-prefer-horizontally)
161   (setq window-combination-resize t)
162 #+END_SRC
163
164 *** Compilation window
165
166 If there is no compilation window, open one at the bottom, spanning
167 the complete width of the frame. Otherwise, reuse existing window. In
168 the former case, if there was no error the window closes
169 automatically.
170
171 #+BEGIN_SRC emacs-lisp
172   (add-to-list 'display-buffer-alist
173                `(,(rx bos "*compilation*" eos)
174                  (display-buffer-reuse-window
175                   display-buffer-in-side-window)
176                  (reusable-frames . visible)
177                  (side            . bottom)
178                  (window-height   . 0.4)))
179 #+END_SRC
180
181 #+BEGIN_SRC emacs-lisp
182   (defun my/compilation-exit-autoclose (status code msg)
183     ;; If M-x compile exists with a 0
184     (when (and (eq status 'exit) (zerop code))
185       ;; and delete the *compilation* window
186       (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
187         (when (and (not (window-at-side-p compilation-window 'top))
188                    (window-at-side-p compilation-window 'left)
189                    (window-at-side-p compilation-window 'right))
190           (delete-window compilation-window))))
191     ;; Always return the anticipated result of compilation-exit-message-function
192     (cons msg code))
193
194   ;; Specify my function (maybe I should have done a lambda function)
195   (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
196 #+END_SRC
197
198 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
199 value, the compilation buffer scrolls automatically to follow the
200 output. If the value is ~first-error~, scrolling stops when the first
201 error appears, leaving point at that error. For any other non-nil
202 value, scrolling continues until there is no more output.
203
204 #+BEGIN_SRC emacs-lisp
205   (setq compilation-scroll-output 'first-error)
206 #+END_SRC
207
208 ** Mode line cleaning
209 *** Diminish
210 #+BEGIN_SRC emacs-lisp
211   (use-package diminish
212     :ensure t)
213 #+END_SRC
214
215 *** Delight 
216 #+BEGIN_SRC emacs-lisp
217   (use-package delight
218     :ensure t)
219 #+END_SRC
220
221 ** Jumping
222 *** Avy
223 #+BEGIN_SRC emacs-lisp
224 (use-package avy
225   :ensure t
226   :bind ("C-c C-SPC" . avy-goto-word-1)
227   :config (progn
228             (setq avy-background t)
229             (key-chord-define-global "jj"  #'avy-goto-word-1)))
230 #+END_SRC
231
232 ** Snippets
233
234 *** Yasnippet
235 #+BEGIN_SRC emacs-lisp
236 (use-package yasnippet
237   :ensure t
238   :diminish yas-minor-mode
239   :config (progn
240             (yas-global-mode)
241             (setq yas-verbosity 1)))
242 #+END_SRC
243
244 ** Helm Flx
245
246 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
247
248 #+BEGIN_SRC emacs-lisp
249 (use-package helm-flx
250   :ensure t
251   :config (progn
252             ;; these are helm configs, but they kind of fit here nicely
253             (setq helm-M-x-fuzzy-match                  t
254                   helm-bookmark-show-location           t
255                   helm-buffers-fuzzy-matching           t
256                   helm-completion-in-region-fuzzy-match t
257                   helm-file-cache-fuzzy-match           t
258                   helm-imenu-fuzzy-match                t
259                   helm-mode-fuzzy-match                 t
260                   helm-locate-fuzzy-match               nil
261                   helm-quick-update                     t
262                   helm-recentf-fuzzy-match              nil
263                   helm-semantic-fuzzy-match             t)
264             (helm-flx-mode +1)))
265 #+END_SRC
266
267
268 ** Tinyprocmail
269
270 #+BEGIN_SRC emacs-lisp
271   ;; load tinyprocmail
272   (use-package tinyprocmail
273     :ensure f
274     :config (with-library 'tinyprocmail
275               ;; (setq tinyprocmail--procmail-version "v3.22")
276               (add-hook 'tinyprocmail--load-hook 'tinyprocmail-install))
277   
278 #+END_SRC
279
280 ** Magit
281 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
282   (use-package magit
283     :ensure f
284     :config
285     ;; don't verify where we are pushing
286     (setq magit-push-always-verify nil)
287     ;; refine diffs always (hilight words)
288     (setq magit-diff-refine-hunk nil)
289     ;; load magit-annex
290     (setq load-path
291           (append '("~/lib/emacs_el/magit-annex")
292                   load-path))
293     )
294   (use-package magit-annex
295     :ensure f
296     :config (require 'magit-annex)
297   )
298 #+END_SRC
299
300 ** Perl
301 #+BEGIN_SRC emacs-lisp
302   (require 'cperl-mode)
303   ;; Use c-mode for perl .xs files
304   (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
305   (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
306   (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
307   (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
308   (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
309   (setq cperl-hairy t
310         cperl-indent-level 4
311         cperl-auto-newline nil
312         cperl-auto-newline-after-colon nil
313         cperl-continued-statement-offset 4
314         cperl-brace-offset -1
315         cperl-continued-brace-offset 0
316         cperl-label-offset -4
317         cperl-highlight-variables-indiscriminately t
318         cperl-electric-lbrace-space nil
319         cperl-indent-parens-as-block nil
320         cperl-close-paren-offset -1
321         cperl-tab-always-indent t)
322   ;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
323 #+END_SRC
324
325 ** Helm
326 #+BEGIN_SRC emacs-lisp
327 (require 'don-helm)
328 #+END_SRC
329 ** Hydra
330 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
331 (require 'don-hydra)
332 #+END_SRC
333
334 ** Tramp
335 #+BEGIN_SRC emacs-lisp
336   (add-to-list 'tramp-methods '("vcsh"
337                                 (tramp-login-program "vcsh")
338                                 (tramp-login-args
339                                  (("enter")
340                                   ("%h")))
341                                 (tramp-remote-shell "/bin/sh")
342                                 (tramp-remote-shell-args
343                                  ("-c"))))
344 #+END_SRC
345 ** LaTeX
346 #+BEGIN_SRC emacs-lisp
347   (load "auctex.el" nil t t)
348   (load "preview-latex.el" nil t t)
349   (load "latex.el" nil t t)
350
351   ;; this is in the very newest auctex; avoid for now
352   (add-to-list 'LaTeX-fill-excluded-macros
353                '("Sexpr"))
354   ;; REFTEX (much enhanced management of cross-ref, labels, etc)
355   ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
356   (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
357   (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
358   (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
359   (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
360   (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
361   (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
362   (add-hook 'LaTeX-mode-hook 'outline-minor-mode)   ; with AUCTeX LaTeX mode
363   (add-hook 'latex-mode-hook 'outline-minor-mode)   ; with Emacs latex mode
364
365   ; use smart quotes by default instead of `` and ''
366   ; taken from http://kieranhealy.org/esk/kjhealy.html
367   (setq TeX-open-quote "“")
368   (setq TeX-close-quote "”")
369
370   ;; (TeX-add-style-hook
371   ;;  "latex"
372   ;;  (lambda ()
373   ;;    (TeX-add-symbols
374   ;;     '("DLA" 1))))
375   ;; (custom-set-variables
376   ;;  '(font-latex-user-keyword-classes 
377   ;;    '(("fixme" 
378   ;;       ("DLA" "RZ")
379   ;;       font-lock-function-name-face 2 (command 1 t))))
380   ;; ) 
381
382   (require 'font-latex)
383   (setq font-latex-match-reference-keywords
384         '(
385           ("fref" "{")
386           ("Fref" "{")
387           ("citep" "{")
388           ("citet" "{")
389           ("acs" "{")
390           ("acsp" "{")
391           ("ac" "{")
392           ("acp" "{")
393           ("acl" "{")
394           ("aclp" "{")
395           ("acsu" "{")
396           ("aclu" "{")
397           ("acused" "{")
398   ;         ))
399   ; (setq font-latex-match-warning-keywords
400   ;       '(
401           ("DLA" "{")
402           ("RZ" "{")
403           ("OM" "{")
404           ("DL" "{")
405           ("fixme" "{")))
406       
407   (setq-default TeX-parse-self t)
408   (setq-default TeX-auto-save t)
409   (setq-default TeX-master nil)
410   (eval-after-load
411       "latex"
412     '(TeX-add-style-hook
413       "cleveref"
414       (lambda ()
415         (if (boundp 'reftex-ref-style-alist)
416         (add-to-list
417          'reftex-ref-style-alist
418          '("Cleveref" "cleveref"
419            (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
420         (reftex-ref-style-activate "Cleveref")
421         (TeX-add-symbols
422          '("cref" TeX-arg-ref)
423          '("Cref" TeX-arg-ref)
424          '("cpageref" TeX-arg-ref)
425          '("Cpageref" TeX-arg-ref)))))
426   ;; this doesn't seem to work; not currently sure why
427   ; (setq font-latex-user-keyword-classes
428   ;       '(("my-warning-commands"
429   ;          (("DLA" "{")
430   ;           ("RZ" "{")
431   ;           ("OM" "{")
432   ;           ("DL" "{")
433   ;           ("fixme" "{")
434   ;           )
435   ;          (:foreground "red" :weight bold :underline (:color foreground-color :style line)))
436   ;         ))
437
438   (setq-default reftex-default-bibliography
439         '("~/projects/research/references.bib"))
440
441
442 #+END_SRC
443 ** Org
444 #+BEGIN_SRC emacs-lisp
445   (require 'org-mode-configuration)
446 #+END_SRC
447 ** ESS
448 #+BEGIN_SRC emacs-lisp
449   (require 'ess_configuration)
450 #+END_SRC
451
452
453 ** Polymode
454 #+BEGIN_SRC emacs-lisp
455   (setq load-path
456         (append '("~/lib/emacs_el/polymode/modes")
457                 load-path))
458   (require 'polymode)
459   (require 'poly-R)
460   (require 'poly-noweb)
461   (require 'poly-markdown)
462   (add-to-list 'auto-mode-alist '("\\.Snw" . poly-noweb+r-mode))
463   (add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))
464   (add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))
465 #+END_SRC
466
467 * Keybindings
468 ** Override other things
469 #+BEGIN_SRC emacs-lisp
470   ; apparently things like to step on C-;, so we'll use a hack from
471   ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
472
473   (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
474
475   ; use iedit everywhere
476   (define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
477   ;; use outline mode keybindings everywhere
478   (define-key my-keys-minor-mode-map (kbd "C-;") 'my/mydra-outline/body)
479
480   (define-minor-mode my-keys-minor-mode
481     "A minor mode so that my key settings override annoying major modes."
482     t " my-keys" 'my-keys-minor-mode-map)
483
484   (my-keys-minor-mode 1)
485   (defun my-minibuffer-setup-hook ()
486     (my-keys-minor-mode 0))
487
488   (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
489   (defadvice load (after give-my-keybindings-priority)
490     "Try to ensure that my keybindings always have priority."
491     (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
492         (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
493           (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
494           (add-to-list 'minor-mode-map-alist mykeys))))
495   (ad-activate 'load)
496 #+END_SRC
497
498 * Misc (uncharacterized)
499 #+BEGIN_SRC emacs-lisp
500   (setq bibtex-user-optional-fields (quote (("annote" "Personal annotation (ignored)") ("abstract" "") ("pmid" "") ("doi" ""))))
501   (setq calendar-latitude 40.11)
502   (setq calendar-longitude -88.24)
503   (setq case-fold-search t)
504   (setq confirm-kill-emacs (quote y-or-n-p))
505   (setq cperl-lazy-help-time nil)
506   (setq debian-changelog-mailing-address "don@debian.org")
507   (display-time)
508   (setq display-time-24hr-format t)
509   (setq display-time-day-and-date t)
510   (display-time-mode 1)
511   (setq font-latex-fontify-script nil)
512   (setq font-latex-fontify-sectioning (quote color))
513   (setq font-latex-script-display (quote (nil)))
514   (global-auto-revert-mode 1)
515   (global-font-lock-mode 1)
516   (icomplete-mode 1)
517   (setq log-edit-keep-buffer t)
518   (setq mail-user-agent (quote sendmail-user-agent))
519   (setq markdown-enable-math t)
520   (setq markdown-follow-wiki-link-on-enter nil)
521   (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
522   (setq post-email-address "don@donarmstrong.com")
523   (setq post-kill-quoted-sig nil)
524   (setq post-mail-message "mutt\\(ng\\|\\)-[a-z0-9]+-[0-9]+-.*")
525   (setq post-uses-fill-mode nil)
526   (setq ps-footer-font-size (quote (8 . 10)))
527   (setq ps-header-font-size (quote (8 . 10)))
528   (setq ps-header-title-font-size (quote (10 . 10)))
529   (setq ps-line-number-color "blue")
530   (setq ps-print-footer t)
531   (setq ps-print-footer-frame nil)
532   (setq ps-print-only-one-header t)
533   (setq safe-local-variable-values (quote ((auto-save-default) (make-backup-files))))
534   (setq sentence-end "[.?!][]\"')]*\\($\\|   \\| \\)[    
535   ]*")
536   (setq sentence-end-double-space nil)
537   ; enable matching parenthesis
538   (show-paren-mode 1)
539   (tool-bar-mode -1)
540   (setq user-mail-address "don@donarmstrong.com")
541   (setq vc-delete-logbuf-window nil)
542   (setq vc-follow-symlinks t)
543
544   ;; use git before SVN; use CVS earlier, because I have CVS
545   ;; repositories inside of git directories
546   (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
547
548   ;; switch back to the old primary selection method
549   (setq x-select-enable-clipboard nil)
550   (setq x-select-enable-primary t)
551   ; (setq mouse-drag-copy-region t)
552
553   (fset 'perl-mode 'cperl-mode)
554   ;;(load-file "cperl-mode.el")
555
556   (require 'vcl-mode)
557
558   (require 'tex-site)
559   ;;(require 'psvn)
560   ;;(require 'ecasound)
561   ;;(require 'emacs-wiki)
562   (require 'bibtex)
563   (require 'post)
564   ;;(require 'fixme)
565   ; (require 'google-weather)
566   ; (require 'org-google-weather)
567   ; (setq-default org-google-weather-format "%i %c, [%l,%h] %s %C")
568
569   ; http://julien.danjou.info/projects/emacs-packages#rainbow-mode
570   ; this colorizes color strings
571   (require 'rainbow-mode)
572   ; add ess to the x major mode
573   (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
574   (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
575
576   (global-set-key "\C-xp" 'server-edit)
577
578   (setq-default auto-mode-alist (cons '("\.wml$" . 
579                     (lambda () (html-mode) (auto-fill-mode)))
580                   auto-mode-alist))
581
582
583   ; use markdown mode for mdwn files
584   (add-to-list 'auto-mode-alist '("\\.mdwn$" . markdown-mode))
585   (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
586
587
588   ;; tramp configuration
589   (setq tramp-use-ssh-controlmaster-options nil)
590
591   ; mail configuration
592   (add-to-list 'auto-mode-alist '("muttng-[a-z0-9]+-[0-9]+-" . message-mode))
593   (add-to-list 'auto-mode-alist '("muttngrc" . muttrc-mode))
594
595   (add-to-list 'auto-mode-alist '("mutt-[a-z0-9]+-[0-9]+-" . message-mode))
596   (add-to-list 'auto-mode-alist '("muttrc" . muttrc-mode))
597   (defun my-message-mode-settings ()
598     (font-lock-add-keywords nil
599                             '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
600                                (0 'message-multiply-quoted-text-face))
601                               ("^[ \t]*>[ \t]*>.*$"
602                                (0 'message-double-quoted-text-face))))
603     (local-set-key (kbd "C-c C-a") 'my-post-attach-file)
604     )
605   (add-hook 'message-mode-hook 'my-message-mode-settings)
606
607   (defun my-post-attach-file ()
608     "Prompt for an attachment."
609     (interactive)
610     (let ((file (read-file-name "Attach file: " nil nil t nil))
611           (description (string-read "Description: ")))
612       (my-header-attach-file file description)))
613
614   (symbol-function 'my-post-attach-file)
615
616   (defun my-header-attach-file (file description)
617     "Attach a FILE to the current message (works with Mutt).
618   Argument DESCRIPTION MIME description."
619     (interactive "fAttach file: \nsDescription: ")
620     (when (> (length file) 0)
621       (save-excursion
622         (save-match-data
623           (save-restriction
624             (widen)
625             (goto-char (point-min))
626             (search-forward-regexp "^$")
627             (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
628                             description "\n"))
629             (message (concat "Attached '" file "'."))
630             (setq post-has-attachment t))))))
631
632
633
634   (setq mail-yank-prefix "> ")
635
636   (global-unset-key "\M-g")
637   (global-set-key "\M-g" 'goto-line)
638
639   ;; self-insert-command hack.
640   ;;   Without this, "if<SP>" expands to
641   ;;   if ( -!-) {
642   ;;   }
643   ;;   which really should be,
644   ;;   if (-!-) {
645   ;;   }
646
647
648
649   ;(load-library "php-mode")
650
651   (setq-default c-indent-level 4)
652   (setq-default c-brace-imaginary-offset 0)
653   (setq-default c-brace-offset -4)
654   (setq-default c-argdecl-indent 4)
655   (setq-default c-label-offset -4)
656   (setq-default c-continued-statement-offset 4)
657   ; tabs are annoying
658   (setq-default indent-tabs-mode nil)
659   (setq-default tab-width 4)
660
661
662   ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
663   ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
664   ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
665   ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
666   ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
667
668
669   (defun insert-date ()
670     "Insert date at point."
671     (interactive)
672     (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
673   (global-set-key "\C-[d" 'insert-date)
674
675   (defun unfill-paragraph (arg)
676     "Pull this whole paragraph up onto one line."
677     (interactive "*p")
678     (let ((fill-column 10000))
679       (fill-paragraph arg))
680     )
681
682   (column-number-mode t)
683   (setq-default reftex-plug-into-AUCTeX t)
684
685   (server-start)
686
687   ; (require 'mode-compile)
688
689   (defadvice server-process-filter (after post-mode-message first activate)
690     "If the buffer is in post mode, overwrite the server-edit
691       message with a post-save-current-buffer-and-exit message."
692     (if (eq major-mode 'post-mode)
693         (message
694          (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
695                       ; This is also needed to see the magic message.  Set to a higher
696                       ; number if you have a faster computer or read slower than me.
697   '(font-lock-verbose 1000)
698   ;(setq-default server-temp-file-regexp "mutt\(-\|ng-\)")
699   ; (add-hook 'server-switch-hook 
700   ;     (function (lambda()
701   ;             (cond ((string-match "Post" mode-name)
702   ;                (post-goto-body)))
703   ;             set-buffer-file-coding-system 'utf-8
704   ;             )))
705   ; 
706
707   (add-hook 'post-mode-hook
708         (auto-fill-mode nil)
709         )
710   ; abbrev mode settings
711   ; load abbreviations from 
712   (setq abbrev-file-name       
713         "~/.emacs_abbrev_def")
714
715   ; read the abbrev file if it exists
716   (if (file-exists-p abbrev-file-name)
717       (quietly-read-abbrev-file))
718
719   ; for now, use abbrev mode everywhere
720   (setq default-abbrev-mode t)
721
722
723   (defun insert-function-documentation ()
724     "Insert function documentation"
725     (interactive)
726     (insert-file-contents "/home/don/lib/templates/perl_function_documentation" nil))
727   (global-set-key "\M-f" 'insert-function-documentation)
728
729   (eval-after-load "lilypond-mode" 
730     '(progn
731        (load-library "lyqi-mode")
732        (define-key LilyPond-mode-map "\C-cq" 'lyqi-mode)))
733
734   (autoload 'spamassassin-mode "spamassassin-mode" nil t)
735
736   (desktop-load-default)
737   (desktop-read)
738   '(icomplete-mode on)
739   (custom-set-faces
740    ;; custom-set-faces was added by Custom.
741    ;; If you edit it by hand, you could mess it up, so be careful.
742    ;; Your init file should contain only one such instance.
743    ;; If there is more than one, they won't work right.
744    '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
745
746
747   (put 'upcase-region 'disabled nil)
748   (put 'downcase-region 'disabled nil)
749   (put 'narrow-to-region 'disabled nil)
750
751
752   (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
753   (add-hook 'message-mode-hook 'turn-on-flyspell)
754   (add-hook 'text-mode-hook 'turn-on-flyspell)
755   (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
756   (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
757   (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
758   ; (defun turn-on-flyspell ()
759   ;    "Force flyspell-mode on using a positive arg.  For use in hooks."
760   ;    (interactive)
761   ;    (flyspell-mode 1))
762
763
764    ; Outline-minor-mode key map
765    (define-prefix-command 'cm-map nil "Outline-")
766    ; HIDE
767    (define-key cm-map "q" 'hide-sublevels)    ; Hide everything but the top-level headings
768    (define-key cm-map "t" 'hide-body)         ; Hide everything but headings (all body lines)
769    (define-key cm-map "o" 'hide-other)        ; Hide other branches
770    (define-key cm-map "c" 'hide-entry)        ; Hide this entry's body
771    (define-key cm-map "l" 'hide-leaves)       ; Hide body lines in this entry and sub-entries
772    (define-key cm-map "d" 'hide-subtree)      ; Hide everything in this entry and sub-entries
773    ; SHOW
774    (define-key cm-map "a" 'show-all)          ; Show (expand) everything
775    (define-key cm-map "e" 'show-entry)        ; Show this heading's body
776    (define-key cm-map "i" 'show-children)     ; Show this heading's immediate child sub-headings
777    (define-key cm-map "k" 'show-branches)     ; Show all sub-headings under this heading
778    (define-key cm-map "s" 'show-subtree)      ; Show (expand) everything in this heading & below
779    ; MOVE
780    (define-key cm-map "u" 'outline-up-heading)                ; Up
781    (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
782    (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
783    (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
784    (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
785    (global-set-key "\M-o" cm-map)
786
787
788   ; debian stuff
789   (setq-default debian-changelog-mailing-address "don@debian.org")
790   (setq-default debian-changelog-full-name "Don Armstrong")
791
792   ; ediff configuration
793   ; don't use the multi-window configuration
794   (setq ediff-window-setup-function 'ediff-setup-windows-plain)
795
796   ; use iedit
797   (require 'iedit)
798   (define-key global-map (kbd "C-;") 'iedit-mode)
799   (global-set-key  (kbd "C-;") 'iedit-mode)
800
801   ; fix up css mode to not be silly
802   ; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
803   (setq cssm-indent-level 4)
804   (setq cssm-newline-before-closing-bracket t)
805   (setq cssm-indent-function #'cssm-c-style-indenter)
806   (setq cssm-mirror-mode nil)
807
808   (require 'multi-web-mode)
809   (setq mweb-default-major-mode 'html-mode)
810   (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
811                     (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
812                     (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
813   (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
814   (multi-web-global-mode 1)
815
816   ;;; alias the new `flymake-report-status-slim' to
817   ;;; `flymake-report-status'
818   (defalias 'flymake-report-status 'flymake-report-status-slim)
819   (defun flymake-report-status-slim (e-w &optional status)
820     "Show \"slim\" flymake status in mode line."
821     (when e-w
822       (setq flymake-mode-line-e-w e-w))
823     (when status
824       (setq flymake-mode-line-status status))
825     (let* ((mode-line " Φ"))
826       (when (> (length flymake-mode-line-e-w) 0)
827         (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
828       (setq mode-line (concat mode-line flymake-mode-line-status))
829       (setq flymake-mode-line mode-line)
830       (force-mode-line-update)))
831
832   ; load sql-indent when sql is loaded
833   (eval-after-load "sql"
834     '(load-library "sql-indent"))
835
836   ; fix up tmux xterm keys
837   ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
838   (if (getenv "TMUX")
839       (progn
840         (let ((x 2) (tkey ""))
841           (while (<= x 8)
842             ;; shift
843             (if (= x 2)
844                 (setq tkey "S-"))
845             ;; alt
846             (if (= x 3)
847                 (setq tkey "M-"))
848             ;; alt + shift
849             (if (= x 4)
850                 (setq tkey "M-S-"))
851             ;; ctrl
852             (if (= x 5)
853                 (setq tkey "C-"))
854             ;; ctrl + shift
855             (if (= x 6)
856                 (setq tkey "C-S-"))
857             ;; ctrl + alt
858             (if (= x 7)
859                 (setq tkey "C-M-"))
860             ;; ctrl + alt + shift
861             (if (= x 8)
862                 (setq tkey "C-M-S-"))
863   
864             ;; arrows
865             (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
866             (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
867             (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
868             (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
869             ;; home
870             (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
871             ;; end
872             (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
873             ;; page up
874             (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
875             ;; page down
876             (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
877             ;; insert
878             (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
879             ;; delete
880             (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
881             ;; f1
882             (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
883             ;; f2
884             (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
885             ;; f3
886             (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
887             ;; f4
888             (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
889             ;; f5
890             (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
891             ;; f6
892             (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
893             ;; f7
894             (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
895             ;; f8
896             (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
897             ;; f9
898             (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
899             ;; f10
900             (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
901             ;; f11
902             (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
903             ;; f12
904             (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
905             ;; f13
906             (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
907             ;; f14
908             (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
909             ;; f15
910             (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
911             ;; f16
912             (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
913             ;; f17
914             (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
915             ;; f18
916             (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
917             ;; f19
918             (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
919             ;; f20
920             (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
921
922             (setq x (+ x 1))
923             ))
924         )
925     )
926
927   ; procmailmode configuration
928   (load "procmail_mode")
929
930   (load "mode-line-cleaner")
931
932   (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
933     "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
934     (if (or (buffer-modified-p)
935             (verify-visited-file-modtime)
936             (< (* 8 1024 1024) (buffer-size))
937             (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
938         ad-do-it
939       (clear-visited-file-modtime)
940       (not-modified)))
941   (ad-activate 'ask-user-about-supersession-threat)
942
943   ; apparently things like to step on C-;, so we'll use a hack from
944   ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
945
946   (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
947
948   ; use iedit everywhere
949   (define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
950
951   (define-minor-mode my-keys-minor-mode
952     "A minor mode so that my key settings override annoying major modes."
953     t " my-keys" 'my-keys-minor-mode-map)
954
955   (my-keys-minor-mode 1)
956   (defun my-minibuffer-setup-hook ()
957     (my-keys-minor-mode 0))
958
959   (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
960   (defadvice load (after give-my-keybindings-priority)
961     "Try to ensure that my keybindings always have priority."
962     (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
963         (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
964           (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
965           (add-to-list 'minor-mode-map-alist mykeys))))
966   (ad-activate 'load)
967   (global-set-key "\M- " 'hippie-expand)
968
969 #+END_SRC
970
971 * END
972 #+BEGIN_SRC emacs-lisp
973   (provide 'don-configuration)
974 #+END_SRC