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