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