6a7cf7078a10ef36589682a4e9a820f8324e31de
[profile] / el / dot-emacs.el
1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
2 ;;;
3 ;;; Functions and macros for .emacs
4 ;;;
5 ;;; (c) 2004 Mark Wooding
6 ;;;
7
8 ;;;----- Licensing notice ---------------------------------------------------
9 ;;;
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
14 ;;;
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software Foundation,
22 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 ;;;--------------------------------------------------------------------------
25 ;;; Check command-line.
26
27 (defvar mdw-fast-startup nil
28 "Whether .emacs should optimize for rapid startup.
29 This may be at the expense of cool features.")
30 (let ((probe nil) (next command-line-args))
31 (while next
32 (cond ((string= (car next) "--mdw-fast-startup")
33 (setq mdw-fast-startup t)
34 (if probe
35 (rplacd probe (cdr next))
36 (setq command-line-args (cdr next))))
37 (t
38 (setq probe next)))
39 (setq next (cdr next))))
40
41 ;;;--------------------------------------------------------------------------
42 ;;; Some general utilities.
43
44 (eval-when-compile
45 (unless (fboundp 'make-regexp)
46 (load "make-regexp"))
47 (require 'cl))
48
49 (defmacro mdw-regexps (&rest list)
50 "Turn a LIST of strings into a single regular expression at compile-time."
51 (declare (indent nil)
52 (debug 0))
53 `',(make-regexp list))
54
55 ;; Some error trapping.
56 ;;
57 ;; If individual bits of this file go tits-up, we don't particularly want
58 ;; the whole lot to stop right there and then, because it's bloody annoying.
59
60 (defmacro trap (&rest forms)
61 "Execute FORMS without allowing errors to propagate outside."
62 (declare (indent 0)
63 (debug t))
64 `(condition-case err
65 ,(if (cdr forms) (cons 'progn forms) (car forms))
66 (error (message "Error (trapped): %s in %s"
67 (error-message-string err)
68 ',forms))))
69
70 ;; Configuration reading.
71
72 (defvar mdw-config nil)
73 (defun mdw-config (sym)
74 "Read the configuration variable named SYM."
75 (unless mdw-config
76 (setq mdw-config
77 (flet ((replace (what with)
78 (goto-char (point-min))
79 (while (re-search-forward what nil t)
80 (replace-match with t))))
81 (with-temp-buffer
82 (insert-file-contents "~/.mdw.conf")
83 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
84 (replace (concat "^[ \t]*"
85 "\\([-a-zA-Z0-9_.]*\\)"
86 "[ \t]*=[ \t]*"
87 "\\(.*[^ \t\n]\\|\\)"
88 "[ \t]**\\(\n\\|$\\)")
89 "(\\1 . \"\\2\")\n")
90 (car (read-from-string
91 (concat "(" (buffer-string) ")")))))))
92 (cdr (assq sym mdw-config)))
93
94 ;; Set up the load path convincingly.
95
96 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
97 (list (concat "/usr/share/"
98 (symbol-name debian-emacs-flavor)
99 "/site-lisp")))))
100 (dolist (sub (directory-files dir t))
101 (when (and (file-accessible-directory-p sub)
102 (not (member sub load-path)))
103 (setq load-path (nconc load-path (list sub))))))
104
105 ;; Is an Emacs library available?
106
107 (defun library-exists-p (name)
108 "Return non-nil if NAME is an available library.
109 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
110 load path. The non-nil value is the filename we found for the
111 library."
112 (let ((path load-path) elt (foundp nil))
113 (while (and path (not foundp))
114 (setq elt (car path))
115 (setq path (cdr path))
116 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
117 (and (file-exists-p file) file))
118 (let ((file (concat elt "/" name ".el")))
119 (and (file-exists-p file) file)))))
120 foundp))
121
122 (defun maybe-autoload (symbol file &optional docstring interactivep type)
123 "Set an autoload if the file actually exists."
124 (and (library-exists-p file)
125 (autoload symbol file docstring interactivep type)))
126
127 ;; Splitting windows.
128
129 (unless (fboundp 'scroll-bar-columns)
130 (defun scroll-bar-columns (side)
131 (cond ((eq side 'left) 0)
132 (window-system 3)
133 (t 1))))
134 (unless (fboundp 'fringe-columns)
135 (defun fringe-columns (side)
136 (cond ((not window-system) 0)
137 ((eq side 'left) 1)
138 (t 2))))
139
140 (defun mdw-divvy-window (&optional width)
141 "Split a wide window into appropriate widths."
142 (interactive "P")
143 (setq width (cond (width (prefix-numeric-value width))
144 ((and window-system
145 (>= emacs-major-version 22))
146 77)
147 (t 78)))
148 (let* ((win (selected-window))
149 (sb-width (if (not window-system)
150 1
151 (let ((tot 0))
152 (dolist (what '(scroll-bar fringe))
153 (dolist (side '(left right))
154 (incf tot
155 (funcall (intern (concat (symbol-name what)
156 "-columns"))
157 side))))
158 tot)))
159 (c (/ (+ (window-width) sb-width)
160 (+ width sb-width))))
161 (while (> c 1)
162 (setq c (1- c))
163 (split-window-horizontally (+ width sb-width))
164 (other-window 1))
165 (select-window win)))
166
167 ;; Functions for sexp diary entries.
168
169 (defun mdw-weekday (l)
170 "Return non-nil if `date' falls on one of the days of the week in L.
171 L is a list of day numbers (from 0 to 6 for Sunday through to
172 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
173 the date stored in `date' falls on a listed day, then the
174 function returns non-nil."
175 (let ((d (calendar-day-of-week date)))
176 (or (memq d l)
177 (memq (nth d '(sunday monday tuesday wednesday
178 thursday friday saturday)) l))))
179
180 (defun mdw-todo (&optional when)
181 "Return non-nil today, or on WHEN, whichever is later."
182 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
183 (d (calendar-absolute-from-gregorian date)))
184 (if when
185 (setq w (max w (calendar-absolute-from-gregorian
186 (cond
187 ((not european-calendar-style)
188 when)
189 ((> (car when) 100)
190 (list (nth 1 when)
191 (nth 2 when)
192 (nth 0 when)))
193 (t
194 (list (nth 1 when)
195 (nth 0 when)
196 (nth 2 when))))))))
197 (eq w d)))
198
199 ;; Fighting with Org-mode's evil key maps.
200
201 (defvar mdw-evil-keymap-keys
202 '(([S-up] . [?\C-c up])
203 ([S-down] . [?\C-c down])
204 ([S-left] . [?\C-c left])
205 ([S-right] . [?\C-c right])
206 (([M-up] [?\e up]) . [C-up])
207 (([M-down] [?\e down]) . [C-down])
208 (([M-left] [?\e left]) . [C-left])
209 (([M-right] [?\e right]) . [C-right]))
210 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
211 The value is an alist mapping evil keys (as a list, or singleton)
212 to good keys (in the same form).")
213
214 (defun mdw-clobber-evil-keymap (keymap)
215 "Replace evil key bindings in the KEYMAP.
216 Evil key bindings are defined in `mdw-evil-keymap-keys'."
217 (dolist (entry mdw-evil-keymap-keys)
218 (let ((binding nil)
219 (keys (if (listp (car entry))
220 (car entry)
221 (list (car entry))))
222 (replacements (if (listp (cdr entry))
223 (cdr entry)
224 (list (cdr entry)))))
225 (catch 'found
226 (dolist (key keys)
227 (setq binding (lookup-key keymap key))
228 (when binding
229 (throw 'found nil))))
230 (when binding
231 (dolist (key keys)
232 (define-key keymap key nil))
233 (dolist (key replacements)
234 (define-key keymap key binding))))))
235
236 (eval-after-load "org-latex"
237 '(progn
238 (push '("strayman"
239 "\\documentclass{strayman}
240 \\usepackage[utf8]{inputenc}
241 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
242 \\usepackage[T1]{fontenc}
243 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
244 ("\\section{%s}" . "\\section*{%s}")
245 ("\\subsection{%s}" . "\\subsection*{%s}")
246 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
247 ("\\paragraph{%s}" . "\\paragraph*{%s}")
248 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
249 org-export-latex-classes)))
250
251 ;;;--------------------------------------------------------------------------
252 ;;; Mail and news hacking.
253
254 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
255 "Major mode for editing news and mail messages from external programs.
256 Not much right now. Just support for doing MailCrypt stuff."
257 :syntax-table nil
258 :abbrev-table nil
259 (run-hooks 'mail-setup-hook))
260
261 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
262
263 (add-hook 'mdwail-mode-hook
264 (lambda ()
265 (set-buffer-file-coding-system 'utf-8)
266 (make-local-variable 'paragraph-separate)
267 (make-local-variable 'paragraph-start)
268 (setq paragraph-start
269 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
270 paragraph-start))
271 (setq paragraph-separate
272 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
273 paragraph-separate))))
274
275 ;; How to encrypt in mdwmail.
276
277 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
278 (or start
279 (setq start (save-excursion
280 (goto-char (point-min))
281 (or (search-forward "\n\n" nil t) (point-min)))))
282 (or end
283 (setq end (point-max)))
284 (mc-encrypt-generic recip scm start end from sign))
285
286 ;; How to sign in mdwmail.
287
288 (defun mdwmail-mc-sign (key scm start end uclr)
289 (or start
290 (setq start (save-excursion
291 (goto-char (point-min))
292 (or (search-forward "\n\n" nil t) (point-min)))))
293 (or end
294 (setq end (point-max)))
295 (mc-sign-generic key scm start end uclr))
296
297 ;; Some signature mangling.
298
299 (defun mdwmail-mangle-signature ()
300 (save-excursion
301 (goto-char (point-min))
302 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
303 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
304 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
305
306 ;; Insert my login name into message-ids, so I can score replies.
307
308 (defadvice message-unique-id (after mdw-user-name last activate compile)
309 "Ensure that the user's name appears at the end of the message-id string,
310 so that it can be used for convenient filtering."
311 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
312
313 ;; Tell my movemail hack where movemail is.
314 ;;
315 ;; This is needed to shup up warnings about LD_PRELOAD.
316
317 (let ((path exec-path))
318 (while path
319 (let ((try (expand-file-name "movemail" (car path))))
320 (if (file-executable-p try)
321 (setenv "REAL_MOVEMAIL" try))
322 (setq path (cdr path)))))
323
324 ;;;--------------------------------------------------------------------------
325 ;;; Utility functions.
326
327 (or (fboundp 'line-number-at-pos)
328 (defun line-number-at-pos (&optional pos)
329 (let ((opoint (or pos (point))) start)
330 (save-excursion
331 (save-restriction
332 (goto-char (point-min))
333 (widen)
334 (forward-line 0)
335 (setq start (point))
336 (goto-char opoint)
337 (forward-line 0)
338 (1+ (count-lines 1 (point))))))))
339
340 (defun mdw-uniquify-alist (&rest alists)
341 "Return the concatenation of the ALISTS with duplicate elements removed.
342 The first association with a given key prevails; others are
343 ignored. The input lists are not modified, although they'll
344 probably become garbage."
345 (and alists
346 (let ((start-list (cons nil nil)))
347 (mdw-do-uniquify start-list
348 start-list
349 (car alists)
350 (cdr alists)))))
351
352 (defun mdw-do-uniquify (done end l rest)
353 "A helper function for mdw-uniquify-alist.
354 The DONE argument is a list whose first element is `nil'. It
355 contains the uniquified alist built so far. The leading `nil' is
356 stripped off at the end of the operation; it's only there so that
357 DONE always references a cons cell. END refers to the final cons
358 cell in the DONE list; it is modified in place each time to avoid
359 the overheads of `append'ing all the time. The L argument is the
360 alist we're currently processing; the remaining alists are given
361 in REST."
362
363 ;; There are several different cases to deal with here.
364 (cond
365
366 ;; Current list isn't empty. Add the first item to the DONE list if
367 ;; there's not an item with the same KEY already there.
368 (l (or (assoc (car (car l)) done)
369 (progn
370 (setcdr end (cons (car l) nil))
371 (setq end (cdr end))))
372 (mdw-do-uniquify done end (cdr l) rest))
373
374 ;; The list we were working on is empty. Shunt the next list into the
375 ;; current list position and go round again.
376 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
377
378 ;; Everything's done. Remove the leading `nil' from the DONE list and
379 ;; return it. Finished!
380 (t (cdr done))))
381
382 (defun date ()
383 "Insert the current date in a pleasing way."
384 (interactive)
385 (insert (save-excursion
386 (let ((buffer (get-buffer-create "*tmp*")))
387 (unwind-protect (progn (set-buffer buffer)
388 (erase-buffer)
389 (shell-command "date +%Y-%m-%d" t)
390 (goto-char (mark))
391 (delete-backward-char 1)
392 (buffer-string))
393 (kill-buffer buffer))))))
394
395 (defun uuencode (file &optional name)
396 "UUencodes a file, maybe calling it NAME, into the current buffer."
397 (interactive "fInput file name: ")
398
399 ;; If NAME isn't specified, then guess from the filename.
400 (if (not name)
401 (setq name
402 (substring file
403 (or (string-match "[^/]*$" file) 0))))
404 (print (format "uuencode `%s' `%s'" file name))
405
406 ;; Now actually do the thing.
407 (call-process "uuencode" file t nil name))
408
409 (defvar np-file "~/.np"
410 "*Where the `now-playing' file is.")
411
412 (defun np (&optional arg)
413 "Grabs a `now-playing' string."
414 (interactive)
415 (save-excursion
416 (or arg (progn
417 (goto-char (point-max))
418 (insert "\nNP: ")
419 (insert-file-contents np-file)))))
420
421 (defun mdw-check-autorevert ()
422 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
423 This takes into consideration whether it's been found using
424 tramp, which seems to get itself into a twist."
425 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
426 nil)
427 ((and (buffer-file-name)
428 (fboundp 'tramp-tramp-file-p)
429 (tramp-tramp-file-p (buffer-file-name)))
430 (unless global-auto-revert-ignore-buffer
431 (setq global-auto-revert-ignore-buffer 'tramp)))
432 ((eq global-auto-revert-ignore-buffer 'tramp)
433 (setq global-auto-revert-ignore-buffer nil))))
434
435 (defadvice find-file (after mdw-autorevert activate)
436 (mdw-check-autorevert))
437 (defadvice write-file (after mdw-autorevert activate)
438 (mdw-check-autorevert))
439
440 ;;;--------------------------------------------------------------------------
441 ;;; Dired hacking.
442
443 (defadvice dired-maybe-insert-subdir
444 (around mdw-marked-insertion first activate)
445 "The DIRNAME may be a list of directory names to insert.
446 Interactively, if files are marked, then insert all of them.
447 With a numeric prefix argument, select that many entries near
448 point; with a non-numeric prefix argument, prompt for listing
449 options."
450 (interactive
451 (list (dired-get-marked-files nil
452 (and (integerp current-prefix-arg)
453 current-prefix-arg)
454 #'file-directory-p)
455 (and current-prefix-arg
456 (not (integerp current-prefix-arg))
457 (read-string "Switches for listing: "
458 (or dired-subdir-switches
459 dired-actual-switches)))))
460 (let ((dirs (ad-get-arg 0)))
461 (dolist (dir (if (listp dirs) dirs (list dirs)))
462 (ad-set-arg 0 dir)
463 ad-do-it)))
464
465 ;;;--------------------------------------------------------------------------
466 ;;; URL viewing.
467
468 (defun mdw-w3m-browse-url (url &optional new-session-p)
469 "Invoke w3m on the URL in its current window, or at least a different one.
470 If NEW-SESSION-P, start a new session."
471 (interactive "sURL: \nP")
472 (save-excursion
473 (let ((window (selected-window)))
474 (unwind-protect
475 (progn
476 (select-window (or (and (not new-session-p)
477 (get-buffer-window "*w3m*"))
478 (progn
479 (if (one-window-p t) (split-window))
480 (get-lru-window))))
481 (w3m-browse-url url new-session-p))
482 (select-window window)))))
483
484 (defvar mdw-good-url-browsers
485 '((w3m . mdw-w3m-browse-url)
486 browse-url-w3
487 browse-url-mozilla)
488 "List of good browsers for mdw-good-url-browsers.
489 Each item is a browser function name, or a cons (CHECK . FUNC).
490 A symbol FOO stands for (FOO . FOO).")
491
492 (defun mdw-good-url-browser ()
493 "Return a good URL browser.
494 Trundle the list of such things, finding the first item for which
495 CHECK is fboundp, and returning the correponding FUNC."
496 (let ((bs mdw-good-url-browsers) b check func answer)
497 (while (and bs (not answer))
498 (setq b (car bs)
499 bs (cdr bs))
500 (if (consp b)
501 (setq check (car b) func (cdr b))
502 (setq check b func b))
503 (if (fboundp check)
504 (setq answer func)))
505 answer))
506
507 (eval-after-load "w3m-search"
508 '(progn
509 (dolist
510 (item
511 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
512 ("gd" "Google Directory"
513 "http://www.google.com/search?cat=gwd/Top&q=%s")
514 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
515 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
516 ("gi" "Images" "http://images.google.com/images?q=%s")
517 ("rfc" "RFC"
518 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
519 ("wp" "Wikipedia"
520 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
521 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
522 ("nc-wiki" "nCipher wiki"
523 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
524 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
525 ("lp" "Launchpad bug by number"
526 "https://bugs.launchpad.net/bugs/%s")
527 ("lppkg" "Launchpad bugs by package"
528 "https://bugs.launchpad.net/%s")
529 ("msdn" "MSDN"
530 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
531 ("debbug" "Debian bug by number"
532 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
533 ("debbugpkg" "Debian bugs by package"
534 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
535 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
536 (add-to-list 'w3m-search-engine-alist
537 (list (cadr item) (caddr item) nil))
538 (add-to-list 'w3m-uri-replace-alist
539 (list (concat "\\`" (car item) ":")
540 'w3m-search-uri-replace
541 (cadr item))))))
542
543 ;;;--------------------------------------------------------------------------
544 ;;; Paragraph filling.
545
546 ;; Useful variables.
547
548 (defvar mdw-fill-prefix nil
549 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
550 If there's no fill prefix currently set (by the `fill-prefix'
551 variable) and there's a match from one of the regexps here, it
552 gets used to set the fill-prefix for the current operation.
553
554 The variable is a list of items of the form `REGEXP . PREFIX'; if
555 the REGEXP matches, the PREFIX is used to set the fill prefix.
556 It in turn is a list of things:
557
558 STRING -- insert a literal string
559 (match . N) -- insert the thing matched by bracketed subexpression N
560 (pad . N) -- a string of whitespace the same width as subexpression N
561 (expr . FORM) -- the result of evaluating FORM")
562
563 (make-variable-buffer-local 'mdw-fill-prefix)
564
565 (defvar mdw-hanging-indents
566 (concat "\\(\\("
567 "\\([*o]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
568 "[ \t]+"
569 "\\)?\\)")
570 "*Standard regexp matching parts of a hanging indent.
571 This is mainly useful in `auto-fill-mode'.")
572
573 ;; Setting things up.
574
575 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
576
577 ;; Utility functions.
578
579 (defun mdw-tabify (s)
580 "Tabify the string S. This is a horrid hack."
581 (save-excursion
582 (save-match-data
583 (let (start end)
584 (beginning-of-line)
585 (setq start (point-marker))
586 (insert s "\n")
587 (setq end (point-marker))
588 (tabify start end)
589 (setq s (buffer-substring start (1- end)))
590 (delete-region start end)
591 (set-marker start nil)
592 (set-marker end nil)
593 s))))
594
595 (defun mdw-examine-fill-prefixes (l)
596 "Given a list of dynamic fill prefixes, pick one which matches
597 context and return the static fill prefix to use. Point must be
598 at the start of a line, and match data must be saved."
599 (cond ((not l) nil)
600 ((looking-at (car (car l)))
601 (mdw-tabify (apply (function concat)
602 (mapcar (function mdw-do-prefix-match)
603 (cdr (car l))))))
604 (t (mdw-examine-fill-prefixes (cdr l)))))
605
606 (defun mdw-maybe-car (p)
607 "If P is a pair, return (car P), otherwise just return P."
608 (if (consp p) (car p) p))
609
610 (defun mdw-padding (s)
611 "Return a string the same width as S but made entirely from whitespace."
612 (let* ((l (length s)) (i 0) (n (make-string l ? )))
613 (while (< i l)
614 (if (= 9 (aref s i))
615 (aset n i 9))
616 (setq i (1+ i)))
617 n))
618
619 (defun mdw-do-prefix-match (m)
620 "Expand a dynamic prefix match element.
621 See `mdw-fill-prefix' for details."
622 (cond ((not (consp m)) (format "%s" m))
623 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
624 ((eq (car m) 'pad) (mdw-padding (match-string
625 (mdw-maybe-car (cdr m)))))
626 ((eq (car m) 'eval) (eval (cdr m)))
627 (t "")))
628
629 (defun mdw-choose-dynamic-fill-prefix ()
630 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
631 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
632 ((not mdw-fill-prefix) fill-prefix)
633 (t (save-excursion
634 (beginning-of-line)
635 (save-match-data
636 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
637
638 (defun do-auto-fill ()
639 "Handle auto-filling, working out a dynamic fill prefix in the
640 case where there isn't a sensible static one."
641 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
642 (mdw-do-auto-fill)))
643
644 (defun mdw-fill-paragraph ()
645 "Fill paragraph, getting a dynamic fill prefix."
646 (interactive)
647 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
648 (fill-paragraph nil)))
649
650 (defun mdw-standard-fill-prefix (rx &optional mat)
651 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
652 This is just a short-cut for setting the thing by hand, and by
653 design it doesn't cope with anything approximating a complicated
654 case."
655 (setq mdw-fill-prefix
656 `((,(concat rx mdw-hanging-indents)
657 (match . 1)
658 (pad . ,(or mat 2))))))
659
660 ;;;--------------------------------------------------------------------------
661 ;;; Other common declarations.
662
663 ;; Common mode settings.
664
665 (defvar mdw-auto-indent t
666 "Whether to indent automatically after a newline.")
667
668 (defun mdw-misc-mode-config ()
669 (and mdw-auto-indent
670 (cond ((eq major-mode 'lisp-mode)
671 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
672 ((or (eq major-mode 'slime-repl-mode)
673 (eq major-mode 'asm-mode))
674 nil)
675 (t
676 (local-set-key "\C-m" 'newline-and-indent))))
677 (local-set-key [C-return] 'newline)
678 (make-variable-buffer-local 'page-delimiter)
679 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
680 (setq comment-column 40)
681 (auto-fill-mode 1)
682 (setq fill-column 77)
683 (setq show-trailing-whitespace t)
684 (let ((whitespace-style (remove 'trailing whitespace-style)))
685 (trap (whitespace-mode t)))
686 (and (fboundp 'gtags-mode)
687 (gtags-mode))
688 (outline-minor-mode t)
689 (hs-minor-mode t)
690 (reveal-mode t)
691 (trap (turn-on-font-lock)))
692
693 (defun mdw-post-config-mode-hack ()
694 (let ((whitespace-style (remove 'trailing whitespace-style)))
695 (trap (whitespace-mode t))))
696
697 (eval-after-load 'gtags
698 '(progn
699 (dolist (key '([mouse-2] [mouse-3]))
700 (define-key gtags-mode-map key nil))
701 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
702 (define-key gtags-select-mode-map [C-S-mouse-2]
703 'gtags-select-tag-by-event)
704 (dolist (map (list gtags-mode-map gtags-select-mode-map))
705 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
706
707 ;; Backup file handling.
708
709 (defvar mdw-backup-disable-regexps nil
710 "*List of regular expressions: if a file name matches any of
711 these then the file is not backed up.")
712
713 (defun mdw-backup-enable-predicate (name)
714 "[mdw]'s default backup predicate.
715 Allows a backup if the standard predicate would allow it, and it
716 doesn't match any of the regular expressions in
717 `mdw-backup-disable-regexps'."
718 (and (normal-backup-enable-predicate name)
719 (let ((answer t) (list mdw-backup-disable-regexps))
720 (save-match-data
721 (while list
722 (if (string-match (car list) name)
723 (setq answer nil))
724 (setq list (cdr list)))
725 answer))))
726 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
727
728 ;; Frame cleanup.
729
730 (defun mdw-last-one-out-turn-off-the-lights (frame)
731 "Disconnect from an X display if this was the last frame on that display."
732 (let ((frame-display (frame-parameter frame 'display)))
733 (when (and frame-display
734 (eq window-system 'x)
735 (not (some (lambda (fr)
736 (message "checking frame %s" frame)
737 (and (not (eq fr frame))
738 (string= (frame-parameter fr 'display)
739 frame-display)
740 (progn "frame %s still uses us" nil)))
741 (frame-list))))
742 (message "turn out the lights")
743 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
744 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
745
746 ;;;--------------------------------------------------------------------------
747 ;;; General fontification.
748
749 (defmacro mdw-define-face (name &rest body)
750 "Define a face, and make sure it's actually set as the definition."
751 (declare (indent 1)
752 (debug 0))
753 `(progn
754 (make-face ',name)
755 (defvar ,name ',name)
756 (put ',name 'face-defface-spec ',body)
757 (face-spec-set ',name ',body nil)))
758
759 (mdw-define-face default
760 (((type w32)) :family "courier new" :height 85)
761 (((type x)) :family "6x13" :height 130)
762 (((type color)) :foreground "white" :background "black")
763 (t nil))
764 (mdw-define-face fixed-pitch
765 (((type w32)) :family "courier new" :height 85)
766 (((type x)) :family "6x13" :height 130)
767 (t :foreground "white" :background "black"))
768 (if (>= emacs-major-version 23)
769 (mdw-define-face variable-pitch
770 (((type x)) :family "sans" :height 100))
771 (mdw-define-face variable-pitch
772 (((type x)) :family "helvetica" :height 120)))
773 (mdw-define-face region
774 (((type tty) (class color)) :background "blue")
775 (((type tty) (class mono)) :inverse-video t)
776 (t :background "grey30"))
777 (mdw-define-face minibuffer-prompt
778 (t :weight bold))
779 (mdw-define-face mode-line
780 (((class color)) :foreground "blue" :background "yellow"
781 :box (:line-width 1 :style released-button))
782 (t :inverse-video t))
783 (mdw-define-face mode-line-inactive
784 (((class color)) :foreground "yellow" :background "blue"
785 :box (:line-width 1 :style released-button))
786 (t :inverse-video t))
787 (mdw-define-face scroll-bar
788 (t :foreground "black" :background "lightgrey"))
789 (mdw-define-face fringe
790 (t :foreground "yellow"))
791 (mdw-define-face show-paren-match
792 (((class color)) :background "darkgreen")
793 (t :underline t))
794 (mdw-define-face show-paren-mismatch
795 (((class color)) :background "red")
796 (t :inverse-video t))
797 (mdw-define-face highlight
798 (((class color)) :background "DarkSeaGreen4")
799 (t :inverse-video t))
800
801 (mdw-define-face holiday-face
802 (t :background "red"))
803 (mdw-define-face calendar-today-face
804 (t :foreground "yellow" :weight bold))
805
806 (mdw-define-face comint-highlight-prompt
807 (t :weight bold))
808 (mdw-define-face comint-highlight-input)
809
810 (mdw-define-face trailing-whitespace
811 (((class color)) :background "red")
812 (t :inverse-video t))
813 (mdw-define-face mdw-punct-face
814 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
815 (mdw-define-face mdw-number-face
816 (t :foreground "yellow"))
817 (mdw-define-face font-lock-function-name-face
818 (t :slant italic))
819 (mdw-define-face font-lock-keyword-face
820 (t :weight bold))
821 (mdw-define-face font-lock-constant-face
822 (t :slant italic))
823 (mdw-define-face font-lock-builtin-face
824 (t :weight bold))
825 (mdw-define-face font-lock-type-face
826 (t :weight bold :slant italic))
827 (mdw-define-face font-lock-reference-face
828 (t :weight bold))
829 (mdw-define-face font-lock-variable-name-face
830 (t :slant italic))
831 (mdw-define-face font-lock-comment-delimiter-face
832 (((class mono)) :weight bold)
833 (((type tty) (class color)) :foreground "green")
834 (t :slant italic :foreground "SeaGreen1"))
835 (mdw-define-face font-lock-comment-face
836 (((class mono)) :weight bold)
837 (((type tty) (class color)) :foreground "green")
838 (t :slant italic :foreground "SeaGreen1"))
839 (mdw-define-face font-lock-string-face
840 (((class mono)) :weight bold)
841 (((class color)) :foreground "SkyBlue1"))
842 (mdw-define-face message-separator
843 (t :background "red" :foreground "white" :weight bold))
844 (mdw-define-face message-cited-text
845 (default :slant italic)
846 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
847 (mdw-define-face message-header-cc
848 (default :weight bold)
849 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
850 (mdw-define-face message-header-newsgroups
851 (default :weight bold)
852 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
853 (mdw-define-face message-header-subject
854 (default :weight bold)
855 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
856 (mdw-define-face message-header-to
857 (default :weight bold)
858 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
859 (mdw-define-face message-header-xheader
860 (default :weight bold)
861 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
862 (mdw-define-face message-header-other
863 (default :weight bold)
864 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
865 (mdw-define-face message-header-name
866 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
867
868 (mdw-define-face diff-index
869 (t :weight bold))
870 (mdw-define-face diff-file-header
871 (t :weight bold))
872 (mdw-define-face diff-hunk-header
873 (t :foreground "SkyBlue1"))
874 (mdw-define-face diff-function
875 (t :foreground "SkyBlue1" :weight bold))
876 (mdw-define-face diff-header
877 (t :background "grey10"))
878 (mdw-define-face diff-added
879 (t :foreground "green"))
880 (mdw-define-face diff-removed
881 (t :foreground "red"))
882 (mdw-define-face diff-context)
883
884 (mdw-define-face erc-input-face
885 (t :foreground "red"))
886
887 (mdw-define-face woman-bold
888 (t :weight bold))
889 (mdw-define-face woman-italic
890 (t :slant italic))
891
892 (mdw-define-face p4-depot-added-face
893 (t :foreground "green"))
894 (mdw-define-face p4-depot-branch-op-face
895 (t :foreground "yellow"))
896 (mdw-define-face p4-depot-deleted-face
897 (t :foreground "red"))
898 (mdw-define-face p4-depot-unmapped-face
899 (t :foreground "SkyBlue1"))
900 (mdw-define-face p4-diff-change-face
901 (t :foreground "yellow"))
902 (mdw-define-face p4-diff-del-face
903 (t :foreground "red"))
904 (mdw-define-face p4-diff-file-face
905 (t :foreground "SkyBlue1"))
906 (mdw-define-face p4-diff-head-face
907 (t :background "grey10"))
908 (mdw-define-face p4-diff-ins-face
909 (t :foreground "green"))
910
911 (mdw-define-face whizzy-slice-face
912 (t :background "grey10"))
913 (mdw-define-face whizzy-error-face
914 (t :background "darkred"))
915
916 ;;;--------------------------------------------------------------------------
917 ;;; C programming configuration.
918
919 ;; Linux kernel hacking.
920
921 (defvar linux-c-mode-hook)
922
923 (defun linux-c-mode ()
924 (interactive)
925 (c-mode)
926 (setq major-mode 'linux-c-mode)
927 (setq mode-name "Linux C")
928 (run-hooks 'linux-c-mode-hook))
929
930 ;; Make C indentation nice.
931
932 (defun mdw-c-lineup-arglist (langelem)
933 "Hack for DWIMmery in c-lineup-arglist."
934 (if (save-excursion
935 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
936 0
937 (c-lineup-arglist langelem)))
938
939 (defun mdw-c-indent-extern-mumble (langelem)
940 "Indent `extern \"...\" {' lines."
941 (save-excursion
942 (back-to-indentation)
943 (if (looking-at
944 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
945 c-basic-offset
946 nil)))
947
948 (defun mdw-c-style ()
949 (c-add-style "[mdw] C and C++ style"
950 '((c-basic-offset . 2)
951 (comment-column . 40)
952 (c-class-key . "class")
953 (c-backslash-column . 72)
954 (c-offsets-alist
955 (substatement-open . (add 0 c-indent-one-line-block))
956 (defun-open . (add 0 c-indent-one-line-block))
957 (arglist-cont-nonempty . mdw-c-lineup-arglist)
958 (topmost-intro . mdw-c-indent-extern-mumble)
959 (cpp-define-intro . 0)
960 (inextern-lang . [0])
961 (label . 0)
962 (case-label . +)
963 (access-label . -)
964 (inclass . +)
965 (inline-open . ++)
966 (statement-cont . 0)
967 (statement-case-intro . +)))
968 t))
969
970 (defvar mdw-c-comment-fill-prefix
971 `((,(concat "\\([ \t]*/?\\)"
972 "\\(\*\\|//]\\)"
973 "\\([ \t]*\\)"
974 "\\([A-Za-z]+:[ \t]*\\)?"
975 mdw-hanging-indents)
976 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
977 "Fill prefix matching C comments (both kinds).")
978
979 (defun mdw-fontify-c-and-c++ ()
980
981 ;; Fiddle with some syntax codes.
982 (modify-syntax-entry ?* ". 23")
983 (modify-syntax-entry ?/ ". 124b")
984 (modify-syntax-entry ?\n "> b")
985
986 ;; Other stuff.
987 (mdw-c-style)
988 (setq c-hanging-comment-ender-p nil)
989 (setq c-backslash-column 72)
990 (setq c-label-minimum-indentation 0)
991 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
992
993 ;; Now define things to be fontified.
994 (make-local-variable 'font-lock-keywords)
995 (let ((c-keywords
996 (mdw-regexps "and" ;C++
997 "and_eq" ;C++
998 "asm" ;K&R, GCC
999 "auto" ;K&R, C89
1000 "bitand" ;C++
1001 "bitor" ;C++
1002 "bool" ;C++, C9X macro
1003 "break" ;K&R, C89
1004 "case" ;K&R, C89
1005 "catch" ;C++
1006 "char" ;K&R, C89
1007 "class" ;C++
1008 "complex" ;C9X macro, C++ template type
1009 "compl" ;C++
1010 "const" ;C89
1011 "const_cast" ;C++
1012 "continue" ;K&R, C89
1013 "defined" ;C89 preprocessor
1014 "default" ;K&R, C89
1015 "delete" ;C++
1016 "do" ;K&R, C89
1017 "double" ;K&R, C89
1018 "dynamic_cast" ;C++
1019 "else" ;K&R, C89
1020 ;; "entry" ;K&R -- never used
1021 "enum" ;C89
1022 "explicit" ;C++
1023 "export" ;C++
1024 "extern" ;K&R, C89
1025 "false" ;C++, C9X macro
1026 "float" ;K&R, C89
1027 "for" ;K&R, C89
1028 ;; "fortran" ;K&R
1029 "friend" ;C++
1030 "goto" ;K&R, C89
1031 "if" ;K&R, C89
1032 "imaginary" ;C9X macro
1033 "inline" ;C++, C9X, GCC
1034 "int" ;K&R, C89
1035 "long" ;K&R, C89
1036 "mutable" ;C++
1037 "namespace" ;C++
1038 "new" ;C++
1039 "operator" ;C++
1040 "or" ;C++
1041 "or_eq" ;C++
1042 "private" ;C++
1043 "protected" ;C++
1044 "public" ;C++
1045 "register" ;K&R, C89
1046 "reinterpret_cast" ;C++
1047 "restrict" ;C9X
1048 "return" ;K&R, C89
1049 "short" ;K&R, C89
1050 "signed" ;C89
1051 "sizeof" ;K&R, C89
1052 "static" ;K&R, C89
1053 "static_cast" ;C++
1054 "struct" ;K&R, C89
1055 "switch" ;K&R, C89
1056 "template" ;C++
1057 "this" ;C++
1058 "throw" ;C++
1059 "true" ;C++, C9X macro
1060 "try" ;C++
1061 "this" ;C++
1062 "typedef" ;C89
1063 "typeid" ;C++
1064 "typeof" ;GCC
1065 "typename" ;C++
1066 "union" ;K&R, C89
1067 "unsigned" ;K&R, C89
1068 "using" ;C++
1069 "virtual" ;C++
1070 "void" ;C89
1071 "volatile" ;C89
1072 "wchar_t" ;C++, C89 library type
1073 "while" ;K&R, C89
1074 "xor" ;C++
1075 "xor_eq" ;C++
1076 "_Bool" ;C9X
1077 "_Complex" ;C9X
1078 "_Imaginary" ;C9X
1079 "_Pragma" ;C9X preprocessor
1080 "__alignof__" ;GCC
1081 "__asm__" ;GCC
1082 "__attribute__" ;GCC
1083 "__complex__" ;GCC
1084 "__const__" ;GCC
1085 "__extension__" ;GCC
1086 "__imag__" ;GCC
1087 "__inline__" ;GCC
1088 "__label__" ;GCC
1089 "__real__" ;GCC
1090 "__signed__" ;GCC
1091 "__typeof__" ;GCC
1092 "__volatile__" ;GCC
1093 ))
1094 (preprocessor-keywords
1095 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1096 "ident" "if" "ifdef" "ifndef" "import" "include"
1097 "line" "pragma" "unassert" "undef" "warning"))
1098 (objc-keywords
1099 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1100 "interface" "private" "protected" "protocol" "public"
1101 "selector")))
1102
1103 (setq font-lock-keywords
1104 (list
1105
1106 ;; Fontify include files as strings.
1107 (list (concat "^[ \t]*\\#[ \t]*"
1108 "\\(include\\|import\\)"
1109 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1110 '(2 font-lock-string-face))
1111
1112 ;; Preprocessor directives are `references'?.
1113 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1114 preprocessor-keywords
1115 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1116 '(1 font-lock-keyword-face))
1117
1118 ;; Handle the keywords defined above.
1119 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1120 '(0 font-lock-keyword-face))
1121
1122 (list (concat "\\<\\(" c-keywords "\\)\\>")
1123 '(0 font-lock-keyword-face))
1124
1125 ;; Handle numbers too.
1126 ;;
1127 ;; This looks strange, I know. It corresponds to the
1128 ;; preprocessor's idea of what a number looks like, rather than
1129 ;; anything sensible.
1130 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1131 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1132 '(0 mdw-number-face))
1133
1134 ;; And anything else is punctuation.
1135 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1136 '(0 mdw-punct-face))))
1137
1138 (mdw-post-config-mode-hack)))
1139
1140 ;;;--------------------------------------------------------------------------
1141 ;;; AP calc mode.
1142
1143 (defun apcalc-mode ()
1144 (interactive)
1145 (c-mode)
1146 (setq major-mode 'apcalc-mode)
1147 (setq mode-name "AP Calc")
1148 (run-hooks 'apcalc-mode-hook))
1149
1150 (defun mdw-fontify-apcalc ()
1151
1152 ;; Fiddle with some syntax codes.
1153 (modify-syntax-entry ?* ". 23")
1154 (modify-syntax-entry ?/ ". 14")
1155
1156 ;; Other stuff.
1157 (mdw-c-style)
1158 (setq c-hanging-comment-ender-p nil)
1159 (setq c-backslash-column 72)
1160 (setq comment-start "/* ")
1161 (setq comment-end " */")
1162 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1163
1164 ;; Now define things to be fontified.
1165 (make-local-variable 'font-lock-keywords)
1166 (let ((c-keywords
1167 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1168 "do" "else" "exit" "for" "global" "goto" "help" "if"
1169 "local" "mat" "obj" "print" "quit" "read" "return"
1170 "show" "static" "switch" "while" "write")))
1171
1172 (setq font-lock-keywords
1173 (list
1174
1175 ;; Handle the keywords defined above.
1176 (list (concat "\\<\\(" c-keywords "\\)\\>")
1177 '(0 font-lock-keyword-face))
1178
1179 ;; Handle numbers too.
1180 ;;
1181 ;; This looks strange, I know. It corresponds to the
1182 ;; preprocessor's idea of what a number looks like, rather than
1183 ;; anything sensible.
1184 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1185 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1186 '(0 mdw-number-face))
1187
1188 ;; And anything else is punctuation.
1189 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1190 '(0 mdw-punct-face)))))
1191
1192 (mdw-post-config-mode-hack))
1193
1194 ;;;--------------------------------------------------------------------------
1195 ;;; Java programming configuration.
1196
1197 ;; Make indentation nice.
1198
1199 (defun mdw-java-style ()
1200 (c-add-style "[mdw] Java style"
1201 '((c-basic-offset . 2)
1202 (c-offsets-alist (substatement-open . 0)
1203 (label . +)
1204 (case-label . +)
1205 (access-label . 0)
1206 (inclass . +)
1207 (statement-case-intro . +)))
1208 t))
1209
1210 ;; Declare Java fontification style.
1211
1212 (defun mdw-fontify-java ()
1213
1214 ;; Other stuff.
1215 (mdw-java-style)
1216 (setq c-hanging-comment-ender-p nil)
1217 (setq c-backslash-column 72)
1218 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1219
1220 ;; Now define things to be fontified.
1221 (make-local-variable 'font-lock-keywords)
1222 (let ((java-keywords
1223 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1224 "char" "class" "const" "continue" "default" "do"
1225 "double" "else" "extends" "final" "finally" "float"
1226 "for" "goto" "if" "implements" "import" "instanceof"
1227 "int" "interface" "long" "native" "new" "package"
1228 "private" "protected" "public" "return" "short"
1229 "static" "super" "switch" "synchronized" "this"
1230 "throw" "throws" "transient" "try" "void" "volatile"
1231 "while"
1232
1233 "false" "null" "true")))
1234
1235 (setq font-lock-keywords
1236 (list
1237
1238 ;; Handle the keywords defined above.
1239 (list (concat "\\<\\(" java-keywords "\\)\\>")
1240 '(0 font-lock-keyword-face))
1241
1242 ;; Handle numbers too.
1243 ;;
1244 ;; The following isn't quite right, but it's close enough.
1245 (list (concat "\\<\\("
1246 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1247 "[0-9]+\\(\\.[0-9]*\\|\\)"
1248 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1249 "[lLfFdD]?")
1250 '(0 mdw-number-face))
1251
1252 ;; And anything else is punctuation.
1253 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1254 '(0 mdw-punct-face)))))
1255
1256 (mdw-post-config-mode-hack))
1257
1258 ;;;--------------------------------------------------------------------------
1259 ;;; C# programming configuration.
1260
1261 ;; Make indentation nice.
1262
1263 (defun mdw-csharp-style ()
1264 (c-add-style "[mdw] C# style"
1265 '((c-basic-offset . 2)
1266 (c-offsets-alist (substatement-open . 0)
1267 (label . 0)
1268 (case-label . +)
1269 (access-label . 0)
1270 (inclass . +)
1271 (statement-case-intro . +)))
1272 t))
1273
1274 ;; Declare C# fontification style.
1275
1276 (defun mdw-fontify-csharp ()
1277
1278 ;; Other stuff.
1279 (mdw-csharp-style)
1280 (setq c-hanging-comment-ender-p nil)
1281 (setq c-backslash-column 72)
1282 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1283
1284 ;; Now define things to be fontified.
1285 (make-local-variable 'font-lock-keywords)
1286 (let ((csharp-keywords
1287 (mdw-regexps "abstract" "as" "base" "bool" "break"
1288 "byte" "case" "catch" "char" "checked"
1289 "class" "const" "continue" "decimal" "default"
1290 "delegate" "do" "double" "else" "enum"
1291 "event" "explicit" "extern" "false" "finally"
1292 "fixed" "float" "for" "foreach" "goto"
1293 "if" "implicit" "in" "int" "interface"
1294 "internal" "is" "lock" "long" "namespace"
1295 "new" "null" "object" "operator" "out"
1296 "override" "params" "private" "protected" "public"
1297 "readonly" "ref" "return" "sbyte" "sealed"
1298 "short" "sizeof" "stackalloc" "static" "string"
1299 "struct" "switch" "this" "throw" "true"
1300 "try" "typeof" "uint" "ulong" "unchecked"
1301 "unsafe" "ushort" "using" "virtual" "void"
1302 "volatile" "while" "yield")))
1303
1304 (setq font-lock-keywords
1305 (list
1306
1307 ;; Handle the keywords defined above.
1308 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1309 '(0 font-lock-keyword-face))
1310
1311 ;; Handle numbers too.
1312 ;;
1313 ;; The following isn't quite right, but it's close enough.
1314 (list (concat "\\<\\("
1315 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1316 "[0-9]+\\(\\.[0-9]*\\|\\)"
1317 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1318 "[lLfFdD]?")
1319 '(0 mdw-number-face))
1320
1321 ;; And anything else is punctuation.
1322 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1323 '(0 mdw-punct-face)))))
1324
1325 (mdw-post-config-mode-hack))
1326
1327 (define-derived-mode csharp-mode java-mode "C#"
1328 "Major mode for editing C# code.")
1329
1330 ;;;--------------------------------------------------------------------------
1331 ;;; Go programming configuration.
1332
1333 (defun mdw-fontify-go ()
1334
1335 (make-local-variable 'font-lock-keywords)
1336 (let ((go-keywords
1337 (mdw-regexps "break" "case" "chan" "const" "continue"
1338 "default" "defer" "else" "fallthrough" "for"
1339 "func" "go" "goto" "if" "import"
1340 "interface" "map" "package" "range" "return"
1341 "select" "struct" "switch" "type" "var")))
1342
1343 (setq font-lock-keywords
1344 (list
1345
1346 ;; Handle the keywords defined above.
1347 (list (concat "\\<\\(" go-keywords "\\)\\>")
1348 '(0 font-lock-keyword-face))
1349
1350 ;; Handle numbers too.
1351 ;;
1352 ;; The following isn't quite right, but it's close enough.
1353 (list (concat "\\<\\("
1354 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1355 "[0-9]+\\(\\.[0-9]*\\|\\)"
1356 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1357 '(0 mdw-number-face))
1358
1359 ;; And anything else is punctuation.
1360 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1361 '(0 mdw-punct-face)))))
1362
1363 (mdw-post-config-mode-hack))
1364
1365 ;;;--------------------------------------------------------------------------
1366 ;;; Awk programming configuration.
1367
1368 ;; Make Awk indentation nice.
1369
1370 (defun mdw-awk-style ()
1371 (c-add-style "[mdw] Awk style"
1372 '((c-basic-offset . 2)
1373 (c-offsets-alist (substatement-open . 0)
1374 (statement-cont . 0)
1375 (statement-case-intro . +)))
1376 t))
1377
1378 ;; Declare Awk fontification style.
1379
1380 (defun mdw-fontify-awk ()
1381
1382 ;; Miscellaneous fiddling.
1383 (mdw-awk-style)
1384 (setq c-backslash-column 72)
1385 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1386
1387 ;; Now define things to be fontified.
1388 (make-local-variable 'font-lock-keywords)
1389 (let ((c-keywords
1390 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1391 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1392 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1393 "RSTART" "RLENGTH" "RT" "SUBSEP"
1394 "atan2" "break" "close" "continue" "cos" "delete"
1395 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1396 "function" "gensub" "getline" "gsub" "if" "in"
1397 "index" "int" "length" "log" "match" "next" "rand"
1398 "return" "print" "printf" "sin" "split" "sprintf"
1399 "sqrt" "srand" "strftime" "sub" "substr" "system"
1400 "systime" "tolower" "toupper" "while")))
1401
1402 (setq font-lock-keywords
1403 (list
1404
1405 ;; Handle the keywords defined above.
1406 (list (concat "\\<\\(" c-keywords "\\)\\>")
1407 '(0 font-lock-keyword-face))
1408
1409 ;; Handle numbers too.
1410 ;;
1411 ;; The following isn't quite right, but it's close enough.
1412 (list (concat "\\<\\("
1413 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1414 "[0-9]+\\(\\.[0-9]*\\|\\)"
1415 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1416 "[uUlL]*")
1417 '(0 mdw-number-face))
1418
1419 ;; And anything else is punctuation.
1420 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1421 '(0 mdw-punct-face)))))
1422
1423 (mdw-post-config-mode-hack))
1424
1425 ;;;--------------------------------------------------------------------------
1426 ;;; Perl programming style.
1427
1428 ;; Perl indentation style.
1429
1430 (setq cperl-indent-level 2)
1431 (setq cperl-continued-statement-offset 2)
1432 (setq cperl-continued-brace-offset 0)
1433 (setq cperl-brace-offset -2)
1434 (setq cperl-brace-imaginary-offset 0)
1435 (setq cperl-label-offset 0)
1436
1437 ;; Define perl fontification style.
1438
1439 (defun mdw-fontify-perl ()
1440
1441 ;; Miscellaneous fiddling.
1442 (modify-syntax-entry ?$ "\\")
1443 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1444 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1445
1446 ;; Now define fontification things.
1447 (make-local-variable 'font-lock-keywords)
1448 (let ((perl-keywords
1449 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1450 "for" "foreach" "ge" "gt" "goto" "if"
1451 "last" "le" "lt" "local" "my" "ne" "next" "or"
1452 "package" "redo" "require" "return" "sub"
1453 "undef" "unless" "until" "use" "while")))
1454
1455 (setq font-lock-keywords
1456 (list
1457
1458 ;; Set up the keywords defined above.
1459 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1460 '(0 font-lock-keyword-face))
1461
1462 ;; At least numbers are simpler than C.
1463 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1464 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1465 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1466 '(0 mdw-number-face))
1467
1468 ;; And anything else is punctuation.
1469 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1470 '(0 mdw-punct-face)))))
1471
1472 (mdw-post-config-mode-hack))
1473
1474 (defun perl-number-tests (&optional arg)
1475 "Assign consecutive numbers to lines containing `#t'. With ARG,
1476 strip numbers instead."
1477 (interactive "P")
1478 (save-excursion
1479 (goto-char (point-min))
1480 (let ((i 0) (fmt (if arg "" " %4d")))
1481 (while (search-forward "#t" nil t)
1482 (delete-region (point) (line-end-position))
1483 (setq i (1+ i))
1484 (insert (format fmt i)))
1485 (goto-char (point-min))
1486 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1487 (replace-match (format "\\1%d" i))))))
1488
1489 ;;;--------------------------------------------------------------------------
1490 ;;; Python programming style.
1491
1492 (defun mdw-fontify-pythonic (keywords)
1493
1494 ;; Miscellaneous fiddling.
1495 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1496
1497 ;; Now define fontification things.
1498 (make-local-variable 'font-lock-keywords)
1499 (setq font-lock-keywords
1500 (list
1501
1502 ;; Set up the keywords defined above.
1503 (list (concat "\\<\\(" keywords "\\)\\>")
1504 '(0 font-lock-keyword-face))
1505
1506 ;; At least numbers are simpler than C.
1507 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1508 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1509 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1510 '(0 mdw-number-face))
1511
1512 ;; And anything else is punctuation.
1513 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1514 '(0 mdw-punct-face))))
1515
1516 (mdw-post-config-mode-hack))
1517
1518 ;; Define Python fontification styles.
1519
1520 (defun mdw-fontify-python ()
1521 (mdw-fontify-pythonic
1522 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1523 "del" "elif" "else" "except" "exec" "finally" "for"
1524 "from" "global" "if" "import" "in" "is" "lambda"
1525 "not" "or" "pass" "print" "raise" "return" "try"
1526 "while" "with" "yield")))
1527
1528 (defun mdw-fontify-pyrex ()
1529 (mdw-fontify-pythonic
1530 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1531 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1532 "extern" "finally" "for" "from" "global" "if"
1533 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1534 "raise" "return" "struct" "try" "while" "with"
1535 "yield")))
1536
1537 ;;;--------------------------------------------------------------------------
1538 ;;; Icon programming style.
1539
1540 ;; Icon indentation style.
1541
1542 (setq icon-brace-offset 0
1543 icon-continued-brace-offset 0
1544 icon-continued-statement-offset 2
1545 icon-indent-level 2)
1546
1547 ;; Define Icon fontification style.
1548
1549 (defun mdw-fontify-icon ()
1550
1551 ;; Miscellaneous fiddling.
1552 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1553
1554 ;; Now define fontification things.
1555 (make-local-variable 'font-lock-keywords)
1556 (let ((icon-keywords
1557 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1558 "end" "every" "fail" "global" "if" "initial"
1559 "invocable" "link" "local" "next" "not" "of"
1560 "procedure" "record" "repeat" "return" "static"
1561 "suspend" "then" "to" "until" "while"))
1562 (preprocessor-keywords
1563 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1564 "include" "line" "undef")))
1565 (setq font-lock-keywords
1566 (list
1567
1568 ;; Set up the keywords defined above.
1569 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1570 '(0 font-lock-keyword-face))
1571
1572 ;; The things that Icon calls keywords.
1573 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1574
1575 ;; At least numbers are simpler than C.
1576 (list (concat "\\<[0-9]+"
1577 "\\([rR][0-9a-zA-Z]+\\|"
1578 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1579 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1580 '(0 mdw-number-face))
1581
1582 ;; Preprocessor.
1583 (list (concat "^[ \t]*$[ \t]*\\<\\("
1584 preprocessor-keywords
1585 "\\)\\>")
1586 '(0 font-lock-keyword-face))
1587
1588 ;; And anything else is punctuation.
1589 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1590 '(0 mdw-punct-face)))))
1591
1592 (mdw-post-config-mode-hack))
1593
1594 ;;;--------------------------------------------------------------------------
1595 ;;; ARM assembler programming configuration.
1596
1597 ;; There doesn't appear to be an Emacs mode for this yet.
1598 ;;
1599 ;; Better do something about that, I suppose.
1600
1601 (defvar arm-assembler-mode-map nil)
1602 (defvar arm-assembler-abbrev-table nil)
1603 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1604
1605 (or arm-assembler-mode-map
1606 (progn
1607 (setq arm-assembler-mode-map (make-sparse-keymap))
1608 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1609 (define-key arm-assembler-mode-map [C-return] 'newline)
1610 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1611
1612 (defun arm-assembler-mode ()
1613 "Major mode for ARM assembler programs"
1614 (interactive)
1615
1616 ;; Do standard major mode things.
1617 (kill-all-local-variables)
1618 (use-local-map arm-assembler-mode-map)
1619 (setq local-abbrev-table arm-assembler-abbrev-table)
1620 (setq major-mode 'arm-assembler-mode)
1621 (setq mode-name "ARM assembler")
1622
1623 ;; Set up syntax table.
1624 (set-syntax-table arm-assembler-mode-syntax-table)
1625 (modify-syntax-entry ?; ; Nasty hack
1626 "<" arm-assembler-mode-syntax-table)
1627 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1628 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1629
1630 (make-local-variable 'comment-start)
1631 (setq comment-start ";")
1632 (make-local-variable 'comment-end)
1633 (setq comment-end "")
1634 (make-local-variable 'comment-column)
1635 (setq comment-column 48)
1636 (make-local-variable 'comment-start-skip)
1637 (setq comment-start-skip ";+[ \t]*")
1638
1639 ;; Play with indentation.
1640 (make-local-variable 'indent-line-function)
1641 (setq indent-line-function 'indent-relative-maybe)
1642
1643 ;; Set fill prefix.
1644 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1645
1646 ;; Fiddle with fontification.
1647 (make-local-variable 'font-lock-keywords)
1648 (setq font-lock-keywords
1649 (list
1650
1651 ;; Handle numbers too.
1652 ;;
1653 ;; The following isn't quite right, but it's close enough.
1654 (list (concat "\\("
1655 "&[0-9a-fA-F]+\\|"
1656 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1657 "\\)")
1658 '(0 mdw-number-face))
1659
1660 ;; Do something about operators.
1661 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1662 '(1 font-lock-keyword-face)
1663 '(2 font-lock-string-face))
1664 (list ":[a-zA-Z]+:"
1665 '(0 font-lock-keyword-face))
1666
1667 ;; Do menemonics and directives.
1668 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1669 '(1 font-lock-keyword-face))
1670
1671 ;; And anything else is punctuation.
1672 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1673 '(0 mdw-punct-face)))
1674
1675 (mdw-post-config-mode-hack))
1676 (run-hooks 'arm-assembler-mode-hook))
1677
1678 ;;;--------------------------------------------------------------------------
1679 ;;; Assembler mode.
1680
1681 (defun mdw-fontify-asm ()
1682 (modify-syntax-entry ?' "\"")
1683 (modify-syntax-entry ?. "w")
1684 (setf fill-prefix nil)
1685 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1686
1687 ;;;--------------------------------------------------------------------------
1688 ;;; TCL configuration.
1689
1690 (defun mdw-fontify-tcl ()
1691 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1692 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1693 (make-local-variable 'font-lock-keywords)
1694 (setq font-lock-keywords
1695 (list
1696 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1697 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1698 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1699 '(0 mdw-number-face))
1700 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1701 '(0 mdw-punct-face))))
1702 (mdw-post-config-mode-hack))
1703
1704 ;;;--------------------------------------------------------------------------
1705 ;;; REXX configuration.
1706
1707 (defun mdw-rexx-electric-* ()
1708 (interactive)
1709 (insert ?*)
1710 (rexx-indent-line))
1711
1712 (defun mdw-rexx-indent-newline-indent ()
1713 (interactive)
1714 (rexx-indent-line)
1715 (if abbrev-mode (expand-abbrev))
1716 (newline-and-indent))
1717
1718 (defun mdw-fontify-rexx ()
1719
1720 ;; Various bits of fiddling.
1721 (setq mdw-auto-indent nil)
1722 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1723 (local-set-key [?*] 'mdw-rexx-electric-*)
1724 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1725 '(?! ?? ?# ?@ ?$))
1726 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1727
1728 ;; Set up keywords and things for fontification.
1729 (make-local-variable 'font-lock-keywords-case-fold-search)
1730 (setq font-lock-keywords-case-fold-search t)
1731
1732 (setq rexx-indent 2)
1733 (setq rexx-end-indent rexx-indent)
1734 (setq rexx-cont-indent rexx-indent)
1735
1736 (make-local-variable 'font-lock-keywords)
1737 (let ((rexx-keywords
1738 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1739 "else" "end" "engineering" "exit" "expose" "for"
1740 "forever" "form" "fuzz" "if" "interpret" "iterate"
1741 "leave" "linein" "name" "nop" "numeric" "off" "on"
1742 "options" "otherwise" "parse" "procedure" "pull"
1743 "push" "queue" "return" "say" "select" "signal"
1744 "scientific" "source" "then" "trace" "to" "until"
1745 "upper" "value" "var" "version" "when" "while"
1746 "with"
1747
1748 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1749 "center" "center" "charin" "charout" "chars"
1750 "compare" "condition" "copies" "c2d" "c2x"
1751 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1752 "errortext" "format" "fuzz" "insert" "lastpos"
1753 "left" "length" "lineout" "lines" "max" "min"
1754 "overlay" "pos" "queued" "random" "reverse" "right"
1755 "sign" "sourceline" "space" "stream" "strip"
1756 "substr" "subword" "symbol" "time" "translate"
1757 "trunc" "value" "verify" "word" "wordindex"
1758 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1759 "x2d")))
1760
1761 (setq font-lock-keywords
1762 (list
1763
1764 ;; Set up the keywords defined above.
1765 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1766 '(0 font-lock-keyword-face))
1767
1768 ;; Fontify all symbols the same way.
1769 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1770 "[A-Za-z0-9.!?_#@$]+\\)")
1771 '(0 font-lock-variable-name-face))
1772
1773 ;; And everything else is punctuation.
1774 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1775 '(0 mdw-punct-face)))))
1776
1777 (mdw-post-config-mode-hack))
1778
1779 ;;;--------------------------------------------------------------------------
1780 ;;; Standard ML programming style.
1781
1782 (defun mdw-fontify-sml ()
1783
1784 ;; Make underscore an honorary letter.
1785 (modify-syntax-entry ?' "w")
1786
1787 ;; Set fill prefix.
1788 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1789
1790 ;; Now define fontification things.
1791 (make-local-variable 'font-lock-keywords)
1792 (let ((sml-keywords
1793 (mdw-regexps "abstype" "and" "andalso" "as"
1794 "case"
1795 "datatype" "do"
1796 "else" "end" "eqtype" "exception"
1797 "fn" "fun" "functor"
1798 "handle"
1799 "if" "in" "include" "infix" "infixr"
1800 "let" "local"
1801 "nonfix"
1802 "of" "op" "open" "orelse"
1803 "raise" "rec"
1804 "sharing" "sig" "signature" "struct" "structure"
1805 "then" "type"
1806 "val"
1807 "where" "while" "with" "withtype")))
1808
1809 (setq font-lock-keywords
1810 (list
1811
1812 ;; Set up the keywords defined above.
1813 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1814 '(0 font-lock-keyword-face))
1815
1816 ;; At least numbers are simpler than C.
1817 (list (concat "\\<\\(\\~\\|\\)"
1818 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1819 "[wW][0-9]+\\)\\|"
1820 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1821 "\\([eE]\\(\\~\\|\\)"
1822 "[0-9]+\\|\\)\\)\\)")
1823 '(0 mdw-number-face))
1824
1825 ;; And anything else is punctuation.
1826 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1827 '(0 mdw-punct-face)))))
1828
1829 (mdw-post-config-mode-hack))
1830
1831 ;;;--------------------------------------------------------------------------
1832 ;;; Haskell configuration.
1833
1834 (defun mdw-fontify-haskell ()
1835
1836 ;; Fiddle with syntax table to get comments right.
1837 (modify-syntax-entry ?' "\"")
1838 (modify-syntax-entry ?- ". 123")
1839 (modify-syntax-entry ?{ ". 1b")
1840 (modify-syntax-entry ?} ". 4b")
1841 (modify-syntax-entry ?\n ">")
1842
1843 ;; Set fill prefix.
1844 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1845
1846 ;; Fiddle with fontification.
1847 (make-local-variable 'font-lock-keywords)
1848 (let ((haskell-keywords
1849 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1850 "deriving" "do" "else" "foreign" "hiding" "if"
1851 "import" "in" "infix" "infixl" "infixr" "instance"
1852 "let" "module" "newtype" "of" "qualified" "safe"
1853 "stdcall" "then" "type" "unsafe" "where")))
1854
1855 (setq font-lock-keywords
1856 (list
1857 (list "--.*$"
1858 '(0 font-lock-comment-face))
1859 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1860 '(0 font-lock-keyword-face))
1861 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1862 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1863 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1864 '(0 mdw-number-face))
1865 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1866 '(0 mdw-punct-face)))))
1867
1868 (mdw-post-config-mode-hack))
1869
1870 ;;;--------------------------------------------------------------------------
1871 ;;; Erlang configuration.
1872
1873 (setq erlang-electric-commannds
1874 '(erlang-electric-newline erlang-electric-semicolon))
1875
1876 (defun mdw-fontify-erlang ()
1877
1878 ;; Set fill prefix.
1879 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1880
1881 ;; Fiddle with fontification.
1882 (make-local-variable 'font-lock-keywords)
1883 (let ((erlang-keywords
1884 (mdw-regexps "after" "and" "andalso"
1885 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1886 "case" "catch" "cond"
1887 "div" "end" "fun" "if" "let" "not"
1888 "of" "or" "orelse"
1889 "query" "receive" "rem" "try" "when" "xor")))
1890
1891 (setq font-lock-keywords
1892 (list
1893 (list "%.*$"
1894 '(0 font-lock-comment-face))
1895 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1896 '(0 font-lock-keyword-face))
1897 (list (concat "^-\\sw+\\>")
1898 '(0 font-lock-keyword-face))
1899 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1900 '(0 mdw-number-face))
1901 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1902 '(0 mdw-punct-face)))))
1903
1904 (mdw-post-config-mode-hack))
1905
1906 ;;;--------------------------------------------------------------------------
1907 ;;; Texinfo configuration.
1908
1909 (defun mdw-fontify-texinfo ()
1910
1911 ;; Set fill prefix.
1912 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1913
1914 ;; Real fontification things.
1915 (make-local-variable 'font-lock-keywords)
1916 (setq font-lock-keywords
1917 (list
1918
1919 ;; Environment names are keywords.
1920 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1921 '(2 font-lock-keyword-face))
1922
1923 ;; Unmark escaped magic characters.
1924 (list "\\(@\\)\\([@{}]\\)"
1925 '(1 font-lock-keyword-face)
1926 '(2 font-lock-variable-name-face))
1927
1928 ;; Make sure we get comments properly.
1929 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1930 '(0 font-lock-comment-face))
1931
1932 ;; Command names are keywords.
1933 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1934 '(0 font-lock-keyword-face))
1935
1936 ;; Fontify TeX special characters as punctuation.
1937 (list "[{}]+"
1938 '(0 mdw-punct-face))))
1939
1940 (mdw-post-config-mode-hack))
1941
1942 ;;;--------------------------------------------------------------------------
1943 ;;; TeX and LaTeX configuration.
1944
1945 (defun mdw-fontify-tex ()
1946 (setq ispell-parser 'tex)
1947 (turn-on-reftex)
1948
1949 ;; Don't make maths into a string.
1950 (modify-syntax-entry ?$ ".")
1951 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1952 (local-set-key [?$] 'self-insert-command)
1953
1954 ;; Set fill prefix.
1955 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1956
1957 ;; Real fontification things.
1958 (make-local-variable 'font-lock-keywords)
1959 (setq font-lock-keywords
1960 (list
1961
1962 ;; Environment names are keywords.
1963 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1964 "{\\([^}\n]*\\)}")
1965 '(2 font-lock-keyword-face))
1966
1967 ;; Suspended environment names are keywords too.
1968 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1969 "{\\([^}\n]*\\)}")
1970 '(3 font-lock-keyword-face))
1971
1972 ;; Command names are keywords.
1973 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1974 '(0 font-lock-keyword-face))
1975
1976 ;; Handle @/.../ for italics.
1977 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
1978 ;; '(1 font-lock-keyword-face)
1979 ;; '(3 font-lock-keyword-face))
1980
1981 ;; Handle @*...* for boldness.
1982 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
1983 ;; '(1 font-lock-keyword-face)
1984 ;; '(3 font-lock-keyword-face))
1985
1986 ;; Handle @`...' for literal syntax things.
1987 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
1988 ;; '(1 font-lock-keyword-face)
1989 ;; '(3 font-lock-keyword-face))
1990
1991 ;; Handle @<...> for nonterminals.
1992 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
1993 ;; '(1 font-lock-keyword-face)
1994 ;; '(3 font-lock-keyword-face))
1995
1996 ;; Handle other @-commands.
1997 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
1998 ;; '(0 font-lock-keyword-face))
1999
2000 ;; Make sure we get comments properly.
2001 (list "%.*"
2002 '(0 font-lock-comment-face))
2003
2004 ;; Fontify TeX special characters as punctuation.
2005 (list "[$^_{}#&]"
2006 '(0 mdw-punct-face))))
2007
2008 (mdw-post-config-mode-hack))
2009
2010 ;;;--------------------------------------------------------------------------
2011 ;;; SGML hacking.
2012
2013 (defun mdw-sgml-mode ()
2014 (interactive)
2015 (sgml-mode)
2016 (mdw-standard-fill-prefix "")
2017 (make-variable-buffer-local 'sgml-delimiters)
2018 (setq sgml-delimiters
2019 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2020 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2021 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2022 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2023 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2024 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2025 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2026 "NULL" ""))
2027 (setq major-mode 'mdw-sgml-mode)
2028 (setq mode-name "[mdw] SGML")
2029 (run-hooks 'mdw-sgml-mode-hook))
2030
2031 ;;;--------------------------------------------------------------------------
2032 ;;; Shell scripts.
2033
2034 (defun mdw-setup-sh-script-mode ()
2035
2036 ;; Fetch the shell interpreter's name.
2037 (let ((shell-name sh-shell-file))
2038
2039 ;; Try reading the hash-bang line.
2040 (save-excursion
2041 (goto-char (point-min))
2042 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2043 (setq shell-name (match-string 1))))
2044
2045 ;; Now try to set the shell.
2046 ;;
2047 ;; Don't let `sh-set-shell' bugger up my script.
2048 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2049 (sh-set-shell shell-name)))
2050
2051 ;; Now enable my keys and the fontification.
2052 (mdw-misc-mode-config)
2053
2054 ;; Set the indentation level correctly.
2055 (setq sh-indentation 2)
2056 (setq sh-basic-offset 2))
2057
2058 ;;;--------------------------------------------------------------------------
2059 ;;; Emacs shell mode.
2060
2061 (defun mdw-eshell-prompt ()
2062 (let ((left "[") (right "]"))
2063 (when (= (user-uid) 0)
2064 (setq left "«" right "»"))
2065 (concat left
2066 (save-match-data
2067 (replace-regexp-in-string "\\..*$" "" (system-name)))
2068 " "
2069 (eshell/pwd)
2070 right)))
2071 (setq eshell-prompt-function 'mdw-eshell-prompt)
2072 (setq eshell-prompt-regexp "^\\[[^]]+\\]")
2073
2074 (mdw-define-face eshell-prompt (t :weight bold))
2075 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2076 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2077 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2078 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2079 (mdw-define-face eshell-ls-executable (t :weight bold))
2080 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2081 (mdw-define-face eshell-ls-readonly (t nil))
2082 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2083
2084 ;;;--------------------------------------------------------------------------
2085 ;;; Messages-file mode.
2086
2087 (defun messages-mode-guts ()
2088 (setq messages-mode-syntax-table (make-syntax-table))
2089 (set-syntax-table messages-mode-syntax-table)
2090 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2091 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2092 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2093 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2094 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2095 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2096 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2097 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2098 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2099 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2100 (make-local-variable 'comment-start)
2101 (make-local-variable 'comment-end)
2102 (make-local-variable 'indent-line-function)
2103 (setq indent-line-function 'indent-relative)
2104 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2105 (make-local-variable 'font-lock-defaults)
2106 (make-local-variable 'messages-mode-keywords)
2107 (let ((keywords
2108 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2109 "export" "enum" "fixed-octetstring" "flags"
2110 "harmless" "map" "nested" "optional"
2111 "optional-tagged" "package" "primitive"
2112 "primitive-nullfree" "relaxed[ \t]+enum"
2113 "set" "table" "tagged-optional" "union"
2114 "variadic" "vector" "version" "version-tag")))
2115 (setq messages-mode-keywords
2116 (list
2117 (list (concat "\\<\\(" keywords "\\)\\>:")
2118 '(0 font-lock-keyword-face))
2119 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2120 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2121 (0 font-lock-variable-name-face))
2122 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2123 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2124 (0 mdw-punct-face)))))
2125 (setq font-lock-defaults
2126 '(messages-mode-keywords nil nil nil nil))
2127 (run-hooks 'messages-file-hook))
2128
2129 (defun messages-mode ()
2130 (interactive)
2131 (fundamental-mode)
2132 (setq major-mode 'messages-mode)
2133 (setq mode-name "Messages")
2134 (messages-mode-guts)
2135 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2136 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2137 (setq comment-start "# ")
2138 (setq comment-end "")
2139 (turn-on-font-lock-if-enabled)
2140 (run-hooks 'messages-mode-hook))
2141
2142 (defun cpp-messages-mode ()
2143 (interactive)
2144 (fundamental-mode)
2145 (setq major-mode 'cpp-messages-mode)
2146 (setq mode-name "CPP Messages")
2147 (messages-mode-guts)
2148 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2149 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2150 (setq comment-start "/* ")
2151 (setq comment-end " */")
2152 (let ((preprocessor-keywords
2153 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2154 "ident" "if" "ifdef" "ifndef" "import" "include"
2155 "line" "pragma" "unassert" "undef" "warning")))
2156 (setq messages-mode-keywords
2157 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2158 "\\(include\\|import\\)"
2159 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2160 '(2 font-lock-string-face))
2161 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2162 preprocessor-keywords
2163 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2164 '(1 font-lock-keyword-face)))
2165 messages-mode-keywords)))
2166 (turn-on-font-lock-if-enabled)
2167 (run-hooks 'cpp-messages-mode-hook))
2168
2169 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2170 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2171 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2172
2173 ;;;--------------------------------------------------------------------------
2174 ;;; Messages-file mode.
2175
2176 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2177 "Face to use for subsittution directives.")
2178 (make-face 'mallow-driver-substitution-face)
2179 (defvar mallow-driver-text-face 'mallow-driver-text-face
2180 "Face to use for body text.")
2181 (make-face 'mallow-driver-text-face)
2182
2183 (defun mallow-driver-mode ()
2184 (interactive)
2185 (fundamental-mode)
2186 (setq major-mode 'mallow-driver-mode)
2187 (setq mode-name "Mallow driver")
2188 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2189 (set-syntax-table mallow-driver-mode-syntax-table)
2190 (make-local-variable 'comment-start)
2191 (make-local-variable 'comment-end)
2192 (make-local-variable 'indent-line-function)
2193 (setq indent-line-function 'indent-relative)
2194 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2195 (make-local-variable 'font-lock-defaults)
2196 (make-local-variable 'mallow-driver-mode-keywords)
2197 (let ((keywords
2198 (mdw-regexps "each" "divert" "file" "if"
2199 "perl" "set" "string" "type" "write")))
2200 (setq mallow-driver-mode-keywords
2201 (list
2202 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2203 '(0 font-lock-keyword-face))
2204 (list "^%\\s *\\(#.*\\|\\)$"
2205 '(0 font-lock-comment-face))
2206 (list "^%"
2207 '(0 font-lock-keyword-face))
2208 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2209 (list "\\${[^}]*}"
2210 '(0 mallow-driver-substitution-face t)))))
2211 (setq font-lock-defaults
2212 '(mallow-driver-mode-keywords nil nil nil nil))
2213 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2214 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2215 (setq comment-start "%# ")
2216 (setq comment-end "")
2217 (turn-on-font-lock-if-enabled)
2218 (run-hooks 'mallow-driver-mode-hook))
2219
2220 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2221
2222 ;;;--------------------------------------------------------------------------
2223 ;;; NFast debugs.
2224
2225 (defun nfast-debug-mode ()
2226 (interactive)
2227 (fundamental-mode)
2228 (setq major-mode 'nfast-debug-mode)
2229 (setq mode-name "NFast debug")
2230 (setq messages-mode-syntax-table (make-syntax-table))
2231 (set-syntax-table messages-mode-syntax-table)
2232 (make-local-variable 'font-lock-defaults)
2233 (make-local-variable 'nfast-debug-mode-keywords)
2234 (setq truncate-lines t)
2235 (setq nfast-debug-mode-keywords
2236 (list
2237 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2238 (0 font-lock-keyword-face))
2239 (list (concat "^[ \t]+\\(\\("
2240 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2241 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2242 "[ \t]+\\)*"
2243 "[0-9a-fA-F]+\\)[ \t]*$")
2244 '(0 mdw-number-face))
2245 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2246 (1 font-lock-keyword-face))
2247 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2248 (1 font-lock-warning-face))
2249 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2250 (1 nil))
2251 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2252 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2253 '(1 font-lock-keyword-face))
2254 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2255 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2256 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2257 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2258 (setq font-lock-defaults
2259 '(nfast-debug-mode-keywords nil nil nil nil))
2260 (turn-on-font-lock-if-enabled)
2261 (run-hooks 'nfast-debug-mode-hook))
2262
2263 ;;;--------------------------------------------------------------------------
2264 ;;; Other languages.
2265
2266 ;; Smalltalk.
2267
2268 (defun mdw-setup-smalltalk ()
2269 (and mdw-auto-indent
2270 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2271 (make-variable-buffer-local 'mdw-auto-indent)
2272 (setq mdw-auto-indent nil)
2273 (local-set-key "\C-i" 'smalltalk-reindent))
2274
2275 (defun mdw-fontify-smalltalk ()
2276 (make-local-variable 'font-lock-keywords)
2277 (setq font-lock-keywords
2278 (list
2279 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2280 '(0 font-lock-keyword-face))
2281 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2282 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2283 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2284 '(0 mdw-number-face))
2285 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2286 '(0 mdw-punct-face))))
2287 (mdw-post-config-mode-hack))
2288
2289 ;; Lispy languages.
2290
2291 ;; Unpleasant bodge.
2292 (unless (boundp 'slime-repl-mode-map)
2293 (setq slime-repl-mode-map (make-sparse-keymap)))
2294
2295 (defun mdw-indent-newline-and-indent ()
2296 (interactive)
2297 (indent-for-tab-command)
2298 (newline-and-indent))
2299
2300 (eval-after-load "cl-indent"
2301 '(progn
2302 (mapc #'(lambda (pair)
2303 (put (car pair)
2304 'common-lisp-indent-function
2305 (cdr pair)))
2306 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2307 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2308
2309 (defun mdw-common-lisp-indent ()
2310 (make-variable-buffer-local 'lisp-indent-function)
2311 (setq lisp-indent-function 'common-lisp-indent-function))
2312
2313 (setq lisp-simple-loop-indentation 2
2314 lisp-loop-keyword-indentation 6
2315 lisp-loop-forms-indentation 6)
2316
2317 (defun mdw-fontify-lispy ()
2318
2319 ;; Set fill prefix.
2320 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2321
2322 ;; Not much fontification needed.
2323 (make-local-variable 'font-lock-keywords)
2324 (setq font-lock-keywords
2325 (list
2326 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2327 '(0 mdw-punct-face))))
2328
2329 (mdw-post-config-mode-hack))
2330
2331 (defun comint-send-and-indent ()
2332 (interactive)
2333 (comint-send-input)
2334 (and mdw-auto-indent
2335 (indent-for-tab-command)))
2336
2337 (defun mdw-setup-m4 ()
2338 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2339
2340 ;;;--------------------------------------------------------------------------
2341 ;;; Text mode.
2342
2343 (defun mdw-text-mode ()
2344 (setq fill-column 72)
2345 (flyspell-mode t)
2346 (mdw-standard-fill-prefix
2347 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2348 (auto-fill-mode 1))
2349
2350 ;;;--------------------------------------------------------------------------
2351 ;;; Outline and hide/show modes.
2352
2353 (defun mdw-outline-collapse-all ()
2354 "Completely collapse everything in the entire buffer."
2355 (interactive)
2356 (save-excursion
2357 (goto-char (point-min))
2358 (while (< (point) (point-max))
2359 (hide-subtree)
2360 (forward-line))))
2361
2362 (setq hs-hide-comments-when-hiding-all nil)
2363
2364 (defadvice hs-hide-all (after hide-first-comment activate)
2365 (save-excursion (hs-hide-initial-comment-block)))
2366
2367 ;;;--------------------------------------------------------------------------
2368 ;;; Shell mode.
2369
2370 (defun mdw-sh-mode-setup ()
2371 (local-set-key [?\C-a] 'comint-bol)
2372 (add-hook 'comint-output-filter-functions
2373 'comint-watch-for-password-prompt))
2374
2375 (defun mdw-term-mode-setup ()
2376 (setq term-prompt-regexp shell-prompt-pattern)
2377 (make-local-variable 'mouse-yank-at-point)
2378 (make-local-variable 'transient-mark-mode)
2379 (setq mouse-yank-at-point t)
2380 (auto-fill-mode -1)
2381 (setq tab-width 8))
2382
2383 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2384 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2385 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2386 (defun term-send-meta-meta-something ()
2387 (interactive)
2388 (term-send-raw-string "\e\e")
2389 (term-send-raw))
2390 (eval-after-load 'term
2391 '(progn
2392 (define-key term-raw-map [?\e ?\e] nil)
2393 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2394 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2395 (define-key term-raw-map [M-right] 'term-send-meta-right)
2396 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2397 (define-key term-raw-map [M-left] 'term-send-meta-left)
2398 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2399
2400 ;;;--------------------------------------------------------------------------
2401 ;;; Inferior Emacs Lisp.
2402
2403 (setq comint-prompt-read-only t)
2404
2405 (eval-after-load "comint"
2406 '(progn
2407 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2408 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2409
2410 (eval-after-load "ielm"
2411 '(progn
2412 (define-key ielm-map "\C-w" 'comint-kill-region)
2413 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2414
2415 ;;;----- That's all, folks --------------------------------------------------
2416
2417 (provide 'dot-emacs)