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