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