chiark / gitweb /
putty-defaults: Prevent changing of the window title.
[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
f617db13
MW
819(defun mdw-c-style ()
820 (c-add-style "[mdw] C and C++ style"
821 '((c-basic-offset . 2)
f617db13
MW
822 (comment-column . 40)
823 (c-class-key . "class")
824 (c-offsets-alist (substatement-open . 0)
825 (label . 0)
826 (case-label . +)
827 (access-label . -)
87c7cecb 828 (inclass . +)
f617db13
MW
829 (inline-open . ++)
830 (statement-cont . 0)
831 (statement-case-intro . +)))
832 t))
833
834(defun mdw-fontify-c-and-c++ ()
835
836 ;; --- Fiddle with some syntax codes ---
837
f617db13
MW
838 (modify-syntax-entry ?* ". 23")
839 (modify-syntax-entry ?/ ". 124b")
840 (modify-syntax-entry ?\n "> b")
841
842 ;; --- Other stuff ---
843
844 (mdw-c-style)
845 (setq c-hanging-comment-ender-p nil)
846 (setq c-backslash-column 72)
847 (setq c-label-minimum-indentation 0)
f617db13
MW
848 (setq mdw-fill-prefix
849 `((,(concat "\\([ \t]*/?\\)"
850 "\\([\*/][ \t]*\\)"
851 "\\([A-Za-z]+:[ \t]*\\)?"
852 mdw-hanging-indents)
853 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
854
855 ;; --- Now define things to be fontified ---
856
02109a0d 857 (make-local-variable 'font-lock-keywords)
f617db13 858 (let ((c-keywords
8d6d55b9
MW
859 (mdw-regexps "and" ;C++
860 "and_eq" ;C++
861 "asm" ;K&R, GCC
862 "auto" ;K&R, C89
863 "bitand" ;C++
864 "bitor" ;C++
865 "bool" ;C++, C9X macro
866 "break" ;K&R, C89
867 "case" ;K&R, C89
868 "catch" ;C++
869 "char" ;K&R, C89
870 "class" ;C++
871 "complex" ;C9X macro, C++ template type
872 "compl" ;C++
873 "const" ;C89
874 "const_cast" ;C++
875 "continue" ;K&R, C89
876 "defined" ;C89 preprocessor
877 "default" ;K&R, C89
878 "delete" ;C++
879 "do" ;K&R, C89
880 "double" ;K&R, C89
881 "dynamic_cast" ;C++
882 "else" ;K&R, C89
883 ;; "entry" ;K&R -- never used
884 "enum" ;C89
885 "explicit" ;C++
886 "export" ;C++
887 "extern" ;K&R, C89
888 "false" ;C++, C9X macro
889 "float" ;K&R, C89
890 "for" ;K&R, C89
891 ;; "fortran" ;K&R
892 "friend" ;C++
893 "goto" ;K&R, C89
894 "if" ;K&R, C89
895 "imaginary" ;C9X macro
896 "inline" ;C++, C9X, GCC
897 "int" ;K&R, C89
898 "long" ;K&R, C89
899 "mutable" ;C++
900 "namespace" ;C++
901 "new" ;C++
902 "operator" ;C++
903 "or" ;C++
904 "or_eq" ;C++
905 "private" ;C++
906 "protected" ;C++
907 "public" ;C++
908 "register" ;K&R, C89
909 "reinterpret_cast" ;C++
910 "restrict" ;C9X
911 "return" ;K&R, C89
912 "short" ;K&R, C89
913 "signed" ;C89
914 "sizeof" ;K&R, C89
915 "static" ;K&R, C89
916 "static_cast" ;C++
917 "struct" ;K&R, C89
918 "switch" ;K&R, C89
919 "template" ;C++
920 "this" ;C++
921 "throw" ;C++
922 "true" ;C++, C9X macro
923 "try" ;C++
924 "this" ;C++
925 "typedef" ;C89
926 "typeid" ;C++
927 "typeof" ;GCC
928 "typename" ;C++
929 "union" ;K&R, C89
930 "unsigned" ;K&R, C89
931 "using" ;C++
932 "virtual" ;C++
933 "void" ;C89
934 "volatile" ;C89
935 "wchar_t" ;C++, C89 library type
936 "while" ;K&R, C89
937 "xor" ;C++
938 "xor_eq" ;C++
939 "_Bool" ;C9X
940 "_Complex" ;C9X
941 "_Imaginary" ;C9X
942 "_Pragma" ;C9X preprocessor
943 "__alignof__" ;GCC
944 "__asm__" ;GCC
945 "__attribute__" ;GCC
946 "__complex__" ;GCC
947 "__const__" ;GCC
948 "__extension__" ;GCC
949 "__imag__" ;GCC
950 "__inline__" ;GCC
951 "__label__" ;GCC
952 "__real__" ;GCC
953 "__signed__" ;GCC
954 "__typeof__" ;GCC
955 "__volatile__" ;GCC
956 ))
f617db13 957 (preprocessor-keywords
8d6d55b9
MW
958 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
959 "ident" "if" "ifdef" "ifndef" "import" "include"
960 "line" "pragma" "unassert" "undef" "warning"))
f617db13 961 (objc-keywords
8d6d55b9
MW
962 (mdw-regexps "class" "defs" "encode" "end" "implementation"
963 "interface" "private" "protected" "protocol" "public"
964 "selector")))
f617db13
MW
965
966 (setq font-lock-keywords
967 (list
f617db13
MW
968
969 ;; --- Fontify include files as strings ---
970
971 (list (concat "^[ \t]*\\#[ \t]*"
972 "\\(include\\|import\\)"
973 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
974 '(2 font-lock-string-face))
975
976 ;; --- Preprocessor directives are `references'? ---
977
978 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
979 preprocessor-keywords
980 "\\)\\>\\|[0-9]+\\|$\\)\\)")
981 '(1 font-lock-keyword-face))
982
983 ;; --- Handle the keywords defined above ---
984
985 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
986 '(0 font-lock-keyword-face))
987
988 (list (concat "\\<\\(" c-keywords "\\)\\>")
989 '(0 font-lock-keyword-face))
990
991 ;; --- Handle numbers too ---
992 ;;
993 ;; This looks strange, I know. It corresponds to the
994 ;; preprocessor's idea of what a number looks like, rather than
995 ;; anything sensible.
996
997 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
998 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
999 '(0 mdw-number-face))
1000
1001 ;; --- And anything else is punctuation ---
1002
1003 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1004 '(0 mdw-punct-face))))))
1005
1006;;;----- AP calc mode -------------------------------------------------------
1007
1008(defun apcalc-mode ()
1009 (interactive)
1010 (c-mode)
1011 (setq major-mode 'apcalc-mode)
1012 (setq mode-name "AP Calc")
1013 (run-hooks 'apcalc-mode-hook))
1014
1015(defun mdw-fontify-apcalc ()
1016
1017 ;; --- Fiddle with some syntax codes ---
1018
f617db13
MW
1019 (modify-syntax-entry ?* ". 23")
1020 (modify-syntax-entry ?/ ". 14")
1021
1022 ;; --- Other stuff ---
1023
1024 (mdw-c-style)
1025 (setq c-hanging-comment-ender-p nil)
1026 (setq c-backslash-column 72)
1027 (setq comment-start "/* ")
1028 (setq comment-end " */")
1029 (setq mdw-fill-prefix
1030 `((,(concat "\\([ \t]*/?\\)"
1031 "\\([\*/][ \t]*\\)"
1032 "\\([A-Za-z]+:[ \t]*\\)?"
1033 mdw-hanging-indents)
1034 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
1035
1036 ;; --- Now define things to be fontified ---
1037
02109a0d 1038 (make-local-variable 'font-lock-keywords)
f617db13 1039 (let ((c-keywords
8d6d55b9
MW
1040 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1041 "do" "else" "exit" "for" "global" "goto" "help" "if"
1042 "local" "mat" "obj" "print" "quit" "read" "return"
1043 "show" "static" "switch" "while" "write")))
f617db13
MW
1044
1045 (setq font-lock-keywords
1046 (list
f617db13
MW
1047
1048 ;; --- Handle the keywords defined above ---
1049
1050 (list (concat "\\<\\(" c-keywords "\\)\\>")
1051 '(0 font-lock-keyword-face))
1052
1053 ;; --- Handle numbers too ---
1054 ;;
1055 ;; This looks strange, I know. It corresponds to the
1056 ;; preprocessor's idea of what a number looks like, rather than
1057 ;; anything sensible.
1058
1059 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1060 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1061 '(0 mdw-number-face))
1062
1063 ;; --- And anything else is punctuation ---
1064
1065 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1066 '(0 mdw-punct-face))))))
1067
1068;;;----- Java programming configuration -------------------------------------
1069
1070;; --- Make indentation nice ---
1071
1072(defun mdw-java-style ()
1073 (c-add-style "[mdw] Java style"
1074 '((c-basic-offset . 2)
f617db13
MW
1075 (c-offsets-alist (substatement-open . 0)
1076 (label . +)
1077 (case-label . +)
1078 (access-label . 0)
1079 (inclass . +)
1080 (statement-case-intro . +)))
1081 t))
1082
1083;; --- Declare Java fontification style ---
1084
1085(defun mdw-fontify-java ()
1086
1087 ;; --- Other stuff ---
1088
1089 (mdw-java-style)
f617db13
MW
1090 (setq c-hanging-comment-ender-p nil)
1091 (setq c-backslash-column 72)
1092 (setq comment-start "/* ")
1093 (setq comment-end " */")
1094 (setq mdw-fill-prefix
1095 `((,(concat "\\([ \t]*/?\\)"
1096 "\\([\*/][ \t]*\\)"
1097 "\\([A-Za-z]+:[ \t]*\\)?"
1098 mdw-hanging-indents)
1099 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
1100
1101 ;; --- Now define things to be fontified ---
1102
02109a0d 1103 (make-local-variable 'font-lock-keywords)
f617db13 1104 (let ((java-keywords
8d6d55b9
MW
1105 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1106 "char" "class" "const" "continue" "default" "do"
1107 "double" "else" "extends" "final" "finally" "float"
1108 "for" "goto" "if" "implements" "import" "instanceof"
1109 "int" "interface" "long" "native" "new" "package"
1110 "private" "protected" "public" "return" "short"
1111 "static" "super" "switch" "synchronized" "this"
1112 "throw" "throws" "transient" "try" "void" "volatile"
1113 "while"
1114
1115 "false" "null" "true")))
f617db13
MW
1116
1117 (setq font-lock-keywords
1118 (list
f617db13
MW
1119
1120 ;; --- Handle the keywords defined above ---
1121
1122 (list (concat "\\<\\(" java-keywords "\\)\\>")
1123 '(0 font-lock-keyword-face))
1124
1125 ;; --- Handle numbers too ---
1126 ;;
1127 ;; The following isn't quite right, but it's close enough.
1128
1129 (list (concat "\\<\\("
1130 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1131 "[0-9]+\\(\\.[0-9]*\\|\\)"
1132 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1133 "[lLfFdD]?")
1134 '(0 mdw-number-face))
1135
1136 ;; --- And anything else is punctuation ---
1137
1138 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1139 '(0 mdw-punct-face))))))
1140
e808c1e5
MW
1141;;;----- C# programming configuration ---------------------------------------
1142
1143;; --- Make indentation nice ---
1144
1145(defun mdw-csharp-style ()
1146 (c-add-style "[mdw] C# style"
1147 '((c-basic-offset . 2)
e808c1e5
MW
1148 (c-offsets-alist (substatement-open . 0)
1149 (label . 0)
1150 (case-label . +)
1151 (access-label . 0)
1152 (inclass . +)
1153 (statement-case-intro . +)))
1154 t))
1155
1156;; --- Declare C# fontification style ---
1157
1158(defun mdw-fontify-csharp ()
1159
1160 ;; --- Other stuff ---
1161
1162 (mdw-csharp-style)
e808c1e5
MW
1163 (setq c-hanging-comment-ender-p nil)
1164 (setq c-backslash-column 72)
1165 (setq comment-start "/* ")
1166 (setq comment-end " */")
1167 (setq mdw-fill-prefix
1168 `((,(concat "\\([ \t]*/?\\)"
1169 "\\([\*/][ \t]*\\)"
1170 "\\([A-Za-z]+:[ \t]*\\)?"
1171 mdw-hanging-indents)
1172 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
1173
1174 ;; --- Now define things to be fontified ---
1175
1176 (make-local-variable 'font-lock-keywords)
1177 (let ((csharp-keywords
8d6d55b9
MW
1178 (mdw-regexps "abstract" "as" "base" "bool" "break"
1179 "byte" "case" "catch" "char" "checked"
1180 "class" "const" "continue" "decimal" "default"
1181 "delegate" "do" "double" "else" "enum"
1182 "event" "explicit" "extern" "false" "finally"
1183 "fixed" "float" "for" "foreach" "goto"
1184 "if" "implicit" "in" "int" "interface"
1185 "internal" "is" "lock" "long" "namespace"
1186 "new" "null" "object" "operator" "out"
1187 "override" "params" "private" "protected" "public"
1188 "readonly" "ref" "return" "sbyte" "sealed"
1189 "short" "sizeof" "stackalloc" "static" "string"
1190 "struct" "switch" "this" "throw" "true"
1191 "try" "typeof" "uint" "ulong" "unchecked"
1192 "unsafe" "ushort" "using" "virtual" "void"
1193 "volatile" "while" "yield")))
e808c1e5
MW
1194
1195 (setq font-lock-keywords
1196 (list
e808c1e5
MW
1197
1198 ;; --- Handle the keywords defined above ---
1199
1200 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1201 '(0 font-lock-keyword-face))
1202
1203 ;; --- Handle numbers too ---
1204 ;;
1205 ;; The following isn't quite right, but it's close enough.
1206
1207 (list (concat "\\<\\("
1208 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1209 "[0-9]+\\(\\.[0-9]*\\|\\)"
1210 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1211 "[lLfFdD]?")
1212 '(0 mdw-number-face))
1213
1214 ;; --- And anything else is punctuation ---
1215
1216 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1217 '(0 mdw-punct-face))))))
1218
1219(defun csharp-mode ()
1220 (interactive)
1221 (java-mode)
1222 (setq major-mode 'csharp-mode)
1223 (setq mode-name "C#")
1224 (mdw-fontify-csharp)
1225 (run-hooks 'csharp-mode-hook))
1226
f617db13
MW
1227;;;----- Awk programming configuration --------------------------------------
1228
1229;; --- Make Awk indentation nice ---
1230
1231(defun mdw-awk-style ()
1232 (c-add-style "[mdw] Awk style"
1233 '((c-basic-offset . 2)
f617db13
MW
1234 (c-offsets-alist (substatement-open . 0)
1235 (statement-cont . 0)
1236 (statement-case-intro . +)))
1237 t))
1238
1239;; --- Declare Awk fontification style ---
1240
1241(defun mdw-fontify-awk ()
1242
1243 ;; --- Miscellaneous fiddling ---
1244
f617db13
MW
1245 (mdw-awk-style)
1246 (setq c-backslash-column 72)
1247 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1248
1249 ;; --- Now define things to be fontified ---
1250
02109a0d 1251 (make-local-variable 'font-lock-keywords)
f617db13 1252 (let ((c-keywords
8d6d55b9
MW
1253 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1254 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1255 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1256 "RSTART" "RLENGTH" "RT" "SUBSEP"
1257 "atan2" "break" "close" "continue" "cos" "delete"
1258 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1259 "function" "gensub" "getline" "gsub" "if" "in"
1260 "index" "int" "length" "log" "match" "next" "rand"
1261 "return" "print" "printf" "sin" "split" "sprintf"
1262 "sqrt" "srand" "strftime" "sub" "substr" "system"
1263 "systime" "tolower" "toupper" "while")))
f617db13
MW
1264
1265 (setq font-lock-keywords
1266 (list
f617db13
MW
1267
1268 ;; --- Handle the keywords defined above ---
1269
1270 (list (concat "\\<\\(" c-keywords "\\)\\>")
1271 '(0 font-lock-keyword-face))
1272
1273 ;; --- Handle numbers too ---
1274 ;;
1275 ;; The following isn't quite right, but it's close enough.
1276
1277 (list (concat "\\<\\("
1278 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1279 "[0-9]+\\(\\.[0-9]*\\|\\)"
1280 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1281 "[uUlL]*")
1282 '(0 mdw-number-face))
1283
1284 ;; --- And anything else is punctuation ---
1285
1286 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1287 '(0 mdw-punct-face))))))
1288
1289;;;----- Perl programming style ---------------------------------------------
1290
1291;; --- Perl indentation style ---
1292
f617db13
MW
1293(setq cperl-indent-level 2)
1294(setq cperl-continued-statement-offset 2)
1295(setq cperl-continued-brace-offset 0)
1296(setq cperl-brace-offset -2)
1297(setq cperl-brace-imaginary-offset 0)
1298(setq cperl-label-offset 0)
1299
1300;; --- Define perl fontification style ---
1301
1302(defun mdw-fontify-perl ()
1303
1304 ;; --- Miscellaneous fiddling ---
1305
f617db13
MW
1306 (modify-syntax-entry ?$ "\\")
1307 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1308 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1309
1310 ;; --- Now define fontification things ---
1311
02109a0d 1312 (make-local-variable 'font-lock-keywords)
f617db13 1313 (let ((perl-keywords
8d6d55b9
MW
1314 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1315 "for" "foreach" "ge" "gt" "goto" "if"
1316 "last" "le" "lt" "local" "my" "ne" "next" "or"
1317 "package" "redo" "require" "return" "sub"
1318 "undef" "unless" "until" "use" "while")))
f617db13
MW
1319
1320 (setq font-lock-keywords
1321 (list
f617db13
MW
1322
1323 ;; --- Set up the keywords defined above ---
1324
1325 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1326 '(0 font-lock-keyword-face))
1327
1328 ;; --- At least numbers are simpler than C ---
1329
1330 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1331 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1332 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1333 '(0 mdw-number-face))
1334
1335 ;; --- And anything else is punctuation ---
1336
1337 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1338 '(0 mdw-punct-face))))))
1339
1340(defun perl-number-tests (&optional arg)
1341 "Assign consecutive numbers to lines containing `#t'. With ARG,
1342strip numbers instead."
1343 (interactive "P")
1344 (save-excursion
1345 (goto-char (point-min))
1346 (let ((i 0) (fmt (if arg "" " %4d")))
1347 (while (search-forward "#t" nil t)
1348 (delete-region (point) (line-end-position))
1349 (setq i (1+ i))
1350 (insert (format fmt i)))
1351 (goto-char (point-min))
1352 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1353 (replace-match (format "\\1%d" i))))))
1354
1355;;;----- Python programming style -------------------------------------------
1356
1357;; --- Define Python fontification style ---
1358
f617db13
MW
1359(defun mdw-fontify-python ()
1360
1361 ;; --- Miscellaneous fiddling ---
1362
f617db13
MW
1363 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1364
1365 ;; --- Now define fontification things ---
1366
02109a0d 1367 (make-local-variable 'font-lock-keywords)
f617db13 1368 (let ((python-keywords
8d6d55b9
MW
1369 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1370 "del" "elif" "else" "except" "exec" "finally" "for"
1371 "from" "global" "if" "import" "in" "is" "lambda"
1372 "not" "or" "pass" "print" "raise" "return" "try"
e61fa1ae 1373 "while" "with" "yield")))
f617db13
MW
1374 (setq font-lock-keywords
1375 (list
f617db13
MW
1376
1377 ;; --- Set up the keywords defined above ---
1378
1379 (list (concat "\\<\\(" python-keywords "\\)\\>")
1380 '(0 font-lock-keyword-face))
1381
1382 ;; --- At least numbers are simpler than C ---
1383
1384 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1385 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1386 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1387 '(0 mdw-number-face))
1388
1389 ;; --- And anything else is punctuation ---
1390
1391 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1392 '(0 mdw-punct-face))))))
1393
1394;;;----- ARM assembler programming configuration ----------------------------
1395
1396;; --- There doesn't appear to be an Emacs mode for this yet ---
1397;;
1398;; Better do something about that, I suppose.
1399
1400(defvar arm-assembler-mode-map nil)
1401(defvar arm-assembler-abbrev-table nil)
1402(defvar arm-assembler-mode-syntax-table (make-syntax-table))
1403
1404(or arm-assembler-mode-map
1405 (progn
1406 (setq arm-assembler-mode-map (make-sparse-keymap))
1407 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1408 (define-key arm-assembler-mode-map [C-return] 'newline)
1409 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1410
1411(defun arm-assembler-mode ()
1412 "Major mode for ARM assembler programs"
1413 (interactive)
1414
1415 ;; --- Do standard major mode things ---
1416
1417 (kill-all-local-variables)
1418 (use-local-map arm-assembler-mode-map)
1419 (setq local-abbrev-table arm-assembler-abbrev-table)
1420 (setq major-mode 'arm-assembler-mode)
1421 (setq mode-name "ARM assembler")
1422
1423 ;; --- Set up syntax table ---
1424
1425 (set-syntax-table arm-assembler-mode-syntax-table)
1426 (modify-syntax-entry ?; ; Nasty hack
1427 "<" arm-assembler-mode-syntax-table)
1428 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1429 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1430
1431 (make-local-variable 'comment-start)
1432 (setq comment-start ";")
1433 (make-local-variable 'comment-end)
1434 (setq comment-end "")
1435 (make-local-variable 'comment-column)
1436 (setq comment-column 48)
1437 (make-local-variable 'comment-start-skip)
1438 (setq comment-start-skip ";+[ \t]*")
1439
1440 ;; --- Play with indentation ---
1441
1442 (make-local-variable 'indent-line-function)
1443 (setq indent-line-function 'indent-relative-maybe)
1444
1445 ;; --- Set fill prefix ---
1446
1447 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1448
1449 ;; --- Fiddle with fontification ---
1450
02109a0d 1451 (make-local-variable 'font-lock-keywords)
f617db13
MW
1452 (setq font-lock-keywords
1453 (list
f617db13
MW
1454
1455 ;; --- Handle numbers too ---
1456 ;;
1457 ;; The following isn't quite right, but it's close enough.
1458
1459 (list (concat "\\("
1460 "&[0-9a-fA-F]+\\|"
1461 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1462 "\\)")
1463 '(0 mdw-number-face))
1464
1465 ;; --- Do something about operators ---
1466
1467 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1468 '(1 font-lock-keyword-face)
1469 '(2 font-lock-string-face))
1470 (list ":[a-zA-Z]+:"
1471 '(0 font-lock-keyword-face))
1472
1473 ;; --- Do menemonics and directives ---
1474
1475 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1476 '(1 font-lock-keyword-face))
1477
1478 ;; --- And anything else is punctuation ---
1479
1480 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1481 '(0 mdw-punct-face))))
1482
1483 (run-hooks 'arm-assembler-mode-hook))
1484
30c8a8fb
MW
1485;;;----- Assembler mode -----------------------------------------------------
1486
1487(defun mdw-fontify-asm ()
1488 (modify-syntax-entry ?' "\"")
1489 (modify-syntax-entry ?. "w")
1490 (setf fill-prefix nil)
1491 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1492
f617db13
MW
1493;;;----- TCL configuration --------------------------------------------------
1494
1495(defun mdw-fontify-tcl ()
1496 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1497 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
02109a0d 1498 (make-local-variable 'font-lock-keywords)
f617db13
MW
1499 (setq font-lock-keywords
1500 (list
f617db13
MW
1501 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1502 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1503 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1504 '(0 mdw-number-face))
1505 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1506 '(0 mdw-punct-face)))))
1507
1508;;;----- REXX configuration -------------------------------------------------
1509
1510(defun mdw-rexx-electric-* ()
1511 (interactive)
1512 (insert ?*)
1513 (rexx-indent-line))
1514
1515(defun mdw-rexx-indent-newline-indent ()
1516 (interactive)
1517 (rexx-indent-line)
1518 (if abbrev-mode (expand-abbrev))
1519 (newline-and-indent))
1520
1521(defun mdw-fontify-rexx ()
1522
1523 ;; --- Various bits of fiddling ---
1524
1525 (setq mdw-auto-indent nil)
1526 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1527 (local-set-key [?*] 'mdw-rexx-electric-*)
1528 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
e443a4cd 1529 '(?! ?? ?# ?@ ?$))
f617db13
MW
1530 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1531
1532 ;; --- Set up keywords and things for fontification ---
1533
1534 (make-local-variable 'font-lock-keywords-case-fold-search)
1535 (setq font-lock-keywords-case-fold-search t)
1536
1537 (setq rexx-indent 2)
1538 (setq rexx-end-indent rexx-indent)
f617db13
MW
1539 (setq rexx-cont-indent rexx-indent)
1540
02109a0d 1541 (make-local-variable 'font-lock-keywords)
f617db13 1542 (let ((rexx-keywords
8d6d55b9
MW
1543 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1544 "else" "end" "engineering" "exit" "expose" "for"
1545 "forever" "form" "fuzz" "if" "interpret" "iterate"
1546 "leave" "linein" "name" "nop" "numeric" "off" "on"
1547 "options" "otherwise" "parse" "procedure" "pull"
1548 "push" "queue" "return" "say" "select" "signal"
1549 "scientific" "source" "then" "trace" "to" "until"
1550 "upper" "value" "var" "version" "when" "while"
1551 "with"
1552
1553 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1554 "center" "center" "charin" "charout" "chars"
1555 "compare" "condition" "copies" "c2d" "c2x"
1556 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1557 "errortext" "format" "fuzz" "insert" "lastpos"
1558 "left" "length" "lineout" "lines" "max" "min"
1559 "overlay" "pos" "queued" "random" "reverse" "right"
1560 "sign" "sourceline" "space" "stream" "strip"
1561 "substr" "subword" "symbol" "time" "translate"
1562 "trunc" "value" "verify" "word" "wordindex"
1563 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1564 "x2d")))
f617db13
MW
1565
1566 (setq font-lock-keywords
1567 (list
f617db13
MW
1568
1569 ;; --- Set up the keywords defined above ---
1570
1571 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1572 '(0 font-lock-keyword-face))
1573
1574 ;; --- Fontify all symbols the same way ---
1575
1576 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1577 "[A-Za-z0-9.!?_#@$]+\\)")
1578 '(0 font-lock-variable-name-face))
1579
1580 ;; --- And everything else is punctuation ---
1581
1582 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1583 '(0 mdw-punct-face))))))
1584
1585;;;----- Standard ML programming style --------------------------------------
1586
1587(defun mdw-fontify-sml ()
1588
1589 ;; --- Make underscore an honorary letter ---
1590
f617db13
MW
1591 (modify-syntax-entry ?' "w")
1592
1593 ;; --- Set fill prefix ---
1594
1595 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1596
1597 ;; --- Now define fontification things ---
1598
02109a0d 1599 (make-local-variable 'font-lock-keywords)
f617db13 1600 (let ((sml-keywords
8d6d55b9
MW
1601 (mdw-regexps "abstype" "and" "andalso" "as"
1602 "case"
1603 "datatype" "do"
1604 "else" "end" "eqtype" "exception"
1605 "fn" "fun" "functor"
1606 "handle"
1607 "if" "in" "include" "infix" "infixr"
1608 "let" "local"
1609 "nonfix"
1610 "of" "op" "open" "orelse"
1611 "raise" "rec"
1612 "sharing" "sig" "signature" "struct" "structure"
1613 "then" "type"
1614 "val"
1615 "where" "while" "with" "withtype")))
f617db13
MW
1616
1617 (setq font-lock-keywords
1618 (list
f617db13
MW
1619
1620 ;; --- Set up the keywords defined above ---
1621
1622 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1623 '(0 font-lock-keyword-face))
1624
1625 ;; --- At least numbers are simpler than C ---
1626
1627 (list (concat "\\<\\(\\~\\|\\)"
1628 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
852cd5fb
MW
1629 "[wW][0-9]+\\)\\|"
1630 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1631 "\\([eE]\\(\\~\\|\\)"
1632 "[0-9]+\\|\\)\\)\\)")
f617db13
MW
1633 '(0 mdw-number-face))
1634
1635 ;; --- And anything else is punctuation ---
1636
1637 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1638 '(0 mdw-punct-face))))))
1639
1640;;;----- Haskell configuration ----------------------------------------------
1641
1642(defun mdw-fontify-haskell ()
1643
1644 ;; --- Fiddle with syntax table to get comments right ---
1645
f617db13
MW
1646 (modify-syntax-entry ?' "\"")
1647 (modify-syntax-entry ?- ". 123")
1648 (modify-syntax-entry ?{ ". 1b")
1649 (modify-syntax-entry ?} ". 4b")
1650 (modify-syntax-entry ?\n ">")
1651
1652 ;; --- Set fill prefix ---
1653
1654 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1655
1656 ;; --- Fiddle with fontification ---
1657
02109a0d 1658 (make-local-variable 'font-lock-keywords)
f617db13 1659 (let ((haskell-keywords
8d6d55b9
MW
1660 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1661 "deriving" "do" "else" "foreign" "hiding" "if"
1662 "import" "in" "infix" "infixl" "infixr" "instance"
1663 "let" "module" "newtype" "of" "qualified" "safe"
1664 "stdcall" "then" "type" "unsafe" "where")))
f617db13
MW
1665
1666 (setq font-lock-keywords
1667 (list
f617db13
MW
1668 (list "--.*$"
1669 '(0 font-lock-comment-face))
1670 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1671 '(0 font-lock-keyword-face))
1672 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1673 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1674 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1675 '(0 mdw-number-face))
1676 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1677 '(0 mdw-punct-face))))))
1678
2ded9493
MW
1679;;;----- Erlang configuration -----------------------------------------------
1680
1681(setq erlang-electric-commannds
1682 '(erlang-electric-newline erlang-electric-semicolon))
1683
1684(defun mdw-fontify-erlang ()
1685
1686 ;; --- Set fill prefix ---
1687
1688 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1689
1690 ;; --- Fiddle with fontification ---
1691
1692 (make-local-variable 'font-lock-keywords)
1693 (let ((erlang-keywords
1694 (mdw-regexps "after" "and" "andalso"
1695 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1696 "case" "catch" "cond"
1697 "div" "end" "fun" "if" "let" "not"
1698 "of" "or" "orelse"
1699 "query" "receive" "rem" "try" "when" "xor")))
1700
1701 (setq font-lock-keywords
1702 (list
1703 (list "%.*$"
1704 '(0 font-lock-comment-face))
1705 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1706 '(0 font-lock-keyword-face))
1707 (list (concat "^-\\sw+\\>")
1708 '(0 font-lock-keyword-face))
1709 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1710 '(0 mdw-number-face))
1711 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1712 '(0 mdw-punct-face))))))
1713
f617db13
MW
1714;;;----- Texinfo configuration ----------------------------------------------
1715
1716(defun mdw-fontify-texinfo ()
1717
1718 ;; --- Set fill prefix ---
1719
1720 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1721
1722 ;; --- Real fontification things ---
1723
02109a0d 1724 (make-local-variable 'font-lock-keywords)
f617db13
MW
1725 (setq font-lock-keywords
1726 (list
f617db13
MW
1727
1728 ;; --- Environment names are keywords ---
1729
1730 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1731 '(2 font-lock-keyword-face))
1732
1733 ;; --- Unmark escaped magic characters ---
1734
1735 (list "\\(@\\)\\([@{}]\\)"
1736 '(1 font-lock-keyword-face)
1737 '(2 font-lock-variable-name-face))
1738
1739 ;; --- Make sure we get comments properly ---
1740
1741 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1742 '(0 font-lock-comment-face))
1743
1744 ;; --- Command names are keywords ---
1745
1746 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1747 '(0 font-lock-keyword-face))
1748
1749 ;; --- Fontify TeX special characters as punctuation ---
1750
1751 (list "[{}]+"
1752 '(0 mdw-punct-face)))))
1753
1754;;;----- TeX and LaTeX configuration ----------------------------------------
1755
1756(defun mdw-fontify-tex ()
1757 (setq ispell-parser 'tex)
55f80fae 1758 (turn-on-reftex)
f617db13
MW
1759
1760 ;; --- Don't make maths into a string ---
1761
1762 (modify-syntax-entry ?$ ".")
1763 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1764 (local-set-key [?$] 'self-insert-command)
1765
1766 ;; --- Set fill prefix ---
1767
1768 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1769
1770 ;; --- Real fontification things ---
1771
02109a0d 1772 (make-local-variable 'font-lock-keywords)
f617db13
MW
1773 (setq font-lock-keywords
1774 (list
f617db13
MW
1775
1776 ;; --- Environment names are keywords ---
1777
1778 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1779 "{\\([^}\n]*\\)}")
1780 '(2 font-lock-keyword-face))
1781
1782 ;; --- Suspended environment names are keywords too ---
1783
1784 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1785 "{\\([^}\n]*\\)}")
1786 '(3 font-lock-keyword-face))
1787
1788 ;; --- Command names are keywords ---
1789
1790 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1791 '(0 font-lock-keyword-face))
1792
1793 ;; --- Handle @/.../ for italics ---
1794
1795 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
852cd5fb
MW
1796 ;; '(1 font-lock-keyword-face)
1797 ;; '(3 font-lock-keyword-face))
f617db13
MW
1798
1799 ;; --- Handle @*...* for boldness ---
1800
1801 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
852cd5fb
MW
1802 ;; '(1 font-lock-keyword-face)
1803 ;; '(3 font-lock-keyword-face))
f617db13
MW
1804
1805 ;; --- Handle @`...' for literal syntax things ---
1806
1807 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
852cd5fb
MW
1808 ;; '(1 font-lock-keyword-face)
1809 ;; '(3 font-lock-keyword-face))
f617db13
MW
1810
1811 ;; --- Handle @<...> for nonterminals ---
1812
1813 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
852cd5fb
MW
1814 ;; '(1 font-lock-keyword-face)
1815 ;; '(3 font-lock-keyword-face))
f617db13
MW
1816
1817 ;; --- Handle other @-commands ---
1818
1819 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
852cd5fb 1820 ;; '(0 font-lock-keyword-face))
f617db13
MW
1821
1822 ;; --- Make sure we get comments properly ---
1823
1824 (list "%.*"
1825 '(0 font-lock-comment-face))
1826
1827 ;; --- Fontify TeX special characters as punctuation ---
1828
1829 (list "[$^_{}#&]"
1830 '(0 mdw-punct-face)))))
1831
f25cf300
MW
1832;;;----- SGML hacking -------------------------------------------------------
1833
1834(defun mdw-sgml-mode ()
1835 (interactive)
1836 (sgml-mode)
1837 (mdw-standard-fill-prefix "")
1838 (make-variable-buffer-local 'sgml-delimiters)
1839 (setq sgml-delimiters
1840 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
1841 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
1842 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
1843 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
1844 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
1845 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
1846 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
1847 "NULL" ""))
1848 (setq major-mode 'mdw-sgml-mode)
1849 (setq mode-name "[mdw] SGML")
1850 (run-hooks 'mdw-sgml-mode-hook))
1851
f617db13
MW
1852;;;----- Shell scripts ------------------------------------------------------
1853
1854(defun mdw-setup-sh-script-mode ()
1855
1856 ;; --- Fetch the shell interpreter's name ---
1857
1858 (let ((shell-name sh-shell-file))
1859
1860 ;; --- Try reading the hash-bang line ---
1861
1862 (save-excursion
1863 (goto-char (point-min))
1864 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
1865 (setq shell-name (match-string 1))))
1866
1867 ;; --- Now try to set the shell ---
1868 ;;
1869 ;; Don't let `sh-set-shell' bugger up my script.
1870
1871 (let ((executable-set-magic #'(lambda (s &rest r) s)))
1872 (sh-set-shell shell-name)))
1873
1874 ;; --- Now enable my keys and the fontification ---
1875
1876 (mdw-misc-mode-config)
1877
1878 ;; --- Set the indentation level correctly ---
1879
1880 (setq sh-indentation 2)
1881 (setq sh-basic-offset 2))
1882
1883;;;----- Messages-file mode -------------------------------------------------
1884
4bb22eea 1885(defun messages-mode-guts ()
f617db13
MW
1886 (setq messages-mode-syntax-table (make-syntax-table))
1887 (set-syntax-table messages-mode-syntax-table)
f617db13
MW
1888 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
1889 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
1890 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
1891 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
1892 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
1893 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
1894 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
1895 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
1896 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
1897 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
1898 (make-local-variable 'comment-start)
1899 (make-local-variable 'comment-end)
1900 (make-local-variable 'indent-line-function)
1901 (setq indent-line-function 'indent-relative)
1902 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1903 (make-local-variable 'font-lock-defaults)
4bb22eea 1904 (make-local-variable 'messages-mode-keywords)
f617db13 1905 (let ((keywords
8d6d55b9
MW
1906 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
1907 "export" "enum" "fixed-octetstring" "flags"
1908 "harmless" "map" "nested" "optional"
1909 "optional-tagged" "package" "primitive"
1910 "primitive-nullfree" "relaxed[ \t]+enum"
1911 "set" "table" "tagged-optional" "union"
1912 "variadic" "vector" "version" "version-tag")))
4bb22eea 1913 (setq messages-mode-keywords
f617db13
MW
1914 (list
1915 (list (concat "\\<\\(" keywords "\\)\\>:")
1916 '(0 font-lock-keyword-face))
1917 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
1918 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
1919 (0 font-lock-variable-name-face))
1920 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
1921 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1922 (0 mdw-punct-face)))))
1923 (setq font-lock-defaults
4bb22eea 1924 '(messages-mode-keywords nil nil nil nil))
f617db13
MW
1925 (run-hooks 'messages-file-hook))
1926
1927(defun messages-mode ()
1928 (interactive)
1929 (fundamental-mode)
1930 (setq major-mode 'messages-mode)
1931 (setq mode-name "Messages")
4bb22eea 1932 (messages-mode-guts)
f617db13
MW
1933 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
1934 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
1935 (setq comment-start "# ")
1936 (setq comment-end "")
1937 (turn-on-font-lock-if-enabled)
1938 (run-hooks 'messages-mode-hook))
1939
1940(defun cpp-messages-mode ()
1941 (interactive)
1942 (fundamental-mode)
1943 (setq major-mode 'cpp-messages-mode)
1944 (setq mode-name "CPP Messages")
4bb22eea 1945 (messages-mode-guts)
f617db13
MW
1946 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
1947 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
1948 (setq comment-start "/* ")
1949 (setq comment-end " */")
1950 (let ((preprocessor-keywords
8d6d55b9
MW
1951 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1952 "ident" "if" "ifdef" "ifndef" "import" "include"
1953 "line" "pragma" "unassert" "undef" "warning")))
4bb22eea 1954 (setq messages-mode-keywords
f617db13
MW
1955 (append (list (list (concat "^[ \t]*\\#[ \t]*"
1956 "\\(include\\|import\\)"
1957 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1958 '(2 font-lock-string-face))
1959 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1960 preprocessor-keywords
852cd5fb 1961 "\\)\\>\\|[0-9]+\\|$\\)\\)")
f617db13 1962 '(1 font-lock-keyword-face)))
4bb22eea 1963 messages-mode-keywords)))
f617db13 1964 (turn-on-font-lock-if-enabled)
297d60aa 1965 (run-hooks 'cpp-messages-mode-hook))
f617db13 1966
297d60aa
MW
1967(add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
1968(add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
f617db13
MW
1969; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
1970
1971;;;----- Messages-file mode -------------------------------------------------
1972
1973(defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
1974 "Face to use for subsittution directives.")
1975(make-face 'mallow-driver-substitution-face)
1976(defvar mallow-driver-text-face 'mallow-driver-text-face
1977 "Face to use for body text.")
1978(make-face 'mallow-driver-text-face)
1979
1980(defun mallow-driver-mode ()
1981 (interactive)
1982 (fundamental-mode)
1983 (setq major-mode 'mallow-driver-mode)
1984 (setq mode-name "Mallow driver")
1985 (setq mallow-driver-mode-syntax-table (make-syntax-table))
1986 (set-syntax-table mallow-driver-mode-syntax-table)
1987 (make-local-variable 'comment-start)
1988 (make-local-variable 'comment-end)
1989 (make-local-variable 'indent-line-function)
1990 (setq indent-line-function 'indent-relative)
1991 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1992 (make-local-variable 'font-lock-defaults)
1993 (make-local-variable 'mallow-driver-mode-keywords)
1994 (let ((keywords
8d6d55b9
MW
1995 (mdw-regexps "each" "divert" "file" "if"
1996 "perl" "set" "string" "type" "write")))
f617db13
MW
1997 (setq mallow-driver-mode-keywords
1998 (list
1999 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2000 '(0 font-lock-keyword-face))
2001 (list "^%\\s *\\(#.*\\|\\)$"
2002 '(0 font-lock-comment-face))
2003 (list "^%"
2004 '(0 font-lock-keyword-face))
2005 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2006 (list "\\${[^}]*}"
2007 '(0 mallow-driver-substitution-face t)))))
2008 (setq font-lock-defaults
2009 '(mallow-driver-mode-keywords nil nil nil nil))
2010 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2011 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2012 (setq comment-start "%# ")
2013 (setq comment-end "")
2014 (turn-on-font-lock-if-enabled)
2015 (run-hooks 'mallow-driver-mode-hook))
2016
2017(add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2018
2019;;;----- NFast debugs -------------------------------------------------------
2020
2021(defun nfast-debug-mode ()
2022 (interactive)
2023 (fundamental-mode)
2024 (setq major-mode 'nfast-debug-mode)
2025 (setq mode-name "NFast debug")
2026 (setq messages-mode-syntax-table (make-syntax-table))
2027 (set-syntax-table messages-mode-syntax-table)
2028 (make-local-variable 'font-lock-defaults)
2029 (make-local-variable 'nfast-debug-mode-keywords)
2030 (setq truncate-lines t)
2031 (setq nfast-debug-mode-keywords
2032 (list
2033 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2034 (0 font-lock-keyword-face))
2035 (list (concat "^[ \t]+\\(\\("
2036 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2037 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2038 "[ \t]+\\)*"
2039 "[0-9a-fA-F]+\\)[ \t]*$")
2040 '(0 mdw-number-face))
2041 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2042 (1 font-lock-keyword-face))
2043 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2044 (1 font-lock-warning-face))
2045 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2046 (1 nil))
2047 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2048 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2049 '(1 font-lock-keyword-face))
2050 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2051 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2052 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2053 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2054 (setq font-lock-defaults
2055 '(nfast-debug-mode-keywords nil nil nil nil))
2056 (turn-on-font-lock-if-enabled)
2057 (run-hooks 'nfast-debug-mode-hook))
2058
2059;;;----- Other languages ----------------------------------------------------
2060
2061;; --- Smalltalk ---
2062
2063(defun mdw-setup-smalltalk ()
2064 (and mdw-auto-indent
2065 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2066 (make-variable-buffer-local 'mdw-auto-indent)
2067 (setq mdw-auto-indent nil)
2068 (local-set-key "\C-i" 'smalltalk-reindent))
2069
2070(defun mdw-fontify-smalltalk ()
02109a0d 2071 (make-local-variable 'font-lock-keywords)
f617db13
MW
2072 (setq font-lock-keywords
2073 (list
f617db13
MW
2074 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2075 '(0 font-lock-keyword-face))
2076 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2077 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2078 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2079 '(0 mdw-number-face))
2080 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2081 '(0 mdw-punct-face)))))
2082
2083;; --- Lispy languages ---
2084
873d87df
MW
2085;; Unpleasant bodge.
2086(unless (boundp 'slime-repl-mode-map)
2087 (setq slime-repl-mode-map (make-sparse-keymap)))
2088
f617db13
MW
2089(defun mdw-indent-newline-and-indent ()
2090 (interactive)
2091 (indent-for-tab-command)
2092 (newline-and-indent))
2093
2094(eval-after-load "cl-indent"
2095 '(progn
2096 (mapc #'(lambda (pair)
2097 (put (car pair)
2098 'common-lisp-indent-function
2099 (cdr pair)))
2100 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2101 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2102
2103(defun mdw-common-lisp-indent ()
2104 (make-variable-buffer-local 'lisp-indent-function)
2105 (setq lisp-indent-function 'common-lisp-indent-function))
2106
037be6de 2107(setq lisp-simple-loop-indentation 2
95575d1f
MW
2108 lisp-loop-keyword-indentation 6
2109 lisp-loop-forms-indentation 6)
2110
f617db13
MW
2111(defun mdw-fontify-lispy ()
2112
2113 ;; --- Set fill prefix ---
2114
2115 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2116
2117 ;; --- Not much fontification needed ---
2118
02109a0d 2119 (make-local-variable 'font-lock-keywords)
f617db13
MW
2120 (setq font-lock-keywords
2121 (list
f617db13
MW
2122 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2123 '(0 mdw-punct-face)))))
2124
2125(defun comint-send-and-indent ()
2126 (interactive)
2127 (comint-send-input)
2128 (and mdw-auto-indent
2129 (indent-for-tab-command)))
2130
ec007bea
MW
2131(defun mdw-setup-m4 ()
2132 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2133
f617db13
MW
2134;;;----- Text mode ----------------------------------------------------------
2135
2136(defun mdw-text-mode ()
2137 (setq fill-column 72)
2138 (flyspell-mode t)
2139 (mdw-standard-fill-prefix
c7a8da49 2140 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
f617db13
MW
2141 (auto-fill-mode 1))
2142
5de5db48
MW
2143;;;----- Outline mode -------------------------------------------------------
2144
2145(defun mdw-outline-collapse-all ()
2146 "Completely collapse everything in the entire buffer."
2147 (interactive)
2148 (save-excursion
2149 (goto-char (point-min))
2150 (while (< (point) (point-max))
2151 (hide-subtree)
2152 (forward-line))))
2153
f617db13
MW
2154;;;----- Shell mode ---------------------------------------------------------
2155
2156(defun mdw-sh-mode-setup ()
2157 (local-set-key [?\C-a] 'comint-bol)
2158 (add-hook 'comint-output-filter-functions
2159 'comint-watch-for-password-prompt))
2160
2161(defun mdw-term-mode-setup ()
3d9147ea 2162 (setq term-prompt-regexp shell-prompt-pattern)
f617db13
MW
2163 (make-local-variable 'mouse-yank-at-point)
2164 (make-local-variable 'transient-mark-mode)
2165 (setq mouse-yank-at-point t)
f617db13
MW
2166 (auto-fill-mode -1)
2167 (setq tab-width 8))
2168
3d9147ea
MW
2169(defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2170(defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2171(defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2172(defun term-send-meta-meta-something ()
2173 (interactive)
2174 (term-send-raw-string "\e\e")
2175 (term-send-raw))
2176(eval-after-load 'term
2177 '(progn
2178 (define-key term-raw-map [?\e ?\e] nil)
2179 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2180 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2181 (define-key term-raw-map [M-right] 'term-send-meta-right)
2182 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2183 (define-key term-raw-map [M-left] 'term-send-meta-left)
2184 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2185
f617db13
MW
2186;;;----- That's all, folks --------------------------------------------------
2187
2188(provide 'dot-emacs)