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