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