el/dot-emacs.el: Colours for `magit' things.
[profile] / el / dot-emacs.el
1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
2 ;;;
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.
14 ;;;
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.
19 ;;;
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
24 ;;;--------------------------------------------------------------------------
25 ;;; Check command-line.
26
27 (defvar mdw-fast-startup nil
28 "Whether .emacs should optimize for rapid startup.
29 This may be at the expense of cool features.")
30 (let ((probe nil) (next command-line-args))
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
41 ;;;--------------------------------------------------------------------------
42 ;;; Some general utilities.
43
44 (eval-when-compile
45 (unless (fboundp 'make-regexp)
46 (load "make-regexp"))
47 (require 'cl))
48
49 (defmacro mdw-regexps (&rest list)
50 "Turn a LIST of strings into a single regular expression at compile-time."
51 (declare (indent nil)
52 (debug 0))
53 `',(make-regexp list))
54
55 ;; Some error trapping.
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."
62 (declare (indent 0)
63 (debug t))
64 `(condition-case err
65 ,(if (cdr forms) (cons 'progn forms) (car forms))
66 (error (message "Error (trapped): %s in %s"
67 (error-message-string err)
68 ',forms))))
69
70 ;; Configuration reading.
71
72 (defvar mdw-config nil)
73 (defun mdw-config (sym)
74 "Read the configuration variable named SYM."
75 (unless mdw-config
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) ")")))))))
92 (cdr (assq sym mdw-config)))
93
94 ;; Set up the load path convincingly.
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
105 ;; Is an Emacs library available?
106
107 (defun library-exists-p (name)
108 "Return non-nil if NAME is an available library.
109 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
110 load path. The non-nil value is the filename we found for the
111 library."
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
127 (defun mdw-kick-menu-bar (&optional frame)
128 "Regenerate FRAME's menu bar so it doesn't have empty menus."
129 (interactive)
130 (unless frame (setq frame (selected-frame)))
131 (let ((old (frame-parameter frame 'menu-bar-lines)))
132 (set-frame-parameter frame 'menu-bar-lines 0)
133 (set-frame-parameter frame 'menu-bar-lines old)))
134
135 ;; Splitting windows.
136
137 (unless (fboundp 'scroll-bar-columns)
138 (defun scroll-bar-columns (side)
139 (cond ((eq side 'left) 0)
140 (window-system 3)
141 (t 1))))
142 (unless (fboundp 'fringe-columns)
143 (defun fringe-columns (side)
144 (cond ((not window-system) 0)
145 ((eq side 'left) 1)
146 (t 2))))
147
148 (defun mdw-horizontal-window-overhead ()
149 "Computes the horizontal window overhead.
150 This is the number of columns used by fringes, scroll bars and other such
151 cruft."
152 (if (not window-system)
153 1
154 (let ((tot 0))
155 (dolist (what '(scroll-bar fringe))
156 (dolist (side '(left right))
157 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
158 side))))
159 tot)))
160
161 (defun mdw-split-window-horizontally (&optional width)
162 "Split a window horizontally.
163 Without a numeric argument, split the window approximately in
164 half. With a numeric argument WIDTH, allocate WIDTH columns to
165 the left-hand window (if positive) or -WIDTH columns to the
166 right-hand window (if negative). Space for scroll bars and
167 fringes is not taken out of the allowance for WIDTH, unlike
168 \\[split-window-horizontally]."
169 (interactive "P")
170 (split-window-horizontally
171 (cond ((null width) nil)
172 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
173 ((< width 0) width))))
174
175 (defun mdw-divvy-window (&optional width)
176 "Split a wide window into appropriate widths."
177 (interactive "P")
178 (setq width (cond (width (prefix-numeric-value width))
179 ((and window-system
180 (>= emacs-major-version 22))
181 77)
182 (t 78)))
183 (let* ((win (selected-window))
184 (sb-width (mdw-horizontal-window-overhead))
185 (c (/ (+ (window-width) sb-width)
186 (+ width sb-width))))
187 (while (> c 1)
188 (setq c (1- c))
189 (split-window-horizontally (+ width sb-width))
190 (other-window 1))
191 (select-window win)))
192
193 ;; Transient mark mode hacks.
194
195 (defadvice exchange-point-and-mark
196 (around mdw-highlight (&optional arg) activate compile)
197 "Maybe don't actually exchange point and mark.
198 If `transient-mark-mode' is on and the mark is inactive, then
199 just activate it. A non-trivial prefix argument will force the
200 usual behaviour. A trivial prefix argument (i.e., just C-u) will
201 activate the mark and temporarily enable `transient-mark-mode' if
202 it's currently off."
203 (cond ((or mark-active
204 (and (not transient-mark-mode) (not arg))
205 (and arg (or (not (consp arg))
206 (not (= (car arg) 4)))))
207 ad-do-it)
208 (t
209 (or transient-mark-mode (setq transient-mark-mode 'only))
210 (set-mark (mark t)))))
211
212 ;; Functions for sexp diary entries.
213
214 (defun mdw-weekday (l)
215 "Return non-nil if `date' falls on one of the days of the week in L.
216 L is a list of day numbers (from 0 to 6 for Sunday through to
217 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
218 the date stored in `date' falls on a listed day, then the
219 function returns non-nil."
220 (let ((d (calendar-day-of-week date)))
221 (or (memq d l)
222 (memq (nth d '(sunday monday tuesday wednesday
223 thursday friday saturday)) l))))
224
225 (defun mdw-todo (&optional when)
226 "Return non-nil today, or on WHEN, whichever is later."
227 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
228 (d (calendar-absolute-from-gregorian date)))
229 (if when
230 (setq w (max w (calendar-absolute-from-gregorian
231 (cond
232 ((not european-calendar-style)
233 when)
234 ((> (car when) 100)
235 (list (nth 1 when)
236 (nth 2 when)
237 (nth 0 when)))
238 (t
239 (list (nth 1 when)
240 (nth 0 when)
241 (nth 2 when))))))))
242 (eq w d)))
243
244 ;; Fighting with Org-mode's evil key maps.
245
246 (defvar mdw-evil-keymap-keys
247 '(([S-up] . [?\C-c up])
248 ([S-down] . [?\C-c down])
249 ([S-left] . [?\C-c left])
250 ([S-right] . [?\C-c right])
251 (([M-up] [?\e up]) . [C-up])
252 (([M-down] [?\e down]) . [C-down])
253 (([M-left] [?\e left]) . [C-left])
254 (([M-right] [?\e right]) . [C-right]))
255 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
256 The value is an alist mapping evil keys (as a list, or singleton)
257 to good keys (in the same form).")
258
259 (defun mdw-clobber-evil-keymap (keymap)
260 "Replace evil key bindings in the KEYMAP.
261 Evil key bindings are defined in `mdw-evil-keymap-keys'."
262 (dolist (entry mdw-evil-keymap-keys)
263 (let ((binding nil)
264 (keys (if (listp (car entry))
265 (car entry)
266 (list (car entry))))
267 (replacements (if (listp (cdr entry))
268 (cdr entry)
269 (list (cdr entry)))))
270 (catch 'found
271 (dolist (key keys)
272 (setq binding (lookup-key keymap key))
273 (when binding
274 (throw 'found nil))))
275 (when binding
276 (dolist (key keys)
277 (define-key keymap key nil))
278 (dolist (key replacements)
279 (define-key keymap key binding))))))
280
281 (eval-after-load "org-latex"
282 '(progn
283 (push '("strayman"
284 "\\documentclass{strayman}
285 \\usepackage[utf8]{inputenc}
286 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
287 \\usepackage[T1]{fontenc}
288 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
289 ("\\section{%s}" . "\\section*{%s}")
290 ("\\subsection{%s}" . "\\subsection*{%s}")
291 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
292 ("\\paragraph{%s}" . "\\paragraph*{%s}")
293 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
294 org-export-latex-classes)))
295
296 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
297 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
298 org-export-docbook-xslt-stylesheet
299 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
300
301 ;;;--------------------------------------------------------------------------
302 ;;; Mail and news hacking.
303
304 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
305 "Major mode for editing news and mail messages from external programs.
306 Not much right now. Just support for doing MailCrypt stuff."
307 :syntax-table nil
308 :abbrev-table nil
309 (run-hooks 'mail-setup-hook))
310
311 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
312
313 (add-hook 'mdwail-mode-hook
314 (lambda ()
315 (set-buffer-file-coding-system 'utf-8)
316 (make-local-variable 'paragraph-separate)
317 (make-local-variable 'paragraph-start)
318 (setq paragraph-start
319 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
320 paragraph-start))
321 (setq paragraph-separate
322 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
323 paragraph-separate))))
324
325 ;; How to encrypt in mdwmail.
326
327 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
328 (or start
329 (setq start (save-excursion
330 (goto-char (point-min))
331 (or (search-forward "\n\n" nil t) (point-min)))))
332 (or end
333 (setq end (point-max)))
334 (mc-encrypt-generic recip scm start end from sign))
335
336 ;; How to sign in mdwmail.
337
338 (defun mdwmail-mc-sign (key scm start end uclr)
339 (or start
340 (setq start (save-excursion
341 (goto-char (point-min))
342 (or (search-forward "\n\n" nil t) (point-min)))))
343 (or end
344 (setq end (point-max)))
345 (mc-sign-generic key scm start end uclr))
346
347 ;; Some signature mangling.
348
349 (defun mdwmail-mangle-signature ()
350 (save-excursion
351 (goto-char (point-min))
352 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
353 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
354 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
355
356 ;; Insert my login name into message-ids, so I can score replies.
357
358 (defadvice message-unique-id (after mdw-user-name last activate compile)
359 "Ensure that the user's name appears at the end of the message-id string,
360 so that it can be used for convenient filtering."
361 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
362
363 ;; Tell my movemail hack where movemail is.
364 ;;
365 ;; This is needed to shup up warnings about LD_PRELOAD.
366
367 (let ((path exec-path))
368 (while path
369 (let ((try (expand-file-name "movemail" (car path))))
370 (if (file-executable-p try)
371 (setenv "REAL_MOVEMAIL" try))
372 (setq path (cdr path)))))
373
374 (eval-after-load "erc"
375 '(load "~/.ercrc.el"))
376
377 ;;;--------------------------------------------------------------------------
378 ;;; Utility functions.
379
380 (or (fboundp 'line-number-at-pos)
381 (defun line-number-at-pos (&optional pos)
382 (let ((opoint (or pos (point))) start)
383 (save-excursion
384 (save-restriction
385 (goto-char (point-min))
386 (widen)
387 (forward-line 0)
388 (setq start (point))
389 (goto-char opoint)
390 (forward-line 0)
391 (1+ (count-lines 1 (point))))))))
392
393 (defun mdw-uniquify-alist (&rest alists)
394 "Return the concatenation of the ALISTS with duplicate elements removed.
395 The first association with a given key prevails; others are
396 ignored. The input lists are not modified, although they'll
397 probably become garbage."
398 (and alists
399 (let ((start-list (cons nil nil)))
400 (mdw-do-uniquify start-list
401 start-list
402 (car alists)
403 (cdr alists)))))
404
405 (defun mdw-do-uniquify (done end l rest)
406 "A helper function for mdw-uniquify-alist.
407 The DONE argument is a list whose first element is `nil'. It
408 contains the uniquified alist built so far. The leading `nil' is
409 stripped off at the end of the operation; it's only there so that
410 DONE always references a cons cell. END refers to the final cons
411 cell in the DONE list; it is modified in place each time to avoid
412 the overheads of `append'ing all the time. The L argument is the
413 alist we're currently processing; the remaining alists are given
414 in REST."
415
416 ;; There are several different cases to deal with here.
417 (cond
418
419 ;; Current list isn't empty. Add the first item to the DONE list if
420 ;; there's not an item with the same KEY already there.
421 (l (or (assoc (car (car l)) done)
422 (progn
423 (setcdr end (cons (car l) nil))
424 (setq end (cdr end))))
425 (mdw-do-uniquify done end (cdr l) rest))
426
427 ;; The list we were working on is empty. Shunt the next list into the
428 ;; current list position and go round again.
429 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
430
431 ;; Everything's done. Remove the leading `nil' from the DONE list and
432 ;; return it. Finished!
433 (t (cdr done))))
434
435 (defun date ()
436 "Insert the current date in a pleasing way."
437 (interactive)
438 (insert (save-excursion
439 (let ((buffer (get-buffer-create "*tmp*")))
440 (unwind-protect (progn (set-buffer buffer)
441 (erase-buffer)
442 (shell-command "date +%Y-%m-%d" t)
443 (goto-char (mark))
444 (delete-backward-char 1)
445 (buffer-string))
446 (kill-buffer buffer))))))
447
448 (defun uuencode (file &optional name)
449 "UUencodes a file, maybe calling it NAME, into the current buffer."
450 (interactive "fInput file name: ")
451
452 ;; If NAME isn't specified, then guess from the filename.
453 (if (not name)
454 (setq name
455 (substring file
456 (or (string-match "[^/]*$" file) 0))))
457 (print (format "uuencode `%s' `%s'" file name))
458
459 ;; Now actually do the thing.
460 (call-process "uuencode" file t nil name))
461
462 (defvar np-file "~/.np"
463 "*Where the `now-playing' file is.")
464
465 (defun np (&optional arg)
466 "Grabs a `now-playing' string."
467 (interactive)
468 (save-excursion
469 (or arg (progn
470 (goto-char (point-max))
471 (insert "\nNP: ")
472 (insert-file-contents np-file)))))
473
474 (defun mdw-version-< (ver-a ver-b)
475 "Answer whether VER-A is strictly earlier than VER-B.
476 VER-A and VER-B are version numbers, which are strings containing digit
477 sequences separated by `.'."
478 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
479 (split-string ver-a "\\.")))
480 (lb (mapcar (lambda (x) (car (read-from-string x)))
481 (split-string ver-b "\\."))))
482 (catch 'done
483 (while t
484 (cond ((null la) (throw 'done lb))
485 ((null lb) (throw 'done nil))
486 ((< (car la) (car lb)) (throw 'done t))
487 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb))))))))
488
489 (defun mdw-check-autorevert ()
490 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
491 This takes into consideration whether it's been found using
492 tramp, which seems to get itself into a twist."
493 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
494 nil)
495 ((and (buffer-file-name)
496 (fboundp 'tramp-tramp-file-p)
497 (tramp-tramp-file-p (buffer-file-name)))
498 (unless global-auto-revert-ignore-buffer
499 (setq global-auto-revert-ignore-buffer 'tramp)))
500 ((eq global-auto-revert-ignore-buffer 'tramp)
501 (setq global-auto-revert-ignore-buffer nil))))
502
503 (defadvice find-file (after mdw-autorevert activate)
504 (mdw-check-autorevert))
505 (defadvice write-file (after mdw-autorevert activate)
506 (mdw-check-autorevert))
507
508 ;;;--------------------------------------------------------------------------
509 ;;; Dired hacking.
510
511 (defadvice dired-maybe-insert-subdir
512 (around mdw-marked-insertion first activate)
513 "The DIRNAME may be a list of directory names to insert.
514 Interactively, if files are marked, then insert all of them.
515 With a numeric prefix argument, select that many entries near
516 point; with a non-numeric prefix argument, prompt for listing
517 options."
518 (interactive
519 (list (dired-get-marked-files nil
520 (and (integerp current-prefix-arg)
521 current-prefix-arg)
522 #'file-directory-p)
523 (and current-prefix-arg
524 (not (integerp current-prefix-arg))
525 (read-string "Switches for listing: "
526 (or dired-subdir-switches
527 dired-actual-switches)))))
528 (let ((dirs (ad-get-arg 0)))
529 (dolist (dir (if (listp dirs) dirs (list dirs)))
530 (ad-set-arg 0 dir)
531 ad-do-it)))
532
533 ;;;--------------------------------------------------------------------------
534 ;;; URL viewing.
535
536 (defun mdw-w3m-browse-url (url &optional new-session-p)
537 "Invoke w3m on the URL in its current window, or at least a different one.
538 If NEW-SESSION-P, start a new session."
539 (interactive "sURL: \nP")
540 (save-excursion
541 (let ((window (selected-window)))
542 (unwind-protect
543 (progn
544 (select-window (or (and (not new-session-p)
545 (get-buffer-window "*w3m*"))
546 (progn
547 (if (one-window-p t) (split-window))
548 (get-lru-window))))
549 (w3m-browse-url url new-session-p))
550 (select-window window)))))
551
552 (defvar mdw-good-url-browsers
553 '(browse-url-generic
554 (w3m . mdw-w3m-browse-url)
555 browse-url-w3
556 browse-url-mozilla)
557 "List of good browsers for mdw-good-url-browsers.
558 Each item is a browser function name, or a cons (CHECK . FUNC).
559 A symbol FOO stands for (FOO . FOO).")
560
561 (defun mdw-good-url-browser ()
562 "Return a good URL browser.
563 Trundle the list of such things, finding the first item for which
564 CHECK is fboundp, and returning the correponding FUNC."
565 (let ((bs mdw-good-url-browsers) b check func answer)
566 (while (and bs (not answer))
567 (setq b (car bs)
568 bs (cdr bs))
569 (if (consp b)
570 (setq check (car b) func (cdr b))
571 (setq check b func b))
572 (if (fboundp check)
573 (setq answer func)))
574 answer))
575
576 (eval-after-load "w3m-search"
577 '(progn
578 (dolist
579 (item
580 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
581 ("gd" "Google Directory"
582 "http://www.google.com/search?cat=gwd/Top&q=%s")
583 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
584 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
585 ("gi" "Images" "http://images.google.com/images?q=%s")
586 ("rfc" "RFC"
587 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
588 ("wp" "Wikipedia"
589 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
590 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
591 ("nc-wiki" "nCipher wiki"
592 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
593 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
594 ("lp" "Launchpad bug by number"
595 "https://bugs.launchpad.net/bugs/%s")
596 ("lppkg" "Launchpad bugs by package"
597 "https://bugs.launchpad.net/%s")
598 ("msdn" "MSDN"
599 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
600 ("debbug" "Debian bug by number"
601 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
602 ("debbugpkg" "Debian bugs by package"
603 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
604 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
605 (add-to-list 'w3m-search-engine-alist
606 (list (cadr item) (caddr item) nil))
607 (add-to-list 'w3m-uri-replace-alist
608 (list (concat "\\`" (car item) ":")
609 'w3m-search-uri-replace
610 (cadr item))))))
611
612 ;;;--------------------------------------------------------------------------
613 ;;; Paragraph filling.
614
615 ;; Useful variables.
616
617 (defvar mdw-fill-prefix nil
618 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
619 If there's no fill prefix currently set (by the `fill-prefix'
620 variable) and there's a match from one of the regexps here, it
621 gets used to set the fill-prefix for the current operation.
622
623 The variable is a list of items of the form `REGEXP . PREFIX'; if
624 the REGEXP matches, the PREFIX is used to set the fill prefix.
625 It in turn is a list of things:
626
627 STRING -- insert a literal string
628 (match . N) -- insert the thing matched by bracketed subexpression N
629 (pad . N) -- a string of whitespace the same width as subexpression N
630 (expr . FORM) -- the result of evaluating FORM")
631
632 (make-variable-buffer-local 'mdw-fill-prefix)
633
634 (defvar mdw-hanging-indents
635 (concat "\\(\\("
636 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
637 "[ \t]+"
638 "\\)?\\)")
639 "*Standard regexp matching parts of a hanging indent.
640 This is mainly useful in `auto-fill-mode'.")
641
642 ;; Setting things up.
643
644 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
645
646 ;; Utility functions.
647
648 (defun mdw-maybe-tabify (s)
649 "Tabify or untabify the string S, according to `indent-tabs-mode'."
650 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
651 (with-temp-buffer
652 (save-match-data
653 (insert s "\n")
654 (let ((start (point-min)) (end (point-max)))
655 (funcall tabfun (point-min) (point-max))
656 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
657
658 (defun mdw-examine-fill-prefixes (l)
659 "Given a list of dynamic fill prefixes, pick one which matches
660 context and return the static fill prefix to use. Point must be
661 at the start of a line, and match data must be saved."
662 (cond ((not l) nil)
663 ((looking-at (car (car l)))
664 (mdw-maybe-tabify (apply #'concat
665 (mapcar #'mdw-do-prefix-match
666 (cdr (car l))))))
667 (t (mdw-examine-fill-prefixes (cdr l)))))
668
669 (defun mdw-maybe-car (p)
670 "If P is a pair, return (car P), otherwise just return P."
671 (if (consp p) (car p) p))
672
673 (defun mdw-padding (s)
674 "Return a string the same width as S but made entirely from whitespace."
675 (let* ((l (length s)) (i 0) (n (make-string l ? )))
676 (while (< i l)
677 (if (= 9 (aref s i))
678 (aset n i 9))
679 (setq i (1+ i)))
680 n))
681
682 (defun mdw-do-prefix-match (m)
683 "Expand a dynamic prefix match element.
684 See `mdw-fill-prefix' for details."
685 (cond ((not (consp m)) (format "%s" m))
686 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
687 ((eq (car m) 'pad) (mdw-padding (match-string
688 (mdw-maybe-car (cdr m)))))
689 ((eq (car m) 'eval) (eval (cdr m)))
690 (t "")))
691
692 (defun mdw-choose-dynamic-fill-prefix ()
693 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
694 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
695 ((not mdw-fill-prefix) fill-prefix)
696 (t (save-excursion
697 (beginning-of-line)
698 (save-match-data
699 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
700
701 (defun do-auto-fill ()
702 "Handle auto-filling, working out a dynamic fill prefix in the
703 case where there isn't a sensible static one."
704 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
705 (mdw-do-auto-fill)))
706
707 (defun mdw-fill-paragraph ()
708 "Fill paragraph, getting a dynamic fill prefix."
709 (interactive)
710 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
711 (fill-paragraph nil)))
712
713 (defun mdw-standard-fill-prefix (rx &optional mat)
714 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
715 This is just a short-cut for setting the thing by hand, and by
716 design it doesn't cope with anything approximating a complicated
717 case."
718 (setq mdw-fill-prefix
719 `((,(concat rx mdw-hanging-indents)
720 (match . 1)
721 (pad . ,(or mat 2))))))
722
723 ;;;--------------------------------------------------------------------------
724 ;;; Other common declarations.
725
726 ;; Common mode settings.
727
728 (defvar mdw-auto-indent t
729 "Whether to indent automatically after a newline.")
730
731 (defun mdw-whitespace-mode (&optional arg)
732 "Turn on/off whitespace mode, but don't highlight trailing space."
733 (interactive "P")
734 (when (and (boundp 'whitespace-style)
735 (fboundp 'whitespace-mode))
736 (let ((whitespace-style (remove 'trailing whitespace-style)))
737 (whitespace-mode arg))
738 (setq show-trailing-whitespace whitespace-mode)))
739
740 (defun mdw-misc-mode-config ()
741 (and mdw-auto-indent
742 (cond ((eq major-mode 'lisp-mode)
743 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
744 ((or (eq major-mode 'slime-repl-mode)
745 (eq major-mode 'asm-mode))
746 nil)
747 (t
748 (local-set-key "\C-m" 'newline-and-indent))))
749 (local-set-key [C-return] 'newline)
750 (make-local-variable 'page-delimiter)
751 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
752 (setq comment-column 40)
753 (auto-fill-mode 1)
754 (setq fill-column 77)
755 (setq show-trailing-whitespace t)
756 (mdw-whitespace-mode 1)
757 (and (fboundp 'gtags-mode)
758 (gtags-mode))
759 (if (fboundp 'hs-minor-mode)
760 (trap (hs-minor-mode t))
761 (outline-minor-mode t))
762 (reveal-mode t)
763 (trap (turn-on-font-lock)))
764
765 (defun mdw-post-config-mode-hack ()
766 (mdw-whitespace-mode 1))
767
768 (eval-after-load 'gtags
769 '(progn
770 (dolist (key '([mouse-2] [mouse-3]))
771 (define-key gtags-mode-map key nil))
772 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
773 (define-key gtags-select-mode-map [C-S-mouse-2]
774 'gtags-select-tag-by-event)
775 (dolist (map (list gtags-mode-map gtags-select-mode-map))
776 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
777
778 ;; Backup file handling.
779
780 (defvar mdw-backup-disable-regexps nil
781 "*List of regular expressions: if a file name matches any of
782 these then the file is not backed up.")
783
784 (defun mdw-backup-enable-predicate (name)
785 "[mdw]'s default backup predicate.
786 Allows a backup if the standard predicate would allow it, and it
787 doesn't match any of the regular expressions in
788 `mdw-backup-disable-regexps'."
789 (and (normal-backup-enable-predicate name)
790 (let ((answer t) (list mdw-backup-disable-regexps))
791 (save-match-data
792 (while list
793 (if (string-match (car list) name)
794 (setq answer nil))
795 (setq list (cdr list)))
796 answer))))
797 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
798
799 ;; Frame cleanup.
800
801 (defun mdw-last-one-out-turn-off-the-lights (frame)
802 "Disconnect from an X display if this was the last frame on that display."
803 (let ((frame-display (frame-parameter frame 'display)))
804 (when (and frame-display
805 (eq window-system 'x)
806 (not (some (lambda (fr)
807 (and (not (eq fr frame))
808 (string= (frame-parameter fr 'display)
809 frame-display)))
810 (frame-list))))
811 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
812 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
813
814 ;;;--------------------------------------------------------------------------
815 ;;; General fontification.
816
817 (defmacro mdw-define-face (name &rest body)
818 "Define a face, and make sure it's actually set as the definition."
819 (declare (indent 1)
820 (debug 0))
821 `(progn
822 (make-face ',name)
823 (defvar ,name ',name)
824 (put ',name 'face-defface-spec ',body)
825 (face-spec-set ',name ',body nil)))
826
827 (mdw-define-face default
828 (((type w32)) :family "courier new" :height 85)
829 (((type x)) :family "6x13" :foundry "trad" :height 130)
830 (((type color)) :foreground "white" :background "black")
831 (t nil))
832 (mdw-define-face fixed-pitch
833 (((type w32)) :family "courier new" :height 85)
834 (((type x)) :family "6x13" :foundry "trad" :height 130)
835 (t :foreground "white" :background "black"))
836 (if (>= emacs-major-version 23)
837 (mdw-define-face variable-pitch
838 (((type x)) :family "sans" :height 100))
839 (mdw-define-face variable-pitch
840 (((type x)) :family "helvetica" :height 90)))
841 (mdw-define-face region
842 (((type tty) (class color)) :background "blue")
843 (((type tty) (class mono)) :inverse-video t)
844 (t :background "grey30"))
845 (mdw-define-face minibuffer-prompt
846 (t :weight bold))
847 (mdw-define-face mode-line
848 (((class color)) :foreground "blue" :background "yellow"
849 :box (:line-width 1 :style released-button))
850 (t :inverse-video t))
851 (mdw-define-face mode-line-inactive
852 (((class color)) :foreground "yellow" :background "blue"
853 :box (:line-width 1 :style released-button))
854 (t :inverse-video t))
855 (mdw-define-face scroll-bar
856 (t :foreground "black" :background "lightgrey"))
857 (mdw-define-face fringe
858 (t :foreground "yellow"))
859 (mdw-define-face show-paren-match
860 (((class color)) :background "darkgreen")
861 (t :underline t))
862 (mdw-define-face show-paren-mismatch
863 (((class color)) :background "red")
864 (t :inverse-video t))
865 (mdw-define-face highlight
866 (((type x) (class color)) :background "DarkSeaGreen4")
867 (((type tty) (class color)) :background "cyan")
868 (t :inverse-video t))
869
870 (mdw-define-face holiday-face
871 (t :background "red"))
872 (mdw-define-face calendar-today-face
873 (t :foreground "yellow" :weight bold))
874
875 (mdw-define-face comint-highlight-prompt
876 (t :weight bold))
877 (mdw-define-face comint-highlight-input
878 (t nil))
879
880 (mdw-define-face dired-directory
881 (t :foreground "cyan" :weight bold))
882 (mdw-define-face dired-symlink
883 (t :foreground "cyan"))
884 (mdw-define-face dired-perm-write
885 (t nil))
886
887 (mdw-define-face trailing-whitespace
888 (((class color)) :background "red")
889 (t :inverse-video t))
890 (mdw-define-face mdw-punct-face
891 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
892 (mdw-define-face mdw-number-face
893 (t :foreground "yellow"))
894 (mdw-define-face font-lock-function-name-face
895 (t :slant italic))
896 (mdw-define-face font-lock-keyword-face
897 (t :weight bold))
898 (mdw-define-face font-lock-constant-face
899 (t :slant italic))
900 (mdw-define-face font-lock-builtin-face
901 (t :weight bold))
902 (mdw-define-face font-lock-type-face
903 (t :weight bold :slant italic))
904 (mdw-define-face font-lock-reference-face
905 (t :weight bold))
906 (mdw-define-face font-lock-variable-name-face
907 (t :slant italic))
908 (mdw-define-face font-lock-comment-delimiter-face
909 (((class mono)) :weight bold)
910 (((type tty) (class color)) :foreground "green")
911 (t :slant italic :foreground "SeaGreen1"))
912 (mdw-define-face font-lock-comment-face
913 (((class mono)) :weight bold)
914 (((type tty) (class color)) :foreground "green")
915 (t :slant italic :foreground "SeaGreen1"))
916 (mdw-define-face font-lock-string-face
917 (((class mono)) :weight bold)
918 (((class color)) :foreground "SkyBlue1"))
919
920 (mdw-define-face message-separator
921 (t :background "red" :foreground "white" :weight bold))
922 (mdw-define-face message-cited-text
923 (default :slant italic)
924 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
925 (mdw-define-face message-header-cc
926 (default :weight bold)
927 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
928 (mdw-define-face message-header-newsgroups
929 (default :weight bold)
930 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
931 (mdw-define-face message-header-subject
932 (default :weight bold)
933 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
934 (mdw-define-face message-header-to
935 (default :weight bold)
936 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
937 (mdw-define-face message-header-xheader
938 (default :weight bold)
939 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
940 (mdw-define-face message-header-other
941 (default :weight bold)
942 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
943 (mdw-define-face message-header-name
944 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
945 (mdw-define-face which-func
946 (t nil))
947
948 (mdw-define-face diff-header
949 (t nil))
950 (mdw-define-face diff-index
951 (t :weight bold))
952 (mdw-define-face diff-file-header
953 (t :weight bold))
954 (mdw-define-face diff-hunk-header
955 (t :foreground "SkyBlue1"))
956 (mdw-define-face diff-function
957 (t :foreground "SkyBlue1" :weight bold))
958 (mdw-define-face diff-header
959 (t :background "grey10"))
960 (mdw-define-face diff-added
961 (t :foreground "green"))
962 (mdw-define-face diff-removed
963 (t :foreground "red"))
964 (mdw-define-face diff-context
965 (t nil))
966 (mdw-define-face diff-refine-change
967 (((class color) (type x)) :background "RoyalBlue4")
968 (t :underline t))
969
970 (mdw-define-face dylan-header-background
971 (((class color) (type x)) :background "NavyBlue")
972 (t :background "blue"))
973
974 (mdw-define-face magit-diff-add
975 (t :foreground "green"))
976 (mdw-define-face magit-diff-del
977 (t :foreground "red"))
978 (mdw-define-face magit-diff-file-header
979 (t :weight bold))
980 (mdw-define-face magit-diff-hunk-header
981 (t :foreground "SkyBlue1"))
982 (mdw-define-face magit-item-highlight
983 (((type tty)) :background "blue")
984 (t :background "DarkSeaGreen4"))
985 (mdw-define-face magit-log-head-label-remote
986 (((type tty)) :background "cyan" :foreground "green")
987 (t :background "grey11" :foreground "DarkSeaGreen2" :box t))
988 (mdw-define-face magit-log-head-label-local
989 (((type tty)) :background "cyan" :foreground "yellow")
990 (t :background "grey11" :foreground "LightSkyBlue1" :box t))
991 (mdw-define-face magit-log-head-label-tags
992 (((type tty)) :background "red" :foreground "yellow")
993 (t :background "LemonChiffon1" :foreground "goldenrod4" :box t))
994 (mdw-define-face magit-log-graph
995 (((type tty)) :foreground "magenta")
996 (t :foreground "grey80"))
997
998 (mdw-define-face erc-input-face
999 (t :foreground "red"))
1000
1001 (mdw-define-face woman-bold
1002 (t :weight bold))
1003 (mdw-define-face woman-italic
1004 (t :slant italic))
1005
1006 (eval-after-load "rst"
1007 '(progn
1008 (mdw-define-face rst-level-1-face
1009 (t :foreground "SkyBlue1" :weight bold))
1010 (mdw-define-face rst-level-2-face
1011 (t :foreground "SeaGreen1" :weight bold))
1012 (mdw-define-face rst-level-3-face
1013 (t :weight bold))
1014 (mdw-define-face rst-level-4-face
1015 (t :slant italic))
1016 (mdw-define-face rst-level-5-face
1017 (t :underline t))
1018 (mdw-define-face rst-level-6-face
1019 ())))
1020
1021 (mdw-define-face p4-depot-added-face
1022 (t :foreground "green"))
1023 (mdw-define-face p4-depot-branch-op-face
1024 (t :foreground "yellow"))
1025 (mdw-define-face p4-depot-deleted-face
1026 (t :foreground "red"))
1027 (mdw-define-face p4-depot-unmapped-face
1028 (t :foreground "SkyBlue1"))
1029 (mdw-define-face p4-diff-change-face
1030 (t :foreground "yellow"))
1031 (mdw-define-face p4-diff-del-face
1032 (t :foreground "red"))
1033 (mdw-define-face p4-diff-file-face
1034 (t :foreground "SkyBlue1"))
1035 (mdw-define-face p4-diff-head-face
1036 (t :background "grey10"))
1037 (mdw-define-face p4-diff-ins-face
1038 (t :foreground "green"))
1039
1040 (mdw-define-face w3m-anchor-face
1041 (t :foreground "SkyBlue1" :underline t))
1042 (mdw-define-face w3m-arrived-anchor-face
1043 (t :foreground "SkyBlue1" :underline t))
1044
1045 (mdw-define-face whizzy-slice-face
1046 (t :background "grey10"))
1047 (mdw-define-face whizzy-error-face
1048 (t :background "darkred"))
1049
1050 ;; Ellipses used to indicate hidden text (and similar).
1051 (mdw-define-face mdw-ellipsis-face
1052 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1053 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1054 (backslash (make-glyph-code ?\ 'mdw-ellipsis-face))
1055 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1056 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1057 (set-display-table-slot standard-display-table 0 dollar)
1058 (set-display-table-slot standard-display-table 1 backslash)
1059 (set-display-table-slot standard-display-table 4
1060 (vector dot dot dot))
1061 (set-display-table-slot standard-display-table 5 bar))
1062
1063 ;;;--------------------------------------------------------------------------
1064 ;;; C programming configuration.
1065
1066 ;; Linux kernel hacking.
1067
1068 (defvar linux-c-mode-hook)
1069
1070 (defun linux-c-mode ()
1071 (interactive)
1072 (c-mode)
1073 (setq major-mode 'linux-c-mode)
1074 (setq mode-name "Linux C")
1075 (run-hooks 'linux-c-mode-hook))
1076
1077 ;; Make C indentation nice.
1078
1079 (defun mdw-c-lineup-arglist (langelem)
1080 "Hack for DWIMmery in c-lineup-arglist."
1081 (if (save-excursion
1082 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1083 0
1084 (c-lineup-arglist langelem)))
1085
1086 (defun mdw-c-indent-extern-mumble (langelem)
1087 "Indent `extern \"...\" {' lines."
1088 (save-excursion
1089 (back-to-indentation)
1090 (if (looking-at
1091 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1092 c-basic-offset
1093 nil)))
1094
1095 (defun mdw-c-style ()
1096 (c-add-style "[mdw] C and C++ style"
1097 '((c-basic-offset . 2)
1098 (comment-column . 40)
1099 (c-class-key . "class")
1100 (c-backslash-column . 72)
1101 (c-offsets-alist
1102 (substatement-open . (add 0 c-indent-one-line-block))
1103 (defun-open . (add 0 c-indent-one-line-block))
1104 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1105 (topmost-intro . mdw-c-indent-extern-mumble)
1106 (cpp-define-intro . 0)
1107 (knr-argdecl . 0)
1108 (inextern-lang . [0])
1109 (label . 0)
1110 (case-label . +)
1111 (access-label . -)
1112 (inclass . +)
1113 (inline-open . ++)
1114 (statement-cont . +)
1115 (statement-case-intro . +)))
1116 t))
1117
1118 (defvar mdw-c-comment-fill-prefix
1119 `((,(concat "\\([ \t]*/?\\)"
1120 "\\(\*\\|//]\\)"
1121 "\\([ \t]*\\)"
1122 "\\([A-Za-z]+:[ \t]*\\)?"
1123 mdw-hanging-indents)
1124 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1125 "Fill prefix matching C comments (both kinds).")
1126
1127 (defun mdw-fontify-c-and-c++ ()
1128
1129 ;; Fiddle with some syntax codes.
1130 (modify-syntax-entry ?* ". 23")
1131 (modify-syntax-entry ?/ ". 124b")
1132 (modify-syntax-entry ?\n "> b")
1133
1134 ;; Other stuff.
1135 (mdw-c-style)
1136 (setq c-hanging-comment-ender-p nil)
1137 (setq c-backslash-column 72)
1138 (setq c-label-minimum-indentation 0)
1139 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1140
1141 ;; Now define things to be fontified.
1142 (make-local-variable 'font-lock-keywords)
1143 (let ((c-keywords
1144 (mdw-regexps "and" ;C++
1145 "and_eq" ;C++
1146 "asm" ;K&R, GCC
1147 "auto" ;K&R, C89
1148 "bitand" ;C++
1149 "bitor" ;C++
1150 "bool" ;C++, C9X macro
1151 "break" ;K&R, C89
1152 "case" ;K&R, C89
1153 "catch" ;C++
1154 "char" ;K&R, C89
1155 "class" ;C++
1156 "complex" ;C9X macro, C++ template type
1157 "compl" ;C++
1158 "const" ;C89
1159 "const_cast" ;C++
1160 "continue" ;K&R, C89
1161 "defined" ;C89 preprocessor
1162 "default" ;K&R, C89
1163 "delete" ;C++
1164 "do" ;K&R, C89
1165 "double" ;K&R, C89
1166 "dynamic_cast" ;C++
1167 "else" ;K&R, C89
1168 ;; "entry" ;K&R -- never used
1169 "enum" ;C89
1170 "explicit" ;C++
1171 "export" ;C++
1172 "extern" ;K&R, C89
1173 "false" ;C++, C9X macro
1174 "float" ;K&R, C89
1175 "for" ;K&R, C89
1176 ;; "fortran" ;K&R
1177 "friend" ;C++
1178 "goto" ;K&R, C89
1179 "if" ;K&R, C89
1180 "imaginary" ;C9X macro
1181 "inline" ;C++, C9X, GCC
1182 "int" ;K&R, C89
1183 "long" ;K&R, C89
1184 "mutable" ;C++
1185 "namespace" ;C++
1186 "new" ;C++
1187 "operator" ;C++
1188 "or" ;C++
1189 "or_eq" ;C++
1190 "private" ;C++
1191 "protected" ;C++
1192 "public" ;C++
1193 "register" ;K&R, C89
1194 "reinterpret_cast" ;C++
1195 "restrict" ;C9X
1196 "return" ;K&R, C89
1197 "short" ;K&R, C89
1198 "signed" ;C89
1199 "sizeof" ;K&R, C89
1200 "static" ;K&R, C89
1201 "static_cast" ;C++
1202 "struct" ;K&R, C89
1203 "switch" ;K&R, C89
1204 "template" ;C++
1205 "this" ;C++
1206 "throw" ;C++
1207 "true" ;C++, C9X macro
1208 "try" ;C++
1209 "this" ;C++
1210 "typedef" ;C89
1211 "typeid" ;C++
1212 "typeof" ;GCC
1213 "typename" ;C++
1214 "union" ;K&R, C89
1215 "unsigned" ;K&R, C89
1216 "using" ;C++
1217 "virtual" ;C++
1218 "void" ;C89
1219 "volatile" ;C89
1220 "wchar_t" ;C++, C89 library type
1221 "while" ;K&R, C89
1222 "xor" ;C++
1223 "xor_eq" ;C++
1224 "_Bool" ;C9X
1225 "_Complex" ;C9X
1226 "_Imaginary" ;C9X
1227 "_Pragma" ;C9X preprocessor
1228 "__alignof__" ;GCC
1229 "__asm__" ;GCC
1230 "__attribute__" ;GCC
1231 "__complex__" ;GCC
1232 "__const__" ;GCC
1233 "__extension__" ;GCC
1234 "__imag__" ;GCC
1235 "__inline__" ;GCC
1236 "__label__" ;GCC
1237 "__real__" ;GCC
1238 "__signed__" ;GCC
1239 "__typeof__" ;GCC
1240 "__volatile__" ;GCC
1241 ))
1242 (preprocessor-keywords
1243 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1244 "ident" "if" "ifdef" "ifndef" "import" "include"
1245 "line" "pragma" "unassert" "undef" "warning"))
1246 (objc-keywords
1247 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1248 "interface" "private" "protected" "protocol" "public"
1249 "selector")))
1250
1251 (setq font-lock-keywords
1252 (list
1253
1254 ;; Fontify include files as strings.
1255 (list (concat "^[ \t]*\\#[ \t]*"
1256 "\\(include\\|import\\)"
1257 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1258 '(2 font-lock-string-face))
1259
1260 ;; Preprocessor directives are `references'?.
1261 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1262 preprocessor-keywords
1263 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1264 '(1 font-lock-keyword-face))
1265
1266 ;; Handle the keywords defined above.
1267 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1268 '(0 font-lock-keyword-face))
1269
1270 (list (concat "\\<\\(" c-keywords "\\)\\>")
1271 '(0 font-lock-keyword-face))
1272
1273 ;; Handle numbers too.
1274 ;;
1275 ;; This looks strange, I know. It corresponds to the
1276 ;; preprocessor's idea of what a number looks like, rather than
1277 ;; anything sensible.
1278 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1279 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1280 '(0 mdw-number-face))
1281
1282 ;; And anything else is punctuation.
1283 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1284 '(0 mdw-punct-face))))
1285
1286 (mdw-post-config-mode-hack)))
1287
1288 ;;;--------------------------------------------------------------------------
1289 ;;; AP calc mode.
1290
1291 (defun apcalc-mode ()
1292 (interactive)
1293 (c-mode)
1294 (setq major-mode 'apcalc-mode)
1295 (setq mode-name "AP Calc")
1296 (run-hooks 'apcalc-mode-hook))
1297
1298 (defun mdw-fontify-apcalc ()
1299
1300 ;; Fiddle with some syntax codes.
1301 (modify-syntax-entry ?* ". 23")
1302 (modify-syntax-entry ?/ ". 14")
1303
1304 ;; Other stuff.
1305 (mdw-c-style)
1306 (setq c-hanging-comment-ender-p nil)
1307 (setq c-backslash-column 72)
1308 (setq comment-start "/* ")
1309 (setq comment-end " */")
1310 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1311
1312 ;; Now define things to be fontified.
1313 (make-local-variable 'font-lock-keywords)
1314 (let ((c-keywords
1315 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1316 "do" "else" "exit" "for" "global" "goto" "help" "if"
1317 "local" "mat" "obj" "print" "quit" "read" "return"
1318 "show" "static" "switch" "while" "write")))
1319
1320 (setq font-lock-keywords
1321 (list
1322
1323 ;; Handle the keywords defined above.
1324 (list (concat "\\<\\(" c-keywords "\\)\\>")
1325 '(0 font-lock-keyword-face))
1326
1327 ;; Handle numbers too.
1328 ;;
1329 ;; This looks strange, I know. It corresponds to the
1330 ;; preprocessor's idea of what a number looks like, rather than
1331 ;; anything sensible.
1332 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1333 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1334 '(0 mdw-number-face))
1335
1336 ;; And anything else is punctuation.
1337 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1338 '(0 mdw-punct-face)))))
1339
1340 (mdw-post-config-mode-hack))
1341
1342 ;;;--------------------------------------------------------------------------
1343 ;;; Java programming configuration.
1344
1345 ;; Make indentation nice.
1346
1347 (defun mdw-java-style ()
1348 (c-add-style "[mdw] Java style"
1349 '((c-basic-offset . 2)
1350 (c-offsets-alist (substatement-open . 0)
1351 (label . +)
1352 (case-label . +)
1353 (access-label . 0)
1354 (inclass . +)
1355 (statement-case-intro . +)))
1356 t))
1357
1358 ;; Declare Java fontification style.
1359
1360 (defun mdw-fontify-java ()
1361
1362 ;; Other stuff.
1363 (mdw-java-style)
1364 (setq c-hanging-comment-ender-p nil)
1365 (setq c-backslash-column 72)
1366 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1367
1368 ;; Now define things to be fontified.
1369 (make-local-variable 'font-lock-keywords)
1370 (let ((java-keywords
1371 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1372 "char" "class" "const" "continue" "default" "do"
1373 "double" "else" "extends" "final" "finally" "float"
1374 "for" "goto" "if" "implements" "import" "instanceof"
1375 "int" "interface" "long" "native" "new" "package"
1376 "private" "protected" "public" "return" "short"
1377 "static" "super" "switch" "synchronized" "this"
1378 "throw" "throws" "transient" "try" "void" "volatile"
1379 "while"
1380
1381 "false" "null" "true")))
1382
1383 (setq font-lock-keywords
1384 (list
1385
1386 ;; Handle the keywords defined above.
1387 (list (concat "\\<\\(" java-keywords "\\)\\>")
1388 '(0 font-lock-keyword-face))
1389
1390 ;; Handle numbers too.
1391 ;;
1392 ;; The following isn't quite right, but it's close enough.
1393 (list (concat "\\<\\("
1394 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1395 "[0-9]+\\(\\.[0-9]*\\|\\)"
1396 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1397 "[lLfFdD]?")
1398 '(0 mdw-number-face))
1399
1400 ;; And anything else is punctuation.
1401 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1402 '(0 mdw-punct-face)))))
1403
1404 (mdw-post-config-mode-hack))
1405
1406 ;;;--------------------------------------------------------------------------
1407 ;;; Javascript programming configuration.
1408
1409 (defun mdw-javascript-style ()
1410 (setq js-indent-level 2)
1411 (setq js-expr-indent-offset 0))
1412
1413 (defun mdw-fontify-javascript ()
1414
1415 ;; Other stuff.
1416 (mdw-javascript-style)
1417 (setq js-auto-indent-flag t)
1418
1419 ;; Now define things to be fontified.
1420 (make-local-variable 'font-lock-keywords)
1421 (let ((javascript-keywords
1422 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1423 "char" "class" "const" "continue" "debugger" "default"
1424 "delete" "do" "double" "else" "enum" "export" "extends"
1425 "final" "finally" "float" "for" "function" "goto" "if"
1426 "implements" "import" "in" "instanceof" "int"
1427 "interface" "let" "long" "native" "new" "package"
1428 "private" "protected" "public" "return" "short"
1429 "static" "super" "switch" "synchronized" "throw"
1430 "throws" "transient" "try" "typeof" "var" "void"
1431 "volatile" "while" "with" "yield"
1432
1433 "boolean" "byte" "char" "double" "float" "int" "long"
1434 "short" "void"))
1435 (javascript-constants
1436 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
1437 "arguments" "this")))
1438
1439 (setq font-lock-keywords
1440 (list
1441
1442 ;; Handle the keywords defined above.
1443 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
1444 '(0 font-lock-keyword-face))
1445
1446 ;; Handle the predefined constants defined above.
1447 (list (concat "\\_<\\(" javascript-constants "\\)\\_>")
1448 '(0 font-lock-variable-name-face))
1449
1450 ;; Handle numbers too.
1451 ;;
1452 ;; The following isn't quite right, but it's close enough.
1453 (list (concat "\\_<\\("
1454 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1455 "[0-9]+\\(\\.[0-9]*\\|\\)"
1456 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1457 "[lLfFdD]?")
1458 '(0 mdw-number-face))
1459
1460 ;; And anything else is punctuation.
1461 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1462 '(0 mdw-punct-face)))))
1463
1464 (mdw-post-config-mode-hack))
1465
1466 ;;;--------------------------------------------------------------------------
1467 ;;; C# programming configuration.
1468
1469 ;; Make indentation nice.
1470
1471 (defun mdw-csharp-style ()
1472 (c-add-style "[mdw] C# style"
1473 '((c-basic-offset . 2)
1474 (c-offsets-alist (substatement-open . 0)
1475 (label . 0)
1476 (case-label . +)
1477 (access-label . 0)
1478 (inclass . +)
1479 (statement-case-intro . +)))
1480 t))
1481
1482 ;; Declare C# fontification style.
1483
1484 (defun mdw-fontify-csharp ()
1485
1486 ;; Other stuff.
1487 (mdw-csharp-style)
1488 (setq c-hanging-comment-ender-p nil)
1489 (setq c-backslash-column 72)
1490 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1491
1492 ;; Now define things to be fontified.
1493 (make-local-variable 'font-lock-keywords)
1494 (let ((csharp-keywords
1495 (mdw-regexps "abstract" "as" "base" "bool" "break"
1496 "byte" "case" "catch" "char" "checked"
1497 "class" "const" "continue" "decimal" "default"
1498 "delegate" "do" "double" "else" "enum"
1499 "event" "explicit" "extern" "false" "finally"
1500 "fixed" "float" "for" "foreach" "goto"
1501 "if" "implicit" "in" "int" "interface"
1502 "internal" "is" "lock" "long" "namespace"
1503 "new" "null" "object" "operator" "out"
1504 "override" "params" "private" "protected" "public"
1505 "readonly" "ref" "return" "sbyte" "sealed"
1506 "short" "sizeof" "stackalloc" "static" "string"
1507 "struct" "switch" "this" "throw" "true"
1508 "try" "typeof" "uint" "ulong" "unchecked"
1509 "unsafe" "ushort" "using" "virtual" "void"
1510 "volatile" "while" "yield")))
1511
1512 (setq font-lock-keywords
1513 (list
1514
1515 ;; Handle the keywords defined above.
1516 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1517 '(0 font-lock-keyword-face))
1518
1519 ;; Handle numbers too.
1520 ;;
1521 ;; The following isn't quite right, but it's close enough.
1522 (list (concat "\\<\\("
1523 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1524 "[0-9]+\\(\\.[0-9]*\\|\\)"
1525 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1526 "[lLfFdD]?")
1527 '(0 mdw-number-face))
1528
1529 ;; And anything else is punctuation.
1530 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1531 '(0 mdw-punct-face)))))
1532
1533 (mdw-post-config-mode-hack))
1534
1535 (define-derived-mode csharp-mode java-mode "C#"
1536 "Major mode for editing C# code.")
1537
1538 ;;;--------------------------------------------------------------------------
1539 ;;; F# programming configuration.
1540
1541 (setq fsharp-indent-offset 2)
1542
1543 (defun mdw-fontify-fsharp ()
1544
1545 (let ((punct "=<>+-*/|&%!@?"))
1546 (do ((i 0 (1+ i)))
1547 ((>= i (length punct)))
1548 (modify-syntax-entry (aref punct i) ".")))
1549
1550 (modify-syntax-entry ?_ "_")
1551 (modify-syntax-entry ?( "(")
1552 (modify-syntax-entry ?) ")")
1553
1554 (setq indent-tabs-mode nil)
1555
1556 (let ((fsharp-keywords
1557 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
1558 "base" "begin" "break"
1559 "checked" "class" "component" "const" "constraint"
1560 "constructor" "continue"
1561 "default" "delegate" "do" "done" "downcast" "downto"
1562 "eager" "elif" "else" "end" "exception" "extern"
1563 "false" "finally" "fixed" "for" "fori" "fun" "function"
1564 "functor"
1565 "global"
1566 "if" "in" "include" "inherit" "inline" "interface"
1567 "internal"
1568 "lazy" "let"
1569 "match" "measure" "member" "method" "mixin" "module"
1570 "mutable"
1571 "namespace" "new" "null"
1572 "object""of" "open" "or" "override"
1573 "parallel" "params" "private" "process" "protected"
1574 "public" "pure"
1575 "rec" "recursive" "return"
1576 "sealed" "sig" "static" "struct"
1577 "tailcall" "then" "to" "trait" "true" "try" "type"
1578 "upcast" "use"
1579 "val" "virtual" "void" "volatile"
1580 "when" "while" "with"
1581 "yield"))
1582
1583 (fsharp-builtins
1584 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"))
1585
1586 (bang-keywords
1587 (mdw-regexps "do" "let" "return" "use" "yield"))
1588
1589 (preprocessor-keywords
1590 (mdw-regexps "if" "indent" "else" "endif")))
1591
1592 (setq font-lock-keywords
1593 (list (list (concat "\\(^\\|[^\"]\\)"
1594 "\\(" "(\\*"
1595 "[^*]*\\*+"
1596 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
1597 ")"
1598 "\\|"
1599 "//.*"
1600 "\\)")
1601 '(2 font-lock-comment-face))
1602
1603 (list (concat "'" "\\("
1604 "\\\\"
1605 "\\(" "[ntbr'\\]"
1606 "\\|" "[0-9][0-9][0-9]"
1607 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
1608 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
1609 "\\)"
1610 "\\|"
1611 "." "\\)" "'"
1612 "\\|"
1613 "\"" "[^\"\\]*"
1614 "\\(" "\\\\" "\\(.\\|\n\\)"
1615 "[^\"\\]*" "\\)*"
1616 "\\(\"\\|\\'\\)")
1617 '(0 font-lock-string-face))
1618
1619 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
1620 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
1621 "\\|"
1622 "\\_<\\(" fsharp-keywords "\\)\\_>")
1623 '(0 font-lock-keyword-face))
1624 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
1625 '(0 font-lock-variable-name-face))
1626
1627 (list (concat "\\_<"
1628 "\\(" "0[bB][01]+" "\\|"
1629 "0[oO][0-7]+" "\\|"
1630 "0[xX][0-9a-fA-F]+" "\\)"
1631 "\\(" "lf\\|LF" "\\|"
1632 "[uU]?[ysnlL]?" "\\)"
1633 "\\|"
1634 "\\_<"
1635 "[0-9]+" "\\("
1636 "[mMQRZING]"
1637 "\\|"
1638 "\\(\\.[0-9]*\\)?"
1639 "\\([eE][-+]?[0-9]+\\)?"
1640 "[fFmM]?"
1641 "\\|"
1642 "[uU]?[ysnlL]?"
1643 "\\)")
1644 '(0 mdw-number-face))
1645
1646 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1647 '(0 mdw-punct-face)))))
1648
1649 (mdw-post-config-mode-hack))
1650
1651 (defun mdw-fontify-inferior-fsharp ()
1652 (mdw-fontify-fsharp)
1653 (setq font-lock-keywords
1654 (append (list (list "^[#-]" '(0 font-lock-comment-face))
1655 (list "^>" '(0 font-lock-keyword-face)))
1656 font-lock-keywords)))
1657
1658 ;;;--------------------------------------------------------------------------
1659 ;;; Go programming configuration.
1660
1661 (defun mdw-fontify-go ()
1662
1663 (make-local-variable 'font-lock-keywords)
1664 (let ((go-keywords
1665 (mdw-regexps "break" "case" "chan" "const" "continue"
1666 "default" "defer" "else" "fallthrough" "for"
1667 "func" "go" "goto" "if" "import"
1668 "interface" "map" "package" "range" "return"
1669 "select" "struct" "switch" "type" "var"))
1670 (go-intrinsics
1671 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
1672 "float32" "float64" "int" "uint8" "int16" "int32"
1673 "int64" "rune" "string" "uint" "uint8" "uint16"
1674 "uint32" "uint64" "uintptr" "void"
1675 "false" "iota" "nil" "true"
1676 "init" "main"
1677 "append" "cap" "copy" "delete" "imag" "len" "make"
1678 "new" "panic" "real" "recover")))
1679
1680 (setq font-lock-keywords
1681 (list
1682
1683 ;; Handle the keywords defined above.
1684 (list (concat "\\<\\(" go-keywords "\\)\\>")
1685 '(0 font-lock-keyword-face))
1686 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
1687 '(0 font-lock-variable-name-face))
1688
1689 ;; Strings and characters.
1690 (list (concat "'"
1691 "\\(" "[^\\']" "\\|"
1692 "\\\\"
1693 "\\(" "[abfnrtv\\'\"]" "\\|"
1694 "[0-7]\\{3\\}" "\\|"
1695 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
1696 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
1697 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
1698 "'"
1699 "\\|"
1700 "\""
1701 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
1702 "\\(\"\\|$\\)"
1703 "\\|"
1704 "`" "[^`]+" "`")
1705 '(0 font-lock-string-face))
1706
1707 ;; Handle numbers too.
1708 ;;
1709 ;; The following isn't quite right, but it's close enough.
1710 (list (concat "\\<\\("
1711 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1712 "[0-9]+\\(\\.[0-9]*\\|\\)"
1713 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1714 '(0 mdw-number-face))
1715
1716 ;; And anything else is punctuation.
1717 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1718 '(0 mdw-punct-face)))))
1719
1720 (mdw-post-config-mode-hack))
1721
1722 ;;;--------------------------------------------------------------------------
1723 ;;; Awk programming configuration.
1724
1725 ;; Make Awk indentation nice.
1726
1727 (defun mdw-awk-style ()
1728 (c-add-style "[mdw] Awk style"
1729 '((c-basic-offset . 2)
1730 (c-offsets-alist (substatement-open . 0)
1731 (statement-cont . 0)
1732 (statement-case-intro . +)))
1733 t))
1734
1735 ;; Declare Awk fontification style.
1736
1737 (defun mdw-fontify-awk ()
1738
1739 ;; Miscellaneous fiddling.
1740 (mdw-awk-style)
1741 (setq c-backslash-column 72)
1742 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1743
1744 ;; Now define things to be fontified.
1745 (make-local-variable 'font-lock-keywords)
1746 (let ((c-keywords
1747 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1748 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1749 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1750 "RSTART" "RLENGTH" "RT" "SUBSEP"
1751 "atan2" "break" "close" "continue" "cos" "delete"
1752 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1753 "function" "gensub" "getline" "gsub" "if" "in"
1754 "index" "int" "length" "log" "match" "next" "rand"
1755 "return" "print" "printf" "sin" "split" "sprintf"
1756 "sqrt" "srand" "strftime" "sub" "substr" "system"
1757 "systime" "tolower" "toupper" "while")))
1758
1759 (setq font-lock-keywords
1760 (list
1761
1762 ;; Handle the keywords defined above.
1763 (list (concat "\\<\\(" c-keywords "\\)\\>")
1764 '(0 font-lock-keyword-face))
1765
1766 ;; Handle numbers too.
1767 ;;
1768 ;; The following isn't quite right, but it's close enough.
1769 (list (concat "\\<\\("
1770 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1771 "[0-9]+\\(\\.[0-9]*\\|\\)"
1772 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1773 "[uUlL]*")
1774 '(0 mdw-number-face))
1775
1776 ;; And anything else is punctuation.
1777 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1778 '(0 mdw-punct-face)))))
1779
1780 (mdw-post-config-mode-hack))
1781
1782 ;;;--------------------------------------------------------------------------
1783 ;;; Perl programming style.
1784
1785 ;; Perl indentation style.
1786
1787 (fset 'perl-mode 'cperl-mode)
1788 (setq cperl-indent-level 2)
1789 (setq cperl-continued-statement-offset 2)
1790 (setq cperl-continued-brace-offset 0)
1791 (setq cperl-brace-offset -2)
1792 (setq cperl-brace-imaginary-offset 0)
1793 (setq cperl-label-offset 0)
1794
1795 ;; Define perl fontification style.
1796
1797 (defun mdw-fontify-perl ()
1798
1799 ;; Miscellaneous fiddling.
1800 (modify-syntax-entry ?$ "\\")
1801 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1802 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1803
1804 ;; Now define fontification things.
1805 (make-local-variable 'font-lock-keywords)
1806 (let ((perl-keywords
1807 (mdw-regexps "and" "break" "cmp" "continue" "do" "else" "elsif" "eq"
1808 "for" "foreach" "ge" "given" "gt" "goto" "if"
1809 "last" "le" "lt" "local" "my" "ne" "next" "or"
1810 "our" "package" "redo" "require" "return" "sub"
1811 "undef" "unless" "until" "use" "when" "while")))
1812
1813 (setq font-lock-keywords
1814 (list
1815
1816 ;; Set up the keywords defined above.
1817 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1818 '(0 font-lock-keyword-face))
1819
1820 ;; At least numbers are simpler than C.
1821 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1822 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1823 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1824 '(0 mdw-number-face))
1825
1826 ;; And anything else is punctuation.
1827 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1828 '(0 mdw-punct-face)))))
1829
1830 (mdw-post-config-mode-hack))
1831
1832 (defun perl-number-tests (&optional arg)
1833 "Assign consecutive numbers to lines containing `#t'. With ARG,
1834 strip numbers instead."
1835 (interactive "P")
1836 (save-excursion
1837 (goto-char (point-min))
1838 (let ((i 0) (fmt (if arg "" " %4d")))
1839 (while (search-forward "#t" nil t)
1840 (delete-region (point) (line-end-position))
1841 (setq i (1+ i))
1842 (insert (format fmt i)))
1843 (goto-char (point-min))
1844 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1845 (replace-match (format "\\1%d" i))))))
1846
1847 ;;;--------------------------------------------------------------------------
1848 ;;; Python programming style.
1849
1850 (defun mdw-fontify-pythonic (keywords)
1851
1852 ;; Miscellaneous fiddling.
1853 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1854 (setq indent-tabs-mode nil)
1855
1856 ;; Now define fontification things.
1857 (make-local-variable 'font-lock-keywords)
1858 (setq font-lock-keywords
1859 (list
1860
1861 ;; Set up the keywords defined above.
1862 (list (concat "\\_<\\(" keywords "\\)\\_>")
1863 '(0 font-lock-keyword-face))
1864
1865 ;; At least numbers are simpler than C.
1866 (list (concat "\\_<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1867 "\\_<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1868 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1869 '(0 mdw-number-face))
1870
1871 ;; And anything else is punctuation.
1872 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1873 '(0 mdw-punct-face))))
1874
1875 (mdw-post-config-mode-hack))
1876
1877 ;; Define Python fontification styles.
1878
1879 (defun mdw-fontify-python ()
1880 (mdw-fontify-pythonic
1881 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1882 "del" "elif" "else" "except" "exec" "finally" "for"
1883 "from" "global" "if" "import" "in" "is" "lambda"
1884 "not" "or" "pass" "print" "raise" "return" "try"
1885 "while" "with" "yield")))
1886
1887 (defun mdw-fontify-pyrex ()
1888 (mdw-fontify-pythonic
1889 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1890 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1891 "extern" "finally" "for" "from" "global" "if"
1892 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1893 "raise" "return" "struct" "try" "while" "with"
1894 "yield")))
1895
1896 ;;;--------------------------------------------------------------------------
1897 ;;; Icon programming style.
1898
1899 ;; Icon indentation style.
1900
1901 (setq icon-brace-offset 0
1902 icon-continued-brace-offset 0
1903 icon-continued-statement-offset 2
1904 icon-indent-level 2)
1905
1906 ;; Define Icon fontification style.
1907
1908 (defun mdw-fontify-icon ()
1909
1910 ;; Miscellaneous fiddling.
1911 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1912
1913 ;; Now define fontification things.
1914 (make-local-variable 'font-lock-keywords)
1915 (let ((icon-keywords
1916 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1917 "end" "every" "fail" "global" "if" "initial"
1918 "invocable" "link" "local" "next" "not" "of"
1919 "procedure" "record" "repeat" "return" "static"
1920 "suspend" "then" "to" "until" "while"))
1921 (preprocessor-keywords
1922 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1923 "include" "line" "undef")))
1924 (setq font-lock-keywords
1925 (list
1926
1927 ;; Set up the keywords defined above.
1928 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1929 '(0 font-lock-keyword-face))
1930
1931 ;; The things that Icon calls keywords.
1932 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1933
1934 ;; At least numbers are simpler than C.
1935 (list (concat "\\<[0-9]+"
1936 "\\([rR][0-9a-zA-Z]+\\|"
1937 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1938 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1939 '(0 mdw-number-face))
1940
1941 ;; Preprocessor.
1942 (list (concat "^[ \t]*$[ \t]*\\<\\("
1943 preprocessor-keywords
1944 "\\)\\>")
1945 '(0 font-lock-keyword-face))
1946
1947 ;; And anything else is punctuation.
1948 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1949 '(0 mdw-punct-face)))))
1950
1951 (mdw-post-config-mode-hack))
1952
1953 ;;;--------------------------------------------------------------------------
1954 ;;; ARM assembler programming configuration.
1955
1956 ;; There doesn't appear to be an Emacs mode for this yet.
1957 ;;
1958 ;; Better do something about that, I suppose.
1959
1960 (defvar arm-assembler-mode-map nil)
1961 (defvar arm-assembler-abbrev-table nil)
1962 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1963
1964 (or arm-assembler-mode-map
1965 (progn
1966 (setq arm-assembler-mode-map (make-sparse-keymap))
1967 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1968 (define-key arm-assembler-mode-map [C-return] 'newline)
1969 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1970
1971 (defun arm-assembler-mode ()
1972 "Major mode for ARM assembler programs"
1973 (interactive)
1974
1975 ;; Do standard major mode things.
1976 (kill-all-local-variables)
1977 (use-local-map arm-assembler-mode-map)
1978 (setq local-abbrev-table arm-assembler-abbrev-table)
1979 (setq major-mode 'arm-assembler-mode)
1980 (setq mode-name "ARM assembler")
1981
1982 ;; Set up syntax table.
1983 (set-syntax-table arm-assembler-mode-syntax-table)
1984 (modify-syntax-entry ?; ; Nasty hack
1985 "<" arm-assembler-mode-syntax-table)
1986 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1987 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1988 (modify-syntax-entry ?' "\"'" arm-assembler-mode-syntax-table)
1989
1990 (make-local-variable 'comment-start)
1991 (setq comment-start ";")
1992 (make-local-variable 'comment-end)
1993 (setq comment-end "")
1994 (make-local-variable 'comment-column)
1995 (setq comment-column 48)
1996 (make-local-variable 'comment-start-skip)
1997 (setq comment-start-skip ";+[ \t]*")
1998
1999 ;; Play with indentation.
2000 (make-local-variable 'indent-line-function)
2001 (setq indent-line-function 'indent-relative-maybe)
2002
2003 ;; Set fill prefix.
2004 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2005
2006 ;; Fiddle with fontification.
2007 (make-local-variable 'font-lock-keywords)
2008 (setq font-lock-keywords
2009 (list
2010
2011 ;; Handle numbers too.
2012 ;;
2013 ;; The following isn't quite right, but it's close enough.
2014 (list (concat "\\("
2015 "&[0-9a-fA-F]+\\|"
2016 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
2017 "\\)")
2018 '(0 mdw-number-face))
2019
2020 ;; Do something about operators.
2021 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
2022 '(1 font-lock-keyword-face)
2023 '(2 font-lock-string-face))
2024 (list ":[a-zA-Z]+:"
2025 '(0 font-lock-keyword-face))
2026
2027 ;; Do menemonics and directives.
2028 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
2029 '(1 font-lock-keyword-face))
2030
2031 ;; And anything else is punctuation.
2032 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2033 '(0 mdw-punct-face))))
2034
2035 (mdw-post-config-mode-hack)
2036 (run-hooks 'arm-assembler-mode-hook))
2037
2038 ;;;--------------------------------------------------------------------------
2039 ;;; Assembler mode.
2040
2041 (defun mdw-fontify-asm ()
2042 (modify-syntax-entry ?' "\"")
2043 (modify-syntax-entry ?. "w")
2044 (setf fill-prefix nil)
2045 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
2046
2047 ;;;--------------------------------------------------------------------------
2048 ;;; TCL configuration.
2049
2050 (defun mdw-fontify-tcl ()
2051 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
2052 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2053 (make-local-variable 'font-lock-keywords)
2054 (setq font-lock-keywords
2055 (list
2056 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2057 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2058 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2059 '(0 mdw-number-face))
2060 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2061 '(0 mdw-punct-face))))
2062 (mdw-post-config-mode-hack))
2063
2064 ;;;--------------------------------------------------------------------------
2065 ;;; Dylan programming configuration.
2066
2067 (defun mdw-fontify-dylan ()
2068
2069 (make-local-variable 'font-lock-keywords)
2070
2071 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
2072 ;; hook, which undoes all of our configuration.
2073 (setq major-mode 'dylan-mode)
2074 (font-lock-set-defaults)
2075
2076 (let* ((word "[-_a-zA-Z!*@<>$%]+")
2077 (dylan-keywords (mdw-regexps
2078
2079 "C-address" "C-callable-wrapper" "C-function"
2080 "C-mapped-subtype" "C-pointer-type" "C-struct"
2081 "C-subtype" "C-union" "C-variable"
2082
2083 "above" "abstract" "afterwards" "all"
2084 "begin" "below" "block" "by"
2085 "case" "class" "cleanup" "constant" "create"
2086 "define" "domain"
2087 "else" "elseif" "end" "exception" "export"
2088 "finally" "for" "from" "function"
2089 "generic"
2090 "handler"
2091 "if" "in" "instance" "interface" "iterate"
2092 "keyed-by"
2093 "let" "library" "local"
2094 "macro" "method" "module"
2095 "otherwise"
2096 "profiling"
2097 "select" "slot" "subclass"
2098 "table" "then" "to"
2099 "unless" "until" "use"
2100 "variable" "virtual"
2101 "when" "while"))
2102 (sharp-keywords (mdw-regexps
2103 "all-keys" "key" "next" "rest" "include"
2104 "t" "f")))
2105 (setq font-lock-keywords
2106 (list (list (concat "\\<\\(" dylan-keywords
2107 "\\|" "with\\(out\\)?-" word
2108 "\\)\\>")
2109 '(0 font-lock-keyword-face))
2110 (list (concat "\\<" word ":" "\\|"
2111 "#\\(" sharp-keywords "\\)\\>")
2112 '(0 font-lock-variable-name-face))
2113 (list (concat "\\("
2114 "\\([-+]\\|\\<\\)[0-9]+" "\\("
2115 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
2116 "\\|" "/[0-9]+"
2117 "\\)"
2118 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
2119 "\\|" "#b[01]+"
2120 "\\|" "#o[0-7]+"
2121 "\\|" "#x[0-9a-zA-Z]+"
2122 "\\)\\>")
2123 '(0 mdw-number-face))
2124 (list (concat "\\("
2125 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
2126 "\\_<[-+*/=<>:&|]+\\_>"
2127 "\\)")
2128 '(0 mdw-punct-face)))))
2129
2130 (mdw-post-config-mode-hack))
2131
2132 ;;;--------------------------------------------------------------------------
2133 ;;; Algol 68 configuration.
2134
2135 (setq a68-indent-step 2)
2136
2137 (defun mdw-fontify-algol-68 ()
2138
2139 ;; Fix up the syntax table.
2140 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
2141 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
2142 (modify-syntax-entry ch "." a68-mode-syntax-table))
2143
2144 (make-local-variable 'font-lock-keywords)
2145
2146 (let ((not-comment
2147 (let ((word "COMMENT"))
2148 (do ((regexp (concat "[^" (substring word 0 1) "]+")
2149 (concat regexp "\\|"
2150 (substring word 0 i)
2151 "[^" (substring word i (1+ i)) "]"))
2152 (i 1 (1+ i)))
2153 ((>= i (length word)) regexp)))))
2154 (setq font-lock-keywords
2155 (list (list (concat "\\<COMMENT\\>"
2156 "\\(" not-comment "\\)\\{0,5\\}"
2157 "\\(\\'\\|\\<COMMENT\\>\\)")
2158 '(0 font-lock-comment-face))
2159 (list (concat "\\<CO\\>"
2160 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
2161 "\\($\\|\\<CO\\>\\)")
2162 '(0 font-lock-comment-face))
2163 (list "\\<[A-Z_]+\\>"
2164 '(0 font-lock-keyword-face))
2165 (list (concat "\\<"
2166 "[0-9]+"
2167 "\\(\\.[0-9]+\\)?"
2168 "\\([eE][-+]?[0-9]+\\)?"
2169 "\\>")
2170 '(0 mdw-number-face))
2171 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
2172 '(0 mdw-punct-face)))))
2173
2174 (mdw-post-config-mode-hack))
2175
2176 ;;;--------------------------------------------------------------------------
2177 ;;; REXX configuration.
2178
2179 (defun mdw-rexx-electric-* ()
2180 (interactive)
2181 (insert ?*)
2182 (rexx-indent-line))
2183
2184 (defun mdw-rexx-indent-newline-indent ()
2185 (interactive)
2186 (rexx-indent-line)
2187 (if abbrev-mode (expand-abbrev))
2188 (newline-and-indent))
2189
2190 (defun mdw-fontify-rexx ()
2191
2192 ;; Various bits of fiddling.
2193 (setq mdw-auto-indent nil)
2194 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
2195 (local-set-key [?*] 'mdw-rexx-electric-*)
2196 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
2197 '(?! ?? ?# ?@ ?$))
2198 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
2199
2200 ;; Set up keywords and things for fontification.
2201 (make-local-variable 'font-lock-keywords-case-fold-search)
2202 (setq font-lock-keywords-case-fold-search t)
2203
2204 (setq rexx-indent 2)
2205 (setq rexx-end-indent rexx-indent)
2206 (setq rexx-cont-indent rexx-indent)
2207
2208 (make-local-variable 'font-lock-keywords)
2209 (let ((rexx-keywords
2210 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
2211 "else" "end" "engineering" "exit" "expose" "for"
2212 "forever" "form" "fuzz" "if" "interpret" "iterate"
2213 "leave" "linein" "name" "nop" "numeric" "off" "on"
2214 "options" "otherwise" "parse" "procedure" "pull"
2215 "push" "queue" "return" "say" "select" "signal"
2216 "scientific" "source" "then" "trace" "to" "until"
2217 "upper" "value" "var" "version" "when" "while"
2218 "with"
2219
2220 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
2221 "center" "center" "charin" "charout" "chars"
2222 "compare" "condition" "copies" "c2d" "c2x"
2223 "datatype" "date" "delstr" "delword" "d2c" "d2x"
2224 "errortext" "format" "fuzz" "insert" "lastpos"
2225 "left" "length" "lineout" "lines" "max" "min"
2226 "overlay" "pos" "queued" "random" "reverse" "right"
2227 "sign" "sourceline" "space" "stream" "strip"
2228 "substr" "subword" "symbol" "time" "translate"
2229 "trunc" "value" "verify" "word" "wordindex"
2230 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
2231 "x2d")))
2232
2233 (setq font-lock-keywords
2234 (list
2235
2236 ;; Set up the keywords defined above.
2237 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
2238 '(0 font-lock-keyword-face))
2239
2240 ;; Fontify all symbols the same way.
2241 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
2242 "[A-Za-z0-9.!?_#@$]+\\)")
2243 '(0 font-lock-variable-name-face))
2244
2245 ;; And everything else is punctuation.
2246 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2247 '(0 mdw-punct-face)))))
2248
2249 (mdw-post-config-mode-hack))
2250
2251 ;;;--------------------------------------------------------------------------
2252 ;;; Standard ML programming style.
2253
2254 (defun mdw-fontify-sml ()
2255
2256 ;; Make underscore an honorary letter.
2257 (modify-syntax-entry ?' "w")
2258
2259 ;; Set fill prefix.
2260 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
2261
2262 ;; Now define fontification things.
2263 (make-local-variable 'font-lock-keywords)
2264 (let ((sml-keywords
2265 (mdw-regexps "abstype" "and" "andalso" "as"
2266 "case"
2267 "datatype" "do"
2268 "else" "end" "eqtype" "exception"
2269 "fn" "fun" "functor"
2270 "handle"
2271 "if" "in" "include" "infix" "infixr"
2272 "let" "local"
2273 "nonfix"
2274 "of" "op" "open" "orelse"
2275 "raise" "rec"
2276 "sharing" "sig" "signature" "struct" "structure"
2277 "then" "type"
2278 "val"
2279 "where" "while" "with" "withtype")))
2280
2281 (setq font-lock-keywords
2282 (list
2283
2284 ;; Set up the keywords defined above.
2285 (list (concat "\\<\\(" sml-keywords "\\)\\>")
2286 '(0 font-lock-keyword-face))
2287
2288 ;; At least numbers are simpler than C.
2289 (list (concat "\\<\\(\\~\\|\\)"
2290 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
2291 "[wW][0-9]+\\)\\|"
2292 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
2293 "\\([eE]\\(\\~\\|\\)"
2294 "[0-9]+\\|\\)\\)\\)")
2295 '(0 mdw-number-face))
2296
2297 ;; And anything else is punctuation.
2298 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2299 '(0 mdw-punct-face)))))
2300
2301 (mdw-post-config-mode-hack))
2302
2303 ;;;--------------------------------------------------------------------------
2304 ;;; Haskell configuration.
2305
2306 (defun mdw-fontify-haskell ()
2307
2308 ;; Fiddle with syntax table to get comments right.
2309 (modify-syntax-entry ?' "_")
2310 (modify-syntax-entry ?- ". 12")
2311 (modify-syntax-entry ?\n ">")
2312
2313 ;; Make punctuation be punctuation
2314 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
2315 (do ((i 0 (1+ i)))
2316 ((>= i (length punct)))
2317 (modify-syntax-entry (aref punct i) ".")))
2318
2319 ;; Set fill prefix.
2320 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
2321
2322 ;; Fiddle with fontification.
2323 (make-local-variable 'font-lock-keywords)
2324 (let ((haskell-keywords
2325 (mdw-regexps "as"
2326 "case" "ccall" "class"
2327 "data" "default" "deriving" "do"
2328 "else" "exists"
2329 "forall" "foreign"
2330 "hiding"
2331 "if" "import" "in" "infix" "infixl" "infixr" "instance"
2332 "let"
2333 "mdo" "module"
2334 "newtype"
2335 "of"
2336 "proc"
2337 "qualified"
2338 "rec"
2339 "safe" "stdcall"
2340 "then" "type"
2341 "unsafe"
2342 "where"))
2343 (control-sequences
2344 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
2345 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
2346 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
2347 "SP" "STX" "SUB" "SYN" "US" "VT")))
2348
2349 (setq font-lock-keywords
2350 (list
2351 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
2352 "\\(-+}\\|-*\\'\\)"
2353 "\\|"
2354 "--.*$")
2355 '(0 font-lock-comment-face))
2356 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
2357 '(0 font-lock-keyword-face))
2358 (list (concat "'\\("
2359 "[^\\]"
2360 "\\|"
2361 "\\\\"
2362 "\\(" "[abfnrtv\\\"']" "\\|"
2363 "^" "\\(" control-sequences "\\|"
2364 "[]A-Z@[\\^_]" "\\)" "\\|"
2365 "\\|"
2366 "[0-9]+" "\\|"
2367 "[oO][0-7]+" "\\|"
2368 "[xX][0-9A-Fa-f]+"
2369 "\\)"
2370 "\\)'")
2371 '(0 font-lock-string-face))
2372 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
2373 '(0 font-lock-variable-name-face))
2374 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
2375 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
2376 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
2377 '(0 mdw-number-face))
2378 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2379 '(0 mdw-punct-face)))))
2380
2381 (mdw-post-config-mode-hack))
2382
2383 ;;;--------------------------------------------------------------------------
2384 ;;; Erlang configuration.
2385
2386 (setq erlang-electric-commands nil)
2387
2388 (defun mdw-fontify-erlang ()
2389
2390 ;; Set fill prefix.
2391 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
2392
2393 ;; Fiddle with fontification.
2394 (make-local-variable 'font-lock-keywords)
2395 (let ((erlang-keywords
2396 (mdw-regexps "after" "and" "andalso"
2397 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
2398 "case" "catch" "cond"
2399 "div" "end" "fun" "if" "let" "not"
2400 "of" "or" "orelse"
2401 "query" "receive" "rem" "try" "when" "xor")))
2402
2403 (setq font-lock-keywords
2404 (list
2405 (list "%.*$"
2406 '(0 font-lock-comment-face))
2407 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
2408 '(0 font-lock-keyword-face))
2409 (list (concat "^-\\sw+\\>")
2410 '(0 font-lock-keyword-face))
2411 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
2412 '(0 mdw-number-face))
2413 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2414 '(0 mdw-punct-face)))))
2415
2416 (mdw-post-config-mode-hack))
2417
2418 ;;;--------------------------------------------------------------------------
2419 ;;; Texinfo configuration.
2420
2421 (defun mdw-fontify-texinfo ()
2422
2423 ;; Set fill prefix.
2424 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
2425
2426 ;; Real fontification things.
2427 (make-local-variable 'font-lock-keywords)
2428 (setq font-lock-keywords
2429 (list
2430
2431 ;; Environment names are keywords.
2432 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
2433 '(2 font-lock-keyword-face))
2434
2435 ;; Unmark escaped magic characters.
2436 (list "\\(@\\)\\([@{}]\\)"
2437 '(1 font-lock-keyword-face)
2438 '(2 font-lock-variable-name-face))
2439
2440 ;; Make sure we get comments properly.
2441 (list "@c\\(\\|omment\\)\\( .*\\)?$"
2442 '(0 font-lock-comment-face))
2443
2444 ;; Command names are keywords.
2445 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2446 '(0 font-lock-keyword-face))
2447
2448 ;; Fontify TeX special characters as punctuation.
2449 (list "[{}]+"
2450 '(0 mdw-punct-face))))
2451
2452 (mdw-post-config-mode-hack))
2453
2454 ;;;--------------------------------------------------------------------------
2455 ;;; TeX and LaTeX configuration.
2456
2457 (defun mdw-fontify-tex ()
2458 (setq ispell-parser 'tex)
2459 (turn-on-reftex)
2460
2461 ;; Don't make maths into a string.
2462 (modify-syntax-entry ?$ ".")
2463 (modify-syntax-entry ?$ "." font-lock-syntax-table)
2464 (local-set-key [?$] 'self-insert-command)
2465
2466 ;; Set fill prefix.
2467 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
2468
2469 ;; Real fontification things.
2470 (make-local-variable 'font-lock-keywords)
2471 (setq font-lock-keywords
2472 (list
2473
2474 ;; Environment names are keywords.
2475 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
2476 "{\\([^}\n]*\\)}")
2477 '(2 font-lock-keyword-face))
2478
2479 ;; Suspended environment names are keywords too.
2480 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
2481 "{\\([^}\n]*\\)}")
2482 '(3 font-lock-keyword-face))
2483
2484 ;; Command names are keywords.
2485 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2486 '(0 font-lock-keyword-face))
2487
2488 ;; Handle @/.../ for italics.
2489 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
2490 ;; '(1 font-lock-keyword-face)
2491 ;; '(3 font-lock-keyword-face))
2492
2493 ;; Handle @*...* for boldness.
2494 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
2495 ;; '(1 font-lock-keyword-face)
2496 ;; '(3 font-lock-keyword-face))
2497
2498 ;; Handle @`...' for literal syntax things.
2499 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
2500 ;; '(1 font-lock-keyword-face)
2501 ;; '(3 font-lock-keyword-face))
2502
2503 ;; Handle @<...> for nonterminals.
2504 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
2505 ;; '(1 font-lock-keyword-face)
2506 ;; '(3 font-lock-keyword-face))
2507
2508 ;; Handle other @-commands.
2509 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
2510 ;; '(0 font-lock-keyword-face))
2511
2512 ;; Make sure we get comments properly.
2513 (list "%.*"
2514 '(0 font-lock-comment-face))
2515
2516 ;; Fontify TeX special characters as punctuation.
2517 (list "[$^_{}#&]"
2518 '(0 mdw-punct-face))))
2519
2520 (mdw-post-config-mode-hack))
2521
2522 ;;;--------------------------------------------------------------------------
2523 ;;; SGML hacking.
2524
2525 (defun mdw-sgml-mode ()
2526 (interactive)
2527 (sgml-mode)
2528 (mdw-standard-fill-prefix "")
2529 (make-local-variable 'sgml-delimiters)
2530 (setq sgml-delimiters
2531 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2532 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2533 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2534 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2535 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2536 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2537 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2538 "NULL" ""))
2539 (setq major-mode 'mdw-sgml-mode)
2540 (setq mode-name "[mdw] SGML")
2541 (run-hooks 'mdw-sgml-mode-hook))
2542
2543 ;;;--------------------------------------------------------------------------
2544 ;;; Configuration files.
2545
2546 (defvar mdw-conf-quote-normal nil
2547 "*Control syntax category of quote characters `\"' and `''.
2548 If this is `t', consider quote characters to be normal
2549 punctuation, as for `conf-quote-normal'. If this is `nil' then
2550 leave quote characters as quotes. If this is a list, then
2551 consider the quote characters in the list to be normal
2552 punctuation. If this is a single quote character, then consider
2553 that character only to be normal punctuation.")
2554 (defun mdw-conf-quote-normal-acceptable-value-p (value)
2555 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
2556 (or (booleanp value)
2557 (every (lambda (v) (memq v '(?\" ?')))
2558 (if (listp value) value (list value)))))
2559 (put 'mdw-conf-quote-normal 'safe-local-variable '
2560 mdw-conf-quote-normal-acceptable-value-p)
2561
2562 (defun mdw-fix-up-quote ()
2563 "Apply the setting of `mdw-conf-quote-normal'."
2564 (let ((flag mdw-conf-quote-normal))
2565 (cond ((eq flag t)
2566 (conf-quote-normal t))
2567 ((not flag)
2568 nil)
2569 (t
2570 (let ((table (copy-syntax-table (syntax-table))))
2571 (mapc (lambda (ch) (modify-syntax-entry ch "." table))
2572 (if (listp flag) flag (list flag)))
2573 (set-syntax-table table)
2574 (and font-lock-mode (font-lock-fontify-buffer)))))))
2575 (defun mdw-fix-up-quote-hack ()
2576 "Unpleasant hack to call `mdw-fix-up-quote' at the right time.
2577 Annoyingly, `hack-local-variables' is done after `set-auto-mode'
2578 so we wouldn't see a local-variable setting of
2579 `mdw-conf-quote-normal' in `conf-mode-hook'. Instead, wire
2580 ourselves onto `hack-local-variables-hook' here, and check the
2581 setting once it's actually been made."
2582 (add-hook 'hack-local-variables-hook 'mdw-fix-up-quote t t))
2583 (add-hook 'conf-mode-hook 'mdw-fix-up-quote-hack t)
2584
2585 ;;;--------------------------------------------------------------------------
2586 ;;; Shell scripts.
2587
2588 (defun mdw-setup-sh-script-mode ()
2589
2590 ;; Fetch the shell interpreter's name.
2591 (let ((shell-name sh-shell-file))
2592
2593 ;; Try reading the hash-bang line.
2594 (save-excursion
2595 (goto-char (point-min))
2596 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2597 (setq shell-name (match-string 1))))
2598
2599 ;; Now try to set the shell.
2600 ;;
2601 ;; Don't let `sh-set-shell' bugger up my script.
2602 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2603 (sh-set-shell shell-name)))
2604
2605 ;; Now enable my keys and the fontification.
2606 (mdw-misc-mode-config)
2607
2608 ;; Set the indentation level correctly.
2609 (setq sh-indentation 2)
2610 (setq sh-basic-offset 2))
2611
2612 (setq sh-shell-file "/bin/sh")
2613
2614 ;; Awful hacking to override the shell detection for particular scripts.
2615 (defmacro define-custom-shell-mode (name shell)
2616 `(defun ,name ()
2617 (interactive)
2618 (set (make-local-variable 'sh-shell-file) ,shell)
2619 (sh-mode)))
2620 (define-custom-shell-mode bash-mode "/bin/bash")
2621 (define-custom-shell-mode rc-mode "/usr/bin/rc")
2622 (put 'sh-shell-file 'permanent-local t)
2623
2624 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
2625 (eval-after-load "sh-script"
2626 '(or (assq 'rc sh-mode-syntax-table-input)
2627 (let ((frag '(nil
2628 ?# "<"
2629 ?\n ">#"
2630 ?\" "\"\""
2631 ?\' "\"\'"
2632 ?$ "'"
2633 ?\` "."
2634 ?! "_"
2635 ?% "_"
2636 ?. "_"
2637 ?^ "_"
2638 ?~ "_"
2639 ?, "_"
2640 ?= "."
2641 ?< "."
2642 ?> "."))
2643 (assoc (assq 'rc sh-mode-syntax-table-input)))
2644 (if assoc
2645 (rplacd assoc frag)
2646 (setq sh-mode-syntax-table-input
2647 (cons (cons 'rc frag)
2648 sh-mode-syntax-table-input))))))
2649
2650 ;;;--------------------------------------------------------------------------
2651 ;;; Emacs shell mode.
2652
2653 (defun mdw-eshell-prompt ()
2654 (let ((left "[") (right "]"))
2655 (when (= (user-uid) 0)
2656 (setq left "«" right "»"))
2657 (concat left
2658 (save-match-data
2659 (replace-regexp-in-string "\\..*$" "" (system-name)))
2660 " "
2661 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
2662 (home (expand-file-name "~")) (nhome (length home)))
2663 (if (and (>= npwd nhome)
2664 (or (= nhome npwd)
2665 (= (elt pwd nhome) ?/))
2666 (string= (substring pwd 0 nhome) home))
2667 (concat "~" (substring pwd (length home)))
2668 pwd))
2669 right)))
2670 (setq eshell-prompt-function 'mdw-eshell-prompt)
2671 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
2672
2673 (defun eshell/e (file) (find-file file) nil)
2674 (defun eshell/ee (file) (find-file-other-window file) nil)
2675 (defun eshell/w3m (url) (w3m-goto-url url) nil)
2676
2677 (mdw-define-face eshell-prompt (t :weight bold))
2678 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2679 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2680 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2681 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2682 (mdw-define-face eshell-ls-executable (t :weight bold))
2683 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2684 (mdw-define-face eshell-ls-readonly (t nil))
2685 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2686
2687 ;;;--------------------------------------------------------------------------
2688 ;;; Messages-file mode.
2689
2690 (defun messages-mode-guts ()
2691 (setq messages-mode-syntax-table (make-syntax-table))
2692 (set-syntax-table messages-mode-syntax-table)
2693 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2694 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2695 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2696 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2697 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2698 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2699 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2700 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2701 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2702 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2703 (make-local-variable 'comment-start)
2704 (make-local-variable 'comment-end)
2705 (make-local-variable 'indent-line-function)
2706 (setq indent-line-function 'indent-relative)
2707 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2708 (make-local-variable 'font-lock-defaults)
2709 (make-local-variable 'messages-mode-keywords)
2710 (let ((keywords
2711 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2712 "export" "enum" "fixed-octetstring" "flags"
2713 "harmless" "map" "nested" "optional"
2714 "optional-tagged" "package" "primitive"
2715 "primitive-nullfree" "relaxed[ \t]+enum"
2716 "set" "table" "tagged-optional" "union"
2717 "variadic" "vector" "version" "version-tag")))
2718 (setq messages-mode-keywords
2719 (list
2720 (list (concat "\\<\\(" keywords "\\)\\>:")
2721 '(0 font-lock-keyword-face))
2722 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2723 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2724 (0 font-lock-variable-name-face))
2725 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2726 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2727 (0 mdw-punct-face)))))
2728 (setq font-lock-defaults
2729 '(messages-mode-keywords nil nil nil nil))
2730 (run-hooks 'messages-file-hook))
2731
2732 (defun messages-mode ()
2733 (interactive)
2734 (fundamental-mode)
2735 (setq major-mode 'messages-mode)
2736 (setq mode-name "Messages")
2737 (messages-mode-guts)
2738 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2739 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2740 (setq comment-start "# ")
2741 (setq comment-end "")
2742 (run-hooks 'messages-mode-hook))
2743
2744 (defun cpp-messages-mode ()
2745 (interactive)
2746 (fundamental-mode)
2747 (setq major-mode 'cpp-messages-mode)
2748 (setq mode-name "CPP Messages")
2749 (messages-mode-guts)
2750 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2751 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2752 (setq comment-start "/* ")
2753 (setq comment-end " */")
2754 (let ((preprocessor-keywords
2755 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2756 "ident" "if" "ifdef" "ifndef" "import" "include"
2757 "line" "pragma" "unassert" "undef" "warning")))
2758 (setq messages-mode-keywords
2759 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2760 "\\(include\\|import\\)"
2761 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2762 '(2 font-lock-string-face))
2763 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2764 preprocessor-keywords
2765 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2766 '(1 font-lock-keyword-face)))
2767 messages-mode-keywords)))
2768 (run-hooks 'cpp-messages-mode-hook))
2769
2770 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2771 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2772 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2773
2774 ;;;--------------------------------------------------------------------------
2775 ;;; Messages-file mode.
2776
2777 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2778 "Face to use for subsittution directives.")
2779 (make-face 'mallow-driver-substitution-face)
2780 (defvar mallow-driver-text-face 'mallow-driver-text-face
2781 "Face to use for body text.")
2782 (make-face 'mallow-driver-text-face)
2783
2784 (defun mallow-driver-mode ()
2785 (interactive)
2786 (fundamental-mode)
2787 (setq major-mode 'mallow-driver-mode)
2788 (setq mode-name "Mallow driver")
2789 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2790 (set-syntax-table mallow-driver-mode-syntax-table)
2791 (make-local-variable 'comment-start)
2792 (make-local-variable 'comment-end)
2793 (make-local-variable 'indent-line-function)
2794 (setq indent-line-function 'indent-relative)
2795 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2796 (make-local-variable 'font-lock-defaults)
2797 (make-local-variable 'mallow-driver-mode-keywords)
2798 (let ((keywords
2799 (mdw-regexps "each" "divert" "file" "if"
2800 "perl" "set" "string" "type" "write")))
2801 (setq mallow-driver-mode-keywords
2802 (list
2803 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2804 '(0 font-lock-keyword-face))
2805 (list "^%\\s *\\(#.*\\|\\)$"
2806 '(0 font-lock-comment-face))
2807 (list "^%"
2808 '(0 font-lock-keyword-face))
2809 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2810 (list "\\${[^}]*}"
2811 '(0 mallow-driver-substitution-face t)))))
2812 (setq font-lock-defaults
2813 '(mallow-driver-mode-keywords nil nil nil nil))
2814 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2815 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2816 (setq comment-start "%# ")
2817 (setq comment-end "")
2818 (run-hooks 'mallow-driver-mode-hook))
2819
2820 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2821
2822 ;;;--------------------------------------------------------------------------
2823 ;;; NFast debugs.
2824
2825 (defun nfast-debug-mode ()
2826 (interactive)
2827 (fundamental-mode)
2828 (setq major-mode 'nfast-debug-mode)
2829 (setq mode-name "NFast debug")
2830 (setq messages-mode-syntax-table (make-syntax-table))
2831 (set-syntax-table messages-mode-syntax-table)
2832 (make-local-variable 'font-lock-defaults)
2833 (make-local-variable 'nfast-debug-mode-keywords)
2834 (setq truncate-lines t)
2835 (setq nfast-debug-mode-keywords
2836 (list
2837 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2838 (0 font-lock-keyword-face))
2839 (list (concat "^[ \t]+\\(\\("
2840 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2841 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2842 "[ \t]+\\)*"
2843 "[0-9a-fA-F]+\\)[ \t]*$")
2844 '(0 mdw-number-face))
2845 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2846 (1 font-lock-keyword-face))
2847 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2848 (1 font-lock-warning-face))
2849 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2850 (1 nil))
2851 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2852 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2853 '(1 font-lock-keyword-face))
2854 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2855 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2856 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2857 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2858 (setq font-lock-defaults
2859 '(nfast-debug-mode-keywords nil nil nil nil))
2860 (run-hooks 'nfast-debug-mode-hook))
2861
2862 ;;;--------------------------------------------------------------------------
2863 ;;; Other languages.
2864
2865 ;; Smalltalk.
2866
2867 (defun mdw-setup-smalltalk ()
2868 (and mdw-auto-indent
2869 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2870 (make-local-variable 'mdw-auto-indent)
2871 (setq mdw-auto-indent nil)
2872 (local-set-key "\C-i" 'smalltalk-reindent))
2873
2874 (defun mdw-fontify-smalltalk ()
2875 (make-local-variable 'font-lock-keywords)
2876 (setq font-lock-keywords
2877 (list
2878 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2879 '(0 font-lock-keyword-face))
2880 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2881 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2882 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2883 '(0 mdw-number-face))
2884 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2885 '(0 mdw-punct-face))))
2886 (mdw-post-config-mode-hack))
2887
2888 ;; Lispy languages.
2889
2890 ;; Unpleasant bodge.
2891 (unless (boundp 'slime-repl-mode-map)
2892 (setq slime-repl-mode-map (make-sparse-keymap)))
2893
2894 (defun mdw-indent-newline-and-indent ()
2895 (interactive)
2896 (indent-for-tab-command)
2897 (newline-and-indent))
2898
2899 (eval-after-load "cl-indent"
2900 '(progn
2901 (mapc #'(lambda (pair)
2902 (put (car pair)
2903 'common-lisp-indent-function
2904 (cdr pair)))
2905 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2906 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2907
2908 (defun mdw-common-lisp-indent ()
2909 (make-local-variable 'lisp-indent-function)
2910 (setq lisp-indent-function 'common-lisp-indent-function))
2911
2912 (setq lisp-simple-loop-indentation 2
2913 lisp-loop-keyword-indentation 6
2914 lisp-loop-forms-indentation 6)
2915
2916 (defun mdw-fontify-lispy ()
2917
2918 ;; Set fill prefix.
2919 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2920
2921 ;; Not much fontification needed.
2922 (make-local-variable 'font-lock-keywords)
2923 (setq font-lock-keywords
2924 (list (list (concat "\\("
2925 "\\_<[-+]?"
2926 "\\(" "[0-9]+/[0-9]+"
2927 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
2928 "\\.[0-9]+" "\\)"
2929 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
2930 "\\)"
2931 "\\|"
2932 "#"
2933 "\\(" "x" "[-+]?"
2934 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
2935 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
2936 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
2937 "\\|" "[0-9]+" "r" "[-+]?"
2938 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
2939 "\\)"
2940 "\\)\\_>")
2941 '(0 mdw-number-face))
2942 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2943 '(0 mdw-punct-face))))
2944
2945 (mdw-post-config-mode-hack))
2946
2947 (defun comint-send-and-indent ()
2948 (interactive)
2949 (comint-send-input)
2950 (and mdw-auto-indent
2951 (indent-for-tab-command)))
2952
2953 (defun mdw-setup-m4 ()
2954 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2955
2956 ;;;--------------------------------------------------------------------------
2957 ;;; Text mode.
2958
2959 (defun mdw-text-mode ()
2960 (setq fill-column 72)
2961 (flyspell-mode t)
2962 (mdw-standard-fill-prefix
2963 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2964 (auto-fill-mode 1))
2965
2966 ;;;--------------------------------------------------------------------------
2967 ;;; Outline and hide/show modes.
2968
2969 (defun mdw-outline-collapse-all ()
2970 "Completely collapse everything in the entire buffer."
2971 (interactive)
2972 (save-excursion
2973 (goto-char (point-min))
2974 (while (< (point) (point-max))
2975 (hide-subtree)
2976 (forward-line))))
2977
2978 (setq hs-hide-comments-when-hiding-all nil)
2979
2980 (defadvice hs-hide-all (after hide-first-comment activate)
2981 (save-excursion (hs-hide-initial-comment-block)))
2982
2983 ;;;--------------------------------------------------------------------------
2984 ;;; Shell mode.
2985
2986 (defun mdw-sh-mode-setup ()
2987 (local-set-key [?\C-a] 'comint-bol)
2988 (add-hook 'comint-output-filter-functions
2989 'comint-watch-for-password-prompt))
2990
2991 (defun mdw-term-mode-setup ()
2992 (setq term-prompt-regexp shell-prompt-pattern)
2993 (make-local-variable 'mouse-yank-at-point)
2994 (make-local-variable 'transient-mark-mode)
2995 (setq mouse-yank-at-point t)
2996 (auto-fill-mode -1)
2997 (setq tab-width 8))
2998
2999 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
3000 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
3001 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
3002 (defun term-send-meta-meta-something ()
3003 (interactive)
3004 (term-send-raw-string "\e\e")
3005 (term-send-raw))
3006 (eval-after-load 'term
3007 '(progn
3008 (define-key term-raw-map [?\e ?\e] nil)
3009 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
3010 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
3011 (define-key term-raw-map [M-right] 'term-send-meta-right)
3012 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
3013 (define-key term-raw-map [M-left] 'term-send-meta-left)
3014 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
3015
3016 (defadvice term-exec (before program-args-list compile activate)
3017 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
3018 This allows you to pass a list of arguments through `ansi-term'."
3019 (let ((program (ad-get-arg 2)))
3020 (if (listp program)
3021 (progn
3022 (ad-set-arg 2 (car program))
3023 (ad-set-arg 4 (cdr program))))))
3024
3025 (defun ssh (host)
3026 "Open a terminal containing an ssh session to the HOST."
3027 (interactive "sHost: ")
3028 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
3029
3030 ;;;--------------------------------------------------------------------------
3031 ;;; Inferior Emacs Lisp.
3032
3033 (setq comint-prompt-read-only t)
3034
3035 (eval-after-load "comint"
3036 '(progn
3037 (define-key comint-mode-map "\C-w" 'comint-kill-region)
3038 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
3039
3040 (eval-after-load "ielm"
3041 '(progn
3042 (define-key ielm-map "\C-w" 'comint-kill-region)
3043 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
3044
3045 ;;;----- That's all, folks --------------------------------------------------
3046
3047 (provide 'dot-emacs)