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-check-autorevert ()
422 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
423 This takes into consideration whether it's been found using
424 tramp, which seems to get itself into a twist."
425 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
427 ((and (buffer-file-name)
428 (fboundp 'tramp-tramp-file-p)
429 (tramp-tramp-file-p (buffer-file-name)))
430 (unless global-auto-revert-ignore-buffer
431 (setq global-auto-revert-ignore-buffer 'tramp)))
432 ((eq global-auto-revert-ignore-buffer 'tramp)
433 (setq global-auto-revert-ignore-buffer nil))))
435 (defadvice find-file (after mdw-autorevert activate)
436 (mdw-check-autorevert))
437 (defadvice write-file (after mdw-autorevert activate)
438 (mdw-check-autorevert))
440 ;;;--------------------------------------------------------------------------
443 (defadvice dired-maybe-insert-subdir
444 (around mdw-marked-insertion first activate)
445 "The DIRNAME may be a list of directory names to insert.
446 Interactively, if files are marked, then insert all of them.
447 With a numeric prefix argument, select that many entries near
448 point; with a non-numeric prefix argument, prompt for listing
451 (list (dired-get-marked-files nil
452 (and (integerp current-prefix-arg)
455 (and current-prefix-arg
456 (not (integerp current-prefix-arg))
457 (read-string "Switches for listing: "
458 (or dired-subdir-switches
459 dired-actual-switches)))))
460 (let ((dirs (ad-get-arg 0)))
461 (dolist (dir (if (listp dirs) dirs (list dirs)))
465 ;;;--------------------------------------------------------------------------
468 (defun mdw-w3m-browse-url (url &optional new-session-p)
469 "Invoke w3m on the URL in its current window, or at least a different one.
470 If NEW-SESSION-P, start a new session."
471 (interactive "sURL: \nP")
473 (let ((window (selected-window)))
476 (select-window (or (and (not new-session-p)
477 (get-buffer-window "*w3m*"))
479 (if (one-window-p t) (split-window))
481 (w3m-browse-url url new-session-p))
482 (select-window window)))))
484 (defvar mdw-good-url-browsers
485 '((w3m . mdw-w3m-browse-url)
488 "List of good browsers for mdw-good-url-browsers.
489 Each item is a browser function name, or a cons (CHECK . FUNC).
490 A symbol FOO stands for (FOO . FOO).")
492 (defun mdw-good-url-browser ()
493 "Return a good URL browser.
494 Trundle the list of such things, finding the first item for which
495 CHECK is fboundp, and returning the correponding FUNC."
496 (let ((bs mdw-good-url-browsers) b check func answer)
497 (while (and bs (not answer))
501 (setq check (car b) func (cdr b))
502 (setq check b func b))
507 (eval-after-load "w3m-search"
511 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
512 ("gd" "Google Directory"
513 "http://www.google.com/search?cat=gwd/Top&q=%s")
514 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
515 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
516 ("gi" "Images" "http://images.google.com/images?q=%s")
518 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
520 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
521 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
522 ("nc-wiki" "nCipher wiki"
523 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
524 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
525 ("lp" "Launchpad bug by number"
526 "https://bugs.launchpad.net/bugs/%s")
527 ("lppkg" "Launchpad bugs by package"
528 "https://bugs.launchpad.net/%s")
530 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
531 ("debbug" "Debian bug by number"
532 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
533 ("debbugpkg" "Debian bugs by package"
534 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
535 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
536 (add-to-list 'w3m-search-engine-alist
537 (list (cadr item) (caddr item) nil))
538 (add-to-list 'w3m-uri-replace-alist
539 (list (concat "\\`" (car item) ":")
540 'w3m-search-uri-replace
543 ;;;--------------------------------------------------------------------------
544 ;;; Paragraph filling.
548 (defvar mdw-fill-prefix nil
549 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
550 If there's no fill prefix currently set (by the `fill-prefix'
551 variable) and there's a match from one of the regexps here, it
552 gets used to set the fill-prefix for the current operation.
554 The variable is a list of items of the form `REGEXP . PREFIX'; if
555 the REGEXP matches, the PREFIX is used to set the fill prefix.
556 It in turn is a list of things:
558 STRING -- insert a literal string
559 (match . N) -- insert the thing matched by bracketed subexpression N
560 (pad . N) -- a string of whitespace the same width as subexpression N
561 (expr . FORM) -- the result of evaluating FORM")
563 (make-variable-buffer-local 'mdw-fill-prefix)
565 (defvar mdw-hanging-indents
567 "\\([*o]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
570 "*Standard regexp matching parts of a hanging indent.
571 This is mainly useful in `auto-fill-mode'.")
573 ;; Setting things up.
575 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
577 ;; Utility functions.
579 (defun mdw-tabify (s)
580 "Tabify the string S. This is a horrid hack."
585 (setq start (point-marker))
587 (setq end (point-marker))
589 (setq s (buffer-substring start (1- end)))
590 (delete-region start end)
591 (set-marker start nil)
595 (defun mdw-examine-fill-prefixes (l)
596 "Given a list of dynamic fill prefixes, pick one which matches
597 context and return the static fill prefix to use. Point must be
598 at the start of a line, and match data must be saved."
600 ((looking-at (car (car l)))
601 (mdw-tabify (apply (function concat)
602 (mapcar (function mdw-do-prefix-match)
604 (t (mdw-examine-fill-prefixes (cdr l)))))
606 (defun mdw-maybe-car (p)
607 "If P is a pair, return (car P), otherwise just return P."
608 (if (consp p) (car p) p))
610 (defun mdw-padding (s)
611 "Return a string the same width as S but made entirely from whitespace."
612 (let* ((l (length s)) (i 0) (n (make-string l ? )))
619 (defun mdw-do-prefix-match (m)
620 "Expand a dynamic prefix match element.
621 See `mdw-fill-prefix' for details."
622 (cond ((not (consp m)) (format "%s" m))
623 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
624 ((eq (car m) 'pad) (mdw-padding (match-string
625 (mdw-maybe-car (cdr m)))))
626 ((eq (car m) 'eval) (eval (cdr m)))
629 (defun mdw-choose-dynamic-fill-prefix ()
630 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
631 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
632 ((not mdw-fill-prefix) fill-prefix)
636 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
638 (defun do-auto-fill ()
639 "Handle auto-filling, working out a dynamic fill prefix in the
640 case where there isn't a sensible static one."
641 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
644 (defun mdw-fill-paragraph ()
645 "Fill paragraph, getting a dynamic fill prefix."
647 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
648 (fill-paragraph nil)))
650 (defun mdw-standard-fill-prefix (rx &optional mat)
651 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
652 This is just a short-cut for setting the thing by hand, and by
653 design it doesn't cope with anything approximating a complicated
655 (setq mdw-fill-prefix
656 `((,(concat rx mdw-hanging-indents)
658 (pad . ,(or mat 2))))))
660 ;;;--------------------------------------------------------------------------
661 ;;; Other common declarations.
663 ;; Common mode settings.
665 (defvar mdw-auto-indent t
666 "Whether to indent automatically after a newline.")
668 (defun mdw-misc-mode-config ()
670 (cond ((eq major-mode 'lisp-mode)
671 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
672 ((or (eq major-mode 'slime-repl-mode)
673 (eq major-mode 'asm-mode))
676 (local-set-key "\C-m" 'newline-and-indent))))
677 (local-set-key [C-return] 'newline)
678 (make-variable-buffer-local 'page-delimiter)
679 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
680 (setq comment-column 40)
682 (setq fill-column 77)
683 (setq show-trailing-whitespace t)
684 (let ((whitespace-style (remove 'trailing whitespace-style)))
685 (trap (whitespace-mode t)))
686 (and (fboundp 'gtags-mode)
688 (outline-minor-mode t)
691 (trap (turn-on-font-lock)))
693 (defun mdw-post-config-mode-hack ()
694 (let ((whitespace-style (remove 'trailing whitespace-style)))
695 (trap (whitespace-mode t))))
697 (eval-after-load 'gtags
699 (dolist (key '([mouse-2] [mouse-3]))
700 (define-key gtags-mode-map key nil))
701 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
702 (define-key gtags-select-mode-map [C-S-mouse-2]
703 'gtags-select-tag-by-event)
704 (dolist (map (list gtags-mode-map gtags-select-mode-map))
705 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
707 ;; Backup file handling.
709 (defvar mdw-backup-disable-regexps nil
710 "*List of regular expressions: if a file name matches any of
711 these then the file is not backed up.")
713 (defun mdw-backup-enable-predicate (name)
714 "[mdw]'s default backup predicate.
715 Allows a backup if the standard predicate would allow it, and it
716 doesn't match any of the regular expressions in
717 `mdw-backup-disable-regexps'."
718 (and (normal-backup-enable-predicate name)
719 (let ((answer t) (list mdw-backup-disable-regexps))
722 (if (string-match (car list) name)
724 (setq list (cdr list)))
726 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
730 (defun mdw-last-one-out-turn-off-the-lights (frame)
731 "Disconnect from an X display if this was the last frame on that display."
732 (let ((frame-display (frame-parameter frame 'display)))
733 (when (and frame-display
734 (eq window-system 'x)
735 (not (some (lambda (fr)
736 (message "checking frame %s" frame)
737 (and (not (eq fr frame))
738 (string= (frame-parameter fr 'display)
740 (progn "frame %s still uses us" nil)))
742 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
743 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
745 (defvar mdw-frame-parameters-alist
746 '((nil (menu-bar-lines . 0))))
747 (defun mdw-set-frame-parameters (frame)
748 (let ((params (assq (if (fboundp 'window-system)
749 (window-system frame)
751 mdw-frame-parameters-alist)))
753 (modify-frame-parameters frame (cdr params)))))
754 (add-hook 'after-make-frame-functions 'mdw-set-frame-parameters)
756 ;;;--------------------------------------------------------------------------
757 ;;; General fontification.
759 (defmacro mdw-define-face (name &rest body)
760 "Define a face, and make sure it's actually set as the definition."
765 (defvar ,name ',name)
766 (put ',name 'face-defface-spec ',body)
767 (face-spec-set ',name ',body nil)))
769 (mdw-define-face default
770 (((type w32)) :family "courier new" :height 85)
771 (((type x)) :family "6x13" :height 130)
772 (((type color)) :foreground "white" :background "black")
774 (mdw-define-face fixed-pitch
775 (((type w32)) :family "courier new" :height 85)
776 (((type x)) :family "6x13" :height 130)
777 (t :foreground "white" :background "black"))
778 (if (>= emacs-major-version 23)
779 (mdw-define-face variable-pitch
780 (((type x)) :family "sans" :height 100))
781 (mdw-define-face variable-pitch
782 (((type x)) :family "helvetica" :height 120)))
783 (mdw-define-face region
784 (((type tty) (class color)) :background "blue")
785 (((type tty) (class mono)) :inverse-video t)
786 (t :background "grey30"))
787 (mdw-define-face minibuffer-prompt
789 (mdw-define-face mode-line
790 (((class color)) :foreground "blue" :background "yellow"
791 :box (:line-width 1 :style released-button))
792 (t :inverse-video t))
793 (mdw-define-face mode-line-inactive
794 (((class color)) :foreground "yellow" :background "blue"
795 :box (:line-width 1 :style released-button))
796 (t :inverse-video t))
797 (mdw-define-face scroll-bar
798 (t :foreground "black" :background "lightgrey"))
799 (mdw-define-face fringe
800 (t :foreground "yellow"))
801 (mdw-define-face show-paren-match
802 (((class color)) :background "darkgreen")
804 (mdw-define-face show-paren-mismatch
805 (((class color)) :background "red")
806 (t :inverse-video t))
807 (mdw-define-face highlight
808 (((class color)) :background "DarkSeaGreen4")
809 (t :inverse-video t))
811 (mdw-define-face holiday-face
812 (t :background "red"))
813 (mdw-define-face calendar-today-face
814 (t :foreground "yellow" :weight bold))
816 (mdw-define-face comint-highlight-prompt
818 (mdw-define-face comint-highlight-input
821 (mdw-define-face trailing-whitespace
822 (((class color)) :background "red")
823 (t :inverse-video t))
824 (mdw-define-face mdw-punct-face
825 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
826 (mdw-define-face mdw-number-face
827 (t :foreground "yellow"))
828 (mdw-define-face font-lock-function-name-face
830 (mdw-define-face font-lock-keyword-face
832 (mdw-define-face font-lock-constant-face
834 (mdw-define-face font-lock-builtin-face
836 (mdw-define-face font-lock-type-face
837 (t :weight bold :slant italic))
838 (mdw-define-face font-lock-reference-face
840 (mdw-define-face font-lock-variable-name-face
842 (mdw-define-face font-lock-comment-delimiter-face
843 (((class mono)) :weight bold)
844 (((type tty) (class color)) :foreground "green")
845 (t :slant italic :foreground "SeaGreen1"))
846 (mdw-define-face font-lock-comment-face
847 (((class mono)) :weight bold)
848 (((type tty) (class color)) :foreground "green")
849 (t :slant italic :foreground "SeaGreen1"))
850 (mdw-define-face font-lock-string-face
851 (((class mono)) :weight bold)
852 (((class color)) :foreground "SkyBlue1"))
853 (mdw-define-face message-separator
854 (t :background "red" :foreground "white" :weight bold))
855 (mdw-define-face message-cited-text
856 (default :slant italic)
857 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
858 (mdw-define-face message-header-cc
859 (default :weight bold)
860 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
861 (mdw-define-face message-header-newsgroups
862 (default :weight bold)
863 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
864 (mdw-define-face message-header-subject
865 (default :weight bold)
866 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
867 (mdw-define-face message-header-to
868 (default :weight bold)
869 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
870 (mdw-define-face message-header-xheader
871 (default :weight bold)
872 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
873 (mdw-define-face message-header-other
874 (default :weight bold)
875 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
876 (mdw-define-face message-header-name
877 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
879 (mdw-define-face diff-index
881 (mdw-define-face diff-file-header
883 (mdw-define-face diff-hunk-header
884 (t :foreground "SkyBlue1"))
885 (mdw-define-face diff-function
886 (t :foreground "SkyBlue1" :weight bold))
887 (mdw-define-face diff-header
888 (t :background "grey10"))
889 (mdw-define-face diff-added
890 (t :foreground "green"))
891 (mdw-define-face diff-removed
892 (t :foreground "red"))
893 (mdw-define-face diff-context
896 (mdw-define-face erc-input-face
897 (t :foreground "red"))
899 (mdw-define-face woman-bold
901 (mdw-define-face woman-italic
904 (mdw-define-face p4-depot-added-face
905 (t :foreground "green"))
906 (mdw-define-face p4-depot-branch-op-face
907 (t :foreground "yellow"))
908 (mdw-define-face p4-depot-deleted-face
909 (t :foreground "red"))
910 (mdw-define-face p4-depot-unmapped-face
911 (t :foreground "SkyBlue1"))
912 (mdw-define-face p4-diff-change-face
913 (t :foreground "yellow"))
914 (mdw-define-face p4-diff-del-face
915 (t :foreground "red"))
916 (mdw-define-face p4-diff-file-face
917 (t :foreground "SkyBlue1"))
918 (mdw-define-face p4-diff-head-face
919 (t :background "grey10"))
920 (mdw-define-face p4-diff-ins-face
921 (t :foreground "green"))
923 (mdw-define-face whizzy-slice-face
924 (t :background "grey10"))
925 (mdw-define-face whizzy-error-face
926 (t :background "darkred"))
928 ;;;--------------------------------------------------------------------------
929 ;;; C programming configuration.
931 ;; Linux kernel hacking.
933 (defvar linux-c-mode-hook)
935 (defun linux-c-mode ()
938 (setq major-mode 'linux-c-mode)
939 (setq mode-name "Linux C")
940 (run-hooks 'linux-c-mode-hook))
942 ;; Make C indentation nice.
944 (defun mdw-c-lineup-arglist (langelem)
945 "Hack for DWIMmery in c-lineup-arglist."
947 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
949 (c-lineup-arglist langelem)))
951 (defun mdw-c-indent-extern-mumble (langelem)
952 "Indent `extern \"...\" {' lines."
954 (back-to-indentation)
956 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
960 (defun mdw-c-style ()
961 (c-add-style "[mdw] C and C++ style"
962 '((c-basic-offset . 2)
963 (comment-column . 40)
964 (c-class-key . "class")
965 (c-backslash-column . 72)
967 (substatement-open . (add 0 c-indent-one-line-block))
968 (defun-open . (add 0 c-indent-one-line-block))
969 (arglist-cont-nonempty . mdw-c-lineup-arglist)
970 (topmost-intro . mdw-c-indent-extern-mumble)
971 (cpp-define-intro . 0)
972 (inextern-lang . [0])
979 (statement-case-intro . +)))
982 (defvar mdw-c-comment-fill-prefix
983 `((,(concat "\\([ \t]*/?\\)"
986 "\\([A-Za-z]+:[ \t]*\\)?"
988 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
989 "Fill prefix matching C comments (both kinds).")
991 (defun mdw-fontify-c-and-c++ ()
993 ;; Fiddle with some syntax codes.
994 (modify-syntax-entry ?* ". 23")
995 (modify-syntax-entry ?/ ". 124b")
996 (modify-syntax-entry ?\n "> b")
1000 (setq c-hanging-comment-ender-p nil)
1001 (setq c-backslash-column 72)
1002 (setq c-label-minimum-indentation 0)
1003 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1005 ;; Now define things to be fontified.
1006 (make-local-variable 'font-lock-keywords)
1008 (mdw-regexps "and" ;C++
1014 "bool" ;C++, C9X macro
1020 "complex" ;C9X macro, C++ template type
1024 "continue" ;K&R, C89
1025 "defined" ;C89 preprocessor
1032 ;; "entry" ;K&R -- never used
1037 "false" ;C++, C9X macro
1044 "imaginary" ;C9X macro
1045 "inline" ;C++, C9X, GCC
1057 "register" ;K&R, C89
1058 "reinterpret_cast" ;C++
1071 "true" ;C++, C9X macro
1079 "unsigned" ;K&R, C89
1084 "wchar_t" ;C++, C89 library type
1091 "_Pragma" ;C9X preprocessor
1094 "__attribute__" ;GCC
1097 "__extension__" ;GCC
1106 (preprocessor-keywords
1107 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1108 "ident" "if" "ifdef" "ifndef" "import" "include"
1109 "line" "pragma" "unassert" "undef" "warning"))
1111 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1112 "interface" "private" "protected" "protocol" "public"
1115 (setq font-lock-keywords
1118 ;; Fontify include files as strings.
1119 (list (concat "^[ \t]*\\#[ \t]*"
1120 "\\(include\\|import\\)"
1121 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1122 '(2 font-lock-string-face))
1124 ;; Preprocessor directives are `references'?.
1125 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1126 preprocessor-keywords
1127 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1128 '(1 font-lock-keyword-face))
1130 ;; Handle the keywords defined above.
1131 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1132 '(0 font-lock-keyword-face))
1134 (list (concat "\\<\\(" c-keywords "\\)\\>")
1135 '(0 font-lock-keyword-face))
1137 ;; Handle numbers too.
1139 ;; This looks strange, I know. It corresponds to the
1140 ;; preprocessor's idea of what a number looks like, rather than
1141 ;; anything sensible.
1142 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1143 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1144 '(0 mdw-number-face))
1146 ;; And anything else is punctuation.
1147 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1148 '(0 mdw-punct-face))))
1150 (mdw-post-config-mode-hack)))
1152 ;;;--------------------------------------------------------------------------
1155 (defun apcalc-mode ()
1158 (setq major-mode 'apcalc-mode)
1159 (setq mode-name "AP Calc")
1160 (run-hooks 'apcalc-mode-hook))
1162 (defun mdw-fontify-apcalc ()
1164 ;; Fiddle with some syntax codes.
1165 (modify-syntax-entry ?* ". 23")
1166 (modify-syntax-entry ?/ ". 14")
1170 (setq c-hanging-comment-ender-p nil)
1171 (setq c-backslash-column 72)
1172 (setq comment-start "/* ")
1173 (setq comment-end " */")
1174 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1176 ;; Now define things to be fontified.
1177 (make-local-variable 'font-lock-keywords)
1179 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1180 "do" "else" "exit" "for" "global" "goto" "help" "if"
1181 "local" "mat" "obj" "print" "quit" "read" "return"
1182 "show" "static" "switch" "while" "write")))
1184 (setq font-lock-keywords
1187 ;; Handle the keywords defined above.
1188 (list (concat "\\<\\(" c-keywords "\\)\\>")
1189 '(0 font-lock-keyword-face))
1191 ;; Handle numbers too.
1193 ;; This looks strange, I know. It corresponds to the
1194 ;; preprocessor's idea of what a number looks like, rather than
1195 ;; anything sensible.
1196 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1197 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1198 '(0 mdw-number-face))
1200 ;; And anything else is punctuation.
1201 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1202 '(0 mdw-punct-face)))))
1204 (mdw-post-config-mode-hack))
1206 ;;;--------------------------------------------------------------------------
1207 ;;; Java programming configuration.
1209 ;; Make indentation nice.
1211 (defun mdw-java-style ()
1212 (c-add-style "[mdw] Java style"
1213 '((c-basic-offset . 2)
1214 (c-offsets-alist (substatement-open . 0)
1219 (statement-case-intro . +)))
1222 ;; Declare Java fontification style.
1224 (defun mdw-fontify-java ()
1228 (setq c-hanging-comment-ender-p nil)
1229 (setq c-backslash-column 72)
1230 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1232 ;; Now define things to be fontified.
1233 (make-local-variable 'font-lock-keywords)
1234 (let ((java-keywords
1235 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1236 "char" "class" "const" "continue" "default" "do"
1237 "double" "else" "extends" "final" "finally" "float"
1238 "for" "goto" "if" "implements" "import" "instanceof"
1239 "int" "interface" "long" "native" "new" "package"
1240 "private" "protected" "public" "return" "short"
1241 "static" "super" "switch" "synchronized" "this"
1242 "throw" "throws" "transient" "try" "void" "volatile"
1245 "false" "null" "true")))
1247 (setq font-lock-keywords
1250 ;; Handle the keywords defined above.
1251 (list (concat "\\<\\(" java-keywords "\\)\\>")
1252 '(0 font-lock-keyword-face))
1254 ;; Handle numbers too.
1256 ;; The following isn't quite right, but it's close enough.
1257 (list (concat "\\<\\("
1258 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1259 "[0-9]+\\(\\.[0-9]*\\|\\)"
1260 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1262 '(0 mdw-number-face))
1264 ;; And anything else is punctuation.
1265 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1266 '(0 mdw-punct-face)))))
1268 (mdw-post-config-mode-hack))
1270 ;;;--------------------------------------------------------------------------
1271 ;;; C# programming configuration.
1273 ;; Make indentation nice.
1275 (defun mdw-csharp-style ()
1276 (c-add-style "[mdw] C# style"
1277 '((c-basic-offset . 2)
1278 (c-offsets-alist (substatement-open . 0)
1283 (statement-case-intro . +)))
1286 ;; Declare C# fontification style.
1288 (defun mdw-fontify-csharp ()
1292 (setq c-hanging-comment-ender-p nil)
1293 (setq c-backslash-column 72)
1294 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1296 ;; Now define things to be fontified.
1297 (make-local-variable 'font-lock-keywords)
1298 (let ((csharp-keywords
1299 (mdw-regexps "abstract" "as" "base" "bool" "break"
1300 "byte" "case" "catch" "char" "checked"
1301 "class" "const" "continue" "decimal" "default"
1302 "delegate" "do" "double" "else" "enum"
1303 "event" "explicit" "extern" "false" "finally"
1304 "fixed" "float" "for" "foreach" "goto"
1305 "if" "implicit" "in" "int" "interface"
1306 "internal" "is" "lock" "long" "namespace"
1307 "new" "null" "object" "operator" "out"
1308 "override" "params" "private" "protected" "public"
1309 "readonly" "ref" "return" "sbyte" "sealed"
1310 "short" "sizeof" "stackalloc" "static" "string"
1311 "struct" "switch" "this" "throw" "true"
1312 "try" "typeof" "uint" "ulong" "unchecked"
1313 "unsafe" "ushort" "using" "virtual" "void"
1314 "volatile" "while" "yield")))
1316 (setq font-lock-keywords
1319 ;; Handle the keywords defined above.
1320 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1321 '(0 font-lock-keyword-face))
1323 ;; Handle numbers too.
1325 ;; The following isn't quite right, but it's close enough.
1326 (list (concat "\\<\\("
1327 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1328 "[0-9]+\\(\\.[0-9]*\\|\\)"
1329 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1331 '(0 mdw-number-face))
1333 ;; And anything else is punctuation.
1334 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1335 '(0 mdw-punct-face)))))
1337 (mdw-post-config-mode-hack))
1339 (define-derived-mode csharp-mode java-mode "C#"
1340 "Major mode for editing C# code.")
1342 ;;;--------------------------------------------------------------------------
1343 ;;; Go programming configuration.
1345 (defun mdw-fontify-go ()
1347 (make-local-variable 'font-lock-keywords)
1349 (mdw-regexps "break" "case" "chan" "const" "continue"
1350 "default" "defer" "else" "fallthrough" "for"
1351 "func" "go" "goto" "if" "import"
1352 "interface" "map" "package" "range" "return"
1353 "select" "struct" "switch" "type" "var")))
1355 (setq font-lock-keywords
1358 ;; Handle the keywords defined above.
1359 (list (concat "\\<\\(" go-keywords "\\)\\>")
1360 '(0 font-lock-keyword-face))
1362 ;; Handle numbers too.
1364 ;; The following isn't quite right, but it's close enough.
1365 (list (concat "\\<\\("
1366 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1367 "[0-9]+\\(\\.[0-9]*\\|\\)"
1368 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1369 '(0 mdw-number-face))
1371 ;; And anything else is punctuation.
1372 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1373 '(0 mdw-punct-face)))))
1375 (mdw-post-config-mode-hack))
1377 ;;;--------------------------------------------------------------------------
1378 ;;; Awk programming configuration.
1380 ;; Make Awk indentation nice.
1382 (defun mdw-awk-style ()
1383 (c-add-style "[mdw] Awk style"
1384 '((c-basic-offset . 2)
1385 (c-offsets-alist (substatement-open . 0)
1386 (statement-cont . 0)
1387 (statement-case-intro . +)))
1390 ;; Declare Awk fontification style.
1392 (defun mdw-fontify-awk ()
1394 ;; Miscellaneous fiddling.
1396 (setq c-backslash-column 72)
1397 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1399 ;; Now define things to be fontified.
1400 (make-local-variable 'font-lock-keywords)
1402 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1403 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1404 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1405 "RSTART" "RLENGTH" "RT" "SUBSEP"
1406 "atan2" "break" "close" "continue" "cos" "delete"
1407 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1408 "function" "gensub" "getline" "gsub" "if" "in"
1409 "index" "int" "length" "log" "match" "next" "rand"
1410 "return" "print" "printf" "sin" "split" "sprintf"
1411 "sqrt" "srand" "strftime" "sub" "substr" "system"
1412 "systime" "tolower" "toupper" "while")))
1414 (setq font-lock-keywords
1417 ;; Handle the keywords defined above.
1418 (list (concat "\\<\\(" c-keywords "\\)\\>")
1419 '(0 font-lock-keyword-face))
1421 ;; Handle numbers too.
1423 ;; The following isn't quite right, but it's close enough.
1424 (list (concat "\\<\\("
1425 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1426 "[0-9]+\\(\\.[0-9]*\\|\\)"
1427 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1429 '(0 mdw-number-face))
1431 ;; And anything else is punctuation.
1432 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1433 '(0 mdw-punct-face)))))
1435 (mdw-post-config-mode-hack))
1437 ;;;--------------------------------------------------------------------------
1438 ;;; Perl programming style.
1440 ;; Perl indentation style.
1442 (setq cperl-indent-level 2)
1443 (setq cperl-continued-statement-offset 2)
1444 (setq cperl-continued-brace-offset 0)
1445 (setq cperl-brace-offset -2)
1446 (setq cperl-brace-imaginary-offset 0)
1447 (setq cperl-label-offset 0)
1449 ;; Define perl fontification style.
1451 (defun mdw-fontify-perl ()
1453 ;; Miscellaneous fiddling.
1454 (modify-syntax-entry ?$ "\\")
1455 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1456 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1458 ;; Now define fontification things.
1459 (make-local-variable 'font-lock-keywords)
1460 (let ((perl-keywords
1461 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1462 "for" "foreach" "ge" "gt" "goto" "if"
1463 "last" "le" "lt" "local" "my" "ne" "next" "or"
1464 "package" "redo" "require" "return" "sub"
1465 "undef" "unless" "until" "use" "while")))
1467 (setq font-lock-keywords
1470 ;; Set up the keywords defined above.
1471 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1472 '(0 font-lock-keyword-face))
1474 ;; At least numbers are simpler than C.
1475 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1476 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1477 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1478 '(0 mdw-number-face))
1480 ;; And anything else is punctuation.
1481 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1482 '(0 mdw-punct-face)))))
1484 (mdw-post-config-mode-hack))
1486 (defun perl-number-tests (&optional arg)
1487 "Assign consecutive numbers to lines containing `#t'. With ARG,
1488 strip numbers instead."
1491 (goto-char (point-min))
1492 (let ((i 0) (fmt (if arg "" " %4d")))
1493 (while (search-forward "#t" nil t)
1494 (delete-region (point) (line-end-position))
1496 (insert (format fmt i)))
1497 (goto-char (point-min))
1498 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1499 (replace-match (format "\\1%d" i))))))
1501 ;;;--------------------------------------------------------------------------
1502 ;;; Python programming style.
1504 (defun mdw-fontify-pythonic (keywords)
1506 ;; Miscellaneous fiddling.
1507 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1509 ;; Now define fontification things.
1510 (make-local-variable 'font-lock-keywords)
1511 (setq font-lock-keywords
1514 ;; Set up the keywords defined above.
1515 (list (concat "\\<\\(" keywords "\\)\\>")
1516 '(0 font-lock-keyword-face))
1518 ;; At least numbers are simpler than C.
1519 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1520 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1521 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1522 '(0 mdw-number-face))
1524 ;; And anything else is punctuation.
1525 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1526 '(0 mdw-punct-face))))
1528 (mdw-post-config-mode-hack))
1530 ;; Define Python fontification styles.
1532 (defun mdw-fontify-python ()
1533 (mdw-fontify-pythonic
1534 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1535 "del" "elif" "else" "except" "exec" "finally" "for"
1536 "from" "global" "if" "import" "in" "is" "lambda"
1537 "not" "or" "pass" "print" "raise" "return" "try"
1538 "while" "with" "yield")))
1540 (defun mdw-fontify-pyrex ()
1541 (mdw-fontify-pythonic
1542 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1543 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1544 "extern" "finally" "for" "from" "global" "if"
1545 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1546 "raise" "return" "struct" "try" "while" "with"
1549 ;;;--------------------------------------------------------------------------
1550 ;;; Icon programming style.
1552 ;; Icon indentation style.
1554 (setq icon-brace-offset 0
1555 icon-continued-brace-offset 0
1556 icon-continued-statement-offset 2
1557 icon-indent-level 2)
1559 ;; Define Icon fontification style.
1561 (defun mdw-fontify-icon ()
1563 ;; Miscellaneous fiddling.
1564 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1566 ;; Now define fontification things.
1567 (make-local-variable 'font-lock-keywords)
1568 (let ((icon-keywords
1569 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1570 "end" "every" "fail" "global" "if" "initial"
1571 "invocable" "link" "local" "next" "not" "of"
1572 "procedure" "record" "repeat" "return" "static"
1573 "suspend" "then" "to" "until" "while"))
1574 (preprocessor-keywords
1575 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1576 "include" "line" "undef")))
1577 (setq font-lock-keywords
1580 ;; Set up the keywords defined above.
1581 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1582 '(0 font-lock-keyword-face))
1584 ;; The things that Icon calls keywords.
1585 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1587 ;; At least numbers are simpler than C.
1588 (list (concat "\\<[0-9]+"
1589 "\\([rR][0-9a-zA-Z]+\\|"
1590 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1591 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1592 '(0 mdw-number-face))
1595 (list (concat "^[ \t]*$[ \t]*\\<\\("
1596 preprocessor-keywords
1598 '(0 font-lock-keyword-face))
1600 ;; And anything else is punctuation.
1601 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1602 '(0 mdw-punct-face)))))
1604 (mdw-post-config-mode-hack))
1606 ;;;--------------------------------------------------------------------------
1607 ;;; ARM assembler programming configuration.
1609 ;; There doesn't appear to be an Emacs mode for this yet.
1611 ;; Better do something about that, I suppose.
1613 (defvar arm-assembler-mode-map nil)
1614 (defvar arm-assembler-abbrev-table nil)
1615 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1617 (or arm-assembler-mode-map
1619 (setq arm-assembler-mode-map (make-sparse-keymap))
1620 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1621 (define-key arm-assembler-mode-map [C-return] 'newline)
1622 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1624 (defun arm-assembler-mode ()
1625 "Major mode for ARM assembler programs"
1628 ;; Do standard major mode things.
1629 (kill-all-local-variables)
1630 (use-local-map arm-assembler-mode-map)
1631 (setq local-abbrev-table arm-assembler-abbrev-table)
1632 (setq major-mode 'arm-assembler-mode)
1633 (setq mode-name "ARM assembler")
1635 ;; Set up syntax table.
1636 (set-syntax-table arm-assembler-mode-syntax-table)
1637 (modify-syntax-entry ?; ; Nasty hack
1638 "<" arm-assembler-mode-syntax-table)
1639 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1640 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1642 (make-local-variable 'comment-start)
1643 (setq comment-start ";")
1644 (make-local-variable 'comment-end)
1645 (setq comment-end "")
1646 (make-local-variable 'comment-column)
1647 (setq comment-column 48)
1648 (make-local-variable 'comment-start-skip)
1649 (setq comment-start-skip ";+[ \t]*")
1651 ;; Play with indentation.
1652 (make-local-variable 'indent-line-function)
1653 (setq indent-line-function 'indent-relative-maybe)
1656 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1658 ;; Fiddle with fontification.
1659 (make-local-variable 'font-lock-keywords)
1660 (setq font-lock-keywords
1663 ;; Handle numbers too.
1665 ;; The following isn't quite right, but it's close enough.
1668 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1670 '(0 mdw-number-face))
1672 ;; Do something about operators.
1673 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1674 '(1 font-lock-keyword-face)
1675 '(2 font-lock-string-face))
1677 '(0 font-lock-keyword-face))
1679 ;; Do menemonics and directives.
1680 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1681 '(1 font-lock-keyword-face))
1683 ;; And anything else is punctuation.
1684 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1685 '(0 mdw-punct-face)))
1687 (mdw-post-config-mode-hack))
1688 (run-hooks 'arm-assembler-mode-hook))
1690 ;;;--------------------------------------------------------------------------
1693 (defun mdw-fontify-asm ()
1694 (modify-syntax-entry ?' "\"")
1695 (modify-syntax-entry ?. "w")
1696 (setf fill-prefix nil)
1697 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1699 ;;;--------------------------------------------------------------------------
1700 ;;; TCL configuration.
1702 (defun mdw-fontify-tcl ()
1703 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1704 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1705 (make-local-variable 'font-lock-keywords)
1706 (setq font-lock-keywords
1708 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1709 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1710 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1711 '(0 mdw-number-face))
1712 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1713 '(0 mdw-punct-face))))
1714 (mdw-post-config-mode-hack))
1716 ;;;--------------------------------------------------------------------------
1717 ;;; REXX configuration.
1719 (defun mdw-rexx-electric-* ()
1724 (defun mdw-rexx-indent-newline-indent ()
1727 (if abbrev-mode (expand-abbrev))
1728 (newline-and-indent))
1730 (defun mdw-fontify-rexx ()
1732 ;; Various bits of fiddling.
1733 (setq mdw-auto-indent nil)
1734 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1735 (local-set-key [?*] 'mdw-rexx-electric-*)
1736 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1738 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1740 ;; Set up keywords and things for fontification.
1741 (make-local-variable 'font-lock-keywords-case-fold-search)
1742 (setq font-lock-keywords-case-fold-search t)
1744 (setq rexx-indent 2)
1745 (setq rexx-end-indent rexx-indent)
1746 (setq rexx-cont-indent rexx-indent)
1748 (make-local-variable 'font-lock-keywords)
1749 (let ((rexx-keywords
1750 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1751 "else" "end" "engineering" "exit" "expose" "for"
1752 "forever" "form" "fuzz" "if" "interpret" "iterate"
1753 "leave" "linein" "name" "nop" "numeric" "off" "on"
1754 "options" "otherwise" "parse" "procedure" "pull"
1755 "push" "queue" "return" "say" "select" "signal"
1756 "scientific" "source" "then" "trace" "to" "until"
1757 "upper" "value" "var" "version" "when" "while"
1760 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1761 "center" "center" "charin" "charout" "chars"
1762 "compare" "condition" "copies" "c2d" "c2x"
1763 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1764 "errortext" "format" "fuzz" "insert" "lastpos"
1765 "left" "length" "lineout" "lines" "max" "min"
1766 "overlay" "pos" "queued" "random" "reverse" "right"
1767 "sign" "sourceline" "space" "stream" "strip"
1768 "substr" "subword" "symbol" "time" "translate"
1769 "trunc" "value" "verify" "word" "wordindex"
1770 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1773 (setq font-lock-keywords
1776 ;; Set up the keywords defined above.
1777 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1778 '(0 font-lock-keyword-face))
1780 ;; Fontify all symbols the same way.
1781 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1782 "[A-Za-z0-9.!?_#@$]+\\)")
1783 '(0 font-lock-variable-name-face))
1785 ;; And everything else is punctuation.
1786 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1787 '(0 mdw-punct-face)))))
1789 (mdw-post-config-mode-hack))
1791 ;;;--------------------------------------------------------------------------
1792 ;;; Standard ML programming style.
1794 (defun mdw-fontify-sml ()
1796 ;; Make underscore an honorary letter.
1797 (modify-syntax-entry ?' "w")
1800 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1802 ;; Now define fontification things.
1803 (make-local-variable 'font-lock-keywords)
1805 (mdw-regexps "abstype" "and" "andalso" "as"
1808 "else" "end" "eqtype" "exception"
1809 "fn" "fun" "functor"
1811 "if" "in" "include" "infix" "infixr"
1814 "of" "op" "open" "orelse"
1816 "sharing" "sig" "signature" "struct" "structure"
1819 "where" "while" "with" "withtype")))
1821 (setq font-lock-keywords
1824 ;; Set up the keywords defined above.
1825 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1826 '(0 font-lock-keyword-face))
1828 ;; At least numbers are simpler than C.
1829 (list (concat "\\<\\(\\~\\|\\)"
1830 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1832 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1833 "\\([eE]\\(\\~\\|\\)"
1834 "[0-9]+\\|\\)\\)\\)")
1835 '(0 mdw-number-face))
1837 ;; And anything else is punctuation.
1838 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1839 '(0 mdw-punct-face)))))
1841 (mdw-post-config-mode-hack))
1843 ;;;--------------------------------------------------------------------------
1844 ;;; Haskell configuration.
1846 (defun mdw-fontify-haskell ()
1848 ;; Fiddle with syntax table to get comments right.
1849 (modify-syntax-entry ?' "\"")
1850 (modify-syntax-entry ?- ". 123")
1851 (modify-syntax-entry ?{ ". 1b")
1852 (modify-syntax-entry ?} ". 4b")
1853 (modify-syntax-entry ?\n ">")
1856 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1858 ;; Fiddle with fontification.
1859 (make-local-variable 'font-lock-keywords)
1860 (let ((haskell-keywords
1861 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1862 "deriving" "do" "else" "foreign" "hiding" "if"
1863 "import" "in" "infix" "infixl" "infixr" "instance"
1864 "let" "module" "newtype" "of" "qualified" "safe"
1865 "stdcall" "then" "type" "unsafe" "where")))
1867 (setq font-lock-keywords
1870 '(0 font-lock-comment-face))
1871 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1872 '(0 font-lock-keyword-face))
1873 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1874 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1875 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1876 '(0 mdw-number-face))
1877 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1878 '(0 mdw-punct-face)))))
1880 (mdw-post-config-mode-hack))
1882 ;;;--------------------------------------------------------------------------
1883 ;;; Erlang configuration.
1885 (setq erlang-electric-commannds
1886 '(erlang-electric-newline erlang-electric-semicolon))
1888 (defun mdw-fontify-erlang ()
1891 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1893 ;; Fiddle with fontification.
1894 (make-local-variable 'font-lock-keywords)
1895 (let ((erlang-keywords
1896 (mdw-regexps "after" "and" "andalso"
1897 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1898 "case" "catch" "cond"
1899 "div" "end" "fun" "if" "let" "not"
1901 "query" "receive" "rem" "try" "when" "xor")))
1903 (setq font-lock-keywords
1906 '(0 font-lock-comment-face))
1907 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1908 '(0 font-lock-keyword-face))
1909 (list (concat "^-\\sw+\\>")
1910 '(0 font-lock-keyword-face))
1911 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1912 '(0 mdw-number-face))
1913 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1914 '(0 mdw-punct-face)))))
1916 (mdw-post-config-mode-hack))
1918 ;;;--------------------------------------------------------------------------
1919 ;;; Texinfo configuration.
1921 (defun mdw-fontify-texinfo ()
1924 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1926 ;; Real fontification things.
1927 (make-local-variable 'font-lock-keywords)
1928 (setq font-lock-keywords
1931 ;; Environment names are keywords.
1932 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1933 '(2 font-lock-keyword-face))
1935 ;; Unmark escaped magic characters.
1936 (list "\\(@\\)\\([@{}]\\)"
1937 '(1 font-lock-keyword-face)
1938 '(2 font-lock-variable-name-face))
1940 ;; Make sure we get comments properly.
1941 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1942 '(0 font-lock-comment-face))
1944 ;; Command names are keywords.
1945 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1946 '(0 font-lock-keyword-face))
1948 ;; Fontify TeX special characters as punctuation.
1950 '(0 mdw-punct-face))))
1952 (mdw-post-config-mode-hack))
1954 ;;;--------------------------------------------------------------------------
1955 ;;; TeX and LaTeX configuration.
1957 (defun mdw-fontify-tex ()
1958 (setq ispell-parser 'tex)
1961 ;; Don't make maths into a string.
1962 (modify-syntax-entry ?$ ".")
1963 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1964 (local-set-key [?$] 'self-insert-command)
1967 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1969 ;; Real fontification things.
1970 (make-local-variable 'font-lock-keywords)
1971 (setq font-lock-keywords
1974 ;; Environment names are keywords.
1975 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1977 '(2 font-lock-keyword-face))
1979 ;; Suspended environment names are keywords too.
1980 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1982 '(3 font-lock-keyword-face))
1984 ;; Command names are keywords.
1985 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1986 '(0 font-lock-keyword-face))
1988 ;; Handle @/.../ for italics.
1989 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
1990 ;; '(1 font-lock-keyword-face)
1991 ;; '(3 font-lock-keyword-face))
1993 ;; Handle @*...* for boldness.
1994 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
1995 ;; '(1 font-lock-keyword-face)
1996 ;; '(3 font-lock-keyword-face))
1998 ;; Handle @`...' for literal syntax things.
1999 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
2000 ;; '(1 font-lock-keyword-face)
2001 ;; '(3 font-lock-keyword-face))
2003 ;; Handle @<...> for nonterminals.
2004 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
2005 ;; '(1 font-lock-keyword-face)
2006 ;; '(3 font-lock-keyword-face))
2008 ;; Handle other @-commands.
2009 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
2010 ;; '(0 font-lock-keyword-face))
2012 ;; Make sure we get comments properly.
2014 '(0 font-lock-comment-face))
2016 ;; Fontify TeX special characters as punctuation.
2018 '(0 mdw-punct-face))))
2020 (mdw-post-config-mode-hack))
2022 ;;;--------------------------------------------------------------------------
2025 (defun mdw-sgml-mode ()
2028 (mdw-standard-fill-prefix "")
2029 (make-variable-buffer-local 'sgml-delimiters)
2030 (setq sgml-delimiters
2031 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2032 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2033 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2034 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2035 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2036 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2037 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2039 (setq major-mode 'mdw-sgml-mode)
2040 (setq mode-name "[mdw] SGML")
2041 (run-hooks 'mdw-sgml-mode-hook))
2043 ;;;--------------------------------------------------------------------------
2046 (defun mdw-setup-sh-script-mode ()
2048 ;; Fetch the shell interpreter's name.
2049 (let ((shell-name sh-shell-file))
2051 ;; Try reading the hash-bang line.
2053 (goto-char (point-min))
2054 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2055 (setq shell-name (match-string 1))))
2057 ;; Now try to set the shell.
2059 ;; Don't let `sh-set-shell' bugger up my script.
2060 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2061 (sh-set-shell shell-name)))
2063 ;; Now enable my keys and the fontification.
2064 (mdw-misc-mode-config)
2066 ;; Set the indentation level correctly.
2067 (setq sh-indentation 2)
2068 (setq sh-basic-offset 2))
2070 ;;;--------------------------------------------------------------------------
2071 ;;; Emacs shell mode.
2073 (defun mdw-eshell-prompt ()
2074 (let ((left "[") (right "]"))
2075 (when (= (user-uid) 0)
2076 (setq left "«" right "»"))
2079 (replace-regexp-in-string "\\..*$" "" (system-name)))
2083 (setq eshell-prompt-function 'mdw-eshell-prompt)
2084 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
2086 (defalias 'eshell/e 'find-file)
2087 (defalias 'eshell/w3m 'w3m-goto-url)
2089 (mdw-define-face eshell-prompt (t :weight bold))
2090 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2091 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2092 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2093 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2094 (mdw-define-face eshell-ls-executable (t :weight bold))
2095 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2096 (mdw-define-face eshell-ls-readonly (t nil))
2097 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2099 ;;;--------------------------------------------------------------------------
2100 ;;; Messages-file mode.
2102 (defun messages-mode-guts ()
2103 (setq messages-mode-syntax-table (make-syntax-table))
2104 (set-syntax-table messages-mode-syntax-table)
2105 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2106 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2107 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2108 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2109 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2110 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2111 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2112 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2113 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2114 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2115 (make-local-variable 'comment-start)
2116 (make-local-variable 'comment-end)
2117 (make-local-variable 'indent-line-function)
2118 (setq indent-line-function 'indent-relative)
2119 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2120 (make-local-variable 'font-lock-defaults)
2121 (make-local-variable 'messages-mode-keywords)
2123 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2124 "export" "enum" "fixed-octetstring" "flags"
2125 "harmless" "map" "nested" "optional"
2126 "optional-tagged" "package" "primitive"
2127 "primitive-nullfree" "relaxed[ \t]+enum"
2128 "set" "table" "tagged-optional" "union"
2129 "variadic" "vector" "version" "version-tag")))
2130 (setq messages-mode-keywords
2132 (list (concat "\\<\\(" keywords "\\)\\>:")
2133 '(0 font-lock-keyword-face))
2134 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2135 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2136 (0 font-lock-variable-name-face))
2137 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2138 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2139 (0 mdw-punct-face)))))
2140 (setq font-lock-defaults
2141 '(messages-mode-keywords nil nil nil nil))
2142 (run-hooks 'messages-file-hook))
2144 (defun messages-mode ()
2147 (setq major-mode 'messages-mode)
2148 (setq mode-name "Messages")
2149 (messages-mode-guts)
2150 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2151 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2152 (setq comment-start "# ")
2153 (setq comment-end "")
2154 (turn-on-font-lock-if-enabled)
2155 (run-hooks 'messages-mode-hook))
2157 (defun cpp-messages-mode ()
2160 (setq major-mode 'cpp-messages-mode)
2161 (setq mode-name "CPP Messages")
2162 (messages-mode-guts)
2163 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2164 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2165 (setq comment-start "/* ")
2166 (setq comment-end " */")
2167 (let ((preprocessor-keywords
2168 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2169 "ident" "if" "ifdef" "ifndef" "import" "include"
2170 "line" "pragma" "unassert" "undef" "warning")))
2171 (setq messages-mode-keywords
2172 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2173 "\\(include\\|import\\)"
2174 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2175 '(2 font-lock-string-face))
2176 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2177 preprocessor-keywords
2178 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2179 '(1 font-lock-keyword-face)))
2180 messages-mode-keywords)))
2181 (turn-on-font-lock-if-enabled)
2182 (run-hooks 'cpp-messages-mode-hook))
2184 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2185 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2186 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2188 ;;;--------------------------------------------------------------------------
2189 ;;; Messages-file mode.
2191 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2192 "Face to use for subsittution directives.")
2193 (make-face 'mallow-driver-substitution-face)
2194 (defvar mallow-driver-text-face 'mallow-driver-text-face
2195 "Face to use for body text.")
2196 (make-face 'mallow-driver-text-face)
2198 (defun mallow-driver-mode ()
2201 (setq major-mode 'mallow-driver-mode)
2202 (setq mode-name "Mallow driver")
2203 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2204 (set-syntax-table mallow-driver-mode-syntax-table)
2205 (make-local-variable 'comment-start)
2206 (make-local-variable 'comment-end)
2207 (make-local-variable 'indent-line-function)
2208 (setq indent-line-function 'indent-relative)
2209 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2210 (make-local-variable 'font-lock-defaults)
2211 (make-local-variable 'mallow-driver-mode-keywords)
2213 (mdw-regexps "each" "divert" "file" "if"
2214 "perl" "set" "string" "type" "write")))
2215 (setq mallow-driver-mode-keywords
2217 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2218 '(0 font-lock-keyword-face))
2219 (list "^%\\s *\\(#.*\\|\\)$"
2220 '(0 font-lock-comment-face))
2222 '(0 font-lock-keyword-face))
2223 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2225 '(0 mallow-driver-substitution-face t)))))
2226 (setq font-lock-defaults
2227 '(mallow-driver-mode-keywords nil nil nil nil))
2228 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2229 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2230 (setq comment-start "%# ")
2231 (setq comment-end "")
2232 (turn-on-font-lock-if-enabled)
2233 (run-hooks 'mallow-driver-mode-hook))
2235 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2237 ;;;--------------------------------------------------------------------------
2240 (defun nfast-debug-mode ()
2243 (setq major-mode 'nfast-debug-mode)
2244 (setq mode-name "NFast debug")
2245 (setq messages-mode-syntax-table (make-syntax-table))
2246 (set-syntax-table messages-mode-syntax-table)
2247 (make-local-variable 'font-lock-defaults)
2248 (make-local-variable 'nfast-debug-mode-keywords)
2249 (setq truncate-lines t)
2250 (setq nfast-debug-mode-keywords
2252 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2253 (0 font-lock-keyword-face))
2254 (list (concat "^[ \t]+\\(\\("
2255 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2256 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2258 "[0-9a-fA-F]+\\)[ \t]*$")
2259 '(0 mdw-number-face))
2260 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2261 (1 font-lock-keyword-face))
2262 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2263 (1 font-lock-warning-face))
2264 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2266 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2267 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2268 '(1 font-lock-keyword-face))
2269 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2270 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2271 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2272 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2273 (setq font-lock-defaults
2274 '(nfast-debug-mode-keywords nil nil nil nil))
2275 (turn-on-font-lock-if-enabled)
2276 (run-hooks 'nfast-debug-mode-hook))
2278 ;;;--------------------------------------------------------------------------
2279 ;;; Other languages.
2283 (defun mdw-setup-smalltalk ()
2284 (and mdw-auto-indent
2285 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2286 (make-variable-buffer-local 'mdw-auto-indent)
2287 (setq mdw-auto-indent nil)
2288 (local-set-key "\C-i" 'smalltalk-reindent))
2290 (defun mdw-fontify-smalltalk ()
2291 (make-local-variable 'font-lock-keywords)
2292 (setq font-lock-keywords
2294 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2295 '(0 font-lock-keyword-face))
2296 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2297 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2298 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2299 '(0 mdw-number-face))
2300 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2301 '(0 mdw-punct-face))))
2302 (mdw-post-config-mode-hack))
2306 ;; Unpleasant bodge.
2307 (unless (boundp 'slime-repl-mode-map)
2308 (setq slime-repl-mode-map (make-sparse-keymap)))
2310 (defun mdw-indent-newline-and-indent ()
2312 (indent-for-tab-command)
2313 (newline-and-indent))
2315 (eval-after-load "cl-indent"
2317 (mapc #'(lambda (pair)
2319 'common-lisp-indent-function
2321 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2322 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2324 (defun mdw-common-lisp-indent ()
2325 (make-variable-buffer-local 'lisp-indent-function)
2326 (setq lisp-indent-function 'common-lisp-indent-function))
2328 (setq lisp-simple-loop-indentation 2
2329 lisp-loop-keyword-indentation 6
2330 lisp-loop-forms-indentation 6)
2332 (defun mdw-fontify-lispy ()
2335 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2337 ;; Not much fontification needed.
2338 (make-local-variable 'font-lock-keywords)
2339 (setq font-lock-keywords
2341 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2342 '(0 mdw-punct-face))))
2344 (mdw-post-config-mode-hack))
2346 (defun comint-send-and-indent ()
2349 (and mdw-auto-indent
2350 (indent-for-tab-command)))
2352 (defun mdw-setup-m4 ()
2353 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2355 ;;;--------------------------------------------------------------------------
2358 (defun mdw-text-mode ()
2359 (setq fill-column 72)
2361 (mdw-standard-fill-prefix
2362 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2365 ;;;--------------------------------------------------------------------------
2366 ;;; Outline and hide/show modes.
2368 (defun mdw-outline-collapse-all ()
2369 "Completely collapse everything in the entire buffer."
2372 (goto-char (point-min))
2373 (while (< (point) (point-max))
2377 (setq hs-hide-comments-when-hiding-all nil)
2379 (defadvice hs-hide-all (after hide-first-comment activate)
2380 (save-excursion (hs-hide-initial-comment-block)))
2382 ;;;--------------------------------------------------------------------------
2385 (defun mdw-sh-mode-setup ()
2386 (local-set-key [?\C-a] 'comint-bol)
2387 (add-hook 'comint-output-filter-functions
2388 'comint-watch-for-password-prompt))
2390 (defun mdw-term-mode-setup ()
2391 (setq term-prompt-regexp shell-prompt-pattern)
2392 (make-local-variable 'mouse-yank-at-point)
2393 (make-local-variable 'transient-mark-mode)
2394 (setq mouse-yank-at-point t)
2398 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2399 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2400 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2401 (defun term-send-meta-meta-something ()
2403 (term-send-raw-string "\e\e")
2405 (eval-after-load 'term
2407 (define-key term-raw-map [?\e ?\e] nil)
2408 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2409 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2410 (define-key term-raw-map [M-right] 'term-send-meta-right)
2411 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2412 (define-key term-raw-map [M-left] 'term-send-meta-left)
2413 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2415 ;;;--------------------------------------------------------------------------
2416 ;;; Inferior Emacs Lisp.
2418 (setq comint-prompt-read-only t)
2420 (eval-after-load "comint"
2422 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2423 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2425 (eval-after-load "ielm"
2427 (define-key ielm-map "\C-w" 'comint-kill-region)
2428 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2430 ;;;----- That's all, folks --------------------------------------------------
2432 (provide 'dot-emacs)