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