1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
3 ;;; Functions and macros for .emacs
5 ;;; (c) 2004 Mark Wooding
8 ;;;----- Licensing notice ---------------------------------------------------
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software Foundation,
22 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ;;;--------------------------------------------------------------------------
25 ;;; Check command-line.
27 (defvar mdw-fast-startup nil
28 "Whether .emacs should optimize for rapid startup.
29 This may be at the expense of cool features.")
30 (let ((probe nil) (next command-line-args))
32 (cond ((string= (car next) "--mdw-fast-startup")
33 (setq mdw-fast-startup t)
35 (rplacd probe (cdr next))
36 (setq command-line-args (cdr next))))
39 (setq next (cdr next))))
41 ;;;--------------------------------------------------------------------------
42 ;;; Some general utilities.
45 (unless (fboundp 'make-regexp)
49 (defmacro mdw-regexps (&rest list)
50 "Turn a LIST of strings into a single regular expression at compile-time."
53 `',(make-regexp list))
55 ;; Some error trapping.
57 ;; If individual bits of this file go tits-up, we don't particularly want
58 ;; the whole lot to stop right there and then, because it's bloody annoying.
60 (defmacro trap (&rest forms)
61 "Execute FORMS without allowing errors to propagate outside."
65 ,(if (cdr forms) (cons 'progn forms) (car forms))
66 (error (message "Error (trapped): %s in %s"
67 (error-message-string err)
70 ;; Configuration reading.
72 (defvar mdw-config nil)
73 (defun mdw-config (sym)
74 "Read the configuration variable named SYM."
77 (flet ((replace (what with)
78 (goto-char (point-min))
79 (while (re-search-forward what nil t)
80 (replace-match with t))))
82 (insert-file-contents "~/.mdw.conf")
83 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
84 (replace (concat "^[ \t]*"
85 "\\([-a-zA-Z0-9_.]*\\)"
88 "[ \t]**\\(\n\\|$\\)")
90 (car (read-from-string
91 (concat "(" (buffer-string) ")")))))))
92 (cdr (assq sym mdw-config)))
94 ;; Set up the load path convincingly.
96 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
97 (list (concat "/usr/share/"
98 (symbol-name debian-emacs-flavor)
100 (dolist (sub (directory-files dir t))
101 (when (and (file-accessible-directory-p sub)
102 (not (member sub load-path)))
103 (setq load-path (nconc load-path (list sub))))))
105 ;; Is an Emacs library available?
107 (defun library-exists-p (name)
108 "Return non-nil if NAME is an available library.
109 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
110 load path. The non-nil value is the filename we found for the
112 (let ((path load-path) elt (foundp nil))
113 (while (and path (not foundp))
114 (setq elt (car path))
115 (setq path (cdr path))
116 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
117 (and (file-exists-p file) file))
118 (let ((file (concat elt "/" name ".el")))
119 (and (file-exists-p file) file)))))
122 (defun maybe-autoload (symbol file &optional docstring interactivep type)
123 "Set an autoload if the file actually exists."
124 (and (library-exists-p file)
125 (autoload symbol file docstring interactivep type)))
127 ;; Splitting windows.
129 (unless (fboundp 'scroll-bar-columns)
130 (defun scroll-bar-columns (side)
131 (cond ((eq side 'left) 0)
134 (unless (fboundp 'fringe-columns)
135 (defun fringe-columns (side)
136 (cond ((not window-system) 0)
140 (defun mdw-divvy-window (&optional width)
141 "Split a wide window into appropriate widths."
143 (setq width (cond (width (prefix-numeric-value width))
145 (>= emacs-major-version 22))
148 (let* ((win (selected-window))
149 (sb-width (if (not window-system)
152 (dolist (what '(scroll-bar fringe))
153 (dolist (side '(left right))
155 (funcall (intern (concat (symbol-name what)
159 (c (/ (+ (window-width) sb-width)
160 (+ width sb-width))))
163 (split-window-horizontally (+ width sb-width))
165 (select-window win)))
167 ;; Functions for sexp diary entries.
169 (defun mdw-weekday (l)
170 "Return non-nil if `date' falls on one of the days of the week in L.
171 L is a list of day numbers (from 0 to 6 for Sunday through to
172 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
173 the date stored in `date' falls on a listed day, then the
174 function returns non-nil."
175 (let ((d (calendar-day-of-week date)))
177 (memq (nth d '(sunday monday tuesday wednesday
178 thursday friday saturday)) l))))
180 (defun mdw-todo (&optional when)
181 "Return non-nil today, or on WHEN, whichever is later."
182 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
183 (d (calendar-absolute-from-gregorian date)))
185 (setq w (max w (calendar-absolute-from-gregorian
187 ((not european-calendar-style)
199 ;; Fighting with Org-mode's evil key maps.
201 (defvar mdw-evil-keymap-keys
202 '(([S-up] . [?\C-c up])
203 ([S-down] . [?\C-c down])
204 ([S-left] . [?\C-c left])
205 ([S-right] . [?\C-c right])
206 (([M-up] [?\e up]) . [C-up])
207 (([M-down] [?\e down]) . [C-down])
208 (([M-left] [?\e left]) . [C-left])
209 (([M-right] [?\e right]) . [C-right]))
210 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
211 The value is an alist mapping evil keys (as a list, or singleton)
212 to good keys (in the same form).")
214 (defun mdw-clobber-evil-keymap (keymap)
215 "Replace evil key bindings in the KEYMAP.
216 Evil key bindings are defined in `mdw-evil-keymap-keys'."
217 (dolist (entry mdw-evil-keymap-keys)
219 (keys (if (listp (car entry))
222 (replacements (if (listp (cdr entry))
224 (list (cdr entry)))))
227 (setq binding (lookup-key keymap key))
229 (throw 'found nil))))
232 (define-key keymap key nil))
233 (dolist (key replacements)
234 (define-key keymap key binding))))))
236 (eval-after-load "org-latex"
239 "\\documentclass{strayman}
240 \\usepackage[utf8]{inputenc}
241 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
242 \\usepackage[T1]{fontenc}
243 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
244 ("\\section{%s}" . "\\section*{%s}")
245 ("\\subsection{%s}" . "\\subsection*{%s}")
246 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
247 ("\\paragraph{%s}" . "\\paragraph*{%s}")
248 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
249 org-export-latex-classes)))
251 ;;;--------------------------------------------------------------------------
252 ;;; Mail and news hacking.
254 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
255 "Major mode for editing news and mail messages from external programs.
256 Not much right now. Just support for doing MailCrypt stuff."
259 (run-hooks 'mail-setup-hook))
261 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
263 (add-hook 'mdwail-mode-hook
265 (set-buffer-file-coding-system 'utf-8)
266 (make-local-variable 'paragraph-separate)
267 (make-local-variable 'paragraph-start)
268 (setq paragraph-start
269 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
271 (setq paragraph-separate
272 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
273 paragraph-separate))))
275 ;; How to encrypt in mdwmail.
277 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
279 (setq start (save-excursion
280 (goto-char (point-min))
281 (or (search-forward "\n\n" nil t) (point-min)))))
283 (setq end (point-max)))
284 (mc-encrypt-generic recip scm start end from sign))
286 ;; How to sign in mdwmail.
288 (defun mdwmail-mc-sign (key scm start end uclr)
290 (setq start (save-excursion
291 (goto-char (point-min))
292 (or (search-forward "\n\n" nil t) (point-min)))))
294 (setq end (point-max)))
295 (mc-sign-generic key scm start end uclr))
297 ;; Some signature mangling.
299 (defun mdwmail-mangle-signature ()
301 (goto-char (point-min))
302 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
303 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
304 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
306 ;; Insert my login name into message-ids, so I can score replies.
308 (defadvice message-unique-id (after mdw-user-name last activate compile)
309 "Ensure that the user's name appears at the end of the message-id string,
310 so that it can be used for convenient filtering."
311 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
313 ;; Tell my movemail hack where movemail is.
315 ;; This is needed to shup up warnings about LD_PRELOAD.
317 (let ((path exec-path))
319 (let ((try (expand-file-name "movemail" (car path))))
320 (if (file-executable-p try)
321 (setenv "REAL_MOVEMAIL" try))
322 (setq path (cdr path)))))
324 ;;;--------------------------------------------------------------------------
325 ;;; Utility functions.
327 (or (fboundp 'line-number-at-pos)
328 (defun line-number-at-pos (&optional pos)
329 (let ((opoint (or pos (point))) start)
332 (goto-char (point-min))
338 (1+ (count-lines 1 (point))))))))
340 (defun mdw-uniquify-alist (&rest alists)
341 "Return the concatenation of the ALISTS with duplicate elements removed.
342 The first association with a given key prevails; others are
343 ignored. The input lists are not modified, although they'll
344 probably become garbage."
346 (let ((start-list (cons nil nil)))
347 (mdw-do-uniquify start-list
352 (defun mdw-do-uniquify (done end l rest)
353 "A helper function for mdw-uniquify-alist.
354 The DONE argument is a list whose first element is `nil'. It
355 contains the uniquified alist built so far. The leading `nil' is
356 stripped off at the end of the operation; it's only there so that
357 DONE always references a cons cell. END refers to the final cons
358 cell in the DONE list; it is modified in place each time to avoid
359 the overheads of `append'ing all the time. The L argument is the
360 alist we're currently processing; the remaining alists are given
363 ;; There are several different cases to deal with here.
366 ;; Current list isn't empty. Add the first item to the DONE list if
367 ;; there's not an item with the same KEY already there.
368 (l (or (assoc (car (car l)) done)
370 (setcdr end (cons (car l) nil))
371 (setq end (cdr end))))
372 (mdw-do-uniquify done end (cdr l) rest))
374 ;; The list we were working on is empty. Shunt the next list into the
375 ;; current list position and go round again.
376 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
378 ;; Everything's done. Remove the leading `nil' from the DONE list and
379 ;; return it. Finished!
383 "Insert the current date in a pleasing way."
385 (insert (save-excursion
386 (let ((buffer (get-buffer-create "*tmp*")))
387 (unwind-protect (progn (set-buffer buffer)
389 (shell-command "date +%Y-%m-%d" t)
391 (delete-backward-char 1)
393 (kill-buffer buffer))))))
395 (defun uuencode (file &optional name)
396 "UUencodes a file, maybe calling it NAME, into the current buffer."
397 (interactive "fInput file name: ")
399 ;; If NAME isn't specified, then guess from the filename.
403 (or (string-match "[^/]*$" file) 0))))
404 (print (format "uuencode `%s' `%s'" file name))
406 ;; Now actually do the thing.
407 (call-process "uuencode" file t nil name))
409 (defvar np-file "~/.np"
410 "*Where the `now-playing' file is.")
412 (defun np (&optional arg)
413 "Grabs a `now-playing' string."
417 (goto-char (point-max))
419 (insert-file-contents np-file)))))
421 (defun mdw-version-< (ver-a ver-b)
422 "Answer whether VER-A is strictly earlier than VER-B.
423 VER-A and VER-B are version numbers, which are strings containing digit
424 sequences separated by `.'."
425 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
426 (split-string ver-a "\\.")))
427 (lb (mapcar (lambda (x) (car (read-from-string x)))
428 (split-string ver-b "\\."))))
431 (cond ((null la) (throw 'done lb))
432 ((null lb) (throw 'done nil))
433 ((< (car la) (car lb)) (throw 'done t))
434 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb))))))))
436 (defun mdw-check-autorevert ()
437 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
438 This takes into consideration whether it's been found using
439 tramp, which seems to get itself into a twist."
440 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
442 ((and (buffer-file-name)
443 (fboundp 'tramp-tramp-file-p)
444 (tramp-tramp-file-p (buffer-file-name)))
445 (unless global-auto-revert-ignore-buffer
446 (setq global-auto-revert-ignore-buffer 'tramp)))
447 ((eq global-auto-revert-ignore-buffer 'tramp)
448 (setq global-auto-revert-ignore-buffer nil))))
450 (defadvice find-file (after mdw-autorevert activate)
451 (mdw-check-autorevert))
452 (defadvice write-file (after mdw-autorevert activate)
453 (mdw-check-autorevert))
455 ;;;--------------------------------------------------------------------------
458 (defadvice dired-maybe-insert-subdir
459 (around mdw-marked-insertion first activate)
460 "The DIRNAME may be a list of directory names to insert.
461 Interactively, if files are marked, then insert all of them.
462 With a numeric prefix argument, select that many entries near
463 point; with a non-numeric prefix argument, prompt for listing
466 (list (dired-get-marked-files nil
467 (and (integerp current-prefix-arg)
470 (and current-prefix-arg
471 (not (integerp current-prefix-arg))
472 (read-string "Switches for listing: "
473 (or dired-subdir-switches
474 dired-actual-switches)))))
475 (let ((dirs (ad-get-arg 0)))
476 (dolist (dir (if (listp dirs) dirs (list dirs)))
480 ;;;--------------------------------------------------------------------------
483 (defun mdw-w3m-browse-url (url &optional new-session-p)
484 "Invoke w3m on the URL in its current window, or at least a different one.
485 If NEW-SESSION-P, start a new session."
486 (interactive "sURL: \nP")
488 (let ((window (selected-window)))
491 (select-window (or (and (not new-session-p)
492 (get-buffer-window "*w3m*"))
494 (if (one-window-p t) (split-window))
496 (w3m-browse-url url new-session-p))
497 (select-window window)))))
499 (defvar mdw-good-url-browsers
500 '((w3m . mdw-w3m-browse-url)
503 "List of good browsers for mdw-good-url-browsers.
504 Each item is a browser function name, or a cons (CHECK . FUNC).
505 A symbol FOO stands for (FOO . FOO).")
507 (defun mdw-good-url-browser ()
508 "Return a good URL browser.
509 Trundle the list of such things, finding the first item for which
510 CHECK is fboundp, and returning the correponding FUNC."
511 (let ((bs mdw-good-url-browsers) b check func answer)
512 (while (and bs (not answer))
516 (setq check (car b) func (cdr b))
517 (setq check b func b))
522 (eval-after-load "w3m-search"
526 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
527 ("gd" "Google Directory"
528 "http://www.google.com/search?cat=gwd/Top&q=%s")
529 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
530 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
531 ("gi" "Images" "http://images.google.com/images?q=%s")
533 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
535 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
536 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
537 ("nc-wiki" "nCipher wiki"
538 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
539 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
540 ("lp" "Launchpad bug by number"
541 "https://bugs.launchpad.net/bugs/%s")
542 ("lppkg" "Launchpad bugs by package"
543 "https://bugs.launchpad.net/%s")
545 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
546 ("debbug" "Debian bug by number"
547 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
548 ("debbugpkg" "Debian bugs by package"
549 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
550 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
551 (add-to-list 'w3m-search-engine-alist
552 (list (cadr item) (caddr item) nil))
553 (add-to-list 'w3m-uri-replace-alist
554 (list (concat "\\`" (car item) ":")
555 'w3m-search-uri-replace
558 ;;;--------------------------------------------------------------------------
559 ;;; Paragraph filling.
563 (defvar mdw-fill-prefix nil
564 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
565 If there's no fill prefix currently set (by the `fill-prefix'
566 variable) and there's a match from one of the regexps here, it
567 gets used to set the fill-prefix for the current operation.
569 The variable is a list of items of the form `REGEXP . PREFIX'; if
570 the REGEXP matches, the PREFIX is used to set the fill prefix.
571 It in turn is a list of things:
573 STRING -- insert a literal string
574 (match . N) -- insert the thing matched by bracketed subexpression N
575 (pad . N) -- a string of whitespace the same width as subexpression N
576 (expr . FORM) -- the result of evaluating FORM")
578 (make-variable-buffer-local 'mdw-fill-prefix)
580 (defvar mdw-hanging-indents
582 "\\([*o]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
585 "*Standard regexp matching parts of a hanging indent.
586 This is mainly useful in `auto-fill-mode'.")
588 ;; Setting things up.
590 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
592 ;; Utility functions.
594 (defun mdw-tabify (s)
595 "Tabify the string S. This is a horrid hack."
600 (setq start (point-marker))
602 (setq end (point-marker))
604 (setq s (buffer-substring start (1- end)))
605 (delete-region start end)
606 (set-marker start nil)
610 (defun mdw-examine-fill-prefixes (l)
611 "Given a list of dynamic fill prefixes, pick one which matches
612 context and return the static fill prefix to use. Point must be
613 at the start of a line, and match data must be saved."
615 ((looking-at (car (car l)))
616 (mdw-tabify (apply (function concat)
617 (mapcar (function mdw-do-prefix-match)
619 (t (mdw-examine-fill-prefixes (cdr l)))))
621 (defun mdw-maybe-car (p)
622 "If P is a pair, return (car P), otherwise just return P."
623 (if (consp p) (car p) p))
625 (defun mdw-padding (s)
626 "Return a string the same width as S but made entirely from whitespace."
627 (let* ((l (length s)) (i 0) (n (make-string l ? )))
634 (defun mdw-do-prefix-match (m)
635 "Expand a dynamic prefix match element.
636 See `mdw-fill-prefix' for details."
637 (cond ((not (consp m)) (format "%s" m))
638 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
639 ((eq (car m) 'pad) (mdw-padding (match-string
640 (mdw-maybe-car (cdr m)))))
641 ((eq (car m) 'eval) (eval (cdr m)))
644 (defun mdw-choose-dynamic-fill-prefix ()
645 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
646 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
647 ((not mdw-fill-prefix) fill-prefix)
651 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
653 (defun do-auto-fill ()
654 "Handle auto-filling, working out a dynamic fill prefix in the
655 case where there isn't a sensible static one."
656 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
659 (defun mdw-fill-paragraph ()
660 "Fill paragraph, getting a dynamic fill prefix."
662 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
663 (fill-paragraph nil)))
665 (defun mdw-standard-fill-prefix (rx &optional mat)
666 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
667 This is just a short-cut for setting the thing by hand, and by
668 design it doesn't cope with anything approximating a complicated
670 (setq mdw-fill-prefix
671 `((,(concat rx mdw-hanging-indents)
673 (pad . ,(or mat 2))))))
675 ;;;--------------------------------------------------------------------------
676 ;;; Other common declarations.
678 ;; Common mode settings.
680 (defvar mdw-auto-indent t
681 "Whether to indent automatically after a newline.")
683 (defun mdw-misc-mode-config ()
685 (cond ((eq major-mode 'lisp-mode)
686 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
687 ((or (eq major-mode 'slime-repl-mode)
688 (eq major-mode 'asm-mode))
691 (local-set-key "\C-m" 'newline-and-indent))))
692 (local-set-key [C-return] 'newline)
693 (make-variable-buffer-local 'page-delimiter)
694 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
695 (setq comment-column 40)
697 (setq fill-column 77)
698 (setq show-trailing-whitespace t)
699 (let ((whitespace-style (remove 'trailing whitespace-style)))
700 (trap (whitespace-mode t)))
701 (and (fboundp 'gtags-mode)
703 (outline-minor-mode t)
706 (trap (turn-on-font-lock)))
708 (defun mdw-post-config-mode-hack ()
709 (let ((whitespace-style (remove 'trailing whitespace-style)))
710 (trap (whitespace-mode t))))
712 (eval-after-load 'gtags
714 (dolist (key '([mouse-2] [mouse-3]))
715 (define-key gtags-mode-map key nil))
716 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
717 (define-key gtags-select-mode-map [C-S-mouse-2]
718 'gtags-select-tag-by-event)
719 (dolist (map (list gtags-mode-map gtags-select-mode-map))
720 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
722 ;; Backup file handling.
724 (defvar mdw-backup-disable-regexps nil
725 "*List of regular expressions: if a file name matches any of
726 these then the file is not backed up.")
728 (defun mdw-backup-enable-predicate (name)
729 "[mdw]'s default backup predicate.
730 Allows a backup if the standard predicate would allow it, and it
731 doesn't match any of the regular expressions in
732 `mdw-backup-disable-regexps'."
733 (and (normal-backup-enable-predicate name)
734 (let ((answer t) (list mdw-backup-disable-regexps))
737 (if (string-match (car list) name)
739 (setq list (cdr list)))
741 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
745 (defun mdw-last-one-out-turn-off-the-lights (frame)
746 "Disconnect from an X display if this was the last frame on that display."
747 (let ((frame-display (frame-parameter frame 'display)))
748 (when (and frame-display
749 (eq window-system 'x)
750 (not (some (lambda (fr)
751 (message "checking frame %s" frame)
752 (and (not (eq fr frame))
753 (string= (frame-parameter fr 'display)
755 (progn "frame %s still uses us" nil)))
757 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
758 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
760 (defvar mdw-frame-parameters-alist
761 '((nil (menu-bar-lines . 0))))
762 (defun mdw-set-frame-parameters (frame)
763 (let ((params (assq (if (fboundp 'window-system)
764 (window-system frame)
766 mdw-frame-parameters-alist)))
768 (modify-frame-parameters frame (cdr params)))))
769 (add-hook 'after-make-frame-functions 'mdw-set-frame-parameters)
771 ;;;--------------------------------------------------------------------------
772 ;;; General fontification.
774 (defmacro mdw-define-face (name &rest body)
775 "Define a face, and make sure it's actually set as the definition."
780 (defvar ,name ',name)
781 (put ',name 'face-defface-spec ',body)
782 (face-spec-set ',name ',body nil)))
784 (mdw-define-face default
785 (((type w32)) :family "courier new" :height 85)
786 (((type x)) :family "6x13" :height 130)
787 (((type color)) :foreground "white" :background "black")
789 (mdw-define-face fixed-pitch
790 (((type w32)) :family "courier new" :height 85)
791 (((type x)) :family "6x13" :height 130)
792 (t :foreground "white" :background "black"))
793 (if (>= emacs-major-version 23)
794 (mdw-define-face variable-pitch
795 (((type x)) :family "sans" :height 100))
796 (mdw-define-face variable-pitch
797 (((type x)) :family "helvetica" :height 120)))
798 (mdw-define-face region
799 (((type tty) (class color)) :background "blue")
800 (((type tty) (class mono)) :inverse-video t)
801 (t :background "grey30"))
802 (mdw-define-face minibuffer-prompt
804 (mdw-define-face mode-line
805 (((class color)) :foreground "blue" :background "yellow"
806 :box (:line-width 1 :style released-button))
807 (t :inverse-video t))
808 (mdw-define-face mode-line-inactive
809 (((class color)) :foreground "yellow" :background "blue"
810 :box (:line-width 1 :style released-button))
811 (t :inverse-video t))
812 (mdw-define-face scroll-bar
813 (t :foreground "black" :background "lightgrey"))
814 (mdw-define-face fringe
815 (t :foreground "yellow"))
816 (mdw-define-face show-paren-match
817 (((class color)) :background "darkgreen")
819 (mdw-define-face show-paren-mismatch
820 (((class color)) :background "red")
821 (t :inverse-video t))
822 (mdw-define-face highlight
823 (((class color)) :background "DarkSeaGreen4")
824 (t :inverse-video t))
826 (mdw-define-face holiday-face
827 (t :background "red"))
828 (mdw-define-face calendar-today-face
829 (t :foreground "yellow" :weight bold))
831 (mdw-define-face comint-highlight-prompt
833 (mdw-define-face comint-highlight-input
836 (mdw-define-face trailing-whitespace
837 (((class color)) :background "red")
838 (t :inverse-video t))
839 (mdw-define-face mdw-punct-face
840 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
841 (mdw-define-face mdw-number-face
842 (t :foreground "yellow"))
843 (mdw-define-face font-lock-function-name-face
845 (mdw-define-face font-lock-keyword-face
847 (mdw-define-face font-lock-constant-face
849 (mdw-define-face font-lock-builtin-face
851 (mdw-define-face font-lock-type-face
852 (t :weight bold :slant italic))
853 (mdw-define-face font-lock-reference-face
855 (mdw-define-face font-lock-variable-name-face
857 (mdw-define-face font-lock-comment-delimiter-face
858 (((class mono)) :weight bold)
859 (((type tty) (class color)) :foreground "green")
860 (t :slant italic :foreground "SeaGreen1"))
861 (mdw-define-face font-lock-comment-face
862 (((class mono)) :weight bold)
863 (((type tty) (class color)) :foreground "green")
864 (t :slant italic :foreground "SeaGreen1"))
865 (mdw-define-face font-lock-string-face
866 (((class mono)) :weight bold)
867 (((class color)) :foreground "SkyBlue1"))
868 (mdw-define-face message-separator
869 (t :background "red" :foreground "white" :weight bold))
870 (mdw-define-face message-cited-text
871 (default :slant italic)
872 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
873 (mdw-define-face message-header-cc
874 (default :weight bold)
875 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
876 (mdw-define-face message-header-newsgroups
877 (default :weight bold)
878 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
879 (mdw-define-face message-header-subject
880 (default :weight bold)
881 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
882 (mdw-define-face message-header-to
883 (default :weight bold)
884 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
885 (mdw-define-face message-header-xheader
886 (default :weight bold)
887 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
888 (mdw-define-face message-header-other
889 (default :weight bold)
890 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
891 (mdw-define-face message-header-name
892 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
894 (mdw-define-face diff-index
896 (mdw-define-face diff-file-header
898 (mdw-define-face diff-hunk-header
899 (t :foreground "SkyBlue1"))
900 (mdw-define-face diff-function
901 (t :foreground "SkyBlue1" :weight bold))
902 (mdw-define-face diff-header
903 (t :background "grey10"))
904 (mdw-define-face diff-added
905 (t :foreground "green"))
906 (mdw-define-face diff-removed
907 (t :foreground "red"))
908 (mdw-define-face diff-context
911 (mdw-define-face erc-input-face
912 (t :foreground "red"))
914 (mdw-define-face woman-bold
916 (mdw-define-face woman-italic
919 (mdw-define-face p4-depot-added-face
920 (t :foreground "green"))
921 (mdw-define-face p4-depot-branch-op-face
922 (t :foreground "yellow"))
923 (mdw-define-face p4-depot-deleted-face
924 (t :foreground "red"))
925 (mdw-define-face p4-depot-unmapped-face
926 (t :foreground "SkyBlue1"))
927 (mdw-define-face p4-diff-change-face
928 (t :foreground "yellow"))
929 (mdw-define-face p4-diff-del-face
930 (t :foreground "red"))
931 (mdw-define-face p4-diff-file-face
932 (t :foreground "SkyBlue1"))
933 (mdw-define-face p4-diff-head-face
934 (t :background "grey10"))
935 (mdw-define-face p4-diff-ins-face
936 (t :foreground "green"))
938 (mdw-define-face whizzy-slice-face
939 (t :background "grey10"))
940 (mdw-define-face whizzy-error-face
941 (t :background "darkred"))
943 ;;;--------------------------------------------------------------------------
944 ;;; C programming configuration.
946 ;; Linux kernel hacking.
948 (defvar linux-c-mode-hook)
950 (defun linux-c-mode ()
953 (setq major-mode 'linux-c-mode)
954 (setq mode-name "Linux C")
955 (run-hooks 'linux-c-mode-hook))
957 ;; Make C indentation nice.
959 (defun mdw-c-lineup-arglist (langelem)
960 "Hack for DWIMmery in c-lineup-arglist."
962 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
964 (c-lineup-arglist langelem)))
966 (defun mdw-c-indent-extern-mumble (langelem)
967 "Indent `extern \"...\" {' lines."
969 (back-to-indentation)
971 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
975 (defun mdw-c-style ()
976 (c-add-style "[mdw] C and C++ style"
977 '((c-basic-offset . 2)
978 (comment-column . 40)
979 (c-class-key . "class")
980 (c-backslash-column . 72)
982 (substatement-open . (add 0 c-indent-one-line-block))
983 (defun-open . (add 0 c-indent-one-line-block))
984 (arglist-cont-nonempty . mdw-c-lineup-arglist)
985 (topmost-intro . mdw-c-indent-extern-mumble)
986 (cpp-define-intro . 0)
987 (inextern-lang . [0])
994 (statement-case-intro . +)))
997 (defvar mdw-c-comment-fill-prefix
998 `((,(concat "\\([ \t]*/?\\)"
1001 "\\([A-Za-z]+:[ \t]*\\)?"
1002 mdw-hanging-indents)
1003 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1004 "Fill prefix matching C comments (both kinds).")
1006 (defun mdw-fontify-c-and-c++ ()
1008 ;; Fiddle with some syntax codes.
1009 (modify-syntax-entry ?* ". 23")
1010 (modify-syntax-entry ?/ ". 124b")
1011 (modify-syntax-entry ?\n "> b")
1015 (setq c-hanging-comment-ender-p nil)
1016 (setq c-backslash-column 72)
1017 (setq c-label-minimum-indentation 0)
1018 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1020 ;; Now define things to be fontified.
1021 (make-local-variable 'font-lock-keywords)
1023 (mdw-regexps "and" ;C++
1029 "bool" ;C++, C9X macro
1035 "complex" ;C9X macro, C++ template type
1039 "continue" ;K&R, C89
1040 "defined" ;C89 preprocessor
1047 ;; "entry" ;K&R -- never used
1052 "false" ;C++, C9X macro
1059 "imaginary" ;C9X macro
1060 "inline" ;C++, C9X, GCC
1072 "register" ;K&R, C89
1073 "reinterpret_cast" ;C++
1086 "true" ;C++, C9X macro
1094 "unsigned" ;K&R, C89
1099 "wchar_t" ;C++, C89 library type
1106 "_Pragma" ;C9X preprocessor
1109 "__attribute__" ;GCC
1112 "__extension__" ;GCC
1121 (preprocessor-keywords
1122 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1123 "ident" "if" "ifdef" "ifndef" "import" "include"
1124 "line" "pragma" "unassert" "undef" "warning"))
1126 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1127 "interface" "private" "protected" "protocol" "public"
1130 (setq font-lock-keywords
1133 ;; Fontify include files as strings.
1134 (list (concat "^[ \t]*\\#[ \t]*"
1135 "\\(include\\|import\\)"
1136 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1137 '(2 font-lock-string-face))
1139 ;; Preprocessor directives are `references'?.
1140 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1141 preprocessor-keywords
1142 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1143 '(1 font-lock-keyword-face))
1145 ;; Handle the keywords defined above.
1146 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1147 '(0 font-lock-keyword-face))
1149 (list (concat "\\<\\(" c-keywords "\\)\\>")
1150 '(0 font-lock-keyword-face))
1152 ;; Handle numbers too.
1154 ;; This looks strange, I know. It corresponds to the
1155 ;; preprocessor's idea of what a number looks like, rather than
1156 ;; anything sensible.
1157 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1158 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1159 '(0 mdw-number-face))
1161 ;; And anything else is punctuation.
1162 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1163 '(0 mdw-punct-face))))
1165 (mdw-post-config-mode-hack)))
1167 ;;;--------------------------------------------------------------------------
1170 (defun apcalc-mode ()
1173 (setq major-mode 'apcalc-mode)
1174 (setq mode-name "AP Calc")
1175 (run-hooks 'apcalc-mode-hook))
1177 (defun mdw-fontify-apcalc ()
1179 ;; Fiddle with some syntax codes.
1180 (modify-syntax-entry ?* ". 23")
1181 (modify-syntax-entry ?/ ". 14")
1185 (setq c-hanging-comment-ender-p nil)
1186 (setq c-backslash-column 72)
1187 (setq comment-start "/* ")
1188 (setq comment-end " */")
1189 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1191 ;; Now define things to be fontified.
1192 (make-local-variable 'font-lock-keywords)
1194 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1195 "do" "else" "exit" "for" "global" "goto" "help" "if"
1196 "local" "mat" "obj" "print" "quit" "read" "return"
1197 "show" "static" "switch" "while" "write")))
1199 (setq font-lock-keywords
1202 ;; Handle the keywords defined above.
1203 (list (concat "\\<\\(" c-keywords "\\)\\>")
1204 '(0 font-lock-keyword-face))
1206 ;; Handle numbers too.
1208 ;; This looks strange, I know. It corresponds to the
1209 ;; preprocessor's idea of what a number looks like, rather than
1210 ;; anything sensible.
1211 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1212 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1213 '(0 mdw-number-face))
1215 ;; And anything else is punctuation.
1216 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1217 '(0 mdw-punct-face)))))
1219 (mdw-post-config-mode-hack))
1221 ;;;--------------------------------------------------------------------------
1222 ;;; Java programming configuration.
1224 ;; Make indentation nice.
1226 (defun mdw-java-style ()
1227 (c-add-style "[mdw] Java style"
1228 '((c-basic-offset . 2)
1229 (c-offsets-alist (substatement-open . 0)
1234 (statement-case-intro . +)))
1237 ;; Declare Java fontification style.
1239 (defun mdw-fontify-java ()
1243 (setq c-hanging-comment-ender-p nil)
1244 (setq c-backslash-column 72)
1245 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1247 ;; Now define things to be fontified.
1248 (make-local-variable 'font-lock-keywords)
1249 (let ((java-keywords
1250 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1251 "char" "class" "const" "continue" "default" "do"
1252 "double" "else" "extends" "final" "finally" "float"
1253 "for" "goto" "if" "implements" "import" "instanceof"
1254 "int" "interface" "long" "native" "new" "package"
1255 "private" "protected" "public" "return" "short"
1256 "static" "super" "switch" "synchronized" "this"
1257 "throw" "throws" "transient" "try" "void" "volatile"
1260 "false" "null" "true")))
1262 (setq font-lock-keywords
1265 ;; Handle the keywords defined above.
1266 (list (concat "\\<\\(" java-keywords "\\)\\>")
1267 '(0 font-lock-keyword-face))
1269 ;; Handle numbers too.
1271 ;; The following isn't quite right, but it's close enough.
1272 (list (concat "\\<\\("
1273 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1274 "[0-9]+\\(\\.[0-9]*\\|\\)"
1275 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1277 '(0 mdw-number-face))
1279 ;; And anything else is punctuation.
1280 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1281 '(0 mdw-punct-face)))))
1283 (mdw-post-config-mode-hack))
1285 ;;;--------------------------------------------------------------------------
1286 ;;; C# programming configuration.
1288 ;; Make indentation nice.
1290 (defun mdw-csharp-style ()
1291 (c-add-style "[mdw] C# style"
1292 '((c-basic-offset . 2)
1293 (c-offsets-alist (substatement-open . 0)
1298 (statement-case-intro . +)))
1301 ;; Declare C# fontification style.
1303 (defun mdw-fontify-csharp ()
1307 (setq c-hanging-comment-ender-p nil)
1308 (setq c-backslash-column 72)
1309 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1311 ;; Now define things to be fontified.
1312 (make-local-variable 'font-lock-keywords)
1313 (let ((csharp-keywords
1314 (mdw-regexps "abstract" "as" "base" "bool" "break"
1315 "byte" "case" "catch" "char" "checked"
1316 "class" "const" "continue" "decimal" "default"
1317 "delegate" "do" "double" "else" "enum"
1318 "event" "explicit" "extern" "false" "finally"
1319 "fixed" "float" "for" "foreach" "goto"
1320 "if" "implicit" "in" "int" "interface"
1321 "internal" "is" "lock" "long" "namespace"
1322 "new" "null" "object" "operator" "out"
1323 "override" "params" "private" "protected" "public"
1324 "readonly" "ref" "return" "sbyte" "sealed"
1325 "short" "sizeof" "stackalloc" "static" "string"
1326 "struct" "switch" "this" "throw" "true"
1327 "try" "typeof" "uint" "ulong" "unchecked"
1328 "unsafe" "ushort" "using" "virtual" "void"
1329 "volatile" "while" "yield")))
1331 (setq font-lock-keywords
1334 ;; Handle the keywords defined above.
1335 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1336 '(0 font-lock-keyword-face))
1338 ;; Handle numbers too.
1340 ;; The following isn't quite right, but it's close enough.
1341 (list (concat "\\<\\("
1342 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1343 "[0-9]+\\(\\.[0-9]*\\|\\)"
1344 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1346 '(0 mdw-number-face))
1348 ;; And anything else is punctuation.
1349 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1350 '(0 mdw-punct-face)))))
1352 (mdw-post-config-mode-hack))
1354 (define-derived-mode csharp-mode java-mode "C#"
1355 "Major mode for editing C# code.")
1357 ;;;--------------------------------------------------------------------------
1358 ;;; Go programming configuration.
1360 (defun mdw-fontify-go ()
1362 (make-local-variable 'font-lock-keywords)
1364 (mdw-regexps "break" "case" "chan" "const" "continue"
1365 "default" "defer" "else" "fallthrough" "for"
1366 "func" "go" "goto" "if" "import"
1367 "interface" "map" "package" "range" "return"
1368 "select" "struct" "switch" "type" "var")))
1370 (setq font-lock-keywords
1373 ;; Handle the keywords defined above.
1374 (list (concat "\\<\\(" go-keywords "\\)\\>")
1375 '(0 font-lock-keyword-face))
1377 ;; Handle numbers too.
1379 ;; The following isn't quite right, but it's close enough.
1380 (list (concat "\\<\\("
1381 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1382 "[0-9]+\\(\\.[0-9]*\\|\\)"
1383 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1384 '(0 mdw-number-face))
1386 ;; And anything else is punctuation.
1387 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1388 '(0 mdw-punct-face)))))
1390 (mdw-post-config-mode-hack))
1392 ;;;--------------------------------------------------------------------------
1393 ;;; Awk programming configuration.
1395 ;; Make Awk indentation nice.
1397 (defun mdw-awk-style ()
1398 (c-add-style "[mdw] Awk style"
1399 '((c-basic-offset . 2)
1400 (c-offsets-alist (substatement-open . 0)
1401 (statement-cont . 0)
1402 (statement-case-intro . +)))
1405 ;; Declare Awk fontification style.
1407 (defun mdw-fontify-awk ()
1409 ;; Miscellaneous fiddling.
1411 (setq c-backslash-column 72)
1412 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1414 ;; Now define things to be fontified.
1415 (make-local-variable 'font-lock-keywords)
1417 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1418 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1419 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1420 "RSTART" "RLENGTH" "RT" "SUBSEP"
1421 "atan2" "break" "close" "continue" "cos" "delete"
1422 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1423 "function" "gensub" "getline" "gsub" "if" "in"
1424 "index" "int" "length" "log" "match" "next" "rand"
1425 "return" "print" "printf" "sin" "split" "sprintf"
1426 "sqrt" "srand" "strftime" "sub" "substr" "system"
1427 "systime" "tolower" "toupper" "while")))
1429 (setq font-lock-keywords
1432 ;; Handle the keywords defined above.
1433 (list (concat "\\<\\(" c-keywords "\\)\\>")
1434 '(0 font-lock-keyword-face))
1436 ;; Handle numbers too.
1438 ;; The following isn't quite right, but it's close enough.
1439 (list (concat "\\<\\("
1440 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1441 "[0-9]+\\(\\.[0-9]*\\|\\)"
1442 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1444 '(0 mdw-number-face))
1446 ;; And anything else is punctuation.
1447 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1448 '(0 mdw-punct-face)))))
1450 (mdw-post-config-mode-hack))
1452 ;;;--------------------------------------------------------------------------
1453 ;;; Perl programming style.
1455 ;; Perl indentation style.
1457 (setq cperl-indent-level 2)
1458 (setq cperl-continued-statement-offset 2)
1459 (setq cperl-continued-brace-offset 0)
1460 (setq cperl-brace-offset -2)
1461 (setq cperl-brace-imaginary-offset 0)
1462 (setq cperl-label-offset 0)
1464 ;; Define perl fontification style.
1466 (defun mdw-fontify-perl ()
1468 ;; Miscellaneous fiddling.
1469 (modify-syntax-entry ?$ "\\")
1470 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1471 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1473 ;; Now define fontification things.
1474 (make-local-variable 'font-lock-keywords)
1475 (let ((perl-keywords
1476 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1477 "for" "foreach" "ge" "gt" "goto" "if"
1478 "last" "le" "lt" "local" "my" "ne" "next" "or"
1479 "package" "redo" "require" "return" "sub"
1480 "undef" "unless" "until" "use" "while")))
1482 (setq font-lock-keywords
1485 ;; Set up the keywords defined above.
1486 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1487 '(0 font-lock-keyword-face))
1489 ;; At least numbers are simpler than C.
1490 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1491 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1492 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1493 '(0 mdw-number-face))
1495 ;; And anything else is punctuation.
1496 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1497 '(0 mdw-punct-face)))))
1499 (mdw-post-config-mode-hack))
1501 (defun perl-number-tests (&optional arg)
1502 "Assign consecutive numbers to lines containing `#t'. With ARG,
1503 strip numbers instead."
1506 (goto-char (point-min))
1507 (let ((i 0) (fmt (if arg "" " %4d")))
1508 (while (search-forward "#t" nil t)
1509 (delete-region (point) (line-end-position))
1511 (insert (format fmt i)))
1512 (goto-char (point-min))
1513 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1514 (replace-match (format "\\1%d" i))))))
1516 ;;;--------------------------------------------------------------------------
1517 ;;; Python programming style.
1519 (defun mdw-fontify-pythonic (keywords)
1521 ;; Miscellaneous fiddling.
1522 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1524 ;; Now define fontification things.
1525 (make-local-variable 'font-lock-keywords)
1526 (setq font-lock-keywords
1529 ;; Set up the keywords defined above.
1530 (list (concat "\\<\\(" keywords "\\)\\>")
1531 '(0 font-lock-keyword-face))
1533 ;; At least numbers are simpler than C.
1534 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1535 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1536 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1537 '(0 mdw-number-face))
1539 ;; And anything else is punctuation.
1540 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1541 '(0 mdw-punct-face))))
1543 (mdw-post-config-mode-hack))
1545 ;; Define Python fontification styles.
1547 (defun mdw-fontify-python ()
1548 (mdw-fontify-pythonic
1549 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1550 "del" "elif" "else" "except" "exec" "finally" "for"
1551 "from" "global" "if" "import" "in" "is" "lambda"
1552 "not" "or" "pass" "print" "raise" "return" "try"
1553 "while" "with" "yield")))
1555 (defun mdw-fontify-pyrex ()
1556 (mdw-fontify-pythonic
1557 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1558 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1559 "extern" "finally" "for" "from" "global" "if"
1560 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1561 "raise" "return" "struct" "try" "while" "with"
1564 ;;;--------------------------------------------------------------------------
1565 ;;; Icon programming style.
1567 ;; Icon indentation style.
1569 (setq icon-brace-offset 0
1570 icon-continued-brace-offset 0
1571 icon-continued-statement-offset 2
1572 icon-indent-level 2)
1574 ;; Define Icon fontification style.
1576 (defun mdw-fontify-icon ()
1578 ;; Miscellaneous fiddling.
1579 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1581 ;; Now define fontification things.
1582 (make-local-variable 'font-lock-keywords)
1583 (let ((icon-keywords
1584 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1585 "end" "every" "fail" "global" "if" "initial"
1586 "invocable" "link" "local" "next" "not" "of"
1587 "procedure" "record" "repeat" "return" "static"
1588 "suspend" "then" "to" "until" "while"))
1589 (preprocessor-keywords
1590 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1591 "include" "line" "undef")))
1592 (setq font-lock-keywords
1595 ;; Set up the keywords defined above.
1596 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1597 '(0 font-lock-keyword-face))
1599 ;; The things that Icon calls keywords.
1600 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1602 ;; At least numbers are simpler than C.
1603 (list (concat "\\<[0-9]+"
1604 "\\([rR][0-9a-zA-Z]+\\|"
1605 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1606 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1607 '(0 mdw-number-face))
1610 (list (concat "^[ \t]*$[ \t]*\\<\\("
1611 preprocessor-keywords
1613 '(0 font-lock-keyword-face))
1615 ;; And anything else is punctuation.
1616 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1617 '(0 mdw-punct-face)))))
1619 (mdw-post-config-mode-hack))
1621 ;;;--------------------------------------------------------------------------
1622 ;;; ARM assembler programming configuration.
1624 ;; There doesn't appear to be an Emacs mode for this yet.
1626 ;; Better do something about that, I suppose.
1628 (defvar arm-assembler-mode-map nil)
1629 (defvar arm-assembler-abbrev-table nil)
1630 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1632 (or arm-assembler-mode-map
1634 (setq arm-assembler-mode-map (make-sparse-keymap))
1635 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1636 (define-key arm-assembler-mode-map [C-return] 'newline)
1637 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1639 (defun arm-assembler-mode ()
1640 "Major mode for ARM assembler programs"
1643 ;; Do standard major mode things.
1644 (kill-all-local-variables)
1645 (use-local-map arm-assembler-mode-map)
1646 (setq local-abbrev-table arm-assembler-abbrev-table)
1647 (setq major-mode 'arm-assembler-mode)
1648 (setq mode-name "ARM assembler")
1650 ;; Set up syntax table.
1651 (set-syntax-table arm-assembler-mode-syntax-table)
1652 (modify-syntax-entry ?; ; Nasty hack
1653 "<" arm-assembler-mode-syntax-table)
1654 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1655 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1657 (make-local-variable 'comment-start)
1658 (setq comment-start ";")
1659 (make-local-variable 'comment-end)
1660 (setq comment-end "")
1661 (make-local-variable 'comment-column)
1662 (setq comment-column 48)
1663 (make-local-variable 'comment-start-skip)
1664 (setq comment-start-skip ";+[ \t]*")
1666 ;; Play with indentation.
1667 (make-local-variable 'indent-line-function)
1668 (setq indent-line-function 'indent-relative-maybe)
1671 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1673 ;; Fiddle with fontification.
1674 (make-local-variable 'font-lock-keywords)
1675 (setq font-lock-keywords
1678 ;; Handle numbers too.
1680 ;; The following isn't quite right, but it's close enough.
1683 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1685 '(0 mdw-number-face))
1687 ;; Do something about operators.
1688 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1689 '(1 font-lock-keyword-face)
1690 '(2 font-lock-string-face))
1692 '(0 font-lock-keyword-face))
1694 ;; Do menemonics and directives.
1695 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1696 '(1 font-lock-keyword-face))
1698 ;; And anything else is punctuation.
1699 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1700 '(0 mdw-punct-face)))
1702 (mdw-post-config-mode-hack))
1703 (run-hooks 'arm-assembler-mode-hook))
1705 ;;;--------------------------------------------------------------------------
1708 (defun mdw-fontify-asm ()
1709 (modify-syntax-entry ?' "\"")
1710 (modify-syntax-entry ?. "w")
1711 (setf fill-prefix nil)
1712 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1714 ;;;--------------------------------------------------------------------------
1715 ;;; TCL configuration.
1717 (defun mdw-fontify-tcl ()
1718 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1719 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1720 (make-local-variable 'font-lock-keywords)
1721 (setq font-lock-keywords
1723 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1724 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1725 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1726 '(0 mdw-number-face))
1727 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1728 '(0 mdw-punct-face))))
1729 (mdw-post-config-mode-hack))
1731 ;;;--------------------------------------------------------------------------
1732 ;;; REXX configuration.
1734 (defun mdw-rexx-electric-* ()
1739 (defun mdw-rexx-indent-newline-indent ()
1742 (if abbrev-mode (expand-abbrev))
1743 (newline-and-indent))
1745 (defun mdw-fontify-rexx ()
1747 ;; Various bits of fiddling.
1748 (setq mdw-auto-indent nil)
1749 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1750 (local-set-key [?*] 'mdw-rexx-electric-*)
1751 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1753 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1755 ;; Set up keywords and things for fontification.
1756 (make-local-variable 'font-lock-keywords-case-fold-search)
1757 (setq font-lock-keywords-case-fold-search t)
1759 (setq rexx-indent 2)
1760 (setq rexx-end-indent rexx-indent)
1761 (setq rexx-cont-indent rexx-indent)
1763 (make-local-variable 'font-lock-keywords)
1764 (let ((rexx-keywords
1765 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1766 "else" "end" "engineering" "exit" "expose" "for"
1767 "forever" "form" "fuzz" "if" "interpret" "iterate"
1768 "leave" "linein" "name" "nop" "numeric" "off" "on"
1769 "options" "otherwise" "parse" "procedure" "pull"
1770 "push" "queue" "return" "say" "select" "signal"
1771 "scientific" "source" "then" "trace" "to" "until"
1772 "upper" "value" "var" "version" "when" "while"
1775 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1776 "center" "center" "charin" "charout" "chars"
1777 "compare" "condition" "copies" "c2d" "c2x"
1778 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1779 "errortext" "format" "fuzz" "insert" "lastpos"
1780 "left" "length" "lineout" "lines" "max" "min"
1781 "overlay" "pos" "queued" "random" "reverse" "right"
1782 "sign" "sourceline" "space" "stream" "strip"
1783 "substr" "subword" "symbol" "time" "translate"
1784 "trunc" "value" "verify" "word" "wordindex"
1785 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1788 (setq font-lock-keywords
1791 ;; Set up the keywords defined above.
1792 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1793 '(0 font-lock-keyword-face))
1795 ;; Fontify all symbols the same way.
1796 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1797 "[A-Za-z0-9.!?_#@$]+\\)")
1798 '(0 font-lock-variable-name-face))
1800 ;; And everything else is punctuation.
1801 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1802 '(0 mdw-punct-face)))))
1804 (mdw-post-config-mode-hack))
1806 ;;;--------------------------------------------------------------------------
1807 ;;; Standard ML programming style.
1809 (defun mdw-fontify-sml ()
1811 ;; Make underscore an honorary letter.
1812 (modify-syntax-entry ?' "w")
1815 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1817 ;; Now define fontification things.
1818 (make-local-variable 'font-lock-keywords)
1820 (mdw-regexps "abstype" "and" "andalso" "as"
1823 "else" "end" "eqtype" "exception"
1824 "fn" "fun" "functor"
1826 "if" "in" "include" "infix" "infixr"
1829 "of" "op" "open" "orelse"
1831 "sharing" "sig" "signature" "struct" "structure"
1834 "where" "while" "with" "withtype")))
1836 (setq font-lock-keywords
1839 ;; Set up the keywords defined above.
1840 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1841 '(0 font-lock-keyword-face))
1843 ;; At least numbers are simpler than C.
1844 (list (concat "\\<\\(\\~\\|\\)"
1845 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1847 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1848 "\\([eE]\\(\\~\\|\\)"
1849 "[0-9]+\\|\\)\\)\\)")
1850 '(0 mdw-number-face))
1852 ;; And anything else is punctuation.
1853 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1854 '(0 mdw-punct-face)))))
1856 (mdw-post-config-mode-hack))
1858 ;;;--------------------------------------------------------------------------
1859 ;;; Haskell configuration.
1861 (defun mdw-fontify-haskell ()
1863 ;; Fiddle with syntax table to get comments right.
1864 (modify-syntax-entry ?' "\"")
1865 (modify-syntax-entry ?- ". 123")
1866 (modify-syntax-entry ?{ ". 1b")
1867 (modify-syntax-entry ?} ". 4b")
1868 (modify-syntax-entry ?\n ">")
1871 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1873 ;; Fiddle with fontification.
1874 (make-local-variable 'font-lock-keywords)
1875 (let ((haskell-keywords
1876 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1877 "deriving" "do" "else" "foreign" "hiding" "if"
1878 "import" "in" "infix" "infixl" "infixr" "instance"
1879 "let" "module" "newtype" "of" "qualified" "safe"
1880 "stdcall" "then" "type" "unsafe" "where")))
1882 (setq font-lock-keywords
1885 '(0 font-lock-comment-face))
1886 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1887 '(0 font-lock-keyword-face))
1888 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1889 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1890 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1891 '(0 mdw-number-face))
1892 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1893 '(0 mdw-punct-face)))))
1895 (mdw-post-config-mode-hack))
1897 ;;;--------------------------------------------------------------------------
1898 ;;; Erlang configuration.
1900 (setq erlang-electric-commannds
1901 '(erlang-electric-newline erlang-electric-semicolon))
1903 (defun mdw-fontify-erlang ()
1906 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1908 ;; Fiddle with fontification.
1909 (make-local-variable 'font-lock-keywords)
1910 (let ((erlang-keywords
1911 (mdw-regexps "after" "and" "andalso"
1912 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1913 "case" "catch" "cond"
1914 "div" "end" "fun" "if" "let" "not"
1916 "query" "receive" "rem" "try" "when" "xor")))
1918 (setq font-lock-keywords
1921 '(0 font-lock-comment-face))
1922 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1923 '(0 font-lock-keyword-face))
1924 (list (concat "^-\\sw+\\>")
1925 '(0 font-lock-keyword-face))
1926 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1927 '(0 mdw-number-face))
1928 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1929 '(0 mdw-punct-face)))))
1931 (mdw-post-config-mode-hack))
1933 ;;;--------------------------------------------------------------------------
1934 ;;; Texinfo configuration.
1936 (defun mdw-fontify-texinfo ()
1939 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1941 ;; Real fontification things.
1942 (make-local-variable 'font-lock-keywords)
1943 (setq font-lock-keywords
1946 ;; Environment names are keywords.
1947 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1948 '(2 font-lock-keyword-face))
1950 ;; Unmark escaped magic characters.
1951 (list "\\(@\\)\\([@{}]\\)"
1952 '(1 font-lock-keyword-face)
1953 '(2 font-lock-variable-name-face))
1955 ;; Make sure we get comments properly.
1956 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1957 '(0 font-lock-comment-face))
1959 ;; Command names are keywords.
1960 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1961 '(0 font-lock-keyword-face))
1963 ;; Fontify TeX special characters as punctuation.
1965 '(0 mdw-punct-face))))
1967 (mdw-post-config-mode-hack))
1969 ;;;--------------------------------------------------------------------------
1970 ;;; TeX and LaTeX configuration.
1972 (defun mdw-fontify-tex ()
1973 (setq ispell-parser 'tex)
1976 ;; Don't make maths into a string.
1977 (modify-syntax-entry ?$ ".")
1978 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1979 (local-set-key [?$] 'self-insert-command)
1982 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1984 ;; Real fontification things.
1985 (make-local-variable 'font-lock-keywords)
1986 (setq font-lock-keywords
1989 ;; Environment names are keywords.
1990 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1992 '(2 font-lock-keyword-face))
1994 ;; Suspended environment names are keywords too.
1995 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1997 '(3 font-lock-keyword-face))
1999 ;; Command names are keywords.
2000 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2001 '(0 font-lock-keyword-face))
2003 ;; Handle @/.../ for italics.
2004 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
2005 ;; '(1 font-lock-keyword-face)
2006 ;; '(3 font-lock-keyword-face))
2008 ;; Handle @*...* for boldness.
2009 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
2010 ;; '(1 font-lock-keyword-face)
2011 ;; '(3 font-lock-keyword-face))
2013 ;; Handle @`...' for literal syntax things.
2014 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
2015 ;; '(1 font-lock-keyword-face)
2016 ;; '(3 font-lock-keyword-face))
2018 ;; Handle @<...> for nonterminals.
2019 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
2020 ;; '(1 font-lock-keyword-face)
2021 ;; '(3 font-lock-keyword-face))
2023 ;; Handle other @-commands.
2024 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
2025 ;; '(0 font-lock-keyword-face))
2027 ;; Make sure we get comments properly.
2029 '(0 font-lock-comment-face))
2031 ;; Fontify TeX special characters as punctuation.
2033 '(0 mdw-punct-face))))
2035 (mdw-post-config-mode-hack))
2037 ;;;--------------------------------------------------------------------------
2040 (defun mdw-sgml-mode ()
2043 (mdw-standard-fill-prefix "")
2044 (make-variable-buffer-local 'sgml-delimiters)
2045 (setq sgml-delimiters
2046 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2047 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2048 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2049 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2050 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2051 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2052 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2054 (setq major-mode 'mdw-sgml-mode)
2055 (setq mode-name "[mdw] SGML")
2056 (run-hooks 'mdw-sgml-mode-hook))
2058 ;;;--------------------------------------------------------------------------
2061 (defun mdw-setup-sh-script-mode ()
2063 ;; Fetch the shell interpreter's name.
2064 (let ((shell-name sh-shell-file))
2066 ;; Try reading the hash-bang line.
2068 (goto-char (point-min))
2069 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2070 (setq shell-name (match-string 1))))
2072 ;; Now try to set the shell.
2074 ;; Don't let `sh-set-shell' bugger up my script.
2075 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2076 (sh-set-shell shell-name)))
2078 ;; Now enable my keys and the fontification.
2079 (mdw-misc-mode-config)
2081 ;; Set the indentation level correctly.
2082 (setq sh-indentation 2)
2083 (setq sh-basic-offset 2))
2085 ;;;--------------------------------------------------------------------------
2086 ;;; Emacs shell mode.
2088 (defun mdw-eshell-prompt ()
2089 (let ((left "[") (right "]"))
2090 (when (= (user-uid) 0)
2091 (setq left "«" right "»"))
2094 (replace-regexp-in-string "\\..*$" "" (system-name)))
2098 (setq eshell-prompt-function 'mdw-eshell-prompt)
2099 (setq eshell-prompt-regexp "^\\[[^]]+\\]")
2101 (defalias 'eshell/e 'find-file)
2102 (defalias 'eshell/w3m 'w3m-goto-url)
2104 (mdw-define-face eshell-prompt (t :weight bold))
2105 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2106 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2107 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2108 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2109 (mdw-define-face eshell-ls-executable (t :weight bold))
2110 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2111 (mdw-define-face eshell-ls-readonly (t nil))
2112 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2114 ;;;--------------------------------------------------------------------------
2115 ;;; Messages-file mode.
2117 (defun messages-mode-guts ()
2118 (setq messages-mode-syntax-table (make-syntax-table))
2119 (set-syntax-table messages-mode-syntax-table)
2120 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2121 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2122 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2123 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2124 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2125 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2126 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2127 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2128 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2129 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2130 (make-local-variable 'comment-start)
2131 (make-local-variable 'comment-end)
2132 (make-local-variable 'indent-line-function)
2133 (setq indent-line-function 'indent-relative)
2134 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2135 (make-local-variable 'font-lock-defaults)
2136 (make-local-variable 'messages-mode-keywords)
2138 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2139 "export" "enum" "fixed-octetstring" "flags"
2140 "harmless" "map" "nested" "optional"
2141 "optional-tagged" "package" "primitive"
2142 "primitive-nullfree" "relaxed[ \t]+enum"
2143 "set" "table" "tagged-optional" "union"
2144 "variadic" "vector" "version" "version-tag")))
2145 (setq messages-mode-keywords
2147 (list (concat "\\<\\(" keywords "\\)\\>:")
2148 '(0 font-lock-keyword-face))
2149 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2150 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2151 (0 font-lock-variable-name-face))
2152 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2153 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2154 (0 mdw-punct-face)))))
2155 (setq font-lock-defaults
2156 '(messages-mode-keywords nil nil nil nil))
2157 (run-hooks 'messages-file-hook))
2159 (defun messages-mode ()
2162 (setq major-mode 'messages-mode)
2163 (setq mode-name "Messages")
2164 (messages-mode-guts)
2165 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2166 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2167 (setq comment-start "# ")
2168 (setq comment-end "")
2169 (turn-on-font-lock-if-enabled)
2170 (run-hooks 'messages-mode-hook))
2172 (defun cpp-messages-mode ()
2175 (setq major-mode 'cpp-messages-mode)
2176 (setq mode-name "CPP Messages")
2177 (messages-mode-guts)
2178 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2179 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2180 (setq comment-start "/* ")
2181 (setq comment-end " */")
2182 (let ((preprocessor-keywords
2183 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2184 "ident" "if" "ifdef" "ifndef" "import" "include"
2185 "line" "pragma" "unassert" "undef" "warning")))
2186 (setq messages-mode-keywords
2187 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2188 "\\(include\\|import\\)"
2189 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2190 '(2 font-lock-string-face))
2191 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2192 preprocessor-keywords
2193 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2194 '(1 font-lock-keyword-face)))
2195 messages-mode-keywords)))
2196 (turn-on-font-lock-if-enabled)
2197 (run-hooks 'cpp-messages-mode-hook))
2199 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2200 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2201 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2203 ;;;--------------------------------------------------------------------------
2204 ;;; Messages-file mode.
2206 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2207 "Face to use for subsittution directives.")
2208 (make-face 'mallow-driver-substitution-face)
2209 (defvar mallow-driver-text-face 'mallow-driver-text-face
2210 "Face to use for body text.")
2211 (make-face 'mallow-driver-text-face)
2213 (defun mallow-driver-mode ()
2216 (setq major-mode 'mallow-driver-mode)
2217 (setq mode-name "Mallow driver")
2218 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2219 (set-syntax-table mallow-driver-mode-syntax-table)
2220 (make-local-variable 'comment-start)
2221 (make-local-variable 'comment-end)
2222 (make-local-variable 'indent-line-function)
2223 (setq indent-line-function 'indent-relative)
2224 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2225 (make-local-variable 'font-lock-defaults)
2226 (make-local-variable 'mallow-driver-mode-keywords)
2228 (mdw-regexps "each" "divert" "file" "if"
2229 "perl" "set" "string" "type" "write")))
2230 (setq mallow-driver-mode-keywords
2232 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2233 '(0 font-lock-keyword-face))
2234 (list "^%\\s *\\(#.*\\|\\)$"
2235 '(0 font-lock-comment-face))
2237 '(0 font-lock-keyword-face))
2238 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2240 '(0 mallow-driver-substitution-face t)))))
2241 (setq font-lock-defaults
2242 '(mallow-driver-mode-keywords nil nil nil nil))
2243 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2244 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2245 (setq comment-start "%# ")
2246 (setq comment-end "")
2247 (turn-on-font-lock-if-enabled)
2248 (run-hooks 'mallow-driver-mode-hook))
2250 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2252 ;;;--------------------------------------------------------------------------
2255 (defun nfast-debug-mode ()
2258 (setq major-mode 'nfast-debug-mode)
2259 (setq mode-name "NFast debug")
2260 (setq messages-mode-syntax-table (make-syntax-table))
2261 (set-syntax-table messages-mode-syntax-table)
2262 (make-local-variable 'font-lock-defaults)
2263 (make-local-variable 'nfast-debug-mode-keywords)
2264 (setq truncate-lines t)
2265 (setq nfast-debug-mode-keywords
2267 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2268 (0 font-lock-keyword-face))
2269 (list (concat "^[ \t]+\\(\\("
2270 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2271 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2273 "[0-9a-fA-F]+\\)[ \t]*$")
2274 '(0 mdw-number-face))
2275 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2276 (1 font-lock-keyword-face))
2277 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2278 (1 font-lock-warning-face))
2279 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2281 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2282 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2283 '(1 font-lock-keyword-face))
2284 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2285 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2286 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2287 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2288 (setq font-lock-defaults
2289 '(nfast-debug-mode-keywords nil nil nil nil))
2290 (turn-on-font-lock-if-enabled)
2291 (run-hooks 'nfast-debug-mode-hook))
2293 ;;;--------------------------------------------------------------------------
2294 ;;; Other languages.
2298 (defun mdw-setup-smalltalk ()
2299 (and mdw-auto-indent
2300 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2301 (make-variable-buffer-local 'mdw-auto-indent)
2302 (setq mdw-auto-indent nil)
2303 (local-set-key "\C-i" 'smalltalk-reindent))
2305 (defun mdw-fontify-smalltalk ()
2306 (make-local-variable 'font-lock-keywords)
2307 (setq font-lock-keywords
2309 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2310 '(0 font-lock-keyword-face))
2311 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2312 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2313 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2314 '(0 mdw-number-face))
2315 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2316 '(0 mdw-punct-face))))
2317 (mdw-post-config-mode-hack))
2321 ;; Unpleasant bodge.
2322 (unless (boundp 'slime-repl-mode-map)
2323 (setq slime-repl-mode-map (make-sparse-keymap)))
2325 (defun mdw-indent-newline-and-indent ()
2327 (indent-for-tab-command)
2328 (newline-and-indent))
2330 (eval-after-load "cl-indent"
2332 (mapc #'(lambda (pair)
2334 'common-lisp-indent-function
2336 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2337 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2339 (defun mdw-common-lisp-indent ()
2340 (make-variable-buffer-local 'lisp-indent-function)
2341 (setq lisp-indent-function 'common-lisp-indent-function))
2343 (setq lisp-simple-loop-indentation 2
2344 lisp-loop-keyword-indentation 6
2345 lisp-loop-forms-indentation 6)
2347 (defun mdw-fontify-lispy ()
2350 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2352 ;; Not much fontification needed.
2353 (make-local-variable 'font-lock-keywords)
2354 (setq font-lock-keywords
2356 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2357 '(0 mdw-punct-face))))
2359 (mdw-post-config-mode-hack))
2361 (defun comint-send-and-indent ()
2364 (and mdw-auto-indent
2365 (indent-for-tab-command)))
2367 (defun mdw-setup-m4 ()
2368 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2370 ;;;--------------------------------------------------------------------------
2373 (defun mdw-text-mode ()
2374 (setq fill-column 72)
2376 (mdw-standard-fill-prefix
2377 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2380 ;;;--------------------------------------------------------------------------
2381 ;;; Outline and hide/show modes.
2383 (defun mdw-outline-collapse-all ()
2384 "Completely collapse everything in the entire buffer."
2387 (goto-char (point-min))
2388 (while (< (point) (point-max))
2392 (setq hs-hide-comments-when-hiding-all nil)
2394 (defadvice hs-hide-all (after hide-first-comment activate)
2395 (save-excursion (hs-hide-initial-comment-block)))
2397 ;;;--------------------------------------------------------------------------
2400 (defun mdw-sh-mode-setup ()
2401 (local-set-key [?\C-a] 'comint-bol)
2402 (add-hook 'comint-output-filter-functions
2403 'comint-watch-for-password-prompt))
2405 (defun mdw-term-mode-setup ()
2406 (setq term-prompt-regexp shell-prompt-pattern)
2407 (make-local-variable 'mouse-yank-at-point)
2408 (make-local-variable 'transient-mark-mode)
2409 (setq mouse-yank-at-point t)
2413 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2414 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2415 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2416 (defun term-send-meta-meta-something ()
2418 (term-send-raw-string "\e\e")
2420 (eval-after-load 'term
2422 (define-key term-raw-map [?\e ?\e] nil)
2423 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2424 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2425 (define-key term-raw-map [M-right] 'term-send-meta-right)
2426 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2427 (define-key term-raw-map [M-left] 'term-send-meta-left)
2428 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2430 ;;;--------------------------------------------------------------------------
2431 ;;; Inferior Emacs Lisp.
2433 (setq comint-prompt-read-only t)
2435 (eval-after-load "comint"
2437 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2438 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2440 (eval-after-load "ielm"
2442 (define-key ielm-map "\C-w" 'comint-kill-region)
2443 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2445 ;;;----- That's all, folks --------------------------------------------------
2447 (provide 'dot-emacs)