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