chiark / gitweb /
emacs: Turn off annoying `help' message in file chooser.
[profile] / 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
c7a8da49
MW
24;;;----- Check command-line -------------------------------------------------
25
26(defvar mdw-fast-startup nil
27 "Whether .emacs should optimize for rapid startup.
28This may be at the expense of cool features.")
29(let ((probe nil) (next command-line-args))
c7a8da49
MW
30 (while next
31 (cond ((string= (car next) "--mdw-fast-startup")
32 (setq mdw-fast-startup t)
33 (if probe
34 (rplacd probe (cdr next))
35 (setq command-line-args (cdr next))))
36 (t
37 (setq probe next)))
38 (setq next (cdr next))))
39
f617db13
MW
40;;;----- Some general utilities ---------------------------------------------
41
417dcddd
MW
42(eval-when-compile
43 (unless (fboundp 'make-regexp)
44 (load "make-regexp"))
45 (require 'cl))
c7a8da49
MW
46
47(defmacro mdw-regexps (&rest list)
48 "Turn a LIST of strings into a single regular expression at compile-time."
417dcddd 49 `',(make-regexp list))
c7a8da49 50
f617db13
MW
51;; --- Some error trapping ---
52;;
53;; If individual bits of this file go tits-up, we don't particularly want
54;; the whole lot to stop right there and then, because it's bloody annoying.
55
56(defmacro trap (&rest forms)
57 "Execute FORMS without allowing errors to propagate outside."
58 `(condition-case err
59 ,(if (cdr forms) (cons 'progn forms) (car forms))
8df912e4
MW
60 (error (message "Error (trapped): %s in %s"
61 (error-message-string err)
62 ',forms))))
f617db13 63
f141fe0f
MW
64;; --- Configuration reading ---
65
66(defvar mdw-config nil)
67(defun mdw-config (sym)
68 "Read the configuration variable named SYM."
69 (unless mdw-config
daff679f
MW
70 (setq mdw-config
71 (flet ((replace (what with)
72 (goto-char (point-min))
73 (while (re-search-forward what nil t)
74 (replace-match with t))))
75 (with-temp-buffer
76 (insert-file-contents "~/.mdw.conf")
77 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
78 (replace (concat "^[ \t]*"
79 "\\([-a-zA-Z0-9_.]*\\)"
80 "[ \t]*=[ \t]*"
81 "\\(.*[^ \t\n]\\|\\)"
82 "[ \t]**\\(\n\\|$\\)")
83 "(\\1 . \"\\2\")\n")
84 (car (read-from-string
85 (concat "(" (buffer-string) ")")))))))
f141fe0f
MW
86 (cdr (assq sym mdw-config)))
87
eac7b622
MW
88;; --- Set up the load path convincingly ---
89
90(dolist (dir (append (and (boundp 'debian-emacs-flavor)
91 (list (concat "/usr/share/"
92 (symbol-name debian-emacs-flavor)
93 "/site-lisp")))))
94 (dolist (sub (directory-files dir t))
95 (when (and (file-accessible-directory-p sub)
96 (not (member sub load-path)))
97 (setq load-path (nconc load-path (list sub))))))
98
cb6e2cd1
MW
99;; --- Is an Emacs library available? ---
100
101(defun library-exists-p (name)
102 "Return non-nil if NAME.el (or NAME.elc) is somewhere on the Emacs load
103path. The non-nil value is the filename we found for the library."
104 (let ((path load-path) elt (foundp nil))
105 (while (and path (not foundp))
106 (setq elt (car path))
107 (setq path (cdr path))
108 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
109 (and (file-exists-p file) file))
110 (let ((file (concat elt "/" name ".el")))
111 (and (file-exists-p file) file)))))
112 foundp))
113
114(defun maybe-autoload (symbol file &optional docstring interactivep type)
115 "Set an autoload if the file actually exists."
116 (and (library-exists-p file)
117 (autoload symbol file docstring interactivep type)))
118
f617db13
MW
119;; --- Splitting windows ---
120
8c2b05d5
MW
121(unless (fboundp 'scroll-bar-columns)
122 (defun scroll-bar-columns (side)
123 (cond ((eq side 'left) 0)
124 (window-system 3)
125 (t 1))))
126(unless (fboundp 'fringe-columns)
127 (defun fringe-columns (side)
128 (cond ((not window-system) 0)
129 ((eq side 'left) 1)
130 (t 2))))
131
132(defun mdw-divvy-window (&optional width)
f617db13 133 "Split a wide window into appropriate widths."
8c2b05d5
MW
134 (interactive "P")
135 (setq width (cond (width (prefix-numeric-value width))
136 ((and window-system
137 (>= emacs-major-version 22))
138 77)
139 (t 78)))
b5d724dd
MW
140 (let* ((win (selected-window))
141 (sb-width (if (not window-system)
142 1
8c2b05d5
MW
143 (let ((tot 0))
144 (dolist (what '(scroll-bar fringe))
145 (dolist (side '(left right))
146 (incf tot
147 (funcall (intern (concat (symbol-name what)
148 "-columns"))
149 side))))
150 tot)))
b5d724dd 151 (c (/ (+ (window-width) sb-width)
8c2b05d5 152 (+ width sb-width))))
f617db13
MW
153 (while (> c 1)
154 (setq c (1- c))
8c2b05d5 155 (split-window-horizontally (+ width sb-width))
f617db13
MW
156 (other-window 1))
157 (select-window win)))
158
159;; --- Functions for sexp diary entries ---
160
161(defun mdw-weekday (l)
162 "Return non-nil if `date' falls on one of the days of the week in L.
163
164L is a list of day numbers (from 0 to 6 for Sunday through to Saturday) or
165symbols `sunday', `monday', etc. (or a mixture). If the date stored in
166`date' falls on a listed day, then the function returns non-nil."
167 (let ((d (calendar-day-of-week date)))
168 (or (memq d l)
169 (memq (nth d '(sunday monday tuesday wednesday
170 thursday friday saturday)) l))))
171
172(defun mdw-todo (&optional when)
173 "Return non-nil today, or on WHEN, whichever is later."
174 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
175 (d (calendar-absolute-from-gregorian date)))
176 (if when
177 (setq w (max w (calendar-absolute-from-gregorian
178 (cond
179 ((not european-calendar-style)
180 when)
181 ((> (car when) 100)
182 (list (nth 1 when)
183 (nth 2 when)
184 (nth 0 when)))
185 (t
186 (list (nth 1 when)
187 (nth 0 when)
188 (nth 2 when))))))))
189 (eq w d)))
190
16fe7c41
MW
191;; --- Fighting with Org-mode's evil key maps ---
192
193(defvar mdw-evil-keymap-keys
194 '(([S-up] . [?\C-c up])
195 ([S-down] . [?\C-c down])
196 ([S-left] . [?\C-c left])
197 ([S-right] . [?\C-c right])
198 (([M-up] [?\e up]) . [C-up])
199 (([M-down] [?\e down]) . [C-down])
200 (([M-left] [?\e left]) . [C-left])
201 (([M-right] [?\e right]) . [C-right]))
202 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
203The value is an alist mapping evil keys (as a list, or singleton)
204to good keys (in the same form).")
205
206(defun mdw-clobber-evil-keymap (keymap)
207 "Replace evil key bindings in the KEYMAP.
208Evil key bindings are defined in `mdw-evil-keymap-keys'."
209 (dolist (entry mdw-evil-keymap-keys)
210 (let ((binding nil)
211 (keys (if (listp (car entry))
212 (car entry)
213 (list (car entry))))
214 (replacements (if (listp (cdr entry))
215 (cdr entry)
216 (list (cdr entry)))))
217 (catch 'found
218 (dolist (key keys)
219 (setq binding (lookup-key keymap key))
220 (when binding
221 (throw 'found nil))))
222 (when binding
223 (dolist (key keys)
224 (define-key keymap key nil))
225 (dolist (key replacements)
226 (define-key keymap key binding))))))
227
a3bdb4d9
MW
228;;;----- Mail and news hacking ----------------------------------------------
229
230(define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
231 "Major mode for editing news and mail messages from external programs
232Not much right now. Just support for doing MailCrypt stuff."
233 :syntax-table nil
234 :abbrev-table nil
235 (run-hooks 'mail-setup-hook))
236
237(define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
238
239(add-hook 'mdwail-mode-hook
240 (lambda ()
241 (set-buffer-file-coding-system 'utf-8)
242 (make-local-variable 'paragraph-separate)
243 (make-local-variable 'paragraph-start)
244 (setq paragraph-start
245 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
246 paragraph-start))
247 (setq paragraph-separate
248 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
249 paragraph-separate))))
250
251;; --- How to encrypt in mdwmail ---
252
253(defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
254 (or start
255 (setq start (save-excursion
256 (goto-char (point-min))
257 (or (search-forward "\n\n" nil t) (point-min)))))
258 (or end
259 (setq end (point-max)))
260 (mc-encrypt-generic recip scm start end from sign))
261
262;; --- How to sign in mdwmail ---
263
264(defun mdwmail-mc-sign (key scm start end uclr)
265 (or start
266 (setq start (save-excursion
267 (goto-char (point-min))
268 (or (search-forward "\n\n" nil t) (point-min)))))
269 (or end
270 (setq end (point-max)))
271 (mc-sign-generic key scm start end uclr))
272
273;; --- Some signature mangling ---
274
275(defun mdwmail-mangle-signature ()
276 (save-excursion
277 (goto-char (point-min))
278 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
279(add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
280(add-hook 'message-setup-hook 'mdwmail-mangle-signature)
281
282;; --- Insert my login name into message-ids, so I can score replies ---
283
284(defadvice message-unique-id (after mdw-user-name last activate compile)
285 "Ensure that the user's name appears at the end of the message-id string,
286so that it can be used for convenient filtering."
287 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
288
289;; --- Tell my movemail hack where movemail is ---
290;;
291;; This is needed to shup up warnings about LD_PRELOAD.
292
293(let ((path exec-path))
294 (while path
295 (let ((try (expand-file-name "movemail" (car path))))
296 (if (file-executable-p try)
297 (setenv "REAL_MOVEMAIL" try))
298 (setq path (cdr path)))))
299
f617db13
MW
300;;;----- Utility functions --------------------------------------------------
301
b5d724dd
MW
302(or (fboundp 'line-number-at-pos)
303 (defun line-number-at-pos (&optional pos)
304 (let ((opoint (or pos (point))) start)
305 (save-excursion
306 (save-restriction
307 (goto-char (point-min))
308 (widen)
309 (forward-line 0)
310 (setq start (point))
311 (goto-char opoint)
312 (forward-line 0)
313 (1+ (count-lines 1 (point))))))))
459c9fb2 314
f617db13
MW
315;; --- mdw-uniquify-alist ---
316
317(defun mdw-uniquify-alist (&rest alists)
318
319 "Return the concatenation of the ALISTS with duplicate elements removed.
320
321The first association with a given key prevails; others are ignored. The
322input lists are not modified, although they'll probably become garbage."
323
324 (and alists
325 (let ((start-list (cons nil nil)))
326 (mdw-do-uniquify start-list
327 start-list
328 (car alists)
329 (cdr alists)))))
330
331;; --- mdw-do-uniquify ---
332;;
333;; The DONE argument is a list whose first element is `nil'. It contains the
334;; uniquified alist built so far. The leading `nil' is stripped off at the
335;; end of the operation; it's only there so that DONE always references a
336;; cons cell. END refers to the final cons cell in the DONE list; it is
337;; modified in place each time to avoid the overheads of `append'ing all the
338;; time. The L argument is the alist we're currently processing; the
339;; remaining alists are given in REST.
340
341(defun mdw-do-uniquify (done end l rest)
342 "A helper function for mdw-uniquify-alist."
343
344 ;; --- There are several different cases to deal with here ---
345
346 (cond
347
348 ;; --- Current list isn't empty ---
349 ;;
350 ;; Add the first item to the DONE list if there's not an item with the
351 ;; same KEY already there.
352
353 (l (or (assoc (car (car l)) done)
354 (progn
355 (setcdr end (cons (car l) nil))
356 (setq end (cdr end))))
357 (mdw-do-uniquify done end (cdr l) rest))
358
359 ;; --- The list we were working on is empty ---
360 ;;
361 ;; Shunt the next list into the current list position and go round again.
362
363 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
364
365 ;; --- Everything's done ---
366 ;;
367 ;; Remove the leading `nil' from the DONE list and return it. Finished!
368
369 (t (cdr done))))
370
371;; --- Insert a date ---
372
373(defun date ()
374 "Insert the current date in a pleasing way."
375 (interactive)
376 (insert (save-excursion
377 (let ((buffer (get-buffer-create "*tmp*")))
378 (unwind-protect (progn (set-buffer buffer)
379 (erase-buffer)
380 (shell-command "date +%Y-%m-%d" t)
381 (goto-char (mark))
382 (delete-backward-char 1)
383 (buffer-string))
384 (kill-buffer buffer))))))
385
386;; --- UUencoding ---
387
388(defun uuencode (file &optional name)
389 "UUencodes a file, maybe calling it NAME, into the current buffer."
390 (interactive "fInput file name: ")
391
392 ;; --- If NAME isn't specified, then guess from the filename ---
393
394 (if (not name)
395 (setq name
396 (substring file
397 (or (string-match "[^/]*$" file) 0))))
398
399 (print (format "uuencode `%s' `%s'" file name))
400
401 ;; --- Now actually do the thing ---
402
403 (call-process "uuencode" file t nil name))
404
405(defvar np-file "~/.np"
406 "*Where the `now-playing' file is.")
407
408(defun np (&optional arg)
409 "Grabs a `now-playing' string."
410 (interactive)
411 (save-excursion
412 (or arg (progn
852cd5fb 413 (goto-char (point-max))
f617db13 414 (insert "\nNP: ")
daff679f 415 (insert-file-contents np-file)))))
f617db13 416
c7a8da49
MW
417(defun mdw-check-autorevert ()
418 "Sets global-auto-revert-ignore-buffer appropriately for this buffer,
419taking into consideration whether it's been found using tramp, which seems to
420get itself into a twist."
46e69f55
MW
421 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
422 nil)
423 ((and (buffer-file-name)
424 (fboundp 'tramp-tramp-file-p)
c7a8da49
MW
425 (tramp-tramp-file-p (buffer-file-name)))
426 (unless global-auto-revert-ignore-buffer
427 (setq global-auto-revert-ignore-buffer 'tramp)))
428 ((eq global-auto-revert-ignore-buffer 'tramp)
429 (setq global-auto-revert-ignore-buffer nil))))
430
431(defadvice find-file (after mdw-autorevert activate)
432 (mdw-check-autorevert))
433(defadvice write-file (after mdw-autorevert activate)
4d9f2d65 434 (mdw-check-autorevert))
eae0aa6d 435
5195cbc3
MW
436;;;----- Dired hacking ------------------------------------------------------
437
438(defadvice dired-maybe-insert-subdir
439 (around mdw-marked-insertion first activate)
440 "The DIRNAME may be a list of directory names to insert. Interactively, if
441files are marked, then insert all of them. With a numeric prefix argument,
442select that many entries near point; with a non-numeric prefix argument,
443prompt for listing options."
444 (interactive
445 (list (dired-get-marked-files nil
446 (and (integerp current-prefix-arg)
447 current-prefix-arg)
448 #'file-directory-p)
449 (and current-prefix-arg
450 (not (integerp current-prefix-arg))
451 (read-string "Switches for listing: "
452 (or dired-subdir-switches
453 dired-actual-switches)))))
454 (let ((dirs (ad-get-arg 0)))
455 (dolist (dir (if (listp dirs) dirs (list dirs)))
456 (ad-set-arg 0 dir)
457 ad-do-it)))
458
a203fba8
MW
459;;;----- URL viewing --------------------------------------------------------
460
461(defun mdw-w3m-browse-url (url &optional new-session-p)
462 "Invoke w3m on the URL in its current window, or at least a different one.
463If NEW-SESSION-P, start a new session."
464 (interactive "sURL: \nP")
465 (save-excursion
63fb20c1
MW
466 (let ((window (selected-window)))
467 (unwind-protect
468 (progn
469 (select-window (or (and (not new-session-p)
470 (get-buffer-window "*w3m*"))
471 (progn
472 (if (one-window-p t) (split-window))
473 (get-lru-window))))
474 (w3m-browse-url url new-session-p))
475 (select-window window)))))
a203fba8
MW
476
477(defvar mdw-good-url-browsers
478 '((w3m . mdw-w3m-browse-url)
479 browse-url-w3
480 browse-url-mozilla)
481 "List of good browsers for mdw-good-url-browsers; each item is a browser
482function name, or a cons (CHECK . FUNC). A symbol FOO stands for (FOO
483. FOO).")
484
485(defun mdw-good-url-browser ()
486 "Return a good URL browser. Trundle the list of such things, finding the
487first item for which CHECK is fboundp, and returning the correponding FUNC."
488 (let ((bs mdw-good-url-browsers) b check func answer)
489 (while (and bs (not answer))
490 (setq b (car bs)
491 bs (cdr bs))
492 (if (consp b)
493 (setq check (car b) func (cdr b))
494 (setq check b func b))
495 (if (fboundp check)
496 (setq answer func)))
497 answer))
498
f617db13
MW
499;;;----- Paragraph filling --------------------------------------------------
500
501;; --- Useful variables ---
502
503(defvar mdw-fill-prefix nil
504 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'. If there's
505no fill prefix currently set (by the `fill-prefix' variable) and there's
506a match from one of the regexps here, it gets used to set the fill-prefix
507for the current operation.
508
509The variable is a list of items of the form `REGEXP . PREFIX'; if the
510REGEXP matches, the PREFIX is used to set the fill prefix. It in turn is
511a list of things:
512
513 STRING -- insert a literal string
514 (match . N) -- insert the thing matched by bracketed subexpression N
515 (pad . N) -- a string of whitespace the same width as subexpression N
516 (expr . FORM) -- the result of evaluating FORM")
517
518(make-variable-buffer-local 'mdw-fill-prefix)
519
520(defvar mdw-hanging-indents
10fa2414
MW
521 (concat "\\(\\("
522 "\\([*o]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
523 "[ \t]+"
524 "\\)?\\)")
f617db13
MW
525 "*Standard regular expression matching things which might be part of a
526hanging indent. This is mainly useful in `auto-fill-mode'.")
527
528;; --- Setting things up ---
529
530(fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
531
532;; --- Utility functions ---
533
534(defun mdw-tabify (s)
535 "Tabify the string S. This is a horrid hack."
536 (save-excursion
537 (save-match-data
538 (let (start end)
539 (beginning-of-line)
540 (setq start (point-marker))
541 (insert s "\n")
542 (setq end (point-marker))
543 (tabify start end)
544 (setq s (buffer-substring start (1- end)))
545 (delete-region start end)
546 (set-marker start nil)
547 (set-marker end nil)
548 s))))
549
550(defun mdw-examine-fill-prefixes (l)
551 "Given a list of dynamic fill prefixes, pick one which matches context and
552return the static fill prefix to use. Point must be at the start of a line,
553and match data must be saved."
554 (cond ((not l) nil)
555 ((looking-at (car (car l)))
556 (mdw-tabify (apply (function concat)
557 (mapcar (function mdw-do-prefix-match)
558 (cdr (car l))))))
559 (t (mdw-examine-fill-prefixes (cdr l)))))
560
561(defun mdw-maybe-car (p)
562 "If P is a pair, return (car P), otherwise just return P."
563 (if (consp p) (car p) p))
564
565(defun mdw-padding (s)
566 "Return a string the same width as S but made entirely from whitespace."
567 (let* ((l (length s)) (i 0) (n (make-string l ? )))
568 (while (< i l)
569 (if (= 9 (aref s i))
570 (aset n i 9))
571 (setq i (1+ i)))
572 n))
573
574(defun mdw-do-prefix-match (m)
575 "Expand a dynamic prefix match element. See `mdw-fill-prefix' for
576details."
577 (cond ((not (consp m)) (format "%s" m))
578 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
579 ((eq (car m) 'pad) (mdw-padding (match-string
580 (mdw-maybe-car (cdr m)))))
581 ((eq (car m) 'eval) (eval (cdr m)))
582 (t "")))
583
584(defun mdw-choose-dynamic-fill-prefix ()
585 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
586 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
587 ((not mdw-fill-prefix) fill-prefix)
588 (t (save-excursion
589 (beginning-of-line)
590 (save-match-data
591 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
592
593(defun do-auto-fill ()
594 "Handle auto-filling, working out a dynamic fill prefix in the case where
595there isn't a sensible static one."
596 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
597 (mdw-do-auto-fill)))
598
599(defun mdw-fill-paragraph ()
600 "Fill paragraph, getting a dynamic fill prefix."
601 (interactive)
602 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
603 (fill-paragraph nil)))
604
605(defun mdw-standard-fill-prefix (rx &optional mat)
606 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
607This is just a short-cut for setting the thing by hand, and by design it
608doesn't cope with anything approximating a complicated case."
609 (setq mdw-fill-prefix
610 `((,(concat rx mdw-hanging-indents)
611 (match . 1)
612 (pad . ,(or mat 2))))))
613
614;;;----- Other common declarations ------------------------------------------
615
f617db13
MW
616;; --- Common mode settings ---
617
618(defvar mdw-auto-indent t
619 "Whether to indent automatically after a newline.")
620
621(defun mdw-misc-mode-config ()
622 (and mdw-auto-indent
623 (cond ((eq major-mode 'lisp-mode)
624 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
30c8a8fb
MW
625 ((or (eq major-mode 'slime-repl-mode)
626 (eq major-mode 'asm-mode))
627 nil)
f617db13
MW
628 (t
629 (local-set-key "\C-m" 'newline-and-indent))))
630 (local-set-key [C-return] 'newline)
8cb7626b
MW
631 (make-variable-buffer-local 'page-delimiter)
632 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
f617db13
MW
633 (setq comment-column 40)
634 (auto-fill-mode 1)
635 (setq fill-column 77)
473ff3b0 636 (setq show-trailing-whitespace t)
253f61b4
MW
637 (and (fboundp 'gtags-mode)
638 (gtags-mode))
5de5db48 639 (outline-minor-mode t)
f617db13
MW
640 (mdw-set-font))
641
253f61b4
MW
642(eval-after-load 'gtags
643 '(dolist (key '([mouse-2] [mouse-3]))
644 (define-key gtags-mode-map key nil)))
645
f617db13
MW
646;; --- Set up all sorts of faces ---
647
648(defvar mdw-set-font nil)
649
650(defvar mdw-punct-face 'mdw-punct-face "Face to use for punctuation")
651(make-face 'mdw-punct-face)
652(defvar mdw-number-face 'mdw-number-face "Face to use for numbers")
653(make-face 'mdw-number-face)
654
2ae647c4
MW
655;; --- Backup file handling ---
656
657(defvar mdw-backup-disable-regexps nil
658 "*List of regular expressions: if a file name matches any of these then the
659file is not backed up.")
660
661(defun mdw-backup-enable-predicate (name)
662 "[mdw]'s default backup predicate: allows a backup if the
663standard predicate would allow it, and it doesn't match any of
664the regular expressions in `mdw-backup-disable-regexps'."
665 (and (normal-backup-enable-predicate name)
666 (let ((answer t) (list mdw-backup-disable-regexps))
667 (save-match-data
668 (while list
669 (if (string-match (car list) name)
670 (setq answer nil))
671 (setq list (cdr list)))
672 answer))))
673(setq backup-enable-predicate 'mdw-backup-enable-predicate)
674
f617db13
MW
675;;;----- General fontification ----------------------------------------------
676
473ff3b0
MW
677(defun mdw-set-fonts (frame faces)
678 (while faces
679 (let ((face (caar faces)))
680 (or (facep face) (make-face face))
681 (set-face-attribute face frame
682 :family 'unspecified
683 :width 'unspecified
684 :height 'unspecified
685 :weight 'unspecified
686 :slant 'unspecified
687 :foreground 'unspecified
688 :background 'unspecified
689 :underline 'unspecified
690 :overline 'unspecified
691 :strike-through 'unspecified
692 :box 'unspecified
693 :inverse-video 'unspecified
694 :stipple 'unspecified
695 ;:font 'unspecified
696 :inherit 'unspecified)
697 (apply 'set-face-attribute face frame (cdar faces))
698 (setq faces (cdr faces)))))
f617db13
MW
699
700(defun mdw-do-set-font (&optional frame)
701 (interactive)
702 (mdw-set-fonts (and (boundp 'frame) frame) `(
703 (default :foreground "white" :background "black"
704 ,@(cond ((eq window-system 'w32)
705 '(:family "courier new" :height 85))
706 ((eq window-system 'x)
9cbbe332 707 '(:family "misc-fixed" :height 130 :width semi-condensed))))
b5d724dd
MW
708 (fixed-pitch)
709 (minibuffer-prompt)
668e254c
MW
710 (mode-line :foreground "blue" :background "yellow"
711 :box (:line-width 1 :style released-button))
414d8484 712 (mode-line-inactive :foreground "yellow" :background "blue"
668e254c 713 :box (:line-width 1 :style released-button))
f617db13 714 (scroll-bar :foreground "black" :background "lightgrey")
414d8484 715 (fringe :foreground "yellow" :background "black")
f617db13
MW
716 (show-paren-match-face :background "darkgreen")
717 (show-paren-mismatch-face :background "red")
718 (font-lock-warning-face :background "red" :weight bold)
719 (highlight :background "DarkSeaGreen4")
720 (holiday-face :background "red")
721 (calendar-today-face :foreground "yellow" :weight bold)
722 (comint-highlight-prompt :weight bold)
723 (comint-highlight-input)
724 (font-lock-builtin-face :weight bold)
725 (font-lock-type-face :weight bold)
be048719 726 (region :background ,(if window-system "grey30" "blue"))
f617db13
MW
727 (isearch :background "palevioletred2")
728 (mdw-punct-face :foreground ,(if window-system "burlywood2" "yellow"))
729 (mdw-number-face :foreground "yellow")
730 (font-lock-function-name-face :weight bold)
731 (font-lock-variable-name-face :slant italic)
52696e46
MW
732 (font-lock-comment-delimiter-face
733 :foreground ,(if window-system "SeaGreen1" "green")
734 :slant italic)
f617db13
MW
735 (font-lock-comment-face
736 :foreground ,(if window-system "SeaGreen1" "green")
737 :slant italic)
738 (font-lock-string-face :foreground ,(if window-system "SkyBlue1" "cyan"))
739 (font-lock-keyword-face :weight bold)
740 (font-lock-constant-face :weight bold)
741 (font-lock-reference-face :weight bold)
81213c7c
MW
742 (message-cited-text
743 :foreground ,(if window-system "SeaGreen1" "green")
744 :slant italic)
745 (message-separator :background "red" :foreground "white" :weight bold)
746 (message-header-cc
747 :foreground ,(if window-system "SeaGreen1" "green")
748 :weight bold)
749 (message-header-newsgroups
750 :foreground ,(if window-system "SeaGreen1" "green")
751 :weight bold)
752 (message-header-subject
753 :foreground ,(if window-system "SeaGreen1" "green")
754 :weight bold)
755 (message-header-to
756 :foreground ,(if window-system "SeaGreen1" "green")
757 :weight bold)
758 (message-header-xheader
759 :foreground ,(if window-system "SeaGreen1" "green")
760 :weight bold)
761 (message-header-other
762 :foreground ,(if window-system "SeaGreen1" "green")
763 :weight bold)
764 (message-header-name
765 :foreground ,(if window-system "SeaGreen1" "green"))
8c521a22
MW
766 (woman-bold :weight bold)
767 (woman-italic :slant italic)
52b00db2
MW
768 (p4-depot-added-face :foreground "green")
769 (p4-depot-branch-op-face :foreground "yellow")
770 (p4-depot-deleted-face :foreground "red")
771 (p4-depot-unmapped-face
772 :foreground ,(if window-system "SkyBlue1" "cyan"))
773 (p4-diff-change-face :foreground "yellow")
774 (p4-diff-del-face :foreground "red")
775 (p4-diff-file-face :foreground "SkyBlue1")
776 (p4-diff-head-face :background "grey10")
777 (p4-diff-ins-face :foreground "green")
8b6bc589
MW
778 (diff-index :weight bold)
779 (diff-file-header :weight bold)
780 (diff-hunk-header :foreground "SkyBlue1")
781 (diff-function :foreground "SkyBlue1" :weight bold)
782 (diff-header :background "grey10")
783 (diff-added :foreground "green")
784 (diff-removed :foreground "red")
785 (diff-context)
f617db13
MW
786 (whizzy-slice-face :background "grey10")
787 (whizzy-error-face :background "darkred")
473ff3b0 788 (trailing-whitespace :background "red")
f617db13
MW
789)))
790
791(defun mdw-set-font ()
792 (trap
793 (turn-on-font-lock)
794 (if (not mdw-set-font)
795 (progn
796 (setq mdw-set-font t)
797 (mdw-do-set-font nil)))))
798
799;;;----- C programming configuration ----------------------------------------
800
801;; --- Linux kernel hacking ---
802
803(defvar linux-c-mode-hook)
804
805(defun linux-c-mode ()
806 (interactive)
807 (c-mode)
808 (setq major-mode 'linux-c-mode)
809 (setq mode-name "Linux C")
810 (run-hooks 'linux-c-mode-hook))
811
812;; --- Make C indentation nice ---
813
c14d7793
MW
814(eval-after-load "cc-mode"
815 '(progn
816 (define-key c-mode-map "*" nil)
817 (define-key c-mode-map "/" nil)))
f06dee7a 818
f50c1bed
MW
819(defun mdw-c-lineup-arglist (langelem)
820 "Hack for DWIMmery in c-lineup-arglist."
821 (if (save-excursion
822 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
823 0
824 (c-lineup-arglist langelem)))
825
826(defun mdw-c-indent-extern-mumble (langelem)
827 "Indent `extern \"...\" {' lines."
828 (save-excursion
829 (back-to-indentation)
830 (if (looking-at
831 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
832 c-basic-offset
833 nil)))
834
f617db13
MW
835(defun mdw-c-style ()
836 (c-add-style "[mdw] C and C++ style"
837 '((c-basic-offset . 2)
f617db13
MW
838 (comment-column . 40)
839 (c-class-key . "class")
f50c1bed
MW
840 (c-backslash-column . 72)
841 (c-offsets-alist
842 (substatement-open . (add 0 c-indent-one-line-block))
843 (defun-open . (add 0 c-indent-one-line-block))
844 (arglist-cont-nonempty . mdw-c-lineup-arglist)
845 (topmost-intro . mdw-c-indent-extern-mumble)
846 (cpp-define-intro . 0)
847 (inextern-lang . [0])
848 (label . 0)
849 (case-label . +)
850 (access-label . -)
851 (inclass . +)
852 (inline-open . ++)
853 (statement-cont . 0)
854 (statement-case-intro . +)))
f617db13
MW
855 t))
856
857(defun mdw-fontify-c-and-c++ ()
858
859 ;; --- Fiddle with some syntax codes ---
860
f617db13
MW
861 (modify-syntax-entry ?* ". 23")
862 (modify-syntax-entry ?/ ". 124b")
863 (modify-syntax-entry ?\n "> b")
864
865 ;; --- Other stuff ---
866
867 (mdw-c-style)
868 (setq c-hanging-comment-ender-p nil)
869 (setq c-backslash-column 72)
870 (setq c-label-minimum-indentation 0)
f617db13
MW
871 (setq mdw-fill-prefix
872 `((,(concat "\\([ \t]*/?\\)"
873 "\\([\*/][ \t]*\\)"
874 "\\([A-Za-z]+:[ \t]*\\)?"
875 mdw-hanging-indents)
876 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
877
878 ;; --- Now define things to be fontified ---
879
02109a0d 880 (make-local-variable 'font-lock-keywords)
f617db13 881 (let ((c-keywords
8d6d55b9
MW
882 (mdw-regexps "and" ;C++
883 "and_eq" ;C++
884 "asm" ;K&R, GCC
885 "auto" ;K&R, C89
886 "bitand" ;C++
887 "bitor" ;C++
888 "bool" ;C++, C9X macro
889 "break" ;K&R, C89
890 "case" ;K&R, C89
891 "catch" ;C++
892 "char" ;K&R, C89
893 "class" ;C++
894 "complex" ;C9X macro, C++ template type
895 "compl" ;C++
896 "const" ;C89
897 "const_cast" ;C++
898 "continue" ;K&R, C89
899 "defined" ;C89 preprocessor
900 "default" ;K&R, C89
901 "delete" ;C++
902 "do" ;K&R, C89
903 "double" ;K&R, C89
904 "dynamic_cast" ;C++
905 "else" ;K&R, C89
906 ;; "entry" ;K&R -- never used
907 "enum" ;C89
908 "explicit" ;C++
909 "export" ;C++
910 "extern" ;K&R, C89
911 "false" ;C++, C9X macro
912 "float" ;K&R, C89
913 "for" ;K&R, C89
914 ;; "fortran" ;K&R
915 "friend" ;C++
916 "goto" ;K&R, C89
917 "if" ;K&R, C89
918 "imaginary" ;C9X macro
919 "inline" ;C++, C9X, GCC
920 "int" ;K&R, C89
921 "long" ;K&R, C89
922 "mutable" ;C++
923 "namespace" ;C++
924 "new" ;C++
925 "operator" ;C++
926 "or" ;C++
927 "or_eq" ;C++
928 "private" ;C++
929 "protected" ;C++
930 "public" ;C++
931 "register" ;K&R, C89
932 "reinterpret_cast" ;C++
933 "restrict" ;C9X
934 "return" ;K&R, C89
935 "short" ;K&R, C89
936 "signed" ;C89
937 "sizeof" ;K&R, C89
938 "static" ;K&R, C89
939 "static_cast" ;C++
940 "struct" ;K&R, C89
941 "switch" ;K&R, C89
942 "template" ;C++
943 "this" ;C++
944 "throw" ;C++
945 "true" ;C++, C9X macro
946 "try" ;C++
947 "this" ;C++
948 "typedef" ;C89
949 "typeid" ;C++
950 "typeof" ;GCC
951 "typename" ;C++
952 "union" ;K&R, C89
953 "unsigned" ;K&R, C89
954 "using" ;C++
955 "virtual" ;C++
956 "void" ;C89
957 "volatile" ;C89
958 "wchar_t" ;C++, C89 library type
959 "while" ;K&R, C89
960 "xor" ;C++
961 "xor_eq" ;C++
962 "_Bool" ;C9X
963 "_Complex" ;C9X
964 "_Imaginary" ;C9X
965 "_Pragma" ;C9X preprocessor
966 "__alignof__" ;GCC
967 "__asm__" ;GCC
968 "__attribute__" ;GCC
969 "__complex__" ;GCC
970 "__const__" ;GCC
971 "__extension__" ;GCC
972 "__imag__" ;GCC
973 "__inline__" ;GCC
974 "__label__" ;GCC
975 "__real__" ;GCC
976 "__signed__" ;GCC
977 "__typeof__" ;GCC
978 "__volatile__" ;GCC
979 ))
f617db13 980 (preprocessor-keywords
8d6d55b9
MW
981 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
982 "ident" "if" "ifdef" "ifndef" "import" "include"
983 "line" "pragma" "unassert" "undef" "warning"))
f617db13 984 (objc-keywords
8d6d55b9
MW
985 (mdw-regexps "class" "defs" "encode" "end" "implementation"
986 "interface" "private" "protected" "protocol" "public"
987 "selector")))
f617db13
MW
988
989 (setq font-lock-keywords
990 (list
f617db13
MW
991
992 ;; --- Fontify include files as strings ---
993
994 (list (concat "^[ \t]*\\#[ \t]*"
995 "\\(include\\|import\\)"
996 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
997 '(2 font-lock-string-face))
998
999 ;; --- Preprocessor directives are `references'? ---
1000
1001 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1002 preprocessor-keywords
1003 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1004 '(1 font-lock-keyword-face))
1005
1006 ;; --- Handle the keywords defined above ---
1007
1008 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1009 '(0 font-lock-keyword-face))
1010
1011 (list (concat "\\<\\(" c-keywords "\\)\\>")
1012 '(0 font-lock-keyword-face))
1013
1014 ;; --- Handle numbers too ---
1015 ;;
1016 ;; This looks strange, I know. It corresponds to the
1017 ;; preprocessor's idea of what a number looks like, rather than
1018 ;; anything sensible.
1019
1020 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1021 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1022 '(0 mdw-number-face))
1023
1024 ;; --- And anything else is punctuation ---
1025
1026 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1027 '(0 mdw-punct-face))))))
1028
1029;;;----- AP calc mode -------------------------------------------------------
1030
1031(defun apcalc-mode ()
1032 (interactive)
1033 (c-mode)
1034 (setq major-mode 'apcalc-mode)
1035 (setq mode-name "AP Calc")
1036 (run-hooks 'apcalc-mode-hook))
1037
1038(defun mdw-fontify-apcalc ()
1039
1040 ;; --- Fiddle with some syntax codes ---
1041
f617db13
MW
1042 (modify-syntax-entry ?* ". 23")
1043 (modify-syntax-entry ?/ ". 14")
1044
1045 ;; --- Other stuff ---
1046
1047 (mdw-c-style)
1048 (setq c-hanging-comment-ender-p nil)
1049 (setq c-backslash-column 72)
1050 (setq comment-start "/* ")
1051 (setq comment-end " */")
1052 (setq mdw-fill-prefix
1053 `((,(concat "\\([ \t]*/?\\)"
1054 "\\([\*/][ \t]*\\)"
1055 "\\([A-Za-z]+:[ \t]*\\)?"
1056 mdw-hanging-indents)
1057 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
1058
1059 ;; --- Now define things to be fontified ---
1060
02109a0d 1061 (make-local-variable 'font-lock-keywords)
f617db13 1062 (let ((c-keywords
8d6d55b9
MW
1063 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1064 "do" "else" "exit" "for" "global" "goto" "help" "if"
1065 "local" "mat" "obj" "print" "quit" "read" "return"
1066 "show" "static" "switch" "while" "write")))
f617db13
MW
1067
1068 (setq font-lock-keywords
1069 (list
f617db13
MW
1070
1071 ;; --- Handle the keywords defined above ---
1072
1073 (list (concat "\\<\\(" c-keywords "\\)\\>")
1074 '(0 font-lock-keyword-face))
1075
1076 ;; --- Handle numbers too ---
1077 ;;
1078 ;; This looks strange, I know. It corresponds to the
1079 ;; preprocessor's idea of what a number looks like, rather than
1080 ;; anything sensible.
1081
1082 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1083 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1084 '(0 mdw-number-face))
1085
1086 ;; --- And anything else is punctuation ---
1087
1088 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1089 '(0 mdw-punct-face))))))
1090
1091;;;----- Java programming configuration -------------------------------------
1092
1093;; --- Make indentation nice ---
1094
1095(defun mdw-java-style ()
1096 (c-add-style "[mdw] Java style"
1097 '((c-basic-offset . 2)
f617db13
MW
1098 (c-offsets-alist (substatement-open . 0)
1099 (label . +)
1100 (case-label . +)
1101 (access-label . 0)
1102 (inclass . +)
1103 (statement-case-intro . +)))
1104 t))
1105
1106;; --- Declare Java fontification style ---
1107
1108(defun mdw-fontify-java ()
1109
1110 ;; --- Other stuff ---
1111
1112 (mdw-java-style)
f617db13
MW
1113 (setq c-hanging-comment-ender-p nil)
1114 (setq c-backslash-column 72)
1115 (setq comment-start "/* ")
1116 (setq comment-end " */")
1117 (setq mdw-fill-prefix
1118 `((,(concat "\\([ \t]*/?\\)"
1119 "\\([\*/][ \t]*\\)"
1120 "\\([A-Za-z]+:[ \t]*\\)?"
1121 mdw-hanging-indents)
1122 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
1123
1124 ;; --- Now define things to be fontified ---
1125
02109a0d 1126 (make-local-variable 'font-lock-keywords)
f617db13 1127 (let ((java-keywords
8d6d55b9
MW
1128 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1129 "char" "class" "const" "continue" "default" "do"
1130 "double" "else" "extends" "final" "finally" "float"
1131 "for" "goto" "if" "implements" "import" "instanceof"
1132 "int" "interface" "long" "native" "new" "package"
1133 "private" "protected" "public" "return" "short"
1134 "static" "super" "switch" "synchronized" "this"
1135 "throw" "throws" "transient" "try" "void" "volatile"
1136 "while"
1137
1138 "false" "null" "true")))
f617db13
MW
1139
1140 (setq font-lock-keywords
1141 (list
f617db13
MW
1142
1143 ;; --- Handle the keywords defined above ---
1144
1145 (list (concat "\\<\\(" java-keywords "\\)\\>")
1146 '(0 font-lock-keyword-face))
1147
1148 ;; --- Handle numbers too ---
1149 ;;
1150 ;; The following isn't quite right, but it's close enough.
1151
1152 (list (concat "\\<\\("
1153 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1154 "[0-9]+\\(\\.[0-9]*\\|\\)"
1155 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1156 "[lLfFdD]?")
1157 '(0 mdw-number-face))
1158
1159 ;; --- And anything else is punctuation ---
1160
1161 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1162 '(0 mdw-punct-face))))))
1163
e808c1e5
MW
1164;;;----- C# programming configuration ---------------------------------------
1165
1166;; --- Make indentation nice ---
1167
1168(defun mdw-csharp-style ()
1169 (c-add-style "[mdw] C# style"
1170 '((c-basic-offset . 2)
e808c1e5
MW
1171 (c-offsets-alist (substatement-open . 0)
1172 (label . 0)
1173 (case-label . +)
1174 (access-label . 0)
1175 (inclass . +)
1176 (statement-case-intro . +)))
1177 t))
1178
1179;; --- Declare C# fontification style ---
1180
1181(defun mdw-fontify-csharp ()
1182
1183 ;; --- Other stuff ---
1184
1185 (mdw-csharp-style)
e808c1e5
MW
1186 (setq c-hanging-comment-ender-p nil)
1187 (setq c-backslash-column 72)
1188 (setq comment-start "/* ")
1189 (setq comment-end " */")
1190 (setq mdw-fill-prefix
1191 `((,(concat "\\([ \t]*/?\\)"
1192 "\\([\*/][ \t]*\\)"
1193 "\\([A-Za-z]+:[ \t]*\\)?"
1194 mdw-hanging-indents)
1195 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
1196
1197 ;; --- Now define things to be fontified ---
1198
1199 (make-local-variable 'font-lock-keywords)
1200 (let ((csharp-keywords
8d6d55b9
MW
1201 (mdw-regexps "abstract" "as" "base" "bool" "break"
1202 "byte" "case" "catch" "char" "checked"
1203 "class" "const" "continue" "decimal" "default"
1204 "delegate" "do" "double" "else" "enum"
1205 "event" "explicit" "extern" "false" "finally"
1206 "fixed" "float" "for" "foreach" "goto"
1207 "if" "implicit" "in" "int" "interface"
1208 "internal" "is" "lock" "long" "namespace"
1209 "new" "null" "object" "operator" "out"
1210 "override" "params" "private" "protected" "public"
1211 "readonly" "ref" "return" "sbyte" "sealed"
1212 "short" "sizeof" "stackalloc" "static" "string"
1213 "struct" "switch" "this" "throw" "true"
1214 "try" "typeof" "uint" "ulong" "unchecked"
1215 "unsafe" "ushort" "using" "virtual" "void"
1216 "volatile" "while" "yield")))
e808c1e5
MW
1217
1218 (setq font-lock-keywords
1219 (list
e808c1e5
MW
1220
1221 ;; --- Handle the keywords defined above ---
1222
1223 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1224 '(0 font-lock-keyword-face))
1225
1226 ;; --- Handle numbers too ---
1227 ;;
1228 ;; The following isn't quite right, but it's close enough.
1229
1230 (list (concat "\\<\\("
1231 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1232 "[0-9]+\\(\\.[0-9]*\\|\\)"
1233 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1234 "[lLfFdD]?")
1235 '(0 mdw-number-face))
1236
1237 ;; --- And anything else is punctuation ---
1238
1239 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1240 '(0 mdw-punct-face))))))
1241
1242(defun csharp-mode ()
1243 (interactive)
1244 (java-mode)
1245 (setq major-mode 'csharp-mode)
1246 (setq mode-name "C#")
1247 (mdw-fontify-csharp)
1248 (run-hooks 'csharp-mode-hook))
1249
f617db13
MW
1250;;;----- Awk programming configuration --------------------------------------
1251
1252;; --- Make Awk indentation nice ---
1253
1254(defun mdw-awk-style ()
1255 (c-add-style "[mdw] Awk style"
1256 '((c-basic-offset . 2)
f617db13
MW
1257 (c-offsets-alist (substatement-open . 0)
1258 (statement-cont . 0)
1259 (statement-case-intro . +)))
1260 t))
1261
1262;; --- Declare Awk fontification style ---
1263
1264(defun mdw-fontify-awk ()
1265
1266 ;; --- Miscellaneous fiddling ---
1267
f617db13
MW
1268 (mdw-awk-style)
1269 (setq c-backslash-column 72)
1270 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1271
1272 ;; --- Now define things to be fontified ---
1273
02109a0d 1274 (make-local-variable 'font-lock-keywords)
f617db13 1275 (let ((c-keywords
8d6d55b9
MW
1276 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1277 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1278 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1279 "RSTART" "RLENGTH" "RT" "SUBSEP"
1280 "atan2" "break" "close" "continue" "cos" "delete"
1281 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1282 "function" "gensub" "getline" "gsub" "if" "in"
1283 "index" "int" "length" "log" "match" "next" "rand"
1284 "return" "print" "printf" "sin" "split" "sprintf"
1285 "sqrt" "srand" "strftime" "sub" "substr" "system"
1286 "systime" "tolower" "toupper" "while")))
f617db13
MW
1287
1288 (setq font-lock-keywords
1289 (list
f617db13
MW
1290
1291 ;; --- Handle the keywords defined above ---
1292
1293 (list (concat "\\<\\(" c-keywords "\\)\\>")
1294 '(0 font-lock-keyword-face))
1295
1296 ;; --- Handle numbers too ---
1297 ;;
1298 ;; The following isn't quite right, but it's close enough.
1299
1300 (list (concat "\\<\\("
1301 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1302 "[0-9]+\\(\\.[0-9]*\\|\\)"
1303 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1304 "[uUlL]*")
1305 '(0 mdw-number-face))
1306
1307 ;; --- And anything else is punctuation ---
1308
1309 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1310 '(0 mdw-punct-face))))))
1311
1312;;;----- Perl programming style ---------------------------------------------
1313
1314;; --- Perl indentation style ---
1315
f617db13
MW
1316(setq cperl-indent-level 2)
1317(setq cperl-continued-statement-offset 2)
1318(setq cperl-continued-brace-offset 0)
1319(setq cperl-brace-offset -2)
1320(setq cperl-brace-imaginary-offset 0)
1321(setq cperl-label-offset 0)
1322
1323;; --- Define perl fontification style ---
1324
1325(defun mdw-fontify-perl ()
1326
1327 ;; --- Miscellaneous fiddling ---
1328
f617db13
MW
1329 (modify-syntax-entry ?$ "\\")
1330 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1331 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1332
1333 ;; --- Now define fontification things ---
1334
02109a0d 1335 (make-local-variable 'font-lock-keywords)
f617db13 1336 (let ((perl-keywords
8d6d55b9
MW
1337 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1338 "for" "foreach" "ge" "gt" "goto" "if"
1339 "last" "le" "lt" "local" "my" "ne" "next" "or"
1340 "package" "redo" "require" "return" "sub"
1341 "undef" "unless" "until" "use" "while")))
f617db13
MW
1342
1343 (setq font-lock-keywords
1344 (list
f617db13
MW
1345
1346 ;; --- Set up the keywords defined above ---
1347
1348 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1349 '(0 font-lock-keyword-face))
1350
1351 ;; --- At least numbers are simpler than C ---
1352
1353 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1354 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1355 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1356 '(0 mdw-number-face))
1357
1358 ;; --- And anything else is punctuation ---
1359
1360 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1361 '(0 mdw-punct-face))))))
1362
1363(defun perl-number-tests (&optional arg)
1364 "Assign consecutive numbers to lines containing `#t'. With ARG,
1365strip numbers instead."
1366 (interactive "P")
1367 (save-excursion
1368 (goto-char (point-min))
1369 (let ((i 0) (fmt (if arg "" " %4d")))
1370 (while (search-forward "#t" nil t)
1371 (delete-region (point) (line-end-position))
1372 (setq i (1+ i))
1373 (insert (format fmt i)))
1374 (goto-char (point-min))
1375 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1376 (replace-match (format "\\1%d" i))))))
1377
1378;;;----- Python programming style -------------------------------------------
1379
1380;; --- Define Python fontification style ---
1381
f617db13
MW
1382(defun mdw-fontify-python ()
1383
1384 ;; --- Miscellaneous fiddling ---
1385
f617db13
MW
1386 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1387
1388 ;; --- Now define fontification things ---
1389
02109a0d 1390 (make-local-variable 'font-lock-keywords)
f617db13 1391 (let ((python-keywords
8d6d55b9
MW
1392 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1393 "del" "elif" "else" "except" "exec" "finally" "for"
1394 "from" "global" "if" "import" "in" "is" "lambda"
1395 "not" "or" "pass" "print" "raise" "return" "try"
e61fa1ae 1396 "while" "with" "yield")))
f617db13
MW
1397 (setq font-lock-keywords
1398 (list
f617db13
MW
1399
1400 ;; --- Set up the keywords defined above ---
1401
1402 (list (concat "\\<\\(" python-keywords "\\)\\>")
1403 '(0 font-lock-keyword-face))
1404
1405 ;; --- At least numbers are simpler than C ---
1406
1407 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1408 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1409 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1410 '(0 mdw-number-face))
1411
1412 ;; --- And anything else is punctuation ---
1413
1414 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1415 '(0 mdw-punct-face))))))
1416
1417;;;----- ARM assembler programming configuration ----------------------------
1418
1419;; --- There doesn't appear to be an Emacs mode for this yet ---
1420;;
1421;; Better do something about that, I suppose.
1422
1423(defvar arm-assembler-mode-map nil)
1424(defvar arm-assembler-abbrev-table nil)
1425(defvar arm-assembler-mode-syntax-table (make-syntax-table))
1426
1427(or arm-assembler-mode-map
1428 (progn
1429 (setq arm-assembler-mode-map (make-sparse-keymap))
1430 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1431 (define-key arm-assembler-mode-map [C-return] 'newline)
1432 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1433
1434(defun arm-assembler-mode ()
1435 "Major mode for ARM assembler programs"
1436 (interactive)
1437
1438 ;; --- Do standard major mode things ---
1439
1440 (kill-all-local-variables)
1441 (use-local-map arm-assembler-mode-map)
1442 (setq local-abbrev-table arm-assembler-abbrev-table)
1443 (setq major-mode 'arm-assembler-mode)
1444 (setq mode-name "ARM assembler")
1445
1446 ;; --- Set up syntax table ---
1447
1448 (set-syntax-table arm-assembler-mode-syntax-table)
1449 (modify-syntax-entry ?; ; Nasty hack
1450 "<" arm-assembler-mode-syntax-table)
1451 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1452 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1453
1454 (make-local-variable 'comment-start)
1455 (setq comment-start ";")
1456 (make-local-variable 'comment-end)
1457 (setq comment-end "")
1458 (make-local-variable 'comment-column)
1459 (setq comment-column 48)
1460 (make-local-variable 'comment-start-skip)
1461 (setq comment-start-skip ";+[ \t]*")
1462
1463 ;; --- Play with indentation ---
1464
1465 (make-local-variable 'indent-line-function)
1466 (setq indent-line-function 'indent-relative-maybe)
1467
1468 ;; --- Set fill prefix ---
1469
1470 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1471
1472 ;; --- Fiddle with fontification ---
1473
02109a0d 1474 (make-local-variable 'font-lock-keywords)
f617db13
MW
1475 (setq font-lock-keywords
1476 (list
f617db13
MW
1477
1478 ;; --- Handle numbers too ---
1479 ;;
1480 ;; The following isn't quite right, but it's close enough.
1481
1482 (list (concat "\\("
1483 "&[0-9a-fA-F]+\\|"
1484 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1485 "\\)")
1486 '(0 mdw-number-face))
1487
1488 ;; --- Do something about operators ---
1489
1490 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1491 '(1 font-lock-keyword-face)
1492 '(2 font-lock-string-face))
1493 (list ":[a-zA-Z]+:"
1494 '(0 font-lock-keyword-face))
1495
1496 ;; --- Do menemonics and directives ---
1497
1498 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1499 '(1 font-lock-keyword-face))
1500
1501 ;; --- And anything else is punctuation ---
1502
1503 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1504 '(0 mdw-punct-face))))
1505
1506 (run-hooks 'arm-assembler-mode-hook))
1507
30c8a8fb
MW
1508;;;----- Assembler mode -----------------------------------------------------
1509
1510(defun mdw-fontify-asm ()
1511 (modify-syntax-entry ?' "\"")
1512 (modify-syntax-entry ?. "w")
1513 (setf fill-prefix nil)
1514 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1515
f617db13
MW
1516;;;----- TCL configuration --------------------------------------------------
1517
1518(defun mdw-fontify-tcl ()
1519 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1520 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
02109a0d 1521 (make-local-variable 'font-lock-keywords)
f617db13
MW
1522 (setq font-lock-keywords
1523 (list
f617db13
MW
1524 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1525 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1526 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1527 '(0 mdw-number-face))
1528 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1529 '(0 mdw-punct-face)))))
1530
1531;;;----- REXX configuration -------------------------------------------------
1532
1533(defun mdw-rexx-electric-* ()
1534 (interactive)
1535 (insert ?*)
1536 (rexx-indent-line))
1537
1538(defun mdw-rexx-indent-newline-indent ()
1539 (interactive)
1540 (rexx-indent-line)
1541 (if abbrev-mode (expand-abbrev))
1542 (newline-and-indent))
1543
1544(defun mdw-fontify-rexx ()
1545
1546 ;; --- Various bits of fiddling ---
1547
1548 (setq mdw-auto-indent nil)
1549 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1550 (local-set-key [?*] 'mdw-rexx-electric-*)
1551 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
e443a4cd 1552 '(?! ?? ?# ?@ ?$))
f617db13
MW
1553 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1554
1555 ;; --- Set up keywords and things for fontification ---
1556
1557 (make-local-variable 'font-lock-keywords-case-fold-search)
1558 (setq font-lock-keywords-case-fold-search t)
1559
1560 (setq rexx-indent 2)
1561 (setq rexx-end-indent rexx-indent)
f617db13
MW
1562 (setq rexx-cont-indent rexx-indent)
1563
02109a0d 1564 (make-local-variable 'font-lock-keywords)
f617db13 1565 (let ((rexx-keywords
8d6d55b9
MW
1566 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1567 "else" "end" "engineering" "exit" "expose" "for"
1568 "forever" "form" "fuzz" "if" "interpret" "iterate"
1569 "leave" "linein" "name" "nop" "numeric" "off" "on"
1570 "options" "otherwise" "parse" "procedure" "pull"
1571 "push" "queue" "return" "say" "select" "signal"
1572 "scientific" "source" "then" "trace" "to" "until"
1573 "upper" "value" "var" "version" "when" "while"
1574 "with"
1575
1576 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1577 "center" "center" "charin" "charout" "chars"
1578 "compare" "condition" "copies" "c2d" "c2x"
1579 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1580 "errortext" "format" "fuzz" "insert" "lastpos"
1581 "left" "length" "lineout" "lines" "max" "min"
1582 "overlay" "pos" "queued" "random" "reverse" "right"
1583 "sign" "sourceline" "space" "stream" "strip"
1584 "substr" "subword" "symbol" "time" "translate"
1585 "trunc" "value" "verify" "word" "wordindex"
1586 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1587 "x2d")))
f617db13
MW
1588
1589 (setq font-lock-keywords
1590 (list
f617db13
MW
1591
1592 ;; --- Set up the keywords defined above ---
1593
1594 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1595 '(0 font-lock-keyword-face))
1596
1597 ;; --- Fontify all symbols the same way ---
1598
1599 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1600 "[A-Za-z0-9.!?_#@$]+\\)")
1601 '(0 font-lock-variable-name-face))
1602
1603 ;; --- And everything else is punctuation ---
1604
1605 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1606 '(0 mdw-punct-face))))))
1607
1608;;;----- Standard ML programming style --------------------------------------
1609
1610(defun mdw-fontify-sml ()
1611
1612 ;; --- Make underscore an honorary letter ---
1613
f617db13
MW
1614 (modify-syntax-entry ?' "w")
1615
1616 ;; --- Set fill prefix ---
1617
1618 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1619
1620 ;; --- Now define fontification things ---
1621
02109a0d 1622 (make-local-variable 'font-lock-keywords)
f617db13 1623 (let ((sml-keywords
8d6d55b9
MW
1624 (mdw-regexps "abstype" "and" "andalso" "as"
1625 "case"
1626 "datatype" "do"
1627 "else" "end" "eqtype" "exception"
1628 "fn" "fun" "functor"
1629 "handle"
1630 "if" "in" "include" "infix" "infixr"
1631 "let" "local"
1632 "nonfix"
1633 "of" "op" "open" "orelse"
1634 "raise" "rec"
1635 "sharing" "sig" "signature" "struct" "structure"
1636 "then" "type"
1637 "val"
1638 "where" "while" "with" "withtype")))
f617db13
MW
1639
1640 (setq font-lock-keywords
1641 (list
f617db13
MW
1642
1643 ;; --- Set up the keywords defined above ---
1644
1645 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1646 '(0 font-lock-keyword-face))
1647
1648 ;; --- At least numbers are simpler than C ---
1649
1650 (list (concat "\\<\\(\\~\\|\\)"
1651 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
852cd5fb
MW
1652 "[wW][0-9]+\\)\\|"
1653 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1654 "\\([eE]\\(\\~\\|\\)"
1655 "[0-9]+\\|\\)\\)\\)")
f617db13
MW
1656 '(0 mdw-number-face))
1657
1658 ;; --- And anything else is punctuation ---
1659
1660 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1661 '(0 mdw-punct-face))))))
1662
1663;;;----- Haskell configuration ----------------------------------------------
1664
1665(defun mdw-fontify-haskell ()
1666
1667 ;; --- Fiddle with syntax table to get comments right ---
1668
f617db13
MW
1669 (modify-syntax-entry ?' "\"")
1670 (modify-syntax-entry ?- ". 123")
1671 (modify-syntax-entry ?{ ". 1b")
1672 (modify-syntax-entry ?} ". 4b")
1673 (modify-syntax-entry ?\n ">")
1674
1675 ;; --- Set fill prefix ---
1676
1677 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1678
1679 ;; --- Fiddle with fontification ---
1680
02109a0d 1681 (make-local-variable 'font-lock-keywords)
f617db13 1682 (let ((haskell-keywords
8d6d55b9
MW
1683 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1684 "deriving" "do" "else" "foreign" "hiding" "if"
1685 "import" "in" "infix" "infixl" "infixr" "instance"
1686 "let" "module" "newtype" "of" "qualified" "safe"
1687 "stdcall" "then" "type" "unsafe" "where")))
f617db13
MW
1688
1689 (setq font-lock-keywords
1690 (list
f617db13
MW
1691 (list "--.*$"
1692 '(0 font-lock-comment-face))
1693 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1694 '(0 font-lock-keyword-face))
1695 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1696 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1697 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1698 '(0 mdw-number-face))
1699 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1700 '(0 mdw-punct-face))))))
1701
2ded9493
MW
1702;;;----- Erlang configuration -----------------------------------------------
1703
1704(setq erlang-electric-commannds
1705 '(erlang-electric-newline erlang-electric-semicolon))
1706
1707(defun mdw-fontify-erlang ()
1708
1709 ;; --- Set fill prefix ---
1710
1711 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1712
1713 ;; --- Fiddle with fontification ---
1714
1715 (make-local-variable 'font-lock-keywords)
1716 (let ((erlang-keywords
1717 (mdw-regexps "after" "and" "andalso"
1718 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1719 "case" "catch" "cond"
1720 "div" "end" "fun" "if" "let" "not"
1721 "of" "or" "orelse"
1722 "query" "receive" "rem" "try" "when" "xor")))
1723
1724 (setq font-lock-keywords
1725 (list
1726 (list "%.*$"
1727 '(0 font-lock-comment-face))
1728 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1729 '(0 font-lock-keyword-face))
1730 (list (concat "^-\\sw+\\>")
1731 '(0 font-lock-keyword-face))
1732 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1733 '(0 mdw-number-face))
1734 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1735 '(0 mdw-punct-face))))))
1736
f617db13
MW
1737;;;----- Texinfo configuration ----------------------------------------------
1738
1739(defun mdw-fontify-texinfo ()
1740
1741 ;; --- Set fill prefix ---
1742
1743 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1744
1745 ;; --- Real fontification things ---
1746
02109a0d 1747 (make-local-variable 'font-lock-keywords)
f617db13
MW
1748 (setq font-lock-keywords
1749 (list
f617db13
MW
1750
1751 ;; --- Environment names are keywords ---
1752
1753 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1754 '(2 font-lock-keyword-face))
1755
1756 ;; --- Unmark escaped magic characters ---
1757
1758 (list "\\(@\\)\\([@{}]\\)"
1759 '(1 font-lock-keyword-face)
1760 '(2 font-lock-variable-name-face))
1761
1762 ;; --- Make sure we get comments properly ---
1763
1764 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1765 '(0 font-lock-comment-face))
1766
1767 ;; --- Command names are keywords ---
1768
1769 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1770 '(0 font-lock-keyword-face))
1771
1772 ;; --- Fontify TeX special characters as punctuation ---
1773
1774 (list "[{}]+"
1775 '(0 mdw-punct-face)))))
1776
1777;;;----- TeX and LaTeX configuration ----------------------------------------
1778
1779(defun mdw-fontify-tex ()
1780 (setq ispell-parser 'tex)
55f80fae 1781 (turn-on-reftex)
f617db13
MW
1782
1783 ;; --- Don't make maths into a string ---
1784
1785 (modify-syntax-entry ?$ ".")
1786 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1787 (local-set-key [?$] 'self-insert-command)
1788
1789 ;; --- Set fill prefix ---
1790
1791 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1792
1793 ;; --- Real fontification things ---
1794
02109a0d 1795 (make-local-variable 'font-lock-keywords)
f617db13
MW
1796 (setq font-lock-keywords
1797 (list
f617db13
MW
1798
1799 ;; --- Environment names are keywords ---
1800
1801 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1802 "{\\([^}\n]*\\)}")
1803 '(2 font-lock-keyword-face))
1804
1805 ;; --- Suspended environment names are keywords too ---
1806
1807 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1808 "{\\([^}\n]*\\)}")
1809 '(3 font-lock-keyword-face))
1810
1811 ;; --- Command names are keywords ---
1812
1813 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1814 '(0 font-lock-keyword-face))
1815
1816 ;; --- Handle @/.../ for italics ---
1817
1818 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
852cd5fb
MW
1819 ;; '(1 font-lock-keyword-face)
1820 ;; '(3 font-lock-keyword-face))
f617db13
MW
1821
1822 ;; --- Handle @*...* for boldness ---
1823
1824 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
852cd5fb
MW
1825 ;; '(1 font-lock-keyword-face)
1826 ;; '(3 font-lock-keyword-face))
f617db13
MW
1827
1828 ;; --- Handle @`...' for literal syntax things ---
1829
1830 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
852cd5fb
MW
1831 ;; '(1 font-lock-keyword-face)
1832 ;; '(3 font-lock-keyword-face))
f617db13
MW
1833
1834 ;; --- Handle @<...> for nonterminals ---
1835
1836 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
852cd5fb
MW
1837 ;; '(1 font-lock-keyword-face)
1838 ;; '(3 font-lock-keyword-face))
f617db13
MW
1839
1840 ;; --- Handle other @-commands ---
1841
1842 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
852cd5fb 1843 ;; '(0 font-lock-keyword-face))
f617db13
MW
1844
1845 ;; --- Make sure we get comments properly ---
1846
1847 (list "%.*"
1848 '(0 font-lock-comment-face))
1849
1850 ;; --- Fontify TeX special characters as punctuation ---
1851
1852 (list "[$^_{}#&]"
1853 '(0 mdw-punct-face)))))
1854
f25cf300
MW
1855;;;----- SGML hacking -------------------------------------------------------
1856
1857(defun mdw-sgml-mode ()
1858 (interactive)
1859 (sgml-mode)
1860 (mdw-standard-fill-prefix "")
1861 (make-variable-buffer-local 'sgml-delimiters)
1862 (setq sgml-delimiters
1863 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
1864 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
1865 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
1866 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
1867 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
1868 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
1869 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
1870 "NULL" ""))
1871 (setq major-mode 'mdw-sgml-mode)
1872 (setq mode-name "[mdw] SGML")
1873 (run-hooks 'mdw-sgml-mode-hook))
1874
f617db13
MW
1875;;;----- Shell scripts ------------------------------------------------------
1876
1877(defun mdw-setup-sh-script-mode ()
1878
1879 ;; --- Fetch the shell interpreter's name ---
1880
1881 (let ((shell-name sh-shell-file))
1882
1883 ;; --- Try reading the hash-bang line ---
1884
1885 (save-excursion
1886 (goto-char (point-min))
1887 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
1888 (setq shell-name (match-string 1))))
1889
1890 ;; --- Now try to set the shell ---
1891 ;;
1892 ;; Don't let `sh-set-shell' bugger up my script.
1893
1894 (let ((executable-set-magic #'(lambda (s &rest r) s)))
1895 (sh-set-shell shell-name)))
1896
1897 ;; --- Now enable my keys and the fontification ---
1898
1899 (mdw-misc-mode-config)
1900
1901 ;; --- Set the indentation level correctly ---
1902
1903 (setq sh-indentation 2)
1904 (setq sh-basic-offset 2))
1905
1906;;;----- Messages-file mode -------------------------------------------------
1907
4bb22eea 1908(defun messages-mode-guts ()
f617db13
MW
1909 (setq messages-mode-syntax-table (make-syntax-table))
1910 (set-syntax-table messages-mode-syntax-table)
f617db13
MW
1911 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
1912 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
1913 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
1914 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
1915 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
1916 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
1917 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
1918 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
1919 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
1920 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
1921 (make-local-variable 'comment-start)
1922 (make-local-variable 'comment-end)
1923 (make-local-variable 'indent-line-function)
1924 (setq indent-line-function 'indent-relative)
1925 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1926 (make-local-variable 'font-lock-defaults)
4bb22eea 1927 (make-local-variable 'messages-mode-keywords)
f617db13 1928 (let ((keywords
8d6d55b9
MW
1929 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
1930 "export" "enum" "fixed-octetstring" "flags"
1931 "harmless" "map" "nested" "optional"
1932 "optional-tagged" "package" "primitive"
1933 "primitive-nullfree" "relaxed[ \t]+enum"
1934 "set" "table" "tagged-optional" "union"
1935 "variadic" "vector" "version" "version-tag")))
4bb22eea 1936 (setq messages-mode-keywords
f617db13
MW
1937 (list
1938 (list (concat "\\<\\(" keywords "\\)\\>:")
1939 '(0 font-lock-keyword-face))
1940 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
1941 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
1942 (0 font-lock-variable-name-face))
1943 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
1944 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1945 (0 mdw-punct-face)))))
1946 (setq font-lock-defaults
4bb22eea 1947 '(messages-mode-keywords nil nil nil nil))
f617db13
MW
1948 (run-hooks 'messages-file-hook))
1949
1950(defun messages-mode ()
1951 (interactive)
1952 (fundamental-mode)
1953 (setq major-mode 'messages-mode)
1954 (setq mode-name "Messages")
4bb22eea 1955 (messages-mode-guts)
f617db13
MW
1956 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
1957 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
1958 (setq comment-start "# ")
1959 (setq comment-end "")
1960 (turn-on-font-lock-if-enabled)
1961 (run-hooks 'messages-mode-hook))
1962
1963(defun cpp-messages-mode ()
1964 (interactive)
1965 (fundamental-mode)
1966 (setq major-mode 'cpp-messages-mode)
1967 (setq mode-name "CPP Messages")
4bb22eea 1968 (messages-mode-guts)
f617db13
MW
1969 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
1970 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
1971 (setq comment-start "/* ")
1972 (setq comment-end " */")
1973 (let ((preprocessor-keywords
8d6d55b9
MW
1974 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1975 "ident" "if" "ifdef" "ifndef" "import" "include"
1976 "line" "pragma" "unassert" "undef" "warning")))
4bb22eea 1977 (setq messages-mode-keywords
f617db13
MW
1978 (append (list (list (concat "^[ \t]*\\#[ \t]*"
1979 "\\(include\\|import\\)"
1980 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1981 '(2 font-lock-string-face))
1982 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1983 preprocessor-keywords
852cd5fb 1984 "\\)\\>\\|[0-9]+\\|$\\)\\)")
f617db13 1985 '(1 font-lock-keyword-face)))
4bb22eea 1986 messages-mode-keywords)))
f617db13 1987 (turn-on-font-lock-if-enabled)
297d60aa 1988 (run-hooks 'cpp-messages-mode-hook))
f617db13 1989
297d60aa
MW
1990(add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
1991(add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
f617db13
MW
1992; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
1993
1994;;;----- Messages-file mode -------------------------------------------------
1995
1996(defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
1997 "Face to use for subsittution directives.")
1998(make-face 'mallow-driver-substitution-face)
1999(defvar mallow-driver-text-face 'mallow-driver-text-face
2000 "Face to use for body text.")
2001(make-face 'mallow-driver-text-face)
2002
2003(defun mallow-driver-mode ()
2004 (interactive)
2005 (fundamental-mode)
2006 (setq major-mode 'mallow-driver-mode)
2007 (setq mode-name "Mallow driver")
2008 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2009 (set-syntax-table mallow-driver-mode-syntax-table)
2010 (make-local-variable 'comment-start)
2011 (make-local-variable 'comment-end)
2012 (make-local-variable 'indent-line-function)
2013 (setq indent-line-function 'indent-relative)
2014 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2015 (make-local-variable 'font-lock-defaults)
2016 (make-local-variable 'mallow-driver-mode-keywords)
2017 (let ((keywords
8d6d55b9
MW
2018 (mdw-regexps "each" "divert" "file" "if"
2019 "perl" "set" "string" "type" "write")))
f617db13
MW
2020 (setq mallow-driver-mode-keywords
2021 (list
2022 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2023 '(0 font-lock-keyword-face))
2024 (list "^%\\s *\\(#.*\\|\\)$"
2025 '(0 font-lock-comment-face))
2026 (list "^%"
2027 '(0 font-lock-keyword-face))
2028 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2029 (list "\\${[^}]*}"
2030 '(0 mallow-driver-substitution-face t)))))
2031 (setq font-lock-defaults
2032 '(mallow-driver-mode-keywords nil nil nil nil))
2033 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2034 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2035 (setq comment-start "%# ")
2036 (setq comment-end "")
2037 (turn-on-font-lock-if-enabled)
2038 (run-hooks 'mallow-driver-mode-hook))
2039
2040(add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2041
2042;;;----- NFast debugs -------------------------------------------------------
2043
2044(defun nfast-debug-mode ()
2045 (interactive)
2046 (fundamental-mode)
2047 (setq major-mode 'nfast-debug-mode)
2048 (setq mode-name "NFast debug")
2049 (setq messages-mode-syntax-table (make-syntax-table))
2050 (set-syntax-table messages-mode-syntax-table)
2051 (make-local-variable 'font-lock-defaults)
2052 (make-local-variable 'nfast-debug-mode-keywords)
2053 (setq truncate-lines t)
2054 (setq nfast-debug-mode-keywords
2055 (list
2056 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2057 (0 font-lock-keyword-face))
2058 (list (concat "^[ \t]+\\(\\("
2059 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2060 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2061 "[ \t]+\\)*"
2062 "[0-9a-fA-F]+\\)[ \t]*$")
2063 '(0 mdw-number-face))
2064 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2065 (1 font-lock-keyword-face))
2066 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2067 (1 font-lock-warning-face))
2068 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2069 (1 nil))
2070 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2071 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2072 '(1 font-lock-keyword-face))
2073 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2074 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2075 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2076 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2077 (setq font-lock-defaults
2078 '(nfast-debug-mode-keywords nil nil nil nil))
2079 (turn-on-font-lock-if-enabled)
2080 (run-hooks 'nfast-debug-mode-hook))
2081
2082;;;----- Other languages ----------------------------------------------------
2083
2084;; --- Smalltalk ---
2085
2086(defun mdw-setup-smalltalk ()
2087 (and mdw-auto-indent
2088 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2089 (make-variable-buffer-local 'mdw-auto-indent)
2090 (setq mdw-auto-indent nil)
2091 (local-set-key "\C-i" 'smalltalk-reindent))
2092
2093(defun mdw-fontify-smalltalk ()
02109a0d 2094 (make-local-variable 'font-lock-keywords)
f617db13
MW
2095 (setq font-lock-keywords
2096 (list
f617db13
MW
2097 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2098 '(0 font-lock-keyword-face))
2099 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2100 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2101 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2102 '(0 mdw-number-face))
2103 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2104 '(0 mdw-punct-face)))))
2105
2106;; --- Lispy languages ---
2107
873d87df
MW
2108;; Unpleasant bodge.
2109(unless (boundp 'slime-repl-mode-map)
2110 (setq slime-repl-mode-map (make-sparse-keymap)))
2111
f617db13
MW
2112(defun mdw-indent-newline-and-indent ()
2113 (interactive)
2114 (indent-for-tab-command)
2115 (newline-and-indent))
2116
2117(eval-after-load "cl-indent"
2118 '(progn
2119 (mapc #'(lambda (pair)
2120 (put (car pair)
2121 'common-lisp-indent-function
2122 (cdr pair)))
2123 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2124 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2125
2126(defun mdw-common-lisp-indent ()
2127 (make-variable-buffer-local 'lisp-indent-function)
2128 (setq lisp-indent-function 'common-lisp-indent-function))
2129
037be6de 2130(setq lisp-simple-loop-indentation 2
95575d1f
MW
2131 lisp-loop-keyword-indentation 6
2132 lisp-loop-forms-indentation 6)
2133
f617db13
MW
2134(defun mdw-fontify-lispy ()
2135
2136 ;; --- Set fill prefix ---
2137
2138 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2139
2140 ;; --- Not much fontification needed ---
2141
02109a0d 2142 (make-local-variable 'font-lock-keywords)
f617db13
MW
2143 (setq font-lock-keywords
2144 (list
f617db13
MW
2145 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2146 '(0 mdw-punct-face)))))
2147
2148(defun comint-send-and-indent ()
2149 (interactive)
2150 (comint-send-input)
2151 (and mdw-auto-indent
2152 (indent-for-tab-command)))
2153
ec007bea
MW
2154(defun mdw-setup-m4 ()
2155 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2156
f617db13
MW
2157;;;----- Text mode ----------------------------------------------------------
2158
2159(defun mdw-text-mode ()
2160 (setq fill-column 72)
2161 (flyspell-mode t)
2162 (mdw-standard-fill-prefix
c7a8da49 2163 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
f617db13
MW
2164 (auto-fill-mode 1))
2165
5de5db48
MW
2166;;;----- Outline mode -------------------------------------------------------
2167
2168(defun mdw-outline-collapse-all ()
2169 "Completely collapse everything in the entire buffer."
2170 (interactive)
2171 (save-excursion
2172 (goto-char (point-min))
2173 (while (< (point) (point-max))
2174 (hide-subtree)
2175 (forward-line))))
2176
f617db13
MW
2177;;;----- Shell mode ---------------------------------------------------------
2178
2179(defun mdw-sh-mode-setup ()
2180 (local-set-key [?\C-a] 'comint-bol)
2181 (add-hook 'comint-output-filter-functions
2182 'comint-watch-for-password-prompt))
2183
2184(defun mdw-term-mode-setup ()
3d9147ea 2185 (setq term-prompt-regexp shell-prompt-pattern)
f617db13
MW
2186 (make-local-variable 'mouse-yank-at-point)
2187 (make-local-variable 'transient-mark-mode)
2188 (setq mouse-yank-at-point t)
f617db13
MW
2189 (auto-fill-mode -1)
2190 (setq tab-width 8))
2191
3d9147ea
MW
2192(defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2193(defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2194(defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2195(defun term-send-meta-meta-something ()
2196 (interactive)
2197 (term-send-raw-string "\e\e")
2198 (term-send-raw))
2199(eval-after-load 'term
2200 '(progn
2201 (define-key term-raw-map [?\e ?\e] nil)
2202 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2203 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2204 (define-key term-raw-map [M-right] 'term-send-meta-right)
2205 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2206 (define-key term-raw-map [M-left] 'term-send-meta-left)
2207 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2208
f617db13
MW
2209;;;----- That's all, folks --------------------------------------------------
2210
2211(provide 'dot-emacs)