el/dot-emacs.el: Fix `whitespace' hacking.
[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 (and (fboundp 'gtags-mode)
685 (gtags-mode))
686 (outline-minor-mode t)
687 (hs-minor-mode t)
688 (reveal-mode t)
689 (trap (turn-on-font-lock)))
690
691 (defun mdw-post-config-mode-hack ()
692 (let ((whitespace-style (remove 'trailing whitespace-style)))
693 (trap (whitespace-mode t))))
694
695 (eval-after-load 'gtags
696 '(progn
697 (dolist (key '([mouse-2] [mouse-3]))
698 (define-key gtags-mode-map key nil))
699 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
700 (define-key gtags-select-mode-map [C-S-mouse-2]
701 'gtags-select-tag-by-event)
702 (dolist (map (list gtags-mode-map gtags-select-mode-map))
703 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
704
705 ;; Backup file handling.
706
707 (defvar mdw-backup-disable-regexps nil
708 "*List of regular expressions: if a file name matches any of
709 these then the file is not backed up.")
710
711 (defun mdw-backup-enable-predicate (name)
712 "[mdw]'s default backup predicate.
713 Allows a backup if the standard predicate would allow it, and it
714 doesn't match any of the regular expressions in
715 `mdw-backup-disable-regexps'."
716 (and (normal-backup-enable-predicate name)
717 (let ((answer t) (list mdw-backup-disable-regexps))
718 (save-match-data
719 (while list
720 (if (string-match (car list) name)
721 (setq answer nil))
722 (setq list (cdr list)))
723 answer))))
724 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
725
726 ;; Frame cleanup.
727
728 (defun mdw-last-one-out-turn-off-the-lights (frame)
729 "Disconnect from an X display if this was the last frame on that display."
730 (let ((frame-display (frame-parameter frame 'display)))
731 (when (and frame-display
732 (eq window-system 'x)
733 (not (some (lambda (fr)
734 (message "checking frame %s" frame)
735 (and (not (eq fr frame))
736 (string= (frame-parameter fr 'display)
737 frame-display)
738 (progn "frame %s still uses us" nil)))
739 (frame-list))))
740 (message "turn out the lights")
741 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
742 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
743
744 ;;;--------------------------------------------------------------------------
745 ;;; General fontification.
746
747 (defmacro mdw-define-face (name &rest body)
748 "Define a face, and make sure it's actually set as the definition."
749 (declare (indent 1)
750 (debug 0))
751 `(progn
752 (make-face ',name)
753 (defvar ,name ',name)
754 (put ',name 'face-defface-spec ',body)
755 (face-spec-set ',name ',body nil)))
756
757 (mdw-define-face default
758 (((type w32)) :family "courier new" :height 85)
759 (((type x)) :family "6x13" :height 130)
760 (((type color)) :foreground "white" :background "black")
761 (t nil))
762 (mdw-define-face fixed-pitch
763 (((type w32)) :family "courier new" :height 85)
764 (((type x)) :family "6x13" :height 130)
765 (t :foreground "white" :background "black"))
766 (if (>= emacs-major-version 23)
767 (mdw-define-face variable-pitch
768 (((type x)) :family "sans" :height 100))
769 (mdw-define-face variable-pitch
770 (((type x)) :family "helvetica" :height 120)))
771 (mdw-define-face region
772 (((type tty) (class color)) :background "blue")
773 (((type tty) (class mono)) :inverse-video t)
774 (t :background "grey30"))
775 (mdw-define-face minibuffer-prompt
776 (t :weight bold))
777 (mdw-define-face mode-line
778 (((class color)) :foreground "blue" :background "yellow"
779 :box (:line-width 1 :style released-button))
780 (t :inverse-video t))
781 (mdw-define-face mode-line-inactive
782 (((class color)) :foreground "yellow" :background "blue"
783 :box (:line-width 1 :style released-button))
784 (t :inverse-video t))
785 (mdw-define-face scroll-bar
786 (t :foreground "black" :background "lightgrey"))
787 (mdw-define-face fringe
788 (t :foreground "yellow"))
789 (mdw-define-face show-paren-match
790 (((class color)) :background "darkgreen")
791 (t :underline t))
792 (mdw-define-face show-paren-mismatch
793 (((class color)) :background "red")
794 (t :inverse-video t))
795 (mdw-define-face highlight
796 (((class color)) :background "DarkSeaGreen4")
797 (t :inverse-video t))
798
799 (mdw-define-face holiday-face
800 (t :background "red"))
801 (mdw-define-face calendar-today-face
802 (t :foreground "yellow" :weight bold))
803
804 (mdw-define-face comint-highlight-prompt
805 (t :weight bold))
806 (mdw-define-face comint-highlight-input)
807
808 (mdw-define-face trailing-whitespace
809 (((class color)) :background "red")
810 (t :inverse-video t))
811 (mdw-define-face mdw-punct-face
812 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
813 (mdw-define-face mdw-number-face
814 (t :foreground "yellow"))
815 (mdw-define-face font-lock-function-name-face
816 (t :slant italic))
817 (mdw-define-face font-lock-keyword-face
818 (t :weight bold))
819 (mdw-define-face font-lock-constant-face
820 (t :slant italic))
821 (mdw-define-face font-lock-builtin-face
822 (t :weight bold))
823 (mdw-define-face font-lock-type-face
824 (t :weight bold :slant italic))
825 (mdw-define-face font-lock-reference-face
826 (t :weight bold))
827 (mdw-define-face font-lock-variable-name-face
828 (t :slant italic))
829 (mdw-define-face font-lock-comment-delimiter-face
830 (((class mono)) :weight bold)
831 (((type tty) (class color)) :foreground "green")
832 (t :slant italic :foreground "SeaGreen1"))
833 (mdw-define-face font-lock-comment-face
834 (((class mono)) :weight bold)
835 (((type tty) (class color)) :foreground "green")
836 (t :slant italic :foreground "SeaGreen1"))
837 (mdw-define-face font-lock-string-face
838 (((class mono)) :weight bold)
839 (((class color)) :foreground "SkyBlue1"))
840 (mdw-define-face message-separator
841 (t :background "red" :foreground "white" :weight bold))
842 (mdw-define-face message-cited-text
843 (default :slant italic)
844 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
845 (mdw-define-face message-header-cc
846 (default :weight bold)
847 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
848 (mdw-define-face message-header-newsgroups
849 (default :weight bold)
850 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
851 (mdw-define-face message-header-subject
852 (default :weight bold)
853 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
854 (mdw-define-face message-header-to
855 (default :weight bold)
856 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
857 (mdw-define-face message-header-xheader
858 (default :weight bold)
859 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
860 (mdw-define-face message-header-other
861 (default :weight bold)
862 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
863 (mdw-define-face message-header-name
864 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
865
866 (mdw-define-face diff-index
867 (t :weight bold))
868 (mdw-define-face diff-file-header
869 (t :weight bold))
870 (mdw-define-face diff-hunk-header
871 (t :foreground "SkyBlue1"))
872 (mdw-define-face diff-function
873 (t :foreground "SkyBlue1" :weight bold))
874 (mdw-define-face diff-header
875 (t :background "grey10"))
876 (mdw-define-face diff-added
877 (t :foreground "green"))
878 (mdw-define-face diff-removed
879 (t :foreground "red"))
880 (mdw-define-face diff-context)
881
882 (mdw-define-face erc-input-face
883 (t :foreground "red"))
884
885 (mdw-define-face woman-bold
886 (t :weight bold))
887 (mdw-define-face woman-italic
888 (t :slant italic))
889
890 (mdw-define-face p4-depot-added-face
891 (t :foreground "green"))
892 (mdw-define-face p4-depot-branch-op-face
893 (t :foreground "yellow"))
894 (mdw-define-face p4-depot-deleted-face
895 (t :foreground "red"))
896 (mdw-define-face p4-depot-unmapped-face
897 (t :foreground "SkyBlue1"))
898 (mdw-define-face p4-diff-change-face
899 (t :foreground "yellow"))
900 (mdw-define-face p4-diff-del-face
901 (t :foreground "red"))
902 (mdw-define-face p4-diff-file-face
903 (t :foreground "SkyBlue1"))
904 (mdw-define-face p4-diff-head-face
905 (t :background "grey10"))
906 (mdw-define-face p4-diff-ins-face
907 (t :foreground "green"))
908
909 (mdw-define-face whizzy-slice-face
910 (t :background "grey10"))
911 (mdw-define-face whizzy-error-face
912 (t :background "darkred"))
913
914 ;;;--------------------------------------------------------------------------
915 ;;; C programming configuration.
916
917 ;; Linux kernel hacking.
918
919 (defvar linux-c-mode-hook)
920
921 (defun linux-c-mode ()
922 (interactive)
923 (c-mode)
924 (setq major-mode 'linux-c-mode)
925 (setq mode-name "Linux C")
926 (run-hooks 'linux-c-mode-hook))
927
928 ;; Make C indentation nice.
929
930 (defun mdw-c-lineup-arglist (langelem)
931 "Hack for DWIMmery in c-lineup-arglist."
932 (if (save-excursion
933 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
934 0
935 (c-lineup-arglist langelem)))
936
937 (defun mdw-c-indent-extern-mumble (langelem)
938 "Indent `extern \"...\" {' lines."
939 (save-excursion
940 (back-to-indentation)
941 (if (looking-at
942 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
943 c-basic-offset
944 nil)))
945
946 (defun mdw-c-style ()
947 (c-add-style "[mdw] C and C++ style"
948 '((c-basic-offset . 2)
949 (comment-column . 40)
950 (c-class-key . "class")
951 (c-backslash-column . 72)
952 (c-offsets-alist
953 (substatement-open . (add 0 c-indent-one-line-block))
954 (defun-open . (add 0 c-indent-one-line-block))
955 (arglist-cont-nonempty . mdw-c-lineup-arglist)
956 (topmost-intro . mdw-c-indent-extern-mumble)
957 (cpp-define-intro . 0)
958 (inextern-lang . [0])
959 (label . 0)
960 (case-label . +)
961 (access-label . -)
962 (inclass . +)
963 (inline-open . ++)
964 (statement-cont . 0)
965 (statement-case-intro . +)))
966 t))
967
968 (defvar mdw-c-comment-fill-prefix
969 `((,(concat "\\([ \t]*/?\\)"
970 "\\(\*\\|//]\\)"
971 "\\([ \t]*\\)"
972 "\\([A-Za-z]+:[ \t]*\\)?"
973 mdw-hanging-indents)
974 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
975 "Fill prefix matching C comments (both kinds).")
976
977 (defun mdw-fontify-c-and-c++ ()
978
979 ;; Fiddle with some syntax codes.
980 (modify-syntax-entry ?* ". 23")
981 (modify-syntax-entry ?/ ". 124b")
982 (modify-syntax-entry ?\n "> b")
983
984 ;; Other stuff.
985 (mdw-c-style)
986 (setq c-hanging-comment-ender-p nil)
987 (setq c-backslash-column 72)
988 (setq c-label-minimum-indentation 0)
989 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
990
991 ;; Now define things to be fontified.
992 (make-local-variable 'font-lock-keywords)
993 (let ((c-keywords
994 (mdw-regexps "and" ;C++
995 "and_eq" ;C++
996 "asm" ;K&R, GCC
997 "auto" ;K&R, C89
998 "bitand" ;C++
999 "bitor" ;C++
1000 "bool" ;C++, C9X macro
1001 "break" ;K&R, C89
1002 "case" ;K&R, C89
1003 "catch" ;C++
1004 "char" ;K&R, C89
1005 "class" ;C++
1006 "complex" ;C9X macro, C++ template type
1007 "compl" ;C++
1008 "const" ;C89
1009 "const_cast" ;C++
1010 "continue" ;K&R, C89
1011 "defined" ;C89 preprocessor
1012 "default" ;K&R, C89
1013 "delete" ;C++
1014 "do" ;K&R, C89
1015 "double" ;K&R, C89
1016 "dynamic_cast" ;C++
1017 "else" ;K&R, C89
1018 ;; "entry" ;K&R -- never used
1019 "enum" ;C89
1020 "explicit" ;C++
1021 "export" ;C++
1022 "extern" ;K&R, C89
1023 "false" ;C++, C9X macro
1024 "float" ;K&R, C89
1025 "for" ;K&R, C89
1026 ;; "fortran" ;K&R
1027 "friend" ;C++
1028 "goto" ;K&R, C89
1029 "if" ;K&R, C89
1030 "imaginary" ;C9X macro
1031 "inline" ;C++, C9X, GCC
1032 "int" ;K&R, C89
1033 "long" ;K&R, C89
1034 "mutable" ;C++
1035 "namespace" ;C++
1036 "new" ;C++
1037 "operator" ;C++
1038 "or" ;C++
1039 "or_eq" ;C++
1040 "private" ;C++
1041 "protected" ;C++
1042 "public" ;C++
1043 "register" ;K&R, C89
1044 "reinterpret_cast" ;C++
1045 "restrict" ;C9X
1046 "return" ;K&R, C89
1047 "short" ;K&R, C89
1048 "signed" ;C89
1049 "sizeof" ;K&R, C89
1050 "static" ;K&R, C89
1051 "static_cast" ;C++
1052 "struct" ;K&R, C89
1053 "switch" ;K&R, C89
1054 "template" ;C++
1055 "this" ;C++
1056 "throw" ;C++
1057 "true" ;C++, C9X macro
1058 "try" ;C++
1059 "this" ;C++
1060 "typedef" ;C89
1061 "typeid" ;C++
1062 "typeof" ;GCC
1063 "typename" ;C++
1064 "union" ;K&R, C89
1065 "unsigned" ;K&R, C89
1066 "using" ;C++
1067 "virtual" ;C++
1068 "void" ;C89
1069 "volatile" ;C89
1070 "wchar_t" ;C++, C89 library type
1071 "while" ;K&R, C89
1072 "xor" ;C++
1073 "xor_eq" ;C++
1074 "_Bool" ;C9X
1075 "_Complex" ;C9X
1076 "_Imaginary" ;C9X
1077 "_Pragma" ;C9X preprocessor
1078 "__alignof__" ;GCC
1079 "__asm__" ;GCC
1080 "__attribute__" ;GCC
1081 "__complex__" ;GCC
1082 "__const__" ;GCC
1083 "__extension__" ;GCC
1084 "__imag__" ;GCC
1085 "__inline__" ;GCC
1086 "__label__" ;GCC
1087 "__real__" ;GCC
1088 "__signed__" ;GCC
1089 "__typeof__" ;GCC
1090 "__volatile__" ;GCC
1091 ))
1092 (preprocessor-keywords
1093 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1094 "ident" "if" "ifdef" "ifndef" "import" "include"
1095 "line" "pragma" "unassert" "undef" "warning"))
1096 (objc-keywords
1097 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1098 "interface" "private" "protected" "protocol" "public"
1099 "selector")))
1100
1101 (setq font-lock-keywords
1102 (list
1103
1104 ;; Fontify include files as strings.
1105 (list (concat "^[ \t]*\\#[ \t]*"
1106 "\\(include\\|import\\)"
1107 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1108 '(2 font-lock-string-face))
1109
1110 ;; Preprocessor directives are `references'?.
1111 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1112 preprocessor-keywords
1113 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1114 '(1 font-lock-keyword-face))
1115
1116 ;; Handle the keywords defined above.
1117 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1118 '(0 font-lock-keyword-face))
1119
1120 (list (concat "\\<\\(" c-keywords "\\)\\>")
1121 '(0 font-lock-keyword-face))
1122
1123 ;; Handle numbers too.
1124 ;;
1125 ;; This looks strange, I know. It corresponds to the
1126 ;; preprocessor's idea of what a number looks like, rather than
1127 ;; anything sensible.
1128 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1129 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1130 '(0 mdw-number-face))
1131
1132 ;; And anything else is punctuation.
1133 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1134 '(0 mdw-punct-face))))
1135
1136 (mdw-post-config-mode-hack)))
1137
1138 ;;;--------------------------------------------------------------------------
1139 ;;; AP calc mode.
1140
1141 (defun apcalc-mode ()
1142 (interactive)
1143 (c-mode)
1144 (setq major-mode 'apcalc-mode)
1145 (setq mode-name "AP Calc")
1146 (run-hooks 'apcalc-mode-hook))
1147
1148 (defun mdw-fontify-apcalc ()
1149
1150 ;; Fiddle with some syntax codes.
1151 (modify-syntax-entry ?* ". 23")
1152 (modify-syntax-entry ?/ ". 14")
1153
1154 ;; Other stuff.
1155 (mdw-c-style)
1156 (setq c-hanging-comment-ender-p nil)
1157 (setq c-backslash-column 72)
1158 (setq comment-start "/* ")
1159 (setq comment-end " */")
1160 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1161
1162 ;; Now define things to be fontified.
1163 (make-local-variable 'font-lock-keywords)
1164 (let ((c-keywords
1165 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1166 "do" "else" "exit" "for" "global" "goto" "help" "if"
1167 "local" "mat" "obj" "print" "quit" "read" "return"
1168 "show" "static" "switch" "while" "write")))
1169
1170 (setq font-lock-keywords
1171 (list
1172
1173 ;; Handle the keywords defined above.
1174 (list (concat "\\<\\(" c-keywords "\\)\\>")
1175 '(0 font-lock-keyword-face))
1176
1177 ;; Handle numbers too.
1178 ;;
1179 ;; This looks strange, I know. It corresponds to the
1180 ;; preprocessor's idea of what a number looks like, rather than
1181 ;; anything sensible.
1182 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1183 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1184 '(0 mdw-number-face))
1185
1186 ;; And anything else is punctuation.
1187 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1188 '(0 mdw-punct-face)))))
1189
1190 (mdw-post-config-mode-hack))
1191
1192 ;;;--------------------------------------------------------------------------
1193 ;;; Java programming configuration.
1194
1195 ;; Make indentation nice.
1196
1197 (defun mdw-java-style ()
1198 (c-add-style "[mdw] Java style"
1199 '((c-basic-offset . 2)
1200 (c-offsets-alist (substatement-open . 0)
1201 (label . +)
1202 (case-label . +)
1203 (access-label . 0)
1204 (inclass . +)
1205 (statement-case-intro . +)))
1206 t))
1207
1208 ;; Declare Java fontification style.
1209
1210 (defun mdw-fontify-java ()
1211
1212 ;; Other stuff.
1213 (mdw-java-style)
1214 (setq c-hanging-comment-ender-p nil)
1215 (setq c-backslash-column 72)
1216 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1217
1218 ;; Now define things to be fontified.
1219 (make-local-variable 'font-lock-keywords)
1220 (let ((java-keywords
1221 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1222 "char" "class" "const" "continue" "default" "do"
1223 "double" "else" "extends" "final" "finally" "float"
1224 "for" "goto" "if" "implements" "import" "instanceof"
1225 "int" "interface" "long" "native" "new" "package"
1226 "private" "protected" "public" "return" "short"
1227 "static" "super" "switch" "synchronized" "this"
1228 "throw" "throws" "transient" "try" "void" "volatile"
1229 "while"
1230
1231 "false" "null" "true")))
1232
1233 (setq font-lock-keywords
1234 (list
1235
1236 ;; Handle the keywords defined above.
1237 (list (concat "\\<\\(" java-keywords "\\)\\>")
1238 '(0 font-lock-keyword-face))
1239
1240 ;; Handle numbers too.
1241 ;;
1242 ;; The following isn't quite right, but it's close enough.
1243 (list (concat "\\<\\("
1244 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1245 "[0-9]+\\(\\.[0-9]*\\|\\)"
1246 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1247 "[lLfFdD]?")
1248 '(0 mdw-number-face))
1249
1250 ;; And anything else is punctuation.
1251 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1252 '(0 mdw-punct-face)))))
1253
1254 (mdw-post-config-mode-hack))
1255
1256 ;;;--------------------------------------------------------------------------
1257 ;;; C# programming configuration.
1258
1259 ;; Make indentation nice.
1260
1261 (defun mdw-csharp-style ()
1262 (c-add-style "[mdw] C# style"
1263 '((c-basic-offset . 2)
1264 (c-offsets-alist (substatement-open . 0)
1265 (label . 0)
1266 (case-label . +)
1267 (access-label . 0)
1268 (inclass . +)
1269 (statement-case-intro . +)))
1270 t))
1271
1272 ;; Declare C# fontification style.
1273
1274 (defun mdw-fontify-csharp ()
1275
1276 ;; Other stuff.
1277 (mdw-csharp-style)
1278 (setq c-hanging-comment-ender-p nil)
1279 (setq c-backslash-column 72)
1280 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1281
1282 ;; Now define things to be fontified.
1283 (make-local-variable 'font-lock-keywords)
1284 (let ((csharp-keywords
1285 (mdw-regexps "abstract" "as" "base" "bool" "break"
1286 "byte" "case" "catch" "char" "checked"
1287 "class" "const" "continue" "decimal" "default"
1288 "delegate" "do" "double" "else" "enum"
1289 "event" "explicit" "extern" "false" "finally"
1290 "fixed" "float" "for" "foreach" "goto"
1291 "if" "implicit" "in" "int" "interface"
1292 "internal" "is" "lock" "long" "namespace"
1293 "new" "null" "object" "operator" "out"
1294 "override" "params" "private" "protected" "public"
1295 "readonly" "ref" "return" "sbyte" "sealed"
1296 "short" "sizeof" "stackalloc" "static" "string"
1297 "struct" "switch" "this" "throw" "true"
1298 "try" "typeof" "uint" "ulong" "unchecked"
1299 "unsafe" "ushort" "using" "virtual" "void"
1300 "volatile" "while" "yield")))
1301
1302 (setq font-lock-keywords
1303 (list
1304
1305 ;; Handle the keywords defined above.
1306 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1307 '(0 font-lock-keyword-face))
1308
1309 ;; Handle numbers too.
1310 ;;
1311 ;; The following isn't quite right, but it's close enough.
1312 (list (concat "\\<\\("
1313 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1314 "[0-9]+\\(\\.[0-9]*\\|\\)"
1315 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1316 "[lLfFdD]?")
1317 '(0 mdw-number-face))
1318
1319 ;; And anything else is punctuation.
1320 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1321 '(0 mdw-punct-face)))))
1322
1323 (mdw-post-config-mode-hack))
1324
1325 (define-derived-mode csharp-mode java-mode "C#"
1326 "Major mode for editing C# code.")
1327
1328 ;;;--------------------------------------------------------------------------
1329 ;;; Go programming configuration.
1330
1331 (defun mdw-fontify-go ()
1332
1333 (make-local-variable 'font-lock-keywords)
1334 (let ((go-keywords
1335 (mdw-regexps "break" "case" "chan" "const" "continue"
1336 "default" "defer" "else" "fallthrough" "for"
1337 "func" "go" "goto" "if" "import"
1338 "interface" "map" "package" "range" "return"
1339 "select" "struct" "switch" "type" "var")))
1340
1341 (setq font-lock-keywords
1342 (list
1343
1344 ;; Handle the keywords defined above.
1345 (list (concat "\\<\\(" go-keywords "\\)\\>")
1346 '(0 font-lock-keyword-face))
1347
1348 ;; Handle numbers too.
1349 ;;
1350 ;; The following isn't quite right, but it's close enough.
1351 (list (concat "\\<\\("
1352 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1353 "[0-9]+\\(\\.[0-9]*\\|\\)"
1354 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1355 '(0 mdw-number-face))
1356
1357 ;; And anything else is punctuation.
1358 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1359 '(0 mdw-punct-face)))))
1360
1361 (mdw-post-config-mode-hack))
1362
1363 ;;;--------------------------------------------------------------------------
1364 ;;; Awk programming configuration.
1365
1366 ;; Make Awk indentation nice.
1367
1368 (defun mdw-awk-style ()
1369 (c-add-style "[mdw] Awk style"
1370 '((c-basic-offset . 2)
1371 (c-offsets-alist (substatement-open . 0)
1372 (statement-cont . 0)
1373 (statement-case-intro . +)))
1374 t))
1375
1376 ;; Declare Awk fontification style.
1377
1378 (defun mdw-fontify-awk ()
1379
1380 ;; Miscellaneous fiddling.
1381 (mdw-awk-style)
1382 (setq c-backslash-column 72)
1383 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1384
1385 ;; Now define things to be fontified.
1386 (make-local-variable 'font-lock-keywords)
1387 (let ((c-keywords
1388 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1389 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1390 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1391 "RSTART" "RLENGTH" "RT" "SUBSEP"
1392 "atan2" "break" "close" "continue" "cos" "delete"
1393 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1394 "function" "gensub" "getline" "gsub" "if" "in"
1395 "index" "int" "length" "log" "match" "next" "rand"
1396 "return" "print" "printf" "sin" "split" "sprintf"
1397 "sqrt" "srand" "strftime" "sub" "substr" "system"
1398 "systime" "tolower" "toupper" "while")))
1399
1400 (setq font-lock-keywords
1401 (list
1402
1403 ;; Handle the keywords defined above.
1404 (list (concat "\\<\\(" c-keywords "\\)\\>")
1405 '(0 font-lock-keyword-face))
1406
1407 ;; Handle numbers too.
1408 ;;
1409 ;; The following isn't quite right, but it's close enough.
1410 (list (concat "\\<\\("
1411 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1412 "[0-9]+\\(\\.[0-9]*\\|\\)"
1413 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1414 "[uUlL]*")
1415 '(0 mdw-number-face))
1416
1417 ;; And anything else is punctuation.
1418 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1419 '(0 mdw-punct-face)))))
1420
1421 (mdw-post-config-mode-hack))
1422
1423 ;;;--------------------------------------------------------------------------
1424 ;;; Perl programming style.
1425
1426 ;; Perl indentation style.
1427
1428 (setq cperl-indent-level 2)
1429 (setq cperl-continued-statement-offset 2)
1430 (setq cperl-continued-brace-offset 0)
1431 (setq cperl-brace-offset -2)
1432 (setq cperl-brace-imaginary-offset 0)
1433 (setq cperl-label-offset 0)
1434
1435 ;; Define perl fontification style.
1436
1437 (defun mdw-fontify-perl ()
1438
1439 ;; Miscellaneous fiddling.
1440 (modify-syntax-entry ?$ "\\")
1441 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1442 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1443
1444 ;; Now define fontification things.
1445 (make-local-variable 'font-lock-keywords)
1446 (let ((perl-keywords
1447 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1448 "for" "foreach" "ge" "gt" "goto" "if"
1449 "last" "le" "lt" "local" "my" "ne" "next" "or"
1450 "package" "redo" "require" "return" "sub"
1451 "undef" "unless" "until" "use" "while")))
1452
1453 (setq font-lock-keywords
1454 (list
1455
1456 ;; Set up the keywords defined above.
1457 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1458 '(0 font-lock-keyword-face))
1459
1460 ;; At least numbers are simpler than C.
1461 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1462 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1463 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1464 '(0 mdw-number-face))
1465
1466 ;; And anything else is punctuation.
1467 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1468 '(0 mdw-punct-face)))))
1469
1470 (mdw-post-config-mode-hack))
1471
1472 (defun perl-number-tests (&optional arg)
1473 "Assign consecutive numbers to lines containing `#t'. With ARG,
1474 strip numbers instead."
1475 (interactive "P")
1476 (save-excursion
1477 (goto-char (point-min))
1478 (let ((i 0) (fmt (if arg "" " %4d")))
1479 (while (search-forward "#t" nil t)
1480 (delete-region (point) (line-end-position))
1481 (setq i (1+ i))
1482 (insert (format fmt i)))
1483 (goto-char (point-min))
1484 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1485 (replace-match (format "\\1%d" i))))))
1486
1487 ;;;--------------------------------------------------------------------------
1488 ;;; Python programming style.
1489
1490 (defun mdw-fontify-pythonic (keywords)
1491
1492 ;; Miscellaneous fiddling.
1493 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1494
1495 ;; Now define fontification things.
1496 (make-local-variable 'font-lock-keywords)
1497 (setq font-lock-keywords
1498 (list
1499
1500 ;; Set up the keywords defined above.
1501 (list (concat "\\<\\(" keywords "\\)\\>")
1502 '(0 font-lock-keyword-face))
1503
1504 ;; At least numbers are simpler than C.
1505 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1506 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1507 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1508 '(0 mdw-number-face))
1509
1510 ;; And anything else is punctuation.
1511 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1512 '(0 mdw-punct-face))))
1513
1514 (mdw-post-config-mode-hack))
1515
1516 ;; Define Python fontification styles.
1517
1518 (defun mdw-fontify-python ()
1519 (mdw-fontify-pythonic
1520 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1521 "del" "elif" "else" "except" "exec" "finally" "for"
1522 "from" "global" "if" "import" "in" "is" "lambda"
1523 "not" "or" "pass" "print" "raise" "return" "try"
1524 "while" "with" "yield")))
1525
1526 (defun mdw-fontify-pyrex ()
1527 (mdw-fontify-pythonic
1528 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1529 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1530 "extern" "finally" "for" "from" "global" "if"
1531 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1532 "raise" "return" "struct" "try" "while" "with"
1533 "yield")))
1534
1535 ;;;--------------------------------------------------------------------------
1536 ;;; Icon programming style.
1537
1538 ;; Icon indentation style.
1539
1540 (setq icon-brace-offset 0
1541 icon-continued-brace-offset 0
1542 icon-continued-statement-offset 2
1543 icon-indent-level 2)
1544
1545 ;; Define Icon fontification style.
1546
1547 (defun mdw-fontify-icon ()
1548
1549 ;; Miscellaneous fiddling.
1550 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1551
1552 ;; Now define fontification things.
1553 (make-local-variable 'font-lock-keywords)
1554 (let ((icon-keywords
1555 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1556 "end" "every" "fail" "global" "if" "initial"
1557 "invocable" "link" "local" "next" "not" "of"
1558 "procedure" "record" "repeat" "return" "static"
1559 "suspend" "then" "to" "until" "while"))
1560 (preprocessor-keywords
1561 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1562 "include" "line" "undef")))
1563 (setq font-lock-keywords
1564 (list
1565
1566 ;; Set up the keywords defined above.
1567 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1568 '(0 font-lock-keyword-face))
1569
1570 ;; The things that Icon calls keywords.
1571 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1572
1573 ;; At least numbers are simpler than C.
1574 (list (concat "\\<[0-9]+"
1575 "\\([rR][0-9a-zA-Z]+\\|"
1576 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1577 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1578 '(0 mdw-number-face))
1579
1580 ;; Preprocessor.
1581 (list (concat "^[ \t]*$[ \t]*\\<\\("
1582 preprocessor-keywords
1583 "\\)\\>")
1584 '(0 font-lock-keyword-face))
1585
1586 ;; And anything else is punctuation.
1587 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1588 '(0 mdw-punct-face)))))
1589
1590 (mdw-post-config-mode-hack))
1591
1592 ;;;--------------------------------------------------------------------------
1593 ;;; ARM assembler programming configuration.
1594
1595 ;; There doesn't appear to be an Emacs mode for this yet.
1596 ;;
1597 ;; Better do something about that, I suppose.
1598
1599 (defvar arm-assembler-mode-map nil)
1600 (defvar arm-assembler-abbrev-table nil)
1601 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1602
1603 (or arm-assembler-mode-map
1604 (progn
1605 (setq arm-assembler-mode-map (make-sparse-keymap))
1606 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1607 (define-key arm-assembler-mode-map [C-return] 'newline)
1608 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1609
1610 (defun arm-assembler-mode ()
1611 "Major mode for ARM assembler programs"
1612 (interactive)
1613
1614 ;; Do standard major mode things.
1615 (kill-all-local-variables)
1616 (use-local-map arm-assembler-mode-map)
1617 (setq local-abbrev-table arm-assembler-abbrev-table)
1618 (setq major-mode 'arm-assembler-mode)
1619 (setq mode-name "ARM assembler")
1620
1621 ;; Set up syntax table.
1622 (set-syntax-table arm-assembler-mode-syntax-table)
1623 (modify-syntax-entry ?; ; Nasty hack
1624 "<" arm-assembler-mode-syntax-table)
1625 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1626 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1627
1628 (make-local-variable 'comment-start)
1629 (setq comment-start ";")
1630 (make-local-variable 'comment-end)
1631 (setq comment-end "")
1632 (make-local-variable 'comment-column)
1633 (setq comment-column 48)
1634 (make-local-variable 'comment-start-skip)
1635 (setq comment-start-skip ";+[ \t]*")
1636
1637 ;; Play with indentation.
1638 (make-local-variable 'indent-line-function)
1639 (setq indent-line-function 'indent-relative-maybe)
1640
1641 ;; Set fill prefix.
1642 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1643
1644 ;; Fiddle with fontification.
1645 (make-local-variable 'font-lock-keywords)
1646 (setq font-lock-keywords
1647 (list
1648
1649 ;; Handle numbers too.
1650 ;;
1651 ;; The following isn't quite right, but it's close enough.
1652 (list (concat "\\("
1653 "&[0-9a-fA-F]+\\|"
1654 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1655 "\\)")
1656 '(0 mdw-number-face))
1657
1658 ;; Do something about operators.
1659 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1660 '(1 font-lock-keyword-face)
1661 '(2 font-lock-string-face))
1662 (list ":[a-zA-Z]+:"
1663 '(0 font-lock-keyword-face))
1664
1665 ;; Do menemonics and directives.
1666 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1667 '(1 font-lock-keyword-face))
1668
1669 ;; And anything else is punctuation.
1670 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1671 '(0 mdw-punct-face)))
1672
1673 (mdw-post-config-mode-hack))
1674 (run-hooks 'arm-assembler-mode-hook))
1675
1676 ;;;--------------------------------------------------------------------------
1677 ;;; Assembler mode.
1678
1679 (defun mdw-fontify-asm ()
1680 (modify-syntax-entry ?' "\"")
1681 (modify-syntax-entry ?. "w")
1682 (setf fill-prefix nil)
1683 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1684
1685 ;;;--------------------------------------------------------------------------
1686 ;;; TCL configuration.
1687
1688 (defun mdw-fontify-tcl ()
1689 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1690 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1691 (make-local-variable 'font-lock-keywords)
1692 (setq font-lock-keywords
1693 (list
1694 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1695 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1696 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1697 '(0 mdw-number-face))
1698 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1699 '(0 mdw-punct-face))))
1700 (mdw-post-config-mode-hack))
1701
1702 ;;;--------------------------------------------------------------------------
1703 ;;; REXX configuration.
1704
1705 (defun mdw-rexx-electric-* ()
1706 (interactive)
1707 (insert ?*)
1708 (rexx-indent-line))
1709
1710 (defun mdw-rexx-indent-newline-indent ()
1711 (interactive)
1712 (rexx-indent-line)
1713 (if abbrev-mode (expand-abbrev))
1714 (newline-and-indent))
1715
1716 (defun mdw-fontify-rexx ()
1717
1718 ;; Various bits of fiddling.
1719 (setq mdw-auto-indent nil)
1720 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1721 (local-set-key [?*] 'mdw-rexx-electric-*)
1722 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1723 '(?! ?? ?# ?@ ?$))
1724 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1725
1726 ;; Set up keywords and things for fontification.
1727 (make-local-variable 'font-lock-keywords-case-fold-search)
1728 (setq font-lock-keywords-case-fold-search t)
1729
1730 (setq rexx-indent 2)
1731 (setq rexx-end-indent rexx-indent)
1732 (setq rexx-cont-indent rexx-indent)
1733
1734 (make-local-variable 'font-lock-keywords)
1735 (let ((rexx-keywords
1736 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1737 "else" "end" "engineering" "exit" "expose" "for"
1738 "forever" "form" "fuzz" "if" "interpret" "iterate"
1739 "leave" "linein" "name" "nop" "numeric" "off" "on"
1740 "options" "otherwise" "parse" "procedure" "pull"
1741 "push" "queue" "return" "say" "select" "signal"
1742 "scientific" "source" "then" "trace" "to" "until"
1743 "upper" "value" "var" "version" "when" "while"
1744 "with"
1745
1746 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1747 "center" "center" "charin" "charout" "chars"
1748 "compare" "condition" "copies" "c2d" "c2x"
1749 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1750 "errortext" "format" "fuzz" "insert" "lastpos"
1751 "left" "length" "lineout" "lines" "max" "min"
1752 "overlay" "pos" "queued" "random" "reverse" "right"
1753 "sign" "sourceline" "space" "stream" "strip"
1754 "substr" "subword" "symbol" "time" "translate"
1755 "trunc" "value" "verify" "word" "wordindex"
1756 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1757 "x2d")))
1758
1759 (setq font-lock-keywords
1760 (list
1761
1762 ;; Set up the keywords defined above.
1763 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1764 '(0 font-lock-keyword-face))
1765
1766 ;; Fontify all symbols the same way.
1767 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1768 "[A-Za-z0-9.!?_#@$]+\\)")
1769 '(0 font-lock-variable-name-face))
1770
1771 ;; And everything else is punctuation.
1772 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1773 '(0 mdw-punct-face)))))
1774
1775 (mdw-post-config-mode-hack))
1776
1777 ;;;--------------------------------------------------------------------------
1778 ;;; Standard ML programming style.
1779
1780 (defun mdw-fontify-sml ()
1781
1782 ;; Make underscore an honorary letter.
1783 (modify-syntax-entry ?' "w")
1784
1785 ;; Set fill prefix.
1786 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1787
1788 ;; Now define fontification things.
1789 (make-local-variable 'font-lock-keywords)
1790 (let ((sml-keywords
1791 (mdw-regexps "abstype" "and" "andalso" "as"
1792 "case"
1793 "datatype" "do"
1794 "else" "end" "eqtype" "exception"
1795 "fn" "fun" "functor"
1796 "handle"
1797 "if" "in" "include" "infix" "infixr"
1798 "let" "local"
1799 "nonfix"
1800 "of" "op" "open" "orelse"
1801 "raise" "rec"
1802 "sharing" "sig" "signature" "struct" "structure"
1803 "then" "type"
1804 "val"
1805 "where" "while" "with" "withtype")))
1806
1807 (setq font-lock-keywords
1808 (list
1809
1810 ;; Set up the keywords defined above.
1811 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1812 '(0 font-lock-keyword-face))
1813
1814 ;; At least numbers are simpler than C.
1815 (list (concat "\\<\\(\\~\\|\\)"
1816 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1817 "[wW][0-9]+\\)\\|"
1818 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1819 "\\([eE]\\(\\~\\|\\)"
1820 "[0-9]+\\|\\)\\)\\)")
1821 '(0 mdw-number-face))
1822
1823 ;; And anything else is punctuation.
1824 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1825 '(0 mdw-punct-face)))))
1826
1827 (mdw-post-config-mode-hack))
1828
1829 ;;;--------------------------------------------------------------------------
1830 ;;; Haskell configuration.
1831
1832 (defun mdw-fontify-haskell ()
1833
1834 ;; Fiddle with syntax table to get comments right.
1835 (modify-syntax-entry ?' "\"")
1836 (modify-syntax-entry ?- ". 123")
1837 (modify-syntax-entry ?{ ". 1b")
1838 (modify-syntax-entry ?} ". 4b")
1839 (modify-syntax-entry ?\n ">")
1840
1841 ;; Set fill prefix.
1842 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1843
1844 ;; Fiddle with fontification.
1845 (make-local-variable 'font-lock-keywords)
1846 (let ((haskell-keywords
1847 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1848 "deriving" "do" "else" "foreign" "hiding" "if"
1849 "import" "in" "infix" "infixl" "infixr" "instance"
1850 "let" "module" "newtype" "of" "qualified" "safe"
1851 "stdcall" "then" "type" "unsafe" "where")))
1852
1853 (setq font-lock-keywords
1854 (list
1855 (list "--.*$"
1856 '(0 font-lock-comment-face))
1857 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1858 '(0 font-lock-keyword-face))
1859 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1860 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1861 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1862 '(0 mdw-number-face))
1863 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1864 '(0 mdw-punct-face)))))
1865
1866 (mdw-post-config-mode-hack))
1867
1868 ;;;--------------------------------------------------------------------------
1869 ;;; Erlang configuration.
1870
1871 (setq erlang-electric-commannds
1872 '(erlang-electric-newline erlang-electric-semicolon))
1873
1874 (defun mdw-fontify-erlang ()
1875
1876 ;; Set fill prefix.
1877 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1878
1879 ;; Fiddle with fontification.
1880 (make-local-variable 'font-lock-keywords)
1881 (let ((erlang-keywords
1882 (mdw-regexps "after" "and" "andalso"
1883 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1884 "case" "catch" "cond"
1885 "div" "end" "fun" "if" "let" "not"
1886 "of" "or" "orelse"
1887 "query" "receive" "rem" "try" "when" "xor")))
1888
1889 (setq font-lock-keywords
1890 (list
1891 (list "%.*$"
1892 '(0 font-lock-comment-face))
1893 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1894 '(0 font-lock-keyword-face))
1895 (list (concat "^-\\sw+\\>")
1896 '(0 font-lock-keyword-face))
1897 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1898 '(0 mdw-number-face))
1899 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1900 '(0 mdw-punct-face)))))
1901
1902 (mdw-post-config-mode-hack))
1903
1904 ;;;--------------------------------------------------------------------------
1905 ;;; Texinfo configuration.
1906
1907 (defun mdw-fontify-texinfo ()
1908
1909 ;; Set fill prefix.
1910 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1911
1912 ;; Real fontification things.
1913 (make-local-variable 'font-lock-keywords)
1914 (setq font-lock-keywords
1915 (list
1916
1917 ;; Environment names are keywords.
1918 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1919 '(2 font-lock-keyword-face))
1920
1921 ;; Unmark escaped magic characters.
1922 (list "\\(@\\)\\([@{}]\\)"
1923 '(1 font-lock-keyword-face)
1924 '(2 font-lock-variable-name-face))
1925
1926 ;; Make sure we get comments properly.
1927 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1928 '(0 font-lock-comment-face))
1929
1930 ;; Command names are keywords.
1931 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1932 '(0 font-lock-keyword-face))
1933
1934 ;; Fontify TeX special characters as punctuation.
1935 (list "[{}]+"
1936 '(0 mdw-punct-face))))
1937
1938 (mdw-post-config-mode-hack))
1939
1940 ;;;--------------------------------------------------------------------------
1941 ;;; TeX and LaTeX configuration.
1942
1943 (defun mdw-fontify-tex ()
1944 (setq ispell-parser 'tex)
1945 (turn-on-reftex)
1946
1947 ;; Don't make maths into a string.
1948 (modify-syntax-entry ?$ ".")
1949 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1950 (local-set-key [?$] 'self-insert-command)
1951
1952 ;; Set fill prefix.
1953 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1954
1955 ;; Real fontification things.
1956 (make-local-variable 'font-lock-keywords)
1957 (setq font-lock-keywords
1958 (list
1959
1960 ;; Environment names are keywords.
1961 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1962 "{\\([^}\n]*\\)}")
1963 '(2 font-lock-keyword-face))
1964
1965 ;; Suspended environment names are keywords too.
1966 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1967 "{\\([^}\n]*\\)}")
1968 '(3 font-lock-keyword-face))
1969
1970 ;; Command names are keywords.
1971 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1972 '(0 font-lock-keyword-face))
1973
1974 ;; Handle @/.../ for italics.
1975 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
1976 ;; '(1 font-lock-keyword-face)
1977 ;; '(3 font-lock-keyword-face))
1978
1979 ;; Handle @*...* for boldness.
1980 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
1981 ;; '(1 font-lock-keyword-face)
1982 ;; '(3 font-lock-keyword-face))
1983
1984 ;; Handle @`...' for literal syntax things.
1985 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
1986 ;; '(1 font-lock-keyword-face)
1987 ;; '(3 font-lock-keyword-face))
1988
1989 ;; Handle @<...> for nonterminals.
1990 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
1991 ;; '(1 font-lock-keyword-face)
1992 ;; '(3 font-lock-keyword-face))
1993
1994 ;; Handle other @-commands.
1995 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
1996 ;; '(0 font-lock-keyword-face))
1997
1998 ;; Make sure we get comments properly.
1999 (list "%.*"
2000 '(0 font-lock-comment-face))
2001
2002 ;; Fontify TeX special characters as punctuation.
2003 (list "[$^_{}#&]"
2004 '(0 mdw-punct-face))))
2005
2006 (mdw-post-config-mode-hack))
2007
2008 ;;;--------------------------------------------------------------------------
2009 ;;; SGML hacking.
2010
2011 (defun mdw-sgml-mode ()
2012 (interactive)
2013 (sgml-mode)
2014 (mdw-standard-fill-prefix "")
2015 (make-variable-buffer-local 'sgml-delimiters)
2016 (setq sgml-delimiters
2017 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2018 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2019 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2020 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2021 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2022 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2023 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2024 "NULL" ""))
2025 (setq major-mode 'mdw-sgml-mode)
2026 (setq mode-name "[mdw] SGML")
2027 (run-hooks 'mdw-sgml-mode-hook))
2028
2029 ;;;--------------------------------------------------------------------------
2030 ;;; Shell scripts.
2031
2032 (defun mdw-setup-sh-script-mode ()
2033
2034 ;; Fetch the shell interpreter's name.
2035 (let ((shell-name sh-shell-file))
2036
2037 ;; Try reading the hash-bang line.
2038 (save-excursion
2039 (goto-char (point-min))
2040 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2041 (setq shell-name (match-string 1))))
2042
2043 ;; Now try to set the shell.
2044 ;;
2045 ;; Don't let `sh-set-shell' bugger up my script.
2046 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2047 (sh-set-shell shell-name)))
2048
2049 ;; Now enable my keys and the fontification.
2050 (mdw-misc-mode-config)
2051
2052 ;; Set the indentation level correctly.
2053 (setq sh-indentation 2)
2054 (setq sh-basic-offset 2))
2055
2056 ;;;--------------------------------------------------------------------------
2057 ;;; Messages-file mode.
2058
2059 (defun messages-mode-guts ()
2060 (setq messages-mode-syntax-table (make-syntax-table))
2061 (set-syntax-table messages-mode-syntax-table)
2062 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2063 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2064 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2065 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2066 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2067 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2068 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2069 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2070 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2071 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2072 (make-local-variable 'comment-start)
2073 (make-local-variable 'comment-end)
2074 (make-local-variable 'indent-line-function)
2075 (setq indent-line-function 'indent-relative)
2076 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2077 (make-local-variable 'font-lock-defaults)
2078 (make-local-variable 'messages-mode-keywords)
2079 (let ((keywords
2080 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2081 "export" "enum" "fixed-octetstring" "flags"
2082 "harmless" "map" "nested" "optional"
2083 "optional-tagged" "package" "primitive"
2084 "primitive-nullfree" "relaxed[ \t]+enum"
2085 "set" "table" "tagged-optional" "union"
2086 "variadic" "vector" "version" "version-tag")))
2087 (setq messages-mode-keywords
2088 (list
2089 (list (concat "\\<\\(" keywords "\\)\\>:")
2090 '(0 font-lock-keyword-face))
2091 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2092 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2093 (0 font-lock-variable-name-face))
2094 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2095 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2096 (0 mdw-punct-face)))))
2097 (setq font-lock-defaults
2098 '(messages-mode-keywords nil nil nil nil))
2099 (run-hooks 'messages-file-hook))
2100
2101 (defun messages-mode ()
2102 (interactive)
2103 (fundamental-mode)
2104 (setq major-mode 'messages-mode)
2105 (setq mode-name "Messages")
2106 (messages-mode-guts)
2107 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2108 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2109 (setq comment-start "# ")
2110 (setq comment-end "")
2111 (turn-on-font-lock-if-enabled)
2112 (run-hooks 'messages-mode-hook))
2113
2114 (defun cpp-messages-mode ()
2115 (interactive)
2116 (fundamental-mode)
2117 (setq major-mode 'cpp-messages-mode)
2118 (setq mode-name "CPP Messages")
2119 (messages-mode-guts)
2120 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2121 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2122 (setq comment-start "/* ")
2123 (setq comment-end " */")
2124 (let ((preprocessor-keywords
2125 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2126 "ident" "if" "ifdef" "ifndef" "import" "include"
2127 "line" "pragma" "unassert" "undef" "warning")))
2128 (setq messages-mode-keywords
2129 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2130 "\\(include\\|import\\)"
2131 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2132 '(2 font-lock-string-face))
2133 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2134 preprocessor-keywords
2135 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2136 '(1 font-lock-keyword-face)))
2137 messages-mode-keywords)))
2138 (turn-on-font-lock-if-enabled)
2139 (run-hooks 'cpp-messages-mode-hook))
2140
2141 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2142 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2143 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2144
2145 ;;;--------------------------------------------------------------------------
2146 ;;; Messages-file mode.
2147
2148 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2149 "Face to use for subsittution directives.")
2150 (make-face 'mallow-driver-substitution-face)
2151 (defvar mallow-driver-text-face 'mallow-driver-text-face
2152 "Face to use for body text.")
2153 (make-face 'mallow-driver-text-face)
2154
2155 (defun mallow-driver-mode ()
2156 (interactive)
2157 (fundamental-mode)
2158 (setq major-mode 'mallow-driver-mode)
2159 (setq mode-name "Mallow driver")
2160 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2161 (set-syntax-table mallow-driver-mode-syntax-table)
2162 (make-local-variable 'comment-start)
2163 (make-local-variable 'comment-end)
2164 (make-local-variable 'indent-line-function)
2165 (setq indent-line-function 'indent-relative)
2166 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2167 (make-local-variable 'font-lock-defaults)
2168 (make-local-variable 'mallow-driver-mode-keywords)
2169 (let ((keywords
2170 (mdw-regexps "each" "divert" "file" "if"
2171 "perl" "set" "string" "type" "write")))
2172 (setq mallow-driver-mode-keywords
2173 (list
2174 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2175 '(0 font-lock-keyword-face))
2176 (list "^%\\s *\\(#.*\\|\\)$"
2177 '(0 font-lock-comment-face))
2178 (list "^%"
2179 '(0 font-lock-keyword-face))
2180 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2181 (list "\\${[^}]*}"
2182 '(0 mallow-driver-substitution-face t)))))
2183 (setq font-lock-defaults
2184 '(mallow-driver-mode-keywords nil nil nil nil))
2185 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2186 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2187 (setq comment-start "%# ")
2188 (setq comment-end "")
2189 (turn-on-font-lock-if-enabled)
2190 (run-hooks 'mallow-driver-mode-hook))
2191
2192 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2193
2194 ;;;--------------------------------------------------------------------------
2195 ;;; NFast debugs.
2196
2197 (defun nfast-debug-mode ()
2198 (interactive)
2199 (fundamental-mode)
2200 (setq major-mode 'nfast-debug-mode)
2201 (setq mode-name "NFast debug")
2202 (setq messages-mode-syntax-table (make-syntax-table))
2203 (set-syntax-table messages-mode-syntax-table)
2204 (make-local-variable 'font-lock-defaults)
2205 (make-local-variable 'nfast-debug-mode-keywords)
2206 (setq truncate-lines t)
2207 (setq nfast-debug-mode-keywords
2208 (list
2209 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2210 (0 font-lock-keyword-face))
2211 (list (concat "^[ \t]+\\(\\("
2212 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2213 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2214 "[ \t]+\\)*"
2215 "[0-9a-fA-F]+\\)[ \t]*$")
2216 '(0 mdw-number-face))
2217 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2218 (1 font-lock-keyword-face))
2219 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2220 (1 font-lock-warning-face))
2221 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2222 (1 nil))
2223 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2224 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2225 '(1 font-lock-keyword-face))
2226 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2227 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2228 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2229 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2230 (setq font-lock-defaults
2231 '(nfast-debug-mode-keywords nil nil nil nil))
2232 (turn-on-font-lock-if-enabled)
2233 (run-hooks 'nfast-debug-mode-hook))
2234
2235 ;;;--------------------------------------------------------------------------
2236 ;;; Other languages.
2237
2238 ;; Smalltalk.
2239
2240 (defun mdw-setup-smalltalk ()
2241 (and mdw-auto-indent
2242 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2243 (make-variable-buffer-local 'mdw-auto-indent)
2244 (setq mdw-auto-indent nil)
2245 (local-set-key "\C-i" 'smalltalk-reindent))
2246
2247 (defun mdw-fontify-smalltalk ()
2248 (make-local-variable 'font-lock-keywords)
2249 (setq font-lock-keywords
2250 (list
2251 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2252 '(0 font-lock-keyword-face))
2253 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2254 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2255 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2256 '(0 mdw-number-face))
2257 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2258 '(0 mdw-punct-face))))
2259 (mdw-post-config-mode-hack))
2260
2261 ;; Lispy languages.
2262
2263 ;; Unpleasant bodge.
2264 (unless (boundp 'slime-repl-mode-map)
2265 (setq slime-repl-mode-map (make-sparse-keymap)))
2266
2267 (defun mdw-indent-newline-and-indent ()
2268 (interactive)
2269 (indent-for-tab-command)
2270 (newline-and-indent))
2271
2272 (eval-after-load "cl-indent"
2273 '(progn
2274 (mapc #'(lambda (pair)
2275 (put (car pair)
2276 'common-lisp-indent-function
2277 (cdr pair)))
2278 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2279 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2280
2281 (defun mdw-common-lisp-indent ()
2282 (make-variable-buffer-local 'lisp-indent-function)
2283 (setq lisp-indent-function 'common-lisp-indent-function))
2284
2285 (setq lisp-simple-loop-indentation 2
2286 lisp-loop-keyword-indentation 6
2287 lisp-loop-forms-indentation 6)
2288
2289 (defun mdw-fontify-lispy ()
2290
2291 ;; Set fill prefix.
2292 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2293
2294 ;; Not much fontification needed.
2295 (make-local-variable 'font-lock-keywords)
2296 (setq font-lock-keywords
2297 (list
2298 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2299 '(0 mdw-punct-face))))
2300
2301 (mdw-post-config-mode-hack))
2302
2303 (defun comint-send-and-indent ()
2304 (interactive)
2305 (comint-send-input)
2306 (and mdw-auto-indent
2307 (indent-for-tab-command)))
2308
2309 (defun mdw-setup-m4 ()
2310 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2311
2312 ;;;--------------------------------------------------------------------------
2313 ;;; Text mode.
2314
2315 (defun mdw-text-mode ()
2316 (setq fill-column 72)
2317 (flyspell-mode t)
2318 (mdw-standard-fill-prefix
2319 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2320 (auto-fill-mode 1))
2321
2322 ;;;--------------------------------------------------------------------------
2323 ;;; Outline and hide/show modes.
2324
2325 (defun mdw-outline-collapse-all ()
2326 "Completely collapse everything in the entire buffer."
2327 (interactive)
2328 (save-excursion
2329 (goto-char (point-min))
2330 (while (< (point) (point-max))
2331 (hide-subtree)
2332 (forward-line))))
2333
2334 (setq hs-hide-comments-when-hiding-all nil)
2335
2336 (defadvice hs-hide-all (after hide-first-comment activate)
2337 (save-excursion (hs-hide-initial-comment-block)))
2338
2339 ;;;--------------------------------------------------------------------------
2340 ;;; Shell mode.
2341
2342 (defun mdw-sh-mode-setup ()
2343 (local-set-key [?\C-a] 'comint-bol)
2344 (add-hook 'comint-output-filter-functions
2345 'comint-watch-for-password-prompt))
2346
2347 (defun mdw-term-mode-setup ()
2348 (setq term-prompt-regexp shell-prompt-pattern)
2349 (make-local-variable 'mouse-yank-at-point)
2350 (make-local-variable 'transient-mark-mode)
2351 (setq mouse-yank-at-point t)
2352 (auto-fill-mode -1)
2353 (setq tab-width 8))
2354
2355 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2356 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2357 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2358 (defun term-send-meta-meta-something ()
2359 (interactive)
2360 (term-send-raw-string "\e\e")
2361 (term-send-raw))
2362 (eval-after-load 'term
2363 '(progn
2364 (define-key term-raw-map [?\e ?\e] nil)
2365 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2366 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2367 (define-key term-raw-map [M-right] 'term-send-meta-right)
2368 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2369 (define-key term-raw-map [M-left] 'term-send-meta-left)
2370 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2371
2372 ;;;--------------------------------------------------------------------------
2373 ;;; Inferior Emacs Lisp.
2374
2375 (setq comint-prompt-read-only t)
2376
2377 (eval-after-load "comint"
2378 '(progn
2379 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2380 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2381
2382 (eval-after-load "ielm"
2383 '(progn
2384 (define-key ielm-map "\C-w" 'comint-kill-region)
2385 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2386
2387 ;;;----- That's all, folks --------------------------------------------------
2388
2389 (provide 'dot-emacs)