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