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