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