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-horizontal-window-overhead ()
141 "Computes the horizontal window overhead.
142 This is the number of columns used by fringes, scroll bars and other such
144 (if (not window-system)
147 (dolist (what '(scroll-bar fringe))
148 (dolist (side '(left right))
149 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
153 (defun mdw-split-window-horizontally (&optional width)
154 "Split a window horizontally.
155 Without a numeric argument, split the window approximately in
156 half. With a numeric argument WIDTH, allocate WIDTH columns to
157 the left-hand window (if positive) or -WIDTH columns to the
158 right-hand window (if negative). Space for scroll bars and
159 fringes is not taken out of the allowance for WIDTH, unlike
160 \\[split-window-horizontally]."
162 (split-window-horizontally
163 (cond ((null width) nil)
164 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
165 ((< width 0) width))))
167 (defun mdw-divvy-window (&optional width)
168 "Split a wide window into appropriate widths."
170 (setq width (cond (width (prefix-numeric-value width))
172 (>= emacs-major-version 22))
175 (let* ((win (selected-window))
176 (sb-width (mdw-horizontal-window-overhead))
177 (c (/ (+ (window-width) sb-width)
178 (+ width sb-width))))
181 (split-window-horizontally (+ width sb-width))
183 (select-window win)))
185 ;; Transient mark mode hacks.
187 (defadvice exchange-point-and-mark
188 (around mdw-highlight (&optional arg) activate compile)
189 "Maybe don't actually exchange point and mark.
190 If `transient-mark-mode' is on and the mark is inactive, then
191 just activate it. A non-trivial prefix argument will force the
192 usual behaviour. A trivial prefix argument (i.e., just C-u) will
193 activate the mark and temporarily enable `transient-mark-mode' if
195 (cond ((or mark-active
196 (and (not transient-mark-mode) (not arg))
197 (and arg (or (not (consp arg))
198 (not (= (car arg) 4)))))
201 (or transient-mark-mode (setq transient-mark-mode 'only))
202 (set-mark (mark t)))))
204 ;; Functions for sexp diary entries.
206 (defun mdw-weekday (l)
207 "Return non-nil if `date' falls on one of the days of the week in L.
208 L is a list of day numbers (from 0 to 6 for Sunday through to
209 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
210 the date stored in `date' falls on a listed day, then the
211 function returns non-nil."
212 (let ((d (calendar-day-of-week date)))
214 (memq (nth d '(sunday monday tuesday wednesday
215 thursday friday saturday)) l))))
217 (defun mdw-todo (&optional when)
218 "Return non-nil today, or on WHEN, whichever is later."
219 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
220 (d (calendar-absolute-from-gregorian date)))
222 (setq w (max w (calendar-absolute-from-gregorian
224 ((not european-calendar-style)
236 ;; Fighting with Org-mode's evil key maps.
238 (defvar mdw-evil-keymap-keys
239 '(([S-up] . [?\C-c up])
240 ([S-down] . [?\C-c down])
241 ([S-left] . [?\C-c left])
242 ([S-right] . [?\C-c right])
243 (([M-up] [?\e up]) . [C-up])
244 (([M-down] [?\e down]) . [C-down])
245 (([M-left] [?\e left]) . [C-left])
246 (([M-right] [?\e right]) . [C-right]))
247 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
248 The value is an alist mapping evil keys (as a list, or singleton)
249 to good keys (in the same form).")
251 (defun mdw-clobber-evil-keymap (keymap)
252 "Replace evil key bindings in the KEYMAP.
253 Evil key bindings are defined in `mdw-evil-keymap-keys'."
254 (dolist (entry mdw-evil-keymap-keys)
256 (keys (if (listp (car entry))
259 (replacements (if (listp (cdr entry))
261 (list (cdr entry)))))
264 (setq binding (lookup-key keymap key))
266 (throw 'found nil))))
269 (define-key keymap key nil))
270 (dolist (key replacements)
271 (define-key keymap key binding))))))
273 (eval-after-load "org-latex"
276 "\\documentclass{strayman}
277 \\usepackage[utf8]{inputenc}
278 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
279 \\usepackage[T1]{fontenc}
280 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
281 ("\\section{%s}" . "\\section*{%s}")
282 ("\\subsection{%s}" . "\\subsection*{%s}")
283 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
284 ("\\paragraph{%s}" . "\\paragraph*{%s}")
285 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
286 org-export-latex-classes)))
288 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
289 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
290 org-export-docbook-xslt-stylesheet
291 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
293 ;;;--------------------------------------------------------------------------
294 ;;; Mail and news hacking.
296 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
297 "Major mode for editing news and mail messages from external programs.
298 Not much right now. Just support for doing MailCrypt stuff."
301 (run-hooks 'mail-setup-hook))
303 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
305 (add-hook 'mdwail-mode-hook
307 (set-buffer-file-coding-system 'utf-8)
308 (make-local-variable 'paragraph-separate)
309 (make-local-variable 'paragraph-start)
310 (setq paragraph-start
311 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
313 (setq paragraph-separate
314 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
315 paragraph-separate))))
317 ;; How to encrypt in mdwmail.
319 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
321 (setq start (save-excursion
322 (goto-char (point-min))
323 (or (search-forward "\n\n" nil t) (point-min)))))
325 (setq end (point-max)))
326 (mc-encrypt-generic recip scm start end from sign))
328 ;; How to sign in mdwmail.
330 (defun mdwmail-mc-sign (key scm start end uclr)
332 (setq start (save-excursion
333 (goto-char (point-min))
334 (or (search-forward "\n\n" nil t) (point-min)))))
336 (setq end (point-max)))
337 (mc-sign-generic key scm start end uclr))
339 ;; Some signature mangling.
341 (defun mdwmail-mangle-signature ()
343 (goto-char (point-min))
344 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
345 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
346 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
348 ;; Insert my login name into message-ids, so I can score replies.
350 (defadvice message-unique-id (after mdw-user-name last activate compile)
351 "Ensure that the user's name appears at the end of the message-id string,
352 so that it can be used for convenient filtering."
353 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
355 ;; Tell my movemail hack where movemail is.
357 ;; This is needed to shup up warnings about LD_PRELOAD.
359 (let ((path exec-path))
361 (let ((try (expand-file-name "movemail" (car path))))
362 (if (file-executable-p try)
363 (setenv "REAL_MOVEMAIL" try))
364 (setq path (cdr path)))))
366 (eval-after-load "erc"
367 '(load "~/.ercrc.el"))
369 ;;;--------------------------------------------------------------------------
370 ;;; Utility functions.
372 (or (fboundp 'line-number-at-pos)
373 (defun line-number-at-pos (&optional pos)
374 (let ((opoint (or pos (point))) start)
377 (goto-char (point-min))
383 (1+ (count-lines 1 (point))))))))
385 (defun mdw-uniquify-alist (&rest alists)
386 "Return the concatenation of the ALISTS with duplicate elements removed.
387 The first association with a given key prevails; others are
388 ignored. The input lists are not modified, although they'll
389 probably become garbage."
391 (let ((start-list (cons nil nil)))
392 (mdw-do-uniquify start-list
397 (defun mdw-do-uniquify (done end l rest)
398 "A helper function for mdw-uniquify-alist.
399 The DONE argument is a list whose first element is `nil'. It
400 contains the uniquified alist built so far. The leading `nil' is
401 stripped off at the end of the operation; it's only there so that
402 DONE always references a cons cell. END refers to the final cons
403 cell in the DONE list; it is modified in place each time to avoid
404 the overheads of `append'ing all the time. The L argument is the
405 alist we're currently processing; the remaining alists are given
408 ;; There are several different cases to deal with here.
411 ;; Current list isn't empty. Add the first item to the DONE list if
412 ;; there's not an item with the same KEY already there.
413 (l (or (assoc (car (car l)) done)
415 (setcdr end (cons (car l) nil))
416 (setq end (cdr end))))
417 (mdw-do-uniquify done end (cdr l) rest))
419 ;; The list we were working on is empty. Shunt the next list into the
420 ;; current list position and go round again.
421 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
423 ;; Everything's done. Remove the leading `nil' from the DONE list and
424 ;; return it. Finished!
428 "Insert the current date in a pleasing way."
430 (insert (save-excursion
431 (let ((buffer (get-buffer-create "*tmp*")))
432 (unwind-protect (progn (set-buffer buffer)
434 (shell-command "date +%Y-%m-%d" t)
436 (delete-backward-char 1)
438 (kill-buffer buffer))))))
440 (defun uuencode (file &optional name)
441 "UUencodes a file, maybe calling it NAME, into the current buffer."
442 (interactive "fInput file name: ")
444 ;; If NAME isn't specified, then guess from the filename.
448 (or (string-match "[^/]*$" file) 0))))
449 (print (format "uuencode `%s' `%s'" file name))
451 ;; Now actually do the thing.
452 (call-process "uuencode" file t nil name))
454 (defvar np-file "~/.np"
455 "*Where the `now-playing' file is.")
457 (defun np (&optional arg)
458 "Grabs a `now-playing' string."
462 (goto-char (point-max))
464 (insert-file-contents np-file)))))
466 (defun mdw-version-< (ver-a ver-b)
467 "Answer whether VER-A is strictly earlier than VER-B.
468 VER-A and VER-B are version numbers, which are strings containing digit
469 sequences separated by `.'."
470 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
471 (split-string ver-a "\\.")))
472 (lb (mapcar (lambda (x) (car (read-from-string x)))
473 (split-string ver-b "\\."))))
476 (cond ((null la) (throw 'done lb))
477 ((null lb) (throw 'done nil))
478 ((< (car la) (car lb)) (throw 'done t))
479 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb))))))))
481 (defun mdw-check-autorevert ()
482 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
483 This takes into consideration whether it's been found using
484 tramp, which seems to get itself into a twist."
485 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
487 ((and (buffer-file-name)
488 (fboundp 'tramp-tramp-file-p)
489 (tramp-tramp-file-p (buffer-file-name)))
490 (unless global-auto-revert-ignore-buffer
491 (setq global-auto-revert-ignore-buffer 'tramp)))
492 ((eq global-auto-revert-ignore-buffer 'tramp)
493 (setq global-auto-revert-ignore-buffer nil))))
495 (defadvice find-file (after mdw-autorevert activate)
496 (mdw-check-autorevert))
497 (defadvice write-file (after mdw-autorevert activate)
498 (mdw-check-autorevert))
500 ;;;--------------------------------------------------------------------------
503 (defadvice dired-maybe-insert-subdir
504 (around mdw-marked-insertion first activate)
505 "The DIRNAME may be a list of directory names to insert.
506 Interactively, if files are marked, then insert all of them.
507 With a numeric prefix argument, select that many entries near
508 point; with a non-numeric prefix argument, prompt for listing
511 (list (dired-get-marked-files nil
512 (and (integerp current-prefix-arg)
515 (and current-prefix-arg
516 (not (integerp current-prefix-arg))
517 (read-string "Switches for listing: "
518 (or dired-subdir-switches
519 dired-actual-switches)))))
520 (let ((dirs (ad-get-arg 0)))
521 (dolist (dir (if (listp dirs) dirs (list dirs)))
525 ;;;--------------------------------------------------------------------------
528 (defun mdw-w3m-browse-url (url &optional new-session-p)
529 "Invoke w3m on the URL in its current window, or at least a different one.
530 If NEW-SESSION-P, start a new session."
531 (interactive "sURL: \nP")
533 (let ((window (selected-window)))
536 (select-window (or (and (not new-session-p)
537 (get-buffer-window "*w3m*"))
539 (if (one-window-p t) (split-window))
541 (w3m-browse-url url new-session-p))
542 (select-window window)))))
544 (defvar mdw-good-url-browsers
546 (w3m . mdw-w3m-browse-url)
549 "List of good browsers for mdw-good-url-browsers.
550 Each item is a browser function name, or a cons (CHECK . FUNC).
551 A symbol FOO stands for (FOO . FOO).")
553 (defun mdw-good-url-browser ()
554 "Return a good URL browser.
555 Trundle the list of such things, finding the first item for which
556 CHECK is fboundp, and returning the correponding FUNC."
557 (let ((bs mdw-good-url-browsers) b check func answer)
558 (while (and bs (not answer))
562 (setq check (car b) func (cdr b))
563 (setq check b func b))
568 (eval-after-load "w3m-search"
572 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
573 ("gd" "Google Directory"
574 "http://www.google.com/search?cat=gwd/Top&q=%s")
575 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
576 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
577 ("gi" "Images" "http://images.google.com/images?q=%s")
579 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
581 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
582 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
583 ("nc-wiki" "nCipher wiki"
584 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
585 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
586 ("lp" "Launchpad bug by number"
587 "https://bugs.launchpad.net/bugs/%s")
588 ("lppkg" "Launchpad bugs by package"
589 "https://bugs.launchpad.net/%s")
591 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
592 ("debbug" "Debian bug by number"
593 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
594 ("debbugpkg" "Debian bugs by package"
595 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
596 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
597 (add-to-list 'w3m-search-engine-alist
598 (list (cadr item) (caddr item) nil))
599 (add-to-list 'w3m-uri-replace-alist
600 (list (concat "\\`" (car item) ":")
601 'w3m-search-uri-replace
604 ;;;--------------------------------------------------------------------------
605 ;;; Paragraph filling.
609 (defvar mdw-fill-prefix nil
610 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
611 If there's no fill prefix currently set (by the `fill-prefix'
612 variable) and there's a match from one of the regexps here, it
613 gets used to set the fill-prefix for the current operation.
615 The variable is a list of items of the form `REGEXP . PREFIX'; if
616 the REGEXP matches, the PREFIX is used to set the fill prefix.
617 It in turn is a list of things:
619 STRING -- insert a literal string
620 (match . N) -- insert the thing matched by bracketed subexpression N
621 (pad . N) -- a string of whitespace the same width as subexpression N
622 (expr . FORM) -- the result of evaluating FORM")
624 (make-variable-buffer-local 'mdw-fill-prefix)
626 (defvar mdw-hanging-indents
628 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
631 "*Standard regexp matching parts of a hanging indent.
632 This is mainly useful in `auto-fill-mode'.")
634 ;; Setting things up.
636 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
638 ;; Utility functions.
640 (defun mdw-tabify (s)
641 "Tabify the string S. This is a horrid hack."
646 (setq start (point-marker))
648 (setq end (point-marker))
650 (setq s (buffer-substring start (1- end)))
651 (delete-region start end)
652 (set-marker start nil)
656 (defun mdw-examine-fill-prefixes (l)
657 "Given a list of dynamic fill prefixes, pick one which matches
658 context and return the static fill prefix to use. Point must be
659 at the start of a line, and match data must be saved."
661 ((looking-at (car (car l)))
662 (mdw-tabify (apply (function concat)
663 (mapcar (function mdw-do-prefix-match)
665 (t (mdw-examine-fill-prefixes (cdr l)))))
667 (defun mdw-maybe-car (p)
668 "If P is a pair, return (car P), otherwise just return P."
669 (if (consp p) (car p) p))
671 (defun mdw-padding (s)
672 "Return a string the same width as S but made entirely from whitespace."
673 (let* ((l (length s)) (i 0) (n (make-string l ? )))
680 (defun mdw-do-prefix-match (m)
681 "Expand a dynamic prefix match element.
682 See `mdw-fill-prefix' for details."
683 (cond ((not (consp m)) (format "%s" m))
684 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
685 ((eq (car m) 'pad) (mdw-padding (match-string
686 (mdw-maybe-car (cdr m)))))
687 ((eq (car m) 'eval) (eval (cdr m)))
690 (defun mdw-choose-dynamic-fill-prefix ()
691 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
692 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
693 ((not mdw-fill-prefix) fill-prefix)
697 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
699 (defun do-auto-fill ()
700 "Handle auto-filling, working out a dynamic fill prefix in the
701 case where there isn't a sensible static one."
702 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
705 (defun mdw-fill-paragraph ()
706 "Fill paragraph, getting a dynamic fill prefix."
708 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
709 (fill-paragraph nil)))
711 (defun mdw-standard-fill-prefix (rx &optional mat)
712 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
713 This is just a short-cut for setting the thing by hand, and by
714 design it doesn't cope with anything approximating a complicated
716 (setq mdw-fill-prefix
717 `((,(concat rx mdw-hanging-indents)
719 (pad . ,(or mat 2))))))
721 ;;;--------------------------------------------------------------------------
722 ;;; Other common declarations.
724 ;; Common mode settings.
726 (defvar mdw-auto-indent t
727 "Whether to indent automatically after a newline.")
729 (defun mdw-whitespace-mode (&optional arg)
730 "Turn on/off whitespace mode, but don't highlight trailing space."
732 (when (and (boundp 'whitespace-style)
733 (fboundp 'whitespace-mode))
734 (let ((whitespace-style (remove 'trailing whitespace-style)))
735 (whitespace-mode arg))
736 (setq show-trailing-whitespace whitespace-mode)))
738 (defun mdw-misc-mode-config ()
740 (cond ((eq major-mode 'lisp-mode)
741 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
742 ((or (eq major-mode 'slime-repl-mode)
743 (eq major-mode 'asm-mode))
746 (local-set-key "\C-m" 'newline-and-indent))))
747 (local-set-key [C-return] 'newline)
748 (make-local-variable 'page-delimiter)
749 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
750 (setq comment-column 40)
752 (setq fill-column 77)
753 (setq show-trailing-whitespace t)
754 (mdw-whitespace-mode 1)
755 (and (fboundp 'gtags-mode)
757 (if (fboundp 'hs-minor-mode)
759 (outline-minor-mode t))
761 (trap (turn-on-font-lock)))
763 (defun mdw-post-config-mode-hack ()
764 (mdw-whitespace-mode 1))
766 (eval-after-load 'gtags
768 (dolist (key '([mouse-2] [mouse-3]))
769 (define-key gtags-mode-map key nil))
770 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
771 (define-key gtags-select-mode-map [C-S-mouse-2]
772 'gtags-select-tag-by-event)
773 (dolist (map (list gtags-mode-map gtags-select-mode-map))
774 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
776 ;; Backup file handling.
778 (defvar mdw-backup-disable-regexps nil
779 "*List of regular expressions: if a file name matches any of
780 these then the file is not backed up.")
782 (defun mdw-backup-enable-predicate (name)
783 "[mdw]'s default backup predicate.
784 Allows a backup if the standard predicate would allow it, and it
785 doesn't match any of the regular expressions in
786 `mdw-backup-disable-regexps'."
787 (and (normal-backup-enable-predicate name)
788 (let ((answer t) (list mdw-backup-disable-regexps))
791 (if (string-match (car list) name)
793 (setq list (cdr list)))
795 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
799 (defun mdw-last-one-out-turn-off-the-lights (frame)
800 "Disconnect from an X display if this was the last frame on that display."
801 (let ((frame-display (frame-parameter frame 'display)))
802 (when (and frame-display
803 (eq window-system 'x)
804 (not (some (lambda (fr)
805 (and (not (eq fr frame))
806 (string= (frame-parameter fr 'display)
809 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
810 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
812 ;;;--------------------------------------------------------------------------
813 ;;; General fontification.
815 (defmacro mdw-define-face (name &rest body)
816 "Define a face, and make sure it's actually set as the definition."
821 (defvar ,name ',name)
822 (put ',name 'face-defface-spec ',body)
823 (face-spec-set ',name ',body nil)))
825 (mdw-define-face default
826 (((type w32)) :family "courier new" :height 85)
827 (((type x)) :family "6x13" :height 130)
828 (((type color)) :foreground "white" :background "black")
830 (mdw-define-face fixed-pitch
831 (((type w32)) :family "courier new" :height 85)
832 (((type x)) :family "6x13" :height 130)
833 (t :foreground "white" :background "black"))
834 (if (>= emacs-major-version 23)
835 (mdw-define-face variable-pitch
836 (((type x)) :family "sans" :height 100))
837 (mdw-define-face variable-pitch
838 (((type x)) :family "helvetica" :height 90)))
839 (mdw-define-face region
840 (((type tty) (class color)) :background "blue")
841 (((type tty) (class mono)) :inverse-video t)
842 (t :background "grey30"))
843 (mdw-define-face minibuffer-prompt
845 (mdw-define-face mode-line
846 (((class color)) :foreground "blue" :background "yellow"
847 :box (:line-width 1 :style released-button))
848 (t :inverse-video t))
849 (mdw-define-face mode-line-inactive
850 (((class color)) :foreground "yellow" :background "blue"
851 :box (:line-width 1 :style released-button))
852 (t :inverse-video t))
853 (mdw-define-face scroll-bar
854 (t :foreground "black" :background "lightgrey"))
855 (mdw-define-face fringe
856 (t :foreground "yellow"))
857 (mdw-define-face show-paren-match
858 (((class color)) :background "darkgreen")
860 (mdw-define-face show-paren-mismatch
861 (((class color)) :background "red")
862 (t :inverse-video t))
863 (mdw-define-face highlight
864 (((class color)) :background "DarkSeaGreen4")
865 (t :inverse-video t))
867 (mdw-define-face holiday-face
868 (t :background "red"))
869 (mdw-define-face calendar-today-face
870 (t :foreground "yellow" :weight bold))
872 (mdw-define-face comint-highlight-prompt
874 (mdw-define-face comint-highlight-input
877 (mdw-define-face dired-directory
878 (t :foreground "cyan" :weight bold))
879 (mdw-define-face dired-symlink
880 (t :foreground "cyan"))
881 (mdw-define-face dired-perm-write
884 (mdw-define-face trailing-whitespace
885 (((class color)) :background "red")
886 (t :inverse-video t))
887 (mdw-define-face mdw-punct-face
888 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
889 (mdw-define-face mdw-number-face
890 (t :foreground "yellow"))
891 (mdw-define-face font-lock-function-name-face
893 (mdw-define-face font-lock-keyword-face
895 (mdw-define-face font-lock-constant-face
897 (mdw-define-face font-lock-builtin-face
899 (mdw-define-face font-lock-type-face
900 (t :weight bold :slant italic))
901 (mdw-define-face font-lock-reference-face
903 (mdw-define-face font-lock-variable-name-face
905 (mdw-define-face font-lock-comment-delimiter-face
906 (((class mono)) :weight bold)
907 (((type tty) (class color)) :foreground "green")
908 (t :slant italic :foreground "SeaGreen1"))
909 (mdw-define-face font-lock-comment-face
910 (((class mono)) :weight bold)
911 (((type tty) (class color)) :foreground "green")
912 (t :slant italic :foreground "SeaGreen1"))
913 (mdw-define-face font-lock-string-face
914 (((class mono)) :weight bold)
915 (((class color)) :foreground "SkyBlue1"))
916 (mdw-define-face message-separator
917 (t :background "red" :foreground "white" :weight bold))
918 (mdw-define-face message-cited-text
919 (default :slant italic)
920 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
921 (mdw-define-face message-header-cc
922 (default :weight bold)
923 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
924 (mdw-define-face message-header-newsgroups
925 (default :weight bold)
926 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
927 (mdw-define-face message-header-subject
928 (default :weight bold)
929 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
930 (mdw-define-face message-header-to
931 (default :weight bold)
932 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
933 (mdw-define-face message-header-xheader
934 (default :weight bold)
935 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
936 (mdw-define-face message-header-other
937 (default :weight bold)
938 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
939 (mdw-define-face message-header-name
940 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
941 (mdw-define-face which-func
944 (mdw-define-face diff-index
946 (mdw-define-face diff-file-header
948 (mdw-define-face diff-hunk-header
949 (t :foreground "SkyBlue1"))
950 (mdw-define-face diff-function
951 (t :foreground "SkyBlue1" :weight bold))
952 (mdw-define-face diff-header
953 (t :background "grey10"))
954 (mdw-define-face diff-added
955 (t :foreground "green"))
956 (mdw-define-face diff-removed
957 (t :foreground "red"))
958 (mdw-define-face diff-context
961 (mdw-define-face erc-input-face
962 (t :foreground "red"))
964 (mdw-define-face woman-bold
966 (mdw-define-face woman-italic
969 (mdw-define-face p4-depot-added-face
970 (t :foreground "green"))
971 (mdw-define-face p4-depot-branch-op-face
972 (t :foreground "yellow"))
973 (mdw-define-face p4-depot-deleted-face
974 (t :foreground "red"))
975 (mdw-define-face p4-depot-unmapped-face
976 (t :foreground "SkyBlue1"))
977 (mdw-define-face p4-diff-change-face
978 (t :foreground "yellow"))
979 (mdw-define-face p4-diff-del-face
980 (t :foreground "red"))
981 (mdw-define-face p4-diff-file-face
982 (t :foreground "SkyBlue1"))
983 (mdw-define-face p4-diff-head-face
984 (t :background "grey10"))
985 (mdw-define-face p4-diff-ins-face
986 (t :foreground "green"))
988 (mdw-define-face whizzy-slice-face
989 (t :background "grey10"))
990 (mdw-define-face whizzy-error-face
991 (t :background "darkred"))
993 ;; Ellipses used to indicate hidden text (and similar).
994 (mdw-define-face mdw-ellipsis-face
995 (((type tty)) :foreground "blue") (t :foreground "grey60"))
996 (let ((dot (make-glyph-code ?. 'mdw-ellipsis-face)))
997 (set-display-table-slot standard-display-table 4
998 (vector dot dot dot)))
1000 ;;;--------------------------------------------------------------------------
1001 ;;; C programming configuration.
1003 ;; Linux kernel hacking.
1005 (defvar linux-c-mode-hook)
1007 (defun linux-c-mode ()
1010 (setq major-mode 'linux-c-mode)
1011 (setq mode-name "Linux C")
1012 (run-hooks 'linux-c-mode-hook))
1014 ;; Make C indentation nice.
1016 (defun mdw-c-lineup-arglist (langelem)
1017 "Hack for DWIMmery in c-lineup-arglist."
1019 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1021 (c-lineup-arglist langelem)))
1023 (defun mdw-c-indent-extern-mumble (langelem)
1024 "Indent `extern \"...\" {' lines."
1026 (back-to-indentation)
1028 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1032 (defun mdw-c-style ()
1033 (c-add-style "[mdw] C and C++ style"
1034 '((c-basic-offset . 2)
1035 (comment-column . 40)
1036 (c-class-key . "class")
1037 (c-backslash-column . 72)
1039 (substatement-open . (add 0 c-indent-one-line-block))
1040 (defun-open . (add 0 c-indent-one-line-block))
1041 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1042 (topmost-intro . mdw-c-indent-extern-mumble)
1043 (cpp-define-intro . 0)
1045 (inextern-lang . [0])
1051 (statement-cont . +)
1052 (statement-case-intro . +)))
1055 (defvar mdw-c-comment-fill-prefix
1056 `((,(concat "\\([ \t]*/?\\)"
1059 "\\([A-Za-z]+:[ \t]*\\)?"
1060 mdw-hanging-indents)
1061 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1062 "Fill prefix matching C comments (both kinds).")
1064 (defun mdw-fontify-c-and-c++ ()
1066 ;; Fiddle with some syntax codes.
1067 (modify-syntax-entry ?* ". 23")
1068 (modify-syntax-entry ?/ ". 124b")
1069 (modify-syntax-entry ?\n "> b")
1073 (setq c-hanging-comment-ender-p nil)
1074 (setq c-backslash-column 72)
1075 (setq c-label-minimum-indentation 0)
1076 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1078 ;; Now define things to be fontified.
1079 (make-local-variable 'font-lock-keywords)
1081 (mdw-regexps "and" ;C++
1087 "bool" ;C++, C9X macro
1093 "complex" ;C9X macro, C++ template type
1097 "continue" ;K&R, C89
1098 "defined" ;C89 preprocessor
1105 ;; "entry" ;K&R -- never used
1110 "false" ;C++, C9X macro
1117 "imaginary" ;C9X macro
1118 "inline" ;C++, C9X, GCC
1130 "register" ;K&R, C89
1131 "reinterpret_cast" ;C++
1144 "true" ;C++, C9X macro
1152 "unsigned" ;K&R, C89
1157 "wchar_t" ;C++, C89 library type
1164 "_Pragma" ;C9X preprocessor
1167 "__attribute__" ;GCC
1170 "__extension__" ;GCC
1179 (preprocessor-keywords
1180 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1181 "ident" "if" "ifdef" "ifndef" "import" "include"
1182 "line" "pragma" "unassert" "undef" "warning"))
1184 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1185 "interface" "private" "protected" "protocol" "public"
1188 (setq font-lock-keywords
1191 ;; Fontify include files as strings.
1192 (list (concat "^[ \t]*\\#[ \t]*"
1193 "\\(include\\|import\\)"
1194 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1195 '(2 font-lock-string-face))
1197 ;; Preprocessor directives are `references'?.
1198 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1199 preprocessor-keywords
1200 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1201 '(1 font-lock-keyword-face))
1203 ;; Handle the keywords defined above.
1204 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1205 '(0 font-lock-keyword-face))
1207 (list (concat "\\<\\(" c-keywords "\\)\\>")
1208 '(0 font-lock-keyword-face))
1210 ;; Handle numbers too.
1212 ;; This looks strange, I know. It corresponds to the
1213 ;; preprocessor's idea of what a number looks like, rather than
1214 ;; anything sensible.
1215 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1216 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1217 '(0 mdw-number-face))
1219 ;; And anything else is punctuation.
1220 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1221 '(0 mdw-punct-face))))
1223 (mdw-post-config-mode-hack)))
1225 ;;;--------------------------------------------------------------------------
1228 (defun apcalc-mode ()
1231 (setq major-mode 'apcalc-mode)
1232 (setq mode-name "AP Calc")
1233 (run-hooks 'apcalc-mode-hook))
1235 (defun mdw-fontify-apcalc ()
1237 ;; Fiddle with some syntax codes.
1238 (modify-syntax-entry ?* ". 23")
1239 (modify-syntax-entry ?/ ". 14")
1243 (setq c-hanging-comment-ender-p nil)
1244 (setq c-backslash-column 72)
1245 (setq comment-start "/* ")
1246 (setq comment-end " */")
1247 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1249 ;; Now define things to be fontified.
1250 (make-local-variable 'font-lock-keywords)
1252 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1253 "do" "else" "exit" "for" "global" "goto" "help" "if"
1254 "local" "mat" "obj" "print" "quit" "read" "return"
1255 "show" "static" "switch" "while" "write")))
1257 (setq font-lock-keywords
1260 ;; Handle the keywords defined above.
1261 (list (concat "\\<\\(" c-keywords "\\)\\>")
1262 '(0 font-lock-keyword-face))
1264 ;; Handle numbers too.
1266 ;; This looks strange, I know. It corresponds to the
1267 ;; preprocessor's idea of what a number looks like, rather than
1268 ;; anything sensible.
1269 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1270 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1271 '(0 mdw-number-face))
1273 ;; And anything else is punctuation.
1274 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1275 '(0 mdw-punct-face)))))
1277 (mdw-post-config-mode-hack))
1279 ;;;--------------------------------------------------------------------------
1280 ;;; Java programming configuration.
1282 ;; Make indentation nice.
1284 (defun mdw-java-style ()
1285 (c-add-style "[mdw] Java style"
1286 '((c-basic-offset . 2)
1287 (c-offsets-alist (substatement-open . 0)
1292 (statement-case-intro . +)))
1295 ;; Declare Java fontification style.
1297 (defun mdw-fontify-java ()
1301 (setq c-hanging-comment-ender-p nil)
1302 (setq c-backslash-column 72)
1303 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1305 ;; Now define things to be fontified.
1306 (make-local-variable 'font-lock-keywords)
1307 (let ((java-keywords
1308 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1309 "char" "class" "const" "continue" "default" "do"
1310 "double" "else" "extends" "final" "finally" "float"
1311 "for" "goto" "if" "implements" "import" "instanceof"
1312 "int" "interface" "long" "native" "new" "package"
1313 "private" "protected" "public" "return" "short"
1314 "static" "super" "switch" "synchronized" "this"
1315 "throw" "throws" "transient" "try" "void" "volatile"
1318 "false" "null" "true")))
1320 (setq font-lock-keywords
1323 ;; Handle the keywords defined above.
1324 (list (concat "\\<\\(" java-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 ;;;--------------------------------------------------------------------------
1344 ;;; Javascript programming configuration.
1346 (defun mdw-javascript-style ()
1347 (setq js-indent-level 2)
1348 (setq js-expr-indent-offset 0))
1350 (defun mdw-fontify-javascript ()
1353 (mdw-javascript-style)
1354 (setq js-auto-indent-flag t)
1356 ;; Now define things to be fontified.
1357 (make-local-variable 'font-lock-keywords)
1358 (let ((javascript-keywords
1359 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1360 "char" "class" "const" "continue" "debugger" "default"
1361 "delete" "do" "double" "else" "enum" "export" "extends"
1362 "final" "finally" "float" "for" "function" "goto" "if"
1363 "implements" "import" "in" "instanceof" "int"
1364 "interface" "let" "long" "native" "new" "package"
1365 "private" "protected" "public" "return" "short"
1366 "static" "super" "switch" "synchronized" "throw"
1367 "throws" "transient" "try" "typeof" "var" "void"
1368 "volatile" "while" "with" "yield"
1370 "boolean" "byte" "char" "double" "float" "int" "long"
1372 (javascript-constants
1373 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
1374 "arguments" "this")))
1376 (setq font-lock-keywords
1379 ;; Handle the keywords defined above.
1380 (list (concat "\\<\\(" javascript-keywords "\\)\\>")
1381 '(0 font-lock-keyword-face))
1383 ;; Handle the predefined constants defined above.
1384 (list (concat "\\<\\(" javascript-constants "\\)\\>")
1385 '(0 font-lock-variable-name-face))
1387 ;; Handle numbers too.
1389 ;; The following isn't quite right, but it's close enough.
1390 (list (concat "\\<\\("
1391 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1392 "[0-9]+\\(\\.[0-9]*\\|\\)"
1393 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1395 '(0 mdw-number-face))
1397 ;; And anything else is punctuation.
1398 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1399 '(0 mdw-punct-face)))))
1401 (mdw-post-config-mode-hack))
1403 ;;;--------------------------------------------------------------------------
1404 ;;; C# programming configuration.
1406 ;; Make indentation nice.
1408 (defun mdw-csharp-style ()
1409 (c-add-style "[mdw] C# style"
1410 '((c-basic-offset . 2)
1411 (c-offsets-alist (substatement-open . 0)
1416 (statement-case-intro . +)))
1419 ;; Declare C# fontification style.
1421 (defun mdw-fontify-csharp ()
1425 (setq c-hanging-comment-ender-p nil)
1426 (setq c-backslash-column 72)
1427 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1429 ;; Now define things to be fontified.
1430 (make-local-variable 'font-lock-keywords)
1431 (let ((csharp-keywords
1432 (mdw-regexps "abstract" "as" "base" "bool" "break"
1433 "byte" "case" "catch" "char" "checked"
1434 "class" "const" "continue" "decimal" "default"
1435 "delegate" "do" "double" "else" "enum"
1436 "event" "explicit" "extern" "false" "finally"
1437 "fixed" "float" "for" "foreach" "goto"
1438 "if" "implicit" "in" "int" "interface"
1439 "internal" "is" "lock" "long" "namespace"
1440 "new" "null" "object" "operator" "out"
1441 "override" "params" "private" "protected" "public"
1442 "readonly" "ref" "return" "sbyte" "sealed"
1443 "short" "sizeof" "stackalloc" "static" "string"
1444 "struct" "switch" "this" "throw" "true"
1445 "try" "typeof" "uint" "ulong" "unchecked"
1446 "unsafe" "ushort" "using" "virtual" "void"
1447 "volatile" "while" "yield")))
1449 (setq font-lock-keywords
1452 ;; Handle the keywords defined above.
1453 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1454 '(0 font-lock-keyword-face))
1456 ;; Handle numbers too.
1458 ;; The following isn't quite right, but it's close enough.
1459 (list (concat "\\<\\("
1460 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1461 "[0-9]+\\(\\.[0-9]*\\|\\)"
1462 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1464 '(0 mdw-number-face))
1466 ;; And anything else is punctuation.
1467 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1468 '(0 mdw-punct-face)))))
1470 (mdw-post-config-mode-hack))
1472 (define-derived-mode csharp-mode java-mode "C#"
1473 "Major mode for editing C# code.")
1475 ;;;--------------------------------------------------------------------------
1476 ;;; Go programming configuration.
1478 (defun mdw-fontify-go ()
1480 (make-local-variable 'font-lock-keywords)
1482 (mdw-regexps "break" "case" "chan" "const" "continue"
1483 "default" "defer" "else" "fallthrough" "for"
1484 "func" "go" "goto" "if" "import"
1485 "interface" "map" "package" "range" "return"
1486 "select" "struct" "switch" "type" "var")))
1488 (setq font-lock-keywords
1491 ;; Handle the keywords defined above.
1492 (list (concat "\\<\\(" go-keywords "\\)\\>")
1493 '(0 font-lock-keyword-face))
1495 ;; Handle numbers too.
1497 ;; The following isn't quite right, but it's close enough.
1498 (list (concat "\\<\\("
1499 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1500 "[0-9]+\\(\\.[0-9]*\\|\\)"
1501 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1502 '(0 mdw-number-face))
1504 ;; And anything else is punctuation.
1505 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1506 '(0 mdw-punct-face)))))
1508 (mdw-post-config-mode-hack))
1510 ;;;--------------------------------------------------------------------------
1511 ;;; Awk programming configuration.
1513 ;; Make Awk indentation nice.
1515 (defun mdw-awk-style ()
1516 (c-add-style "[mdw] Awk style"
1517 '((c-basic-offset . 2)
1518 (c-offsets-alist (substatement-open . 0)
1519 (statement-cont . 0)
1520 (statement-case-intro . +)))
1523 ;; Declare Awk fontification style.
1525 (defun mdw-fontify-awk ()
1527 ;; Miscellaneous fiddling.
1529 (setq c-backslash-column 72)
1530 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1532 ;; Now define things to be fontified.
1533 (make-local-variable 'font-lock-keywords)
1535 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1536 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1537 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1538 "RSTART" "RLENGTH" "RT" "SUBSEP"
1539 "atan2" "break" "close" "continue" "cos" "delete"
1540 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1541 "function" "gensub" "getline" "gsub" "if" "in"
1542 "index" "int" "length" "log" "match" "next" "rand"
1543 "return" "print" "printf" "sin" "split" "sprintf"
1544 "sqrt" "srand" "strftime" "sub" "substr" "system"
1545 "systime" "tolower" "toupper" "while")))
1547 (setq font-lock-keywords
1550 ;; Handle the keywords defined above.
1551 (list (concat "\\<\\(" c-keywords "\\)\\>")
1552 '(0 font-lock-keyword-face))
1554 ;; Handle numbers too.
1556 ;; The following isn't quite right, but it's close enough.
1557 (list (concat "\\<\\("
1558 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1559 "[0-9]+\\(\\.[0-9]*\\|\\)"
1560 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1562 '(0 mdw-number-face))
1564 ;; And anything else is punctuation.
1565 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1566 '(0 mdw-punct-face)))))
1568 (mdw-post-config-mode-hack))
1570 ;;;--------------------------------------------------------------------------
1571 ;;; Perl programming style.
1573 ;; Perl indentation style.
1575 (fset 'perl-mode 'cperl-mode)
1576 (setq cperl-indent-level 2)
1577 (setq cperl-continued-statement-offset 2)
1578 (setq cperl-continued-brace-offset 0)
1579 (setq cperl-brace-offset -2)
1580 (setq cperl-brace-imaginary-offset 0)
1581 (setq cperl-label-offset 0)
1583 ;; Define perl fontification style.
1585 (defun mdw-fontify-perl ()
1587 ;; Miscellaneous fiddling.
1588 (modify-syntax-entry ?$ "\\")
1589 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1590 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1592 ;; Now define fontification things.
1593 (make-local-variable 'font-lock-keywords)
1594 (let ((perl-keywords
1595 (mdw-regexps "and" "break" "cmp" "continue" "do" "else" "elsif" "eq"
1596 "for" "foreach" "ge" "given" "gt" "goto" "if"
1597 "last" "le" "lt" "local" "my" "ne" "next" "or"
1598 "our" "package" "redo" "require" "return" "sub"
1599 "undef" "unless" "until" "use" "when" "while")))
1601 (setq font-lock-keywords
1604 ;; Set up the keywords defined above.
1605 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1606 '(0 font-lock-keyword-face))
1608 ;; At least numbers are simpler than C.
1609 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1610 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1611 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1612 '(0 mdw-number-face))
1614 ;; And anything else is punctuation.
1615 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1616 '(0 mdw-punct-face)))))
1618 (mdw-post-config-mode-hack))
1620 (defun perl-number-tests (&optional arg)
1621 "Assign consecutive numbers to lines containing `#t'. With ARG,
1622 strip numbers instead."
1625 (goto-char (point-min))
1626 (let ((i 0) (fmt (if arg "" " %4d")))
1627 (while (search-forward "#t" nil t)
1628 (delete-region (point) (line-end-position))
1630 (insert (format fmt i)))
1631 (goto-char (point-min))
1632 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1633 (replace-match (format "\\1%d" i))))))
1635 ;;;--------------------------------------------------------------------------
1636 ;;; Python programming style.
1638 (defun mdw-fontify-pythonic (keywords)
1640 ;; Miscellaneous fiddling.
1641 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1642 (setq indent-tabs-mode nil)
1644 ;; Now define fontification things.
1645 (make-local-variable 'font-lock-keywords)
1646 (setq font-lock-keywords
1649 ;; Set up the keywords defined above.
1650 (list (concat "\\<\\(" keywords "\\)\\>")
1651 '(0 font-lock-keyword-face))
1653 ;; At least numbers are simpler than C.
1654 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1655 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1656 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1657 '(0 mdw-number-face))
1659 ;; And anything else is punctuation.
1660 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1661 '(0 mdw-punct-face))))
1663 (mdw-post-config-mode-hack))
1665 ;; Define Python fontification styles.
1667 (defun mdw-fontify-python ()
1668 (mdw-fontify-pythonic
1669 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1670 "del" "elif" "else" "except" "exec" "finally" "for"
1671 "from" "global" "if" "import" "in" "is" "lambda"
1672 "not" "or" "pass" "print" "raise" "return" "try"
1673 "while" "with" "yield")))
1675 (defun mdw-fontify-pyrex ()
1676 (mdw-fontify-pythonic
1677 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1678 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1679 "extern" "finally" "for" "from" "global" "if"
1680 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1681 "raise" "return" "struct" "try" "while" "with"
1684 ;;;--------------------------------------------------------------------------
1685 ;;; Icon programming style.
1687 ;; Icon indentation style.
1689 (setq icon-brace-offset 0
1690 icon-continued-brace-offset 0
1691 icon-continued-statement-offset 2
1692 icon-indent-level 2)
1694 ;; Define Icon fontification style.
1696 (defun mdw-fontify-icon ()
1698 ;; Miscellaneous fiddling.
1699 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1701 ;; Now define fontification things.
1702 (make-local-variable 'font-lock-keywords)
1703 (let ((icon-keywords
1704 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1705 "end" "every" "fail" "global" "if" "initial"
1706 "invocable" "link" "local" "next" "not" "of"
1707 "procedure" "record" "repeat" "return" "static"
1708 "suspend" "then" "to" "until" "while"))
1709 (preprocessor-keywords
1710 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1711 "include" "line" "undef")))
1712 (setq font-lock-keywords
1715 ;; Set up the keywords defined above.
1716 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1717 '(0 font-lock-keyword-face))
1719 ;; The things that Icon calls keywords.
1720 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1722 ;; At least numbers are simpler than C.
1723 (list (concat "\\<[0-9]+"
1724 "\\([rR][0-9a-zA-Z]+\\|"
1725 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1726 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1727 '(0 mdw-number-face))
1730 (list (concat "^[ \t]*$[ \t]*\\<\\("
1731 preprocessor-keywords
1733 '(0 font-lock-keyword-face))
1735 ;; And anything else is punctuation.
1736 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1737 '(0 mdw-punct-face)))))
1739 (mdw-post-config-mode-hack))
1741 ;;;--------------------------------------------------------------------------
1742 ;;; ARM assembler programming configuration.
1744 ;; There doesn't appear to be an Emacs mode for this yet.
1746 ;; Better do something about that, I suppose.
1748 (defvar arm-assembler-mode-map nil)
1749 (defvar arm-assembler-abbrev-table nil)
1750 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1752 (or arm-assembler-mode-map
1754 (setq arm-assembler-mode-map (make-sparse-keymap))
1755 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1756 (define-key arm-assembler-mode-map [C-return] 'newline)
1757 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1759 (defun arm-assembler-mode ()
1760 "Major mode for ARM assembler programs"
1763 ;; Do standard major mode things.
1764 (kill-all-local-variables)
1765 (use-local-map arm-assembler-mode-map)
1766 (setq local-abbrev-table arm-assembler-abbrev-table)
1767 (setq major-mode 'arm-assembler-mode)
1768 (setq mode-name "ARM assembler")
1770 ;; Set up syntax table.
1771 (set-syntax-table arm-assembler-mode-syntax-table)
1772 (modify-syntax-entry ?; ; Nasty hack
1773 "<" arm-assembler-mode-syntax-table)
1774 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1775 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1777 (make-local-variable 'comment-start)
1778 (setq comment-start ";")
1779 (make-local-variable 'comment-end)
1780 (setq comment-end "")
1781 (make-local-variable 'comment-column)
1782 (setq comment-column 48)
1783 (make-local-variable 'comment-start-skip)
1784 (setq comment-start-skip ";+[ \t]*")
1786 ;; Play with indentation.
1787 (make-local-variable 'indent-line-function)
1788 (setq indent-line-function 'indent-relative-maybe)
1791 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1793 ;; Fiddle with fontification.
1794 (make-local-variable 'font-lock-keywords)
1795 (setq font-lock-keywords
1798 ;; Handle numbers too.
1800 ;; The following isn't quite right, but it's close enough.
1803 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1805 '(0 mdw-number-face))
1807 ;; Do something about operators.
1808 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1809 '(1 font-lock-keyword-face)
1810 '(2 font-lock-string-face))
1812 '(0 font-lock-keyword-face))
1814 ;; Do menemonics and directives.
1815 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1816 '(1 font-lock-keyword-face))
1818 ;; And anything else is punctuation.
1819 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1820 '(0 mdw-punct-face)))
1822 (mdw-post-config-mode-hack))
1823 (run-hooks 'arm-assembler-mode-hook))
1825 ;;;--------------------------------------------------------------------------
1828 (defun mdw-fontify-asm ()
1829 (modify-syntax-entry ?' "\"")
1830 (modify-syntax-entry ?. "w")
1831 (setf fill-prefix nil)
1832 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1834 ;;;--------------------------------------------------------------------------
1835 ;;; TCL configuration.
1837 (defun mdw-fontify-tcl ()
1838 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1839 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1840 (make-local-variable 'font-lock-keywords)
1841 (setq font-lock-keywords
1843 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1844 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1845 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1846 '(0 mdw-number-face))
1847 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1848 '(0 mdw-punct-face))))
1849 (mdw-post-config-mode-hack))
1851 ;;;--------------------------------------------------------------------------
1852 ;;; REXX configuration.
1854 (defun mdw-rexx-electric-* ()
1859 (defun mdw-rexx-indent-newline-indent ()
1862 (if abbrev-mode (expand-abbrev))
1863 (newline-and-indent))
1865 (defun mdw-fontify-rexx ()
1867 ;; Various bits of fiddling.
1868 (setq mdw-auto-indent nil)
1869 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1870 (local-set-key [?*] 'mdw-rexx-electric-*)
1871 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1873 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1875 ;; Set up keywords and things for fontification.
1876 (make-local-variable 'font-lock-keywords-case-fold-search)
1877 (setq font-lock-keywords-case-fold-search t)
1879 (setq rexx-indent 2)
1880 (setq rexx-end-indent rexx-indent)
1881 (setq rexx-cont-indent rexx-indent)
1883 (make-local-variable 'font-lock-keywords)
1884 (let ((rexx-keywords
1885 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1886 "else" "end" "engineering" "exit" "expose" "for"
1887 "forever" "form" "fuzz" "if" "interpret" "iterate"
1888 "leave" "linein" "name" "nop" "numeric" "off" "on"
1889 "options" "otherwise" "parse" "procedure" "pull"
1890 "push" "queue" "return" "say" "select" "signal"
1891 "scientific" "source" "then" "trace" "to" "until"
1892 "upper" "value" "var" "version" "when" "while"
1895 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1896 "center" "center" "charin" "charout" "chars"
1897 "compare" "condition" "copies" "c2d" "c2x"
1898 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1899 "errortext" "format" "fuzz" "insert" "lastpos"
1900 "left" "length" "lineout" "lines" "max" "min"
1901 "overlay" "pos" "queued" "random" "reverse" "right"
1902 "sign" "sourceline" "space" "stream" "strip"
1903 "substr" "subword" "symbol" "time" "translate"
1904 "trunc" "value" "verify" "word" "wordindex"
1905 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1908 (setq font-lock-keywords
1911 ;; Set up the keywords defined above.
1912 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1913 '(0 font-lock-keyword-face))
1915 ;; Fontify all symbols the same way.
1916 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1917 "[A-Za-z0-9.!?_#@$]+\\)")
1918 '(0 font-lock-variable-name-face))
1920 ;; And everything else is punctuation.
1921 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1922 '(0 mdw-punct-face)))))
1924 (mdw-post-config-mode-hack))
1926 ;;;--------------------------------------------------------------------------
1927 ;;; Standard ML programming style.
1929 (defun mdw-fontify-sml ()
1931 ;; Make underscore an honorary letter.
1932 (modify-syntax-entry ?' "w")
1935 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1937 ;; Now define fontification things.
1938 (make-local-variable 'font-lock-keywords)
1940 (mdw-regexps "abstype" "and" "andalso" "as"
1943 "else" "end" "eqtype" "exception"
1944 "fn" "fun" "functor"
1946 "if" "in" "include" "infix" "infixr"
1949 "of" "op" "open" "orelse"
1951 "sharing" "sig" "signature" "struct" "structure"
1954 "where" "while" "with" "withtype")))
1956 (setq font-lock-keywords
1959 ;; Set up the keywords defined above.
1960 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1961 '(0 font-lock-keyword-face))
1963 ;; At least numbers are simpler than C.
1964 (list (concat "\\<\\(\\~\\|\\)"
1965 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1967 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1968 "\\([eE]\\(\\~\\|\\)"
1969 "[0-9]+\\|\\)\\)\\)")
1970 '(0 mdw-number-face))
1972 ;; And anything else is punctuation.
1973 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1974 '(0 mdw-punct-face)))))
1976 (mdw-post-config-mode-hack))
1978 ;;;--------------------------------------------------------------------------
1979 ;;; Haskell configuration.
1981 (defun mdw-fontify-haskell ()
1983 ;; Fiddle with syntax table to get comments right.
1984 (modify-syntax-entry ?' "\"")
1985 (modify-syntax-entry ?- ". 123")
1986 (modify-syntax-entry ?{ ". 1b")
1987 (modify-syntax-entry ?} ". 4b")
1988 (modify-syntax-entry ?\n ">")
1991 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1993 ;; Fiddle with fontification.
1994 (make-local-variable 'font-lock-keywords)
1995 (let ((haskell-keywords
1996 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1997 "deriving" "do" "else" "foreign" "hiding" "if"
1998 "import" "in" "infix" "infixl" "infixr" "instance"
1999 "let" "module" "newtype" "of" "qualified" "safe"
2000 "stdcall" "then" "type" "unsafe" "where")))
2002 (setq font-lock-keywords
2005 '(0 font-lock-comment-face))
2006 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
2007 '(0 font-lock-keyword-face))
2008 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2009 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
2010 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
2011 '(0 mdw-number-face))
2012 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2013 '(0 mdw-punct-face)))))
2015 (mdw-post-config-mode-hack))
2017 ;;;--------------------------------------------------------------------------
2018 ;;; Erlang configuration.
2020 (setq erlang-electric-commands nil)
2022 (defun mdw-fontify-erlang ()
2025 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
2027 ;; Fiddle with fontification.
2028 (make-local-variable 'font-lock-keywords)
2029 (let ((erlang-keywords
2030 (mdw-regexps "after" "and" "andalso"
2031 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
2032 "case" "catch" "cond"
2033 "div" "end" "fun" "if" "let" "not"
2035 "query" "receive" "rem" "try" "when" "xor")))
2037 (setq font-lock-keywords
2040 '(0 font-lock-comment-face))
2041 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
2042 '(0 font-lock-keyword-face))
2043 (list (concat "^-\\sw+\\>")
2044 '(0 font-lock-keyword-face))
2045 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
2046 '(0 mdw-number-face))
2047 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2048 '(0 mdw-punct-face)))))
2050 (mdw-post-config-mode-hack))
2052 ;;;--------------------------------------------------------------------------
2053 ;;; Texinfo configuration.
2055 (defun mdw-fontify-texinfo ()
2058 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
2060 ;; Real fontification things.
2061 (make-local-variable 'font-lock-keywords)
2062 (setq font-lock-keywords
2065 ;; Environment names are keywords.
2066 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
2067 '(2 font-lock-keyword-face))
2069 ;; Unmark escaped magic characters.
2070 (list "\\(@\\)\\([@{}]\\)"
2071 '(1 font-lock-keyword-face)
2072 '(2 font-lock-variable-name-face))
2074 ;; Make sure we get comments properly.
2075 (list "@c\\(\\|omment\\)\\( .*\\)?$"
2076 '(0 font-lock-comment-face))
2078 ;; Command names are keywords.
2079 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2080 '(0 font-lock-keyword-face))
2082 ;; Fontify TeX special characters as punctuation.
2084 '(0 mdw-punct-face))))
2086 (mdw-post-config-mode-hack))
2088 ;;;--------------------------------------------------------------------------
2089 ;;; TeX and LaTeX configuration.
2091 (defun mdw-fontify-tex ()
2092 (setq ispell-parser 'tex)
2095 ;; Don't make maths into a string.
2096 (modify-syntax-entry ?$ ".")
2097 (modify-syntax-entry ?$ "." font-lock-syntax-table)
2098 (local-set-key [?$] 'self-insert-command)
2101 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
2103 ;; Real fontification things.
2104 (make-local-variable 'font-lock-keywords)
2105 (setq font-lock-keywords
2108 ;; Environment names are keywords.
2109 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
2111 '(2 font-lock-keyword-face))
2113 ;; Suspended environment names are keywords too.
2114 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
2116 '(3 font-lock-keyword-face))
2118 ;; Command names are keywords.
2119 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2120 '(0 font-lock-keyword-face))
2122 ;; Handle @/.../ for italics.
2123 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
2124 ;; '(1 font-lock-keyword-face)
2125 ;; '(3 font-lock-keyword-face))
2127 ;; Handle @*...* for boldness.
2128 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
2129 ;; '(1 font-lock-keyword-face)
2130 ;; '(3 font-lock-keyword-face))
2132 ;; Handle @`...' for literal syntax things.
2133 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
2134 ;; '(1 font-lock-keyword-face)
2135 ;; '(3 font-lock-keyword-face))
2137 ;; Handle @<...> for nonterminals.
2138 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
2139 ;; '(1 font-lock-keyword-face)
2140 ;; '(3 font-lock-keyword-face))
2142 ;; Handle other @-commands.
2143 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
2144 ;; '(0 font-lock-keyword-face))
2146 ;; Make sure we get comments properly.
2148 '(0 font-lock-comment-face))
2150 ;; Fontify TeX special characters as punctuation.
2152 '(0 mdw-punct-face))))
2154 (mdw-post-config-mode-hack))
2156 ;;;--------------------------------------------------------------------------
2159 (defun mdw-sgml-mode ()
2162 (mdw-standard-fill-prefix "")
2163 (make-local-variable 'sgml-delimiters)
2164 (setq sgml-delimiters
2165 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2166 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2167 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2168 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2169 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2170 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2171 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2173 (setq major-mode 'mdw-sgml-mode)
2174 (setq mode-name "[mdw] SGML")
2175 (run-hooks 'mdw-sgml-mode-hook))
2177 ;;;--------------------------------------------------------------------------
2180 (defun mdw-setup-sh-script-mode ()
2182 ;; Fetch the shell interpreter's name.
2183 (let ((shell-name sh-shell-file))
2185 ;; Try reading the hash-bang line.
2187 (goto-char (point-min))
2188 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2189 (setq shell-name (match-string 1))))
2191 ;; Now try to set the shell.
2193 ;; Don't let `sh-set-shell' bugger up my script.
2194 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2195 (sh-set-shell shell-name)))
2197 ;; Now enable my keys and the fontification.
2198 (mdw-misc-mode-config)
2200 ;; Set the indentation level correctly.
2201 (setq sh-indentation 2)
2202 (setq sh-basic-offset 2))
2204 (setq sh-shell-file "/bin/sh")
2206 ;;;--------------------------------------------------------------------------
2207 ;;; Emacs shell mode.
2209 (defun mdw-eshell-prompt ()
2210 (let ((left "[") (right "]"))
2211 (when (= (user-uid) 0)
2212 (setq left "«" right "»"))
2215 (replace-regexp-in-string "\\..*$" "" (system-name)))
2217 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
2218 (home (expand-file-name "~")) (nhome (length home)))
2219 (if (and (>= npwd nhome)
2221 (= (elt pwd nhome) ?/))
2222 (string= (substring pwd 0 nhome) home))
2223 (concat "~" (substring pwd (length home)))
2226 (setq eshell-prompt-function 'mdw-eshell-prompt)
2227 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
2229 (defun eshell/e (file) (find-file file) nil)
2230 (defun eshell/ee (file) (find-file-other-window file) nil)
2231 (defun eshell/w3m (url) (w3m-goto-url url) nil)
2233 (mdw-define-face eshell-prompt (t :weight bold))
2234 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2235 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2236 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2237 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2238 (mdw-define-face eshell-ls-executable (t :weight bold))
2239 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2240 (mdw-define-face eshell-ls-readonly (t nil))
2241 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2243 ;;;--------------------------------------------------------------------------
2244 ;;; Messages-file mode.
2246 (defun messages-mode-guts ()
2247 (setq messages-mode-syntax-table (make-syntax-table))
2248 (set-syntax-table messages-mode-syntax-table)
2249 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2250 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2251 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2252 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2253 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2254 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2255 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2256 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2257 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2258 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2259 (make-local-variable 'comment-start)
2260 (make-local-variable 'comment-end)
2261 (make-local-variable 'indent-line-function)
2262 (setq indent-line-function 'indent-relative)
2263 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2264 (make-local-variable 'font-lock-defaults)
2265 (make-local-variable 'messages-mode-keywords)
2267 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2268 "export" "enum" "fixed-octetstring" "flags"
2269 "harmless" "map" "nested" "optional"
2270 "optional-tagged" "package" "primitive"
2271 "primitive-nullfree" "relaxed[ \t]+enum"
2272 "set" "table" "tagged-optional" "union"
2273 "variadic" "vector" "version" "version-tag")))
2274 (setq messages-mode-keywords
2276 (list (concat "\\<\\(" keywords "\\)\\>:")
2277 '(0 font-lock-keyword-face))
2278 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2279 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2280 (0 font-lock-variable-name-face))
2281 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2282 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2283 (0 mdw-punct-face)))))
2284 (setq font-lock-defaults
2285 '(messages-mode-keywords nil nil nil nil))
2286 (run-hooks 'messages-file-hook))
2288 (defun messages-mode ()
2291 (setq major-mode 'messages-mode)
2292 (setq mode-name "Messages")
2293 (messages-mode-guts)
2294 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2295 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2296 (setq comment-start "# ")
2297 (setq comment-end "")
2298 (run-hooks 'messages-mode-hook))
2300 (defun cpp-messages-mode ()
2303 (setq major-mode 'cpp-messages-mode)
2304 (setq mode-name "CPP Messages")
2305 (messages-mode-guts)
2306 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2307 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2308 (setq comment-start "/* ")
2309 (setq comment-end " */")
2310 (let ((preprocessor-keywords
2311 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2312 "ident" "if" "ifdef" "ifndef" "import" "include"
2313 "line" "pragma" "unassert" "undef" "warning")))
2314 (setq messages-mode-keywords
2315 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2316 "\\(include\\|import\\)"
2317 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2318 '(2 font-lock-string-face))
2319 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2320 preprocessor-keywords
2321 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2322 '(1 font-lock-keyword-face)))
2323 messages-mode-keywords)))
2324 (run-hooks 'cpp-messages-mode-hook))
2326 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2327 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2328 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2330 ;;;--------------------------------------------------------------------------
2331 ;;; Messages-file mode.
2333 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2334 "Face to use for subsittution directives.")
2335 (make-face 'mallow-driver-substitution-face)
2336 (defvar mallow-driver-text-face 'mallow-driver-text-face
2337 "Face to use for body text.")
2338 (make-face 'mallow-driver-text-face)
2340 (defun mallow-driver-mode ()
2343 (setq major-mode 'mallow-driver-mode)
2344 (setq mode-name "Mallow driver")
2345 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2346 (set-syntax-table mallow-driver-mode-syntax-table)
2347 (make-local-variable 'comment-start)
2348 (make-local-variable 'comment-end)
2349 (make-local-variable 'indent-line-function)
2350 (setq indent-line-function 'indent-relative)
2351 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2352 (make-local-variable 'font-lock-defaults)
2353 (make-local-variable 'mallow-driver-mode-keywords)
2355 (mdw-regexps "each" "divert" "file" "if"
2356 "perl" "set" "string" "type" "write")))
2357 (setq mallow-driver-mode-keywords
2359 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2360 '(0 font-lock-keyword-face))
2361 (list "^%\\s *\\(#.*\\|\\)$"
2362 '(0 font-lock-comment-face))
2364 '(0 font-lock-keyword-face))
2365 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2367 '(0 mallow-driver-substitution-face t)))))
2368 (setq font-lock-defaults
2369 '(mallow-driver-mode-keywords nil nil nil nil))
2370 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2371 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2372 (setq comment-start "%# ")
2373 (setq comment-end "")
2374 (run-hooks 'mallow-driver-mode-hook))
2376 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2378 ;;;--------------------------------------------------------------------------
2381 (defun nfast-debug-mode ()
2384 (setq major-mode 'nfast-debug-mode)
2385 (setq mode-name "NFast debug")
2386 (setq messages-mode-syntax-table (make-syntax-table))
2387 (set-syntax-table messages-mode-syntax-table)
2388 (make-local-variable 'font-lock-defaults)
2389 (make-local-variable 'nfast-debug-mode-keywords)
2390 (setq truncate-lines t)
2391 (setq nfast-debug-mode-keywords
2393 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2394 (0 font-lock-keyword-face))
2395 (list (concat "^[ \t]+\\(\\("
2396 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2397 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2399 "[0-9a-fA-F]+\\)[ \t]*$")
2400 '(0 mdw-number-face))
2401 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2402 (1 font-lock-keyword-face))
2403 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2404 (1 font-lock-warning-face))
2405 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2407 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2408 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2409 '(1 font-lock-keyword-face))
2410 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2411 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2412 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2413 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2414 (setq font-lock-defaults
2415 '(nfast-debug-mode-keywords nil nil nil nil))
2416 (run-hooks 'nfast-debug-mode-hook))
2418 ;;;--------------------------------------------------------------------------
2419 ;;; Other languages.
2423 (defun mdw-setup-smalltalk ()
2424 (and mdw-auto-indent
2425 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2426 (make-local-variable 'mdw-auto-indent)
2427 (setq mdw-auto-indent nil)
2428 (local-set-key "\C-i" 'smalltalk-reindent))
2430 (defun mdw-fontify-smalltalk ()
2431 (make-local-variable 'font-lock-keywords)
2432 (setq font-lock-keywords
2434 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2435 '(0 font-lock-keyword-face))
2436 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2437 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2438 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2439 '(0 mdw-number-face))
2440 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2441 '(0 mdw-punct-face))))
2442 (mdw-post-config-mode-hack))
2446 ;; Unpleasant bodge.
2447 (unless (boundp 'slime-repl-mode-map)
2448 (setq slime-repl-mode-map (make-sparse-keymap)))
2450 (defun mdw-indent-newline-and-indent ()
2452 (indent-for-tab-command)
2453 (newline-and-indent))
2455 (eval-after-load "cl-indent"
2457 (mapc #'(lambda (pair)
2459 'common-lisp-indent-function
2461 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2462 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2464 (defun mdw-common-lisp-indent ()
2465 (make-local-variable 'lisp-indent-function)
2466 (setq lisp-indent-function 'common-lisp-indent-function))
2468 (setq lisp-simple-loop-indentation 2
2469 lisp-loop-keyword-indentation 6
2470 lisp-loop-forms-indentation 6)
2472 (defun mdw-fontify-lispy ()
2475 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2477 ;; Not much fontification needed.
2478 (make-local-variable 'font-lock-keywords)
2479 (setq font-lock-keywords
2481 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2482 '(0 mdw-punct-face))))
2484 (mdw-post-config-mode-hack))
2486 (defun comint-send-and-indent ()
2489 (and mdw-auto-indent
2490 (indent-for-tab-command)))
2492 (defun mdw-setup-m4 ()
2493 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2495 ;;;--------------------------------------------------------------------------
2498 (defun mdw-text-mode ()
2499 (setq fill-column 72)
2501 (mdw-standard-fill-prefix
2502 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2505 ;;;--------------------------------------------------------------------------
2506 ;;; Outline and hide/show modes.
2508 (defun mdw-outline-collapse-all ()
2509 "Completely collapse everything in the entire buffer."
2512 (goto-char (point-min))
2513 (while (< (point) (point-max))
2517 (setq hs-hide-comments-when-hiding-all nil)
2519 (defadvice hs-hide-all (after hide-first-comment activate)
2520 (save-excursion (hs-hide-initial-comment-block)))
2522 ;;;--------------------------------------------------------------------------
2525 (defun mdw-sh-mode-setup ()
2526 (local-set-key [?\C-a] 'comint-bol)
2527 (add-hook 'comint-output-filter-functions
2528 'comint-watch-for-password-prompt))
2530 (defun mdw-term-mode-setup ()
2531 (setq term-prompt-regexp shell-prompt-pattern)
2532 (make-local-variable 'mouse-yank-at-point)
2533 (make-local-variable 'transient-mark-mode)
2534 (setq mouse-yank-at-point t)
2538 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2539 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2540 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2541 (defun term-send-meta-meta-something ()
2543 (term-send-raw-string "\e\e")
2545 (eval-after-load 'term
2547 (define-key term-raw-map [?\e ?\e] nil)
2548 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2549 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2550 (define-key term-raw-map [M-right] 'term-send-meta-right)
2551 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2552 (define-key term-raw-map [M-left] 'term-send-meta-left)
2553 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2555 (defadvice term-exec (before program-args-list compile activate)
2556 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
2557 This allows you to pass a list of arguments through `ansi-term'."
2558 (let ((program (ad-get-arg 2)))
2561 (ad-set-arg 2 (car program))
2562 (ad-set-arg 4 (cdr program))))))
2565 "Open a terminal containing an ssh session to the HOST."
2566 (interactive "sHost: ")
2567 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
2569 ;;;--------------------------------------------------------------------------
2570 ;;; Inferior Emacs Lisp.
2572 (setq comint-prompt-read-only t)
2574 (eval-after-load "comint"
2576 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2577 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2579 (eval-after-load "ielm"
2581 (define-key ielm-map "\C-w" 'comint-kill-region)
2582 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2584 ;;;----- That's all, folks --------------------------------------------------
2586 (provide 'dot-emacs)