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))
56 "This is not the key sequence you're looking for."
58 (error "wrong button"))
60 (defun mdw-emacs-version-p (major &optional minor)
61 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
62 (or (> emacs-major-version major)
63 (and (= emacs-major-version major)
64 (>= emacs-minor-version (or minor 0)))))
66 ;; Some error trapping.
68 ;; If individual bits of this file go tits-up, we don't particularly want
69 ;; the whole lot to stop right there and then, because it's bloody annoying.
71 (defmacro trap (&rest forms)
72 "Execute FORMS without allowing errors to propagate outside."
76 ,(if (cdr forms) (cons 'progn forms) (car forms))
77 (error (message "Error (trapped): %s in %s"
78 (error-message-string err)
81 ;; Configuration reading.
83 (defvar mdw-config nil)
84 (defun mdw-config (sym)
85 "Read the configuration variable named SYM."
88 (flet ((replace (what with)
89 (goto-char (point-min))
90 (while (re-search-forward what nil t)
91 (replace-match with t))))
93 (insert-file-contents "~/.mdw.conf")
94 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
95 (replace (concat "^[ \t]*"
96 "\\([-a-zA-Z0-9_.]*\\)"
99 "[ \t]**\\(\n\\|$\\)")
101 (car (read-from-string
102 (concat "(" (buffer-string) ")")))))))
103 (cdr (assq sym mdw-config)))
105 ;; Width configuration.
107 (defvar mdw-column-width
108 (string-to-number (or (mdw-config 'emacs-width) "77"))
109 "Width of Emacs columns.")
110 (defvar mdw-text-width mdw-column-width
111 "Expected width of text within columns.")
112 (put 'mdw-text-width 'safe-local-variable 'integerp)
114 ;; Local variables hacking.
116 (defun run-local-vars-mode-hook ()
117 "Run a hook for the major-mode after local variables have been processed."
118 (run-hooks (intern (concat (symbol-name major-mode)
119 "-local-variables-hook"))))
120 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
122 ;; Set up the load path convincingly.
124 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
125 (list (concat "/usr/share/"
126 (symbol-name debian-emacs-flavor)
128 (dolist (sub (directory-files dir t))
129 (when (and (file-accessible-directory-p sub)
130 (not (member sub load-path)))
131 (setq load-path (nconc load-path (list sub))))))
133 ;; Is an Emacs library available?
135 (defun library-exists-p (name)
136 "Return non-nil if NAME is an available library.
137 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
138 load path. The non-nil value is the filename we found for the
140 (let ((path load-path) elt (foundp nil))
141 (while (and path (not foundp))
142 (setq elt (car path))
143 (setq path (cdr path))
144 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
145 (and (file-exists-p file) file))
146 (let ((file (concat elt "/" name ".el")))
147 (and (file-exists-p file) file)))))
150 (defun maybe-autoload (symbol file &optional docstring interactivep type)
151 "Set an autoload if the file actually exists."
152 (and (library-exists-p file)
153 (autoload symbol file docstring interactivep type)))
155 (defun mdw-kick-menu-bar (&optional frame)
156 "Regenerate FRAME's menu bar so it doesn't have empty menus."
158 (unless frame (setq frame (selected-frame)))
159 (let ((old (frame-parameter frame 'menu-bar-lines)))
160 (set-frame-parameter frame 'menu-bar-lines 0)
161 (set-frame-parameter frame 'menu-bar-lines old)))
163 ;; Splitting windows.
165 (unless (fboundp 'scroll-bar-columns)
166 (defun scroll-bar-columns (side)
167 (cond ((eq side 'left) 0)
170 (unless (fboundp 'fringe-columns)
171 (defun fringe-columns (side)
172 (cond ((not window-system) 0)
176 (defun mdw-horizontal-window-overhead ()
177 "Computes the horizontal window overhead.
178 This is the number of columns used by fringes, scroll bars and other such
180 (if (not window-system)
183 (dolist (what '(scroll-bar fringe))
184 (dolist (side '(left right))
185 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
189 (defun mdw-split-window-horizontally (&optional width)
190 "Split a window horizontally.
191 Without a numeric argument, split the window approximately in
192 half. With a numeric argument WIDTH, allocate WIDTH columns to
193 the left-hand window (if positive) or -WIDTH columns to the
194 right-hand window (if negative). Space for scroll bars and
195 fringes is not taken out of the allowance for WIDTH, unlike
196 \\[split-window-horizontally]."
198 (split-window-horizontally
199 (cond ((null width) nil)
200 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
201 ((< width 0) width))))
203 (defun mdw-divvy-window (&optional width)
204 "Split a wide window into appropriate widths."
206 (setq width (cond (width (prefix-numeric-value width))
207 ((and window-system (mdw-emacs-version-p 22))
209 (t (1+ mdw-column-width))))
210 (let* ((win (selected-window))
211 (sb-width (mdw-horizontal-window-overhead))
212 (c (/ (+ (window-width) sb-width)
213 (+ width sb-width))))
216 (split-window-horizontally (+ width sb-width))
218 (select-window win)))
220 ;; Don't raise windows unless I say so.
222 (defvar mdw-inhibit-raise-frame nil
223 "*Whether `raise-frame' should do nothing when the frame is mapped.")
225 (defadvice raise-frame
226 (around mdw-inhibit (&optional frame) activate compile)
227 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
228 frame is actually mapped on the screen."
229 (if mdw-inhibit-raise-frame
230 (make-frame-visible frame)
233 (defmacro mdw-advise-to-inhibit-raise-frame (function)
234 "Advise the FUNCTION not to raise frames, even if it wants to."
235 `(defadvice ,function
236 (around mdw-inhibit-raise (&rest hunoz) activate compile)
237 "Don't raise the window unless you have to."
238 (let ((mdw-inhibit-raise-frame t))
241 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
242 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
244 ;; Bug fix for markdown-mode, which breaks point positioning during
246 (defadvice markdown-check-change-for-wiki-link
247 (around mdw-save-match activate compile)
248 "Save match data around the `markdown-mode' `after-change-functions' hook."
249 (save-match-data ad-do-it))
251 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
252 ;; always returns nil, with the result that all email addresses are lost.
253 ;; Replace the function entirely.
254 (defadvice bbdb-canonicalize-address
255 (around mdw-bug-fix activate compile)
256 "Don't use `run-hook-with-args', because that doesn't work."
257 (let ((net (ad-get-arg 0)))
259 ;; Make sure this is a proper hook list.
260 (if (functionp bbdb-canonicalize-net-hook)
261 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
263 ;; Iterate over the hooks until things converge.
266 (let (next (changep nil)
267 hook (hooks bbdb-canonicalize-net-hook))
269 (setq hook (pop hooks))
270 (setq next (funcall hook net))
271 (if (not (equal next net))
274 (setq donep (not changep)))))
275 (setq ad-return-value net)))
277 ;; Transient mark mode hacks.
279 (defadvice exchange-point-and-mark
280 (around mdw-highlight (&optional arg) activate compile)
281 "Maybe don't actually exchange point and mark.
282 If `transient-mark-mode' is on and the mark is inactive, then
283 just activate it. A non-trivial prefix argument will force the
284 usual behaviour. A trivial prefix argument (i.e., just C-u) will
285 activate the mark and temporarily enable `transient-mark-mode' if
287 (cond ((or mark-active
288 (and (not transient-mark-mode) (not arg))
289 (and arg (or (not (consp arg))
290 (not (= (car arg) 4)))))
293 (or transient-mark-mode (setq transient-mark-mode 'only))
294 (set-mark (mark t)))))
296 ;; Functions for sexp diary entries.
298 (defun mdw-not-org-mode (form)
299 "As FORM, but not in Org mode agenda."
300 (and (not mdw-diary-for-org-mode-p)
303 (defun mdw-weekday (l)
304 "Return non-nil if `date' falls on one of the days of the week in L.
305 L is a list of day numbers (from 0 to 6 for Sunday through to
306 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
307 the date stored in `date' falls on a listed day, then the
308 function returns non-nil."
309 (let ((d (calendar-day-of-week date)))
311 (memq (nth d '(sunday monday tuesday wednesday
312 thursday friday saturday)) l))))
314 (defun mdw-discordian-date (date)
315 "Return the Discordian calendar date corresponding to DATE.
317 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
319 The original is by David Pearson. I modified it to produce date components
320 as output rather than a string."
321 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
322 "Prickle-Prickle" "Setting Orange"])
323 (months ["Chaos" "Discord" "Confusion"
324 "Bureaucracy" "Aftermath"])
325 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
326 (year (- (extract-calendar-year date) 1900))
327 (month (1- (extract-calendar-month date)))
328 (day (1- (extract-calendar-day date)))
329 (julian (+ (aref day-count month) day))
330 (dyear (+ year 3066)))
331 (if (and (= month 1) (= day 28))
332 (cons dyear 'st-tibs-day)
334 (aref months (floor (/ julian 73)))
336 (aref days (mod julian 5))))))
338 (defun mdw-diary-discordian-date ()
339 "Convert the date in `date' to a string giving the Discordian date."
340 (let* ((ddate (mdw-discordian-date date))
341 (tail (format "in the YOLD %d" (car ddate))))
342 (if (eq (cdr ddate) 'st-tibs-day)
343 (format "St Tib's Day %s" tail)
344 (let ((season (cadr ddate))
345 (daynum (caddr ddate))
346 (dayname (cadddr ddate)))
347 (format "%s, the %d%s day of %s %s"
350 (let ((ldig (mod daynum 10)))
351 (cond ((= ldig 1) "st")
358 (defun mdw-todo (&optional when)
359 "Return non-nil today, or on WHEN, whichever is later."
360 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
361 (d (calendar-absolute-from-gregorian date)))
363 (setq w (max w (calendar-absolute-from-gregorian
365 ((not european-calendar-style)
377 (defvar mdw-diary-for-org-mode-p nil)
379 (defadvice org-agenda-list (around mdw-preserve-links activate)
380 (let ((mdw-diary-for-org-mode-p t))
383 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
384 "Trim leading space from the diary entry string."
386 (let ((str (ad-get-arg 1))
390 (setq str (cond ((null str) nil)
391 ((string-match "\\(^\\|\n\\)[ \t]+" str)
392 (replace-match "\\1" nil nil str))
393 ((and mdw-diary-for-org-mode-p
394 (string-match (concat
396 "\\(" diary-time-regexp
397 "\\(-" diary-time-regexp "\\)?"
399 "\\(\t[ \t]*\\| [ \t]+\\)")
401 (replace-match "\\1\\2 " nil nil str))
402 ((and (not mdw-diary-for-org-mode-p)
403 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
405 (replace-match "\\1" nil nil str))
407 (if (equal str old) (setq done t)))
408 (ad-set-arg 1 str))))
410 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
411 "Return a string rather than a list."
414 (dolist (e (let ((ee ad-return-value))
415 (if (atom ee) (list ee) ee)))
417 (when anyp (insert ?\n))
420 (setq ad-return-value
421 (and anyp (buffer-string))))))
423 ;; Fighting with Org-mode's evil key maps.
425 (defvar mdw-evil-keymap-keys
426 '(([S-up] . [?\C-c up])
427 ([S-down] . [?\C-c down])
428 ([S-left] . [?\C-c left])
429 ([S-right] . [?\C-c right])
430 (([M-up] [?\e up]) . [C-up])
431 (([M-down] [?\e down]) . [C-down])
432 (([M-left] [?\e left]) . [C-left])
433 (([M-right] [?\e right]) . [C-right]))
434 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
435 The value is an alist mapping evil keys (as a list, or singleton)
436 to good keys (in the same form).")
438 (defun mdw-clobber-evil-keymap (keymap)
439 "Replace evil key bindings in the KEYMAP.
440 Evil key bindings are defined in `mdw-evil-keymap-keys'."
441 (dolist (entry mdw-evil-keymap-keys)
443 (keys (if (listp (car entry))
446 (replacements (if (listp (cdr entry))
448 (list (cdr entry)))))
451 (setq binding (lookup-key keymap key))
453 (throw 'found nil))))
456 (define-key keymap key nil))
457 (dolist (key replacements)
458 (define-key keymap key binding))))))
460 (eval-after-load "org-latex"
463 "\\documentclass{strayman}
464 \\usepackage[utf8]{inputenc}
465 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
466 \\usepackage[T1]{fontenc}
467 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
468 ("\\section{%s}" . "\\section*{%s}")
469 ("\\subsection{%s}" . "\\subsection*{%s}")
470 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
471 ("\\paragraph{%s}" . "\\paragraph*{%s}")
472 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
473 org-export-latex-classes)))
475 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
476 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
477 org-export-docbook-xslt-stylesheet
478 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
480 ;; Some hacks to do with window placement.
482 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
483 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
484 (interactive "bBuffer: ")
485 (let ((home-frame (selected-frame))
486 (buffer (get-buffer buffer-or-name))
487 (safe-buffer (get-buffer "*scratch*")))
488 (mapc (lambda (frame)
489 (or (eq frame home-frame)
490 (mapc (lambda (window)
491 (and (eq (window-buffer window) buffer)
492 (set-window-buffer window safe-buffer)))
493 (window-list frame))))
496 (defvar mdw-inhibit-walk-windows nil
497 "If non-nil, then `walk-windows' does nothing.
498 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
499 buffers in random frames.")
501 (defadvice walk-windows (around mdw-inhibit activate)
502 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
503 (and (not mdw-inhibit-walk-windows)
506 (defadvice switch-to-buffer-other-frame
507 (around mdw-always-new-frame activate)
508 "Always make a new frame.
509 Even if an existing window in some random frame looks tempting."
510 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
512 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
513 "Don't try to do anything fancy with other frames.
514 Pretend they don't exist. They might be on other display devices."
517 ;;;--------------------------------------------------------------------------
518 ;;; Mail and news hacking.
520 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
521 "Major mode for editing news and mail messages from external programs.
522 Not much right now. Just support for doing MailCrypt stuff."
525 (run-hooks 'mail-setup-hook))
527 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
529 (add-hook 'mdwail-mode-hook
531 (set-buffer-file-coding-system 'utf-8)
532 (make-local-variable 'paragraph-separate)
533 (make-local-variable 'paragraph-start)
534 (setq paragraph-start
535 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
537 (setq paragraph-separate
538 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
539 paragraph-separate))))
541 ;; How to encrypt in mdwmail.
543 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
545 (setq start (save-excursion
546 (goto-char (point-min))
547 (or (search-forward "\n\n" nil t) (point-min)))))
549 (setq end (point-max)))
550 (mc-encrypt-generic recip scm start end from sign))
552 ;; How to sign in mdwmail.
554 (defun mdwmail-mc-sign (key scm start end uclr)
556 (setq start (save-excursion
557 (goto-char (point-min))
558 (or (search-forward "\n\n" nil t) (point-min)))))
560 (setq end (point-max)))
561 (mc-sign-generic key scm start end uclr))
563 ;; Some signature mangling.
565 (defun mdwmail-mangle-signature ()
567 (goto-char (point-min))
568 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
569 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
570 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
572 ;; Insert my login name into message-ids, so I can score replies.
574 (defadvice message-unique-id (after mdw-user-name last activate compile)
575 "Ensure that the user's name appears at the end of the message-id string,
576 so that it can be used for convenient filtering."
577 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
579 ;; Tell my movemail hack where movemail is.
581 ;; This is needed to shup up warnings about LD_PRELOAD.
583 (let ((path exec-path))
585 (let ((try (expand-file-name "movemail" (car path))))
586 (if (file-executable-p try)
587 (setenv "REAL_MOVEMAIL" try))
588 (setq path (cdr path)))))
590 ;; AUTHINFO GENERIC kludge.
592 (defvar nntp-authinfo-generic nil
593 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
595 Use this to arrange for per-server settings.")
597 (defun nntp-open-authinfo-kludge (buffer)
598 "Open a connection to SERVER using `authinfo-kludge'."
599 (let ((proc (start-process "nntpd" buffer
600 "env" (concat "NNTPAUTH="
601 (or nntp-authinfo-generic
603 (error "NNTPAUTH unset")))
604 "authinfo-kludge" nntp-address)))
606 (nntp-wait-for-string "^\r*200")
608 (delete-region (point-min) (point))
611 (eval-after-load "erc"
612 '(load "~/.ercrc.el"))
614 ;;;--------------------------------------------------------------------------
615 ;;; Utility functions.
617 (or (fboundp 'line-number-at-pos)
618 (defun line-number-at-pos (&optional pos)
619 (let ((opoint (or pos (point))) start)
622 (goto-char (point-min))
628 (1+ (count-lines 1 (point))))))))
630 (defun mdw-uniquify-alist (&rest alists)
631 "Return the concatenation of the ALISTS with duplicate elements removed.
632 The first association with a given key prevails; others are
633 ignored. The input lists are not modified, although they'll
634 probably become garbage."
636 (let ((start-list (cons nil nil)))
637 (mdw-do-uniquify start-list
642 (defun mdw-do-uniquify (done end l rest)
643 "A helper function for mdw-uniquify-alist.
644 The DONE argument is a list whose first element is `nil'. It
645 contains the uniquified alist built so far. The leading `nil' is
646 stripped off at the end of the operation; it's only there so that
647 DONE always references a cons cell. END refers to the final cons
648 cell in the DONE list; it is modified in place each time to avoid
649 the overheads of `append'ing all the time. The L argument is the
650 alist we're currently processing; the remaining alists are given
653 ;; There are several different cases to deal with here.
656 ;; Current list isn't empty. Add the first item to the DONE list if
657 ;; there's not an item with the same KEY already there.
658 (l (or (assoc (car (car l)) done)
660 (setcdr end (cons (car l) nil))
661 (setq end (cdr end))))
662 (mdw-do-uniquify done end (cdr l) rest))
664 ;; The list we were working on is empty. Shunt the next list into the
665 ;; current list position and go round again.
666 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
668 ;; Everything's done. Remove the leading `nil' from the DONE list and
669 ;; return it. Finished!
673 "Insert the current date in a pleasing way."
675 (insert (save-excursion
676 (let ((buffer (get-buffer-create "*tmp*")))
677 (unwind-protect (progn (set-buffer buffer)
679 (shell-command "date +%Y-%m-%d" t)
681 (delete-backward-char 1)
683 (kill-buffer buffer))))))
685 (defun uuencode (file &optional name)
686 "UUencodes a file, maybe calling it NAME, into the current buffer."
687 (interactive "fInput file name: ")
689 ;; If NAME isn't specified, then guess from the filename.
693 (or (string-match "[^/]*$" file) 0))))
694 (print (format "uuencode `%s' `%s'" file name))
696 ;; Now actually do the thing.
697 (call-process "uuencode" file t nil name))
699 (defvar np-file "~/.np"
700 "*Where the `now-playing' file is.")
702 (defun np (&optional arg)
703 "Grabs a `now-playing' string."
707 (goto-char (point-max))
709 (insert-file-contents np-file)))))
711 (defun mdw-version-< (ver-a ver-b)
712 "Answer whether VER-A is strictly earlier than VER-B.
713 VER-A and VER-B are version numbers, which are strings containing digit
714 sequences separated by `.'."
715 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
716 (split-string ver-a "\\.")))
717 (lb (mapcar (lambda (x) (car (read-from-string x)))
718 (split-string ver-b "\\."))))
721 (cond ((null la) (throw 'done lb))
722 ((null lb) (throw 'done nil))
723 ((< (car la) (car lb)) (throw 'done t))
724 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
725 (t (throw 'done nil)))))))
727 (defun mdw-check-autorevert ()
728 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
729 This takes into consideration whether it's been found using
730 tramp, which seems to get itself into a twist."
731 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
733 ((and (buffer-file-name)
734 (fboundp 'tramp-tramp-file-p)
735 (tramp-tramp-file-p (buffer-file-name)))
736 (unless global-auto-revert-ignore-buffer
737 (setq global-auto-revert-ignore-buffer 'tramp)))
738 ((eq global-auto-revert-ignore-buffer 'tramp)
739 (setq global-auto-revert-ignore-buffer nil))))
741 (defadvice find-file (after mdw-autorevert activate)
742 (mdw-check-autorevert))
743 (defadvice write-file (after mdw-autorevert activate)
744 (mdw-check-autorevert))
746 ;;;--------------------------------------------------------------------------
749 (defadvice dired-maybe-insert-subdir
750 (around mdw-marked-insertion first activate)
751 "The DIRNAME may be a list of directory names to insert.
752 Interactively, if files are marked, then insert all of them.
753 With a numeric prefix argument, select that many entries near
754 point; with a non-numeric prefix argument, prompt for listing
757 (list (dired-get-marked-files nil
758 (and (integerp current-prefix-arg)
761 (and current-prefix-arg
762 (not (integerp current-prefix-arg))
763 (read-string "Switches for listing: "
764 (or dired-subdir-switches
765 dired-actual-switches)))))
766 (let ((dirs (ad-get-arg 0)))
767 (dolist (dir (if (listp dirs) dirs (list dirs)))
771 ;;;--------------------------------------------------------------------------
774 (defun mdw-w3m-browse-url (url &optional new-session-p)
775 "Invoke w3m on the URL in its current window, or at least a different one.
776 If NEW-SESSION-P, start a new session."
777 (interactive "sURL: \nP")
779 (let ((window (selected-window)))
782 (select-window (or (and (not new-session-p)
783 (get-buffer-window "*w3m*"))
785 (if (one-window-p t) (split-window))
787 (w3m-browse-url url new-session-p))
788 (select-window window)))))
790 (defvar mdw-good-url-browsers
793 (w3m . mdw-w3m-browse-url)
795 "List of good browsers for mdw-good-url-browsers.
796 Each item is a browser function name, or a cons (CHECK . FUNC).
797 A symbol FOO stands for (FOO . FOO).")
799 (defun mdw-good-url-browser ()
800 "Return a good URL browser.
801 Trundle the list of such things, finding the first item for which
802 CHECK is fboundp, and returning the correponding FUNC."
803 (let ((bs mdw-good-url-browsers) b check func answer)
804 (while (and bs (not answer))
808 (setq check (car b) func (cdr b))
809 (setq check b func b))
814 (eval-after-load "w3m-search"
818 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
819 ("gd" "Google Directory"
820 "http://www.google.com/search?cat=gwd/Top&q=%s")
821 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
822 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
823 ("gi" "Images" "http://images.google.com/images?q=%s")
825 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
827 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
828 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
829 ("nc-wiki" "nCipher wiki"
830 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
831 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
832 ("lp" "Launchpad bug by number"
833 "https://bugs.launchpad.net/bugs/%s")
834 ("lppkg" "Launchpad bugs by package"
835 "https://bugs.launchpad.net/%s")
837 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
838 ("debbug" "Debian bug by number"
839 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
840 ("debbugpkg" "Debian bugs by package"
841 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
842 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
843 (add-to-list 'w3m-search-engine-alist
844 (list (cadr item) (caddr item) nil))
845 (add-to-list 'w3m-uri-replace-alist
846 (list (concat "\\`" (car item) ":")
847 'w3m-search-uri-replace
850 ;;;--------------------------------------------------------------------------
851 ;;; Paragraph filling.
855 (defvar mdw-fill-prefix nil
856 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
857 If there's no fill prefix currently set (by the `fill-prefix'
858 variable) and there's a match from one of the regexps here, it
859 gets used to set the fill-prefix for the current operation.
861 The variable is a list of items of the form `REGEXP . PREFIX'; if
862 the REGEXP matches, the PREFIX is used to set the fill prefix.
863 It in turn is a list of things:
865 STRING -- insert a literal string
866 (match . N) -- insert the thing matched by bracketed subexpression N
867 (pad . N) -- a string of whitespace the same width as subexpression N
868 (expr . FORM) -- the result of evaluating FORM")
870 (make-variable-buffer-local 'mdw-fill-prefix)
872 (defvar mdw-hanging-indents
874 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
877 "*Standard regexp matching parts of a hanging indent.
878 This is mainly useful in `auto-fill-mode'.")
880 ;; Setting things up.
882 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
884 ;; Utility functions.
886 (defun mdw-maybe-tabify (s)
887 "Tabify or untabify the string S, according to `indent-tabs-mode'."
888 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
892 (let ((start (point-min)) (end (point-max)))
893 (funcall tabfun (point-min) (point-max))
894 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
896 (defun mdw-examine-fill-prefixes (l)
897 "Given a list of dynamic fill prefixes, pick one which matches
898 context and return the static fill prefix to use. Point must be
899 at the start of a line, and match data must be saved."
901 ((looking-at (car (car l)))
902 (mdw-maybe-tabify (apply #'concat
903 (mapcar #'mdw-do-prefix-match
905 (t (mdw-examine-fill-prefixes (cdr l)))))
907 (defun mdw-maybe-car (p)
908 "If P is a pair, return (car P), otherwise just return P."
909 (if (consp p) (car p) p))
911 (defun mdw-padding (s)
912 "Return a string the same width as S but made entirely from whitespace."
913 (let* ((l (length s)) (i 0) (n (make-string l ? )))
920 (defun mdw-do-prefix-match (m)
921 "Expand a dynamic prefix match element.
922 See `mdw-fill-prefix' for details."
923 (cond ((not (consp m)) (format "%s" m))
924 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
925 ((eq (car m) 'pad) (mdw-padding (match-string
926 (mdw-maybe-car (cdr m)))))
927 ((eq (car m) 'eval) (eval (cdr m)))
930 (defun mdw-choose-dynamic-fill-prefix ()
931 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
932 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
933 ((not mdw-fill-prefix) fill-prefix)
937 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
939 (defun do-auto-fill ()
940 "Handle auto-filling, working out a dynamic fill prefix in the
941 case where there isn't a sensible static one."
942 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
945 (defun mdw-fill-paragraph ()
946 "Fill paragraph, getting a dynamic fill prefix."
948 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
949 (fill-paragraph nil)))
951 (defun mdw-standard-fill-prefix (rx &optional mat)
952 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
953 This is just a short-cut for setting the thing by hand, and by
954 design it doesn't cope with anything approximating a complicated
956 (setq mdw-fill-prefix
957 `((,(concat rx mdw-hanging-indents)
959 (pad . ,(or mat 2))))))
961 ;;;--------------------------------------------------------------------------
962 ;;; Other common declarations.
964 ;; Common mode settings.
966 (defvar mdw-auto-indent t
967 "Whether to indent automatically after a newline.")
969 (defun mdw-whitespace-mode (&optional arg)
970 "Turn on/off whitespace mode, but don't highlight trailing space."
972 (when (and (boundp 'whitespace-style)
973 (fboundp 'whitespace-mode))
974 (let ((whitespace-style (remove 'trailing whitespace-style)))
975 (whitespace-mode arg))
976 (setq show-trailing-whitespace whitespace-mode)))
978 (defvar mdw-do-misc-mode-hacking nil)
980 (defun mdw-misc-mode-config ()
982 (cond ((eq major-mode 'lisp-mode)
983 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
984 ((or (eq major-mode 'slime-repl-mode)
985 (eq major-mode 'asm-mode))
988 (local-set-key "\C-m" 'newline-and-indent))))
989 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
990 (local-set-key [C-return] 'newline)
991 (make-local-variable 'page-delimiter)
992 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
993 (setq comment-column 40)
995 (setq fill-column mdw-text-width)
996 (and (fboundp 'gtags-mode)
998 (if (fboundp 'hs-minor-mode)
999 (trap (hs-minor-mode t))
1000 (outline-minor-mode t))
1002 (trap (turn-on-font-lock)))
1004 (defun mdw-post-local-vars-misc-mode-config ()
1005 (setq whitespace-line-column mdw-text-width)
1006 (when (and mdw-do-misc-mode-hacking
1007 (not buffer-read-only))
1008 (setq show-trailing-whitespace t)
1009 (mdw-whitespace-mode 1)))
1010 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1012 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1013 `(progn ,@(mapcar (lambda (func)
1015 (after mdw-angry-fruit-salad activate)
1016 (when mdw-do-misc-mode-hacking
1017 (setq show-trailing-whitespace
1018 (not buffer-read-only))
1019 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1021 (mdw-advise-update-angry-fruit-salad toggle-read-only
1027 (eval-after-load 'gtags
1029 (dolist (key '([mouse-2] [mouse-3]))
1030 (define-key gtags-mode-map key nil))
1031 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1032 (define-key gtags-select-mode-map [C-S-mouse-2]
1033 'gtags-select-tag-by-event)
1034 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1035 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1037 ;; Backup file handling.
1039 (defvar mdw-backup-disable-regexps nil
1040 "*List of regular expressions: if a file name matches any of
1041 these then the file is not backed up.")
1043 (defun mdw-backup-enable-predicate (name)
1044 "[mdw]'s default backup predicate.
1045 Allows a backup if the standard predicate would allow it, and it
1046 doesn't match any of the regular expressions in
1047 `mdw-backup-disable-regexps'."
1048 (and (normal-backup-enable-predicate name)
1049 (let ((answer t) (list mdw-backup-disable-regexps))
1052 (if (string-match (car list) name)
1054 (setq list (cdr list)))
1056 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1060 (defun mdw-last-one-out-turn-off-the-lights (frame)
1061 "Disconnect from an X display if this was the last frame on that display."
1062 (let ((frame-display (frame-parameter frame 'display)))
1063 (when (and frame-display
1064 (eq window-system 'x)
1065 (not (some (lambda (fr)
1066 (and (not (eq fr frame))
1067 (string= (frame-parameter fr 'display)
1070 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1071 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1073 ;;;--------------------------------------------------------------------------
1076 (defvar mdw-point-overlay
1077 (let ((ov (make-overlay 0 0))
1079 (overlay-put ov 'priority 2)
1080 (put-text-property 0 1 'display '(left-fringe vertical-bar) s)
1081 (overlay-put ov 'before-string s)
1084 "An overlay used for showing where point is in the selected window.")
1086 (defun mdw-remove-point-overlay ()
1087 "Remove the current-point overlay."
1088 (delete-overlay mdw-point-overlay))
1090 (defun mdw-update-point-overlay ()
1091 "Mark the current point position with an overlay."
1092 (if (not mdw-point-overlay-mode)
1093 (mdw-remove-point-overlay)
1094 (overlay-put mdw-point-overlay 'window (selected-window))
1096 (move-overlay mdw-point-overlay
1097 (point) (1+ (point)) (current-buffer))
1098 (move-overlay mdw-point-overlay
1099 (1- (point)) (point) (current-buffer)))))
1101 (defvar mdw-point-overlay-buffers nil
1102 "List of buffers using `mdw-point-overlay-mode'.")
1104 (define-minor-mode mdw-point-overlay-mode
1105 "Indicate current line with an overlay."
1107 (let ((buffer (current-buffer)))
1108 (setq mdw-point-overlay-buffers
1109 (mapcan (lambda (buf)
1110 (if (and (buffer-live-p buf)
1111 (not (eq buf buffer)))
1113 mdw-point-overlay-buffers))
1114 (if mdw-point-overlay-mode
1115 (setq mdw-point-overlay-buffers
1116 (cons buffer mdw-point-overlay-buffers))))
1117 (cond (mdw-point-overlay-buffers
1118 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1119 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1121 (mdw-remove-point-overlay)
1122 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1123 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1125 (define-globalized-minor-mode mdw-global-point-overlay-mode
1126 mdw-point-overlay-mode
1127 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1129 ;;;--------------------------------------------------------------------------
1130 ;;; Fullscreen-ness.
1132 (defvar mdw-full-screen-parameters
1133 '((menu-bar-lines . 0)
1134 ;(vertical-scroll-bars . nil)
1136 "Frame parameters to set when making a frame fullscreen.")
1138 (defvar mdw-full-screen-save
1140 "Extra frame parameters to save when setting fullscreen.")
1142 (defun mdw-toggle-full-screen (&optional frame)
1143 "Show the FRAME fullscreen."
1146 (cond ((frame-parameter frame 'fullscreen)
1147 (set-frame-parameter frame 'fullscreen nil)
1148 (modify-frame-parameters
1150 (or (frame-parameter frame 'mdw-full-screen-saved)
1151 (mapcar (lambda (assoc)
1152 (assq (car assoc) default-frame-alist))
1153 mdw-full-screen-parameters))))
1155 (let ((saved (mapcar (lambda (param)
1156 (cons param (frame-parameter frame param)))
1157 (append (mapcar #'car
1158 mdw-full-screen-parameters)
1159 mdw-full-screen-save))))
1160 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1161 (modify-frame-parameters frame mdw-full-screen-parameters)
1162 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1164 ;;;--------------------------------------------------------------------------
1165 ;;; General fontification.
1167 (make-face 'mdw-virgin-face)
1169 (defmacro mdw-define-face (name &rest body)
1170 "Define a face, and make sure it's actually set as the definition."
1174 (copy-face 'mdw-virgin-face ',name)
1175 (defvar ,name ',name)
1176 (put ',name 'face-defface-spec ',body)
1177 (face-spec-set ',name ',body nil)))
1179 (mdw-define-face default
1180 (((type w32)) :family "courier new" :height 85)
1181 (((type x)) :family "6x13" :foundry "trad" :height 130)
1182 (((type color)) :foreground "white" :background "black")
1184 (mdw-define-face fixed-pitch
1185 (((type w32)) :family "courier new" :height 85)
1186 (((type x)) :family "6x13" :foundry "trad" :height 130)
1187 (t :foreground "white" :background "black"))
1188 (if (mdw-emacs-version-p 23)
1189 (mdw-define-face variable-pitch
1190 (((type x)) :family "sans" :height 100))
1191 (mdw-define-face variable-pitch
1192 (((type x)) :family "helvetica" :height 90)))
1193 (mdw-define-face region
1194 (((type tty) (class color)) :background "blue")
1195 (((type tty) (class mono)) :inverse-video t)
1196 (t :background "grey30"))
1197 (mdw-define-face match
1198 (((type tty) (class color)) :background "blue")
1199 (((type tty) (class mono)) :inverse-video t)
1200 (t :background "blue"))
1201 (mdw-define-face mc/cursor-face
1202 (((type tty) (class mono)) :inverse-video t)
1203 (t :background "red"))
1204 (mdw-define-face minibuffer-prompt
1206 (mdw-define-face mode-line
1207 (((class color)) :foreground "blue" :background "yellow"
1208 :box (:line-width 1 :style released-button))
1209 (t :inverse-video t))
1210 (mdw-define-face mode-line-inactive
1211 (((class color)) :foreground "yellow" :background "blue"
1212 :box (:line-width 1 :style released-button))
1213 (t :inverse-video t))
1214 (mdw-define-face nobreak-space
1216 (t :inherit escape-glyph :underline t))
1217 (mdw-define-face scroll-bar
1218 (t :foreground "black" :background "lightgrey"))
1219 (mdw-define-face fringe
1220 (t :foreground "yellow"))
1221 (mdw-define-face show-paren-match
1222 (((class color)) :background "darkgreen")
1224 (mdw-define-face show-paren-mismatch
1225 (((class color)) :background "red")
1226 (t :inverse-video t))
1227 (mdw-define-face highlight
1228 (((type x) (class color)) :background "DarkSeaGreen4")
1229 (((type tty) (class color)) :background "cyan")
1230 (t :inverse-video t))
1232 (mdw-define-face holiday-face
1233 (t :background "red"))
1234 (mdw-define-face calendar-today-face
1235 (t :foreground "yellow" :weight bold))
1237 (mdw-define-face comint-highlight-prompt
1239 (mdw-define-face comint-highlight-input
1242 (mdw-define-face dired-directory
1243 (t :foreground "cyan" :weight bold))
1244 (mdw-define-face dired-symlink
1245 (t :foreground "cyan"))
1246 (mdw-define-face dired-perm-write
1249 (mdw-define-face trailing-whitespace
1250 (((class color)) :background "red")
1251 (t :inverse-video t))
1252 (mdw-define-face whitespace-line
1253 (((class color)) :background "darkred")
1254 (t :inverse-video t))
1255 (mdw-define-face mdw-punct-face
1256 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
1257 (mdw-define-face mdw-number-face
1258 (t :foreground "yellow"))
1259 (mdw-define-face mdw-trivial-face)
1260 (mdw-define-face font-lock-function-name-face
1262 (mdw-define-face font-lock-keyword-face
1264 (mdw-define-face font-lock-constant-face
1266 (mdw-define-face font-lock-builtin-face
1268 (mdw-define-face font-lock-type-face
1269 (t :weight bold :slant italic))
1270 (mdw-define-face font-lock-reference-face
1272 (mdw-define-face font-lock-variable-name-face
1274 (mdw-define-face font-lock-comment-delimiter-face
1275 (((class mono)) :weight bold)
1276 (((type tty) (class color)) :foreground "green")
1277 (t :slant italic :foreground "SeaGreen1"))
1278 (mdw-define-face font-lock-comment-face
1279 (((class mono)) :weight bold)
1280 (((type tty) (class color)) :foreground "green")
1281 (t :slant italic :foreground "SeaGreen1"))
1282 (mdw-define-face font-lock-string-face
1283 (((class mono)) :weight bold)
1284 (((class color)) :foreground "SkyBlue1"))
1286 (mdw-define-face message-separator
1287 (t :background "red" :foreground "white" :weight bold))
1288 (mdw-define-face message-cited-text
1289 (default :slant italic)
1290 (((type tty)) :foreground "cyan") (t :foreground "SkyBlue1"))
1291 (mdw-define-face message-header-cc
1292 (default :slant italic)
1293 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1294 (mdw-define-face message-header-newsgroups
1295 (default :slant italic)
1296 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1297 (mdw-define-face message-header-subject
1298 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1299 (mdw-define-face message-header-to
1300 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1301 (mdw-define-face message-header-xheader
1302 (default :slant italic)
1303 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1304 (mdw-define-face message-header-other
1305 (default :slant italic)
1306 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1307 (mdw-define-face message-header-name
1308 (default :weight bold)
1309 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1311 (mdw-define-face which-func
1314 (mdw-define-face gnus-header-name
1315 (default :weight bold)
1316 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1317 (mdw-define-face gnus-header-subject
1318 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1319 (mdw-define-face gnus-header-from
1320 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1321 (mdw-define-face gnus-header-to
1322 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1323 (mdw-define-face gnus-header-content
1324 (default :slant italic)
1325 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1327 (mdw-define-face gnus-cite-1
1328 (((type tty)) :foreground "cyan") (t :foreground "SkyBlue1"))
1329 (mdw-define-face gnus-cite-2
1330 (((type tty)) :foreground "blue") (t :foreground "RoyalBlue2"))
1331 (mdw-define-face gnus-cite-3
1332 (((type tty)) :foreground "magenta") (t :foreground "MediumOrchid"))
1333 (mdw-define-face gnus-cite-4
1334 (((type tty)) :foreground "red") (t :foreground "firebrick2"))
1335 (mdw-define-face gnus-cite-5
1336 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
1337 (mdw-define-face gnus-cite-6
1338 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1339 (mdw-define-face gnus-cite-7
1340 (((type tty)) :foreground "cyan") (t :foreground "SlateBlue1"))
1341 (mdw-define-face gnus-cite-8
1342 (((type tty)) :foreground "blue") (t :foreground "RoyalBlue2"))
1343 (mdw-define-face gnus-cite-9
1344 (((type tty)) :foreground "magenta") (t :foreground "purple2"))
1345 (mdw-define-face gnus-cite-10
1346 (((type tty)) :foreground "red") (t :foreground "DarkOrange2"))
1347 (mdw-define-face gnus-cite-11
1348 (t :foreground "grey"))
1350 (mdw-define-face diff-header
1352 (mdw-define-face diff-index
1354 (mdw-define-face diff-file-header
1356 (mdw-define-face diff-hunk-header
1357 (t :foreground "SkyBlue1"))
1358 (mdw-define-face diff-function
1359 (t :foreground "SkyBlue1" :weight bold))
1360 (mdw-define-face diff-header
1361 (t :background "grey10"))
1362 (mdw-define-face diff-added
1363 (t :foreground "green"))
1364 (mdw-define-face diff-removed
1365 (t :foreground "red"))
1366 (mdw-define-face diff-context
1368 (mdw-define-face diff-refine-change
1369 (((class color) (type x)) :background "RoyalBlue4")
1371 (mdw-define-face diff-refine-removed
1372 (((class color) (type x)) :background "#500")
1374 (mdw-define-face diff-refine-added
1375 (((class color) (type x)) :background "#050")
1378 (setq ediff-force-faces t)
1379 (mdw-define-face ediff-current-diff-A
1380 (((class color) (type x)) :background "darkred")
1381 (((class color) (type tty)) :background "red")
1382 (t :inverse-video t))
1383 (mdw-define-face ediff-fine-diff-A
1384 (((class color) (type x)) :background "red3")
1385 (((class color) (type tty)) :inverse-video t)
1386 (t :inverse-video nil))
1387 (mdw-define-face ediff-even-diff-A
1388 (((class color) (type x)) :background "#300"))
1389 (mdw-define-face ediff-odd-diff-A
1390 (((class color) (type x)) :background "#300"))
1391 (mdw-define-face ediff-current-diff-B
1392 (((class color) (type x)) :background "darkgreen")
1393 (((class color) (type tty)) :background "magenta")
1394 (t :inverse-video t))
1395 (mdw-define-face ediff-fine-diff-B
1396 (((class color) (type x)) :background "green4")
1397 (((class color) (type tty)) :inverse-video t)
1398 (t :inverse-video nil))
1399 (mdw-define-face ediff-even-diff-B
1400 (((class color) (type x)) :background "#020"))
1401 (mdw-define-face ediff-odd-diff-B
1402 (((class color) (type x)) :background "#020"))
1403 (mdw-define-face ediff-current-diff-C
1404 (((class color) (type x)) :background "darkblue")
1405 (((class color) (type tty)) :background "blue")
1406 (t :inverse-video t))
1407 (mdw-define-face ediff-fine-diff-C
1408 (((class color) (type x)) :background "blue1")
1409 (((class color) (type tty)) :inverse-video t)
1410 (t :inverse-video nil))
1411 (mdw-define-face ediff-even-diff-C
1412 (((class color) (type x)) :background "#004"))
1413 (mdw-define-face ediff-odd-diff-C
1414 (((class color) (type x)) :background "#004"))
1415 (mdw-define-face ediff-current-diff-Ancestor
1416 (((class color) (type x)) :background "#630")
1417 (((class color) (type tty)) :background "blue")
1418 (t :inverse-video t))
1419 (mdw-define-face ediff-even-diff-Ancestor
1420 (((class color) (type x)) :background "#320"))
1421 (mdw-define-face ediff-odd-diff-Ancestor
1422 (((class color) (type x)) :background "#320"))
1424 (mdw-define-face dylan-header-background
1425 (((class color) (type x)) :background "NavyBlue")
1426 (t :background "blue"))
1428 (mdw-define-face erc-input-face
1429 (t :foreground "red"))
1431 (mdw-define-face woman-bold
1433 (mdw-define-face woman-italic
1436 (eval-after-load "rst"
1438 (mdw-define-face rst-level-1-face
1439 (t :foreground "SkyBlue1" :weight bold))
1440 (mdw-define-face rst-level-2-face
1441 (t :foreground "SeaGreen1" :weight bold))
1442 (mdw-define-face rst-level-3-face
1444 (mdw-define-face rst-level-4-face
1446 (mdw-define-face rst-level-5-face
1448 (mdw-define-face rst-level-6-face
1451 (mdw-define-face p4-depot-added-face
1452 (t :foreground "green"))
1453 (mdw-define-face p4-depot-branch-op-face
1454 (t :foreground "yellow"))
1455 (mdw-define-face p4-depot-deleted-face
1456 (t :foreground "red"))
1457 (mdw-define-face p4-depot-unmapped-face
1458 (t :foreground "SkyBlue1"))
1459 (mdw-define-face p4-diff-change-face
1460 (t :foreground "yellow"))
1461 (mdw-define-face p4-diff-del-face
1462 (t :foreground "red"))
1463 (mdw-define-face p4-diff-file-face
1464 (t :foreground "SkyBlue1"))
1465 (mdw-define-face p4-diff-head-face
1466 (t :background "grey10"))
1467 (mdw-define-face p4-diff-ins-face
1468 (t :foreground "green"))
1470 (mdw-define-face w3m-anchor-face
1471 (t :foreground "SkyBlue1" :underline t))
1472 (mdw-define-face w3m-arrived-anchor-face
1473 (t :foreground "SkyBlue1" :underline t))
1475 (mdw-define-face whizzy-slice-face
1476 (t :background "grey10"))
1477 (mdw-define-face whizzy-error-face
1478 (t :background "darkred"))
1480 ;; Ellipses used to indicate hidden text (and similar).
1481 (mdw-define-face mdw-ellipsis-face
1482 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1483 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1484 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1485 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1486 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1487 (set-display-table-slot standard-display-table 0 dollar)
1488 (set-display-table-slot standard-display-table 1 backslash)
1489 (set-display-table-slot standard-display-table 4
1490 (vector dot dot dot))
1491 (set-display-table-slot standard-display-table 5 bar))
1493 ;;;--------------------------------------------------------------------------
1494 ;;; C programming configuration.
1496 ;; Make C indentation nice.
1498 (defun mdw-c-lineup-arglist (langelem)
1499 "Hack for DWIMmery in c-lineup-arglist."
1501 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1503 (c-lineup-arglist langelem)))
1505 (defun mdw-c-indent-extern-mumble (langelem)
1506 "Indent `extern \"...\" {' lines."
1508 (back-to-indentation)
1510 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1514 (defun mdw-c-indent-arglist-nested (langelem)
1515 "Indent continued argument lists.
1516 If we've nested more than one argument list, then only introduce a single
1517 indentation anyway."
1518 (let ((context c-syntactic-context)
1519 (pos (c-langelem-2nd-pos c-syntactic-element))
1520 (should-indent-p t))
1522 (eq (caar context) 'arglist-cont-nonempty))
1523 (when (and (= (caddr (pop context)) pos)
1525 (memq (caar context) '(arglist-intro
1526 arglist-cont-nonempty)))
1527 (setq should-indent-p nil)))
1528 (if should-indent-p '+ 0)))
1530 (defvar mdw-define-c-styles-hook nil
1531 "Hook run when `cc-mode' starts up to define styles.")
1533 (defmacro mdw-define-c-style (name &rest assocs)
1534 "Define a C style, called NAME (a symbol), setting ASSOCs.
1535 A function, named `mdw-define-c-style/NAME', is defined to actually install
1536 the style using `c-add-style', and added to the hook
1537 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1539 (declare (indent defun))
1540 (let* ((name-string (symbol-name name))
1541 (func (intern (concat "mdw-define-c-style/" name-string))))
1543 (defun ,func () (c-add-style ,name-string ',assocs))
1544 (and (featurep 'cc-mode) (,func))
1545 (add-hook 'mdw-define-c-styles-hook ',func))))
1547 (eval-after-load "cc-mode"
1548 '(run-hooks 'mdw-define-c-styles-hook))
1550 (mdw-define-c-style mdw-trustonic-c
1551 (c-basic-offset . 4)
1552 (comment-column . 0)
1553 (c-indent-comment-alist (anchored-comment . (column . 0))
1554 (end-block . (space . 1))
1555 (cpp-end-block . (space . 1))
1556 (other . (space . 1)))
1557 (c-class-key . "class")
1558 (c-backslash-column . 0)
1559 (c-auto-align-backslashes . nil)
1560 (c-label-minimum-indentation . 0)
1561 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1562 (defun-open . (add 0 c-indent-one-line-block))
1563 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1564 (topmost-intro . mdw-c-indent-extern-mumble)
1565 (cpp-define-intro . 0)
1567 (inextern-lang . [0])
1573 (statement-cont . +)
1574 (statement-case-intro . +)))
1576 (mdw-define-c-style mdw-c
1577 (c-basic-offset . 2)
1578 (comment-column . 40)
1579 (c-class-key . "class")
1580 (c-backslash-column . 72)
1581 (c-label-minimum-indentation . 0)
1582 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1583 (defun-open . (add 0 c-indent-one-line-block))
1584 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1585 (topmost-intro . mdw-c-indent-extern-mumble)
1586 (cpp-define-intro . 0)
1588 (inextern-lang . [0])
1594 (statement-cont . +)
1595 (statement-case-intro . +)))
1597 (defun mdw-set-default-c-style (modes style)
1598 "Update the default CC Mode style for MODES to be STYLE.
1600 MODES may be a list of major mode names or a singleton. STYLE is a style
1602 (let ((modes (if (listp modes) modes (list modes)))
1603 (style (symbol-name style)))
1604 (setq c-default-style
1605 (append (mapcar (lambda (mode)
1608 (remove-if (lambda (assoc)
1609 (memq (car assoc) modes))
1610 (if (listp c-default-style)
1612 (list (cons 'other c-default-style))))))))
1613 (setq c-default-style "mdw-c")
1615 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
1617 (defvar mdw-c-comment-fill-prefix
1618 `((,(concat "\\([ \t]*/?\\)"
1621 "\\([A-Za-z]+:[ \t]*\\)?"
1622 mdw-hanging-indents)
1623 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1624 "Fill prefix matching C comments (both kinds).")
1626 (defun mdw-fontify-c-and-c++ ()
1628 ;; Fiddle with some syntax codes.
1629 (modify-syntax-entry ?* ". 23")
1630 (modify-syntax-entry ?/ ". 124b")
1631 (modify-syntax-entry ?\n "> b")
1634 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1636 ;; Now define things to be fontified.
1637 (make-local-variable 'font-lock-keywords)
1639 (mdw-regexps "alignas" ;C11 macro, C++11
1641 "and" ;C++, C95 macro
1642 "and_eq" ;C++, C95 macro
1643 "asm" ;K&R, C++, GCC
1644 "atomic" ;C11 macro, C++11 template type
1646 "bitand" ;C++, C95 macro
1647 "bitor" ;C++, C95 macro
1648 "bool" ;C++, C99 macro
1653 "char16_t" ;C++11, C11 library type
1654 "char32_t" ;C++11, C11 library type
1656 "complex" ;C99 macro, C++ template type
1657 "compl" ;C++, C95 macro
1661 "continue" ;K&R, C89
1663 "defined" ;C89 preprocessor
1670 ;; "entry" ;K&R -- never used
1681 "imaginary" ;C99 macro
1682 "inline" ;C++, C99, GCC
1689 "noreturn" ;C11 macro
1690 "not" ;C++, C95 macro
1691 "not_eq" ;C++, C95 macro
1694 "or" ;C++, C95 macro
1695 "or_eq" ;C++, C95 macro
1699 "register" ;K&R, C89
1700 "reinterpret_cast" ;C++
1707 "static_assert" ;C11 macro, C++11
1714 "thread_local" ;C11 macro, C++11
1720 "unsigned" ;K&R, C89
1725 "wchar_t" ;C++, C89 library type
1727 "xor" ;C++, C95 macro
1728 "xor_eq" ;C++, C95 macro
1737 "_Pragma" ;C99 preprocessor
1738 "_Static_assert" ;C11
1739 "_Thread_local" ;C11
1742 "__attribute__" ;GCC
1745 "__extension__" ;GCC
1755 (mdw-regexps "false" ;C++, C99 macro
1757 "true" ;C++, C99 macro
1759 (preprocessor-keywords
1760 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1761 "ident" "if" "ifdef" "ifndef" "import" "include"
1762 "line" "pragma" "unassert" "undef" "warning"))
1764 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1765 "interface" "private" "protected" "protocol" "public"
1768 (setq font-lock-keywords
1771 ;; Fontify include files as strings.
1772 (list (concat "^[ \t]*\\#[ \t]*"
1773 "\\(include\\|import\\)"
1774 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1775 '(2 font-lock-string-face))
1777 ;; Preprocessor directives are `references'?.
1778 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1779 preprocessor-keywords
1780 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1781 '(1 font-lock-keyword-face))
1783 ;; Handle the keywords defined above.
1784 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1785 '(0 font-lock-keyword-face))
1787 (list (concat "\\<\\(" c-keywords "\\)\\>")
1788 '(0 font-lock-keyword-face))
1790 (list (concat "\\<\\(" c-constants "\\)\\>")
1791 '(0 font-lock-variable-name-face))
1793 ;; Handle numbers too.
1795 ;; This looks strange, I know. It corresponds to the
1796 ;; preprocessor's idea of what a number looks like, rather than
1797 ;; anything sensible.
1798 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1799 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1800 '(0 mdw-number-face))
1802 ;; And anything else is punctuation.
1803 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1804 '(0 mdw-punct-face))))))
1806 ;;;--------------------------------------------------------------------------
1809 (define-derived-mode apcalc-mode c-mode "AP Calc"
1810 "Major mode for editing Calc code.")
1812 (defun mdw-fontify-apcalc ()
1814 ;; Fiddle with some syntax codes.
1815 (modify-syntax-entry ?* ". 23")
1816 (modify-syntax-entry ?/ ". 14")
1819 (setq comment-start "/* ")
1820 (setq comment-end " */")
1821 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1823 ;; Now define things to be fontified.
1824 (make-local-variable 'font-lock-keywords)
1826 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1827 "do" "else" "exit" "for" "global" "goto" "help" "if"
1828 "local" "mat" "obj" "print" "quit" "read" "return"
1829 "show" "static" "switch" "while" "write")))
1831 (setq font-lock-keywords
1834 ;; Handle the keywords defined above.
1835 (list (concat "\\<\\(" c-keywords "\\)\\>")
1836 '(0 font-lock-keyword-face))
1838 ;; Handle numbers too.
1840 ;; This looks strange, I know. It corresponds to the
1841 ;; preprocessor's idea of what a number looks like, rather than
1842 ;; anything sensible.
1843 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1844 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1845 '(0 mdw-number-face))
1847 ;; And anything else is punctuation.
1848 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1849 '(0 mdw-punct-face))))))
1851 ;;;--------------------------------------------------------------------------
1852 ;;; Java programming configuration.
1854 ;; Make indentation nice.
1856 (mdw-define-c-style mdw-java
1857 (c-basic-offset . 2)
1858 (c-backslash-column . 72)
1859 (c-offsets-alist (substatement-open . 0)
1864 (statement-case-intro . +)))
1865 (mdw-set-default-c-style 'java-mode 'mdw-java)
1867 ;; Declare Java fontification style.
1869 (defun mdw-fontify-java ()
1872 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1874 ;; Now define things to be fontified.
1875 (make-local-variable 'font-lock-keywords)
1876 (let ((java-keywords
1877 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1878 "char" "class" "const" "continue" "default" "do"
1879 "double" "else" "extends" "final" "finally" "float"
1880 "for" "goto" "if" "implements" "import" "instanceof"
1881 "int" "interface" "long" "native" "new" "package"
1882 "private" "protected" "public" "return" "short"
1883 "static" "switch" "synchronized" "throw" "throws"
1884 "transient" "try" "void" "volatile" "while"))
1887 (mdw-regexps "false" "null" "super" "this" "true")))
1889 (setq font-lock-keywords
1892 ;; Handle the keywords defined above.
1893 (list (concat "\\<\\(" java-keywords "\\)\\>")
1894 '(0 font-lock-keyword-face))
1896 ;; Handle the magic constants defined above.
1897 (list (concat "\\<\\(" java-constants "\\)\\>")
1898 '(0 font-lock-variable-name-face))
1900 ;; Handle numbers too.
1902 ;; The following isn't quite right, but it's close enough.
1903 (list (concat "\\<\\("
1904 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1905 "[0-9]+\\(\\.[0-9]*\\|\\)"
1906 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1908 '(0 mdw-number-face))
1910 ;; And anything else is punctuation.
1911 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1912 '(0 mdw-punct-face))))))
1914 ;;;--------------------------------------------------------------------------
1915 ;;; Javascript programming configuration.
1917 (defun mdw-javascript-style ()
1918 (setq js-indent-level 2)
1919 (setq js-expr-indent-offset 0))
1921 (defun mdw-fontify-javascript ()
1924 (mdw-javascript-style)
1925 (setq js-auto-indent-flag t)
1927 ;; Now define things to be fontified.
1928 (make-local-variable 'font-lock-keywords)
1929 (let ((javascript-keywords
1930 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1931 "char" "class" "const" "continue" "debugger" "default"
1932 "delete" "do" "double" "else" "enum" "export" "extends"
1933 "final" "finally" "float" "for" "function" "goto" "if"
1934 "implements" "import" "in" "instanceof" "int"
1935 "interface" "let" "long" "native" "new" "package"
1936 "private" "protected" "public" "return" "short"
1937 "static" "super" "switch" "synchronized" "throw"
1938 "throws" "transient" "try" "typeof" "var" "void"
1939 "volatile" "while" "with" "yield"
1941 "boolean" "byte" "char" "double" "float" "int" "long"
1943 (javascript-constants
1944 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
1945 "arguments" "this")))
1947 (setq font-lock-keywords
1950 ;; Handle the keywords defined above.
1951 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
1952 '(0 font-lock-keyword-face))
1954 ;; Handle the predefined constants defined above.
1955 (list (concat "\\_<\\(" javascript-constants "\\)\\_>")
1956 '(0 font-lock-variable-name-face))
1958 ;; Handle numbers too.
1960 ;; The following isn't quite right, but it's close enough.
1961 (list (concat "\\_<\\("
1962 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1963 "[0-9]+\\(\\.[0-9]*\\|\\)"
1964 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1966 '(0 mdw-number-face))
1968 ;; And anything else is punctuation.
1969 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1970 '(0 mdw-punct-face))))))
1972 ;;;--------------------------------------------------------------------------
1973 ;;; Scala programming configuration.
1975 (defun mdw-fontify-scala ()
1978 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1980 ;; Define things to be fontified.
1981 (make-local-variable 'font-lock-keywords)
1982 (let ((scala-keywords
1983 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
1984 "extends" "final" "finally" "for" "forSome" "if"
1985 "implicit" "import" "lazy" "match" "new" "object"
1986 "override" "package" "private" "protected" "return"
1987 "sealed" "throw" "trait" "try" "type" "val"
1988 "var" "while" "with" "yield"))
1990 (mdw-regexps "false" "null" "super" "this" "true"))
1991 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
1993 (setq font-lock-keywords
1996 ;; Magical identifiers between backticks.
1997 (list (concat "`\\([^`]+\\)`")
1998 '(1 font-lock-variable-name-face))
2000 ;; Handle the keywords defined above.
2001 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2002 '(0 font-lock-keyword-face))
2004 ;; Handle the constants defined above.
2005 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2006 '(0 font-lock-variable-name-face))
2008 ;; Magical identifiers between backticks.
2009 (list (concat "`\\([^`]+\\)`")
2010 '(1 font-lock-variable-name-face))
2012 ;; Handle numbers too.
2014 ;; As usual, not quite right.
2015 (list (concat "\\_<\\("
2016 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2017 "[0-9]+\\(\\.[0-9]*\\|\\)"
2018 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2020 '(0 mdw-number-face))
2022 ;; Identifiers with trailing operators.
2023 (list (concat "_\\(" punctuation "\\)+")
2024 '(0 mdw-trivial-face))
2026 ;; And everything else is punctuation.
2027 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2028 '(0 mdw-punct-face)))
2030 font-lock-syntactic-keywords
2033 ;; Single quotes around characters. But not when used to quote
2034 ;; symbol names. Ugh.
2035 (list (concat "\\('\\)"
2037 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2038 "u+" "[0-9a-fA-F]\\{4\\}"
2039 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2040 "\\|" "\\\\" "." "\\)"
2045 ;;;--------------------------------------------------------------------------
2046 ;;; C# programming configuration.
2048 ;; Make indentation nice.
2050 (mdw-define-c-style mdw-csharp
2051 (c-basic-offset . 2)
2052 (c-backslash-column . 72)
2053 (c-offsets-alist (substatement-open . 0)
2058 (statement-case-intro . +)))
2059 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2061 ;; Declare C# fontification style.
2063 (defun mdw-fontify-csharp ()
2066 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2068 ;; Now define things to be fontified.
2069 (make-local-variable 'font-lock-keywords)
2070 (let ((csharp-keywords
2071 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2072 "char" "checked" "class" "const" "continue" "decimal"
2073 "default" "delegate" "do" "double" "else" "enum"
2074 "event" "explicit" "extern" "finally" "fixed" "float"
2075 "for" "foreach" "goto" "if" "implicit" "in" "int"
2076 "interface" "internal" "is" "lock" "long" "namespace"
2077 "new" "object" "operator" "out" "override" "params"
2078 "private" "protected" "public" "readonly" "ref"
2079 "return" "sbyte" "sealed" "short" "sizeof"
2080 "stackalloc" "static" "string" "struct" "switch"
2081 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2082 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2086 (mdw-regexps "base" "false" "null" "this" "true")))
2088 (setq font-lock-keywords
2091 ;; Handle the keywords defined above.
2092 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2093 '(0 font-lock-keyword-face))
2095 ;; Handle the magic constants defined above.
2096 (list (concat "\\<\\(" csharp-constants "\\)\\>")
2097 '(0 font-lock-variable-name-face))
2099 ;; Handle numbers too.
2101 ;; The following isn't quite right, but it's close enough.
2102 (list (concat "\\<\\("
2103 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2104 "[0-9]+\\(\\.[0-9]*\\|\\)"
2105 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2107 '(0 mdw-number-face))
2109 ;; And anything else is punctuation.
2110 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2111 '(0 mdw-punct-face))))))
2113 (define-derived-mode csharp-mode java-mode "C#"
2114 "Major mode for editing C# code.")
2116 ;;;--------------------------------------------------------------------------
2117 ;;; F# programming configuration.
2119 (setq fsharp-indent-offset 2)
2121 (defun mdw-fontify-fsharp ()
2123 (let ((punct "=<>+-*/|&%!@?"))
2125 ((>= i (length punct)))
2126 (modify-syntax-entry (aref punct i) ".")))
2128 (modify-syntax-entry ?_ "_")
2129 (modify-syntax-entry ?( "(")
2130 (modify-syntax-entry ?) ")")
2132 (setq indent-tabs-mode nil)
2134 (let ((fsharp-keywords
2135 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2137 "checked" "class" "component" "const" "constraint"
2138 "constructor" "continue"
2139 "default" "delegate" "do" "done" "downcast" "downto"
2140 "eager" "elif" "else" "end" "exception" "extern"
2141 "finally" "fixed" "for" "fori" "fun" "function"
2144 "if" "in" "include" "inherit" "inline" "interface"
2147 "match" "measure" "member" "method" "mixin" "module"
2150 "object" "of" "open" "or" "override"
2151 "parallel" "params" "private" "process" "protected"
2153 "rec" "recursive" "return"
2154 "sealed" "sig" "static" "struct"
2155 "tailcall" "then" "to" "trait" "try" "type"
2157 "val" "virtual" "void" "volatile"
2158 "when" "while" "with"
2162 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2163 "base" "false" "null" "true"))
2166 (mdw-regexps "do" "let" "return" "use" "yield"))
2168 (preprocessor-keywords
2169 (mdw-regexps "if" "indent" "else" "endif")))
2171 (setq font-lock-keywords
2172 (list (list (concat "\\(^\\|[^\"]\\)"
2175 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2180 '(2 font-lock-comment-face))
2182 (list (concat "'" "\\("
2185 "\\|" "[0-9][0-9][0-9]"
2186 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2187 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2193 "\\(" "\\\\" "\\(.\\|\n\\)"
2196 '(0 font-lock-string-face))
2198 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2199 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2201 "\\_<\\(" fsharp-keywords "\\)\\_>")
2202 '(0 font-lock-keyword-face))
2203 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2204 '(0 font-lock-variable-name-face))
2206 (list (concat "\\_<"
2207 "\\(" "0[bB][01]+" "\\|"
2209 "0[xX][0-9a-fA-F]+" "\\)"
2210 "\\(" "lf\\|LF" "\\|"
2211 "[uU]?[ysnlL]?" "\\)"
2218 "\\([eE][-+]?[0-9]+\\)?"
2223 '(0 mdw-number-face))
2225 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2226 '(0 mdw-punct-face))))))
2228 (defun mdw-fontify-inferior-fsharp ()
2229 (mdw-fontify-fsharp)
2230 (setq font-lock-keywords
2231 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2232 (list "^>" '(0 font-lock-keyword-face)))
2233 font-lock-keywords)))
2235 ;;;--------------------------------------------------------------------------
2236 ;;; Go programming configuration.
2238 (defun mdw-fontify-go ()
2240 (make-local-variable 'font-lock-keywords)
2242 (mdw-regexps "break" "case" "chan" "const" "continue"
2243 "default" "defer" "else" "fallthrough" "for"
2244 "func" "go" "goto" "if" "import"
2245 "interface" "map" "package" "range" "return"
2246 "select" "struct" "switch" "type" "var"))
2248 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2249 "float32" "float64" "int" "uint8" "int16" "int32"
2250 "int64" "rune" "string" "uint" "uint8" "uint16"
2251 "uint32" "uint64" "uintptr" "void"
2252 "false" "iota" "nil" "true"
2254 "append" "cap" "copy" "delete" "imag" "len" "make"
2255 "new" "panic" "real" "recover")))
2257 (setq font-lock-keywords
2260 ;; Handle the keywords defined above.
2261 (list (concat "\\<\\(" go-keywords "\\)\\>")
2262 '(0 font-lock-keyword-face))
2263 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2264 '(0 font-lock-variable-name-face))
2266 ;; Strings and characters.
2268 "\\(" "[^\\']" "\\|"
2270 "\\(" "[abfnrtv\\'\"]" "\\|"
2271 "[0-7]\\{3\\}" "\\|"
2272 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2273 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2274 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2278 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2282 '(0 font-lock-string-face))
2284 ;; Handle numbers too.
2286 ;; The following isn't quite right, but it's close enough.
2287 (list (concat "\\<\\("
2288 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2289 "[0-9]+\\(\\.[0-9]*\\|\\)"
2290 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2291 '(0 mdw-number-face))
2293 ;; And anything else is punctuation.
2294 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2295 '(0 mdw-punct-face))))))
2297 ;;;--------------------------------------------------------------------------
2298 ;;; Rust programming configuration.
2300 (setq-default rust-indent-offset 2)
2302 (defun mdw-self-insert-and-indent (count)
2304 (self-insert-command count)
2305 (indent-according-to-mode))
2307 (defun mdw-fontify-rust ()
2309 ;; Hack syntax categories.
2310 (modify-syntax-entry ?= ".")
2312 ;; Fontify keywords and things.
2313 (make-local-variable 'font-lock-keywords)
2314 (let ((rust-keywords
2315 (mdw-regexps "abstract" "alignof" "as"
2316 "become" "box" "break"
2317 "const" "continue" "create"
2319 "else" "enum" "extern"
2320 "false" "final" "fn" "for"
2323 "macro" "match" "mod" "move" "mut"
2324 "offsetof" "override"
2327 "self" "sizeof" "static" "struct" "super"
2328 "true" "trait" "type" "typeof"
2329 "unsafe" "unsized" "use"
2334 (mdw-regexps "array" "pointer" "slice" "tuple"
2335 "bool" "true" "false"
2337 "i8" "i16" "i32" "i64" "isize"
2338 "u8" "u16" "u32" "u64" "usize"
2340 (setq font-lock-keywords
2343 ;; Handle the keywords defined above.
2344 (list (concat "\\<\\(" rust-keywords "\\)\\>")
2345 '(0 font-lock-keyword-face))
2346 (list (concat "\\<\\(" rust-builtins "\\)\\>")
2347 '(0 font-lock-variable-name-face))
2349 ;; Handle numbers too.
2350 (list (concat "\\<\\("
2352 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2356 "\\|" "\\(" "[0-9][0-9_]*"
2357 "\\|" "0x[0-9a-fA-F_]+"
2361 "\\([ui]\\(8\\|16\\|32\\|64\\|s\\|size\\)\\)?"
2363 '(0 mdw-number-face))
2365 ;; And anything else is punctuation.
2366 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2367 '(0 mdw-punct-face)))))
2369 ;; Hack key bindings.
2370 (local-set-key [?{] 'mdw-self-insert-and-indent)
2371 (local-set-key [?}] 'mdw-self-insert-and-indent))
2373 ;;;--------------------------------------------------------------------------
2374 ;;; Awk programming configuration.
2376 ;; Make Awk indentation nice.
2378 (mdw-define-c-style mdw-awk
2379 (c-basic-offset . 2)
2380 (c-offsets-alist (substatement-open . 0)
2381 (c-backslash-column . 72)
2382 (statement-cont . 0)
2383 (statement-case-intro . +)))
2384 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2386 ;; Declare Awk fontification style.
2388 (defun mdw-fontify-awk ()
2390 ;; Miscellaneous fiddling.
2391 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2393 ;; Now define things to be fontified.
2394 (make-local-variable 'font-lock-keywords)
2396 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2397 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2398 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2399 "RSTART" "RLENGTH" "RT" "SUBSEP"
2400 "atan2" "break" "close" "continue" "cos" "delete"
2401 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2402 "function" "gensub" "getline" "gsub" "if" "in"
2403 "index" "int" "length" "log" "match" "next" "rand"
2404 "return" "print" "printf" "sin" "split" "sprintf"
2405 "sqrt" "srand" "strftime" "sub" "substr" "system"
2406 "systime" "tolower" "toupper" "while")))
2408 (setq font-lock-keywords
2411 ;; Handle the keywords defined above.
2412 (list (concat "\\<\\(" c-keywords "\\)\\>")
2413 '(0 font-lock-keyword-face))
2415 ;; Handle numbers too.
2417 ;; The following isn't quite right, but it's close enough.
2418 (list (concat "\\<\\("
2419 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2420 "[0-9]+\\(\\.[0-9]*\\|\\)"
2421 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2423 '(0 mdw-number-face))
2425 ;; And anything else is punctuation.
2426 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2427 '(0 mdw-punct-face))))))
2429 ;;;--------------------------------------------------------------------------
2430 ;;; Perl programming style.
2432 ;; Perl indentation style.
2434 (setq perl-indent-level 2)
2436 (setq cperl-indent-level 2)
2437 (setq cperl-continued-statement-offset 2)
2438 (setq cperl-continued-brace-offset 0)
2439 (setq cperl-brace-offset -2)
2440 (setq cperl-brace-imaginary-offset 0)
2441 (setq cperl-label-offset 0)
2443 ;; Define perl fontification style.
2445 (defun mdw-fontify-perl ()
2447 ;; Miscellaneous fiddling.
2448 (modify-syntax-entry ?$ "\\")
2449 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2450 (modify-syntax-entry ?: "." font-lock-syntax-table)
2451 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2453 ;; Now define fontification things.
2454 (make-local-variable 'font-lock-keywords)
2455 (let ((perl-keywords
2462 "ge" "given" "gt" "goto"
2464 "last" "le" "local" "lt"
2469 "redo" "require" "return"
2471 "undef" "unless" "until" "use"
2474 (setq font-lock-keywords
2477 ;; Set up the keywords defined above.
2478 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2479 '(0 font-lock-keyword-face))
2481 ;; At least numbers are simpler than C.
2482 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2483 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2484 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2485 '(0 mdw-number-face))
2487 ;; And anything else is punctuation.
2488 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2489 '(0 mdw-punct-face))))))
2491 (defun perl-number-tests (&optional arg)
2492 "Assign consecutive numbers to lines containing `#t'. With ARG,
2493 strip numbers instead."
2496 (goto-char (point-min))
2497 (let ((i 0) (fmt (if arg "" " %4d")))
2498 (while (search-forward "#t" nil t)
2499 (delete-region (point) (line-end-position))
2501 (insert (format fmt i)))
2502 (goto-char (point-min))
2503 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2504 (replace-match (format "\\1%d" i))))))
2506 ;;;--------------------------------------------------------------------------
2507 ;;; Python programming style.
2509 (defun mdw-fontify-pythonic (keywords)
2511 ;; Miscellaneous fiddling.
2512 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2513 (setq indent-tabs-mode nil)
2515 ;; Now define fontification things.
2516 (make-local-variable 'font-lock-keywords)
2517 (setq font-lock-keywords
2520 ;; Set up the keywords defined above.
2521 (list (concat "\\_<\\(" keywords "\\)\\_>")
2522 '(0 font-lock-keyword-face))
2524 ;; At least numbers are simpler than C.
2525 (list (concat "\\_<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2526 "\\_<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2527 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
2528 '(0 mdw-number-face))
2530 ;; And anything else is punctuation.
2531 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2532 '(0 mdw-punct-face)))))
2534 ;; Define Python fontification styles.
2536 (defun mdw-fontify-python ()
2537 (mdw-fontify-pythonic
2538 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
2539 "del" "elif" "else" "except" "exec" "finally" "for"
2540 "from" "global" "if" "import" "in" "is" "lambda"
2541 "not" "or" "pass" "print" "raise" "return" "try"
2542 "while" "with" "yield")))
2544 (defun mdw-fontify-pyrex ()
2545 (mdw-fontify-pythonic
2546 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
2547 "ctypedef" "def" "del" "elif" "else" "except" "exec"
2548 "extern" "finally" "for" "from" "global" "if"
2549 "import" "in" "is" "lambda" "not" "or" "pass" "print"
2550 "raise" "return" "struct" "try" "while" "with"
2553 ;;;--------------------------------------------------------------------------
2554 ;;; Icon programming style.
2556 ;; Icon indentation style.
2558 (setq icon-brace-offset 0
2559 icon-continued-brace-offset 0
2560 icon-continued-statement-offset 2
2561 icon-indent-level 2)
2563 ;; Define Icon fontification style.
2565 (defun mdw-fontify-icon ()
2567 ;; Miscellaneous fiddling.
2568 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2570 ;; Now define fontification things.
2571 (make-local-variable 'font-lock-keywords)
2572 (let ((icon-keywords
2573 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
2574 "end" "every" "fail" "global" "if" "initial"
2575 "invocable" "link" "local" "next" "not" "of"
2576 "procedure" "record" "repeat" "return" "static"
2577 "suspend" "then" "to" "until" "while"))
2578 (preprocessor-keywords
2579 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
2580 "include" "line" "undef")))
2581 (setq font-lock-keywords
2584 ;; Set up the keywords defined above.
2585 (list (concat "\\<\\(" icon-keywords "\\)\\>")
2586 '(0 font-lock-keyword-face))
2588 ;; The things that Icon calls keywords.
2589 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
2591 ;; At least numbers are simpler than C.
2592 (list (concat "\\<[0-9]+"
2593 "\\([rR][0-9a-zA-Z]+\\|"
2594 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
2595 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
2596 '(0 mdw-number-face))
2599 (list (concat "^[ \t]*$[ \t]*\\<\\("
2600 preprocessor-keywords
2602 '(0 font-lock-keyword-face))
2604 ;; And anything else is punctuation.
2605 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2606 '(0 mdw-punct-face))))))
2608 ;;;--------------------------------------------------------------------------
2611 (defun mdw-fontify-asm ()
2612 (modify-syntax-entry ?' "\"")
2613 (modify-syntax-entry ?. "w")
2614 (modify-syntax-entry ?\n ">")
2615 (setf fill-prefix nil)
2616 (local-set-key ";" 'self-insert-command)
2617 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
2619 (defun mdw-asm-set-comment ()
2620 (modify-syntax-entry ?; "."
2622 (modify-syntax-entry asm-comment-char "<b")
2623 (setq comment-start (string asm-comment-char ? )))
2624 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
2625 (put 'asm-comment-char 'safe-local-variable 'characterp)
2627 ;;;--------------------------------------------------------------------------
2628 ;;; TCL configuration.
2630 (defun mdw-fontify-tcl ()
2631 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
2632 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2633 (make-local-variable 'font-lock-keywords)
2634 (setq font-lock-keywords
2636 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2637 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2638 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2639 '(0 mdw-number-face))
2640 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2641 '(0 mdw-punct-face)))))
2643 ;;;--------------------------------------------------------------------------
2644 ;;; Dylan programming configuration.
2646 (defun mdw-fontify-dylan ()
2648 (make-local-variable 'font-lock-keywords)
2650 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
2651 ;; hook, which undoes all of our configuration.
2652 (setq major-mode 'dylan-mode)
2653 (font-lock-set-defaults)
2655 (let* ((word "[-_a-zA-Z!*@<>$%]+")
2656 (dylan-keywords (mdw-regexps
2658 "C-address" "C-callable-wrapper" "C-function"
2659 "C-mapped-subtype" "C-pointer-type" "C-struct"
2660 "C-subtype" "C-union" "C-variable"
2662 "above" "abstract" "afterwards" "all"
2663 "begin" "below" "block" "by"
2664 "case" "class" "cleanup" "constant" "create"
2666 "else" "elseif" "end" "exception" "export"
2667 "finally" "for" "from" "function"
2670 "if" "in" "instance" "interface" "iterate"
2672 "let" "library" "local"
2673 "macro" "method" "module"
2676 "select" "slot" "subclass"
2678 "unless" "until" "use"
2679 "variable" "virtual"
2681 (sharp-keywords (mdw-regexps
2682 "all-keys" "key" "next" "rest" "include"
2684 (setq font-lock-keywords
2685 (list (list (concat "\\<\\(" dylan-keywords
2686 "\\|" "with\\(out\\)?-" word
2688 '(0 font-lock-keyword-face))
2689 (list (concat "\\<" word ":" "\\|"
2690 "#\\(" sharp-keywords "\\)\\>")
2691 '(0 font-lock-variable-name-face))
2693 "\\([-+]\\|\\<\\)[0-9]+" "\\("
2694 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
2697 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
2700 "\\|" "#x[0-9a-zA-Z]+"
2702 '(0 mdw-number-face))
2704 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
2705 "\\_<[-+*/=<>:&|]+\\_>"
2707 '(0 mdw-punct-face))))))
2709 ;;;--------------------------------------------------------------------------
2710 ;;; Algol 68 configuration.
2712 (setq a68-indent-step 2)
2714 (defun mdw-fontify-algol-68 ()
2716 ;; Fix up the syntax table.
2717 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
2718 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
2719 (modify-syntax-entry ch "." a68-mode-syntax-table))
2721 (make-local-variable 'font-lock-keywords)
2724 (let ((word "COMMENT"))
2725 (do ((regexp (concat "[^" (substring word 0 1) "]+")
2726 (concat regexp "\\|"
2727 (substring word 0 i)
2728 "[^" (substring word i (1+ i)) "]"))
2730 ((>= i (length word)) regexp)))))
2731 (setq font-lock-keywords
2732 (list (list (concat "\\<COMMENT\\>"
2733 "\\(" not-comment "\\)\\{0,5\\}"
2734 "\\(\\'\\|\\<COMMENT\\>\\)")
2735 '(0 font-lock-comment-face))
2736 (list (concat "\\<CO\\>"
2737 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
2738 "\\($\\|\\<CO\\>\\)")
2739 '(0 font-lock-comment-face))
2740 (list "\\<[A-Z_]+\\>"
2741 '(0 font-lock-keyword-face))
2745 "\\([eE][-+]?[0-9]+\\)?"
2747 '(0 mdw-number-face))
2748 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
2749 '(0 mdw-punct-face))))))
2751 ;;;--------------------------------------------------------------------------
2752 ;;; REXX configuration.
2754 (defun mdw-rexx-electric-* ()
2759 (defun mdw-rexx-indent-newline-indent ()
2762 (if abbrev-mode (expand-abbrev))
2763 (newline-and-indent))
2765 (defun mdw-fontify-rexx ()
2767 ;; Various bits of fiddling.
2768 (setq mdw-auto-indent nil)
2769 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
2770 (local-set-key [?*] 'mdw-rexx-electric-*)
2771 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
2773 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
2775 ;; Set up keywords and things for fontification.
2776 (make-local-variable 'font-lock-keywords-case-fold-search)
2777 (setq font-lock-keywords-case-fold-search t)
2779 (setq rexx-indent 2)
2780 (setq rexx-end-indent rexx-indent)
2781 (setq rexx-cont-indent rexx-indent)
2783 (make-local-variable 'font-lock-keywords)
2784 (let ((rexx-keywords
2785 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
2786 "else" "end" "engineering" "exit" "expose" "for"
2787 "forever" "form" "fuzz" "if" "interpret" "iterate"
2788 "leave" "linein" "name" "nop" "numeric" "off" "on"
2789 "options" "otherwise" "parse" "procedure" "pull"
2790 "push" "queue" "return" "say" "select" "signal"
2791 "scientific" "source" "then" "trace" "to" "until"
2792 "upper" "value" "var" "version" "when" "while"
2795 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
2796 "center" "center" "charin" "charout" "chars"
2797 "compare" "condition" "copies" "c2d" "c2x"
2798 "datatype" "date" "delstr" "delword" "d2c" "d2x"
2799 "errortext" "format" "fuzz" "insert" "lastpos"
2800 "left" "length" "lineout" "lines" "max" "min"
2801 "overlay" "pos" "queued" "random" "reverse" "right"
2802 "sign" "sourceline" "space" "stream" "strip"
2803 "substr" "subword" "symbol" "time" "translate"
2804 "trunc" "value" "verify" "word" "wordindex"
2805 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
2808 (setq font-lock-keywords
2811 ;; Set up the keywords defined above.
2812 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
2813 '(0 font-lock-keyword-face))
2815 ;; Fontify all symbols the same way.
2816 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
2817 "[A-Za-z0-9.!?_#@$]+\\)")
2818 '(0 font-lock-variable-name-face))
2820 ;; And everything else is punctuation.
2821 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2822 '(0 mdw-punct-face))))))
2824 ;;;--------------------------------------------------------------------------
2825 ;;; Standard ML programming style.
2827 (defun mdw-fontify-sml ()
2829 ;; Make underscore an honorary letter.
2830 (modify-syntax-entry ?' "w")
2833 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
2835 ;; Now define fontification things.
2836 (make-local-variable 'font-lock-keywords)
2838 (mdw-regexps "abstype" "and" "andalso" "as"
2841 "else" "end" "eqtype" "exception"
2842 "fn" "fun" "functor"
2844 "if" "in" "include" "infix" "infixr"
2847 "of" "op" "open" "orelse"
2849 "sharing" "sig" "signature" "struct" "structure"
2852 "where" "while" "with" "withtype")))
2854 (setq font-lock-keywords
2857 ;; Set up the keywords defined above.
2858 (list (concat "\\<\\(" sml-keywords "\\)\\>")
2859 '(0 font-lock-keyword-face))
2861 ;; At least numbers are simpler than C.
2862 (list (concat "\\<\\(\\~\\|\\)"
2863 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
2865 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
2866 "\\([eE]\\(\\~\\|\\)"
2867 "[0-9]+\\|\\)\\)\\)")
2868 '(0 mdw-number-face))
2870 ;; And anything else is punctuation.
2871 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2872 '(0 mdw-punct-face))))))
2874 ;;;--------------------------------------------------------------------------
2875 ;;; Haskell configuration.
2877 (defun mdw-fontify-haskell ()
2879 ;; Fiddle with syntax table to get comments right.
2880 (modify-syntax-entry ?' "_")
2881 (modify-syntax-entry ?- ". 12")
2882 (modify-syntax-entry ?\n ">")
2884 ;; Make punctuation be punctuation
2885 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
2887 ((>= i (length punct)))
2888 (modify-syntax-entry (aref punct i) ".")))
2891 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
2893 ;; Fiddle with fontification.
2894 (make-local-variable 'font-lock-keywords)
2895 (let ((haskell-keywords
2897 "case" "ccall" "class"
2898 "data" "default" "deriving" "do"
2902 "if" "import" "in" "infix" "infixl" "infixr" "instance"
2915 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
2916 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
2917 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
2918 "SP" "STX" "SUB" "SYN" "US" "VT")))
2920 (setq font-lock-keywords
2922 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
2926 '(0 font-lock-comment-face))
2927 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
2928 '(0 font-lock-keyword-face))
2929 (list (concat "'\\("
2933 "\\(" "[abfnrtv\\\"']" "\\|"
2934 "^" "\\(" control-sequences "\\|"
2935 "[]A-Z@[\\^_]" "\\)" "\\|"
2942 '(0 font-lock-string-face))
2943 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
2944 '(0 font-lock-variable-name-face))
2945 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
2946 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
2947 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
2948 '(0 mdw-number-face))
2949 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2950 '(0 mdw-punct-face))))))
2952 ;;;--------------------------------------------------------------------------
2953 ;;; Erlang configuration.
2955 (setq erlang-electric-commands nil)
2957 (defun mdw-fontify-erlang ()
2960 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
2962 ;; Fiddle with fontification.
2963 (make-local-variable 'font-lock-keywords)
2964 (let ((erlang-keywords
2965 (mdw-regexps "after" "and" "andalso"
2966 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
2967 "case" "catch" "cond"
2968 "div" "end" "fun" "if" "let" "not"
2970 "query" "receive" "rem" "try" "when" "xor")))
2972 (setq font-lock-keywords
2975 '(0 font-lock-comment-face))
2976 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
2977 '(0 font-lock-keyword-face))
2978 (list (concat "^-\\sw+\\>")
2979 '(0 font-lock-keyword-face))
2980 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
2981 '(0 mdw-number-face))
2982 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2983 '(0 mdw-punct-face))))))
2985 ;;;--------------------------------------------------------------------------
2986 ;;; Texinfo configuration.
2988 (defun mdw-fontify-texinfo ()
2991 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
2993 ;; Real fontification things.
2994 (make-local-variable 'font-lock-keywords)
2995 (setq font-lock-keywords
2998 ;; Environment names are keywords.
2999 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3000 '(2 font-lock-keyword-face))
3002 ;; Unmark escaped magic characters.
3003 (list "\\(@\\)\\([@{}]\\)"
3004 '(1 font-lock-keyword-face)
3005 '(2 font-lock-variable-name-face))
3007 ;; Make sure we get comments properly.
3008 (list "@c\\(\\|omment\\)\\( .*\\)?$"
3009 '(0 font-lock-comment-face))
3011 ;; Command names are keywords.
3012 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3013 '(0 font-lock-keyword-face))
3015 ;; Fontify TeX special characters as punctuation.
3017 '(0 mdw-punct-face)))))
3019 ;;;--------------------------------------------------------------------------
3020 ;;; TeX and LaTeX configuration.
3022 (defun mdw-fontify-tex ()
3023 (setq ispell-parser 'tex)
3026 ;; Don't make maths into a string.
3027 (modify-syntax-entry ?$ ".")
3028 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3029 (local-set-key [?$] 'self-insert-command)
3031 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3032 (local-set-key "\C-i" 'indent-relative)
3033 (setq indent-tabs-mode nil)
3036 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3038 ;; Real fontification things.
3039 (make-local-variable 'font-lock-keywords)
3040 (setq font-lock-keywords
3043 ;; Environment names are keywords.
3044 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3046 '(2 font-lock-keyword-face))
3048 ;; Suspended environment names are keywords too.
3049 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3051 '(3 font-lock-keyword-face))
3053 ;; Command names are keywords.
3054 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3055 '(0 font-lock-keyword-face))
3057 ;; Handle @/.../ for italics.
3058 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3059 ;; '(1 font-lock-keyword-face)
3060 ;; '(3 font-lock-keyword-face))
3062 ;; Handle @*...* for boldness.
3063 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3064 ;; '(1 font-lock-keyword-face)
3065 ;; '(3 font-lock-keyword-face))
3067 ;; Handle @`...' for literal syntax things.
3068 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3069 ;; '(1 font-lock-keyword-face)
3070 ;; '(3 font-lock-keyword-face))
3072 ;; Handle @<...> for nonterminals.
3073 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3074 ;; '(1 font-lock-keyword-face)
3075 ;; '(3 font-lock-keyword-face))
3077 ;; Handle other @-commands.
3078 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3079 ;; '(0 font-lock-keyword-face))
3081 ;; Make sure we get comments properly.
3083 '(0 font-lock-comment-face))
3085 ;; Fontify TeX special characters as punctuation.
3087 '(0 mdw-punct-face)))))
3089 (eval-after-load 'font-latex
3090 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3091 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3092 ;; The following block is an expansion of `jit-lock-force-redisplay'
3093 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3094 (with-current-buffer buf
3095 (let ((modified (buffer-modified-p)))
3097 (let ((buffer-undo-list t)
3098 (inhibit-read-only t)
3099 (inhibit-point-motion-hooks t)
3100 (inhibit-modification-hooks t)
3103 buffer-file-truename)
3104 (put-text-property start end 'fontified t))
3106 (restore-buffer-modified-p nil)))))))
3108 ;;;--------------------------------------------------------------------------
3111 (defun mdw-sgml-mode ()
3114 (mdw-standard-fill-prefix "")
3115 (make-local-variable 'sgml-delimiters)
3116 (setq sgml-delimiters
3117 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3118 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3119 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3120 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3121 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3122 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3123 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3125 (setq major-mode 'mdw-sgml-mode)
3126 (setq mode-name "[mdw] SGML")
3127 (run-hooks 'mdw-sgml-mode-hook))
3129 ;;;--------------------------------------------------------------------------
3130 ;;; Configuration files.
3132 (defvar mdw-conf-quote-normal nil
3133 "*Control syntax category of quote characters `\"' and `''.
3134 If this is `t', consider quote characters to be normal
3135 punctuation, as for `conf-quote-normal'. If this is `nil' then
3136 leave quote characters as quotes. If this is a list, then
3137 consider the quote characters in the list to be normal
3138 punctuation. If this is a single quote character, then consider
3139 that character only to be normal punctuation.")
3140 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3141 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3142 (or (booleanp value)
3143 (every (lambda (v) (memq v '(?\" ?')))
3144 (if (listp value) value (list value)))))
3145 (put 'mdw-conf-quote-normal 'safe-local-variable
3146 'mdw-conf-quote-normal-acceptable-value-p)
3148 (defun mdw-fix-up-quote ()
3149 "Apply the setting of `mdw-conf-quote-normal'."
3150 (let ((flag mdw-conf-quote-normal))
3152 (conf-quote-normal t))
3156 (let ((table (copy-syntax-table (syntax-table))))
3157 (mapc (lambda (ch) (modify-syntax-entry ch "." table))
3158 (if (listp flag) flag (list flag)))
3159 (set-syntax-table table)
3160 (and font-lock-mode (font-lock-fontify-buffer)))))))
3161 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t)
3163 ;;;--------------------------------------------------------------------------
3166 (defun mdw-setup-sh-script-mode ()
3168 ;; Fetch the shell interpreter's name.
3169 (let ((shell-name sh-shell-file))
3171 ;; Try reading the hash-bang line.
3173 (goto-char (point-min))
3174 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3175 (setq shell-name (match-string 1))))
3177 ;; Now try to set the shell.
3179 ;; Don't let `sh-set-shell' bugger up my script.
3180 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3181 (sh-set-shell shell-name)))
3183 ;; Don't insert here-document scaffolding automatically.
3184 (local-set-key "<" 'self-insert-command)
3186 ;; Now enable my keys and the fontification.
3187 (mdw-misc-mode-config)
3189 ;; Set the indentation level correctly.
3190 (setq sh-indentation 2)
3191 (setq sh-basic-offset 2))
3193 (setq sh-shell-file "/bin/sh")
3195 ;; Awful hacking to override the shell detection for particular scripts.
3196 (defmacro define-custom-shell-mode (name shell)
3199 (set (make-local-variable 'sh-shell-file) ,shell)
3201 (define-custom-shell-mode bash-mode "/bin/bash")
3202 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3203 (put 'sh-shell-file 'permanent-local t)
3205 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3206 (eval-after-load "sh-script"
3207 '(or (assq 'rc sh-mode-syntax-table-input)
3224 (assoc (assq 'rc sh-mode-syntax-table-input)))
3227 (setq sh-mode-syntax-table-input
3228 (cons (cons 'rc frag)
3229 sh-mode-syntax-table-input))))))
3231 ;;;--------------------------------------------------------------------------
3232 ;;; Emacs shell mode.
3234 (defun mdw-eshell-prompt ()
3235 (let ((left "[") (right "]"))
3236 (when (= (user-uid) 0)
3237 (setq left "«" right "»"))
3240 (replace-regexp-in-string "\\..*$" "" (system-name)))
3242 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3243 (home (expand-file-name "~")) (nhome (length home)))
3244 (if (and (>= npwd nhome)
3246 (= (elt pwd nhome) ?/))
3247 (string= (substring pwd 0 nhome) home))
3248 (concat "~" (substring pwd (length home)))
3251 (setq eshell-prompt-function 'mdw-eshell-prompt)
3252 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3254 (defun eshell/e (file) (find-file file) nil)
3255 (defun eshell/ee (file) (find-file-other-window file) nil)
3256 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3258 (mdw-define-face eshell-prompt (t :weight bold))
3259 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3260 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3261 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3262 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3263 (mdw-define-face eshell-ls-executable (t :weight bold))
3264 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3265 (mdw-define-face eshell-ls-readonly (t nil))
3266 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3268 ;;;--------------------------------------------------------------------------
3269 ;;; Messages-file mode.
3271 (defun messages-mode-guts ()
3272 (setq messages-mode-syntax-table (make-syntax-table))
3273 (set-syntax-table messages-mode-syntax-table)
3274 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3275 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3276 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3277 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3278 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3279 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3280 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3281 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3282 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3283 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3284 (make-local-variable 'comment-start)
3285 (make-local-variable 'comment-end)
3286 (make-local-variable 'indent-line-function)
3287 (setq indent-line-function 'indent-relative)
3288 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3289 (make-local-variable 'font-lock-defaults)
3290 (make-local-variable 'messages-mode-keywords)
3292 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3293 "export" "enum" "fixed-octetstring" "flags"
3294 "harmless" "map" "nested" "optional"
3295 "optional-tagged" "package" "primitive"
3296 "primitive-nullfree" "relaxed[ \t]+enum"
3297 "set" "table" "tagged-optional" "union"
3298 "variadic" "vector" "version" "version-tag")))
3299 (setq messages-mode-keywords
3301 (list (concat "\\<\\(" keywords "\\)\\>:")
3302 '(0 font-lock-keyword-face))
3303 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
3304 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
3305 (0 font-lock-variable-name-face))
3306 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
3307 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3308 (0 mdw-punct-face)))))
3309 (setq font-lock-defaults
3310 '(messages-mode-keywords nil nil nil nil))
3311 (run-hooks 'messages-file-hook))
3313 (defun messages-mode ()
3316 (setq major-mode 'messages-mode)
3317 (setq mode-name "Messages")
3318 (messages-mode-guts)
3319 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
3320 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
3321 (setq comment-start "# ")
3322 (setq comment-end "")
3323 (run-hooks 'messages-mode-hook))
3325 (defun cpp-messages-mode ()
3328 (setq major-mode 'cpp-messages-mode)
3329 (setq mode-name "CPP Messages")
3330 (messages-mode-guts)
3331 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
3332 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
3333 (setq comment-start "/* ")
3334 (setq comment-end " */")
3335 (let ((preprocessor-keywords
3336 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3337 "ident" "if" "ifdef" "ifndef" "import" "include"
3338 "line" "pragma" "unassert" "undef" "warning")))
3339 (setq messages-mode-keywords
3340 (append (list (list (concat "^[ \t]*\\#[ \t]*"
3341 "\\(include\\|import\\)"
3342 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
3343 '(2 font-lock-string-face))
3344 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3345 preprocessor-keywords
3346 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3347 '(1 font-lock-keyword-face)))
3348 messages-mode-keywords)))
3349 (run-hooks 'cpp-messages-mode-hook))
3351 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
3352 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
3353 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
3355 ;;;--------------------------------------------------------------------------
3356 ;;; Messages-file mode.
3358 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
3359 "Face to use for subsittution directives.")
3360 (make-face 'mallow-driver-substitution-face)
3361 (defvar mallow-driver-text-face 'mallow-driver-text-face
3362 "Face to use for body text.")
3363 (make-face 'mallow-driver-text-face)
3365 (defun mallow-driver-mode ()
3368 (setq major-mode 'mallow-driver-mode)
3369 (setq mode-name "Mallow driver")
3370 (setq mallow-driver-mode-syntax-table (make-syntax-table))
3371 (set-syntax-table mallow-driver-mode-syntax-table)
3372 (make-local-variable 'comment-start)
3373 (make-local-variable 'comment-end)
3374 (make-local-variable 'indent-line-function)
3375 (setq indent-line-function 'indent-relative)
3376 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3377 (make-local-variable 'font-lock-defaults)
3378 (make-local-variable 'mallow-driver-mode-keywords)
3380 (mdw-regexps "each" "divert" "file" "if"
3381 "perl" "set" "string" "type" "write")))
3382 (setq mallow-driver-mode-keywords
3384 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
3385 '(0 font-lock-keyword-face))
3386 (list "^%\\s *\\(#.*\\|\\)$"
3387 '(0 font-lock-comment-face))
3389 '(0 font-lock-keyword-face))
3390 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
3392 '(0 mallow-driver-substitution-face t)))))
3393 (setq font-lock-defaults
3394 '(mallow-driver-mode-keywords nil nil nil nil))
3395 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
3396 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
3397 (setq comment-start "%# ")
3398 (setq comment-end "")
3399 (run-hooks 'mallow-driver-mode-hook))
3401 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
3403 ;;;--------------------------------------------------------------------------
3406 (defun nfast-debug-mode ()
3409 (setq major-mode 'nfast-debug-mode)
3410 (setq mode-name "NFast debug")
3411 (setq messages-mode-syntax-table (make-syntax-table))
3412 (set-syntax-table messages-mode-syntax-table)
3413 (make-local-variable 'font-lock-defaults)
3414 (make-local-variable 'nfast-debug-mode-keywords)
3415 (setq truncate-lines t)
3416 (setq nfast-debug-mode-keywords
3418 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
3419 (0 font-lock-keyword-face))
3420 (list (concat "^[ \t]+\\(\\("
3421 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3422 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3424 "[0-9a-fA-F]+\\)[ \t]*$")
3425 '(0 mdw-number-face))
3426 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
3427 (1 font-lock-keyword-face))
3428 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
3429 (1 font-lock-warning-face))
3430 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
3432 (list (concat "^[ \t]+\\.cmd=[ \t]+"
3433 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
3434 '(1 font-lock-keyword-face))
3435 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
3436 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
3437 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
3438 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
3439 (setq font-lock-defaults
3440 '(nfast-debug-mode-keywords nil nil nil nil))
3441 (run-hooks 'nfast-debug-mode-hook))
3443 ;;;--------------------------------------------------------------------------
3444 ;;; Other languages.
3448 (defun mdw-setup-smalltalk ()
3449 (and mdw-auto-indent
3450 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
3451 (make-local-variable 'mdw-auto-indent)
3452 (setq mdw-auto-indent nil)
3453 (local-set-key "\C-i" 'smalltalk-reindent))
3455 (defun mdw-fontify-smalltalk ()
3456 (make-local-variable 'font-lock-keywords)
3457 (setq font-lock-keywords
3459 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
3460 '(0 font-lock-keyword-face))
3461 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3462 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3463 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3464 '(0 mdw-number-face))
3465 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3466 '(0 mdw-punct-face)))))
3470 ;; Unpleasant bodge.
3471 (unless (boundp 'slime-repl-mode-map)
3472 (setq slime-repl-mode-map (make-sparse-keymap)))
3474 (defun mdw-indent-newline-and-indent ()
3476 (indent-for-tab-command)
3477 (newline-and-indent))
3479 (eval-after-load "cl-indent"
3481 (mapc #'(lambda (pair)
3483 'common-lisp-indent-function
3485 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
3486 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
3488 (defun mdw-common-lisp-indent ()
3489 (make-local-variable 'lisp-indent-function)
3490 (setq lisp-indent-function 'common-lisp-indent-function))
3492 (setq lisp-simple-loop-indentation 2
3493 lisp-loop-keyword-indentation 6
3494 lisp-loop-forms-indentation 6)
3496 (defun mdw-fontify-lispy ()
3499 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
3501 ;; Not much fontification needed.
3502 (make-local-variable 'font-lock-keywords)
3503 (setq font-lock-keywords
3504 (list (list (concat "\\("
3506 "\\(" "[0-9]+/[0-9]+"
3507 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
3509 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
3514 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
3515 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
3516 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
3517 "\\|" "[0-9]+" "r" "[-+]?"
3518 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
3521 '(0 mdw-number-face))
3522 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3523 '(0 mdw-punct-face)))))
3525 (defun comint-send-and-indent ()
3528 (and mdw-auto-indent
3529 (indent-for-tab-command)))
3531 (defun mdw-setup-m4 ()
3533 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
3534 ;; annoying: fix it.
3535 (modify-syntax-entry ?{ "(")
3536 (modify-syntax-entry ?} ")")
3539 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
3541 ;;;--------------------------------------------------------------------------
3544 (defun mdw-text-mode ()
3545 (setq fill-column 72)
3547 (mdw-standard-fill-prefix
3548 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
3551 ;;;--------------------------------------------------------------------------
3552 ;;; Outline and hide/show modes.
3554 (defun mdw-outline-collapse-all ()
3555 "Completely collapse everything in the entire buffer."
3558 (goto-char (point-min))
3559 (while (< (point) (point-max))
3563 (setq hs-hide-comments-when-hiding-all nil)
3565 (defadvice hs-hide-all (after hide-first-comment activate)
3566 (save-excursion (hs-hide-initial-comment-block)))
3568 ;;;--------------------------------------------------------------------------
3571 (defun mdw-sh-mode-setup ()
3572 (local-set-key [?\C-a] 'comint-bol)
3573 (add-hook 'comint-output-filter-functions
3574 'comint-watch-for-password-prompt))
3576 (defun mdw-term-mode-setup ()
3577 (setq term-prompt-regexp shell-prompt-pattern)
3578 (make-local-variable 'mouse-yank-at-point)
3579 (make-local-variable 'transient-mark-mode)
3580 (setq mouse-yank-at-point t)
3584 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
3585 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
3586 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
3587 (defun term-send-meta-meta-something ()
3589 (term-send-raw-string "\e\e")
3591 (eval-after-load 'term
3593 (define-key term-raw-map [?\e ?\e] nil)
3594 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
3595 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
3596 (define-key term-raw-map [M-right] 'term-send-meta-right)
3597 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
3598 (define-key term-raw-map [M-left] 'term-send-meta-left)
3599 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
3601 (defadvice term-exec (before program-args-list compile activate)
3602 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
3603 This allows you to pass a list of arguments through `ansi-term'."
3604 (let ((program (ad-get-arg 2)))
3607 (ad-set-arg 2 (car program))
3608 (ad-set-arg 4 (cdr program))))))
3611 "Open a terminal containing an ssh session to the HOST."
3612 (interactive "sHost: ")
3613 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
3615 (defvar git-grep-command
3616 "env PAGER=cat git grep --no-color -nH -e "
3617 "*The default command for \\[git-grep].")
3619 (defvar git-grep-history nil)
3621 (defun git-grep (command-args)
3622 "Run `git grep' with user-specified args and collect output in a buffer."
3624 (list (read-shell-command "Run git grep (like this): "
3625 git-grep-command 'git-grep-history)))
3626 (grep command-args))
3628 (setq magit-diff-refine-hunk 'all
3629 magit-view-git-manual-method 'man
3630 magit-wip-after-save-local-mode-lighter ""
3631 magit-wip-after-apply-mode-lighter ""
3632 magit-wip-before-change-mode-lighter "")
3633 (eval-after-load "magit"
3634 '(progn (global-magit-file-mode 1)
3635 (magit-wip-after-save-mode 1)
3636 (magit-wip-after-apply-mode 1)
3637 (magit-wip-before-change-mode 1)
3638 (add-to-list 'magit-no-confirm 'safe-with-wip)))
3640 ;;;--------------------------------------------------------------------------
3641 ;;; Inferior Emacs Lisp.
3643 (setq comint-prompt-read-only t)
3645 (eval-after-load "comint"
3647 (define-key comint-mode-map "\C-w" 'comint-kill-region)
3648 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
3650 (eval-after-load "ielm"
3652 (define-key ielm-map "\C-w" 'comint-kill-region)
3653 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
3655 ;;;----- That's all, folks --------------------------------------------------
3657 (provide 'dot-emacs)