1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
3 ;;; Functions and macros for .emacs
5 ;;; (c) 2004 Mark Wooding
8 ;;;----- Licensing notice ---------------------------------------------------
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.
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.
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.
24 ;;;--------------------------------------------------------------------------
25 ;;; Check command-line.
27 (defvar mdw-fast-startup nil
28 "Whether .emacs should optimize for rapid startup.
29 This may be at the expense of cool features.")
30 (let ((probe nil) (next command-line-args))
32 (cond ((string= (car next) "--mdw-fast-startup")
33 (setq mdw-fast-startup t)
35 (rplacd probe (cdr next))
36 (setq command-line-args (cdr next))))
39 (setq next (cdr next))))
41 ;;;--------------------------------------------------------------------------
42 ;;; Some general utilities.
45 (unless (fboundp 'make-regexp)
49 (defmacro mdw-regexps (&rest list)
50 "Turn a LIST of strings into a single regular expression at compile-time."
53 `',(make-regexp list))
55 ;; Some error trapping.
57 ;; If individual bits of this file go tits-up, we don't particularly want
58 ;; the whole lot to stop right there and then, because it's bloody annoying.
60 (defmacro trap (&rest forms)
61 "Execute FORMS without allowing errors to propagate outside."
65 ,(if (cdr forms) (cons 'progn forms) (car forms))
66 (error (message "Error (trapped): %s in %s"
67 (error-message-string err)
70 ;; Configuration reading.
72 (defvar mdw-config nil)
73 (defun mdw-config (sym)
74 "Read the configuration variable named SYM."
77 (flet ((replace (what with)
78 (goto-char (point-min))
79 (while (re-search-forward what nil t)
80 (replace-match with t))))
82 (insert-file-contents "~/.mdw.conf")
83 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
84 (replace (concat "^[ \t]*"
85 "\\([-a-zA-Z0-9_.]*\\)"
88 "[ \t]**\\(\n\\|$\\)")
90 (car (read-from-string
91 (concat "(" (buffer-string) ")")))))))
92 (cdr (assq sym mdw-config)))
94 ;; Set up the load path convincingly.
96 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
97 (list (concat "/usr/share/"
98 (symbol-name debian-emacs-flavor)
100 (dolist (sub (directory-files dir t))
101 (when (and (file-accessible-directory-p sub)
102 (not (member sub load-path)))
103 (setq load-path (nconc load-path (list sub))))))
105 ;; Is an Emacs library available?
107 (defun library-exists-p (name)
108 "Return non-nil if NAME is an available library.
109 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
110 load path. The non-nil value is the filename we found for the
112 (let ((path load-path) elt (foundp nil))
113 (while (and path (not foundp))
114 (setq elt (car path))
115 (setq path (cdr path))
116 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
117 (and (file-exists-p file) file))
118 (let ((file (concat elt "/" name ".el")))
119 (and (file-exists-p file) file)))))
122 (defun maybe-autoload (symbol file &optional docstring interactivep type)
123 "Set an autoload if the file actually exists."
124 (and (library-exists-p file)
125 (autoload symbol file docstring interactivep type)))
127 ;; Splitting windows.
129 (unless (fboundp 'scroll-bar-columns)
130 (defun scroll-bar-columns (side)
131 (cond ((eq side 'left) 0)
134 (unless (fboundp 'fringe-columns)
135 (defun fringe-columns (side)
136 (cond ((not window-system) 0)
140 (defun mdw-divvy-window (&optional width)
141 "Split a wide window into appropriate widths."
143 (setq width (cond (width (prefix-numeric-value width))
145 (>= emacs-major-version 22))
148 (let* ((win (selected-window))
149 (sb-width (if (not window-system)
152 (dolist (what '(scroll-bar fringe))
153 (dolist (side '(left right))
155 (funcall (intern (concat (symbol-name what)
159 (c (/ (+ (window-width) sb-width)
160 (+ width sb-width))))
163 (split-window-horizontally (+ width sb-width))
165 (select-window win)))
167 ;; Functions for sexp diary entries.
169 (defun mdw-weekday (l)
170 "Return non-nil if `date' falls on one of the days of the week in L.
171 L is a list of day numbers (from 0 to 6 for Sunday through to
172 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
173 the date stored in `date' falls on a listed day, then the
174 function returns non-nil."
175 (let ((d (calendar-day-of-week date)))
177 (memq (nth d '(sunday monday tuesday wednesday
178 thursday friday saturday)) l))))
180 (defun mdw-todo (&optional when)
181 "Return non-nil today, or on WHEN, whichever is later."
182 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
183 (d (calendar-absolute-from-gregorian date)))
185 (setq w (max w (calendar-absolute-from-gregorian
187 ((not european-calendar-style)
199 ;; Fighting with Org-mode's evil key maps.
201 (defvar mdw-evil-keymap-keys
202 '(([S-up] . [?\C-c up])
203 ([S-down] . [?\C-c down])
204 ([S-left] . [?\C-c left])
205 ([S-right] . [?\C-c right])
206 (([M-up] [?\e up]) . [C-up])
207 (([M-down] [?\e down]) . [C-down])
208 (([M-left] [?\e left]) . [C-left])
209 (([M-right] [?\e right]) . [C-right]))
210 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
211 The value is an alist mapping evil keys (as a list, or singleton)
212 to good keys (in the same form).")
214 (defun mdw-clobber-evil-keymap (keymap)
215 "Replace evil key bindings in the KEYMAP.
216 Evil key bindings are defined in `mdw-evil-keymap-keys'."
217 (dolist (entry mdw-evil-keymap-keys)
219 (keys (if (listp (car entry))
222 (replacements (if (listp (cdr entry))
224 (list (cdr entry)))))
227 (setq binding (lookup-key keymap key))
229 (throw 'found nil))))
232 (define-key keymap key nil))
233 (dolist (key replacements)
234 (define-key keymap key binding))))))
236 (eval-after-load "org-latex"
239 "\\documentclass{strayman}
240 \\usepackage[utf8]{inputenc}
241 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
242 \\usepackage[T1]{fontenc}
243 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
244 ("\\section{%s}" . "\\section*{%s}")
245 ("\\subsection{%s}" . "\\subsection*{%s}")
246 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
247 ("\\paragraph{%s}" . "\\paragraph*{%s}")
248 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
249 org-export-latex-classes)))
251 ;;;--------------------------------------------------------------------------
252 ;;; Mail and news hacking.
254 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
255 "Major mode for editing news and mail messages from external programs.
256 Not much right now. Just support for doing MailCrypt stuff."
259 (run-hooks 'mail-setup-hook))
261 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
263 (add-hook 'mdwail-mode-hook
265 (set-buffer-file-coding-system 'utf-8)
266 (make-local-variable 'paragraph-separate)
267 (make-local-variable 'paragraph-start)
268 (setq paragraph-start
269 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
271 (setq paragraph-separate
272 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
273 paragraph-separate))))
275 ;; How to encrypt in mdwmail.
277 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
279 (setq start (save-excursion
280 (goto-char (point-min))
281 (or (search-forward "\n\n" nil t) (point-min)))))
283 (setq end (point-max)))
284 (mc-encrypt-generic recip scm start end from sign))
286 ;; How to sign in mdwmail.
288 (defun mdwmail-mc-sign (key scm start end uclr)
290 (setq start (save-excursion
291 (goto-char (point-min))
292 (or (search-forward "\n\n" nil t) (point-min)))))
294 (setq end (point-max)))
295 (mc-sign-generic key scm start end uclr))
297 ;; Some signature mangling.
299 (defun mdwmail-mangle-signature ()
301 (goto-char (point-min))
302 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
303 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
304 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
306 ;; Insert my login name into message-ids, so I can score replies.
308 (defadvice message-unique-id (after mdw-user-name last activate compile)
309 "Ensure that the user's name appears at the end of the message-id string,
310 so that it can be used for convenient filtering."
311 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
313 ;; Tell my movemail hack where movemail is.
315 ;; This is needed to shup up warnings about LD_PRELOAD.
317 (let ((path exec-path))
319 (let ((try (expand-file-name "movemail" (car path))))
320 (if (file-executable-p try)
321 (setenv "REAL_MOVEMAIL" try))
322 (setq path (cdr path)))))
324 ;;;--------------------------------------------------------------------------
325 ;;; Utility functions.
327 (or (fboundp 'line-number-at-pos)
328 (defun line-number-at-pos (&optional pos)
329 (let ((opoint (or pos (point))) start)
332 (goto-char (point-min))
338 (1+ (count-lines 1 (point))))))))
340 (defun mdw-uniquify-alist (&rest alists)
341 "Return the concatenation of the ALISTS with duplicate elements removed.
342 The first association with a given key prevails; others are
343 ignored. The input lists are not modified, although they'll
344 probably become garbage."
346 (let ((start-list (cons nil nil)))
347 (mdw-do-uniquify start-list
352 (defun mdw-do-uniquify (done end l rest)
353 "A helper function for mdw-uniquify-alist.
354 The DONE argument is a list whose first element is `nil'. It
355 contains the uniquified alist built so far. The leading `nil' is
356 stripped off at the end of the operation; it's only there so that
357 DONE always references a cons cell. END refers to the final cons
358 cell in the DONE list; it is modified in place each time to avoid
359 the overheads of `append'ing all the time. The L argument is the
360 alist we're currently processing; the remaining alists are given
363 ;; There are several different cases to deal with here.
366 ;; Current list isn't empty. Add the first item to the DONE list if
367 ;; there's not an item with the same KEY already there.
368 (l (or (assoc (car (car l)) done)
370 (setcdr end (cons (car l) nil))
371 (setq end (cdr end))))
372 (mdw-do-uniquify done end (cdr l) rest))
374 ;; The list we were working on is empty. Shunt the next list into the
375 ;; current list position and go round again.
376 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
378 ;; Everything's done. Remove the leading `nil' from the DONE list and
379 ;; return it. Finished!
383 "Insert the current date in a pleasing way."
385 (insert (save-excursion
386 (let ((buffer (get-buffer-create "*tmp*")))
387 (unwind-protect (progn (set-buffer buffer)
389 (shell-command "date +%Y-%m-%d" t)
391 (delete-backward-char 1)
393 (kill-buffer buffer))))))
395 (defun uuencode (file &optional name)
396 "UUencodes a file, maybe calling it NAME, into the current buffer."
397 (interactive "fInput file name: ")
399 ;; If NAME isn't specified, then guess from the filename.
403 (or (string-match "[^/]*$" file) 0))))
404 (print (format "uuencode `%s' `%s'" file name))
406 ;; Now actually do the thing.
407 (call-process "uuencode" file t nil name))
409 (defvar np-file "~/.np"
410 "*Where the `now-playing' file is.")
412 (defun np (&optional arg)
413 "Grabs a `now-playing' string."
417 (goto-char (point-max))
419 (insert-file-contents np-file)))))
421 (defun mdw-check-autorevert ()
422 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
423 This takes into consideration whether it's been found using
424 tramp, which seems to get itself into a twist."
425 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
427 ((and (buffer-file-name)
428 (fboundp 'tramp-tramp-file-p)
429 (tramp-tramp-file-p (buffer-file-name)))
430 (unless global-auto-revert-ignore-buffer
431 (setq global-auto-revert-ignore-buffer 'tramp)))
432 ((eq global-auto-revert-ignore-buffer 'tramp)
433 (setq global-auto-revert-ignore-buffer nil))))
435 (defadvice find-file (after mdw-autorevert activate)
436 (mdw-check-autorevert))
437 (defadvice write-file (after mdw-autorevert activate)
438 (mdw-check-autorevert))
440 ;;;--------------------------------------------------------------------------
443 (defadvice dired-maybe-insert-subdir
444 (around mdw-marked-insertion first activate)
445 "The DIRNAME may be a list of directory names to insert.
446 Interactively, if files are marked, then insert all of them.
447 With a numeric prefix argument, select that many entries near
448 point; with a non-numeric prefix argument, prompt for listing
451 (list (dired-get-marked-files nil
452 (and (integerp current-prefix-arg)
455 (and current-prefix-arg
456 (not (integerp current-prefix-arg))
457 (read-string "Switches for listing: "
458 (or dired-subdir-switches
459 dired-actual-switches)))))
460 (let ((dirs (ad-get-arg 0)))
461 (dolist (dir (if (listp dirs) dirs (list dirs)))
465 ;;;--------------------------------------------------------------------------
468 (defun mdw-w3m-browse-url (url &optional new-session-p)
469 "Invoke w3m on the URL in its current window, or at least a different one.
470 If NEW-SESSION-P, start a new session."
471 (interactive "sURL: \nP")
473 (let ((window (selected-window)))
476 (select-window (or (and (not new-session-p)
477 (get-buffer-window "*w3m*"))
479 (if (one-window-p t) (split-window))
481 (w3m-browse-url url new-session-p))
482 (select-window window)))))
484 (defvar mdw-good-url-browsers
485 '((w3m . mdw-w3m-browse-url)
488 "List of good browsers for mdw-good-url-browsers.
489 Each item is a browser function name, or a cons (CHECK . FUNC).
490 A symbol FOO stands for (FOO . FOO).")
492 (defun mdw-good-url-browser ()
493 "Return a good URL browser.
494 Trundle the list of such things, finding the first item for which
495 CHECK is fboundp, and returning the correponding FUNC."
496 (let ((bs mdw-good-url-browsers) b check func answer)
497 (while (and bs (not answer))
501 (setq check (car b) func (cdr b))
502 (setq check b func b))
507 (eval-after-load "w3m-search"
511 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
512 ("gd" "Google Directory"
513 "http://www.google.com/search?cat=gwd/Top&q=%s")
514 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
515 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
516 ("gi" "Images" "http://images.google.com/images?q=%s")
518 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
520 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
521 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
522 ("nc-wiki" "nCipher wiki"
523 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
524 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
525 ("lp" "Launchpad bug by number"
526 "https://bugs.launchpad.net/bugs/%s")
527 ("lppkg" "Launchpad bugs by package"
528 "https://bugs.launchpad.net/%s")
530 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
531 ("debbug" "Debian bug by number"
532 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
533 ("debbugpkg" "Debian bugs by package"
534 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
535 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
536 (add-to-list 'w3m-search-engine-alist
537 (list (cadr item) (caddr item) nil))
538 (add-to-list 'w3m-uri-replace-alist
539 (list (concat "\\`" (car item) ":")
540 'w3m-search-uri-replace
543 ;;;--------------------------------------------------------------------------
544 ;;; Paragraph filling.
548 (defvar mdw-fill-prefix nil
549 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
550 If there's no fill prefix currently set (by the `fill-prefix'
551 variable) and there's a match from one of the regexps here, it
552 gets used to set the fill-prefix for the current operation.
554 The variable is a list of items of the form `REGEXP . PREFIX'; if
555 the REGEXP matches, the PREFIX is used to set the fill prefix.
556 It in turn is a list of things:
558 STRING -- insert a literal string
559 (match . N) -- insert the thing matched by bracketed subexpression N
560 (pad . N) -- a string of whitespace the same width as subexpression N
561 (expr . FORM) -- the result of evaluating FORM")
563 (make-variable-buffer-local 'mdw-fill-prefix)
565 (defvar mdw-hanging-indents
567 "\\([*o]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
570 "*Standard regexp matching parts of a hanging indent.
571 This is mainly useful in `auto-fill-mode'.")
573 ;; Setting things up.
575 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
577 ;; Utility functions.
579 (defun mdw-tabify (s)
580 "Tabify the string S. This is a horrid hack."
585 (setq start (point-marker))
587 (setq end (point-marker))
589 (setq s (buffer-substring start (1- end)))
590 (delete-region start end)
591 (set-marker start nil)
595 (defun mdw-examine-fill-prefixes (l)
596 "Given a list of dynamic fill prefixes, pick one which matches
597 context and return the static fill prefix to use. Point must be
598 at the start of a line, and match data must be saved."
600 ((looking-at (car (car l)))
601 (mdw-tabify (apply (function concat)
602 (mapcar (function mdw-do-prefix-match)
604 (t (mdw-examine-fill-prefixes (cdr l)))))
606 (defun mdw-maybe-car (p)
607 "If P is a pair, return (car P), otherwise just return P."
608 (if (consp p) (car p) p))
610 (defun mdw-padding (s)
611 "Return a string the same width as S but made entirely from whitespace."
612 (let* ((l (length s)) (i 0) (n (make-string l ? )))
619 (defun mdw-do-prefix-match (m)
620 "Expand a dynamic prefix match element.
621 See `mdw-fill-prefix' for details."
622 (cond ((not (consp m)) (format "%s" m))
623 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
624 ((eq (car m) 'pad) (mdw-padding (match-string
625 (mdw-maybe-car (cdr m)))))
626 ((eq (car m) 'eval) (eval (cdr m)))
629 (defun mdw-choose-dynamic-fill-prefix ()
630 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
631 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
632 ((not mdw-fill-prefix) fill-prefix)
636 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
638 (defun do-auto-fill ()
639 "Handle auto-filling, working out a dynamic fill prefix in the
640 case where there isn't a sensible static one."
641 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
644 (defun mdw-fill-paragraph ()
645 "Fill paragraph, getting a dynamic fill prefix."
647 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
648 (fill-paragraph nil)))
650 (defun mdw-standard-fill-prefix (rx &optional mat)
651 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
652 This is just a short-cut for setting the thing by hand, and by
653 design it doesn't cope with anything approximating a complicated
655 (setq mdw-fill-prefix
656 `((,(concat rx mdw-hanging-indents)
658 (pad . ,(or mat 2))))))
660 ;;;--------------------------------------------------------------------------
661 ;;; Other common declarations.
663 ;; Common mode settings.
665 (defvar mdw-auto-indent t
666 "Whether to indent automatically after a newline.")
668 (defun mdw-whitespace-mode (&optional arg)
669 "Turn on/off whitespace mode, but don't highlight trailing space."
671 (when (and (boundp 'whitespace-style)
672 (fboundp 'whitespace-mode))
673 (let ((whitespace-style (remove 'trailing whitespace-style)))
674 (whitespace-mode arg))))
676 (defun mdw-misc-mode-config ()
678 (cond ((eq major-mode 'lisp-mode)
679 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
680 ((or (eq major-mode 'slime-repl-mode)
681 (eq major-mode 'asm-mode))
684 (local-set-key "\C-m" 'newline-and-indent))))
685 (local-set-key [C-return] 'newline)
686 (make-variable-buffer-local 'page-delimiter)
687 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
688 (setq comment-column 40)
690 (setq fill-column 77)
691 (setq show-trailing-whitespace t)
692 (mdw-whitespace-mode 1)
693 (and (fboundp 'gtags-mode)
695 (outline-minor-mode t)
698 (trap (turn-on-font-lock)))
700 (defun mdw-post-config-mode-hack ()
701 (mdw-whitespace-mode 1))
703 (eval-after-load 'gtags
705 (dolist (key '([mouse-2] [mouse-3]))
706 (define-key gtags-mode-map key nil))
707 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
708 (define-key gtags-select-mode-map [C-S-mouse-2]
709 'gtags-select-tag-by-event)
710 (dolist (map (list gtags-mode-map gtags-select-mode-map))
711 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
713 ;; Backup file handling.
715 (defvar mdw-backup-disable-regexps nil
716 "*List of regular expressions: if a file name matches any of
717 these then the file is not backed up.")
719 (defun mdw-backup-enable-predicate (name)
720 "[mdw]'s default backup predicate.
721 Allows a backup if the standard predicate would allow it, and it
722 doesn't match any of the regular expressions in
723 `mdw-backup-disable-regexps'."
724 (and (normal-backup-enable-predicate name)
725 (let ((answer t) (list mdw-backup-disable-regexps))
728 (if (string-match (car list) name)
730 (setq list (cdr list)))
732 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
736 (defun mdw-last-one-out-turn-off-the-lights (frame)
737 "Disconnect from an X display if this was the last frame on that display."
738 (let ((frame-display (frame-parameter frame 'display)))
739 (when (and frame-display
740 (eq window-system 'x)
741 (not (some (lambda (fr)
742 (message "checking frame %s" frame)
743 (and (not (eq fr frame))
744 (string= (frame-parameter fr 'display)
746 (progn "frame %s still uses us" nil)))
748 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
749 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
751 (defvar mdw-frame-parameters-alist
752 '((nil (menu-bar-lines . 0))))
753 (defun mdw-set-frame-parameters (frame)
754 (let ((params (assq (if (fboundp 'window-system)
755 (window-system frame)
757 mdw-frame-parameters-alist)))
759 (modify-frame-parameters frame (cdr params)))))
760 (add-hook 'after-make-frame-functions 'mdw-set-frame-parameters)
762 ;;;--------------------------------------------------------------------------
763 ;;; General fontification.
765 (defmacro mdw-define-face (name &rest body)
766 "Define a face, and make sure it's actually set as the definition."
771 (defvar ,name ',name)
772 (put ',name 'face-defface-spec ',body)
773 (face-spec-set ',name ',body nil)))
775 (mdw-define-face default
776 (((type w32)) :family "courier new" :height 85)
777 (((type x)) :family "6x13" :height 130)
778 (((type color)) :foreground "white" :background "black")
780 (mdw-define-face fixed-pitch
781 (((type w32)) :family "courier new" :height 85)
782 (((type x)) :family "6x13" :height 130)
783 (t :foreground "white" :background "black"))
784 (if (>= emacs-major-version 23)
785 (mdw-define-face variable-pitch
786 (((type x)) :family "sans" :height 100))
787 (mdw-define-face variable-pitch
788 (((type x)) :family "helvetica" :height 120)))
789 (mdw-define-face region
790 (((type tty) (class color)) :background "blue")
791 (((type tty) (class mono)) :inverse-video t)
792 (t :background "grey30"))
793 (mdw-define-face minibuffer-prompt
795 (mdw-define-face mode-line
796 (((class color)) :foreground "blue" :background "yellow"
797 :box (:line-width 1 :style released-button))
798 (t :inverse-video t))
799 (mdw-define-face mode-line-inactive
800 (((class color)) :foreground "yellow" :background "blue"
801 :box (:line-width 1 :style released-button))
802 (t :inverse-video t))
803 (mdw-define-face scroll-bar
804 (t :foreground "black" :background "lightgrey"))
805 (mdw-define-face fringe
806 (t :foreground "yellow"))
807 (mdw-define-face show-paren-match
808 (((class color)) :background "darkgreen")
810 (mdw-define-face show-paren-mismatch
811 (((class color)) :background "red")
812 (t :inverse-video t))
813 (mdw-define-face highlight
814 (((class color)) :background "DarkSeaGreen4")
815 (t :inverse-video t))
817 (mdw-define-face holiday-face
818 (t :background "red"))
819 (mdw-define-face calendar-today-face
820 (t :foreground "yellow" :weight bold))
822 (mdw-define-face comint-highlight-prompt
824 (mdw-define-face comint-highlight-input)
826 (mdw-define-face trailing-whitespace
827 (((class color)) :background "red")
828 (t :inverse-video t))
829 (mdw-define-face mdw-punct-face
830 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
831 (mdw-define-face mdw-number-face
832 (t :foreground "yellow"))
833 (mdw-define-face font-lock-function-name-face
835 (mdw-define-face font-lock-keyword-face
837 (mdw-define-face font-lock-constant-face
839 (mdw-define-face font-lock-builtin-face
841 (mdw-define-face font-lock-type-face
842 (t :weight bold :slant italic))
843 (mdw-define-face font-lock-reference-face
845 (mdw-define-face font-lock-variable-name-face
847 (mdw-define-face font-lock-comment-delimiter-face
848 (((class mono)) :weight bold)
849 (((type tty) (class color)) :foreground "green")
850 (t :slant italic :foreground "SeaGreen1"))
851 (mdw-define-face font-lock-comment-face
852 (((class mono)) :weight bold)
853 (((type tty) (class color)) :foreground "green")
854 (t :slant italic :foreground "SeaGreen1"))
855 (mdw-define-face font-lock-string-face
856 (((class mono)) :weight bold)
857 (((class color)) :foreground "SkyBlue1"))
858 (mdw-define-face message-separator
859 (t :background "red" :foreground "white" :weight bold))
860 (mdw-define-face message-cited-text
861 (default :slant italic)
862 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
863 (mdw-define-face message-header-cc
864 (default :weight bold)
865 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
866 (mdw-define-face message-header-newsgroups
867 (default :weight bold)
868 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
869 (mdw-define-face message-header-subject
870 (default :weight bold)
871 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
872 (mdw-define-face message-header-to
873 (default :weight bold)
874 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
875 (mdw-define-face message-header-xheader
876 (default :weight bold)
877 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
878 (mdw-define-face message-header-other
879 (default :weight bold)
880 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
881 (mdw-define-face message-header-name
882 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
884 (mdw-define-face diff-index
886 (mdw-define-face diff-file-header
888 (mdw-define-face diff-hunk-header
889 (t :foreground "SkyBlue1"))
890 (mdw-define-face diff-function
891 (t :foreground "SkyBlue1" :weight bold))
892 (mdw-define-face diff-header
893 (t :background "grey10"))
894 (mdw-define-face diff-added
895 (t :foreground "green"))
896 (mdw-define-face diff-removed
897 (t :foreground "red"))
898 (mdw-define-face diff-context)
900 (mdw-define-face erc-input-face
901 (t :foreground "red"))
903 (mdw-define-face woman-bold
905 (mdw-define-face woman-italic
908 (mdw-define-face p4-depot-added-face
909 (t :foreground "green"))
910 (mdw-define-face p4-depot-branch-op-face
911 (t :foreground "yellow"))
912 (mdw-define-face p4-depot-deleted-face
913 (t :foreground "red"))
914 (mdw-define-face p4-depot-unmapped-face
915 (t :foreground "SkyBlue1"))
916 (mdw-define-face p4-diff-change-face
917 (t :foreground "yellow"))
918 (mdw-define-face p4-diff-del-face
919 (t :foreground "red"))
920 (mdw-define-face p4-diff-file-face
921 (t :foreground "SkyBlue1"))
922 (mdw-define-face p4-diff-head-face
923 (t :background "grey10"))
924 (mdw-define-face p4-diff-ins-face
925 (t :foreground "green"))
927 (mdw-define-face whizzy-slice-face
928 (t :background "grey10"))
929 (mdw-define-face whizzy-error-face
930 (t :background "darkred"))
932 ;;;--------------------------------------------------------------------------
933 ;;; C programming configuration.
935 ;; Linux kernel hacking.
937 (defvar linux-c-mode-hook)
939 (defun linux-c-mode ()
942 (setq major-mode 'linux-c-mode)
943 (setq mode-name "Linux C")
944 (run-hooks 'linux-c-mode-hook))
946 ;; Make C indentation nice.
948 (defun mdw-c-lineup-arglist (langelem)
949 "Hack for DWIMmery in c-lineup-arglist."
951 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
953 (c-lineup-arglist langelem)))
955 (defun mdw-c-indent-extern-mumble (langelem)
956 "Indent `extern \"...\" {' lines."
958 (back-to-indentation)
960 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
964 (defun mdw-c-style ()
965 (c-add-style "[mdw] C and C++ style"
966 '((c-basic-offset . 2)
967 (comment-column . 40)
968 (c-class-key . "class")
969 (c-backslash-column . 72)
971 (substatement-open . (add 0 c-indent-one-line-block))
972 (defun-open . (add 0 c-indent-one-line-block))
973 (arglist-cont-nonempty . mdw-c-lineup-arglist)
974 (topmost-intro . mdw-c-indent-extern-mumble)
975 (cpp-define-intro . 0)
976 (inextern-lang . [0])
983 (statement-case-intro . +)))
986 (defvar mdw-c-comment-fill-prefix
987 `((,(concat "\\([ \t]*/?\\)"
990 "\\([A-Za-z]+:[ \t]*\\)?"
992 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
993 "Fill prefix matching C comments (both kinds).")
995 (defun mdw-fontify-c-and-c++ ()
997 ;; Fiddle with some syntax codes.
998 (modify-syntax-entry ?* ". 23")
999 (modify-syntax-entry ?/ ". 124b")
1000 (modify-syntax-entry ?\n "> b")
1004 (setq c-hanging-comment-ender-p nil)
1005 (setq c-backslash-column 72)
1006 (setq c-label-minimum-indentation 0)
1007 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1009 ;; Now define things to be fontified.
1010 (make-local-variable 'font-lock-keywords)
1012 (mdw-regexps "and" ;C++
1018 "bool" ;C++, C9X macro
1024 "complex" ;C9X macro, C++ template type
1028 "continue" ;K&R, C89
1029 "defined" ;C89 preprocessor
1036 ;; "entry" ;K&R -- never used
1041 "false" ;C++, C9X macro
1048 "imaginary" ;C9X macro
1049 "inline" ;C++, C9X, GCC
1061 "register" ;K&R, C89
1062 "reinterpret_cast" ;C++
1075 "true" ;C++, C9X macro
1083 "unsigned" ;K&R, C89
1088 "wchar_t" ;C++, C89 library type
1095 "_Pragma" ;C9X preprocessor
1098 "__attribute__" ;GCC
1101 "__extension__" ;GCC
1110 (preprocessor-keywords
1111 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1112 "ident" "if" "ifdef" "ifndef" "import" "include"
1113 "line" "pragma" "unassert" "undef" "warning"))
1115 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1116 "interface" "private" "protected" "protocol" "public"
1119 (setq font-lock-keywords
1122 ;; Fontify include files as strings.
1123 (list (concat "^[ \t]*\\#[ \t]*"
1124 "\\(include\\|import\\)"
1125 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1126 '(2 font-lock-string-face))
1128 ;; Preprocessor directives are `references'?.
1129 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1130 preprocessor-keywords
1131 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1132 '(1 font-lock-keyword-face))
1134 ;; Handle the keywords defined above.
1135 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1136 '(0 font-lock-keyword-face))
1138 (list (concat "\\<\\(" c-keywords "\\)\\>")
1139 '(0 font-lock-keyword-face))
1141 ;; Handle numbers too.
1143 ;; This looks strange, I know. It corresponds to the
1144 ;; preprocessor's idea of what a number looks like, rather than
1145 ;; anything sensible.
1146 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1147 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1148 '(0 mdw-number-face))
1150 ;; And anything else is punctuation.
1151 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1152 '(0 mdw-punct-face))))
1154 (mdw-post-config-mode-hack)))
1156 ;;;--------------------------------------------------------------------------
1159 (defun apcalc-mode ()
1162 (setq major-mode 'apcalc-mode)
1163 (setq mode-name "AP Calc")
1164 (run-hooks 'apcalc-mode-hook))
1166 (defun mdw-fontify-apcalc ()
1168 ;; Fiddle with some syntax codes.
1169 (modify-syntax-entry ?* ". 23")
1170 (modify-syntax-entry ?/ ". 14")
1174 (setq c-hanging-comment-ender-p nil)
1175 (setq c-backslash-column 72)
1176 (setq comment-start "/* ")
1177 (setq comment-end " */")
1178 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1180 ;; Now define things to be fontified.
1181 (make-local-variable 'font-lock-keywords)
1183 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1184 "do" "else" "exit" "for" "global" "goto" "help" "if"
1185 "local" "mat" "obj" "print" "quit" "read" "return"
1186 "show" "static" "switch" "while" "write")))
1188 (setq font-lock-keywords
1191 ;; Handle the keywords defined above.
1192 (list (concat "\\<\\(" c-keywords "\\)\\>")
1193 '(0 font-lock-keyword-face))
1195 ;; Handle numbers too.
1197 ;; This looks strange, I know. It corresponds to the
1198 ;; preprocessor's idea of what a number looks like, rather than
1199 ;; anything sensible.
1200 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1201 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1202 '(0 mdw-number-face))
1204 ;; And anything else is punctuation.
1205 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1206 '(0 mdw-punct-face)))))
1208 (mdw-post-config-mode-hack))
1210 ;;;--------------------------------------------------------------------------
1211 ;;; Java programming configuration.
1213 ;; Make indentation nice.
1215 (defun mdw-java-style ()
1216 (c-add-style "[mdw] Java style"
1217 '((c-basic-offset . 2)
1218 (c-offsets-alist (substatement-open . 0)
1223 (statement-case-intro . +)))
1226 ;; Declare Java fontification style.
1228 (defun mdw-fontify-java ()
1232 (setq c-hanging-comment-ender-p nil)
1233 (setq c-backslash-column 72)
1234 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1236 ;; Now define things to be fontified.
1237 (make-local-variable 'font-lock-keywords)
1238 (let ((java-keywords
1239 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1240 "char" "class" "const" "continue" "default" "do"
1241 "double" "else" "extends" "final" "finally" "float"
1242 "for" "goto" "if" "implements" "import" "instanceof"
1243 "int" "interface" "long" "native" "new" "package"
1244 "private" "protected" "public" "return" "short"
1245 "static" "super" "switch" "synchronized" "this"
1246 "throw" "throws" "transient" "try" "void" "volatile"
1249 "false" "null" "true")))
1251 (setq font-lock-keywords
1254 ;; Handle the keywords defined above.
1255 (list (concat "\\<\\(" java-keywords "\\)\\>")
1256 '(0 font-lock-keyword-face))
1258 ;; Handle numbers too.
1260 ;; The following isn't quite right, but it's close enough.
1261 (list (concat "\\<\\("
1262 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1263 "[0-9]+\\(\\.[0-9]*\\|\\)"
1264 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1266 '(0 mdw-number-face))
1268 ;; And anything else is punctuation.
1269 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1270 '(0 mdw-punct-face)))))
1272 (mdw-post-config-mode-hack))
1274 ;;;--------------------------------------------------------------------------
1275 ;;; C# programming configuration.
1277 ;; Make indentation nice.
1279 (defun mdw-csharp-style ()
1280 (c-add-style "[mdw] C# style"
1281 '((c-basic-offset . 2)
1282 (c-offsets-alist (substatement-open . 0)
1287 (statement-case-intro . +)))
1290 ;; Declare C# fontification style.
1292 (defun mdw-fontify-csharp ()
1296 (setq c-hanging-comment-ender-p nil)
1297 (setq c-backslash-column 72)
1298 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1300 ;; Now define things to be fontified.
1301 (make-local-variable 'font-lock-keywords)
1302 (let ((csharp-keywords
1303 (mdw-regexps "abstract" "as" "base" "bool" "break"
1304 "byte" "case" "catch" "char" "checked"
1305 "class" "const" "continue" "decimal" "default"
1306 "delegate" "do" "double" "else" "enum"
1307 "event" "explicit" "extern" "false" "finally"
1308 "fixed" "float" "for" "foreach" "goto"
1309 "if" "implicit" "in" "int" "interface"
1310 "internal" "is" "lock" "long" "namespace"
1311 "new" "null" "object" "operator" "out"
1312 "override" "params" "private" "protected" "public"
1313 "readonly" "ref" "return" "sbyte" "sealed"
1314 "short" "sizeof" "stackalloc" "static" "string"
1315 "struct" "switch" "this" "throw" "true"
1316 "try" "typeof" "uint" "ulong" "unchecked"
1317 "unsafe" "ushort" "using" "virtual" "void"
1318 "volatile" "while" "yield")))
1320 (setq font-lock-keywords
1323 ;; Handle the keywords defined above.
1324 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1325 '(0 font-lock-keyword-face))
1327 ;; Handle numbers too.
1329 ;; The following isn't quite right, but it's close enough.
1330 (list (concat "\\<\\("
1331 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1332 "[0-9]+\\(\\.[0-9]*\\|\\)"
1333 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1335 '(0 mdw-number-face))
1337 ;; And anything else is punctuation.
1338 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1339 '(0 mdw-punct-face)))))
1341 (mdw-post-config-mode-hack))
1343 (define-derived-mode csharp-mode java-mode "C#"
1344 "Major mode for editing C# code.")
1346 ;;;--------------------------------------------------------------------------
1347 ;;; Go programming configuration.
1349 (defun mdw-fontify-go ()
1351 (make-local-variable 'font-lock-keywords)
1353 (mdw-regexps "break" "case" "chan" "const" "continue"
1354 "default" "defer" "else" "fallthrough" "for"
1355 "func" "go" "goto" "if" "import"
1356 "interface" "map" "package" "range" "return"
1357 "select" "struct" "switch" "type" "var")))
1359 (setq font-lock-keywords
1362 ;; Handle the keywords defined above.
1363 (list (concat "\\<\\(" go-keywords "\\)\\>")
1364 '(0 font-lock-keyword-face))
1366 ;; Handle numbers too.
1368 ;; The following isn't quite right, but it's close enough.
1369 (list (concat "\\<\\("
1370 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1371 "[0-9]+\\(\\.[0-9]*\\|\\)"
1372 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1373 '(0 mdw-number-face))
1375 ;; And anything else is punctuation.
1376 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1377 '(0 mdw-punct-face)))))
1379 (mdw-post-config-mode-hack))
1381 ;;;--------------------------------------------------------------------------
1382 ;;; Awk programming configuration.
1384 ;; Make Awk indentation nice.
1386 (defun mdw-awk-style ()
1387 (c-add-style "[mdw] Awk style"
1388 '((c-basic-offset . 2)
1389 (c-offsets-alist (substatement-open . 0)
1390 (statement-cont . 0)
1391 (statement-case-intro . +)))
1394 ;; Declare Awk fontification style.
1396 (defun mdw-fontify-awk ()
1398 ;; Miscellaneous fiddling.
1400 (setq c-backslash-column 72)
1401 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1403 ;; Now define things to be fontified.
1404 (make-local-variable 'font-lock-keywords)
1406 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1407 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1408 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1409 "RSTART" "RLENGTH" "RT" "SUBSEP"
1410 "atan2" "break" "close" "continue" "cos" "delete"
1411 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1412 "function" "gensub" "getline" "gsub" "if" "in"
1413 "index" "int" "length" "log" "match" "next" "rand"
1414 "return" "print" "printf" "sin" "split" "sprintf"
1415 "sqrt" "srand" "strftime" "sub" "substr" "system"
1416 "systime" "tolower" "toupper" "while")))
1418 (setq font-lock-keywords
1421 ;; Handle the keywords defined above.
1422 (list (concat "\\<\\(" c-keywords "\\)\\>")
1423 '(0 font-lock-keyword-face))
1425 ;; Handle numbers too.
1427 ;; The following isn't quite right, but it's close enough.
1428 (list (concat "\\<\\("
1429 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1430 "[0-9]+\\(\\.[0-9]*\\|\\)"
1431 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1433 '(0 mdw-number-face))
1435 ;; And anything else is punctuation.
1436 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1437 '(0 mdw-punct-face)))))
1439 (mdw-post-config-mode-hack))
1441 ;;;--------------------------------------------------------------------------
1442 ;;; Perl programming style.
1444 ;; Perl indentation style.
1446 (setq cperl-indent-level 2)
1447 (setq cperl-continued-statement-offset 2)
1448 (setq cperl-continued-brace-offset 0)
1449 (setq cperl-brace-offset -2)
1450 (setq cperl-brace-imaginary-offset 0)
1451 (setq cperl-label-offset 0)
1453 ;; Define perl fontification style.
1455 (defun mdw-fontify-perl ()
1457 ;; Miscellaneous fiddling.
1458 (modify-syntax-entry ?$ "\\")
1459 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1460 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1462 ;; Now define fontification things.
1463 (make-local-variable 'font-lock-keywords)
1464 (let ((perl-keywords
1465 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1466 "for" "foreach" "ge" "gt" "goto" "if"
1467 "last" "le" "lt" "local" "my" "ne" "next" "or"
1468 "package" "redo" "require" "return" "sub"
1469 "undef" "unless" "until" "use" "while")))
1471 (setq font-lock-keywords
1474 ;; Set up the keywords defined above.
1475 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1476 '(0 font-lock-keyword-face))
1478 ;; At least numbers are simpler than C.
1479 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1480 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1481 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1482 '(0 mdw-number-face))
1484 ;; And anything else is punctuation.
1485 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1486 '(0 mdw-punct-face)))))
1488 (mdw-post-config-mode-hack))
1490 (defun perl-number-tests (&optional arg)
1491 "Assign consecutive numbers to lines containing `#t'. With ARG,
1492 strip numbers instead."
1495 (goto-char (point-min))
1496 (let ((i 0) (fmt (if arg "" " %4d")))
1497 (while (search-forward "#t" nil t)
1498 (delete-region (point) (line-end-position))
1500 (insert (format fmt i)))
1501 (goto-char (point-min))
1502 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1503 (replace-match (format "\\1%d" i))))))
1505 ;;;--------------------------------------------------------------------------
1506 ;;; Python programming style.
1508 (defun mdw-fontify-pythonic (keywords)
1510 ;; Miscellaneous fiddling.
1511 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1513 ;; Now define fontification things.
1514 (make-local-variable 'font-lock-keywords)
1515 (setq font-lock-keywords
1518 ;; Set up the keywords defined above.
1519 (list (concat "\\<\\(" keywords "\\)\\>")
1520 '(0 font-lock-keyword-face))
1522 ;; At least numbers are simpler than C.
1523 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1524 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1525 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1526 '(0 mdw-number-face))
1528 ;; And anything else is punctuation.
1529 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1530 '(0 mdw-punct-face))))
1532 (mdw-post-config-mode-hack))
1534 ;; Define Python fontification styles.
1536 (defun mdw-fontify-python ()
1537 (mdw-fontify-pythonic
1538 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1539 "del" "elif" "else" "except" "exec" "finally" "for"
1540 "from" "global" "if" "import" "in" "is" "lambda"
1541 "not" "or" "pass" "print" "raise" "return" "try"
1542 "while" "with" "yield")))
1544 (defun mdw-fontify-pyrex ()
1545 (mdw-fontify-pythonic
1546 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1547 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1548 "extern" "finally" "for" "from" "global" "if"
1549 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1550 "raise" "return" "struct" "try" "while" "with"
1553 ;;;--------------------------------------------------------------------------
1554 ;;; Icon programming style.
1556 ;; Icon indentation style.
1558 (setq icon-brace-offset 0
1559 icon-continued-brace-offset 0
1560 icon-continued-statement-offset 2
1561 icon-indent-level 2)
1563 ;; Define Icon fontification style.
1565 (defun mdw-fontify-icon ()
1567 ;; Miscellaneous fiddling.
1568 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1570 ;; Now define fontification things.
1571 (make-local-variable 'font-lock-keywords)
1572 (let ((icon-keywords
1573 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1574 "end" "every" "fail" "global" "if" "initial"
1575 "invocable" "link" "local" "next" "not" "of"
1576 "procedure" "record" "repeat" "return" "static"
1577 "suspend" "then" "to" "until" "while"))
1578 (preprocessor-keywords
1579 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1580 "include" "line" "undef")))
1581 (setq font-lock-keywords
1584 ;; Set up the keywords defined above.
1585 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1586 '(0 font-lock-keyword-face))
1588 ;; The things that Icon calls keywords.
1589 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1591 ;; At least numbers are simpler than C.
1592 (list (concat "\\<[0-9]+"
1593 "\\([rR][0-9a-zA-Z]+\\|"
1594 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1595 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1596 '(0 mdw-number-face))
1599 (list (concat "^[ \t]*$[ \t]*\\<\\("
1600 preprocessor-keywords
1602 '(0 font-lock-keyword-face))
1604 ;; And anything else is punctuation.
1605 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1606 '(0 mdw-punct-face)))))
1608 (mdw-post-config-mode-hack))
1610 ;;;--------------------------------------------------------------------------
1611 ;;; ARM assembler programming configuration.
1613 ;; There doesn't appear to be an Emacs mode for this yet.
1615 ;; Better do something about that, I suppose.
1617 (defvar arm-assembler-mode-map nil)
1618 (defvar arm-assembler-abbrev-table nil)
1619 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1621 (or arm-assembler-mode-map
1623 (setq arm-assembler-mode-map (make-sparse-keymap))
1624 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1625 (define-key arm-assembler-mode-map [C-return] 'newline)
1626 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1628 (defun arm-assembler-mode ()
1629 "Major mode for ARM assembler programs"
1632 ;; Do standard major mode things.
1633 (kill-all-local-variables)
1634 (use-local-map arm-assembler-mode-map)
1635 (setq local-abbrev-table arm-assembler-abbrev-table)
1636 (setq major-mode 'arm-assembler-mode)
1637 (setq mode-name "ARM assembler")
1639 ;; Set up syntax table.
1640 (set-syntax-table arm-assembler-mode-syntax-table)
1641 (modify-syntax-entry ?; ; Nasty hack
1642 "<" arm-assembler-mode-syntax-table)
1643 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1644 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1646 (make-local-variable 'comment-start)
1647 (setq comment-start ";")
1648 (make-local-variable 'comment-end)
1649 (setq comment-end "")
1650 (make-local-variable 'comment-column)
1651 (setq comment-column 48)
1652 (make-local-variable 'comment-start-skip)
1653 (setq comment-start-skip ";+[ \t]*")
1655 ;; Play with indentation.
1656 (make-local-variable 'indent-line-function)
1657 (setq indent-line-function 'indent-relative-maybe)
1660 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1662 ;; Fiddle with fontification.
1663 (make-local-variable 'font-lock-keywords)
1664 (setq font-lock-keywords
1667 ;; Handle numbers too.
1669 ;; The following isn't quite right, but it's close enough.
1672 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1674 '(0 mdw-number-face))
1676 ;; Do something about operators.
1677 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1678 '(1 font-lock-keyword-face)
1679 '(2 font-lock-string-face))
1681 '(0 font-lock-keyword-face))
1683 ;; Do menemonics and directives.
1684 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1685 '(1 font-lock-keyword-face))
1687 ;; And anything else is punctuation.
1688 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1689 '(0 mdw-punct-face)))
1691 (mdw-post-config-mode-hack))
1692 (run-hooks 'arm-assembler-mode-hook))
1694 ;;;--------------------------------------------------------------------------
1697 (defun mdw-fontify-asm ()
1698 (modify-syntax-entry ?' "\"")
1699 (modify-syntax-entry ?. "w")
1700 (setf fill-prefix nil)
1701 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1703 ;;;--------------------------------------------------------------------------
1704 ;;; TCL configuration.
1706 (defun mdw-fontify-tcl ()
1707 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1708 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1709 (make-local-variable 'font-lock-keywords)
1710 (setq font-lock-keywords
1712 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1713 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1714 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1715 '(0 mdw-number-face))
1716 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1717 '(0 mdw-punct-face))))
1718 (mdw-post-config-mode-hack))
1720 ;;;--------------------------------------------------------------------------
1721 ;;; REXX configuration.
1723 (defun mdw-rexx-electric-* ()
1728 (defun mdw-rexx-indent-newline-indent ()
1731 (if abbrev-mode (expand-abbrev))
1732 (newline-and-indent))
1734 (defun mdw-fontify-rexx ()
1736 ;; Various bits of fiddling.
1737 (setq mdw-auto-indent nil)
1738 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1739 (local-set-key [?*] 'mdw-rexx-electric-*)
1740 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1742 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1744 ;; Set up keywords and things for fontification.
1745 (make-local-variable 'font-lock-keywords-case-fold-search)
1746 (setq font-lock-keywords-case-fold-search t)
1748 (setq rexx-indent 2)
1749 (setq rexx-end-indent rexx-indent)
1750 (setq rexx-cont-indent rexx-indent)
1752 (make-local-variable 'font-lock-keywords)
1753 (let ((rexx-keywords
1754 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1755 "else" "end" "engineering" "exit" "expose" "for"
1756 "forever" "form" "fuzz" "if" "interpret" "iterate"
1757 "leave" "linein" "name" "nop" "numeric" "off" "on"
1758 "options" "otherwise" "parse" "procedure" "pull"
1759 "push" "queue" "return" "say" "select" "signal"
1760 "scientific" "source" "then" "trace" "to" "until"
1761 "upper" "value" "var" "version" "when" "while"
1764 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1765 "center" "center" "charin" "charout" "chars"
1766 "compare" "condition" "copies" "c2d" "c2x"
1767 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1768 "errortext" "format" "fuzz" "insert" "lastpos"
1769 "left" "length" "lineout" "lines" "max" "min"
1770 "overlay" "pos" "queued" "random" "reverse" "right"
1771 "sign" "sourceline" "space" "stream" "strip"
1772 "substr" "subword" "symbol" "time" "translate"
1773 "trunc" "value" "verify" "word" "wordindex"
1774 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1777 (setq font-lock-keywords
1780 ;; Set up the keywords defined above.
1781 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1782 '(0 font-lock-keyword-face))
1784 ;; Fontify all symbols the same way.
1785 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1786 "[A-Za-z0-9.!?_#@$]+\\)")
1787 '(0 font-lock-variable-name-face))
1789 ;; And everything else is punctuation.
1790 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1791 '(0 mdw-punct-face)))))
1793 (mdw-post-config-mode-hack))
1795 ;;;--------------------------------------------------------------------------
1796 ;;; Standard ML programming style.
1798 (defun mdw-fontify-sml ()
1800 ;; Make underscore an honorary letter.
1801 (modify-syntax-entry ?' "w")
1804 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1806 ;; Now define fontification things.
1807 (make-local-variable 'font-lock-keywords)
1809 (mdw-regexps "abstype" "and" "andalso" "as"
1812 "else" "end" "eqtype" "exception"
1813 "fn" "fun" "functor"
1815 "if" "in" "include" "infix" "infixr"
1818 "of" "op" "open" "orelse"
1820 "sharing" "sig" "signature" "struct" "structure"
1823 "where" "while" "with" "withtype")))
1825 (setq font-lock-keywords
1828 ;; Set up the keywords defined above.
1829 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1830 '(0 font-lock-keyword-face))
1832 ;; At least numbers are simpler than C.
1833 (list (concat "\\<\\(\\~\\|\\)"
1834 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1836 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1837 "\\([eE]\\(\\~\\|\\)"
1838 "[0-9]+\\|\\)\\)\\)")
1839 '(0 mdw-number-face))
1841 ;; And anything else is punctuation.
1842 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1843 '(0 mdw-punct-face)))))
1845 (mdw-post-config-mode-hack))
1847 ;;;--------------------------------------------------------------------------
1848 ;;; Haskell configuration.
1850 (defun mdw-fontify-haskell ()
1852 ;; Fiddle with syntax table to get comments right.
1853 (modify-syntax-entry ?' "\"")
1854 (modify-syntax-entry ?- ". 123")
1855 (modify-syntax-entry ?{ ". 1b")
1856 (modify-syntax-entry ?} ". 4b")
1857 (modify-syntax-entry ?\n ">")
1860 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1862 ;; Fiddle with fontification.
1863 (make-local-variable 'font-lock-keywords)
1864 (let ((haskell-keywords
1865 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1866 "deriving" "do" "else" "foreign" "hiding" "if"
1867 "import" "in" "infix" "infixl" "infixr" "instance"
1868 "let" "module" "newtype" "of" "qualified" "safe"
1869 "stdcall" "then" "type" "unsafe" "where")))
1871 (setq font-lock-keywords
1874 '(0 font-lock-comment-face))
1875 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1876 '(0 font-lock-keyword-face))
1877 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1878 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1879 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1880 '(0 mdw-number-face))
1881 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1882 '(0 mdw-punct-face)))))
1884 (mdw-post-config-mode-hack))
1886 ;;;--------------------------------------------------------------------------
1887 ;;; Erlang configuration.
1889 (setq erlang-electric-commannds
1890 '(erlang-electric-newline erlang-electric-semicolon))
1892 (defun mdw-fontify-erlang ()
1895 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1897 ;; Fiddle with fontification.
1898 (make-local-variable 'font-lock-keywords)
1899 (let ((erlang-keywords
1900 (mdw-regexps "after" "and" "andalso"
1901 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1902 "case" "catch" "cond"
1903 "div" "end" "fun" "if" "let" "not"
1905 "query" "receive" "rem" "try" "when" "xor")))
1907 (setq font-lock-keywords
1910 '(0 font-lock-comment-face))
1911 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1912 '(0 font-lock-keyword-face))
1913 (list (concat "^-\\sw+\\>")
1914 '(0 font-lock-keyword-face))
1915 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1916 '(0 mdw-number-face))
1917 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1918 '(0 mdw-punct-face)))))
1920 (mdw-post-config-mode-hack))
1922 ;;;--------------------------------------------------------------------------
1923 ;;; Texinfo configuration.
1925 (defun mdw-fontify-texinfo ()
1928 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1930 ;; Real fontification things.
1931 (make-local-variable 'font-lock-keywords)
1932 (setq font-lock-keywords
1935 ;; Environment names are keywords.
1936 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1937 '(2 font-lock-keyword-face))
1939 ;; Unmark escaped magic characters.
1940 (list "\\(@\\)\\([@{}]\\)"
1941 '(1 font-lock-keyword-face)
1942 '(2 font-lock-variable-name-face))
1944 ;; Make sure we get comments properly.
1945 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1946 '(0 font-lock-comment-face))
1948 ;; Command names are keywords.
1949 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1950 '(0 font-lock-keyword-face))
1952 ;; Fontify TeX special characters as punctuation.
1954 '(0 mdw-punct-face))))
1956 (mdw-post-config-mode-hack))
1958 ;;;--------------------------------------------------------------------------
1959 ;;; TeX and LaTeX configuration.
1961 (defun mdw-fontify-tex ()
1962 (setq ispell-parser 'tex)
1965 ;; Don't make maths into a string.
1966 (modify-syntax-entry ?$ ".")
1967 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1968 (local-set-key [?$] 'self-insert-command)
1971 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1973 ;; Real fontification things.
1974 (make-local-variable 'font-lock-keywords)
1975 (setq font-lock-keywords
1978 ;; Environment names are keywords.
1979 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1981 '(2 font-lock-keyword-face))
1983 ;; Suspended environment names are keywords too.
1984 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1986 '(3 font-lock-keyword-face))
1988 ;; Command names are keywords.
1989 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1990 '(0 font-lock-keyword-face))
1992 ;; Handle @/.../ for italics.
1993 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
1994 ;; '(1 font-lock-keyword-face)
1995 ;; '(3 font-lock-keyword-face))
1997 ;; Handle @*...* for boldness.
1998 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
1999 ;; '(1 font-lock-keyword-face)
2000 ;; '(3 font-lock-keyword-face))
2002 ;; Handle @`...' for literal syntax things.
2003 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
2004 ;; '(1 font-lock-keyword-face)
2005 ;; '(3 font-lock-keyword-face))
2007 ;; Handle @<...> for nonterminals.
2008 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
2009 ;; '(1 font-lock-keyword-face)
2010 ;; '(3 font-lock-keyword-face))
2012 ;; Handle other @-commands.
2013 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
2014 ;; '(0 font-lock-keyword-face))
2016 ;; Make sure we get comments properly.
2018 '(0 font-lock-comment-face))
2020 ;; Fontify TeX special characters as punctuation.
2022 '(0 mdw-punct-face))))
2024 (mdw-post-config-mode-hack))
2026 ;;;--------------------------------------------------------------------------
2029 (defun mdw-sgml-mode ()
2032 (mdw-standard-fill-prefix "")
2033 (make-variable-buffer-local 'sgml-delimiters)
2034 (setq sgml-delimiters
2035 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2036 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2037 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2038 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2039 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2040 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2041 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2043 (setq major-mode 'mdw-sgml-mode)
2044 (setq mode-name "[mdw] SGML")
2045 (run-hooks 'mdw-sgml-mode-hook))
2047 ;;;--------------------------------------------------------------------------
2050 (defun mdw-setup-sh-script-mode ()
2052 ;; Fetch the shell interpreter's name.
2053 (let ((shell-name sh-shell-file))
2055 ;; Try reading the hash-bang line.
2057 (goto-char (point-min))
2058 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2059 (setq shell-name (match-string 1))))
2061 ;; Now try to set the shell.
2063 ;; Don't let `sh-set-shell' bugger up my script.
2064 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2065 (sh-set-shell shell-name)))
2067 ;; Now enable my keys and the fontification.
2068 (mdw-misc-mode-config)
2070 ;; Set the indentation level correctly.
2071 (setq sh-indentation 2)
2072 (setq sh-basic-offset 2))
2074 ;;;--------------------------------------------------------------------------
2075 ;;; Emacs shell mode.
2077 (defun mdw-eshell-prompt ()
2078 (let ((left "[") (right "]"))
2079 (when (= (user-uid) 0)
2080 (setq left "«" right "»"))
2083 (replace-regexp-in-string "\\..*$" "" (system-name)))
2087 (setq eshell-prompt-function 'mdw-eshell-prompt)
2088 (setq eshell-prompt-regexp "^\\[[^]]+\\]")
2090 (defalias 'eshell/e 'find-file)
2091 (defalias 'eshell/w3m 'w3m-goto-url)
2093 (mdw-define-face eshell-prompt (t :weight bold))
2094 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2095 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2096 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2097 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2098 (mdw-define-face eshell-ls-executable (t :weight bold))
2099 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2100 (mdw-define-face eshell-ls-readonly (t nil))
2101 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2103 ;;;--------------------------------------------------------------------------
2104 ;;; Messages-file mode.
2106 (defun messages-mode-guts ()
2107 (setq messages-mode-syntax-table (make-syntax-table))
2108 (set-syntax-table messages-mode-syntax-table)
2109 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2110 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2111 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2112 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2113 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2114 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2115 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2116 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2117 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2118 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2119 (make-local-variable 'comment-start)
2120 (make-local-variable 'comment-end)
2121 (make-local-variable 'indent-line-function)
2122 (setq indent-line-function 'indent-relative)
2123 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2124 (make-local-variable 'font-lock-defaults)
2125 (make-local-variable 'messages-mode-keywords)
2127 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2128 "export" "enum" "fixed-octetstring" "flags"
2129 "harmless" "map" "nested" "optional"
2130 "optional-tagged" "package" "primitive"
2131 "primitive-nullfree" "relaxed[ \t]+enum"
2132 "set" "table" "tagged-optional" "union"
2133 "variadic" "vector" "version" "version-tag")))
2134 (setq messages-mode-keywords
2136 (list (concat "\\<\\(" keywords "\\)\\>:")
2137 '(0 font-lock-keyword-face))
2138 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2139 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2140 (0 font-lock-variable-name-face))
2141 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2142 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2143 (0 mdw-punct-face)))))
2144 (setq font-lock-defaults
2145 '(messages-mode-keywords nil nil nil nil))
2146 (run-hooks 'messages-file-hook))
2148 (defun messages-mode ()
2151 (setq major-mode 'messages-mode)
2152 (setq mode-name "Messages")
2153 (messages-mode-guts)
2154 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2155 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2156 (setq comment-start "# ")
2157 (setq comment-end "")
2158 (turn-on-font-lock-if-enabled)
2159 (run-hooks 'messages-mode-hook))
2161 (defun cpp-messages-mode ()
2164 (setq major-mode 'cpp-messages-mode)
2165 (setq mode-name "CPP Messages")
2166 (messages-mode-guts)
2167 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2168 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2169 (setq comment-start "/* ")
2170 (setq comment-end " */")
2171 (let ((preprocessor-keywords
2172 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2173 "ident" "if" "ifdef" "ifndef" "import" "include"
2174 "line" "pragma" "unassert" "undef" "warning")))
2175 (setq messages-mode-keywords
2176 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2177 "\\(include\\|import\\)"
2178 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2179 '(2 font-lock-string-face))
2180 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2181 preprocessor-keywords
2182 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2183 '(1 font-lock-keyword-face)))
2184 messages-mode-keywords)))
2185 (turn-on-font-lock-if-enabled)
2186 (run-hooks 'cpp-messages-mode-hook))
2188 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2189 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2190 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2192 ;;;--------------------------------------------------------------------------
2193 ;;; Messages-file mode.
2195 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2196 "Face to use for subsittution directives.")
2197 (make-face 'mallow-driver-substitution-face)
2198 (defvar mallow-driver-text-face 'mallow-driver-text-face
2199 "Face to use for body text.")
2200 (make-face 'mallow-driver-text-face)
2202 (defun mallow-driver-mode ()
2205 (setq major-mode 'mallow-driver-mode)
2206 (setq mode-name "Mallow driver")
2207 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2208 (set-syntax-table mallow-driver-mode-syntax-table)
2209 (make-local-variable 'comment-start)
2210 (make-local-variable 'comment-end)
2211 (make-local-variable 'indent-line-function)
2212 (setq indent-line-function 'indent-relative)
2213 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2214 (make-local-variable 'font-lock-defaults)
2215 (make-local-variable 'mallow-driver-mode-keywords)
2217 (mdw-regexps "each" "divert" "file" "if"
2218 "perl" "set" "string" "type" "write")))
2219 (setq mallow-driver-mode-keywords
2221 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2222 '(0 font-lock-keyword-face))
2223 (list "^%\\s *\\(#.*\\|\\)$"
2224 '(0 font-lock-comment-face))
2226 '(0 font-lock-keyword-face))
2227 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2229 '(0 mallow-driver-substitution-face t)))))
2230 (setq font-lock-defaults
2231 '(mallow-driver-mode-keywords nil nil nil nil))
2232 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2233 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2234 (setq comment-start "%# ")
2235 (setq comment-end "")
2236 (turn-on-font-lock-if-enabled)
2237 (run-hooks 'mallow-driver-mode-hook))
2239 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2241 ;;;--------------------------------------------------------------------------
2244 (defun nfast-debug-mode ()
2247 (setq major-mode 'nfast-debug-mode)
2248 (setq mode-name "NFast debug")
2249 (setq messages-mode-syntax-table (make-syntax-table))
2250 (set-syntax-table messages-mode-syntax-table)
2251 (make-local-variable 'font-lock-defaults)
2252 (make-local-variable 'nfast-debug-mode-keywords)
2253 (setq truncate-lines t)
2254 (setq nfast-debug-mode-keywords
2256 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2257 (0 font-lock-keyword-face))
2258 (list (concat "^[ \t]+\\(\\("
2259 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2260 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2262 "[0-9a-fA-F]+\\)[ \t]*$")
2263 '(0 mdw-number-face))
2264 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2265 (1 font-lock-keyword-face))
2266 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2267 (1 font-lock-warning-face))
2268 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2270 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2271 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2272 '(1 font-lock-keyword-face))
2273 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2274 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2275 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2276 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2277 (setq font-lock-defaults
2278 '(nfast-debug-mode-keywords nil nil nil nil))
2279 (turn-on-font-lock-if-enabled)
2280 (run-hooks 'nfast-debug-mode-hook))
2282 ;;;--------------------------------------------------------------------------
2283 ;;; Other languages.
2287 (defun mdw-setup-smalltalk ()
2288 (and mdw-auto-indent
2289 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2290 (make-variable-buffer-local 'mdw-auto-indent)
2291 (setq mdw-auto-indent nil)
2292 (local-set-key "\C-i" 'smalltalk-reindent))
2294 (defun mdw-fontify-smalltalk ()
2295 (make-local-variable 'font-lock-keywords)
2296 (setq font-lock-keywords
2298 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2299 '(0 font-lock-keyword-face))
2300 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2301 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2302 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2303 '(0 mdw-number-face))
2304 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2305 '(0 mdw-punct-face))))
2306 (mdw-post-config-mode-hack))
2310 ;; Unpleasant bodge.
2311 (unless (boundp 'slime-repl-mode-map)
2312 (setq slime-repl-mode-map (make-sparse-keymap)))
2314 (defun mdw-indent-newline-and-indent ()
2316 (indent-for-tab-command)
2317 (newline-and-indent))
2319 (eval-after-load "cl-indent"
2321 (mapc #'(lambda (pair)
2323 'common-lisp-indent-function
2325 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2326 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2328 (defun mdw-common-lisp-indent ()
2329 (make-variable-buffer-local 'lisp-indent-function)
2330 (setq lisp-indent-function 'common-lisp-indent-function))
2332 (setq lisp-simple-loop-indentation 2
2333 lisp-loop-keyword-indentation 6
2334 lisp-loop-forms-indentation 6)
2336 (defun mdw-fontify-lispy ()
2339 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2341 ;; Not much fontification needed.
2342 (make-local-variable 'font-lock-keywords)
2343 (setq font-lock-keywords
2345 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2346 '(0 mdw-punct-face))))
2348 (mdw-post-config-mode-hack))
2350 (defun comint-send-and-indent ()
2353 (and mdw-auto-indent
2354 (indent-for-tab-command)))
2356 (defun mdw-setup-m4 ()
2357 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2359 ;;;--------------------------------------------------------------------------
2362 (defun mdw-text-mode ()
2363 (setq fill-column 72)
2365 (mdw-standard-fill-prefix
2366 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2369 ;;;--------------------------------------------------------------------------
2370 ;;; Outline and hide/show modes.
2372 (defun mdw-outline-collapse-all ()
2373 "Completely collapse everything in the entire buffer."
2376 (goto-char (point-min))
2377 (while (< (point) (point-max))
2381 (setq hs-hide-comments-when-hiding-all nil)
2383 (defadvice hs-hide-all (after hide-first-comment activate)
2384 (save-excursion (hs-hide-initial-comment-block)))
2386 ;;;--------------------------------------------------------------------------
2389 (defun mdw-sh-mode-setup ()
2390 (local-set-key [?\C-a] 'comint-bol)
2391 (add-hook 'comint-output-filter-functions
2392 'comint-watch-for-password-prompt))
2394 (defun mdw-term-mode-setup ()
2395 (setq term-prompt-regexp shell-prompt-pattern)
2396 (make-local-variable 'mouse-yank-at-point)
2397 (make-local-variable 'transient-mark-mode)
2398 (setq mouse-yank-at-point t)
2402 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2403 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2404 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2405 (defun term-send-meta-meta-something ()
2407 (term-send-raw-string "\e\e")
2409 (eval-after-load 'term
2411 (define-key term-raw-map [?\e ?\e] nil)
2412 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2413 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2414 (define-key term-raw-map [M-right] 'term-send-meta-right)
2415 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2416 (define-key term-raw-map [M-left] 'term-send-meta-left)
2417 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2419 ;;;--------------------------------------------------------------------------
2420 ;;; Inferior Emacs Lisp.
2422 (setq comint-prompt-read-only t)
2424 (eval-after-load "comint"
2426 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2427 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2429 (eval-after-load "ielm"
2431 (define-key ielm-map "\C-w" 'comint-kill-region)
2432 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2434 ;;;----- That's all, folks --------------------------------------------------
2436 (provide 'dot-emacs)