1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
3 ;;; Functions and macros for .emacs
5 ;;; (c) 2004 Mark Wooding
8 ;;;----- Licensing notice ---------------------------------------------------
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software Foundation,
22 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ;;;--------------------------------------------------------------------------
25 ;;; Check command-line.
27 (defvar mdw-fast-startup nil
28 "Whether .emacs should optimize for rapid startup.
29 This may be at the expense of cool features.")
30 (let ((probe nil) (next command-line-args))
32 (cond ((string= (car next) "--mdw-fast-startup")
33 (setq mdw-fast-startup t)
35 (rplacd probe (cdr next))
36 (setq command-line-args (cdr next))))
39 (setq next (cdr next))))
41 ;;;--------------------------------------------------------------------------
42 ;;; Some general utilities.
45 (unless (fboundp 'make-regexp)
49 (defmacro mdw-regexps (&rest list)
50 "Turn a LIST of strings into a single regular expression at compile-time."
53 `',(make-regexp list))
56 "This is not the key sequence you're looking for."
58 (error "wrong button"))
60 (defun mdw-emacs-version-p (major &optional minor)
61 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
62 (or (> emacs-major-version major)
63 (and (= emacs-major-version major)
64 (>= emacs-minor-version (or minor 0)))))
66 ;; Some error trapping.
68 ;; If individual bits of this file go tits-up, we don't particularly want
69 ;; the whole lot to stop right there and then, because it's bloody annoying.
71 (defmacro trap (&rest forms)
72 "Execute FORMS without allowing errors to propagate outside."
76 ,(if (cdr forms) (cons 'progn forms) (car forms))
77 (error (message "Error (trapped): %s in %s"
78 (error-message-string err)
81 ;; Configuration reading.
83 (defvar mdw-config nil)
84 (defun mdw-config (sym)
85 "Read the configuration variable named SYM."
88 (flet ((replace (what with)
89 (goto-char (point-min))
90 (while (re-search-forward what nil t)
91 (replace-match with t))))
93 (insert-file-contents "~/.mdw.conf")
94 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
95 (replace (concat "^[ \t]*"
96 "\\([-a-zA-Z0-9_.]*\\)"
99 "[ \t]**\\(\n\\|$\\)")
101 (car (read-from-string
102 (concat "(" (buffer-string) ")")))))))
103 (cdr (assq sym mdw-config)))
105 ;; Width configuration.
107 (defvar mdw-column-width
108 (string-to-number (or (mdw-config 'emacs-width) "77"))
109 "Width of Emacs columns.")
110 (defvar mdw-text-width mdw-column-width
111 "Expected width of text within columns.")
112 (put 'mdw-text-width 'safe-local-variable 'integerp)
114 ;; Local variables hacking.
116 (defun run-local-vars-mode-hook ()
117 "Run a hook for the major-mode after local variables have been processed."
118 (run-hooks (intern (concat (symbol-name major-mode)
119 "-local-variables-hook"))))
120 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
122 ;; Set up the load path convincingly.
124 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
125 (list (concat "/usr/share/"
126 (symbol-name debian-emacs-flavor)
128 (dolist (sub (directory-files dir t))
129 (when (and (file-accessible-directory-p sub)
130 (not (member sub load-path)))
131 (setq load-path (nconc load-path (list sub))))))
133 ;; Is an Emacs library available?
135 (defun library-exists-p (name)
136 "Return non-nil if NAME is an available library.
137 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
138 load path. The non-nil value is the filename we found for the
140 (let ((path load-path) elt (foundp nil))
141 (while (and path (not foundp))
142 (setq elt (car path))
143 (setq path (cdr path))
144 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
145 (and (file-exists-p file) file))
146 (let ((file (concat elt "/" name ".el")))
147 (and (file-exists-p file) file)))))
150 (defun maybe-autoload (symbol file &optional docstring interactivep type)
151 "Set an autoload if the file actually exists."
152 (and (library-exists-p file)
153 (autoload symbol file docstring interactivep type)))
155 (defun mdw-kick-menu-bar (&optional frame)
156 "Regenerate FRAME's menu bar so it doesn't have empty menus."
158 (unless frame (setq frame (selected-frame)))
159 (let ((old (frame-parameter frame 'menu-bar-lines)))
160 (set-frame-parameter frame 'menu-bar-lines 0)
161 (set-frame-parameter frame 'menu-bar-lines old)))
163 ;; Splitting windows.
165 (unless (fboundp 'scroll-bar-columns)
166 (defun scroll-bar-columns (side)
167 (cond ((eq side 'left) 0)
170 (unless (fboundp 'fringe-columns)
171 (defun fringe-columns (side)
172 (cond ((not window-system) 0)
176 (defun mdw-horizontal-window-overhead ()
177 "Computes the horizontal window overhead.
178 This is the number of columns used by fringes, scroll bars and other such
180 (if (not window-system)
183 (dolist (what '(scroll-bar fringe))
184 (dolist (side '(left right))
185 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
189 (defun mdw-split-window-horizontally (&optional width)
190 "Split a window horizontally.
191 Without a numeric argument, split the window approximately in
192 half. With a numeric argument WIDTH, allocate WIDTH columns to
193 the left-hand window (if positive) or -WIDTH columns to the
194 right-hand window (if negative). Space for scroll bars and
195 fringes is not taken out of the allowance for WIDTH, unlike
196 \\[split-window-horizontally]."
198 (split-window-horizontally
199 (cond ((null width) nil)
200 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
201 ((< width 0) width))))
203 (defun mdw-divvy-window (&optional width)
204 "Split a wide window into appropriate widths."
206 (setq width (cond (width (prefix-numeric-value width))
207 ((and window-system (mdw-emacs-version-p 22))
209 (t (1+ mdw-column-width))))
210 (let* ((win (selected-window))
211 (sb-width (mdw-horizontal-window-overhead))
212 (c (/ (+ (window-width) sb-width)
213 (+ width sb-width))))
216 (split-window-horizontally (+ width sb-width))
218 (select-window win)))
220 ;; Don't raise windows unless I say so.
222 (defvar mdw-inhibit-raise-frame nil
223 "*Whether `raise-frame' should do nothing when the frame is mapped.")
225 (defadvice raise-frame
226 (around mdw-inhibit (&optional frame) activate compile)
227 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
228 frame is actually mapped on the screen."
229 (if mdw-inhibit-raise-frame
230 (make-frame-visible frame)
233 (defmacro mdw-advise-to-inhibit-raise-frame (function)
234 "Advise the FUNCTION not to raise frames, even if it wants to."
235 `(defadvice ,function
236 (around mdw-inhibit-raise (&rest hunoz) activate compile)
237 "Don't raise the window unless you have to."
238 (let ((mdw-inhibit-raise-frame t))
241 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
242 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
244 ;; Bug fix for markdown-mode, which breaks point positioning during
246 (defadvice markdown-check-change-for-wiki-link
247 (around mdw-save-match activate compile)
248 "Save match data around the `markdown-mode' `after-change-functions' hook."
249 (save-match-data ad-do-it))
251 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
252 ;; always returns nil, with the result that all email addresses are lost.
253 ;; Replace the function entirely.
254 (defadvice bbdb-canonicalize-address
255 (around mdw-bug-fix activate compile)
256 "Don't use `run-hook-with-args', because that doesn't work."
257 (let ((net (ad-get-arg 0)))
259 ;; Make sure this is a proper hook list.
260 (if (functionp bbdb-canonicalize-net-hook)
261 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
263 ;; Iterate over the hooks until things converge.
266 (let (next (changep nil)
267 hook (hooks bbdb-canonicalize-net-hook))
269 (setq hook (pop hooks))
270 (setq next (funcall hook net))
271 (if (not (equal next net))
274 (setq donep (not changep)))))
275 (setq ad-return-value net)))
277 ;; Transient mark mode hacks.
279 (defadvice exchange-point-and-mark
280 (around mdw-highlight (&optional arg) activate compile)
281 "Maybe don't actually exchange point and mark.
282 If `transient-mark-mode' is on and the mark is inactive, then
283 just activate it. A non-trivial prefix argument will force the
284 usual behaviour. A trivial prefix argument (i.e., just C-u) will
285 activate the mark and temporarily enable `transient-mark-mode' if
287 (cond ((or mark-active
288 (and (not transient-mark-mode) (not arg))
289 (and arg (or (not (consp arg))
290 (not (= (car arg) 4)))))
293 (or transient-mark-mode (setq transient-mark-mode 'only))
294 (set-mark (mark t)))))
296 ;; Functions for sexp diary entries.
298 (defun mdw-not-org-mode (form)
299 "As FORM, but not in Org mode agenda."
300 (and (not mdw-diary-for-org-mode-p)
303 (defun mdw-weekday (l)
304 "Return non-nil if `date' falls on one of the days of the week in L.
305 L is a list of day numbers (from 0 to 6 for Sunday through to
306 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
307 the date stored in `date' falls on a listed day, then the
308 function returns non-nil."
309 (let ((d (calendar-day-of-week date)))
311 (memq (nth d '(sunday monday tuesday wednesday
312 thursday friday saturday)) l))))
314 (defun mdw-discordian-date (date)
315 "Return the Discordian calendar date corresponding to DATE.
317 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
319 The original is by David Pearson. I modified it to produce date components
320 as output rather than a string."
321 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
322 "Prickle-Prickle" "Setting Orange"])
323 (months ["Chaos" "Discord" "Confusion"
324 "Bureaucracy" "Aftermath"])
325 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
326 (year (- (extract-calendar-year date) 1900))
327 (month (1- (extract-calendar-month date)))
328 (day (1- (extract-calendar-day date)))
329 (julian (+ (aref day-count month) day))
330 (dyear (+ year 3066)))
331 (if (and (= month 1) (= day 28))
332 (cons dyear 'st-tibs-day)
334 (aref months (floor (/ julian 73)))
336 (aref days (mod julian 5))))))
338 (defun mdw-diary-discordian-date ()
339 "Convert the date in `date' to a string giving the Discordian date."
340 (let* ((ddate (mdw-discordian-date date))
341 (tail (format "in the YOLD %d" (car ddate))))
342 (if (eq (cdr ddate) 'st-tibs-day)
343 (format "St Tib's Day %s" tail)
344 (let ((season (cadr ddate))
345 (daynum (caddr ddate))
346 (dayname (cadddr ddate)))
347 (format "%s, the %d%s day of %s %s"
350 (let ((ldig (mod daynum 10)))
351 (cond ((= ldig 1) "st")
358 (defun mdw-todo (&optional when)
359 "Return non-nil today, or on WHEN, whichever is later."
360 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
361 (d (calendar-absolute-from-gregorian date)))
363 (setq w (max w (calendar-absolute-from-gregorian
365 ((not european-calendar-style)
377 (defvar mdw-diary-for-org-mode-p nil)
379 (defadvice org-agenda-list (around mdw-preserve-links activate)
380 (let ((mdw-diary-for-org-mode-p t))
383 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
384 "Trim leading space from the diary entry string."
386 (let ((str (ad-get-arg 1))
390 (setq str (cond ((null str) nil)
391 ((string-match "\\(^\\|\n\\)[ \t]+" str)
392 (replace-match "\\1" nil nil str))
393 ((and mdw-diary-for-org-mode-p
394 (string-match (concat
396 "\\(" diary-time-regexp
397 "\\(-" diary-time-regexp "\\)?"
399 "\\(\t[ \t]*\\| [ \t]+\\)")
401 (replace-match "\\1\\2 " nil nil str))
402 ((and (not mdw-diary-for-org-mode-p)
403 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
405 (replace-match "\\1" nil nil str))
407 (if (equal str old) (setq done t)))
408 (ad-set-arg 1 str))))
410 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
411 "Return a string rather than a list."
414 (dolist (e (let ((ee ad-return-value))
415 (if (atom ee) (list ee) ee)))
417 (when anyp (insert ?\n))
420 (setq ad-return-value
421 (and anyp (buffer-string))))))
423 ;; Fighting with Org-mode's evil key maps.
425 (defvar mdw-evil-keymap-keys
426 '(([S-up] . [?\C-c up])
427 ([S-down] . [?\C-c down])
428 ([S-left] . [?\C-c left])
429 ([S-right] . [?\C-c right])
430 (([M-up] [?\e up]) . [C-up])
431 (([M-down] [?\e down]) . [C-down])
432 (([M-left] [?\e left]) . [C-left])
433 (([M-right] [?\e right]) . [C-right]))
434 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
435 The value is an alist mapping evil keys (as a list, or singleton)
436 to good keys (in the same form).")
438 (defun mdw-clobber-evil-keymap (keymap)
439 "Replace evil key bindings in the KEYMAP.
440 Evil key bindings are defined in `mdw-evil-keymap-keys'."
441 (dolist (entry mdw-evil-keymap-keys)
443 (keys (if (listp (car entry))
446 (replacements (if (listp (cdr entry))
448 (list (cdr entry)))))
451 (setq binding (lookup-key keymap key))
453 (throw 'found nil))))
456 (define-key keymap key nil))
457 (dolist (key replacements)
458 (define-key keymap key binding))))))
460 (eval-after-load "org-latex"
463 "\\documentclass{strayman}
464 \\usepackage[utf8]{inputenc}
465 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
466 \\usepackage[T1]{fontenc}
467 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
468 ("\\section{%s}" . "\\section*{%s}")
469 ("\\subsection{%s}" . "\\subsection*{%s}")
470 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
471 ("\\paragraph{%s}" . "\\paragraph*{%s}")
472 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
473 org-export-latex-classes)))
475 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
476 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
477 org-export-docbook-xslt-stylesheet
478 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
480 ;; Some hacks to do with window placement.
482 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
483 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
484 (interactive "bBuffer: ")
485 (let ((home-frame (selected-frame))
486 (buffer (get-buffer buffer-or-name))
487 (safe-buffer (get-buffer "*scratch*")))
488 (mapc (lambda (frame)
489 (or (eq frame home-frame)
490 (mapc (lambda (window)
491 (and (eq (window-buffer window) buffer)
492 (set-window-buffer window safe-buffer)))
493 (window-list frame))))
496 (defvar mdw-inhibit-walk-windows nil
497 "If non-nil, then `walk-windows' does nothing.
498 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
499 buffers in random frames.")
501 (defadvice walk-windows (around mdw-inhibit activate)
502 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
503 (and (not mdw-inhibit-walk-windows)
506 (defadvice switch-to-buffer-other-frame
507 (around mdw-always-new-frame activate)
508 "Always make a new frame.
509 Even if an existing window in some random frame looks tempting."
510 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
512 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
513 "Don't try to do anything fancy with other frames.
514 Pretend they don't exist. They might be on other display devices."
517 ;;;--------------------------------------------------------------------------
518 ;;; Mail and news hacking.
520 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
521 "Major mode for editing news and mail messages from external programs.
522 Not much right now. Just support for doing MailCrypt stuff."
525 (run-hooks 'mail-setup-hook))
527 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
529 (add-hook 'mdwail-mode-hook
531 (set-buffer-file-coding-system 'utf-8)
532 (make-local-variable 'paragraph-separate)
533 (make-local-variable 'paragraph-start)
534 (setq paragraph-start
535 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
537 (setq paragraph-separate
538 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
539 paragraph-separate))))
541 ;; How to encrypt in mdwmail.
543 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
545 (setq start (save-excursion
546 (goto-char (point-min))
547 (or (search-forward "\n\n" nil t) (point-min)))))
549 (setq end (point-max)))
550 (mc-encrypt-generic recip scm start end from sign))
552 ;; How to sign in mdwmail.
554 (defun mdwmail-mc-sign (key scm start end uclr)
556 (setq start (save-excursion
557 (goto-char (point-min))
558 (or (search-forward "\n\n" nil t) (point-min)))))
560 (setq end (point-max)))
561 (mc-sign-generic key scm start end uclr))
563 ;; Some signature mangling.
565 (defun mdwmail-mangle-signature ()
567 (goto-char (point-min))
568 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
569 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
570 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
572 ;; Insert my login name into message-ids, so I can score replies.
574 (defadvice message-unique-id (after mdw-user-name last activate compile)
575 "Ensure that the user's name appears at the end of the message-id string,
576 so that it can be used for convenient filtering."
577 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
579 ;; Tell my movemail hack where movemail is.
581 ;; This is needed to shup up warnings about LD_PRELOAD.
583 (let ((path exec-path))
585 (let ((try (expand-file-name "movemail" (car path))))
586 (if (file-executable-p try)
587 (setenv "REAL_MOVEMAIL" try))
588 (setq path (cdr path)))))
590 ;; AUTHINFO GENERIC kludge.
592 (defvar nntp-authinfo-generic nil
593 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
595 Use this to arrange for per-server settings.")
597 (defun nntp-open-authinfo-kludge (buffer)
598 "Open a connection to SERVER using `authinfo-kludge'."
599 (let ((proc (start-process "nntpd" buffer
600 "env" (concat "NNTPAUTH="
601 (or nntp-authinfo-generic
603 (error "NNTPAUTH unset")))
604 "authinfo-kludge" nntp-address)))
606 (nntp-wait-for-string "^\r*200")
608 (delete-region (point-min) (point))
611 (eval-after-load "erc"
612 '(load "~/.ercrc.el"))
614 ;;;--------------------------------------------------------------------------
615 ;;; Utility functions.
617 (or (fboundp 'line-number-at-pos)
618 (defun line-number-at-pos (&optional pos)
619 (let ((opoint (or pos (point))) start)
622 (goto-char (point-min))
628 (1+ (count-lines 1 (point))))))))
630 (defun mdw-uniquify-alist (&rest alists)
631 "Return the concatenation of the ALISTS with duplicate elements removed.
632 The first association with a given key prevails; others are
633 ignored. The input lists are not modified, although they'll
634 probably become garbage."
636 (let ((start-list (cons nil nil)))
637 (mdw-do-uniquify start-list
642 (defun mdw-do-uniquify (done end l rest)
643 "A helper function for mdw-uniquify-alist.
644 The DONE argument is a list whose first element is `nil'. It
645 contains the uniquified alist built so far. The leading `nil' is
646 stripped off at the end of the operation; it's only there so that
647 DONE always references a cons cell. END refers to the final cons
648 cell in the DONE list; it is modified in place each time to avoid
649 the overheads of `append'ing all the time. The L argument is the
650 alist we're currently processing; the remaining alists are given
653 ;; There are several different cases to deal with here.
656 ;; Current list isn't empty. Add the first item to the DONE list if
657 ;; there's not an item with the same KEY already there.
658 (l (or (assoc (car (car l)) done)
660 (setcdr end (cons (car l) nil))
661 (setq end (cdr end))))
662 (mdw-do-uniquify done end (cdr l) rest))
664 ;; The list we were working on is empty. Shunt the next list into the
665 ;; current list position and go round again.
666 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
668 ;; Everything's done. Remove the leading `nil' from the DONE list and
669 ;; return it. Finished!
673 "Insert the current date in a pleasing way."
675 (insert (save-excursion
676 (let ((buffer (get-buffer-create "*tmp*")))
677 (unwind-protect (progn (set-buffer buffer)
679 (shell-command "date +%Y-%m-%d" t)
681 (delete-backward-char 1)
683 (kill-buffer buffer))))))
685 (defun uuencode (file &optional name)
686 "UUencodes a file, maybe calling it NAME, into the current buffer."
687 (interactive "fInput file name: ")
689 ;; If NAME isn't specified, then guess from the filename.
693 (or (string-match "[^/]*$" file) 0))))
694 (print (format "uuencode `%s' `%s'" file name))
696 ;; Now actually do the thing.
697 (call-process "uuencode" file t nil name))
699 (defvar np-file "~/.np"
700 "*Where the `now-playing' file is.")
702 (defun np (&optional arg)
703 "Grabs a `now-playing' string."
707 (goto-char (point-max))
709 (insert-file-contents np-file)))))
711 (defun mdw-version-< (ver-a ver-b)
712 "Answer whether VER-A is strictly earlier than VER-B.
713 VER-A and VER-B are version numbers, which are strings containing digit
714 sequences separated by `.'."
715 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
716 (split-string ver-a "\\.")))
717 (lb (mapcar (lambda (x) (car (read-from-string x)))
718 (split-string ver-b "\\."))))
721 (cond ((null la) (throw 'done lb))
722 ((null lb) (throw 'done nil))
723 ((< (car la) (car lb)) (throw 'done t))
724 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
725 (t (throw 'done nil)))))))
727 (defun mdw-check-autorevert ()
728 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
729 This takes into consideration whether it's been found using
730 tramp, which seems to get itself into a twist."
731 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
733 ((and (buffer-file-name)
734 (fboundp 'tramp-tramp-file-p)
735 (tramp-tramp-file-p (buffer-file-name)))
736 (unless global-auto-revert-ignore-buffer
737 (setq global-auto-revert-ignore-buffer 'tramp)))
738 ((eq global-auto-revert-ignore-buffer 'tramp)
739 (setq global-auto-revert-ignore-buffer nil))))
741 (defadvice find-file (after mdw-autorevert activate)
742 (mdw-check-autorevert))
743 (defadvice write-file (after mdw-autorevert activate)
744 (mdw-check-autorevert))
746 ;;;--------------------------------------------------------------------------
749 (defadvice dired-maybe-insert-subdir
750 (around mdw-marked-insertion first activate)
751 "The DIRNAME may be a list of directory names to insert.
752 Interactively, if files are marked, then insert all of them.
753 With a numeric prefix argument, select that many entries near
754 point; with a non-numeric prefix argument, prompt for listing
757 (list (dired-get-marked-files nil
758 (and (integerp current-prefix-arg)
761 (and current-prefix-arg
762 (not (integerp current-prefix-arg))
763 (read-string "Switches for listing: "
764 (or dired-subdir-switches
765 dired-actual-switches)))))
766 (let ((dirs (ad-get-arg 0)))
767 (dolist (dir (if (listp dirs) dirs (list dirs)))
771 (defun mdw-dired-run (args &optional syncp)
772 (interactive (let ((file (dired-get-filename t)))
773 (list (read-string (format "Arguments for %s: " file))
774 current-prefix-arg)))
775 (funcall (if syncp 'shell-command 'async-shell-command)
776 (concat (shell-quote-argument (dired-get-filename nil))
779 (eval-after-load "dired"
780 '(define-key dired-mode-map "X" 'mdw-dired-run))
782 ;;;--------------------------------------------------------------------------
785 (defun mdw-w3m-browse-url (url &optional new-session-p)
786 "Invoke w3m on the URL in its current window, or at least a different one.
787 If NEW-SESSION-P, start a new session."
788 (interactive "sURL: \nP")
790 (let ((window (selected-window)))
793 (select-window (or (and (not new-session-p)
794 (get-buffer-window "*w3m*"))
796 (if (one-window-p t) (split-window))
798 (w3m-browse-url url new-session-p))
799 (select-window window)))))
801 (defvar mdw-good-url-browsers
804 (w3m . mdw-w3m-browse-url)
806 "List of good browsers for mdw-good-url-browsers.
807 Each item is a browser function name, or a cons (CHECK . FUNC).
808 A symbol FOO stands for (FOO . FOO).")
810 (defun mdw-good-url-browser ()
811 "Return a good URL browser.
812 Trundle the list of such things, finding the first item for which
813 CHECK is fboundp, and returning the correponding FUNC."
814 (let ((bs mdw-good-url-browsers) b check func answer)
815 (while (and bs (not answer))
819 (setq check (car b) func (cdr b))
820 (setq check b func b))
825 (eval-after-load "w3m-search"
829 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
830 ("gd" "Google Directory"
831 "http://www.google.com/search?cat=gwd/Top&q=%s")
832 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
833 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
834 ("gi" "Images" "http://images.google.com/images?q=%s")
836 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
838 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
839 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
840 ("nc-wiki" "nCipher wiki"
841 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
842 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
843 ("lp" "Launchpad bug by number"
844 "https://bugs.launchpad.net/bugs/%s")
845 ("lppkg" "Launchpad bugs by package"
846 "https://bugs.launchpad.net/%s")
848 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
849 ("debbug" "Debian bug by number"
850 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
851 ("debbugpkg" "Debian bugs by package"
852 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
853 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
854 (add-to-list 'w3m-search-engine-alist
855 (list (cadr item) (caddr item) nil))
856 (add-to-list 'w3m-uri-replace-alist
857 (list (concat "\\`" (car item) ":")
858 'w3m-search-uri-replace
861 ;;;--------------------------------------------------------------------------
862 ;;; Paragraph filling.
866 (defvar mdw-fill-prefix nil
867 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
868 If there's no fill prefix currently set (by the `fill-prefix'
869 variable) and there's a match from one of the regexps here, it
870 gets used to set the fill-prefix for the current operation.
872 The variable is a list of items of the form `REGEXP . PREFIX'; if
873 the REGEXP matches, the PREFIX is used to set the fill prefix.
874 It in turn is a list of things:
876 STRING -- insert a literal string
877 (match . N) -- insert the thing matched by bracketed subexpression N
878 (pad . N) -- a string of whitespace the same width as subexpression N
879 (expr . FORM) -- the result of evaluating FORM")
881 (make-variable-buffer-local 'mdw-fill-prefix)
883 (defvar mdw-hanging-indents
885 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
888 "*Standard regexp matching parts of a hanging indent.
889 This is mainly useful in `auto-fill-mode'.")
891 ;; Setting things up.
893 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
895 ;; Utility functions.
897 (defun mdw-maybe-tabify (s)
898 "Tabify or untabify the string S, according to `indent-tabs-mode'."
899 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
903 (let ((start (point-min)) (end (point-max)))
904 (funcall tabfun (point-min) (point-max))
905 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
907 (defun mdw-examine-fill-prefixes (l)
908 "Given a list of dynamic fill prefixes, pick one which matches
909 context and return the static fill prefix to use. Point must be
910 at the start of a line, and match data must be saved."
912 ((looking-at (car (car l)))
913 (mdw-maybe-tabify (apply #'concat
914 (mapcar #'mdw-do-prefix-match
916 (t (mdw-examine-fill-prefixes (cdr l)))))
918 (defun mdw-maybe-car (p)
919 "If P is a pair, return (car P), otherwise just return P."
920 (if (consp p) (car p) p))
922 (defun mdw-padding (s)
923 "Return a string the same width as S but made entirely from whitespace."
924 (let* ((l (length s)) (i 0) (n (make-string l ? )))
931 (defun mdw-do-prefix-match (m)
932 "Expand a dynamic prefix match element.
933 See `mdw-fill-prefix' for details."
934 (cond ((not (consp m)) (format "%s" m))
935 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
936 ((eq (car m) 'pad) (mdw-padding (match-string
937 (mdw-maybe-car (cdr m)))))
938 ((eq (car m) 'eval) (eval (cdr m)))
941 (defun mdw-choose-dynamic-fill-prefix ()
942 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
943 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
944 ((not mdw-fill-prefix) fill-prefix)
948 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
950 (defun do-auto-fill ()
951 "Handle auto-filling, working out a dynamic fill prefix in the
952 case where there isn't a sensible static one."
953 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
956 (defun mdw-fill-paragraph ()
957 "Fill paragraph, getting a dynamic fill prefix."
959 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
960 (fill-paragraph nil)))
962 (defun mdw-standard-fill-prefix (rx &optional mat)
963 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
964 This is just a short-cut for setting the thing by hand, and by
965 design it doesn't cope with anything approximating a complicated
967 (setq mdw-fill-prefix
968 `((,(concat rx mdw-hanging-indents)
970 (pad . ,(or mat 2))))))
972 ;;;--------------------------------------------------------------------------
973 ;;; Other common declarations.
975 ;; Common mode settings.
977 (defvar mdw-auto-indent t
978 "Whether to indent automatically after a newline.")
980 (defun mdw-whitespace-mode (&optional arg)
981 "Turn on/off whitespace mode, but don't highlight trailing space."
983 (when (and (boundp 'whitespace-style)
984 (fboundp 'whitespace-mode))
985 (let ((whitespace-style (remove 'trailing whitespace-style)))
986 (whitespace-mode arg))
987 (setq show-trailing-whitespace whitespace-mode)))
989 (defvar mdw-do-misc-mode-hacking nil)
991 (defun mdw-misc-mode-config ()
993 (cond ((eq major-mode 'lisp-mode)
994 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
995 ((or (eq major-mode 'slime-repl-mode)
996 (eq major-mode 'asm-mode))
999 (local-set-key "\C-m" 'newline-and-indent))))
1000 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1001 (local-set-key [C-return] 'newline)
1002 (make-local-variable 'page-delimiter)
1003 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
1004 (setq comment-column 40)
1006 (setq fill-column mdw-text-width)
1007 (and (fboundp 'gtags-mode)
1009 (if (fboundp 'hs-minor-mode)
1010 (trap (hs-minor-mode t))
1011 (outline-minor-mode t))
1013 (trap (turn-on-font-lock)))
1015 (defun mdw-post-local-vars-misc-mode-config ()
1016 (setq whitespace-line-column mdw-text-width)
1017 (when (and mdw-do-misc-mode-hacking
1018 (not buffer-read-only))
1019 (setq show-trailing-whitespace t)
1020 (mdw-whitespace-mode 1)))
1021 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1023 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1024 `(progn ,@(mapcar (lambda (func)
1026 (after mdw-angry-fruit-salad activate)
1027 (when mdw-do-misc-mode-hacking
1028 (setq show-trailing-whitespace
1029 (not buffer-read-only))
1030 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1032 (mdw-advise-update-angry-fruit-salad toggle-read-only
1038 (eval-after-load 'gtags
1040 (dolist (key '([mouse-2] [mouse-3]))
1041 (define-key gtags-mode-map key nil))
1042 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1043 (define-key gtags-select-mode-map [C-S-mouse-2]
1044 'gtags-select-tag-by-event)
1045 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1046 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1048 ;; Backup file handling.
1050 (defvar mdw-backup-disable-regexps nil
1051 "*List of regular expressions: if a file name matches any of
1052 these then the file is not backed up.")
1054 (defun mdw-backup-enable-predicate (name)
1055 "[mdw]'s default backup predicate.
1056 Allows a backup if the standard predicate would allow it, and it
1057 doesn't match any of the regular expressions in
1058 `mdw-backup-disable-regexps'."
1059 (and (normal-backup-enable-predicate name)
1060 (let ((answer t) (list mdw-backup-disable-regexps))
1063 (if (string-match (car list) name)
1065 (setq list (cdr list)))
1067 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1071 (defun mdw-last-one-out-turn-off-the-lights (frame)
1072 "Disconnect from an X display if this was the last frame on that display."
1073 (let ((frame-display (frame-parameter frame 'display)))
1074 (when (and frame-display
1075 (eq window-system 'x)
1076 (not (some (lambda (fr)
1077 (and (not (eq fr frame))
1078 (string= (frame-parameter fr 'display)
1081 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1082 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1084 ;;;--------------------------------------------------------------------------
1087 (defvar mdw-point-overlay
1088 (let ((ov (make-overlay 0 0))
1090 (overlay-put ov 'priority 2)
1091 (put-text-property 0 1 'display '(left-fringe vertical-bar) s)
1092 (overlay-put ov 'before-string s)
1095 "An overlay used for showing where point is in the selected window.")
1097 (defun mdw-remove-point-overlay ()
1098 "Remove the current-point overlay."
1099 (delete-overlay mdw-point-overlay))
1101 (defun mdw-update-point-overlay ()
1102 "Mark the current point position with an overlay."
1103 (if (not mdw-point-overlay-mode)
1104 (mdw-remove-point-overlay)
1105 (overlay-put mdw-point-overlay 'window (selected-window))
1107 (move-overlay mdw-point-overlay
1108 (point) (1+ (point)) (current-buffer))
1109 (move-overlay mdw-point-overlay
1110 (1- (point)) (point) (current-buffer)))))
1112 (defvar mdw-point-overlay-buffers nil
1113 "List of buffers using `mdw-point-overlay-mode'.")
1115 (define-minor-mode mdw-point-overlay-mode
1116 "Indicate current line with an overlay."
1118 (let ((buffer (current-buffer)))
1119 (setq mdw-point-overlay-buffers
1120 (mapcan (lambda (buf)
1121 (if (and (buffer-live-p buf)
1122 (not (eq buf buffer)))
1124 mdw-point-overlay-buffers))
1125 (if mdw-point-overlay-mode
1126 (setq mdw-point-overlay-buffers
1127 (cons buffer mdw-point-overlay-buffers))))
1128 (cond (mdw-point-overlay-buffers
1129 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1130 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1132 (mdw-remove-point-overlay)
1133 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1134 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1136 (define-globalized-minor-mode mdw-global-point-overlay-mode
1137 mdw-point-overlay-mode
1138 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1140 ;;;--------------------------------------------------------------------------
1141 ;;; Fullscreen-ness.
1143 (defvar mdw-full-screen-parameters
1144 '((menu-bar-lines . 0)
1145 ;(vertical-scroll-bars . nil)
1147 "Frame parameters to set when making a frame fullscreen.")
1149 (defvar mdw-full-screen-save
1151 "Extra frame parameters to save when setting fullscreen.")
1153 (defun mdw-toggle-full-screen (&optional frame)
1154 "Show the FRAME fullscreen."
1157 (cond ((frame-parameter frame 'fullscreen)
1158 (set-frame-parameter frame 'fullscreen nil)
1159 (modify-frame-parameters
1161 (or (frame-parameter frame 'mdw-full-screen-saved)
1162 (mapcar (lambda (assoc)
1163 (assq (car assoc) default-frame-alist))
1164 mdw-full-screen-parameters))))
1166 (let ((saved (mapcar (lambda (param)
1167 (cons param (frame-parameter frame param)))
1168 (append (mapcar #'car
1169 mdw-full-screen-parameters)
1170 mdw-full-screen-save))))
1171 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1172 (modify-frame-parameters frame mdw-full-screen-parameters)
1173 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1175 ;;;--------------------------------------------------------------------------
1176 ;;; General fontification.
1178 (make-face 'mdw-virgin-face)
1180 (defmacro mdw-define-face (name &rest body)
1181 "Define a face, and make sure it's actually set as the definition."
1185 (copy-face 'mdw-virgin-face ',name)
1186 (defvar ,name ',name)
1187 (put ',name 'face-defface-spec ',body)
1188 (face-spec-set ',name ',body nil)))
1190 (mdw-define-face default
1191 (((type w32)) :family "courier new" :height 85)
1192 (((type x)) :family "6x13" :foundry "trad" :height 130)
1193 (((type color)) :foreground "white" :background "black")
1195 (mdw-define-face fixed-pitch
1196 (((type w32)) :family "courier new" :height 85)
1197 (((type x)) :family "6x13" :foundry "trad" :height 130)
1198 (t :foreground "white" :background "black"))
1199 (if (mdw-emacs-version-p 23)
1200 (mdw-define-face variable-pitch
1201 (((type x)) :family "sans" :height 100))
1202 (mdw-define-face variable-pitch
1203 (((type x)) :family "helvetica" :height 90)))
1204 (mdw-define-face region
1205 (((type tty) (class color)) :background "blue")
1206 (((type tty) (class mono)) :inverse-video t)
1207 (t :background "grey30"))
1208 (mdw-define-face match
1209 (((type tty) (class color)) :background "blue")
1210 (((type tty) (class mono)) :inverse-video t)
1211 (t :background "blue"))
1212 (mdw-define-face mc/cursor-face
1213 (((type tty) (class mono)) :inverse-video t)
1214 (t :background "red"))
1215 (mdw-define-face minibuffer-prompt
1217 (mdw-define-face mode-line
1218 (((class color)) :foreground "blue" :background "yellow"
1219 :box (:line-width 1 :style released-button))
1220 (t :inverse-video t))
1221 (mdw-define-face mode-line-inactive
1222 (((class color)) :foreground "yellow" :background "blue"
1223 :box (:line-width 1 :style released-button))
1224 (t :inverse-video t))
1225 (mdw-define-face nobreak-space
1227 (t :inherit escape-glyph :underline t))
1228 (mdw-define-face scroll-bar
1229 (t :foreground "black" :background "lightgrey"))
1230 (mdw-define-face fringe
1231 (t :foreground "yellow"))
1232 (mdw-define-face show-paren-match
1233 (((class color)) :background "darkgreen")
1235 (mdw-define-face show-paren-mismatch
1236 (((class color)) :background "red")
1237 (t :inverse-video t))
1238 (mdw-define-face highlight
1239 (((type x) (class color)) :background "DarkSeaGreen4")
1240 (((type tty) (class color)) :background "cyan")
1241 (t :inverse-video t))
1243 (mdw-define-face holiday-face
1244 (t :background "red"))
1245 (mdw-define-face calendar-today-face
1246 (t :foreground "yellow" :weight bold))
1248 (mdw-define-face comint-highlight-prompt
1250 (mdw-define-face comint-highlight-input
1253 (mdw-define-face ido-subdir
1254 (t :foreground "cyan" :weight bold))
1256 (mdw-define-face dired-directory
1257 (t :foreground "cyan" :weight bold))
1258 (mdw-define-face dired-symlink
1259 (t :foreground "cyan"))
1260 (mdw-define-face dired-perm-write
1263 (mdw-define-face trailing-whitespace
1264 (((class color)) :background "red")
1265 (t :inverse-video t))
1266 (mdw-define-face whitespace-line
1267 (((class color)) :background "darkred")
1268 (t :inverse-video t))
1269 (mdw-define-face mdw-punct-face
1270 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
1271 (mdw-define-face mdw-number-face
1272 (t :foreground "yellow"))
1273 (mdw-define-face mdw-trivial-face)
1274 (mdw-define-face font-lock-function-name-face
1276 (mdw-define-face font-lock-keyword-face
1278 (mdw-define-face font-lock-constant-face
1280 (mdw-define-face font-lock-builtin-face
1282 (mdw-define-face font-lock-type-face
1283 (t :weight bold :slant italic))
1284 (mdw-define-face font-lock-reference-face
1286 (mdw-define-face font-lock-variable-name-face
1288 (mdw-define-face font-lock-comment-delimiter-face
1289 (((class mono)) :weight bold)
1290 (((type tty) (class color)) :foreground "green")
1291 (t :slant italic :foreground "SeaGreen1"))
1292 (mdw-define-face font-lock-comment-face
1293 (((class mono)) :weight bold)
1294 (((type tty) (class color)) :foreground "green")
1295 (t :slant italic :foreground "SeaGreen1"))
1296 (mdw-define-face font-lock-string-face
1297 (((class mono)) :weight bold)
1298 (((class color)) :foreground "SkyBlue1"))
1300 (mdw-define-face message-separator
1301 (t :background "red" :foreground "white" :weight bold))
1302 (mdw-define-face message-cited-text
1303 (default :slant italic)
1304 (((type tty)) :foreground "cyan") (t :foreground "SkyBlue1"))
1305 (mdw-define-face message-header-cc
1306 (default :slant italic)
1307 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1308 (mdw-define-face message-header-newsgroups
1309 (default :slant italic)
1310 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1311 (mdw-define-face message-header-subject
1312 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1313 (mdw-define-face message-header-to
1314 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1315 (mdw-define-face message-header-xheader
1316 (default :slant italic)
1317 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1318 (mdw-define-face message-header-other
1319 (default :slant italic)
1320 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1321 (mdw-define-face message-header-name
1322 (default :weight bold)
1323 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1325 (mdw-define-face which-func
1328 (mdw-define-face gnus-header-name
1329 (default :weight bold)
1330 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1331 (mdw-define-face gnus-header-subject
1332 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1333 (mdw-define-face gnus-header-from
1334 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1335 (mdw-define-face gnus-header-to
1336 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1337 (mdw-define-face gnus-header-content
1338 (default :slant italic)
1339 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1341 (mdw-define-face gnus-cite-1
1342 (((type tty)) :foreground "cyan") (t :foreground "SkyBlue1"))
1343 (mdw-define-face gnus-cite-2
1344 (((type tty)) :foreground "blue") (t :foreground "RoyalBlue2"))
1345 (mdw-define-face gnus-cite-3
1346 (((type tty)) :foreground "magenta") (t :foreground "MediumOrchid"))
1347 (mdw-define-face gnus-cite-4
1348 (((type tty)) :foreground "red") (t :foreground "firebrick2"))
1349 (mdw-define-face gnus-cite-5
1350 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
1351 (mdw-define-face gnus-cite-6
1352 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
1353 (mdw-define-face gnus-cite-7
1354 (((type tty)) :foreground "cyan") (t :foreground "SlateBlue1"))
1355 (mdw-define-face gnus-cite-8
1356 (((type tty)) :foreground "blue") (t :foreground "RoyalBlue2"))
1357 (mdw-define-face gnus-cite-9
1358 (((type tty)) :foreground "magenta") (t :foreground "purple2"))
1359 (mdw-define-face gnus-cite-10
1360 (((type tty)) :foreground "red") (t :foreground "DarkOrange2"))
1361 (mdw-define-face gnus-cite-11
1362 (t :foreground "grey"))
1364 (mdw-define-face diff-header
1366 (mdw-define-face diff-index
1368 (mdw-define-face diff-file-header
1370 (mdw-define-face diff-hunk-header
1371 (t :foreground "SkyBlue1"))
1372 (mdw-define-face diff-function
1373 (t :foreground "SkyBlue1" :weight bold))
1374 (mdw-define-face diff-header
1375 (t :background "grey10"))
1376 (mdw-define-face diff-added
1377 (t :foreground "green"))
1378 (mdw-define-face diff-removed
1379 (t :foreground "red"))
1380 (mdw-define-face diff-context
1382 (mdw-define-face diff-refine-change
1383 (((class color) (type x)) :background "RoyalBlue4")
1385 (mdw-define-face diff-refine-removed
1386 (((class color) (type x)) :background "#500")
1388 (mdw-define-face diff-refine-added
1389 (((class color) (type x)) :background "#050")
1392 (setq ediff-force-faces t)
1393 (mdw-define-face ediff-current-diff-A
1394 (((class color) (type x)) :background "darkred")
1395 (((class color) (type tty)) :background "red")
1396 (t :inverse-video t))
1397 (mdw-define-face ediff-fine-diff-A
1398 (((class color) (type x)) :background "red3")
1399 (((class color) (type tty)) :inverse-video t)
1400 (t :inverse-video nil))
1401 (mdw-define-face ediff-even-diff-A
1402 (((class color) (type x)) :background "#300"))
1403 (mdw-define-face ediff-odd-diff-A
1404 (((class color) (type x)) :background "#300"))
1405 (mdw-define-face ediff-current-diff-B
1406 (((class color) (type x)) :background "darkgreen")
1407 (((class color) (type tty)) :background "magenta")
1408 (t :inverse-video t))
1409 (mdw-define-face ediff-fine-diff-B
1410 (((class color) (type x)) :background "green4")
1411 (((class color) (type tty)) :inverse-video t)
1412 (t :inverse-video nil))
1413 (mdw-define-face ediff-even-diff-B
1414 (((class color) (type x)) :background "#020"))
1415 (mdw-define-face ediff-odd-diff-B
1416 (((class color) (type x)) :background "#020"))
1417 (mdw-define-face ediff-current-diff-C
1418 (((class color) (type x)) :background "darkblue")
1419 (((class color) (type tty)) :background "blue")
1420 (t :inverse-video t))
1421 (mdw-define-face ediff-fine-diff-C
1422 (((class color) (type x)) :background "blue1")
1423 (((class color) (type tty)) :inverse-video t)
1424 (t :inverse-video nil))
1425 (mdw-define-face ediff-even-diff-C
1426 (((class color) (type x)) :background "#004"))
1427 (mdw-define-face ediff-odd-diff-C
1428 (((class color) (type x)) :background "#004"))
1429 (mdw-define-face ediff-current-diff-Ancestor
1430 (((class color) (type x)) :background "#630")
1431 (((class color) (type tty)) :background "blue")
1432 (t :inverse-video t))
1433 (mdw-define-face ediff-even-diff-Ancestor
1434 (((class color) (type x)) :background "#320"))
1435 (mdw-define-face ediff-odd-diff-Ancestor
1436 (((class color) (type x)) :background "#320"))
1438 (mdw-define-face magit-hash
1439 (((class color) (type x)) :foreground "grey40")
1440 (((class color) (type tty)) :foreground "blue"))
1441 (mdw-define-face magit-diff-hunk-heading
1442 (((class color) (type x)) :foreground "grey70" :background "grey25")
1443 (((class color) (type tty)) :foreground "yellow"))
1444 (mdw-define-face magit-diff-hunk-heading-highlight
1445 (((class color) (type x)) :foreground "grey70" :background "grey35")
1446 (((class color) (type tty)) :foreground "yellow" :background "blue"))
1447 (mdw-define-face magit-diff-added
1448 (((class color) (type x)) :foreground "#ddffdd" :background "#335533")
1449 (((class color) (type tty)) :foreground "green"))
1450 (mdw-define-face magit-diff-added-highlight
1451 (((class color) (type x)) :foreground "#cceecc" :background "#336633")
1452 (((class color) (type tty)) :foreground "green" :background "blue"))
1453 (mdw-define-face magit-diff-removed
1454 (((class color) (type x)) :foreground "#ffdddd" :background "#553333")
1455 (((class color) (type tty)) :foreground "red"))
1456 (mdw-define-face magit-diff-removed-highlight
1457 (((class color) (type x)) :foreground "#eecccc" :background "#663333")
1458 (((class color) (type tty)) :foreground "red" :background "blue"))
1460 (mdw-define-face dylan-header-background
1461 (((class color) (type x)) :background "NavyBlue")
1462 (t :background "blue"))
1464 (mdw-define-face erc-input-face
1465 (t :foreground "red"))
1467 (mdw-define-face woman-bold
1469 (mdw-define-face woman-italic
1472 (eval-after-load "rst"
1474 (mdw-define-face rst-level-1-face
1475 (t :foreground "SkyBlue1" :weight bold))
1476 (mdw-define-face rst-level-2-face
1477 (t :foreground "SeaGreen1" :weight bold))
1478 (mdw-define-face rst-level-3-face
1480 (mdw-define-face rst-level-4-face
1482 (mdw-define-face rst-level-5-face
1484 (mdw-define-face rst-level-6-face
1487 (mdw-define-face p4-depot-added-face
1488 (t :foreground "green"))
1489 (mdw-define-face p4-depot-branch-op-face
1490 (t :foreground "yellow"))
1491 (mdw-define-face p4-depot-deleted-face
1492 (t :foreground "red"))
1493 (mdw-define-face p4-depot-unmapped-face
1494 (t :foreground "SkyBlue1"))
1495 (mdw-define-face p4-diff-change-face
1496 (t :foreground "yellow"))
1497 (mdw-define-face p4-diff-del-face
1498 (t :foreground "red"))
1499 (mdw-define-face p4-diff-file-face
1500 (t :foreground "SkyBlue1"))
1501 (mdw-define-face p4-diff-head-face
1502 (t :background "grey10"))
1503 (mdw-define-face p4-diff-ins-face
1504 (t :foreground "green"))
1506 (mdw-define-face w3m-anchor-face
1507 (t :foreground "SkyBlue1" :underline t))
1508 (mdw-define-face w3m-arrived-anchor-face
1509 (t :foreground "SkyBlue1" :underline t))
1511 (mdw-define-face whizzy-slice-face
1512 (t :background "grey10"))
1513 (mdw-define-face whizzy-error-face
1514 (t :background "darkred"))
1516 ;; Ellipses used to indicate hidden text (and similar).
1517 (mdw-define-face mdw-ellipsis-face
1518 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1519 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1520 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1521 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1522 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1523 (set-display-table-slot standard-display-table 0 dollar)
1524 (set-display-table-slot standard-display-table 1 backslash)
1525 (set-display-table-slot standard-display-table 4
1526 (vector dot dot dot))
1527 (set-display-table-slot standard-display-table 5 bar))
1529 ;;;--------------------------------------------------------------------------
1530 ;;; C programming configuration.
1532 ;; Make C indentation nice.
1534 (defun mdw-c-lineup-arglist (langelem)
1535 "Hack for DWIMmery in c-lineup-arglist."
1537 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1539 (c-lineup-arglist langelem)))
1541 (defun mdw-c-indent-extern-mumble (langelem)
1542 "Indent `extern \"...\" {' lines."
1544 (back-to-indentation)
1546 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1550 (defun mdw-c-indent-arglist-nested (langelem)
1551 "Indent continued argument lists.
1552 If we've nested more than one argument list, then only introduce a single
1553 indentation anyway."
1554 (let ((context c-syntactic-context)
1555 (pos (c-langelem-2nd-pos c-syntactic-element))
1556 (should-indent-p t))
1558 (eq (caar context) 'arglist-cont-nonempty))
1559 (when (and (= (caddr (pop context)) pos)
1561 (memq (caar context) '(arglist-intro
1562 arglist-cont-nonempty)))
1563 (setq should-indent-p nil)))
1564 (if should-indent-p '+ 0)))
1566 (defvar mdw-define-c-styles-hook nil
1567 "Hook run when `cc-mode' starts up to define styles.")
1569 (defmacro mdw-define-c-style (name &rest assocs)
1570 "Define a C style, called NAME (a symbol), setting ASSOCs.
1571 A function, named `mdw-define-c-style/NAME', is defined to actually install
1572 the style using `c-add-style', and added to the hook
1573 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1575 (declare (indent defun))
1576 (let* ((name-string (symbol-name name))
1577 (func (intern (concat "mdw-define-c-style/" name-string))))
1579 (defun ,func () (c-add-style ,name-string ',assocs))
1580 (and (featurep 'cc-mode) (,func))
1581 (add-hook 'mdw-define-c-styles-hook ',func))))
1583 (eval-after-load "cc-mode"
1584 '(run-hooks 'mdw-define-c-styles-hook))
1586 (mdw-define-c-style mdw-trustonic-c
1587 (c-basic-offset . 4)
1588 (comment-column . 0)
1589 (c-indent-comment-alist (anchored-comment . (column . 0))
1590 (end-block . (space . 1))
1591 (cpp-end-block . (space . 1))
1592 (other . (space . 1)))
1593 (c-class-key . "class")
1594 (c-backslash-column . 0)
1595 (c-auto-align-backslashes . nil)
1596 (c-label-minimum-indentation . 0)
1597 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1598 (defun-open . (add 0 c-indent-one-line-block))
1599 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1600 (topmost-intro . mdw-c-indent-extern-mumble)
1601 (cpp-define-intro . 0)
1603 (inextern-lang . [0])
1609 (statement-cont . +)
1610 (statement-case-intro . +)))
1612 (mdw-define-c-style mdw-c
1613 (c-basic-offset . 2)
1614 (comment-column . 40)
1615 (c-class-key . "class")
1616 (c-backslash-column . 72)
1617 (c-label-minimum-indentation . 0)
1618 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1619 (defun-open . (add 0 c-indent-one-line-block))
1620 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1621 (topmost-intro . mdw-c-indent-extern-mumble)
1622 (cpp-define-intro . 0)
1624 (inextern-lang . [0])
1630 (statement-cont . +)
1631 (statement-case-intro . +)))
1633 (defun mdw-set-default-c-style (modes style)
1634 "Update the default CC Mode style for MODES to be STYLE.
1636 MODES may be a list of major mode names or a singleton. STYLE is a style
1638 (let ((modes (if (listp modes) modes (list modes)))
1639 (style (symbol-name style)))
1640 (setq c-default-style
1641 (append (mapcar (lambda (mode)
1644 (remove-if (lambda (assoc)
1645 (memq (car assoc) modes))
1646 (if (listp c-default-style)
1648 (list (cons 'other c-default-style))))))))
1649 (setq c-default-style "mdw-c")
1651 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
1653 (defvar mdw-c-comment-fill-prefix
1654 `((,(concat "\\([ \t]*/?\\)"
1657 "\\([A-Za-z]+:[ \t]*\\)?"
1658 mdw-hanging-indents)
1659 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1660 "Fill prefix matching C comments (both kinds).")
1662 (defun mdw-fontify-c-and-c++ ()
1664 ;; Fiddle with some syntax codes.
1665 (modify-syntax-entry ?* ". 23")
1666 (modify-syntax-entry ?/ ". 124b")
1667 (modify-syntax-entry ?\n "> b")
1670 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1672 ;; Now define things to be fontified.
1673 (make-local-variable 'font-lock-keywords)
1675 (mdw-regexps "alignas" ;C11 macro, C++11
1677 "and" ;C++, C95 macro
1678 "and_eq" ;C++, C95 macro
1679 "asm" ;K&R, C++, GCC
1680 "atomic" ;C11 macro, C++11 template type
1682 "bitand" ;C++, C95 macro
1683 "bitor" ;C++, C95 macro
1684 "bool" ;C++, C99 macro
1689 "char16_t" ;C++11, C11 library type
1690 "char32_t" ;C++11, C11 library type
1692 "complex" ;C99 macro, C++ template type
1693 "compl" ;C++, C95 macro
1697 "continue" ;K&R, C89
1699 "defined" ;C89 preprocessor
1706 ;; "entry" ;K&R -- never used
1717 "imaginary" ;C99 macro
1718 "inline" ;C++, C99, GCC
1725 "noreturn" ;C11 macro
1726 "not" ;C++, C95 macro
1727 "not_eq" ;C++, C95 macro
1730 "or" ;C++, C95 macro
1731 "or_eq" ;C++, C95 macro
1735 "register" ;K&R, C89
1736 "reinterpret_cast" ;C++
1743 "static_assert" ;C11 macro, C++11
1750 "thread_local" ;C11 macro, C++11
1756 "unsigned" ;K&R, C89
1761 "wchar_t" ;C++, C89 library type
1763 "xor" ;C++, C95 macro
1764 "xor_eq" ;C++, C95 macro
1773 "_Pragma" ;C99 preprocessor
1774 "_Static_assert" ;C11
1775 "_Thread_local" ;C11
1778 "__attribute__" ;GCC
1781 "__extension__" ;GCC
1791 (mdw-regexps "false" ;C++, C99 macro
1793 "true" ;C++, C99 macro
1795 (preprocessor-keywords
1796 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1797 "ident" "if" "ifdef" "ifndef" "import" "include"
1798 "line" "pragma" "unassert" "undef" "warning"))
1800 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1801 "interface" "private" "protected" "protocol" "public"
1804 (setq font-lock-keywords
1807 ;; Fontify include files as strings.
1808 (list (concat "^[ \t]*\\#[ \t]*"
1809 "\\(include\\|import\\)"
1810 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1811 '(2 font-lock-string-face))
1813 ;; Preprocessor directives are `references'?.
1814 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1815 preprocessor-keywords
1816 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1817 '(1 font-lock-keyword-face))
1819 ;; Handle the keywords defined above.
1820 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1821 '(0 font-lock-keyword-face))
1823 (list (concat "\\<\\(" c-keywords "\\)\\>")
1824 '(0 font-lock-keyword-face))
1826 (list (concat "\\<\\(" c-constants "\\)\\>")
1827 '(0 font-lock-variable-name-face))
1829 ;; Handle numbers too.
1831 ;; This looks strange, I know. It corresponds to the
1832 ;; preprocessor's idea of what a number looks like, rather than
1833 ;; anything sensible.
1834 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1835 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1836 '(0 mdw-number-face))
1838 ;; And anything else is punctuation.
1839 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1840 '(0 mdw-punct-face))))))
1842 ;;;--------------------------------------------------------------------------
1845 (define-derived-mode apcalc-mode c-mode "AP Calc"
1846 "Major mode for editing Calc code.")
1848 (defun mdw-fontify-apcalc ()
1850 ;; Fiddle with some syntax codes.
1851 (modify-syntax-entry ?* ". 23")
1852 (modify-syntax-entry ?/ ". 14")
1855 (setq comment-start "/* ")
1856 (setq comment-end " */")
1857 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1859 ;; Now define things to be fontified.
1860 (make-local-variable 'font-lock-keywords)
1862 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1863 "do" "else" "exit" "for" "global" "goto" "help" "if"
1864 "local" "mat" "obj" "print" "quit" "read" "return"
1865 "show" "static" "switch" "while" "write")))
1867 (setq font-lock-keywords
1870 ;; Handle the keywords defined above.
1871 (list (concat "\\<\\(" c-keywords "\\)\\>")
1872 '(0 font-lock-keyword-face))
1874 ;; Handle numbers too.
1876 ;; This looks strange, I know. It corresponds to the
1877 ;; preprocessor's idea of what a number looks like, rather than
1878 ;; anything sensible.
1879 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1880 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1881 '(0 mdw-number-face))
1883 ;; And anything else is punctuation.
1884 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1885 '(0 mdw-punct-face))))))
1887 ;;;--------------------------------------------------------------------------
1888 ;;; Java programming configuration.
1890 ;; Make indentation nice.
1892 (mdw-define-c-style mdw-java
1893 (c-basic-offset . 2)
1894 (c-backslash-column . 72)
1895 (c-offsets-alist (substatement-open . 0)
1900 (statement-case-intro . +)))
1901 (mdw-set-default-c-style 'java-mode 'mdw-java)
1903 ;; Declare Java fontification style.
1905 (defun mdw-fontify-java ()
1908 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1910 ;; Now define things to be fontified.
1911 (make-local-variable 'font-lock-keywords)
1912 (let ((java-keywords
1913 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1914 "char" "class" "const" "continue" "default" "do"
1915 "double" "else" "extends" "final" "finally" "float"
1916 "for" "goto" "if" "implements" "import" "instanceof"
1917 "int" "interface" "long" "native" "new" "package"
1918 "private" "protected" "public" "return" "short"
1919 "static" "switch" "synchronized" "throw" "throws"
1920 "transient" "try" "void" "volatile" "while"))
1923 (mdw-regexps "false" "null" "super" "this" "true")))
1925 (setq font-lock-keywords
1928 ;; Handle the keywords defined above.
1929 (list (concat "\\<\\(" java-keywords "\\)\\>")
1930 '(0 font-lock-keyword-face))
1932 ;; Handle the magic constants defined above.
1933 (list (concat "\\<\\(" java-constants "\\)\\>")
1934 '(0 font-lock-variable-name-face))
1936 ;; Handle numbers too.
1938 ;; The following isn't quite right, but it's close enough.
1939 (list (concat "\\<\\("
1940 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1941 "[0-9]+\\(\\.[0-9]*\\|\\)"
1942 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1944 '(0 mdw-number-face))
1946 ;; And anything else is punctuation.
1947 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1948 '(0 mdw-punct-face))))))
1950 ;;;--------------------------------------------------------------------------
1951 ;;; Javascript programming configuration.
1953 (defun mdw-javascript-style ()
1954 (setq js-indent-level 2)
1955 (setq js-expr-indent-offset 0))
1957 (defun mdw-fontify-javascript ()
1960 (mdw-javascript-style)
1961 (setq js-auto-indent-flag t)
1963 ;; Now define things to be fontified.
1964 (make-local-variable 'font-lock-keywords)
1965 (let ((javascript-keywords
1966 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1967 "char" "class" "const" "continue" "debugger" "default"
1968 "delete" "do" "double" "else" "enum" "export" "extends"
1969 "final" "finally" "float" "for" "function" "goto" "if"
1970 "implements" "import" "in" "instanceof" "int"
1971 "interface" "let" "long" "native" "new" "package"
1972 "private" "protected" "public" "return" "short"
1973 "static" "super" "switch" "synchronized" "throw"
1974 "throws" "transient" "try" "typeof" "var" "void"
1975 "volatile" "while" "with" "yield"
1977 "boolean" "byte" "char" "double" "float" "int" "long"
1979 (javascript-constants
1980 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
1981 "arguments" "this")))
1983 (setq font-lock-keywords
1986 ;; Handle the keywords defined above.
1987 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
1988 '(0 font-lock-keyword-face))
1990 ;; Handle the predefined constants defined above.
1991 (list (concat "\\_<\\(" javascript-constants "\\)\\_>")
1992 '(0 font-lock-variable-name-face))
1994 ;; Handle numbers too.
1996 ;; The following isn't quite right, but it's close enough.
1997 (list (concat "\\_<\\("
1998 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1999 "[0-9]+\\(\\.[0-9]*\\|\\)"
2000 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2002 '(0 mdw-number-face))
2004 ;; And anything else is punctuation.
2005 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2006 '(0 mdw-punct-face))))))
2008 ;;;--------------------------------------------------------------------------
2009 ;;; Scala programming configuration.
2011 (defun mdw-fontify-scala ()
2014 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2016 ;; Define things to be fontified.
2017 (make-local-variable 'font-lock-keywords)
2018 (let ((scala-keywords
2019 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2020 "extends" "final" "finally" "for" "forSome" "if"
2021 "implicit" "import" "lazy" "match" "new" "object"
2022 "override" "package" "private" "protected" "return"
2023 "sealed" "throw" "trait" "try" "type" "val"
2024 "var" "while" "with" "yield"))
2026 (mdw-regexps "false" "null" "super" "this" "true"))
2027 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2029 (setq font-lock-keywords
2032 ;; Magical identifiers between backticks.
2033 (list (concat "`\\([^`]+\\)`")
2034 '(1 font-lock-variable-name-face))
2036 ;; Handle the keywords defined above.
2037 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2038 '(0 font-lock-keyword-face))
2040 ;; Handle the constants defined above.
2041 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2042 '(0 font-lock-variable-name-face))
2044 ;; Magical identifiers between backticks.
2045 (list (concat "`\\([^`]+\\)`")
2046 '(1 font-lock-variable-name-face))
2048 ;; Handle numbers too.
2050 ;; As usual, not quite right.
2051 (list (concat "\\_<\\("
2052 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2053 "[0-9]+\\(\\.[0-9]*\\|\\)"
2054 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2056 '(0 mdw-number-face))
2058 ;; Identifiers with trailing operators.
2059 (list (concat "_\\(" punctuation "\\)+")
2060 '(0 mdw-trivial-face))
2062 ;; And everything else is punctuation.
2063 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2064 '(0 mdw-punct-face)))
2066 font-lock-syntactic-keywords
2069 ;; Single quotes around characters. But not when used to quote
2070 ;; symbol names. Ugh.
2071 (list (concat "\\('\\)"
2073 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2074 "u+" "[0-9a-fA-F]\\{4\\}"
2075 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2076 "\\|" "\\\\" "." "\\)"
2081 ;;;--------------------------------------------------------------------------
2082 ;;; C# programming configuration.
2084 ;; Make indentation nice.
2086 (mdw-define-c-style mdw-csharp
2087 (c-basic-offset . 2)
2088 (c-backslash-column . 72)
2089 (c-offsets-alist (substatement-open . 0)
2094 (statement-case-intro . +)))
2095 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2097 ;; Declare C# fontification style.
2099 (defun mdw-fontify-csharp ()
2102 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2104 ;; Now define things to be fontified.
2105 (make-local-variable 'font-lock-keywords)
2106 (let ((csharp-keywords
2107 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2108 "char" "checked" "class" "const" "continue" "decimal"
2109 "default" "delegate" "do" "double" "else" "enum"
2110 "event" "explicit" "extern" "finally" "fixed" "float"
2111 "for" "foreach" "goto" "if" "implicit" "in" "int"
2112 "interface" "internal" "is" "lock" "long" "namespace"
2113 "new" "object" "operator" "out" "override" "params"
2114 "private" "protected" "public" "readonly" "ref"
2115 "return" "sbyte" "sealed" "short" "sizeof"
2116 "stackalloc" "static" "string" "struct" "switch"
2117 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2118 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2122 (mdw-regexps "base" "false" "null" "this" "true")))
2124 (setq font-lock-keywords
2127 ;; Handle the keywords defined above.
2128 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2129 '(0 font-lock-keyword-face))
2131 ;; Handle the magic constants defined above.
2132 (list (concat "\\<\\(" csharp-constants "\\)\\>")
2133 '(0 font-lock-variable-name-face))
2135 ;; Handle numbers too.
2137 ;; The following isn't quite right, but it's close enough.
2138 (list (concat "\\<\\("
2139 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2140 "[0-9]+\\(\\.[0-9]*\\|\\)"
2141 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2143 '(0 mdw-number-face))
2145 ;; And anything else is punctuation.
2146 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2147 '(0 mdw-punct-face))))))
2149 (define-derived-mode csharp-mode java-mode "C#"
2150 "Major mode for editing C# code.")
2152 ;;;--------------------------------------------------------------------------
2153 ;;; F# programming configuration.
2155 (setq fsharp-indent-offset 2)
2157 (defun mdw-fontify-fsharp ()
2159 (let ((punct "=<>+-*/|&%!@?"))
2161 ((>= i (length punct)))
2162 (modify-syntax-entry (aref punct i) ".")))
2164 (modify-syntax-entry ?_ "_")
2165 (modify-syntax-entry ?( "(")
2166 (modify-syntax-entry ?) ")")
2168 (setq indent-tabs-mode nil)
2170 (let ((fsharp-keywords
2171 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2173 "checked" "class" "component" "const" "constraint"
2174 "constructor" "continue"
2175 "default" "delegate" "do" "done" "downcast" "downto"
2176 "eager" "elif" "else" "end" "exception" "extern"
2177 "finally" "fixed" "for" "fori" "fun" "function"
2180 "if" "in" "include" "inherit" "inline" "interface"
2183 "match" "measure" "member" "method" "mixin" "module"
2186 "object" "of" "open" "or" "override"
2187 "parallel" "params" "private" "process" "protected"
2189 "rec" "recursive" "return"
2190 "sealed" "sig" "static" "struct"
2191 "tailcall" "then" "to" "trait" "try" "type"
2193 "val" "virtual" "void" "volatile"
2194 "when" "while" "with"
2198 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2199 "base" "false" "null" "true"))
2202 (mdw-regexps "do" "let" "return" "use" "yield"))
2204 (preprocessor-keywords
2205 (mdw-regexps "if" "indent" "else" "endif")))
2207 (setq font-lock-keywords
2208 (list (list (concat "\\(^\\|[^\"]\\)"
2211 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2216 '(2 font-lock-comment-face))
2218 (list (concat "'" "\\("
2221 "\\|" "[0-9][0-9][0-9]"
2222 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2223 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2229 "\\(" "\\\\" "\\(.\\|\n\\)"
2232 '(0 font-lock-string-face))
2234 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2235 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2237 "\\_<\\(" fsharp-keywords "\\)\\_>")
2238 '(0 font-lock-keyword-face))
2239 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2240 '(0 font-lock-variable-name-face))
2242 (list (concat "\\_<"
2243 "\\(" "0[bB][01]+" "\\|"
2245 "0[xX][0-9a-fA-F]+" "\\)"
2246 "\\(" "lf\\|LF" "\\|"
2247 "[uU]?[ysnlL]?" "\\)"
2254 "\\([eE][-+]?[0-9]+\\)?"
2259 '(0 mdw-number-face))
2261 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2262 '(0 mdw-punct-face))))))
2264 (defun mdw-fontify-inferior-fsharp ()
2265 (mdw-fontify-fsharp)
2266 (setq font-lock-keywords
2267 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2268 (list "^>" '(0 font-lock-keyword-face)))
2269 font-lock-keywords)))
2271 ;;;--------------------------------------------------------------------------
2272 ;;; Go programming configuration.
2274 (defun mdw-fontify-go ()
2276 (make-local-variable 'font-lock-keywords)
2278 (mdw-regexps "break" "case" "chan" "const" "continue"
2279 "default" "defer" "else" "fallthrough" "for"
2280 "func" "go" "goto" "if" "import"
2281 "interface" "map" "package" "range" "return"
2282 "select" "struct" "switch" "type" "var"))
2284 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2285 "float32" "float64" "int" "uint8" "int16" "int32"
2286 "int64" "rune" "string" "uint" "uint8" "uint16"
2287 "uint32" "uint64" "uintptr" "void"
2288 "false" "iota" "nil" "true"
2290 "append" "cap" "copy" "delete" "imag" "len" "make"
2291 "new" "panic" "real" "recover")))
2293 (setq font-lock-keywords
2296 ;; Handle the keywords defined above.
2297 (list (concat "\\<\\(" go-keywords "\\)\\>")
2298 '(0 font-lock-keyword-face))
2299 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2300 '(0 font-lock-variable-name-face))
2302 ;; Strings and characters.
2304 "\\(" "[^\\']" "\\|"
2306 "\\(" "[abfnrtv\\'\"]" "\\|"
2307 "[0-7]\\{3\\}" "\\|"
2308 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2309 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2310 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2314 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2318 '(0 font-lock-string-face))
2320 ;; Handle numbers too.
2322 ;; The following isn't quite right, but it's close enough.
2323 (list (concat "\\<\\("
2324 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2325 "[0-9]+\\(\\.[0-9]*\\|\\)"
2326 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2327 '(0 mdw-number-face))
2329 ;; And anything else is punctuation.
2330 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2331 '(0 mdw-punct-face))))))
2333 ;;;--------------------------------------------------------------------------
2334 ;;; Rust programming configuration.
2336 (setq-default rust-indent-offset 2)
2338 (defun mdw-self-insert-and-indent (count)
2340 (self-insert-command count)
2341 (indent-according-to-mode))
2343 (defun mdw-fontify-rust ()
2345 ;; Hack syntax categories.
2346 (modify-syntax-entry ?= ".")
2348 ;; Fontify keywords and things.
2349 (make-local-variable 'font-lock-keywords)
2350 (let ((rust-keywords
2351 (mdw-regexps "abstract" "alignof" "as"
2352 "become" "box" "break"
2353 "const" "continue" "create"
2355 "else" "enum" "extern"
2356 "false" "final" "fn" "for"
2359 "macro" "match" "mod" "move" "mut"
2360 "offsetof" "override"
2363 "self" "sizeof" "static" "struct" "super"
2364 "true" "trait" "type" "typeof"
2365 "unsafe" "unsized" "use"
2370 (mdw-regexps "array" "pointer" "slice" "tuple"
2371 "bool" "true" "false"
2373 "i8" "i16" "i32" "i64" "isize"
2374 "u8" "u16" "u32" "u64" "usize"
2376 (setq font-lock-keywords
2379 ;; Handle the keywords defined above.
2380 (list (concat "\\<\\(" rust-keywords "\\)\\>")
2381 '(0 font-lock-keyword-face))
2382 (list (concat "\\<\\(" rust-builtins "\\)\\>")
2383 '(0 font-lock-variable-name-face))
2385 ;; Handle numbers too.
2386 (list (concat "\\<\\("
2388 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2392 "\\|" "\\(" "[0-9][0-9_]*"
2393 "\\|" "0x[0-9a-fA-F_]+"
2397 "\\([ui]\\(8\\|16\\|32\\|64\\|s\\|size\\)\\)?"
2399 '(0 mdw-number-face))
2401 ;; And anything else is punctuation.
2402 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2403 '(0 mdw-punct-face)))))
2405 ;; Hack key bindings.
2406 (local-set-key [?{] 'mdw-self-insert-and-indent)
2407 (local-set-key [?}] 'mdw-self-insert-and-indent))
2409 ;;;--------------------------------------------------------------------------
2410 ;;; Awk programming configuration.
2412 ;; Make Awk indentation nice.
2414 (mdw-define-c-style mdw-awk
2415 (c-basic-offset . 2)
2416 (c-offsets-alist (substatement-open . 0)
2417 (c-backslash-column . 72)
2418 (statement-cont . 0)
2419 (statement-case-intro . +)))
2420 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2422 ;; Declare Awk fontification style.
2424 (defun mdw-fontify-awk ()
2426 ;; Miscellaneous fiddling.
2427 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2429 ;; Now define things to be fontified.
2430 (make-local-variable 'font-lock-keywords)
2432 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2433 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2434 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2435 "RSTART" "RLENGTH" "RT" "SUBSEP"
2436 "atan2" "break" "close" "continue" "cos" "delete"
2437 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2438 "function" "gensub" "getline" "gsub" "if" "in"
2439 "index" "int" "length" "log" "match" "next" "rand"
2440 "return" "print" "printf" "sin" "split" "sprintf"
2441 "sqrt" "srand" "strftime" "sub" "substr" "system"
2442 "systime" "tolower" "toupper" "while")))
2444 (setq font-lock-keywords
2447 ;; Handle the keywords defined above.
2448 (list (concat "\\<\\(" c-keywords "\\)\\>")
2449 '(0 font-lock-keyword-face))
2451 ;; Handle numbers too.
2453 ;; The following isn't quite right, but it's close enough.
2454 (list (concat "\\<\\("
2455 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2456 "[0-9]+\\(\\.[0-9]*\\|\\)"
2457 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2459 '(0 mdw-number-face))
2461 ;; And anything else is punctuation.
2462 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2463 '(0 mdw-punct-face))))))
2465 ;;;--------------------------------------------------------------------------
2466 ;;; Perl programming style.
2468 ;; Perl indentation style.
2470 (setq perl-indent-level 2)
2472 (setq cperl-indent-level 2)
2473 (setq cperl-continued-statement-offset 2)
2474 (setq cperl-continued-brace-offset 0)
2475 (setq cperl-brace-offset -2)
2476 (setq cperl-brace-imaginary-offset 0)
2477 (setq cperl-label-offset 0)
2479 ;; Define perl fontification style.
2481 (defun mdw-fontify-perl ()
2483 ;; Miscellaneous fiddling.
2484 (modify-syntax-entry ?$ "\\")
2485 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2486 (modify-syntax-entry ?: "." font-lock-syntax-table)
2487 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2489 ;; Now define fontification things.
2490 (make-local-variable 'font-lock-keywords)
2491 (let ((perl-keywords
2498 "ge" "given" "gt" "goto"
2500 "last" "le" "local" "lt"
2505 "redo" "require" "return"
2507 "undef" "unless" "until" "use"
2510 (setq font-lock-keywords
2513 ;; Set up the keywords defined above.
2514 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2515 '(0 font-lock-keyword-face))
2517 ;; At least numbers are simpler than C.
2518 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2519 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2520 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2521 '(0 mdw-number-face))
2523 ;; And anything else is punctuation.
2524 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2525 '(0 mdw-punct-face))))))
2527 (defun perl-number-tests (&optional arg)
2528 "Assign consecutive numbers to lines containing `#t'. With ARG,
2529 strip numbers instead."
2532 (goto-char (point-min))
2533 (let ((i 0) (fmt (if arg "" " %4d")))
2534 (while (search-forward "#t" nil t)
2535 (delete-region (point) (line-end-position))
2537 (insert (format fmt i)))
2538 (goto-char (point-min))
2539 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2540 (replace-match (format "\\1%d" i))))))
2542 ;;;--------------------------------------------------------------------------
2543 ;;; Python programming style.
2545 (defun mdw-fontify-pythonic (keywords)
2547 ;; Miscellaneous fiddling.
2548 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2549 (setq indent-tabs-mode nil)
2551 ;; Now define fontification things.
2552 (make-local-variable 'font-lock-keywords)
2553 (setq font-lock-keywords
2556 ;; Set up the keywords defined above.
2557 (list (concat "\\_<\\(" keywords "\\)\\_>")
2558 '(0 font-lock-keyword-face))
2560 ;; At least numbers are simpler than C.
2561 (list (concat "\\_<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2562 "\\_<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2563 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
2564 '(0 mdw-number-face))
2566 ;; And anything else is punctuation.
2567 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2568 '(0 mdw-punct-face)))))
2570 ;; Define Python fontification styles.
2572 (defun mdw-fontify-python ()
2573 (mdw-fontify-pythonic
2574 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
2575 "del" "elif" "else" "except" "exec" "finally" "for"
2576 "from" "global" "if" "import" "in" "is" "lambda"
2577 "not" "or" "pass" "print" "raise" "return" "try"
2578 "while" "with" "yield")))
2580 (defun mdw-fontify-pyrex ()
2581 (mdw-fontify-pythonic
2582 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
2583 "ctypedef" "def" "del" "elif" "else" "except" "exec"
2584 "extern" "finally" "for" "from" "global" "if"
2585 "import" "in" "is" "lambda" "not" "or" "pass" "print"
2586 "raise" "return" "struct" "try" "while" "with"
2589 ;;;--------------------------------------------------------------------------
2590 ;;; Lua programming style.
2592 (setq lua-indent-level 2)
2594 (defun mdw-fontify-lua ()
2596 ;; Miscellaneous fiddling.
2597 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2599 ;; Now define fontification things.
2600 (make-local-variable 'font-lock-keywords)
2602 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
2603 "false" "for" "function" "goto" "if" "in" "local"
2604 "nil" "not" "or" "repeat" "return" "then" "true"
2606 (setq font-lock-keywords
2609 ;; Set up the keywords defined above.
2610 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
2611 '(0 font-lock-keyword-face))
2613 ;; At least numbers are simpler than C.
2614 (list (concat "\\_<\\(" "0[xX]"
2615 "\\(" "[0-9a-fA-F]+"
2616 "\\(\\.[0-9a-fA-F]*\\)?"
2617 "\\|" "\\.[0-9a-fA-F]+"
2619 "\\([pP][-+]?[0-9]+\\)?"
2620 "\\|" "\\(" "[0-9]+"
2624 "\\([eE][-+]?[0-9]+\\)?"
2626 '(0 mdw-number-face))
2628 ;; And anything else is punctuation.
2629 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2630 '(0 mdw-punct-face))))))
2632 ;;;--------------------------------------------------------------------------
2633 ;;; Icon programming style.
2635 ;; Icon indentation style.
2637 (setq icon-brace-offset 0
2638 icon-continued-brace-offset 0
2639 icon-continued-statement-offset 2
2640 icon-indent-level 2)
2642 ;; Define Icon fontification style.
2644 (defun mdw-fontify-icon ()
2646 ;; Miscellaneous fiddling.
2647 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2649 ;; Now define fontification things.
2650 (make-local-variable 'font-lock-keywords)
2651 (let ((icon-keywords
2652 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
2653 "end" "every" "fail" "global" "if" "initial"
2654 "invocable" "link" "local" "next" "not" "of"
2655 "procedure" "record" "repeat" "return" "static"
2656 "suspend" "then" "to" "until" "while"))
2657 (preprocessor-keywords
2658 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
2659 "include" "line" "undef")))
2660 (setq font-lock-keywords
2663 ;; Set up the keywords defined above.
2664 (list (concat "\\<\\(" icon-keywords "\\)\\>")
2665 '(0 font-lock-keyword-face))
2667 ;; The things that Icon calls keywords.
2668 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
2670 ;; At least numbers are simpler than C.
2671 (list (concat "\\<[0-9]+"
2672 "\\([rR][0-9a-zA-Z]+\\|"
2673 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
2674 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
2675 '(0 mdw-number-face))
2678 (list (concat "^[ \t]*$[ \t]*\\<\\("
2679 preprocessor-keywords
2681 '(0 font-lock-keyword-face))
2683 ;; And anything else is punctuation.
2684 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2685 '(0 mdw-punct-face))))))
2687 ;;;--------------------------------------------------------------------------
2690 (defun mdw-fontify-asm ()
2691 (modify-syntax-entry ?' "\"")
2692 (modify-syntax-entry ?. "w")
2693 (modify-syntax-entry ?\n ">")
2694 (setf fill-prefix nil)
2695 (local-set-key ";" 'self-insert-command)
2696 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
2698 (defun mdw-asm-set-comment ()
2699 (modify-syntax-entry ?; "."
2701 (modify-syntax-entry asm-comment-char "<b")
2702 (setq comment-start (string asm-comment-char ? )))
2703 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
2704 (put 'asm-comment-char 'safe-local-variable 'characterp)
2706 ;;;--------------------------------------------------------------------------
2707 ;;; TCL configuration.
2709 (defun mdw-fontify-tcl ()
2710 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
2711 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2712 (make-local-variable 'font-lock-keywords)
2713 (setq font-lock-keywords
2715 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2716 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2717 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2718 '(0 mdw-number-face))
2719 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2720 '(0 mdw-punct-face)))))
2722 ;;;--------------------------------------------------------------------------
2723 ;;; Dylan programming configuration.
2725 (defun mdw-fontify-dylan ()
2727 (make-local-variable 'font-lock-keywords)
2729 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
2730 ;; hook, which undoes all of our configuration.
2731 (setq major-mode 'dylan-mode)
2732 (font-lock-set-defaults)
2734 (let* ((word "[-_a-zA-Z!*@<>$%]+")
2735 (dylan-keywords (mdw-regexps
2737 "C-address" "C-callable-wrapper" "C-function"
2738 "C-mapped-subtype" "C-pointer-type" "C-struct"
2739 "C-subtype" "C-union" "C-variable"
2741 "above" "abstract" "afterwards" "all"
2742 "begin" "below" "block" "by"
2743 "case" "class" "cleanup" "constant" "create"
2745 "else" "elseif" "end" "exception" "export"
2746 "finally" "for" "from" "function"
2749 "if" "in" "instance" "interface" "iterate"
2751 "let" "library" "local"
2752 "macro" "method" "module"
2755 "select" "slot" "subclass"
2757 "unless" "until" "use"
2758 "variable" "virtual"
2760 (sharp-keywords (mdw-regexps
2761 "all-keys" "key" "next" "rest" "include"
2763 (setq font-lock-keywords
2764 (list (list (concat "\\<\\(" dylan-keywords
2765 "\\|" "with\\(out\\)?-" word
2767 '(0 font-lock-keyword-face))
2768 (list (concat "\\<" word ":" "\\|"
2769 "#\\(" sharp-keywords "\\)\\>")
2770 '(0 font-lock-variable-name-face))
2772 "\\([-+]\\|\\<\\)[0-9]+" "\\("
2773 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
2776 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
2779 "\\|" "#x[0-9a-zA-Z]+"
2781 '(0 mdw-number-face))
2783 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
2784 "\\_<[-+*/=<>:&|]+\\_>"
2786 '(0 mdw-punct-face))))))
2788 ;;;--------------------------------------------------------------------------
2789 ;;; Algol 68 configuration.
2791 (setq a68-indent-step 2)
2793 (defun mdw-fontify-algol-68 ()
2795 ;; Fix up the syntax table.
2796 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
2797 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
2798 (modify-syntax-entry ch "." a68-mode-syntax-table))
2800 (make-local-variable 'font-lock-keywords)
2803 (let ((word "COMMENT"))
2804 (do ((regexp (concat "[^" (substring word 0 1) "]+")
2805 (concat regexp "\\|"
2806 (substring word 0 i)
2807 "[^" (substring word i (1+ i)) "]"))
2809 ((>= i (length word)) regexp)))))
2810 (setq font-lock-keywords
2811 (list (list (concat "\\<COMMENT\\>"
2812 "\\(" not-comment "\\)\\{0,5\\}"
2813 "\\(\\'\\|\\<COMMENT\\>\\)")
2814 '(0 font-lock-comment-face))
2815 (list (concat "\\<CO\\>"
2816 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
2817 "\\($\\|\\<CO\\>\\)")
2818 '(0 font-lock-comment-face))
2819 (list "\\<[A-Z_]+\\>"
2820 '(0 font-lock-keyword-face))
2824 "\\([eE][-+]?[0-9]+\\)?"
2826 '(0 mdw-number-face))
2827 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
2828 '(0 mdw-punct-face))))))
2830 ;;;--------------------------------------------------------------------------
2831 ;;; REXX configuration.
2833 (defun mdw-rexx-electric-* ()
2838 (defun mdw-rexx-indent-newline-indent ()
2841 (if abbrev-mode (expand-abbrev))
2842 (newline-and-indent))
2844 (defun mdw-fontify-rexx ()
2846 ;; Various bits of fiddling.
2847 (setq mdw-auto-indent nil)
2848 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
2849 (local-set-key [?*] 'mdw-rexx-electric-*)
2850 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
2852 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
2854 ;; Set up keywords and things for fontification.
2855 (make-local-variable 'font-lock-keywords-case-fold-search)
2856 (setq font-lock-keywords-case-fold-search t)
2858 (setq rexx-indent 2)
2859 (setq rexx-end-indent rexx-indent)
2860 (setq rexx-cont-indent rexx-indent)
2862 (make-local-variable 'font-lock-keywords)
2863 (let ((rexx-keywords
2864 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
2865 "else" "end" "engineering" "exit" "expose" "for"
2866 "forever" "form" "fuzz" "if" "interpret" "iterate"
2867 "leave" "linein" "name" "nop" "numeric" "off" "on"
2868 "options" "otherwise" "parse" "procedure" "pull"
2869 "push" "queue" "return" "say" "select" "signal"
2870 "scientific" "source" "then" "trace" "to" "until"
2871 "upper" "value" "var" "version" "when" "while"
2874 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
2875 "center" "center" "charin" "charout" "chars"
2876 "compare" "condition" "copies" "c2d" "c2x"
2877 "datatype" "date" "delstr" "delword" "d2c" "d2x"
2878 "errortext" "format" "fuzz" "insert" "lastpos"
2879 "left" "length" "lineout" "lines" "max" "min"
2880 "overlay" "pos" "queued" "random" "reverse" "right"
2881 "sign" "sourceline" "space" "stream" "strip"
2882 "substr" "subword" "symbol" "time" "translate"
2883 "trunc" "value" "verify" "word" "wordindex"
2884 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
2887 (setq font-lock-keywords
2890 ;; Set up the keywords defined above.
2891 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
2892 '(0 font-lock-keyword-face))
2894 ;; Fontify all symbols the same way.
2895 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
2896 "[A-Za-z0-9.!?_#@$]+\\)")
2897 '(0 font-lock-variable-name-face))
2899 ;; And everything else is punctuation.
2900 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2901 '(0 mdw-punct-face))))))
2903 ;;;--------------------------------------------------------------------------
2904 ;;; Standard ML programming style.
2906 (defun mdw-fontify-sml ()
2908 ;; Make underscore an honorary letter.
2909 (modify-syntax-entry ?' "w")
2912 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
2914 ;; Now define fontification things.
2915 (make-local-variable 'font-lock-keywords)
2917 (mdw-regexps "abstype" "and" "andalso" "as"
2920 "else" "end" "eqtype" "exception"
2921 "fn" "fun" "functor"
2923 "if" "in" "include" "infix" "infixr"
2926 "of" "op" "open" "orelse"
2928 "sharing" "sig" "signature" "struct" "structure"
2931 "where" "while" "with" "withtype")))
2933 (setq font-lock-keywords
2936 ;; Set up the keywords defined above.
2937 (list (concat "\\<\\(" sml-keywords "\\)\\>")
2938 '(0 font-lock-keyword-face))
2940 ;; At least numbers are simpler than C.
2941 (list (concat "\\<\\(\\~\\|\\)"
2942 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
2944 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
2945 "\\([eE]\\(\\~\\|\\)"
2946 "[0-9]+\\|\\)\\)\\)")
2947 '(0 mdw-number-face))
2949 ;; And anything else is punctuation.
2950 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2951 '(0 mdw-punct-face))))))
2953 ;;;--------------------------------------------------------------------------
2954 ;;; Haskell configuration.
2956 (defun mdw-fontify-haskell ()
2958 ;; Fiddle with syntax table to get comments right.
2959 (modify-syntax-entry ?' "_")
2960 (modify-syntax-entry ?- ". 12")
2961 (modify-syntax-entry ?\n ">")
2963 ;; Make punctuation be punctuation
2964 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
2966 ((>= i (length punct)))
2967 (modify-syntax-entry (aref punct i) ".")))
2970 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
2972 ;; Fiddle with fontification.
2973 (make-local-variable 'font-lock-keywords)
2974 (let ((haskell-keywords
2976 "case" "ccall" "class"
2977 "data" "default" "deriving" "do"
2981 "if" "import" "in" "infix" "infixl" "infixr" "instance"
2994 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
2995 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
2996 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
2997 "SP" "STX" "SUB" "SYN" "US" "VT")))
2999 (setq font-lock-keywords
3001 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3005 '(0 font-lock-comment-face))
3006 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
3007 '(0 font-lock-keyword-face))
3008 (list (concat "'\\("
3012 "\\(" "[abfnrtv\\\"']" "\\|"
3013 "^" "\\(" control-sequences "\\|"
3014 "[]A-Z@[\\^_]" "\\)" "\\|"
3021 '(0 font-lock-string-face))
3022 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3023 '(0 font-lock-variable-name-face))
3024 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3025 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
3026 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
3027 '(0 mdw-number-face))
3028 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3029 '(0 mdw-punct-face))))))
3031 ;;;--------------------------------------------------------------------------
3032 ;;; Erlang configuration.
3034 (setq erlang-electric-commands nil)
3036 (defun mdw-fontify-erlang ()
3039 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3041 ;; Fiddle with fontification.
3042 (make-local-variable 'font-lock-keywords)
3043 (let ((erlang-keywords
3044 (mdw-regexps "after" "and" "andalso"
3045 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3046 "case" "catch" "cond"
3047 "div" "end" "fun" "if" "let" "not"
3049 "query" "receive" "rem" "try" "when" "xor")))
3051 (setq font-lock-keywords
3054 '(0 font-lock-comment-face))
3055 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
3056 '(0 font-lock-keyword-face))
3057 (list (concat "^-\\sw+\\>")
3058 '(0 font-lock-keyword-face))
3059 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
3060 '(0 mdw-number-face))
3061 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3062 '(0 mdw-punct-face))))))
3064 ;;;--------------------------------------------------------------------------
3065 ;;; Texinfo configuration.
3067 (defun mdw-fontify-texinfo ()
3070 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
3072 ;; Real fontification things.
3073 (make-local-variable 'font-lock-keywords)
3074 (setq font-lock-keywords
3077 ;; Environment names are keywords.
3078 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3079 '(2 font-lock-keyword-face))
3081 ;; Unmark escaped magic characters.
3082 (list "\\(@\\)\\([@{}]\\)"
3083 '(1 font-lock-keyword-face)
3084 '(2 font-lock-variable-name-face))
3086 ;; Make sure we get comments properly.
3087 (list "@c\\(\\|omment\\)\\( .*\\)?$"
3088 '(0 font-lock-comment-face))
3090 ;; Command names are keywords.
3091 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3092 '(0 font-lock-keyword-face))
3094 ;; Fontify TeX special characters as punctuation.
3096 '(0 mdw-punct-face)))))
3098 ;;;--------------------------------------------------------------------------
3099 ;;; TeX and LaTeX configuration.
3101 (defun mdw-fontify-tex ()
3102 (setq ispell-parser 'tex)
3105 ;; Don't make maths into a string.
3106 (modify-syntax-entry ?$ ".")
3107 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3108 (local-set-key [?$] 'self-insert-command)
3110 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3111 (local-set-key "\C-i" 'indent-relative)
3112 (setq indent-tabs-mode nil)
3115 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3117 ;; Real fontification things.
3118 (make-local-variable 'font-lock-keywords)
3119 (setq font-lock-keywords
3122 ;; Environment names are keywords.
3123 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3125 '(2 font-lock-keyword-face))
3127 ;; Suspended environment names are keywords too.
3128 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3130 '(3 font-lock-keyword-face))
3132 ;; Command names are keywords.
3133 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3134 '(0 font-lock-keyword-face))
3136 ;; Handle @/.../ for italics.
3137 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3138 ;; '(1 font-lock-keyword-face)
3139 ;; '(3 font-lock-keyword-face))
3141 ;; Handle @*...* for boldness.
3142 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3143 ;; '(1 font-lock-keyword-face)
3144 ;; '(3 font-lock-keyword-face))
3146 ;; Handle @`...' for literal syntax things.
3147 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3148 ;; '(1 font-lock-keyword-face)
3149 ;; '(3 font-lock-keyword-face))
3151 ;; Handle @<...> for nonterminals.
3152 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3153 ;; '(1 font-lock-keyword-face)
3154 ;; '(3 font-lock-keyword-face))
3156 ;; Handle other @-commands.
3157 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3158 ;; '(0 font-lock-keyword-face))
3160 ;; Make sure we get comments properly.
3162 '(0 font-lock-comment-face))
3164 ;; Fontify TeX special characters as punctuation.
3166 '(0 mdw-punct-face)))))
3168 (eval-after-load 'font-latex
3169 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3170 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3171 ;; The following block is an expansion of `jit-lock-force-redisplay'
3172 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3173 (with-current-buffer buf
3174 (let ((modified (buffer-modified-p)))
3176 (let ((buffer-undo-list t)
3177 (inhibit-read-only t)
3178 (inhibit-point-motion-hooks t)
3179 (inhibit-modification-hooks t)
3182 buffer-file-truename)
3183 (put-text-property start end 'fontified t))
3185 (restore-buffer-modified-p nil)))))))
3187 ;;;--------------------------------------------------------------------------
3190 (defun mdw-sgml-mode ()
3193 (mdw-standard-fill-prefix "")
3194 (make-local-variable 'sgml-delimiters)
3195 (setq sgml-delimiters
3196 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3197 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3198 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3199 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3200 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3201 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3202 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3204 (setq major-mode 'mdw-sgml-mode)
3205 (setq mode-name "[mdw] SGML")
3206 (run-hooks 'mdw-sgml-mode-hook))
3208 ;;;--------------------------------------------------------------------------
3209 ;;; Configuration files.
3211 (defvar mdw-conf-quote-normal nil
3212 "*Control syntax category of quote characters `\"' and `''.
3213 If this is `t', consider quote characters to be normal
3214 punctuation, as for `conf-quote-normal'. If this is `nil' then
3215 leave quote characters as quotes. If this is a list, then
3216 consider the quote characters in the list to be normal
3217 punctuation. If this is a single quote character, then consider
3218 that character only to be normal punctuation.")
3219 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3220 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3221 (or (booleanp value)
3222 (every (lambda (v) (memq v '(?\" ?')))
3223 (if (listp value) value (list value)))))
3224 (put 'mdw-conf-quote-normal 'safe-local-variable
3225 'mdw-conf-quote-normal-acceptable-value-p)
3227 (defun mdw-fix-up-quote ()
3228 "Apply the setting of `mdw-conf-quote-normal'."
3229 (let ((flag mdw-conf-quote-normal))
3231 (conf-quote-normal t))
3235 (let ((table (copy-syntax-table (syntax-table))))
3236 (mapc (lambda (ch) (modify-syntax-entry ch "." table))
3237 (if (listp flag) flag (list flag)))
3238 (set-syntax-table table)
3239 (and font-lock-mode (font-lock-fontify-buffer)))))))
3240 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t)
3242 ;;;--------------------------------------------------------------------------
3245 (defun mdw-setup-sh-script-mode ()
3247 ;; Fetch the shell interpreter's name.
3248 (let ((shell-name sh-shell-file))
3250 ;; Try reading the hash-bang line.
3252 (goto-char (point-min))
3253 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3254 (setq shell-name (match-string 1))))
3256 ;; Now try to set the shell.
3258 ;; Don't let `sh-set-shell' bugger up my script.
3259 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3260 (sh-set-shell shell-name)))
3262 ;; Don't insert here-document scaffolding automatically.
3263 (local-set-key "<" 'self-insert-command)
3265 ;; Now enable my keys and the fontification.
3266 (mdw-misc-mode-config)
3268 ;; Set the indentation level correctly.
3269 (setq sh-indentation 2)
3270 (setq sh-basic-offset 2))
3272 (setq sh-shell-file "/bin/sh")
3274 ;; Awful hacking to override the shell detection for particular scripts.
3275 (defmacro define-custom-shell-mode (name shell)
3278 (set (make-local-variable 'sh-shell-file) ,shell)
3280 (define-custom-shell-mode bash-mode "/bin/bash")
3281 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3282 (put 'sh-shell-file 'permanent-local t)
3284 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3285 (eval-after-load "sh-script"
3286 '(or (assq 'rc sh-mode-syntax-table-input)
3303 (assoc (assq 'rc sh-mode-syntax-table-input)))
3306 (setq sh-mode-syntax-table-input
3307 (cons (cons 'rc frag)
3308 sh-mode-syntax-table-input))))))
3310 ;;;--------------------------------------------------------------------------
3311 ;;; Emacs shell mode.
3313 (defun mdw-eshell-prompt ()
3314 (let ((left "[") (right "]"))
3315 (when (= (user-uid) 0)
3316 (setq left "«" right "»"))
3319 (replace-regexp-in-string "\\..*$" "" (system-name)))
3321 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3322 (home (expand-file-name "~")) (nhome (length home)))
3323 (if (and (>= npwd nhome)
3325 (= (elt pwd nhome) ?/))
3326 (string= (substring pwd 0 nhome) home))
3327 (concat "~" (substring pwd (length home)))
3330 (setq eshell-prompt-function 'mdw-eshell-prompt)
3331 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3333 (defun eshell/e (file) (find-file file) nil)
3334 (defun eshell/ee (file) (find-file-other-window file) nil)
3335 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3337 (mdw-define-face eshell-prompt (t :weight bold))
3338 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3339 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3340 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3341 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3342 (mdw-define-face eshell-ls-executable (t :weight bold))
3343 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3344 (mdw-define-face eshell-ls-readonly (t nil))
3345 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3347 ;;;--------------------------------------------------------------------------
3348 ;;; Messages-file mode.
3350 (defun messages-mode-guts ()
3351 (setq messages-mode-syntax-table (make-syntax-table))
3352 (set-syntax-table messages-mode-syntax-table)
3353 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3354 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3355 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3356 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3357 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3358 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3359 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3360 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3361 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3362 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3363 (make-local-variable 'comment-start)
3364 (make-local-variable 'comment-end)
3365 (make-local-variable 'indent-line-function)
3366 (setq indent-line-function 'indent-relative)
3367 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3368 (make-local-variable 'font-lock-defaults)
3369 (make-local-variable 'messages-mode-keywords)
3371 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3372 "export" "enum" "fixed-octetstring" "flags"
3373 "harmless" "map" "nested" "optional"
3374 "optional-tagged" "package" "primitive"
3375 "primitive-nullfree" "relaxed[ \t]+enum"
3376 "set" "table" "tagged-optional" "union"
3377 "variadic" "vector" "version" "version-tag")))
3378 (setq messages-mode-keywords
3380 (list (concat "\\<\\(" keywords "\\)\\>:")
3381 '(0 font-lock-keyword-face))
3382 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
3383 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
3384 (0 font-lock-variable-name-face))
3385 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
3386 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3387 (0 mdw-punct-face)))))
3388 (setq font-lock-defaults
3389 '(messages-mode-keywords nil nil nil nil))
3390 (run-hooks 'messages-file-hook))
3392 (defun messages-mode ()
3395 (setq major-mode 'messages-mode)
3396 (setq mode-name "Messages")
3397 (messages-mode-guts)
3398 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
3399 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
3400 (setq comment-start "# ")
3401 (setq comment-end "")
3402 (run-hooks 'messages-mode-hook))
3404 (defun cpp-messages-mode ()
3407 (setq major-mode 'cpp-messages-mode)
3408 (setq mode-name "CPP Messages")
3409 (messages-mode-guts)
3410 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
3411 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
3412 (setq comment-start "/* ")
3413 (setq comment-end " */")
3414 (let ((preprocessor-keywords
3415 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3416 "ident" "if" "ifdef" "ifndef" "import" "include"
3417 "line" "pragma" "unassert" "undef" "warning")))
3418 (setq messages-mode-keywords
3419 (append (list (list (concat "^[ \t]*\\#[ \t]*"
3420 "\\(include\\|import\\)"
3421 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
3422 '(2 font-lock-string-face))
3423 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3424 preprocessor-keywords
3425 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3426 '(1 font-lock-keyword-face)))
3427 messages-mode-keywords)))
3428 (run-hooks 'cpp-messages-mode-hook))
3430 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
3431 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
3432 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
3434 ;;;--------------------------------------------------------------------------
3435 ;;; Messages-file mode.
3437 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
3438 "Face to use for subsittution directives.")
3439 (make-face 'mallow-driver-substitution-face)
3440 (defvar mallow-driver-text-face 'mallow-driver-text-face
3441 "Face to use for body text.")
3442 (make-face 'mallow-driver-text-face)
3444 (defun mallow-driver-mode ()
3447 (setq major-mode 'mallow-driver-mode)
3448 (setq mode-name "Mallow driver")
3449 (setq mallow-driver-mode-syntax-table (make-syntax-table))
3450 (set-syntax-table mallow-driver-mode-syntax-table)
3451 (make-local-variable 'comment-start)
3452 (make-local-variable 'comment-end)
3453 (make-local-variable 'indent-line-function)
3454 (setq indent-line-function 'indent-relative)
3455 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3456 (make-local-variable 'font-lock-defaults)
3457 (make-local-variable 'mallow-driver-mode-keywords)
3459 (mdw-regexps "each" "divert" "file" "if"
3460 "perl" "set" "string" "type" "write")))
3461 (setq mallow-driver-mode-keywords
3463 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
3464 '(0 font-lock-keyword-face))
3465 (list "^%\\s *\\(#.*\\|\\)$"
3466 '(0 font-lock-comment-face))
3468 '(0 font-lock-keyword-face))
3469 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
3471 '(0 mallow-driver-substitution-face t)))))
3472 (setq font-lock-defaults
3473 '(mallow-driver-mode-keywords nil nil nil nil))
3474 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
3475 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
3476 (setq comment-start "%# ")
3477 (setq comment-end "")
3478 (run-hooks 'mallow-driver-mode-hook))
3480 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
3482 ;;;--------------------------------------------------------------------------
3485 (defun nfast-debug-mode ()
3488 (setq major-mode 'nfast-debug-mode)
3489 (setq mode-name "NFast debug")
3490 (setq messages-mode-syntax-table (make-syntax-table))
3491 (set-syntax-table messages-mode-syntax-table)
3492 (make-local-variable 'font-lock-defaults)
3493 (make-local-variable 'nfast-debug-mode-keywords)
3494 (setq truncate-lines t)
3495 (setq nfast-debug-mode-keywords
3497 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
3498 (0 font-lock-keyword-face))
3499 (list (concat "^[ \t]+\\(\\("
3500 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3501 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3503 "[0-9a-fA-F]+\\)[ \t]*$")
3504 '(0 mdw-number-face))
3505 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
3506 (1 font-lock-keyword-face))
3507 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
3508 (1 font-lock-warning-face))
3509 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
3511 (list (concat "^[ \t]+\\.cmd=[ \t]+"
3512 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
3513 '(1 font-lock-keyword-face))
3514 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
3515 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
3516 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
3517 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
3518 (setq font-lock-defaults
3519 '(nfast-debug-mode-keywords nil nil nil nil))
3520 (run-hooks 'nfast-debug-mode-hook))
3522 ;;;--------------------------------------------------------------------------
3523 ;;; Other languages.
3527 (defun mdw-setup-smalltalk ()
3528 (and mdw-auto-indent
3529 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
3530 (make-local-variable 'mdw-auto-indent)
3531 (setq mdw-auto-indent nil)
3532 (local-set-key "\C-i" 'smalltalk-reindent))
3534 (defun mdw-fontify-smalltalk ()
3535 (make-local-variable 'font-lock-keywords)
3536 (setq font-lock-keywords
3538 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
3539 '(0 font-lock-keyword-face))
3540 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3541 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3542 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3543 '(0 mdw-number-face))
3544 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3545 '(0 mdw-punct-face)))))
3549 ;; Unpleasant bodge.
3550 (unless (boundp 'slime-repl-mode-map)
3551 (setq slime-repl-mode-map (make-sparse-keymap)))
3553 (defun mdw-indent-newline-and-indent ()
3555 (indent-for-tab-command)
3556 (newline-and-indent))
3558 (eval-after-load "cl-indent"
3560 (mapc #'(lambda (pair)
3562 'common-lisp-indent-function
3564 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
3565 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
3567 (defun mdw-common-lisp-indent ()
3568 (make-local-variable 'lisp-indent-function)
3569 (setq lisp-indent-function 'common-lisp-indent-function))
3571 (setq lisp-simple-loop-indentation 2
3572 lisp-loop-keyword-indentation 6
3573 lisp-loop-forms-indentation 6)
3575 (defun mdw-fontify-lispy ()
3578 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
3580 ;; Not much fontification needed.
3581 (make-local-variable 'font-lock-keywords)
3582 (setq font-lock-keywords
3583 (list (list (concat "\\("
3585 "\\(" "[0-9]+/[0-9]+"
3586 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
3588 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
3593 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
3594 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
3595 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
3596 "\\|" "[0-9]+" "r" "[-+]?"
3597 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
3600 '(0 mdw-number-face))
3601 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3602 '(0 mdw-punct-face)))))
3604 (defun comint-send-and-indent ()
3607 (and mdw-auto-indent
3608 (indent-for-tab-command)))
3610 (defun mdw-setup-m4 ()
3612 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
3613 ;; annoying: fix it.
3614 (modify-syntax-entry ?{ "(")
3615 (modify-syntax-entry ?} ")")
3618 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
3620 ;;;--------------------------------------------------------------------------
3623 (defun mdw-text-mode ()
3624 (setq fill-column 72)
3626 (mdw-standard-fill-prefix
3627 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
3630 ;;;--------------------------------------------------------------------------
3631 ;;; Outline and hide/show modes.
3633 (defun mdw-outline-collapse-all ()
3634 "Completely collapse everything in the entire buffer."
3637 (goto-char (point-min))
3638 (while (< (point) (point-max))
3642 (setq hs-hide-comments-when-hiding-all nil)
3644 (defadvice hs-hide-all (after hide-first-comment activate)
3645 (save-excursion (hs-hide-initial-comment-block)))
3647 ;;;--------------------------------------------------------------------------
3650 (defun mdw-sh-mode-setup ()
3651 (local-set-key [?\C-a] 'comint-bol)
3652 (add-hook 'comint-output-filter-functions
3653 'comint-watch-for-password-prompt))
3655 (defun mdw-term-mode-setup ()
3656 (setq term-prompt-regexp shell-prompt-pattern)
3657 (make-local-variable 'mouse-yank-at-point)
3658 (make-local-variable 'transient-mark-mode)
3659 (setq mouse-yank-at-point t)
3663 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
3664 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
3665 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
3666 (defun term-send-meta-meta-something ()
3668 (term-send-raw-string "\e\e")
3670 (eval-after-load 'term
3672 (define-key term-raw-map [?\e ?\e] nil)
3673 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
3674 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
3675 (define-key term-raw-map [M-right] 'term-send-meta-right)
3676 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
3677 (define-key term-raw-map [M-left] 'term-send-meta-left)
3678 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
3680 (defadvice term-exec (before program-args-list compile activate)
3681 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
3682 This allows you to pass a list of arguments through `ansi-term'."
3683 (let ((program (ad-get-arg 2)))
3686 (ad-set-arg 2 (car program))
3687 (ad-set-arg 4 (cdr program))))))
3690 "Open a terminal containing an ssh session to the HOST."
3691 (interactive "sHost: ")
3692 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
3694 (defvar git-grep-command
3695 "env PAGER=cat git grep --no-color -nH -e "
3696 "*The default command for \\[git-grep].")
3698 (defvar git-grep-history nil)
3700 (defun git-grep (command-args)
3701 "Run `git grep' with user-specified args and collect output in a buffer."
3703 (list (read-shell-command "Run git grep (like this): "
3704 git-grep-command 'git-grep-history)))
3705 (grep command-args))
3707 ;;;--------------------------------------------------------------------------
3708 ;;; Magit configuration.
3710 (setq magit-diff-refine-hunk 'all
3711 magit-view-git-manual-method 'man
3712 magit-log-margin '(nil age magit-log-margin-width t 18)
3713 magit-wip-after-save-local-mode-lighter ""
3714 magit-wip-after-apply-mode-lighter ""
3715 magit-wip-before-change-mode-lighter "")
3716 (eval-after-load "magit"
3717 '(progn (global-magit-file-mode 1)
3718 (magit-wip-after-save-mode 1)
3719 (magit-wip-after-apply-mode 1)
3720 (magit-wip-before-change-mode 1)
3721 (add-to-list 'magit-no-confirm 'safe-with-wip)
3722 (push '(:eval (if (or magit-wip-after-save-local-mode
3723 magit-wip-after-apply-mode
3724 magit-wip-before-change-mode)
3725 (format " wip:%s%s%s"
3726 (if magit-wip-after-apply-mode "A" "")
3727 (if magit-wip-before-change-mode "C" "")
3728 (if magit-wip-after-save-local-mode "S" ""))))
3730 (dolist (popup '(magit-diff-popup
3731 magit-diff-refresh-popup
3732 magit-diff-mode-refresh-popup
3733 magit-revision-mode-refresh-popup))
3734 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))))
3736 (setq magit-repolist-columns
3737 '(("Name" 16 magit-repolist-column-ident nil)
3738 ("Version" 18 magit-repolist-column-version nil)
3739 ("St" 2 magit-repolist-column-dirty nil)
3740 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
3741 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
3742 ("Path" 32 magit-repolist-column-path nil)))
3744 (setq magit-repository-directories '(("~/etc/profile" . 0)
3747 (defadvice magit-list-repos (around mdw-dirname () activate compile)
3748 "Make sure the returned names are directory names.
3749 Otherwise child processes get started in the wrong directory and
3751 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
3753 (defun mdw-repolist-column-unpulled-from-upstream (_id)
3754 "Insert number of upstream commits not in the current branch."
3755 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
3757 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
3758 (propertize (number-to-string n) 'face
3759 (if (> n 0) 'bold 'shadow))))))
3761 (defun mdw-repolist-column-unpushed-to-upstream (_id)
3762 "Insert number of commits in the current branch but not its upstream."
3763 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
3765 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
3766 (propertize (number-to-string n) 'face
3767 (if (> n 0) 'bold 'shadow))))))
3769 ;;;--------------------------------------------------------------------------
3770 ;;; MPC configuration.
3772 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
3774 (defun mdw-mpc-now-playing ()
3778 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
3779 (mpc--status-callback))
3780 (let ((state (cdr (assq 'state mpc-status))))
3781 (cond ((member state '("stop"))
3782 (message "mpd stopped."))
3783 ((member state '("play" "pause"))
3784 (let* ((artist (cdr (assq 'Artist mpc-status)))
3785 (album (cdr (assq 'Album mpc-status)))
3786 (title (cdr (assq 'Title mpc-status)))
3787 (file (cdr (assq 'file mpc-status)))
3788 (duration-string (cdr (assq 'Time mpc-status)))
3789 (time-string (cdr (assq 'time mpc-status)))
3790 (time (and time-string
3792 (if (string-match ":" time-string)
3793 (substring time-string
3794 0 (match-beginning 0))
3796 (duration (and duration-string
3797 (string-to-number duration-string)))
3798 (pos (and time duration
3799 (format " [%d:%02d/%d:%02d]"
3800 (/ time 60) (mod time 60)
3801 (/ duration 60) (mod duration 60))))
3802 (fmt (cond ((and artist title)
3803 (format "`%s' by %s%s" title artist
3804 (if album (format ", from `%s'" album)
3807 (format "`%s' (no tags)" file))
3809 "(no idea what's playing!)"))))
3810 (if (string= state "play")
3811 (message "mpd playing %s%s" fmt (or pos ""))
3812 (message "mpd paused in %s%s" fmt (or pos "")))))
3814 (message "mpd in unknown state `%s'" state)))))
3816 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
3818 (interactive ,@interactive)
3821 (mdw-mpc-now-playing)))
3823 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
3824 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
3828 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
3829 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
3830 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
3832 (defun mdw-mpc-hack-lines (arg interactivep func)
3833 (if (and interactivep (use-region-p))
3834 (let ((from (region-beginning)) (to (region-end)))
3839 (while (< (point) to)
3842 (let ((n (prefix-numeric-value arg)))
3859 (defun mdw-mpc-select-one ()
3860 (when (and (get-char-property (point) 'mpc-file)
3861 (not (get-char-property (point) 'mpc-select)))
3862 (mpc-select-toggle)))
3864 (defun mdw-mpc-unselect-one ()
3865 (when (get-char-property (point) 'mpc-select)
3866 (mpc-select-toggle)))
3868 (defun mdw-mpc-select (&optional arg interactivep)
3869 (interactive (list current-prefix-arg t))
3870 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
3872 (defun mdw-mpc-unselect (&optional arg interactivep)
3873 (interactive (list current-prefix-arg t))
3874 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
3876 (defun mdw-mpc-unselect-backwards (arg)
3878 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
3880 (defun mdw-mpc-unselect-all ()
3882 (setq mpc-select nil)
3883 (mpc-selection-refresh))
3885 (defun mdw-mpc-next-line (arg)
3890 (defun mdw-mpc-previous-line (arg)
3893 (forward-line (- arg)))
3895 (defun mdw-mpc-hack-tagbrowsers ()
3896 (setq-local mode-line-format
3898 mode-line-frame-identification
3899 mode-line-buffer-identification)))
3900 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
3902 (eval-after-load "mpc"
3904 (define-key mpc-mode-map "m" 'mdw-mpc-select)
3905 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
3906 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
3907 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
3908 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
3909 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
3910 (define-key mpc-mode-map "/" 'mpc-songs-search)
3911 (setq mpc-songs-mode-map (make-sparse-keymap))
3912 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
3913 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
3914 (define-key mpc-songs-mode-map "+" 'mpc-playlist-add)
3915 (define-key mpc-songs-mode-map "-" 'mpc-playlist-delete)
3916 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
3918 ;;;--------------------------------------------------------------------------
3919 ;;; Inferior Emacs Lisp.
3921 (setq comint-prompt-read-only t)
3923 (eval-after-load "comint"
3925 (define-key comint-mode-map "\C-w" 'comint-kill-region)
3926 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
3928 (eval-after-load "ielm"
3930 (define-key ielm-map "\C-w" 'comint-kill-region)
3931 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
3933 ;;;----- That's all, folks --------------------------------------------------
3935 (provide 'dot-emacs)