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