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