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