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