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))))))))
726 (defun mdw-check-autorevert ()
727 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
728 This takes into consideration whether it's been found using
729 tramp, which seems to get itself into a twist."
730 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
732 ((and (buffer-file-name)
733 (fboundp 'tramp-tramp-file-p)
734 (tramp-tramp-file-p (buffer-file-name)))
735 (unless global-auto-revert-ignore-buffer
736 (setq global-auto-revert-ignore-buffer 'tramp)))
737 ((eq global-auto-revert-ignore-buffer 'tramp)
738 (setq global-auto-revert-ignore-buffer nil))))
740 (defadvice find-file (after mdw-autorevert activate)
741 (mdw-check-autorevert))
742 (defadvice write-file (after mdw-autorevert activate)
743 (mdw-check-autorevert))
745 ;;;--------------------------------------------------------------------------
748 (defadvice dired-maybe-insert-subdir
749 (around mdw-marked-insertion first activate)
750 "The DIRNAME may be a list of directory names to insert.
751 Interactively, if files are marked, then insert all of them.
752 With a numeric prefix argument, select that many entries near
753 point; with a non-numeric prefix argument, prompt for listing
756 (list (dired-get-marked-files nil
757 (and (integerp current-prefix-arg)
760 (and current-prefix-arg
761 (not (integerp current-prefix-arg))
762 (read-string "Switches for listing: "
763 (or dired-subdir-switches
764 dired-actual-switches)))))
765 (let ((dirs (ad-get-arg 0)))
766 (dolist (dir (if (listp dirs) dirs (list dirs)))
770 ;;;--------------------------------------------------------------------------
773 (defun mdw-w3m-browse-url (url &optional new-session-p)
774 "Invoke w3m on the URL in its current window, or at least a different one.
775 If NEW-SESSION-P, start a new session."
776 (interactive "sURL: \nP")
778 (let ((window (selected-window)))
781 (select-window (or (and (not new-session-p)
782 (get-buffer-window "*w3m*"))
784 (if (one-window-p t) (split-window))
786 (w3m-browse-url url new-session-p))
787 (select-window window)))))
789 (defvar mdw-good-url-browsers
792 (w3m . mdw-w3m-browse-url)
794 "List of good browsers for mdw-good-url-browsers.
795 Each item is a browser function name, or a cons (CHECK . FUNC).
796 A symbol FOO stands for (FOO . FOO).")
798 (defun mdw-good-url-browser ()
799 "Return a good URL browser.
800 Trundle the list of such things, finding the first item for which
801 CHECK is fboundp, and returning the correponding FUNC."
802 (let ((bs mdw-good-url-browsers) b check func answer)
803 (while (and bs (not answer))
807 (setq check (car b) func (cdr b))
808 (setq check b func b))
813 (eval-after-load "w3m-search"
817 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
818 ("gd" "Google Directory"
819 "http://www.google.com/search?cat=gwd/Top&q=%s")
820 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
821 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
822 ("gi" "Images" "http://images.google.com/images?q=%s")
824 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
826 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
827 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
828 ("nc-wiki" "nCipher wiki"
829 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
830 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
831 ("lp" "Launchpad bug by number"
832 "https://bugs.launchpad.net/bugs/%s")
833 ("lppkg" "Launchpad bugs by package"
834 "https://bugs.launchpad.net/%s")
836 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
837 ("debbug" "Debian bug by number"
838 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
839 ("debbugpkg" "Debian bugs by package"
840 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
841 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
842 (add-to-list 'w3m-search-engine-alist
843 (list (cadr item) (caddr item) nil))
844 (add-to-list 'w3m-uri-replace-alist
845 (list (concat "\\`" (car item) ":")
846 'w3m-search-uri-replace
849 ;;;--------------------------------------------------------------------------
850 ;;; Paragraph filling.
854 (defvar mdw-fill-prefix nil
855 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
856 If there's no fill prefix currently set (by the `fill-prefix'
857 variable) and there's a match from one of the regexps here, it
858 gets used to set the fill-prefix for the current operation.
860 The variable is a list of items of the form `REGEXP . PREFIX'; if
861 the REGEXP matches, the PREFIX is used to set the fill prefix.
862 It in turn is a list of things:
864 STRING -- insert a literal string
865 (match . N) -- insert the thing matched by bracketed subexpression N
866 (pad . N) -- a string of whitespace the same width as subexpression N
867 (expr . FORM) -- the result of evaluating FORM")
869 (make-variable-buffer-local 'mdw-fill-prefix)
871 (defvar mdw-hanging-indents
873 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
876 "*Standard regexp matching parts of a hanging indent.
877 This is mainly useful in `auto-fill-mode'.")
879 ;; Setting things up.
881 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
883 ;; Utility functions.
885 (defun mdw-maybe-tabify (s)
886 "Tabify or untabify the string S, according to `indent-tabs-mode'."
887 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
891 (let ((start (point-min)) (end (point-max)))
892 (funcall tabfun (point-min) (point-max))
893 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
895 (defun mdw-examine-fill-prefixes (l)
896 "Given a list of dynamic fill prefixes, pick one which matches
897 context and return the static fill prefix to use. Point must be
898 at the start of a line, and match data must be saved."
900 ((looking-at (car (car l)))
901 (mdw-maybe-tabify (apply #'concat
902 (mapcar #'mdw-do-prefix-match
904 (t (mdw-examine-fill-prefixes (cdr l)))))
906 (defun mdw-maybe-car (p)
907 "If P is a pair, return (car P), otherwise just return P."
908 (if (consp p) (car p) p))
910 (defun mdw-padding (s)
911 "Return a string the same width as S but made entirely from whitespace."
912 (let* ((l (length s)) (i 0) (n (make-string l ? )))
919 (defun mdw-do-prefix-match (m)
920 "Expand a dynamic prefix match element.
921 See `mdw-fill-prefix' for details."
922 (cond ((not (consp m)) (format "%s" m))
923 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
924 ((eq (car m) 'pad) (mdw-padding (match-string
925 (mdw-maybe-car (cdr m)))))
926 ((eq (car m) 'eval) (eval (cdr m)))
929 (defun mdw-choose-dynamic-fill-prefix ()
930 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
931 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
932 ((not mdw-fill-prefix) fill-prefix)
936 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
938 (defun do-auto-fill ()
939 "Handle auto-filling, working out a dynamic fill prefix in the
940 case where there isn't a sensible static one."
941 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
944 (defun mdw-fill-paragraph ()
945 "Fill paragraph, getting a dynamic fill prefix."
947 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
948 (fill-paragraph nil)))
950 (defun mdw-standard-fill-prefix (rx &optional mat)
951 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
952 This is just a short-cut for setting the thing by hand, and by
953 design it doesn't cope with anything approximating a complicated
955 (setq mdw-fill-prefix
956 `((,(concat rx mdw-hanging-indents)
958 (pad . ,(or mat 2))))))
960 ;;;--------------------------------------------------------------------------
961 ;;; Other common declarations.
963 ;; Common mode settings.
965 (defvar mdw-auto-indent t
966 "Whether to indent automatically after a newline.")
968 (defun mdw-whitespace-mode (&optional arg)
969 "Turn on/off whitespace mode, but don't highlight trailing space."
971 (when (and (boundp 'whitespace-style)
972 (fboundp 'whitespace-mode))
973 (let ((whitespace-style (remove 'trailing whitespace-style)))
974 (whitespace-mode arg))
975 (setq show-trailing-whitespace whitespace-mode)))
977 (defvar mdw-do-misc-mode-hacking nil)
979 (defun mdw-misc-mode-config ()
981 (cond ((eq major-mode 'lisp-mode)
982 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
983 ((or (eq major-mode 'slime-repl-mode)
984 (eq major-mode 'asm-mode))
987 (local-set-key "\C-m" 'newline-and-indent))))
988 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
989 (local-set-key [C-return] 'newline)
990 (make-local-variable 'page-delimiter)
991 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
992 (setq comment-column 40)
994 (setq fill-column mdw-text-width)
995 (and (fboundp 'gtags-mode)
997 (if (fboundp 'hs-minor-mode)
998 (trap (hs-minor-mode t))
999 (outline-minor-mode t))
1001 (trap (turn-on-font-lock)))
1003 (defun mdw-post-local-vars-misc-mode-config ()
1004 (setq whitespace-line-column mdw-text-width)
1005 (when (and mdw-do-misc-mode-hacking
1006 (not buffer-read-only))
1007 (setq show-trailing-whitespace t)
1008 (mdw-whitespace-mode 1)))
1009 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1011 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1012 `(progn ,@(mapcar (lambda (func)
1014 (after mdw-angry-fruit-salad activate)
1015 (when mdw-do-misc-mode-hacking
1016 (setq show-trailing-whitespace
1017 (not buffer-read-only))
1018 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1020 (mdw-advise-update-angry-fruit-salad toggle-read-only
1026 (eval-after-load 'gtags
1028 (dolist (key '([mouse-2] [mouse-3]))
1029 (define-key gtags-mode-map key nil))
1030 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1031 (define-key gtags-select-mode-map [C-S-mouse-2]
1032 'gtags-select-tag-by-event)
1033 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1034 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1036 ;; Backup file handling.
1038 (defvar mdw-backup-disable-regexps nil
1039 "*List of regular expressions: if a file name matches any of
1040 these then the file is not backed up.")
1042 (defun mdw-backup-enable-predicate (name)
1043 "[mdw]'s default backup predicate.
1044 Allows a backup if the standard predicate would allow it, and it
1045 doesn't match any of the regular expressions in
1046 `mdw-backup-disable-regexps'."
1047 (and (normal-backup-enable-predicate name)
1048 (let ((answer t) (list mdw-backup-disable-regexps))
1051 (if (string-match (car list) name)
1053 (setq list (cdr list)))
1055 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1059 (defun mdw-last-one-out-turn-off-the-lights (frame)
1060 "Disconnect from an X display if this was the last frame on that display."
1061 (let ((frame-display (frame-parameter frame 'display)))
1062 (when (and frame-display
1063 (eq window-system 'x)
1064 (not (some (lambda (fr)
1065 (and (not (eq fr frame))
1066 (string= (frame-parameter fr 'display)
1069 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1070 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1072 ;;;--------------------------------------------------------------------------
1075 (defvar mdw-point-overlay
1076 (let ((ov (make-overlay 0 0))
1078 (overlay-put ov 'priority 2)
1079 (put-text-property 0 1 'display '(left-fringe vertical-bar) s)
1080 (overlay-put ov 'before-string s)
1083 "An overlay used for showing where point is in the selected window.")
1085 (defun mdw-remove-point-overlay ()
1086 "Remove the current-point overlay."
1087 (delete-overlay mdw-point-overlay))
1089 (defun mdw-update-point-overlay ()
1090 "Mark the current point position with an overlay."
1091 (if (not mdw-point-overlay-mode)
1092 (mdw-remove-point-overlay)
1093 (overlay-put mdw-point-overlay 'window (selected-window))
1095 (move-overlay mdw-point-overlay
1096 (point) (1+ (point)) (current-buffer))
1097 (move-overlay mdw-point-overlay
1098 (1- (point)) (point) (current-buffer)))))
1100 (defvar mdw-point-overlay-buffers nil
1101 "List of buffers using `mdw-point-overlay-mode'.")
1103 (define-minor-mode mdw-point-overlay-mode
1104 "Indicate current line with an overlay."
1106 (let ((buffer (current-buffer)))
1107 (setq mdw-point-overlay-buffers
1108 (mapcan (lambda (buf)
1109 (if (and (buffer-live-p buf)
1110 (not (eq buf buffer)))
1112 mdw-point-overlay-buffers))
1113 (if mdw-point-overlay-mode
1114 (setq mdw-point-overlay-buffers
1115 (cons buffer mdw-point-overlay-buffers))))
1116 (cond (mdw-point-overlay-buffers
1117 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1118 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1120 (mdw-remove-point-overlay)
1121 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1122 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1124 (define-globalized-minor-mode mdw-global-point-overlay-mode
1125 mdw-point-overlay-mode
1126 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1128 ;;;--------------------------------------------------------------------------
1129 ;;; Fullscreen-ness.
1131 (defvar mdw-full-screen-parameters
1132 '((menu-bar-lines . 0)
1133 ;(vertical-scroll-bars . nil)
1135 "Frame parameters to set when making a frame fullscreen.")
1137 (defvar mdw-full-screen-save
1139 "Extra frame parameters to save when setting fullscreen.")
1141 (defun mdw-toggle-full-screen (&optional frame)
1142 "Show the FRAME fullscreen."
1145 (cond ((frame-parameter frame 'fullscreen)
1146 (set-frame-parameter frame 'fullscreen nil)
1147 (modify-frame-parameters
1149 (or (frame-parameter frame 'mdw-full-screen-saved)
1150 (mapcar (lambda (assoc)
1151 (assq (car assoc) default-frame-alist))
1152 mdw-full-screen-parameters))))
1154 (let ((saved (mapcar (lambda (param)
1155 (cons param (frame-parameter frame param)))
1156 (append (mapcar #'car
1157 mdw-full-screen-parameters)
1158 mdw-full-screen-save))))
1159 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1160 (modify-frame-parameters frame mdw-full-screen-parameters)
1161 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1163 ;;;--------------------------------------------------------------------------
1164 ;;; General fontification.
1166 (make-face 'mdw-virgin-face)
1168 (defmacro mdw-define-face (name &rest body)
1169 "Define a face, and make sure it's actually set as the definition."
1173 (copy-face 'mdw-virgin-face ',name)
1174 (defvar ,name ',name)
1175 (put ',name 'face-defface-spec ',body)
1176 (face-spec-set ',name ',body nil)))
1178 (mdw-define-face default
1179 (((type w32)) :family "courier new" :height 85)
1180 (((type x)) :family "6x13" :foundry "trad" :height 130)
1181 (((type color)) :foreground "white" :background "black")
1183 (mdw-define-face fixed-pitch
1184 (((type w32)) :family "courier new" :height 85)
1185 (((type x)) :family "6x13" :foundry "trad" :height 130)
1186 (t :foreground "white" :background "black"))
1187 (if (mdw-emacs-version-p 23)
1188 (mdw-define-face variable-pitch
1189 (((type x)) :family "sans" :height 100))
1190 (mdw-define-face variable-pitch
1191 (((type x)) :family "helvetica" :height 90)))
1192 (mdw-define-face region
1193 (((type tty) (class color)) :background "blue")
1194 (((type tty) (class mono)) :inverse-video t)
1195 (t :background "grey30"))
1196 (mdw-define-face match
1197 (((type tty) (class color)) :background "blue")
1198 (((type tty) (class mono)) :inverse-video t)
1199 (t :background "blue"))
1200 (mdw-define-face mc/cursor-face
1201 (((type tty) (class mono)) :inverse-video t)
1202 (t :background "red"))
1203 (mdw-define-face minibuffer-prompt
1205 (mdw-define-face mode-line
1206 (((class color)) :foreground "blue" :background "yellow"
1207 :box (:line-width 1 :style released-button))
1208 (t :inverse-video t))
1209 (mdw-define-face mode-line-inactive
1210 (((class color)) :foreground "yellow" :background "blue"
1211 :box (:line-width 1 :style released-button))
1212 (t :inverse-video t))
1213 (mdw-define-face nobreak-space
1215 (t :inherit escape-glyph :underline t))
1216 (mdw-define-face scroll-bar
1217 (t :foreground "black" :background "lightgrey"))
1218 (mdw-define-face fringe
1219 (t :foreground "yellow"))
1220 (mdw-define-face show-paren-match
1221 (((class color)) :background "darkgreen")
1223 (mdw-define-face show-paren-mismatch
1224 (((class color)) :background "red")
1225 (t :inverse-video t))
1226 (mdw-define-face highlight
1227 (((type x) (class color)) :background "DarkSeaGreen4")
1228 (((type tty) (class color)) :background "cyan")
1229 (t :inverse-video t))
1231 (mdw-define-face holiday-face
1232 (t :background "red"))
1233 (mdw-define-face calendar-today-face
1234 (t :foreground "yellow" :weight bold))
1236 (mdw-define-face comint-highlight-prompt
1238 (mdw-define-face comint-highlight-input
1241 (mdw-define-face dired-directory
1242 (t :foreground "cyan" :weight bold))
1243 (mdw-define-face dired-symlink
1244 (t :foreground "cyan"))
1245 (mdw-define-face dired-perm-write
1248 (mdw-define-face trailing-whitespace
1249 (((class color)) :background "red")
1250 (t :inverse-video t))
1251 (mdw-define-face whitespace-line
1252 (((class color)) :background "darkred")
1253 (t :inverse-video t))
1254 (mdw-define-face mdw-punct-face
1255 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
1256 (mdw-define-face mdw-number-face
1257 (t :foreground "yellow"))
1258 (mdw-define-face mdw-trivial-face)
1259 (mdw-define-face font-lock-function-name-face
1261 (mdw-define-face font-lock-keyword-face
1263 (mdw-define-face font-lock-constant-face
1265 (mdw-define-face font-lock-builtin-face
1267 (mdw-define-face font-lock-type-face
1268 (t :weight bold :slant italic))
1269 (mdw-define-face font-lock-reference-face
1271 (mdw-define-face font-lock-variable-name-face
1273 (mdw-define-face font-lock-comment-delimiter-face
1274 (((class mono)) :weight bold)
1275 (((type tty) (class color)) :foreground "green")
1276 (t :slant italic :foreground "SeaGreen1"))
1277 (mdw-define-face font-lock-comment-face
1278 (((class mono)) :weight bold)
1279 (((type tty) (class color)) :foreground "green")
1280 (t :slant italic :foreground "SeaGreen1"))
1281 (mdw-define-face font-lock-string-face
1282 (((class mono)) :weight bold)
1283 (((class color)) :foreground "SkyBlue1"))
1285 (mdw-define-face message-separator
1286 (t :background "red" :foreground "white" :weight bold))
1287 (mdw-define-face message-cited-text
1288 (default :slant italic)
1289 (((type tty)) :foreground "cyan") (t :foreground "SkyBlue1"))
1290 (mdw-define-face message-header-cc
1291 (default :slant italic)
1292 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1293 (mdw-define-face message-header-newsgroups
1294 (default :slant italic)
1295 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1296 (mdw-define-face message-header-subject
1297 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1298 (mdw-define-face message-header-to
1299 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1300 (mdw-define-face message-header-xheader
1301 (default :slant italic)
1302 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1303 (mdw-define-face message-header-other
1304 (default :slant italic)
1305 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1306 (mdw-define-face message-header-name
1307 (default :weight bold)
1308 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1310 (mdw-define-face which-func
1313 (mdw-define-face gnus-header-name
1314 (default :weight bold)
1315 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1316 (mdw-define-face gnus-header-subject
1317 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1318 (mdw-define-face gnus-header-from
1319 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1320 (mdw-define-face gnus-header-to
1321 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1322 (mdw-define-face gnus-header-content
1323 (default :slant italic)
1324 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1326 (mdw-define-face gnus-cite-1
1327 (((type tty)) :foreground "cyan") (t :foreground "SkyBlue1"))
1328 (mdw-define-face gnus-cite-2
1329 (((type tty)) :foreground "blue") (t :foreground "RoyalBlue2"))
1330 (mdw-define-face gnus-cite-3
1331 (((type tty)) :foreground "magenta") (t :foreground "MediumOrchid"))
1332 (mdw-define-face gnus-cite-4
1333 (((type tty)) :foreground "red") (t :foreground "firebrick2"))
1334 (mdw-define-face gnus-cite-5
1335 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
1336 (mdw-define-face gnus-cite-6
1337 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1338 (mdw-define-face gnus-cite-7
1339 (((type tty)) :foreground "cyan") (t :foreground "SlateBlue1"))
1340 (mdw-define-face gnus-cite-8
1341 (((type tty)) :foreground "blue") (t :foreground "RoyalBlue2"))
1342 (mdw-define-face gnus-cite-9
1343 (((type tty)) :foreground "magenta") (t :foreground "purple2"))
1344 (mdw-define-face gnus-cite-10
1345 (((type tty)) :foreground "red") (t :foreground "DarkOrange2"))
1346 (mdw-define-face gnus-cite-11
1347 (t :foreground "grey"))
1349 (mdw-define-face diff-header
1351 (mdw-define-face diff-index
1353 (mdw-define-face diff-file-header
1355 (mdw-define-face diff-hunk-header
1356 (t :foreground "SkyBlue1"))
1357 (mdw-define-face diff-function
1358 (t :foreground "SkyBlue1" :weight bold))
1359 (mdw-define-face diff-header
1360 (t :background "grey10"))
1361 (mdw-define-face diff-added
1362 (t :foreground "green"))
1363 (mdw-define-face diff-removed
1364 (t :foreground "red"))
1365 (mdw-define-face diff-context
1367 (mdw-define-face diff-refine-change
1368 (((class color) (type x)) :background "RoyalBlue4")
1370 (mdw-define-face diff-refine-removed
1371 (((class color) (type x)) :background "#500")
1373 (mdw-define-face diff-refine-added
1374 (((class color) (type x)) :background "#050")
1377 (mdw-define-face dylan-header-background
1378 (((class color) (type x)) :background "NavyBlue")
1379 (t :background "blue"))
1381 (mdw-define-face magit-diff-add
1382 (t :foreground "green"))
1383 (mdw-define-face magit-diff-del
1384 (t :foreground "red"))
1385 (mdw-define-face magit-diff-file-header
1387 (mdw-define-face magit-diff-hunk-header
1388 (t :foreground "SkyBlue1"))
1389 (mdw-define-face magit-item-highlight
1390 (((type tty)) :background "blue")
1391 (t :background "grey11"))
1392 (mdw-define-face magit-log-head-label-remote
1393 (((type tty)) :background "cyan" :foreground "green")
1394 (t :background "grey11" :foreground "DarkSeaGreen2" :box t))
1395 (mdw-define-face magit-log-head-label-local
1396 (((type tty)) :background "cyan" :foreground "yellow")
1397 (t :background "grey11" :foreground "LightSkyBlue1" :box t))
1398 (mdw-define-face magit-log-head-label-tags
1399 (((type tty)) :background "red" :foreground "yellow")
1400 (t :background "LemonChiffon1" :foreground "goldenrod4" :box t))
1401 (mdw-define-face magit-log-graph
1402 (((type tty)) :foreground "magenta")
1403 (t :foreground "grey80"))
1405 (mdw-define-face erc-input-face
1406 (t :foreground "red"))
1408 (mdw-define-face woman-bold
1410 (mdw-define-face woman-italic
1413 (eval-after-load "rst"
1415 (mdw-define-face rst-level-1-face
1416 (t :foreground "SkyBlue1" :weight bold))
1417 (mdw-define-face rst-level-2-face
1418 (t :foreground "SeaGreen1" :weight bold))
1419 (mdw-define-face rst-level-3-face
1421 (mdw-define-face rst-level-4-face
1423 (mdw-define-face rst-level-5-face
1425 (mdw-define-face rst-level-6-face
1428 (mdw-define-face p4-depot-added-face
1429 (t :foreground "green"))
1430 (mdw-define-face p4-depot-branch-op-face
1431 (t :foreground "yellow"))
1432 (mdw-define-face p4-depot-deleted-face
1433 (t :foreground "red"))
1434 (mdw-define-face p4-depot-unmapped-face
1435 (t :foreground "SkyBlue1"))
1436 (mdw-define-face p4-diff-change-face
1437 (t :foreground "yellow"))
1438 (mdw-define-face p4-diff-del-face
1439 (t :foreground "red"))
1440 (mdw-define-face p4-diff-file-face
1441 (t :foreground "SkyBlue1"))
1442 (mdw-define-face p4-diff-head-face
1443 (t :background "grey10"))
1444 (mdw-define-face p4-diff-ins-face
1445 (t :foreground "green"))
1447 (mdw-define-face w3m-anchor-face
1448 (t :foreground "SkyBlue1" :underline t))
1449 (mdw-define-face w3m-arrived-anchor-face
1450 (t :foreground "SkyBlue1" :underline t))
1452 (mdw-define-face whizzy-slice-face
1453 (t :background "grey10"))
1454 (mdw-define-face whizzy-error-face
1455 (t :background "darkred"))
1457 ;; Ellipses used to indicate hidden text (and similar).
1458 (mdw-define-face mdw-ellipsis-face
1459 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1460 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1461 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1462 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1463 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1464 (set-display-table-slot standard-display-table 0 dollar)
1465 (set-display-table-slot standard-display-table 1 backslash)
1466 (set-display-table-slot standard-display-table 4
1467 (vector dot dot dot))
1468 (set-display-table-slot standard-display-table 5 bar))
1470 ;;;--------------------------------------------------------------------------
1471 ;;; C programming configuration.
1473 ;; Make C indentation nice.
1475 (defun mdw-c-lineup-arglist (langelem)
1476 "Hack for DWIMmery in c-lineup-arglist."
1478 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1480 (c-lineup-arglist langelem)))
1482 (defun mdw-c-indent-extern-mumble (langelem)
1483 "Indent `extern \"...\" {' lines."
1485 (back-to-indentation)
1487 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1491 (defun mdw-c-indent-arglist-nested (langelem)
1492 "Indent continued argument lists.
1493 If we've nested more than one argument list, then only introduce a single
1494 indentation anyway."
1495 (let ((context c-syntactic-context)
1496 (pos (c-langelem-2nd-pos c-syntactic-element))
1497 (should-indent-p t))
1499 (eq (caar context) 'arglist-cont-nonempty))
1500 (when (and (= (caddr (pop context)) pos)
1502 (memq (caar context) '(arglist-intro
1503 arglist-cont-nonempty)))
1504 (setq should-indent-p nil)))
1505 (if should-indent-p '+ 0)))
1507 (defvar mdw-define-c-styles-hook nil
1508 "Hook run when `cc-mode' starts up to define styles.")
1510 (defmacro mdw-define-c-style (name &rest assocs)
1511 "Define a C style, called NAME (a symbol), setting ASSOCs.
1512 A function, named `mdw-define-c-style/NAME', is defined to actually install
1513 the style using `c-add-style', and added to the hook
1514 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1516 (declare (indent defun))
1517 (let* ((name-string (symbol-name name))
1518 (func (intern (concat "mdw-define-c-style/" name-string))))
1520 (defun ,func () (c-add-style ,name-string ',assocs))
1521 (and (featurep 'cc-mode) (,func))
1522 (add-hook 'mdw-define-c-styles-hook ',func))))
1524 (eval-after-load "cc-mode"
1525 '(run-hooks 'mdw-define-c-styles-hook))
1527 (mdw-define-c-style mdw-trustonic-c
1528 (c-basic-offset . 4)
1529 (comment-column . 0)
1530 (c-indent-comment-alist (anchored-comment . (column . 0))
1531 (end-block . (space . 1))
1532 (cpp-end-block . (space . 1))
1533 (other . (space . 1)))
1534 (c-class-key . "class")
1535 (c-backslash-column . 0)
1536 (c-auto-align-backslashes . nil)
1537 (c-label-minimum-indentation . 0)
1538 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1539 (defun-open . (add 0 c-indent-one-line-block))
1540 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1541 (topmost-intro . mdw-c-indent-extern-mumble)
1542 (cpp-define-intro . 0)
1544 (inextern-lang . [0])
1550 (statement-cont . +)
1551 (statement-case-intro . +)))
1553 (mdw-define-c-style mdw-c
1554 (c-basic-offset . 2)
1555 (comment-column . 40)
1556 (c-class-key . "class")
1557 (c-backslash-column . 72)
1558 (c-label-minimum-indentation . 0)
1559 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1560 (defun-open . (add 0 c-indent-one-line-block))
1561 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1562 (topmost-intro . mdw-c-indent-extern-mumble)
1563 (cpp-define-intro . 0)
1565 (inextern-lang . [0])
1571 (statement-cont . +)
1572 (statement-case-intro . +)))
1574 (defun mdw-set-default-c-style (modes style)
1575 "Update the default CC Mode style for MODES to be STYLE.
1577 MODES may be a list of major mode names or a singleton. STYLE is a style
1579 (let ((modes (if (listp modes) modes (list modes)))
1580 (style (symbol-name style)))
1581 (setq c-default-style
1582 (append (mapcar (lambda (mode)
1585 (remove-if (lambda (assoc)
1586 (memq (car assoc) modes))
1587 (if (listp c-default-style)
1589 (list (cons 'other c-default-style))))))))
1590 (setq c-default-style "mdw-c")
1592 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
1594 (defvar mdw-c-comment-fill-prefix
1595 `((,(concat "\\([ \t]*/?\\)"
1598 "\\([A-Za-z]+:[ \t]*\\)?"
1599 mdw-hanging-indents)
1600 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1601 "Fill prefix matching C comments (both kinds).")
1603 (defun mdw-fontify-c-and-c++ ()
1605 ;; Fiddle with some syntax codes.
1606 (modify-syntax-entry ?* ". 23")
1607 (modify-syntax-entry ?/ ". 124b")
1608 (modify-syntax-entry ?\n "> b")
1611 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1613 ;; Now define things to be fontified.
1614 (make-local-variable 'font-lock-keywords)
1616 (mdw-regexps "alignas" ;C11 macro, C++11
1618 "and" ;C++, C95 macro
1619 "and_eq" ;C++, C95 macro
1620 "asm" ;K&R, C++, GCC
1621 "atomic" ;C11 macro, C++11 template type
1623 "bitand" ;C++, C95 macro
1624 "bitor" ;C++, C95 macro
1625 "bool" ;C++, C99 macro
1630 "char16_t" ;C++11, C11 library type
1631 "char32_t" ;C++11, C11 library type
1633 "complex" ;C99 macro, C++ template type
1634 "compl" ;C++, C95 macro
1638 "continue" ;K&R, C89
1640 "defined" ;C89 preprocessor
1647 ;; "entry" ;K&R -- never used
1658 "imaginary" ;C99 macro
1659 "inline" ;C++, C99, GCC
1666 "noreturn" ;C11 macro
1667 "not" ;C++, C95 macro
1668 "not_eq" ;C++, C95 macro
1671 "or" ;C++, C95 macro
1672 "or_eq" ;C++, C95 macro
1676 "register" ;K&R, C89
1677 "reinterpret_cast" ;C++
1684 "static_assert" ;C11 macro, C++11
1691 "thread_local" ;C11 macro, C++11
1697 "unsigned" ;K&R, C89
1702 "wchar_t" ;C++, C89 library type
1704 "xor" ;C++, C95 macro
1705 "xor_eq" ;C++, C95 macro
1714 "_Pragma" ;C99 preprocessor
1715 "_Static_assert" ;C11
1716 "_Thread_local" ;C11
1719 "__attribute__" ;GCC
1722 "__extension__" ;GCC
1732 (mdw-regexps "false" ;C++, C99 macro
1734 "true" ;C++, C99 macro
1736 (preprocessor-keywords
1737 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1738 "ident" "if" "ifdef" "ifndef" "import" "include"
1739 "line" "pragma" "unassert" "undef" "warning"))
1741 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1742 "interface" "private" "protected" "protocol" "public"
1745 (setq font-lock-keywords
1748 ;; Fontify include files as strings.
1749 (list (concat "^[ \t]*\\#[ \t]*"
1750 "\\(include\\|import\\)"
1751 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1752 '(2 font-lock-string-face))
1754 ;; Preprocessor directives are `references'?.
1755 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1756 preprocessor-keywords
1757 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1758 '(1 font-lock-keyword-face))
1760 ;; Handle the keywords defined above.
1761 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1762 '(0 font-lock-keyword-face))
1764 (list (concat "\\<\\(" c-keywords "\\)\\>")
1765 '(0 font-lock-keyword-face))
1767 (list (concat "\\<\\(" c-constants "\\)\\>")
1768 '(0 font-lock-variable-name-face))
1770 ;; Handle numbers too.
1772 ;; This looks strange, I know. It corresponds to the
1773 ;; preprocessor's idea of what a number looks like, rather than
1774 ;; anything sensible.
1775 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1776 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1777 '(0 mdw-number-face))
1779 ;; And anything else is punctuation.
1780 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1781 '(0 mdw-punct-face))))))
1783 ;;;--------------------------------------------------------------------------
1786 (define-derived-mode apcalc-mode c-mode "AP Calc"
1787 "Major mode for editing Calc code.")
1789 (defun mdw-fontify-apcalc ()
1791 ;; Fiddle with some syntax codes.
1792 (modify-syntax-entry ?* ". 23")
1793 (modify-syntax-entry ?/ ". 14")
1796 (setq comment-start "/* ")
1797 (setq comment-end " */")
1798 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1800 ;; Now define things to be fontified.
1801 (make-local-variable 'font-lock-keywords)
1803 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1804 "do" "else" "exit" "for" "global" "goto" "help" "if"
1805 "local" "mat" "obj" "print" "quit" "read" "return"
1806 "show" "static" "switch" "while" "write")))
1808 (setq font-lock-keywords
1811 ;; Handle the keywords defined above.
1812 (list (concat "\\<\\(" c-keywords "\\)\\>")
1813 '(0 font-lock-keyword-face))
1815 ;; Handle numbers too.
1817 ;; This looks strange, I know. It corresponds to the
1818 ;; preprocessor's idea of what a number looks like, rather than
1819 ;; anything sensible.
1820 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1821 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1822 '(0 mdw-number-face))
1824 ;; And anything else is punctuation.
1825 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1826 '(0 mdw-punct-face))))))
1828 ;;;--------------------------------------------------------------------------
1829 ;;; Java programming configuration.
1831 ;; Make indentation nice.
1833 (mdw-define-c-style mdw-java
1834 (c-basic-offset . 2)
1835 (c-backslash-column . 72)
1836 (c-offsets-alist (substatement-open . 0)
1841 (statement-case-intro . +)))
1842 (mdw-set-default-c-style 'java-mode 'mdw-java)
1844 ;; Declare Java fontification style.
1846 (defun mdw-fontify-java ()
1849 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1851 ;; Now define things to be fontified.
1852 (make-local-variable 'font-lock-keywords)
1853 (let ((java-keywords
1854 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1855 "char" "class" "const" "continue" "default" "do"
1856 "double" "else" "extends" "final" "finally" "float"
1857 "for" "goto" "if" "implements" "import" "instanceof"
1858 "int" "interface" "long" "native" "new" "package"
1859 "private" "protected" "public" "return" "short"
1860 "static" "switch" "synchronized" "throw" "throws"
1861 "transient" "try" "void" "volatile" "while"))
1864 (mdw-regexps "false" "null" "super" "this" "true")))
1866 (setq font-lock-keywords
1869 ;; Handle the keywords defined above.
1870 (list (concat "\\<\\(" java-keywords "\\)\\>")
1871 '(0 font-lock-keyword-face))
1873 ;; Handle the magic constants defined above.
1874 (list (concat "\\<\\(" java-constants "\\)\\>")
1875 '(0 font-lock-variable-name-face))
1877 ;; Handle numbers too.
1879 ;; The following isn't quite right, but it's close enough.
1880 (list (concat "\\<\\("
1881 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1882 "[0-9]+\\(\\.[0-9]*\\|\\)"
1883 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1885 '(0 mdw-number-face))
1887 ;; And anything else is punctuation.
1888 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1889 '(0 mdw-punct-face))))))
1891 ;;;--------------------------------------------------------------------------
1892 ;;; Javascript programming configuration.
1894 (defun mdw-javascript-style ()
1895 (setq js-indent-level 2)
1896 (setq js-expr-indent-offset 0))
1898 (defun mdw-fontify-javascript ()
1901 (mdw-javascript-style)
1902 (setq js-auto-indent-flag t)
1904 ;; Now define things to be fontified.
1905 (make-local-variable 'font-lock-keywords)
1906 (let ((javascript-keywords
1907 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1908 "char" "class" "const" "continue" "debugger" "default"
1909 "delete" "do" "double" "else" "enum" "export" "extends"
1910 "final" "finally" "float" "for" "function" "goto" "if"
1911 "implements" "import" "in" "instanceof" "int"
1912 "interface" "let" "long" "native" "new" "package"
1913 "private" "protected" "public" "return" "short"
1914 "static" "super" "switch" "synchronized" "throw"
1915 "throws" "transient" "try" "typeof" "var" "void"
1916 "volatile" "while" "with" "yield"
1918 "boolean" "byte" "char" "double" "float" "int" "long"
1920 (javascript-constants
1921 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
1922 "arguments" "this")))
1924 (setq font-lock-keywords
1927 ;; Handle the keywords defined above.
1928 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
1929 '(0 font-lock-keyword-face))
1931 ;; Handle the predefined constants defined above.
1932 (list (concat "\\_<\\(" javascript-constants "\\)\\_>")
1933 '(0 font-lock-variable-name-face))
1935 ;; Handle numbers too.
1937 ;; The following isn't quite right, but it's close enough.
1938 (list (concat "\\_<\\("
1939 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1940 "[0-9]+\\(\\.[0-9]*\\|\\)"
1941 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1943 '(0 mdw-number-face))
1945 ;; And anything else is punctuation.
1946 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1947 '(0 mdw-punct-face))))))
1949 ;;;--------------------------------------------------------------------------
1950 ;;; Scala programming configuration.
1952 (defun mdw-fontify-scala ()
1955 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1957 ;; Define things to be fontified.
1958 (make-local-variable 'font-lock-keywords)
1959 (let ((scala-keywords
1960 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
1961 "extends" "final" "finally" "for" "forSome" "if"
1962 "implicit" "import" "lazy" "match" "new" "object"
1963 "override" "package" "private" "protected" "return"
1964 "sealed" "throw" "trait" "try" "type" "val"
1965 "var" "while" "with" "yield"))
1967 (mdw-regexps "false" "null" "super" "this" "true"))
1968 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
1970 (setq font-lock-keywords
1973 ;; Magical identifiers between backticks.
1974 (list (concat "`\\([^`]+\\)`")
1975 '(1 font-lock-variable-name-face))
1977 ;; Handle the keywords defined above.
1978 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
1979 '(0 font-lock-keyword-face))
1981 ;; Handle the constants defined above.
1982 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
1983 '(0 font-lock-variable-name-face))
1985 ;; Magical identifiers between backticks.
1986 (list (concat "`\\([^`]+\\)`")
1987 '(1 font-lock-variable-name-face))
1989 ;; Handle numbers too.
1991 ;; As usual, not quite right.
1992 (list (concat "\\_<\\("
1993 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1994 "[0-9]+\\(\\.[0-9]*\\|\\)"
1995 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1997 '(0 mdw-number-face))
1999 ;; Identifiers with trailing operators.
2000 (list (concat "_\\(" punctuation "\\)+")
2001 '(0 mdw-trivial-face))
2003 ;; And everything else is punctuation.
2004 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2005 '(0 mdw-punct-face)))
2007 font-lock-syntactic-keywords
2010 ;; Single quotes around characters. But not when used to quote
2011 ;; symbol names. Ugh.
2012 (list (concat "\\('\\)"
2014 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2015 "u+" "[0-9a-fA-F]\\{4\\}"
2016 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2017 "\\|" "\\\\" "." "\\)"
2022 ;;;--------------------------------------------------------------------------
2023 ;;; C# programming configuration.
2025 ;; Make indentation nice.
2027 (mdw-define-c-style mdw-csharp
2028 (c-basic-offset . 2)
2029 (c-backslash-column . 72)
2030 (c-offsets-alist (substatement-open . 0)
2035 (statement-case-intro . +)))
2036 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2038 ;; Declare C# fontification style.
2040 (defun mdw-fontify-csharp ()
2043 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2045 ;; Now define things to be fontified.
2046 (make-local-variable 'font-lock-keywords)
2047 (let ((csharp-keywords
2048 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2049 "char" "checked" "class" "const" "continue" "decimal"
2050 "default" "delegate" "do" "double" "else" "enum"
2051 "event" "explicit" "extern" "finally" "fixed" "float"
2052 "for" "foreach" "goto" "if" "implicit" "in" "int"
2053 "interface" "internal" "is" "lock" "long" "namespace"
2054 "new" "object" "operator" "out" "override" "params"
2055 "private" "protected" "public" "readonly" "ref"
2056 "return" "sbyte" "sealed" "short" "sizeof"
2057 "stackalloc" "static" "string" "struct" "switch"
2058 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2059 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2063 (mdw-regexps "base" "false" "null" "this" "true")))
2065 (setq font-lock-keywords
2068 ;; Handle the keywords defined above.
2069 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2070 '(0 font-lock-keyword-face))
2072 ;; Handle the magic constants defined above.
2073 (list (concat "\\<\\(" csharp-constants "\\)\\>")
2074 '(0 font-lock-variable-name-face))
2076 ;; Handle numbers too.
2078 ;; The following isn't quite right, but it's close enough.
2079 (list (concat "\\<\\("
2080 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2081 "[0-9]+\\(\\.[0-9]*\\|\\)"
2082 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2084 '(0 mdw-number-face))
2086 ;; And anything else is punctuation.
2087 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2088 '(0 mdw-punct-face))))))
2090 (define-derived-mode csharp-mode java-mode "C#"
2091 "Major mode for editing C# code.")
2093 ;;;--------------------------------------------------------------------------
2094 ;;; F# programming configuration.
2096 (setq fsharp-indent-offset 2)
2098 (defun mdw-fontify-fsharp ()
2100 (let ((punct "=<>+-*/|&%!@?"))
2102 ((>= i (length punct)))
2103 (modify-syntax-entry (aref punct i) ".")))
2105 (modify-syntax-entry ?_ "_")
2106 (modify-syntax-entry ?( "(")
2107 (modify-syntax-entry ?) ")")
2109 (setq indent-tabs-mode nil)
2111 (let ((fsharp-keywords
2112 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2114 "checked" "class" "component" "const" "constraint"
2115 "constructor" "continue"
2116 "default" "delegate" "do" "done" "downcast" "downto"
2117 "eager" "elif" "else" "end" "exception" "extern"
2118 "finally" "fixed" "for" "fori" "fun" "function"
2121 "if" "in" "include" "inherit" "inline" "interface"
2124 "match" "measure" "member" "method" "mixin" "module"
2127 "object" "of" "open" "or" "override"
2128 "parallel" "params" "private" "process" "protected"
2130 "rec" "recursive" "return"
2131 "sealed" "sig" "static" "struct"
2132 "tailcall" "then" "to" "trait" "try" "type"
2134 "val" "virtual" "void" "volatile"
2135 "when" "while" "with"
2139 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2140 "base" "false" "null" "true"))
2143 (mdw-regexps "do" "let" "return" "use" "yield"))
2145 (preprocessor-keywords
2146 (mdw-regexps "if" "indent" "else" "endif")))
2148 (setq font-lock-keywords
2149 (list (list (concat "\\(^\\|[^\"]\\)"
2152 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2157 '(2 font-lock-comment-face))
2159 (list (concat "'" "\\("
2162 "\\|" "[0-9][0-9][0-9]"
2163 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2164 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2170 "\\(" "\\\\" "\\(.\\|\n\\)"
2173 '(0 font-lock-string-face))
2175 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2176 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2178 "\\_<\\(" fsharp-keywords "\\)\\_>")
2179 '(0 font-lock-keyword-face))
2180 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2181 '(0 font-lock-variable-name-face))
2183 (list (concat "\\_<"
2184 "\\(" "0[bB][01]+" "\\|"
2186 "0[xX][0-9a-fA-F]+" "\\)"
2187 "\\(" "lf\\|LF" "\\|"
2188 "[uU]?[ysnlL]?" "\\)"
2195 "\\([eE][-+]?[0-9]+\\)?"
2200 '(0 mdw-number-face))
2202 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2203 '(0 mdw-punct-face))))))
2205 (defun mdw-fontify-inferior-fsharp ()
2206 (mdw-fontify-fsharp)
2207 (setq font-lock-keywords
2208 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2209 (list "^>" '(0 font-lock-keyword-face)))
2210 font-lock-keywords)))
2212 ;;;--------------------------------------------------------------------------
2213 ;;; Go programming configuration.
2215 (defun mdw-fontify-go ()
2217 (make-local-variable 'font-lock-keywords)
2219 (mdw-regexps "break" "case" "chan" "const" "continue"
2220 "default" "defer" "else" "fallthrough" "for"
2221 "func" "go" "goto" "if" "import"
2222 "interface" "map" "package" "range" "return"
2223 "select" "struct" "switch" "type" "var"))
2225 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2226 "float32" "float64" "int" "uint8" "int16" "int32"
2227 "int64" "rune" "string" "uint" "uint8" "uint16"
2228 "uint32" "uint64" "uintptr" "void"
2229 "false" "iota" "nil" "true"
2231 "append" "cap" "copy" "delete" "imag" "len" "make"
2232 "new" "panic" "real" "recover")))
2234 (setq font-lock-keywords
2237 ;; Handle the keywords defined above.
2238 (list (concat "\\<\\(" go-keywords "\\)\\>")
2239 '(0 font-lock-keyword-face))
2240 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2241 '(0 font-lock-variable-name-face))
2243 ;; Strings and characters.
2245 "\\(" "[^\\']" "\\|"
2247 "\\(" "[abfnrtv\\'\"]" "\\|"
2248 "[0-7]\\{3\\}" "\\|"
2249 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2250 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2251 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2255 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2259 '(0 font-lock-string-face))
2261 ;; Handle numbers too.
2263 ;; The following isn't quite right, but it's close enough.
2264 (list (concat "\\<\\("
2265 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2266 "[0-9]+\\(\\.[0-9]*\\|\\)"
2267 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2268 '(0 mdw-number-face))
2270 ;; And anything else is punctuation.
2271 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2272 '(0 mdw-punct-face))))))
2274 ;;;--------------------------------------------------------------------------
2275 ;;; Rust programming configuration.
2277 (setq-default rust-indent-offset 2)
2279 (defun mdw-self-insert-and-indent (count)
2281 (self-insert-command count)
2282 (indent-according-to-mode))
2284 (defun mdw-fontify-rust ()
2286 ;; Hack syntax categories.
2287 (modify-syntax-entry ?= ".")
2289 ;; Fontify keywords and things.
2290 (make-local-variable 'font-lock-keywords)
2291 (let ((rust-keywords
2292 (mdw-regexps "abstract" "alignof" "as"
2293 "become" "box" "break"
2294 "const" "continue" "create"
2296 "else" "enum" "extern"
2297 "false" "final" "fn" "for"
2300 "macro" "match" "mod" "move" "mut"
2301 "offsetof" "override"
2304 "self" "sizeof" "static" "struct" "super"
2305 "true" "trait" "type" "typeof"
2306 "unsafe" "unsized" "use"
2311 (mdw-regexps "array" "pointer" "slice" "tuple"
2312 "bool" "true" "false"
2314 "i8" "i16" "i32" "i64" "isize"
2315 "u8" "u16" "u32" "u64" "usize"
2317 (setq font-lock-keywords
2320 ;; Handle the keywords defined above.
2321 (list (concat "\\<\\(" rust-keywords "\\)\\>")
2322 '(0 font-lock-keyword-face))
2323 (list (concat "\\<\\(" rust-builtins "\\)\\>")
2324 '(0 font-lock-variable-name-face))
2326 ;; Handle numbers too.
2327 (list (concat "\\<\\("
2329 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2333 "\\|" "\\(" "[0-9][0-9_]*"
2334 "\\|" "0x[0-9a-fA-F_]+"
2338 "\\([ui]\\(8\\|16\\|32\\|64\\|s\\|size\\)\\)?"
2340 '(0 mdw-number-face))
2342 ;; And anything else is punctuation.
2343 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2344 '(0 mdw-punct-face)))))
2346 ;; Hack key bindings.
2347 (local-set-key [?{] 'mdw-self-insert-and-indent)
2348 (local-set-key [?}] 'mdw-self-insert-and-indent))
2350 ;;;--------------------------------------------------------------------------
2351 ;;; Awk programming configuration.
2353 ;; Make Awk indentation nice.
2355 (mdw-define-c-style mdw-awk
2356 (c-basic-offset . 2)
2357 (c-offsets-alist (substatement-open . 0)
2358 (c-backslash-column . 72)
2359 (statement-cont . 0)
2360 (statement-case-intro . +)))
2361 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2363 ;; Declare Awk fontification style.
2365 (defun mdw-fontify-awk ()
2367 ;; Miscellaneous fiddling.
2368 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2370 ;; Now define things to be fontified.
2371 (make-local-variable 'font-lock-keywords)
2373 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2374 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2375 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2376 "RSTART" "RLENGTH" "RT" "SUBSEP"
2377 "atan2" "break" "close" "continue" "cos" "delete"
2378 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2379 "function" "gensub" "getline" "gsub" "if" "in"
2380 "index" "int" "length" "log" "match" "next" "rand"
2381 "return" "print" "printf" "sin" "split" "sprintf"
2382 "sqrt" "srand" "strftime" "sub" "substr" "system"
2383 "systime" "tolower" "toupper" "while")))
2385 (setq font-lock-keywords
2388 ;; Handle the keywords defined above.
2389 (list (concat "\\<\\(" c-keywords "\\)\\>")
2390 '(0 font-lock-keyword-face))
2392 ;; Handle numbers too.
2394 ;; The following isn't quite right, but it's close enough.
2395 (list (concat "\\<\\("
2396 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2397 "[0-9]+\\(\\.[0-9]*\\|\\)"
2398 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2400 '(0 mdw-number-face))
2402 ;; And anything else is punctuation.
2403 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2404 '(0 mdw-punct-face))))))
2406 ;;;--------------------------------------------------------------------------
2407 ;;; Perl programming style.
2409 ;; Perl indentation style.
2411 (setq perl-indent-level 2)
2413 (setq cperl-indent-level 2)
2414 (setq cperl-continued-statement-offset 2)
2415 (setq cperl-continued-brace-offset 0)
2416 (setq cperl-brace-offset -2)
2417 (setq cperl-brace-imaginary-offset 0)
2418 (setq cperl-label-offset 0)
2420 ;; Define perl fontification style.
2422 (defun mdw-fontify-perl ()
2424 ;; Miscellaneous fiddling.
2425 (modify-syntax-entry ?$ "\\")
2426 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2427 (modify-syntax-entry ?: "." font-lock-syntax-table)
2428 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2430 ;; Now define fontification things.
2431 (make-local-variable 'font-lock-keywords)
2432 (let ((perl-keywords
2439 "ge" "given" "gt" "goto"
2441 "last" "le" "local" "lt"
2446 "redo" "require" "return"
2448 "undef" "unless" "until" "use"
2451 (setq font-lock-keywords
2454 ;; Set up the keywords defined above.
2455 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2456 '(0 font-lock-keyword-face))
2458 ;; At least numbers are simpler than C.
2459 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2460 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2461 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2462 '(0 mdw-number-face))
2464 ;; And anything else is punctuation.
2465 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2466 '(0 mdw-punct-face))))))
2468 (defun perl-number-tests (&optional arg)
2469 "Assign consecutive numbers to lines containing `#t'. With ARG,
2470 strip numbers instead."
2473 (goto-char (point-min))
2474 (let ((i 0) (fmt (if arg "" " %4d")))
2475 (while (search-forward "#t" nil t)
2476 (delete-region (point) (line-end-position))
2478 (insert (format fmt i)))
2479 (goto-char (point-min))
2480 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2481 (replace-match (format "\\1%d" i))))))
2483 ;;;--------------------------------------------------------------------------
2484 ;;; Python programming style.
2486 (defun mdw-fontify-pythonic (keywords)
2488 ;; Miscellaneous fiddling.
2489 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2490 (setq indent-tabs-mode nil)
2492 ;; Now define fontification things.
2493 (make-local-variable 'font-lock-keywords)
2494 (setq font-lock-keywords
2497 ;; Set up the keywords defined above.
2498 (list (concat "\\_<\\(" keywords "\\)\\_>")
2499 '(0 font-lock-keyword-face))
2501 ;; At least numbers are simpler than C.
2502 (list (concat "\\_<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2503 "\\_<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2504 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
2505 '(0 mdw-number-face))
2507 ;; And anything else is punctuation.
2508 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2509 '(0 mdw-punct-face)))))
2511 ;; Define Python fontification styles.
2513 (defun mdw-fontify-python ()
2514 (mdw-fontify-pythonic
2515 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
2516 "del" "elif" "else" "except" "exec" "finally" "for"
2517 "from" "global" "if" "import" "in" "is" "lambda"
2518 "not" "or" "pass" "print" "raise" "return" "try"
2519 "while" "with" "yield")))
2521 (defun mdw-fontify-pyrex ()
2522 (mdw-fontify-pythonic
2523 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
2524 "ctypedef" "def" "del" "elif" "else" "except" "exec"
2525 "extern" "finally" "for" "from" "global" "if"
2526 "import" "in" "is" "lambda" "not" "or" "pass" "print"
2527 "raise" "return" "struct" "try" "while" "with"
2530 ;;;--------------------------------------------------------------------------
2531 ;;; Icon programming style.
2533 ;; Icon indentation style.
2535 (setq icon-brace-offset 0
2536 icon-continued-brace-offset 0
2537 icon-continued-statement-offset 2
2538 icon-indent-level 2)
2540 ;; Define Icon fontification style.
2542 (defun mdw-fontify-icon ()
2544 ;; Miscellaneous fiddling.
2545 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2547 ;; Now define fontification things.
2548 (make-local-variable 'font-lock-keywords)
2549 (let ((icon-keywords
2550 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
2551 "end" "every" "fail" "global" "if" "initial"
2552 "invocable" "link" "local" "next" "not" "of"
2553 "procedure" "record" "repeat" "return" "static"
2554 "suspend" "then" "to" "until" "while"))
2555 (preprocessor-keywords
2556 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
2557 "include" "line" "undef")))
2558 (setq font-lock-keywords
2561 ;; Set up the keywords defined above.
2562 (list (concat "\\<\\(" icon-keywords "\\)\\>")
2563 '(0 font-lock-keyword-face))
2565 ;; The things that Icon calls keywords.
2566 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
2568 ;; At least numbers are simpler than C.
2569 (list (concat "\\<[0-9]+"
2570 "\\([rR][0-9a-zA-Z]+\\|"
2571 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
2572 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
2573 '(0 mdw-number-face))
2576 (list (concat "^[ \t]*$[ \t]*\\<\\("
2577 preprocessor-keywords
2579 '(0 font-lock-keyword-face))
2581 ;; And anything else is punctuation.
2582 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2583 '(0 mdw-punct-face))))))
2585 ;;;--------------------------------------------------------------------------
2588 (defun mdw-fontify-asm ()
2589 (modify-syntax-entry ?' "\"")
2590 (modify-syntax-entry ?. "w")
2591 (modify-syntax-entry ?\n ">")
2592 (setf fill-prefix nil)
2593 (local-set-key ";" 'self-insert-command)
2594 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
2596 (defun mdw-asm-set-comment ()
2597 (modify-syntax-entry ?; "."
2599 (modify-syntax-entry asm-comment-char "<b")
2600 (setq comment-start (string asm-comment-char ? )))
2601 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
2602 (put 'asm-comment-char 'safe-local-variable 'characterp)
2604 ;;;--------------------------------------------------------------------------
2605 ;;; TCL configuration.
2607 (defun mdw-fontify-tcl ()
2608 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
2609 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2610 (make-local-variable 'font-lock-keywords)
2611 (setq font-lock-keywords
2613 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2614 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2615 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2616 '(0 mdw-number-face))
2617 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2618 '(0 mdw-punct-face)))))
2620 ;;;--------------------------------------------------------------------------
2621 ;;; Dylan programming configuration.
2623 (defun mdw-fontify-dylan ()
2625 (make-local-variable 'font-lock-keywords)
2627 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
2628 ;; hook, which undoes all of our configuration.
2629 (setq major-mode 'dylan-mode)
2630 (font-lock-set-defaults)
2632 (let* ((word "[-_a-zA-Z!*@<>$%]+")
2633 (dylan-keywords (mdw-regexps
2635 "C-address" "C-callable-wrapper" "C-function"
2636 "C-mapped-subtype" "C-pointer-type" "C-struct"
2637 "C-subtype" "C-union" "C-variable"
2639 "above" "abstract" "afterwards" "all"
2640 "begin" "below" "block" "by"
2641 "case" "class" "cleanup" "constant" "create"
2643 "else" "elseif" "end" "exception" "export"
2644 "finally" "for" "from" "function"
2647 "if" "in" "instance" "interface" "iterate"
2649 "let" "library" "local"
2650 "macro" "method" "module"
2653 "select" "slot" "subclass"
2655 "unless" "until" "use"
2656 "variable" "virtual"
2658 (sharp-keywords (mdw-regexps
2659 "all-keys" "key" "next" "rest" "include"
2661 (setq font-lock-keywords
2662 (list (list (concat "\\<\\(" dylan-keywords
2663 "\\|" "with\\(out\\)?-" word
2665 '(0 font-lock-keyword-face))
2666 (list (concat "\\<" word ":" "\\|"
2667 "#\\(" sharp-keywords "\\)\\>")
2668 '(0 font-lock-variable-name-face))
2670 "\\([-+]\\|\\<\\)[0-9]+" "\\("
2671 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
2674 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
2677 "\\|" "#x[0-9a-zA-Z]+"
2679 '(0 mdw-number-face))
2681 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
2682 "\\_<[-+*/=<>:&|]+\\_>"
2684 '(0 mdw-punct-face))))))
2686 ;;;--------------------------------------------------------------------------
2687 ;;; Algol 68 configuration.
2689 (setq a68-indent-step 2)
2691 (defun mdw-fontify-algol-68 ()
2693 ;; Fix up the syntax table.
2694 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
2695 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
2696 (modify-syntax-entry ch "." a68-mode-syntax-table))
2698 (make-local-variable 'font-lock-keywords)
2701 (let ((word "COMMENT"))
2702 (do ((regexp (concat "[^" (substring word 0 1) "]+")
2703 (concat regexp "\\|"
2704 (substring word 0 i)
2705 "[^" (substring word i (1+ i)) "]"))
2707 ((>= i (length word)) regexp)))))
2708 (setq font-lock-keywords
2709 (list (list (concat "\\<COMMENT\\>"
2710 "\\(" not-comment "\\)\\{0,5\\}"
2711 "\\(\\'\\|\\<COMMENT\\>\\)")
2712 '(0 font-lock-comment-face))
2713 (list (concat "\\<CO\\>"
2714 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
2715 "\\($\\|\\<CO\\>\\)")
2716 '(0 font-lock-comment-face))
2717 (list "\\<[A-Z_]+\\>"
2718 '(0 font-lock-keyword-face))
2722 "\\([eE][-+]?[0-9]+\\)?"
2724 '(0 mdw-number-face))
2725 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
2726 '(0 mdw-punct-face))))))
2728 ;;;--------------------------------------------------------------------------
2729 ;;; REXX configuration.
2731 (defun mdw-rexx-electric-* ()
2736 (defun mdw-rexx-indent-newline-indent ()
2739 (if abbrev-mode (expand-abbrev))
2740 (newline-and-indent))
2742 (defun mdw-fontify-rexx ()
2744 ;; Various bits of fiddling.
2745 (setq mdw-auto-indent nil)
2746 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
2747 (local-set-key [?*] 'mdw-rexx-electric-*)
2748 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
2750 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
2752 ;; Set up keywords and things for fontification.
2753 (make-local-variable 'font-lock-keywords-case-fold-search)
2754 (setq font-lock-keywords-case-fold-search t)
2756 (setq rexx-indent 2)
2757 (setq rexx-end-indent rexx-indent)
2758 (setq rexx-cont-indent rexx-indent)
2760 (make-local-variable 'font-lock-keywords)
2761 (let ((rexx-keywords
2762 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
2763 "else" "end" "engineering" "exit" "expose" "for"
2764 "forever" "form" "fuzz" "if" "interpret" "iterate"
2765 "leave" "linein" "name" "nop" "numeric" "off" "on"
2766 "options" "otherwise" "parse" "procedure" "pull"
2767 "push" "queue" "return" "say" "select" "signal"
2768 "scientific" "source" "then" "trace" "to" "until"
2769 "upper" "value" "var" "version" "when" "while"
2772 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
2773 "center" "center" "charin" "charout" "chars"
2774 "compare" "condition" "copies" "c2d" "c2x"
2775 "datatype" "date" "delstr" "delword" "d2c" "d2x"
2776 "errortext" "format" "fuzz" "insert" "lastpos"
2777 "left" "length" "lineout" "lines" "max" "min"
2778 "overlay" "pos" "queued" "random" "reverse" "right"
2779 "sign" "sourceline" "space" "stream" "strip"
2780 "substr" "subword" "symbol" "time" "translate"
2781 "trunc" "value" "verify" "word" "wordindex"
2782 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
2785 (setq font-lock-keywords
2788 ;; Set up the keywords defined above.
2789 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
2790 '(0 font-lock-keyword-face))
2792 ;; Fontify all symbols the same way.
2793 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
2794 "[A-Za-z0-9.!?_#@$]+\\)")
2795 '(0 font-lock-variable-name-face))
2797 ;; And everything else is punctuation.
2798 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2799 '(0 mdw-punct-face))))))
2801 ;;;--------------------------------------------------------------------------
2802 ;;; Standard ML programming style.
2804 (defun mdw-fontify-sml ()
2806 ;; Make underscore an honorary letter.
2807 (modify-syntax-entry ?' "w")
2810 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
2812 ;; Now define fontification things.
2813 (make-local-variable 'font-lock-keywords)
2815 (mdw-regexps "abstype" "and" "andalso" "as"
2818 "else" "end" "eqtype" "exception"
2819 "fn" "fun" "functor"
2821 "if" "in" "include" "infix" "infixr"
2824 "of" "op" "open" "orelse"
2826 "sharing" "sig" "signature" "struct" "structure"
2829 "where" "while" "with" "withtype")))
2831 (setq font-lock-keywords
2834 ;; Set up the keywords defined above.
2835 (list (concat "\\<\\(" sml-keywords "\\)\\>")
2836 '(0 font-lock-keyword-face))
2838 ;; At least numbers are simpler than C.
2839 (list (concat "\\<\\(\\~\\|\\)"
2840 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
2842 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
2843 "\\([eE]\\(\\~\\|\\)"
2844 "[0-9]+\\|\\)\\)\\)")
2845 '(0 mdw-number-face))
2847 ;; And anything else is punctuation.
2848 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2849 '(0 mdw-punct-face))))))
2851 ;;;--------------------------------------------------------------------------
2852 ;;; Haskell configuration.
2854 (defun mdw-fontify-haskell ()
2856 ;; Fiddle with syntax table to get comments right.
2857 (modify-syntax-entry ?' "_")
2858 (modify-syntax-entry ?- ". 12")
2859 (modify-syntax-entry ?\n ">")
2861 ;; Make punctuation be punctuation
2862 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
2864 ((>= i (length punct)))
2865 (modify-syntax-entry (aref punct i) ".")))
2868 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
2870 ;; Fiddle with fontification.
2871 (make-local-variable 'font-lock-keywords)
2872 (let ((haskell-keywords
2874 "case" "ccall" "class"
2875 "data" "default" "deriving" "do"
2879 "if" "import" "in" "infix" "infixl" "infixr" "instance"
2892 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
2893 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
2894 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
2895 "SP" "STX" "SUB" "SYN" "US" "VT")))
2897 (setq font-lock-keywords
2899 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
2903 '(0 font-lock-comment-face))
2904 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
2905 '(0 font-lock-keyword-face))
2906 (list (concat "'\\("
2910 "\\(" "[abfnrtv\\\"']" "\\|"
2911 "^" "\\(" control-sequences "\\|"
2912 "[]A-Z@[\\^_]" "\\)" "\\|"
2919 '(0 font-lock-string-face))
2920 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
2921 '(0 font-lock-variable-name-face))
2922 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
2923 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
2924 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
2925 '(0 mdw-number-face))
2926 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2927 '(0 mdw-punct-face))))))
2929 ;;;--------------------------------------------------------------------------
2930 ;;; Erlang configuration.
2932 (setq erlang-electric-commands nil)
2934 (defun mdw-fontify-erlang ()
2937 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
2939 ;; Fiddle with fontification.
2940 (make-local-variable 'font-lock-keywords)
2941 (let ((erlang-keywords
2942 (mdw-regexps "after" "and" "andalso"
2943 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
2944 "case" "catch" "cond"
2945 "div" "end" "fun" "if" "let" "not"
2947 "query" "receive" "rem" "try" "when" "xor")))
2949 (setq font-lock-keywords
2952 '(0 font-lock-comment-face))
2953 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
2954 '(0 font-lock-keyword-face))
2955 (list (concat "^-\\sw+\\>")
2956 '(0 font-lock-keyword-face))
2957 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
2958 '(0 mdw-number-face))
2959 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2960 '(0 mdw-punct-face))))))
2962 ;;;--------------------------------------------------------------------------
2963 ;;; Texinfo configuration.
2965 (defun mdw-fontify-texinfo ()
2968 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
2970 ;; Real fontification things.
2971 (make-local-variable 'font-lock-keywords)
2972 (setq font-lock-keywords
2975 ;; Environment names are keywords.
2976 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
2977 '(2 font-lock-keyword-face))
2979 ;; Unmark escaped magic characters.
2980 (list "\\(@\\)\\([@{}]\\)"
2981 '(1 font-lock-keyword-face)
2982 '(2 font-lock-variable-name-face))
2984 ;; Make sure we get comments properly.
2985 (list "@c\\(\\|omment\\)\\( .*\\)?$"
2986 '(0 font-lock-comment-face))
2988 ;; Command names are keywords.
2989 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2990 '(0 font-lock-keyword-face))
2992 ;; Fontify TeX special characters as punctuation.
2994 '(0 mdw-punct-face)))))
2996 ;;;--------------------------------------------------------------------------
2997 ;;; TeX and LaTeX configuration.
2999 (defun mdw-fontify-tex ()
3000 (setq ispell-parser 'tex)
3003 ;; Don't make maths into a string.
3004 (modify-syntax-entry ?$ ".")
3005 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3006 (local-set-key [?$] 'self-insert-command)
3008 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3009 (local-set-key "\C-i" 'indent-relative)
3010 (setq indent-tabs-mode nil)
3013 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3015 ;; Real fontification things.
3016 (make-local-variable 'font-lock-keywords)
3017 (setq font-lock-keywords
3020 ;; Environment names are keywords.
3021 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3023 '(2 font-lock-keyword-face))
3025 ;; Suspended environment names are keywords too.
3026 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3028 '(3 font-lock-keyword-face))
3030 ;; Command names are keywords.
3031 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3032 '(0 font-lock-keyword-face))
3034 ;; Handle @/.../ for italics.
3035 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3036 ;; '(1 font-lock-keyword-face)
3037 ;; '(3 font-lock-keyword-face))
3039 ;; Handle @*...* for boldness.
3040 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3041 ;; '(1 font-lock-keyword-face)
3042 ;; '(3 font-lock-keyword-face))
3044 ;; Handle @`...' for literal syntax things.
3045 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3046 ;; '(1 font-lock-keyword-face)
3047 ;; '(3 font-lock-keyword-face))
3049 ;; Handle @<...> for nonterminals.
3050 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3051 ;; '(1 font-lock-keyword-face)
3052 ;; '(3 font-lock-keyword-face))
3054 ;; Handle other @-commands.
3055 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3056 ;; '(0 font-lock-keyword-face))
3058 ;; Make sure we get comments properly.
3060 '(0 font-lock-comment-face))
3062 ;; Fontify TeX special characters as punctuation.
3064 '(0 mdw-punct-face)))))
3066 ;;;--------------------------------------------------------------------------
3069 (defun mdw-sgml-mode ()
3072 (mdw-standard-fill-prefix "")
3073 (make-local-variable 'sgml-delimiters)
3074 (setq sgml-delimiters
3075 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3076 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3077 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3078 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3079 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3080 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3081 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3083 (setq major-mode 'mdw-sgml-mode)
3084 (setq mode-name "[mdw] SGML")
3085 (run-hooks 'mdw-sgml-mode-hook))
3087 ;;;--------------------------------------------------------------------------
3088 ;;; Configuration files.
3090 (defvar mdw-conf-quote-normal nil
3091 "*Control syntax category of quote characters `\"' and `''.
3092 If this is `t', consider quote characters to be normal
3093 punctuation, as for `conf-quote-normal'. If this is `nil' then
3094 leave quote characters as quotes. If this is a list, then
3095 consider the quote characters in the list to be normal
3096 punctuation. If this is a single quote character, then consider
3097 that character only to be normal punctuation.")
3098 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3099 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3100 (or (booleanp value)
3101 (every (lambda (v) (memq v '(?\" ?')))
3102 (if (listp value) value (list value)))))
3103 (put 'mdw-conf-quote-normal 'safe-local-variable
3104 'mdw-conf-quote-normal-acceptable-value-p)
3106 (defun mdw-fix-up-quote ()
3107 "Apply the setting of `mdw-conf-quote-normal'."
3108 (let ((flag mdw-conf-quote-normal))
3110 (conf-quote-normal t))
3114 (let ((table (copy-syntax-table (syntax-table))))
3115 (mapc (lambda (ch) (modify-syntax-entry ch "." table))
3116 (if (listp flag) flag (list flag)))
3117 (set-syntax-table table)
3118 (and font-lock-mode (font-lock-fontify-buffer)))))))
3119 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t)
3121 ;;;--------------------------------------------------------------------------
3124 (defun mdw-setup-sh-script-mode ()
3126 ;; Fetch the shell interpreter's name.
3127 (let ((shell-name sh-shell-file))
3129 ;; Try reading the hash-bang line.
3131 (goto-char (point-min))
3132 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3133 (setq shell-name (match-string 1))))
3135 ;; Now try to set the shell.
3137 ;; Don't let `sh-set-shell' bugger up my script.
3138 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3139 (sh-set-shell shell-name)))
3141 ;; Don't insert here-document scaffolding automatically.
3142 (local-set-key "<" 'self-insert-command)
3144 ;; Now enable my keys and the fontification.
3145 (mdw-misc-mode-config)
3147 ;; Set the indentation level correctly.
3148 (setq sh-indentation 2)
3149 (setq sh-basic-offset 2))
3151 (setq sh-shell-file "/bin/sh")
3153 ;; Awful hacking to override the shell detection for particular scripts.
3154 (defmacro define-custom-shell-mode (name shell)
3157 (set (make-local-variable 'sh-shell-file) ,shell)
3159 (define-custom-shell-mode bash-mode "/bin/bash")
3160 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3161 (put 'sh-shell-file 'permanent-local t)
3163 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3164 (eval-after-load "sh-script"
3165 '(or (assq 'rc sh-mode-syntax-table-input)
3182 (assoc (assq 'rc sh-mode-syntax-table-input)))
3185 (setq sh-mode-syntax-table-input
3186 (cons (cons 'rc frag)
3187 sh-mode-syntax-table-input))))))
3189 ;;;--------------------------------------------------------------------------
3190 ;;; Emacs shell mode.
3192 (defun mdw-eshell-prompt ()
3193 (let ((left "[") (right "]"))
3194 (when (= (user-uid) 0)
3195 (setq left "«" right "»"))
3198 (replace-regexp-in-string "\\..*$" "" (system-name)))
3200 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3201 (home (expand-file-name "~")) (nhome (length home)))
3202 (if (and (>= npwd nhome)
3204 (= (elt pwd nhome) ?/))
3205 (string= (substring pwd 0 nhome) home))
3206 (concat "~" (substring pwd (length home)))
3209 (setq eshell-prompt-function 'mdw-eshell-prompt)
3210 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3212 (defun eshell/e (file) (find-file file) nil)
3213 (defun eshell/ee (file) (find-file-other-window file) nil)
3214 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3216 (mdw-define-face eshell-prompt (t :weight bold))
3217 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3218 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3219 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3220 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3221 (mdw-define-face eshell-ls-executable (t :weight bold))
3222 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3223 (mdw-define-face eshell-ls-readonly (t nil))
3224 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3226 ;;;--------------------------------------------------------------------------
3227 ;;; Messages-file mode.
3229 (defun messages-mode-guts ()
3230 (setq messages-mode-syntax-table (make-syntax-table))
3231 (set-syntax-table messages-mode-syntax-table)
3232 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3233 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3234 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3235 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3236 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3237 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3238 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3239 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3240 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3241 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3242 (make-local-variable 'comment-start)
3243 (make-local-variable 'comment-end)
3244 (make-local-variable 'indent-line-function)
3245 (setq indent-line-function 'indent-relative)
3246 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3247 (make-local-variable 'font-lock-defaults)
3248 (make-local-variable 'messages-mode-keywords)
3250 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3251 "export" "enum" "fixed-octetstring" "flags"
3252 "harmless" "map" "nested" "optional"
3253 "optional-tagged" "package" "primitive"
3254 "primitive-nullfree" "relaxed[ \t]+enum"
3255 "set" "table" "tagged-optional" "union"
3256 "variadic" "vector" "version" "version-tag")))
3257 (setq messages-mode-keywords
3259 (list (concat "\\<\\(" keywords "\\)\\>:")
3260 '(0 font-lock-keyword-face))
3261 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
3262 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
3263 (0 font-lock-variable-name-face))
3264 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
3265 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3266 (0 mdw-punct-face)))))
3267 (setq font-lock-defaults
3268 '(messages-mode-keywords nil nil nil nil))
3269 (run-hooks 'messages-file-hook))
3271 (defun messages-mode ()
3274 (setq major-mode 'messages-mode)
3275 (setq mode-name "Messages")
3276 (messages-mode-guts)
3277 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
3278 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
3279 (setq comment-start "# ")
3280 (setq comment-end "")
3281 (run-hooks 'messages-mode-hook))
3283 (defun cpp-messages-mode ()
3286 (setq major-mode 'cpp-messages-mode)
3287 (setq mode-name "CPP Messages")
3288 (messages-mode-guts)
3289 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
3290 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
3291 (setq comment-start "/* ")
3292 (setq comment-end " */")
3293 (let ((preprocessor-keywords
3294 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3295 "ident" "if" "ifdef" "ifndef" "import" "include"
3296 "line" "pragma" "unassert" "undef" "warning")))
3297 (setq messages-mode-keywords
3298 (append (list (list (concat "^[ \t]*\\#[ \t]*"
3299 "\\(include\\|import\\)"
3300 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
3301 '(2 font-lock-string-face))
3302 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3303 preprocessor-keywords
3304 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3305 '(1 font-lock-keyword-face)))
3306 messages-mode-keywords)))
3307 (run-hooks 'cpp-messages-mode-hook))
3309 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
3310 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
3311 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
3313 ;;;--------------------------------------------------------------------------
3314 ;;; Messages-file mode.
3316 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
3317 "Face to use for subsittution directives.")
3318 (make-face 'mallow-driver-substitution-face)
3319 (defvar mallow-driver-text-face 'mallow-driver-text-face
3320 "Face to use for body text.")
3321 (make-face 'mallow-driver-text-face)
3323 (defun mallow-driver-mode ()
3326 (setq major-mode 'mallow-driver-mode)
3327 (setq mode-name "Mallow driver")
3328 (setq mallow-driver-mode-syntax-table (make-syntax-table))
3329 (set-syntax-table mallow-driver-mode-syntax-table)
3330 (make-local-variable 'comment-start)
3331 (make-local-variable 'comment-end)
3332 (make-local-variable 'indent-line-function)
3333 (setq indent-line-function 'indent-relative)
3334 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3335 (make-local-variable 'font-lock-defaults)
3336 (make-local-variable 'mallow-driver-mode-keywords)
3338 (mdw-regexps "each" "divert" "file" "if"
3339 "perl" "set" "string" "type" "write")))
3340 (setq mallow-driver-mode-keywords
3342 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
3343 '(0 font-lock-keyword-face))
3344 (list "^%\\s *\\(#.*\\|\\)$"
3345 '(0 font-lock-comment-face))
3347 '(0 font-lock-keyword-face))
3348 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
3350 '(0 mallow-driver-substitution-face t)))))
3351 (setq font-lock-defaults
3352 '(mallow-driver-mode-keywords nil nil nil nil))
3353 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
3354 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
3355 (setq comment-start "%# ")
3356 (setq comment-end "")
3357 (run-hooks 'mallow-driver-mode-hook))
3359 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
3361 ;;;--------------------------------------------------------------------------
3364 (defun nfast-debug-mode ()
3367 (setq major-mode 'nfast-debug-mode)
3368 (setq mode-name "NFast debug")
3369 (setq messages-mode-syntax-table (make-syntax-table))
3370 (set-syntax-table messages-mode-syntax-table)
3371 (make-local-variable 'font-lock-defaults)
3372 (make-local-variable 'nfast-debug-mode-keywords)
3373 (setq truncate-lines t)
3374 (setq nfast-debug-mode-keywords
3376 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
3377 (0 font-lock-keyword-face))
3378 (list (concat "^[ \t]+\\(\\("
3379 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3380 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3382 "[0-9a-fA-F]+\\)[ \t]*$")
3383 '(0 mdw-number-face))
3384 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
3385 (1 font-lock-keyword-face))
3386 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
3387 (1 font-lock-warning-face))
3388 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
3390 (list (concat "^[ \t]+\\.cmd=[ \t]+"
3391 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
3392 '(1 font-lock-keyword-face))
3393 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
3394 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
3395 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
3396 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
3397 (setq font-lock-defaults
3398 '(nfast-debug-mode-keywords nil nil nil nil))
3399 (run-hooks 'nfast-debug-mode-hook))
3401 ;;;--------------------------------------------------------------------------
3402 ;;; Other languages.
3406 (defun mdw-setup-smalltalk ()
3407 (and mdw-auto-indent
3408 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
3409 (make-local-variable 'mdw-auto-indent)
3410 (setq mdw-auto-indent nil)
3411 (local-set-key "\C-i" 'smalltalk-reindent))
3413 (defun mdw-fontify-smalltalk ()
3414 (make-local-variable 'font-lock-keywords)
3415 (setq font-lock-keywords
3417 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
3418 '(0 font-lock-keyword-face))
3419 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3420 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3421 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3422 '(0 mdw-number-face))
3423 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3424 '(0 mdw-punct-face)))))
3428 ;; Unpleasant bodge.
3429 (unless (boundp 'slime-repl-mode-map)
3430 (setq slime-repl-mode-map (make-sparse-keymap)))
3432 (defun mdw-indent-newline-and-indent ()
3434 (indent-for-tab-command)
3435 (newline-and-indent))
3437 (eval-after-load "cl-indent"
3439 (mapc #'(lambda (pair)
3441 'common-lisp-indent-function
3443 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
3444 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
3446 (defun mdw-common-lisp-indent ()
3447 (make-local-variable 'lisp-indent-function)
3448 (setq lisp-indent-function 'common-lisp-indent-function))
3450 (setq lisp-simple-loop-indentation 2
3451 lisp-loop-keyword-indentation 6
3452 lisp-loop-forms-indentation 6)
3454 (defun mdw-fontify-lispy ()
3457 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
3459 ;; Not much fontification needed.
3460 (make-local-variable 'font-lock-keywords)
3461 (setq font-lock-keywords
3462 (list (list (concat "\\("
3464 "\\(" "[0-9]+/[0-9]+"
3465 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
3467 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
3472 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
3473 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
3474 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
3475 "\\|" "[0-9]+" "r" "[-+]?"
3476 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
3479 '(0 mdw-number-face))
3480 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3481 '(0 mdw-punct-face)))))
3483 (defun comint-send-and-indent ()
3486 (and mdw-auto-indent
3487 (indent-for-tab-command)))
3489 (defun mdw-setup-m4 ()
3491 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
3492 ;; annoying: fix it.
3493 (modify-syntax-entry ?{ "(")
3494 (modify-syntax-entry ?} ")")
3497 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
3499 ;;;--------------------------------------------------------------------------
3502 (defun mdw-text-mode ()
3503 (setq fill-column 72)
3505 (mdw-standard-fill-prefix
3506 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
3509 ;;;--------------------------------------------------------------------------
3510 ;;; Outline and hide/show modes.
3512 (defun mdw-outline-collapse-all ()
3513 "Completely collapse everything in the entire buffer."
3516 (goto-char (point-min))
3517 (while (< (point) (point-max))
3521 (setq hs-hide-comments-when-hiding-all nil)
3523 (defadvice hs-hide-all (after hide-first-comment activate)
3524 (save-excursion (hs-hide-initial-comment-block)))
3526 ;;;--------------------------------------------------------------------------
3529 (defun mdw-sh-mode-setup ()
3530 (local-set-key [?\C-a] 'comint-bol)
3531 (add-hook 'comint-output-filter-functions
3532 'comint-watch-for-password-prompt))
3534 (defun mdw-term-mode-setup ()
3535 (setq term-prompt-regexp shell-prompt-pattern)
3536 (make-local-variable 'mouse-yank-at-point)
3537 (make-local-variable 'transient-mark-mode)
3538 (setq mouse-yank-at-point t)
3542 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
3543 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
3544 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
3545 (defun term-send-meta-meta-something ()
3547 (term-send-raw-string "\e\e")
3549 (eval-after-load 'term
3551 (define-key term-raw-map [?\e ?\e] nil)
3552 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
3553 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
3554 (define-key term-raw-map [M-right] 'term-send-meta-right)
3555 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
3556 (define-key term-raw-map [M-left] 'term-send-meta-left)
3557 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
3559 (defadvice term-exec (before program-args-list compile activate)
3560 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
3561 This allows you to pass a list of arguments through `ansi-term'."
3562 (let ((program (ad-get-arg 2)))
3565 (ad-set-arg 2 (car program))
3566 (ad-set-arg 4 (cdr program))))))
3569 "Open a terminal containing an ssh session to the HOST."
3570 (interactive "sHost: ")
3571 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
3573 (defvar git-grep-command
3574 "env PAGER=cat git grep --no-color -nH -e "
3575 "*The default command for \\[git-grep].")
3577 (defvar git-grep-history nil)
3579 (defun git-grep (command-args)
3580 "Run `git grep' with user-specified args and collect output in a buffer."
3582 (list (read-shell-command "Run git grep (like this): "
3583 git-grep-command 'git-grep-history)))
3584 (grep command-args))
3586 ;;;--------------------------------------------------------------------------
3587 ;;; Inferior Emacs Lisp.
3589 (setq comint-prompt-read-only t)
3591 (eval-after-load "comint"
3593 (define-key comint-mode-map "\C-w" 'comint-kill-region)
3594 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
3596 (eval-after-load "ielm"
3598 (define-key ielm-map "\C-w" 'comint-kill-region)
3599 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
3601 ;;;----- That's all, folks --------------------------------------------------
3603 (provide 'dot-emacs)