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