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