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-horizontal-window-overhead ()
141 "Computes the horizontal window overhead.
142 This is the number of columns used by fringes, scroll bars and other such
144 (if (not window-system)
147 (dolist (what '(scroll-bar fringe))
148 (dolist (side '(left right))
149 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
153 (defun mdw-split-window-horizontally (&optional width)
154 "Split a window horizontally.
155 Without a numeric argument, split the window approximately in
156 half. With a numeric argument WIDTH, allocate WIDTH columns to
157 the left-hand window (if positive) or -WIDTH columns to the
158 right-hand window (if negative). Space for scroll bars and
159 fringes is not taken out of the allowance for WIDTH, unlike
160 \\[split-window-horizontally]."
162 (split-window-horizontally
163 (cond ((null width) nil)
164 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
165 ((< width 0) width))))
167 (defun mdw-divvy-window (&optional width)
168 "Split a wide window into appropriate widths."
170 (setq width (cond (width (prefix-numeric-value width))
172 (>= emacs-major-version 22))
175 (let* ((win (selected-window))
176 (sb-width (mdw-horizontal-window-overhead))
177 (c (/ (+ (window-width) sb-width)
178 (+ width sb-width))))
181 (split-window-horizontally (+ width sb-width))
183 (select-window win)))
185 ;; Transient mark mode hacks.
187 (defadvice exchange-point-and-mark
188 (around mdw-highlight (&optional arg) activate compile)
189 "Maybe don't actually exchange point and mark.
190 If `transient-mark-mode' is on and the mark is inactive, then
191 just activate it. A non-trivial prefix argument will force the
192 usual behaviour. A trivial prefix argument (i.e., just C-u) will
193 activate the mark and temporarily enable `transient-mark-mode' if
195 (cond ((or mark-active
196 (and (not transient-mark-mode) (not arg))
197 (and arg (or (not (consp arg))
198 (not (= (car arg) 4)))))
201 (or transient-mark-mode (setq transient-mark-mode 'only))
202 (set-mark (mark t)))))
204 ;; Functions for sexp diary entries.
206 (defun mdw-weekday (l)
207 "Return non-nil if `date' falls on one of the days of the week in L.
208 L is a list of day numbers (from 0 to 6 for Sunday through to
209 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
210 the date stored in `date' falls on a listed day, then the
211 function returns non-nil."
212 (let ((d (calendar-day-of-week date)))
214 (memq (nth d '(sunday monday tuesday wednesday
215 thursday friday saturday)) l))))
217 (defun mdw-todo (&optional when)
218 "Return non-nil today, or on WHEN, whichever is later."
219 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
220 (d (calendar-absolute-from-gregorian date)))
222 (setq w (max w (calendar-absolute-from-gregorian
224 ((not european-calendar-style)
236 ;; Fighting with Org-mode's evil key maps.
238 (defvar mdw-evil-keymap-keys
239 '(([S-up] . [?\C-c up])
240 ([S-down] . [?\C-c down])
241 ([S-left] . [?\C-c left])
242 ([S-right] . [?\C-c right])
243 (([M-up] [?\e up]) . [C-up])
244 (([M-down] [?\e down]) . [C-down])
245 (([M-left] [?\e left]) . [C-left])
246 (([M-right] [?\e right]) . [C-right]))
247 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
248 The value is an alist mapping evil keys (as a list, or singleton)
249 to good keys (in the same form).")
251 (defun mdw-clobber-evil-keymap (keymap)
252 "Replace evil key bindings in the KEYMAP.
253 Evil key bindings are defined in `mdw-evil-keymap-keys'."
254 (dolist (entry mdw-evil-keymap-keys)
256 (keys (if (listp (car entry))
259 (replacements (if (listp (cdr entry))
261 (list (cdr entry)))))
264 (setq binding (lookup-key keymap key))
266 (throw 'found nil))))
269 (define-key keymap key nil))
270 (dolist (key replacements)
271 (define-key keymap key binding))))))
273 (eval-after-load "org-latex"
276 "\\documentclass{strayman}
277 \\usepackage[utf8]{inputenc}
278 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
279 \\usepackage[T1]{fontenc}
280 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
281 ("\\section{%s}" . "\\section*{%s}")
282 ("\\subsection{%s}" . "\\subsection*{%s}")
283 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
284 ("\\paragraph{%s}" . "\\paragraph*{%s}")
285 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
286 org-export-latex-classes)))
288 ;;;--------------------------------------------------------------------------
289 ;;; Mail and news hacking.
291 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
292 "Major mode for editing news and mail messages from external programs.
293 Not much right now. Just support for doing MailCrypt stuff."
296 (run-hooks 'mail-setup-hook))
298 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
300 (add-hook 'mdwail-mode-hook
302 (set-buffer-file-coding-system 'utf-8)
303 (make-local-variable 'paragraph-separate)
304 (make-local-variable 'paragraph-start)
305 (setq paragraph-start
306 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
308 (setq paragraph-separate
309 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
310 paragraph-separate))))
312 ;; How to encrypt in mdwmail.
314 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
316 (setq start (save-excursion
317 (goto-char (point-min))
318 (or (search-forward "\n\n" nil t) (point-min)))))
320 (setq end (point-max)))
321 (mc-encrypt-generic recip scm start end from sign))
323 ;; How to sign in mdwmail.
325 (defun mdwmail-mc-sign (key scm start end uclr)
327 (setq start (save-excursion
328 (goto-char (point-min))
329 (or (search-forward "\n\n" nil t) (point-min)))))
331 (setq end (point-max)))
332 (mc-sign-generic key scm start end uclr))
334 ;; Some signature mangling.
336 (defun mdwmail-mangle-signature ()
338 (goto-char (point-min))
339 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
340 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
341 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
343 ;; Insert my login name into message-ids, so I can score replies.
345 (defadvice message-unique-id (after mdw-user-name last activate compile)
346 "Ensure that the user's name appears at the end of the message-id string,
347 so that it can be used for convenient filtering."
348 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
350 ;; Tell my movemail hack where movemail is.
352 ;; This is needed to shup up warnings about LD_PRELOAD.
354 (let ((path exec-path))
356 (let ((try (expand-file-name "movemail" (car path))))
357 (if (file-executable-p try)
358 (setenv "REAL_MOVEMAIL" try))
359 (setq path (cdr path)))))
361 ;;;--------------------------------------------------------------------------
362 ;;; Utility functions.
364 (or (fboundp 'line-number-at-pos)
365 (defun line-number-at-pos (&optional pos)
366 (let ((opoint (or pos (point))) start)
369 (goto-char (point-min))
375 (1+ (count-lines 1 (point))))))))
377 (defun mdw-uniquify-alist (&rest alists)
378 "Return the concatenation of the ALISTS with duplicate elements removed.
379 The first association with a given key prevails; others are
380 ignored. The input lists are not modified, although they'll
381 probably become garbage."
383 (let ((start-list (cons nil nil)))
384 (mdw-do-uniquify start-list
389 (defun mdw-do-uniquify (done end l rest)
390 "A helper function for mdw-uniquify-alist.
391 The DONE argument is a list whose first element is `nil'. It
392 contains the uniquified alist built so far. The leading `nil' is
393 stripped off at the end of the operation; it's only there so that
394 DONE always references a cons cell. END refers to the final cons
395 cell in the DONE list; it is modified in place each time to avoid
396 the overheads of `append'ing all the time. The L argument is the
397 alist we're currently processing; the remaining alists are given
400 ;; There are several different cases to deal with here.
403 ;; Current list isn't empty. Add the first item to the DONE list if
404 ;; there's not an item with the same KEY already there.
405 (l (or (assoc (car (car l)) done)
407 (setcdr end (cons (car l) nil))
408 (setq end (cdr end))))
409 (mdw-do-uniquify done end (cdr l) rest))
411 ;; The list we were working on is empty. Shunt the next list into the
412 ;; current list position and go round again.
413 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
415 ;; Everything's done. Remove the leading `nil' from the DONE list and
416 ;; return it. Finished!
420 "Insert the current date in a pleasing way."
422 (insert (save-excursion
423 (let ((buffer (get-buffer-create "*tmp*")))
424 (unwind-protect (progn (set-buffer buffer)
426 (shell-command "date +%Y-%m-%d" t)
428 (delete-backward-char 1)
430 (kill-buffer buffer))))))
432 (defun uuencode (file &optional name)
433 "UUencodes a file, maybe calling it NAME, into the current buffer."
434 (interactive "fInput file name: ")
436 ;; If NAME isn't specified, then guess from the filename.
440 (or (string-match "[^/]*$" file) 0))))
441 (print (format "uuencode `%s' `%s'" file name))
443 ;; Now actually do the thing.
444 (call-process "uuencode" file t nil name))
446 (defvar np-file "~/.np"
447 "*Where the `now-playing' file is.")
449 (defun np (&optional arg)
450 "Grabs a `now-playing' string."
454 (goto-char (point-max))
456 (insert-file-contents np-file)))))
458 (defun mdw-version-< (ver-a ver-b)
459 "Answer whether VER-A is strictly earlier than VER-B.
460 VER-A and VER-B are version numbers, which are strings containing digit
461 sequences separated by `.'."
462 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
463 (split-string ver-a "\\.")))
464 (lb (mapcar (lambda (x) (car (read-from-string x)))
465 (split-string ver-b "\\."))))
468 (cond ((null la) (throw 'done lb))
469 ((null lb) (throw 'done nil))
470 ((< (car la) (car lb)) (throw 'done t))
471 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb))))))))
473 (defun mdw-check-autorevert ()
474 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
475 This takes into consideration whether it's been found using
476 tramp, which seems to get itself into a twist."
477 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
479 ((and (buffer-file-name)
480 (fboundp 'tramp-tramp-file-p)
481 (tramp-tramp-file-p (buffer-file-name)))
482 (unless global-auto-revert-ignore-buffer
483 (setq global-auto-revert-ignore-buffer 'tramp)))
484 ((eq global-auto-revert-ignore-buffer 'tramp)
485 (setq global-auto-revert-ignore-buffer nil))))
487 (defadvice find-file (after mdw-autorevert activate)
488 (mdw-check-autorevert))
489 (defadvice write-file (after mdw-autorevert activate)
490 (mdw-check-autorevert))
492 ;;;--------------------------------------------------------------------------
495 (defadvice dired-maybe-insert-subdir
496 (around mdw-marked-insertion first activate)
497 "The DIRNAME may be a list of directory names to insert.
498 Interactively, if files are marked, then insert all of them.
499 With a numeric prefix argument, select that many entries near
500 point; with a non-numeric prefix argument, prompt for listing
503 (list (dired-get-marked-files nil
504 (and (integerp current-prefix-arg)
507 (and current-prefix-arg
508 (not (integerp current-prefix-arg))
509 (read-string "Switches for listing: "
510 (or dired-subdir-switches
511 dired-actual-switches)))))
512 (let ((dirs (ad-get-arg 0)))
513 (dolist (dir (if (listp dirs) dirs (list dirs)))
517 ;;;--------------------------------------------------------------------------
520 (defun mdw-w3m-browse-url (url &optional new-session-p)
521 "Invoke w3m on the URL in its current window, or at least a different one.
522 If NEW-SESSION-P, start a new session."
523 (interactive "sURL: \nP")
525 (let ((window (selected-window)))
528 (select-window (or (and (not new-session-p)
529 (get-buffer-window "*w3m*"))
531 (if (one-window-p t) (split-window))
533 (w3m-browse-url url new-session-p))
534 (select-window window)))))
536 (defvar mdw-good-url-browsers
538 (w3m . mdw-w3m-browse-url)
541 "List of good browsers for mdw-good-url-browsers.
542 Each item is a browser function name, or a cons (CHECK . FUNC).
543 A symbol FOO stands for (FOO . FOO).")
545 (defun mdw-good-url-browser ()
546 "Return a good URL browser.
547 Trundle the list of such things, finding the first item for which
548 CHECK is fboundp, and returning the correponding FUNC."
549 (let ((bs mdw-good-url-browsers) b check func answer)
550 (while (and bs (not answer))
554 (setq check (car b) func (cdr b))
555 (setq check b func b))
560 (eval-after-load "w3m-search"
564 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
565 ("gd" "Google Directory"
566 "http://www.google.com/search?cat=gwd/Top&q=%s")
567 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
568 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
569 ("gi" "Images" "http://images.google.com/images?q=%s")
571 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
573 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
574 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
575 ("nc-wiki" "nCipher wiki"
576 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
577 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
578 ("lp" "Launchpad bug by number"
579 "https://bugs.launchpad.net/bugs/%s")
580 ("lppkg" "Launchpad bugs by package"
581 "https://bugs.launchpad.net/%s")
583 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
584 ("debbug" "Debian bug by number"
585 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
586 ("debbugpkg" "Debian bugs by package"
587 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
588 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
589 (add-to-list 'w3m-search-engine-alist
590 (list (cadr item) (caddr item) nil))
591 (add-to-list 'w3m-uri-replace-alist
592 (list (concat "\\`" (car item) ":")
593 'w3m-search-uri-replace
596 ;;;--------------------------------------------------------------------------
597 ;;; Paragraph filling.
601 (defvar mdw-fill-prefix nil
602 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
603 If there's no fill prefix currently set (by the `fill-prefix'
604 variable) and there's a match from one of the regexps here, it
605 gets used to set the fill-prefix for the current operation.
607 The variable is a list of items of the form `REGEXP . PREFIX'; if
608 the REGEXP matches, the PREFIX is used to set the fill prefix.
609 It in turn is a list of things:
611 STRING -- insert a literal string
612 (match . N) -- insert the thing matched by bracketed subexpression N
613 (pad . N) -- a string of whitespace the same width as subexpression N
614 (expr . FORM) -- the result of evaluating FORM")
616 (make-variable-buffer-local 'mdw-fill-prefix)
618 (defvar mdw-hanging-indents
620 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
623 "*Standard regexp matching parts of a hanging indent.
624 This is mainly useful in `auto-fill-mode'.")
626 ;; Setting things up.
628 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
630 ;; Utility functions.
632 (defun mdw-tabify (s)
633 "Tabify the string S. This is a horrid hack."
638 (setq start (point-marker))
640 (setq end (point-marker))
642 (setq s (buffer-substring start (1- end)))
643 (delete-region start end)
644 (set-marker start nil)
648 (defun mdw-examine-fill-prefixes (l)
649 "Given a list of dynamic fill prefixes, pick one which matches
650 context and return the static fill prefix to use. Point must be
651 at the start of a line, and match data must be saved."
653 ((looking-at (car (car l)))
654 (mdw-tabify (apply (function concat)
655 (mapcar (function mdw-do-prefix-match)
657 (t (mdw-examine-fill-prefixes (cdr l)))))
659 (defun mdw-maybe-car (p)
660 "If P is a pair, return (car P), otherwise just return P."
661 (if (consp p) (car p) p))
663 (defun mdw-padding (s)
664 "Return a string the same width as S but made entirely from whitespace."
665 (let* ((l (length s)) (i 0) (n (make-string l ? )))
672 (defun mdw-do-prefix-match (m)
673 "Expand a dynamic prefix match element.
674 See `mdw-fill-prefix' for details."
675 (cond ((not (consp m)) (format "%s" m))
676 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
677 ((eq (car m) 'pad) (mdw-padding (match-string
678 (mdw-maybe-car (cdr m)))))
679 ((eq (car m) 'eval) (eval (cdr m)))
682 (defun mdw-choose-dynamic-fill-prefix ()
683 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
684 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
685 ((not mdw-fill-prefix) fill-prefix)
689 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
691 (defun do-auto-fill ()
692 "Handle auto-filling, working out a dynamic fill prefix in the
693 case where there isn't a sensible static one."
694 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
697 (defun mdw-fill-paragraph ()
698 "Fill paragraph, getting a dynamic fill prefix."
700 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
701 (fill-paragraph nil)))
703 (defun mdw-standard-fill-prefix (rx &optional mat)
704 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
705 This is just a short-cut for setting the thing by hand, and by
706 design it doesn't cope with anything approximating a complicated
708 (setq mdw-fill-prefix
709 `((,(concat rx mdw-hanging-indents)
711 (pad . ,(or mat 2))))))
713 ;;;--------------------------------------------------------------------------
714 ;;; Other common declarations.
716 ;; Common mode settings.
718 (defvar mdw-auto-indent t
719 "Whether to indent automatically after a newline.")
721 (defun mdw-whitespace-mode (&optional arg)
722 "Turn on/off whitespace mode, but don't highlight trailing space."
724 (when (and (boundp 'whitespace-style)
725 (fboundp 'whitespace-mode))
726 (let ((whitespace-style (remove 'trailing whitespace-style)))
727 (whitespace-mode arg))
728 (setq show-trailing-whitespace whitespace-mode)))
730 (defun mdw-misc-mode-config ()
732 (cond ((eq major-mode 'lisp-mode)
733 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
734 ((or (eq major-mode 'slime-repl-mode)
735 (eq major-mode 'asm-mode))
738 (local-set-key "\C-m" 'newline-and-indent))))
739 (local-set-key [C-return] 'newline)
740 (make-local-variable 'page-delimiter)
741 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
742 (setq comment-column 40)
744 (setq fill-column 77)
745 (setq show-trailing-whitespace t)
746 (mdw-whitespace-mode 1)
747 (and (fboundp 'gtags-mode)
749 (outline-minor-mode t)
752 (trap (turn-on-font-lock)))
754 (defun mdw-post-config-mode-hack ()
755 (mdw-whitespace-mode 1))
757 (eval-after-load 'gtags
759 (dolist (key '([mouse-2] [mouse-3]))
760 (define-key gtags-mode-map key nil))
761 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
762 (define-key gtags-select-mode-map [C-S-mouse-2]
763 'gtags-select-tag-by-event)
764 (dolist (map (list gtags-mode-map gtags-select-mode-map))
765 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
767 ;; Backup file handling.
769 (defvar mdw-backup-disable-regexps nil
770 "*List of regular expressions: if a file name matches any of
771 these then the file is not backed up.")
773 (defun mdw-backup-enable-predicate (name)
774 "[mdw]'s default backup predicate.
775 Allows a backup if the standard predicate would allow it, and it
776 doesn't match any of the regular expressions in
777 `mdw-backup-disable-regexps'."
778 (and (normal-backup-enable-predicate name)
779 (let ((answer t) (list mdw-backup-disable-regexps))
782 (if (string-match (car list) name)
784 (setq list (cdr list)))
786 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
790 (defun mdw-last-one-out-turn-off-the-lights (frame)
791 "Disconnect from an X display if this was the last frame on that display."
792 (let ((frame-display (frame-parameter frame 'display)))
793 (when (and frame-display
794 (eq window-system 'x)
795 (not (some (lambda (fr)
796 (and (not (eq fr frame))
797 (string= (frame-parameter fr 'display)
800 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
801 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
803 ;;;--------------------------------------------------------------------------
804 ;;; General fontification.
806 (defmacro mdw-define-face (name &rest body)
807 "Define a face, and make sure it's actually set as the definition."
812 (defvar ,name ',name)
813 (put ',name 'face-defface-spec ',body)
814 (face-spec-set ',name ',body nil)))
816 (mdw-define-face default
817 (((type w32)) :family "courier new" :height 85)
818 (((type x)) :family "6x13" :height 130)
819 (((type color)) :foreground "white" :background "black")
821 (mdw-define-face fixed-pitch
822 (((type w32)) :family "courier new" :height 85)
823 (((type x)) :family "6x13" :height 130)
824 (t :foreground "white" :background "black"))
825 (if (>= emacs-major-version 23)
826 (mdw-define-face variable-pitch
827 (((type x)) :family "sans" :height 100))
828 (mdw-define-face variable-pitch
829 (((type x)) :family "helvetica" :height 90)))
830 (mdw-define-face region
831 (((type tty) (class color)) :background "blue")
832 (((type tty) (class mono)) :inverse-video t)
833 (t :background "grey30"))
834 (mdw-define-face minibuffer-prompt
836 (mdw-define-face mode-line
837 (((class color)) :foreground "blue" :background "yellow"
838 :box (:line-width 1 :style released-button))
839 (t :inverse-video t))
840 (mdw-define-face mode-line-inactive
841 (((class color)) :foreground "yellow" :background "blue"
842 :box (:line-width 1 :style released-button))
843 (t :inverse-video t))
844 (mdw-define-face scroll-bar
845 (t :foreground "black" :background "lightgrey"))
846 (mdw-define-face fringe
847 (t :foreground "yellow"))
848 (mdw-define-face show-paren-match
849 (((class color)) :background "darkgreen")
851 (mdw-define-face show-paren-mismatch
852 (((class color)) :background "red")
853 (t :inverse-video t))
854 (mdw-define-face highlight
855 (((class color)) :background "DarkSeaGreen4")
856 (t :inverse-video t))
858 (mdw-define-face holiday-face
859 (t :background "red"))
860 (mdw-define-face calendar-today-face
861 (t :foreground "yellow" :weight bold))
863 (mdw-define-face comint-highlight-prompt
865 (mdw-define-face comint-highlight-input
868 (mdw-define-face trailing-whitespace
869 (((class color)) :background "red")
870 (t :inverse-video t))
871 (mdw-define-face mdw-punct-face
872 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
873 (mdw-define-face mdw-number-face
874 (t :foreground "yellow"))
875 (mdw-define-face font-lock-function-name-face
877 (mdw-define-face font-lock-keyword-face
879 (mdw-define-face font-lock-constant-face
881 (mdw-define-face font-lock-builtin-face
883 (mdw-define-face font-lock-type-face
884 (t :weight bold :slant italic))
885 (mdw-define-face font-lock-reference-face
887 (mdw-define-face font-lock-variable-name-face
889 (mdw-define-face font-lock-comment-delimiter-face
890 (((class mono)) :weight bold)
891 (((type tty) (class color)) :foreground "green")
892 (t :slant italic :foreground "SeaGreen1"))
893 (mdw-define-face font-lock-comment-face
894 (((class mono)) :weight bold)
895 (((type tty) (class color)) :foreground "green")
896 (t :slant italic :foreground "SeaGreen1"))
897 (mdw-define-face font-lock-string-face
898 (((class mono)) :weight bold)
899 (((class color)) :foreground "SkyBlue1"))
900 (mdw-define-face message-separator
901 (t :background "red" :foreground "white" :weight bold))
902 (mdw-define-face message-cited-text
903 (default :slant italic)
904 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
905 (mdw-define-face message-header-cc
906 (default :weight bold)
907 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
908 (mdw-define-face message-header-newsgroups
909 (default :weight bold)
910 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
911 (mdw-define-face message-header-subject
912 (default :weight bold)
913 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
914 (mdw-define-face message-header-to
915 (default :weight bold)
916 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
917 (mdw-define-face message-header-xheader
918 (default :weight bold)
919 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
920 (mdw-define-face message-header-other
921 (default :weight bold)
922 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
923 (mdw-define-face message-header-name
924 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
926 (mdw-define-face diff-index
928 (mdw-define-face diff-file-header
930 (mdw-define-face diff-hunk-header
931 (t :foreground "SkyBlue1"))
932 (mdw-define-face diff-function
933 (t :foreground "SkyBlue1" :weight bold))
934 (mdw-define-face diff-header
935 (t :background "grey10"))
936 (mdw-define-face diff-added
937 (t :foreground "green"))
938 (mdw-define-face diff-removed
939 (t :foreground "red"))
940 (mdw-define-face diff-context
943 (mdw-define-face erc-input-face
944 (t :foreground "red"))
946 (mdw-define-face woman-bold
948 (mdw-define-face woman-italic
951 (mdw-define-face p4-depot-added-face
952 (t :foreground "green"))
953 (mdw-define-face p4-depot-branch-op-face
954 (t :foreground "yellow"))
955 (mdw-define-face p4-depot-deleted-face
956 (t :foreground "red"))
957 (mdw-define-face p4-depot-unmapped-face
958 (t :foreground "SkyBlue1"))
959 (mdw-define-face p4-diff-change-face
960 (t :foreground "yellow"))
961 (mdw-define-face p4-diff-del-face
962 (t :foreground "red"))
963 (mdw-define-face p4-diff-file-face
964 (t :foreground "SkyBlue1"))
965 (mdw-define-face p4-diff-head-face
966 (t :background "grey10"))
967 (mdw-define-face p4-diff-ins-face
968 (t :foreground "green"))
970 (mdw-define-face whizzy-slice-face
971 (t :background "grey10"))
972 (mdw-define-face whizzy-error-face
973 (t :background "darkred"))
975 ;;;--------------------------------------------------------------------------
976 ;;; C programming configuration.
978 ;; Linux kernel hacking.
980 (defvar linux-c-mode-hook)
982 (defun linux-c-mode ()
985 (setq major-mode 'linux-c-mode)
986 (setq mode-name "Linux C")
987 (run-hooks 'linux-c-mode-hook))
989 ;; Make C indentation nice.
991 (defun mdw-c-lineup-arglist (langelem)
992 "Hack for DWIMmery in c-lineup-arglist."
994 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
996 (c-lineup-arglist langelem)))
998 (defun mdw-c-indent-extern-mumble (langelem)
999 "Indent `extern \"...\" {' lines."
1001 (back-to-indentation)
1003 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1007 (defun mdw-c-style ()
1008 (c-add-style "[mdw] C and C++ style"
1009 '((c-basic-offset . 2)
1010 (comment-column . 40)
1011 (c-class-key . "class")
1012 (c-backslash-column . 72)
1014 (substatement-open . (add 0 c-indent-one-line-block))
1015 (defun-open . (add 0 c-indent-one-line-block))
1016 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1017 (topmost-intro . mdw-c-indent-extern-mumble)
1018 (cpp-define-intro . 0)
1019 (inextern-lang . [0])
1025 (statement-cont . 0)
1026 (statement-case-intro . +)))
1029 (defvar mdw-c-comment-fill-prefix
1030 `((,(concat "\\([ \t]*/?\\)"
1033 "\\([A-Za-z]+:[ \t]*\\)?"
1034 mdw-hanging-indents)
1035 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1036 "Fill prefix matching C comments (both kinds).")
1038 (defun mdw-fontify-c-and-c++ ()
1040 ;; Fiddle with some syntax codes.
1041 (modify-syntax-entry ?* ". 23")
1042 (modify-syntax-entry ?/ ". 124b")
1043 (modify-syntax-entry ?\n "> b")
1047 (setq c-hanging-comment-ender-p nil)
1048 (setq c-backslash-column 72)
1049 (setq c-label-minimum-indentation 0)
1050 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1052 ;; Now define things to be fontified.
1053 (make-local-variable 'font-lock-keywords)
1055 (mdw-regexps "and" ;C++
1061 "bool" ;C++, C9X macro
1067 "complex" ;C9X macro, C++ template type
1071 "continue" ;K&R, C89
1072 "defined" ;C89 preprocessor
1079 ;; "entry" ;K&R -- never used
1084 "false" ;C++, C9X macro
1091 "imaginary" ;C9X macro
1092 "inline" ;C++, C9X, GCC
1104 "register" ;K&R, C89
1105 "reinterpret_cast" ;C++
1118 "true" ;C++, C9X macro
1126 "unsigned" ;K&R, C89
1131 "wchar_t" ;C++, C89 library type
1138 "_Pragma" ;C9X preprocessor
1141 "__attribute__" ;GCC
1144 "__extension__" ;GCC
1153 (preprocessor-keywords
1154 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1155 "ident" "if" "ifdef" "ifndef" "import" "include"
1156 "line" "pragma" "unassert" "undef" "warning"))
1158 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1159 "interface" "private" "protected" "protocol" "public"
1162 (setq font-lock-keywords
1165 ;; Fontify include files as strings.
1166 (list (concat "^[ \t]*\\#[ \t]*"
1167 "\\(include\\|import\\)"
1168 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1169 '(2 font-lock-string-face))
1171 ;; Preprocessor directives are `references'?.
1172 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1173 preprocessor-keywords
1174 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1175 '(1 font-lock-keyword-face))
1177 ;; Handle the keywords defined above.
1178 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1179 '(0 font-lock-keyword-face))
1181 (list (concat "\\<\\(" c-keywords "\\)\\>")
1182 '(0 font-lock-keyword-face))
1184 ;; Handle numbers too.
1186 ;; This looks strange, I know. It corresponds to the
1187 ;; preprocessor's idea of what a number looks like, rather than
1188 ;; anything sensible.
1189 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1190 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1191 '(0 mdw-number-face))
1193 ;; And anything else is punctuation.
1194 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1195 '(0 mdw-punct-face))))
1197 (mdw-post-config-mode-hack)))
1199 ;;;--------------------------------------------------------------------------
1202 (defun apcalc-mode ()
1205 (setq major-mode 'apcalc-mode)
1206 (setq mode-name "AP Calc")
1207 (run-hooks 'apcalc-mode-hook))
1209 (defun mdw-fontify-apcalc ()
1211 ;; Fiddle with some syntax codes.
1212 (modify-syntax-entry ?* ". 23")
1213 (modify-syntax-entry ?/ ". 14")
1217 (setq c-hanging-comment-ender-p nil)
1218 (setq c-backslash-column 72)
1219 (setq comment-start "/* ")
1220 (setq comment-end " */")
1221 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1223 ;; Now define things to be fontified.
1224 (make-local-variable 'font-lock-keywords)
1226 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1227 "do" "else" "exit" "for" "global" "goto" "help" "if"
1228 "local" "mat" "obj" "print" "quit" "read" "return"
1229 "show" "static" "switch" "while" "write")))
1231 (setq font-lock-keywords
1234 ;; Handle the keywords defined above.
1235 (list (concat "\\<\\(" c-keywords "\\)\\>")
1236 '(0 font-lock-keyword-face))
1238 ;; Handle numbers too.
1240 ;; This looks strange, I know. It corresponds to the
1241 ;; preprocessor's idea of what a number looks like, rather than
1242 ;; anything sensible.
1243 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1244 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1245 '(0 mdw-number-face))
1247 ;; And anything else is punctuation.
1248 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1249 '(0 mdw-punct-face)))))
1251 (mdw-post-config-mode-hack))
1253 ;;;--------------------------------------------------------------------------
1254 ;;; Java programming configuration.
1256 ;; Make indentation nice.
1258 (defun mdw-java-style ()
1259 (c-add-style "[mdw] Java style"
1260 '((c-basic-offset . 2)
1261 (c-offsets-alist (substatement-open . 0)
1266 (statement-case-intro . +)))
1269 ;; Declare Java fontification style.
1271 (defun mdw-fontify-java ()
1275 (setq c-hanging-comment-ender-p nil)
1276 (setq c-backslash-column 72)
1277 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1279 ;; Now define things to be fontified.
1280 (make-local-variable 'font-lock-keywords)
1281 (let ((java-keywords
1282 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1283 "char" "class" "const" "continue" "default" "do"
1284 "double" "else" "extends" "final" "finally" "float"
1285 "for" "goto" "if" "implements" "import" "instanceof"
1286 "int" "interface" "long" "native" "new" "package"
1287 "private" "protected" "public" "return" "short"
1288 "static" "super" "switch" "synchronized" "this"
1289 "throw" "throws" "transient" "try" "void" "volatile"
1292 "false" "null" "true")))
1294 (setq font-lock-keywords
1297 ;; Handle the keywords defined above.
1298 (list (concat "\\<\\(" java-keywords "\\)\\>")
1299 '(0 font-lock-keyword-face))
1301 ;; Handle numbers too.
1303 ;; The following isn't quite right, but it's close enough.
1304 (list (concat "\\<\\("
1305 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1306 "[0-9]+\\(\\.[0-9]*\\|\\)"
1307 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1309 '(0 mdw-number-face))
1311 ;; And anything else is punctuation.
1312 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1313 '(0 mdw-punct-face)))))
1315 (mdw-post-config-mode-hack))
1317 ;;;--------------------------------------------------------------------------
1318 ;;; C# programming configuration.
1320 ;; Make indentation nice.
1322 (defun mdw-csharp-style ()
1323 (c-add-style "[mdw] C# style"
1324 '((c-basic-offset . 2)
1325 (c-offsets-alist (substatement-open . 0)
1330 (statement-case-intro . +)))
1333 ;; Declare C# fontification style.
1335 (defun mdw-fontify-csharp ()
1339 (setq c-hanging-comment-ender-p nil)
1340 (setq c-backslash-column 72)
1341 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1343 ;; Now define things to be fontified.
1344 (make-local-variable 'font-lock-keywords)
1345 (let ((csharp-keywords
1346 (mdw-regexps "abstract" "as" "base" "bool" "break"
1347 "byte" "case" "catch" "char" "checked"
1348 "class" "const" "continue" "decimal" "default"
1349 "delegate" "do" "double" "else" "enum"
1350 "event" "explicit" "extern" "false" "finally"
1351 "fixed" "float" "for" "foreach" "goto"
1352 "if" "implicit" "in" "int" "interface"
1353 "internal" "is" "lock" "long" "namespace"
1354 "new" "null" "object" "operator" "out"
1355 "override" "params" "private" "protected" "public"
1356 "readonly" "ref" "return" "sbyte" "sealed"
1357 "short" "sizeof" "stackalloc" "static" "string"
1358 "struct" "switch" "this" "throw" "true"
1359 "try" "typeof" "uint" "ulong" "unchecked"
1360 "unsafe" "ushort" "using" "virtual" "void"
1361 "volatile" "while" "yield")))
1363 (setq font-lock-keywords
1366 ;; Handle the keywords defined above.
1367 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1368 '(0 font-lock-keyword-face))
1370 ;; Handle numbers too.
1372 ;; The following isn't quite right, but it's close enough.
1373 (list (concat "\\<\\("
1374 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1375 "[0-9]+\\(\\.[0-9]*\\|\\)"
1376 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1378 '(0 mdw-number-face))
1380 ;; And anything else is punctuation.
1381 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1382 '(0 mdw-punct-face)))))
1384 (mdw-post-config-mode-hack))
1386 (define-derived-mode csharp-mode java-mode "C#"
1387 "Major mode for editing C# code.")
1389 ;;;--------------------------------------------------------------------------
1390 ;;; Go programming configuration.
1392 (defun mdw-fontify-go ()
1394 (make-local-variable 'font-lock-keywords)
1396 (mdw-regexps "break" "case" "chan" "const" "continue"
1397 "default" "defer" "else" "fallthrough" "for"
1398 "func" "go" "goto" "if" "import"
1399 "interface" "map" "package" "range" "return"
1400 "select" "struct" "switch" "type" "var")))
1402 (setq font-lock-keywords
1405 ;; Handle the keywords defined above.
1406 (list (concat "\\<\\(" go-keywords "\\)\\>")
1407 '(0 font-lock-keyword-face))
1409 ;; Handle numbers too.
1411 ;; The following isn't quite right, but it's close enough.
1412 (list (concat "\\<\\("
1413 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1414 "[0-9]+\\(\\.[0-9]*\\|\\)"
1415 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1416 '(0 mdw-number-face))
1418 ;; And anything else is punctuation.
1419 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1420 '(0 mdw-punct-face)))))
1422 (mdw-post-config-mode-hack))
1424 ;;;--------------------------------------------------------------------------
1425 ;;; Awk programming configuration.
1427 ;; Make Awk indentation nice.
1429 (defun mdw-awk-style ()
1430 (c-add-style "[mdw] Awk style"
1431 '((c-basic-offset . 2)
1432 (c-offsets-alist (substatement-open . 0)
1433 (statement-cont . 0)
1434 (statement-case-intro . +)))
1437 ;; Declare Awk fontification style.
1439 (defun mdw-fontify-awk ()
1441 ;; Miscellaneous fiddling.
1443 (setq c-backslash-column 72)
1444 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1446 ;; Now define things to be fontified.
1447 (make-local-variable 'font-lock-keywords)
1449 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1450 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1451 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1452 "RSTART" "RLENGTH" "RT" "SUBSEP"
1453 "atan2" "break" "close" "continue" "cos" "delete"
1454 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1455 "function" "gensub" "getline" "gsub" "if" "in"
1456 "index" "int" "length" "log" "match" "next" "rand"
1457 "return" "print" "printf" "sin" "split" "sprintf"
1458 "sqrt" "srand" "strftime" "sub" "substr" "system"
1459 "systime" "tolower" "toupper" "while")))
1461 (setq font-lock-keywords
1464 ;; Handle the keywords defined above.
1465 (list (concat "\\<\\(" c-keywords "\\)\\>")
1466 '(0 font-lock-keyword-face))
1468 ;; Handle numbers too.
1470 ;; The following isn't quite right, but it's close enough.
1471 (list (concat "\\<\\("
1472 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1473 "[0-9]+\\(\\.[0-9]*\\|\\)"
1474 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1476 '(0 mdw-number-face))
1478 ;; And anything else is punctuation.
1479 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1480 '(0 mdw-punct-face)))))
1482 (mdw-post-config-mode-hack))
1484 ;;;--------------------------------------------------------------------------
1485 ;;; Perl programming style.
1487 ;; Perl indentation style.
1489 (setq cperl-indent-level 2)
1490 (setq cperl-continued-statement-offset 2)
1491 (setq cperl-continued-brace-offset 0)
1492 (setq cperl-brace-offset -2)
1493 (setq cperl-brace-imaginary-offset 0)
1494 (setq cperl-label-offset 0)
1496 ;; Define perl fontification style.
1498 (defun mdw-fontify-perl ()
1500 ;; Miscellaneous fiddling.
1501 (modify-syntax-entry ?$ "\\")
1502 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1503 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1505 ;; Now define fontification things.
1506 (make-local-variable 'font-lock-keywords)
1507 (let ((perl-keywords
1508 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1509 "for" "foreach" "ge" "gt" "goto" "if"
1510 "last" "le" "lt" "local" "my" "ne" "next" "or"
1511 "package" "redo" "require" "return" "sub"
1512 "undef" "unless" "until" "use" "while")))
1514 (setq font-lock-keywords
1517 ;; Set up the keywords defined above.
1518 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1519 '(0 font-lock-keyword-face))
1521 ;; At least numbers are simpler than C.
1522 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1523 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1524 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1525 '(0 mdw-number-face))
1527 ;; And anything else is punctuation.
1528 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1529 '(0 mdw-punct-face)))))
1531 (mdw-post-config-mode-hack))
1533 (defun perl-number-tests (&optional arg)
1534 "Assign consecutive numbers to lines containing `#t'. With ARG,
1535 strip numbers instead."
1538 (goto-char (point-min))
1539 (let ((i 0) (fmt (if arg "" " %4d")))
1540 (while (search-forward "#t" nil t)
1541 (delete-region (point) (line-end-position))
1543 (insert (format fmt i)))
1544 (goto-char (point-min))
1545 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1546 (replace-match (format "\\1%d" i))))))
1548 ;;;--------------------------------------------------------------------------
1549 ;;; Python programming style.
1551 (defun mdw-fontify-pythonic (keywords)
1553 ;; Miscellaneous fiddling.
1554 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1555 (setq indent-tabs-mode nil)
1557 ;; Now define fontification things.
1558 (make-local-variable 'font-lock-keywords)
1559 (setq font-lock-keywords
1562 ;; Set up the keywords defined above.
1563 (list (concat "\\<\\(" keywords "\\)\\>")
1564 '(0 font-lock-keyword-face))
1566 ;; At least numbers are simpler than C.
1567 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1568 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1569 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1570 '(0 mdw-number-face))
1572 ;; And anything else is punctuation.
1573 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1574 '(0 mdw-punct-face))))
1576 (mdw-post-config-mode-hack))
1578 ;; Define Python fontification styles.
1580 (defun mdw-fontify-python ()
1581 (mdw-fontify-pythonic
1582 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1583 "del" "elif" "else" "except" "exec" "finally" "for"
1584 "from" "global" "if" "import" "in" "is" "lambda"
1585 "not" "or" "pass" "print" "raise" "return" "try"
1586 "while" "with" "yield")))
1588 (defun mdw-fontify-pyrex ()
1589 (mdw-fontify-pythonic
1590 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1591 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1592 "extern" "finally" "for" "from" "global" "if"
1593 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1594 "raise" "return" "struct" "try" "while" "with"
1597 ;;;--------------------------------------------------------------------------
1598 ;;; Icon programming style.
1600 ;; Icon indentation style.
1602 (setq icon-brace-offset 0
1603 icon-continued-brace-offset 0
1604 icon-continued-statement-offset 2
1605 icon-indent-level 2)
1607 ;; Define Icon fontification style.
1609 (defun mdw-fontify-icon ()
1611 ;; Miscellaneous fiddling.
1612 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1614 ;; Now define fontification things.
1615 (make-local-variable 'font-lock-keywords)
1616 (let ((icon-keywords
1617 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1618 "end" "every" "fail" "global" "if" "initial"
1619 "invocable" "link" "local" "next" "not" "of"
1620 "procedure" "record" "repeat" "return" "static"
1621 "suspend" "then" "to" "until" "while"))
1622 (preprocessor-keywords
1623 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1624 "include" "line" "undef")))
1625 (setq font-lock-keywords
1628 ;; Set up the keywords defined above.
1629 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1630 '(0 font-lock-keyword-face))
1632 ;; The things that Icon calls keywords.
1633 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1635 ;; At least numbers are simpler than C.
1636 (list (concat "\\<[0-9]+"
1637 "\\([rR][0-9a-zA-Z]+\\|"
1638 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1639 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1640 '(0 mdw-number-face))
1643 (list (concat "^[ \t]*$[ \t]*\\<\\("
1644 preprocessor-keywords
1646 '(0 font-lock-keyword-face))
1648 ;; And anything else is punctuation.
1649 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1650 '(0 mdw-punct-face)))))
1652 (mdw-post-config-mode-hack))
1654 ;;;--------------------------------------------------------------------------
1655 ;;; ARM assembler programming configuration.
1657 ;; There doesn't appear to be an Emacs mode for this yet.
1659 ;; Better do something about that, I suppose.
1661 (defvar arm-assembler-mode-map nil)
1662 (defvar arm-assembler-abbrev-table nil)
1663 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1665 (or arm-assembler-mode-map
1667 (setq arm-assembler-mode-map (make-sparse-keymap))
1668 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1669 (define-key arm-assembler-mode-map [C-return] 'newline)
1670 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1672 (defun arm-assembler-mode ()
1673 "Major mode for ARM assembler programs"
1676 ;; Do standard major mode things.
1677 (kill-all-local-variables)
1678 (use-local-map arm-assembler-mode-map)
1679 (setq local-abbrev-table arm-assembler-abbrev-table)
1680 (setq major-mode 'arm-assembler-mode)
1681 (setq mode-name "ARM assembler")
1683 ;; Set up syntax table.
1684 (set-syntax-table arm-assembler-mode-syntax-table)
1685 (modify-syntax-entry ?; ; Nasty hack
1686 "<" arm-assembler-mode-syntax-table)
1687 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1688 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1690 (make-local-variable 'comment-start)
1691 (setq comment-start ";")
1692 (make-local-variable 'comment-end)
1693 (setq comment-end "")
1694 (make-local-variable 'comment-column)
1695 (setq comment-column 48)
1696 (make-local-variable 'comment-start-skip)
1697 (setq comment-start-skip ";+[ \t]*")
1699 ;; Play with indentation.
1700 (make-local-variable 'indent-line-function)
1701 (setq indent-line-function 'indent-relative-maybe)
1704 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1706 ;; Fiddle with fontification.
1707 (make-local-variable 'font-lock-keywords)
1708 (setq font-lock-keywords
1711 ;; Handle numbers too.
1713 ;; The following isn't quite right, but it's close enough.
1716 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1718 '(0 mdw-number-face))
1720 ;; Do something about operators.
1721 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1722 '(1 font-lock-keyword-face)
1723 '(2 font-lock-string-face))
1725 '(0 font-lock-keyword-face))
1727 ;; Do menemonics and directives.
1728 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1729 '(1 font-lock-keyword-face))
1731 ;; And anything else is punctuation.
1732 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1733 '(0 mdw-punct-face)))
1735 (mdw-post-config-mode-hack))
1736 (run-hooks 'arm-assembler-mode-hook))
1738 ;;;--------------------------------------------------------------------------
1741 (defun mdw-fontify-asm ()
1742 (modify-syntax-entry ?' "\"")
1743 (modify-syntax-entry ?. "w")
1744 (setf fill-prefix nil)
1745 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1747 ;;;--------------------------------------------------------------------------
1748 ;;; TCL configuration.
1750 (defun mdw-fontify-tcl ()
1751 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1752 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1753 (make-local-variable 'font-lock-keywords)
1754 (setq font-lock-keywords
1756 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1757 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1758 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1759 '(0 mdw-number-face))
1760 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1761 '(0 mdw-punct-face))))
1762 (mdw-post-config-mode-hack))
1764 ;;;--------------------------------------------------------------------------
1765 ;;; REXX configuration.
1767 (defun mdw-rexx-electric-* ()
1772 (defun mdw-rexx-indent-newline-indent ()
1775 (if abbrev-mode (expand-abbrev))
1776 (newline-and-indent))
1778 (defun mdw-fontify-rexx ()
1780 ;; Various bits of fiddling.
1781 (setq mdw-auto-indent nil)
1782 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1783 (local-set-key [?*] 'mdw-rexx-electric-*)
1784 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1786 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1788 ;; Set up keywords and things for fontification.
1789 (make-local-variable 'font-lock-keywords-case-fold-search)
1790 (setq font-lock-keywords-case-fold-search t)
1792 (setq rexx-indent 2)
1793 (setq rexx-end-indent rexx-indent)
1794 (setq rexx-cont-indent rexx-indent)
1796 (make-local-variable 'font-lock-keywords)
1797 (let ((rexx-keywords
1798 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1799 "else" "end" "engineering" "exit" "expose" "for"
1800 "forever" "form" "fuzz" "if" "interpret" "iterate"
1801 "leave" "linein" "name" "nop" "numeric" "off" "on"
1802 "options" "otherwise" "parse" "procedure" "pull"
1803 "push" "queue" "return" "say" "select" "signal"
1804 "scientific" "source" "then" "trace" "to" "until"
1805 "upper" "value" "var" "version" "when" "while"
1808 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1809 "center" "center" "charin" "charout" "chars"
1810 "compare" "condition" "copies" "c2d" "c2x"
1811 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1812 "errortext" "format" "fuzz" "insert" "lastpos"
1813 "left" "length" "lineout" "lines" "max" "min"
1814 "overlay" "pos" "queued" "random" "reverse" "right"
1815 "sign" "sourceline" "space" "stream" "strip"
1816 "substr" "subword" "symbol" "time" "translate"
1817 "trunc" "value" "verify" "word" "wordindex"
1818 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1821 (setq font-lock-keywords
1824 ;; Set up the keywords defined above.
1825 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1826 '(0 font-lock-keyword-face))
1828 ;; Fontify all symbols the same way.
1829 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1830 "[A-Za-z0-9.!?_#@$]+\\)")
1831 '(0 font-lock-variable-name-face))
1833 ;; And everything else is punctuation.
1834 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1835 '(0 mdw-punct-face)))))
1837 (mdw-post-config-mode-hack))
1839 ;;;--------------------------------------------------------------------------
1840 ;;; Standard ML programming style.
1842 (defun mdw-fontify-sml ()
1844 ;; Make underscore an honorary letter.
1845 (modify-syntax-entry ?' "w")
1848 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1850 ;; Now define fontification things.
1851 (make-local-variable 'font-lock-keywords)
1853 (mdw-regexps "abstype" "and" "andalso" "as"
1856 "else" "end" "eqtype" "exception"
1857 "fn" "fun" "functor"
1859 "if" "in" "include" "infix" "infixr"
1862 "of" "op" "open" "orelse"
1864 "sharing" "sig" "signature" "struct" "structure"
1867 "where" "while" "with" "withtype")))
1869 (setq font-lock-keywords
1872 ;; Set up the keywords defined above.
1873 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1874 '(0 font-lock-keyword-face))
1876 ;; At least numbers are simpler than C.
1877 (list (concat "\\<\\(\\~\\|\\)"
1878 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1880 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1881 "\\([eE]\\(\\~\\|\\)"
1882 "[0-9]+\\|\\)\\)\\)")
1883 '(0 mdw-number-face))
1885 ;; And anything else is punctuation.
1886 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1887 '(0 mdw-punct-face)))))
1889 (mdw-post-config-mode-hack))
1891 ;;;--------------------------------------------------------------------------
1892 ;;; Haskell configuration.
1894 (defun mdw-fontify-haskell ()
1896 ;; Fiddle with syntax table to get comments right.
1897 (modify-syntax-entry ?' "\"")
1898 (modify-syntax-entry ?- ". 123")
1899 (modify-syntax-entry ?{ ". 1b")
1900 (modify-syntax-entry ?} ". 4b")
1901 (modify-syntax-entry ?\n ">")
1904 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1906 ;; Fiddle with fontification.
1907 (make-local-variable 'font-lock-keywords)
1908 (let ((haskell-keywords
1909 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1910 "deriving" "do" "else" "foreign" "hiding" "if"
1911 "import" "in" "infix" "infixl" "infixr" "instance"
1912 "let" "module" "newtype" "of" "qualified" "safe"
1913 "stdcall" "then" "type" "unsafe" "where")))
1915 (setq font-lock-keywords
1918 '(0 font-lock-comment-face))
1919 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1920 '(0 font-lock-keyword-face))
1921 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1922 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1923 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1924 '(0 mdw-number-face))
1925 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1926 '(0 mdw-punct-face)))))
1928 (mdw-post-config-mode-hack))
1930 ;;;--------------------------------------------------------------------------
1931 ;;; Erlang configuration.
1933 (setq erlang-electric-commannds
1934 '(erlang-electric-newline erlang-electric-semicolon))
1936 (defun mdw-fontify-erlang ()
1939 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1941 ;; Fiddle with fontification.
1942 (make-local-variable 'font-lock-keywords)
1943 (let ((erlang-keywords
1944 (mdw-regexps "after" "and" "andalso"
1945 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1946 "case" "catch" "cond"
1947 "div" "end" "fun" "if" "let" "not"
1949 "query" "receive" "rem" "try" "when" "xor")))
1951 (setq font-lock-keywords
1954 '(0 font-lock-comment-face))
1955 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1956 '(0 font-lock-keyword-face))
1957 (list (concat "^-\\sw+\\>")
1958 '(0 font-lock-keyword-face))
1959 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1960 '(0 mdw-number-face))
1961 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1962 '(0 mdw-punct-face)))))
1964 (mdw-post-config-mode-hack))
1966 ;;;--------------------------------------------------------------------------
1967 ;;; Texinfo configuration.
1969 (defun mdw-fontify-texinfo ()
1972 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1974 ;; Real fontification things.
1975 (make-local-variable 'font-lock-keywords)
1976 (setq font-lock-keywords
1979 ;; Environment names are keywords.
1980 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1981 '(2 font-lock-keyword-face))
1983 ;; Unmark escaped magic characters.
1984 (list "\\(@\\)\\([@{}]\\)"
1985 '(1 font-lock-keyword-face)
1986 '(2 font-lock-variable-name-face))
1988 ;; Make sure we get comments properly.
1989 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1990 '(0 font-lock-comment-face))
1992 ;; Command names are keywords.
1993 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1994 '(0 font-lock-keyword-face))
1996 ;; Fontify TeX special characters as punctuation.
1998 '(0 mdw-punct-face))))
2000 (mdw-post-config-mode-hack))
2002 ;;;--------------------------------------------------------------------------
2003 ;;; TeX and LaTeX configuration.
2005 (defun mdw-fontify-tex ()
2006 (setq ispell-parser 'tex)
2009 ;; Don't make maths into a string.
2010 (modify-syntax-entry ?$ ".")
2011 (modify-syntax-entry ?$ "." font-lock-syntax-table)
2012 (local-set-key [?$] 'self-insert-command)
2015 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
2017 ;; Real fontification things.
2018 (make-local-variable 'font-lock-keywords)
2019 (setq font-lock-keywords
2022 ;; Environment names are keywords.
2023 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
2025 '(2 font-lock-keyword-face))
2027 ;; Suspended environment names are keywords too.
2028 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
2030 '(3 font-lock-keyword-face))
2032 ;; Command names are keywords.
2033 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2034 '(0 font-lock-keyword-face))
2036 ;; Handle @/.../ for italics.
2037 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
2038 ;; '(1 font-lock-keyword-face)
2039 ;; '(3 font-lock-keyword-face))
2041 ;; Handle @*...* for boldness.
2042 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
2043 ;; '(1 font-lock-keyword-face)
2044 ;; '(3 font-lock-keyword-face))
2046 ;; Handle @`...' for literal syntax things.
2047 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
2048 ;; '(1 font-lock-keyword-face)
2049 ;; '(3 font-lock-keyword-face))
2051 ;; Handle @<...> for nonterminals.
2052 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
2053 ;; '(1 font-lock-keyword-face)
2054 ;; '(3 font-lock-keyword-face))
2056 ;; Handle other @-commands.
2057 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
2058 ;; '(0 font-lock-keyword-face))
2060 ;; Make sure we get comments properly.
2062 '(0 font-lock-comment-face))
2064 ;; Fontify TeX special characters as punctuation.
2066 '(0 mdw-punct-face))))
2068 (mdw-post-config-mode-hack))
2070 ;;;--------------------------------------------------------------------------
2073 (defun mdw-sgml-mode ()
2076 (mdw-standard-fill-prefix "")
2077 (make-local-variable 'sgml-delimiters)
2078 (setq sgml-delimiters
2079 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2080 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2081 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2082 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2083 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2084 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2085 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2087 (setq major-mode 'mdw-sgml-mode)
2088 (setq mode-name "[mdw] SGML")
2089 (run-hooks 'mdw-sgml-mode-hook))
2091 ;;;--------------------------------------------------------------------------
2094 (defun mdw-setup-sh-script-mode ()
2096 ;; Fetch the shell interpreter's name.
2097 (let ((shell-name sh-shell-file))
2099 ;; Try reading the hash-bang line.
2101 (goto-char (point-min))
2102 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2103 (setq shell-name (match-string 1))))
2105 ;; Now try to set the shell.
2107 ;; Don't let `sh-set-shell' bugger up my script.
2108 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2109 (sh-set-shell shell-name)))
2111 ;; Now enable my keys and the fontification.
2112 (mdw-misc-mode-config)
2114 ;; Set the indentation level correctly.
2115 (setq sh-indentation 2)
2116 (setq sh-basic-offset 2))
2118 ;;;--------------------------------------------------------------------------
2119 ;;; Emacs shell mode.
2121 (defun mdw-eshell-prompt ()
2122 (let ((left "[") (right "]"))
2123 (when (= (user-uid) 0)
2124 (setq left "«" right "»"))
2127 (replace-regexp-in-string "\\..*$" "" (system-name)))
2131 (setq eshell-prompt-function 'mdw-eshell-prompt)
2132 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
2134 (defalias 'eshell/e 'find-file)
2135 (defalias 'eshell/w3m 'w3m-goto-url)
2137 (mdw-define-face eshell-prompt (t :weight bold))
2138 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2139 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2140 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2141 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2142 (mdw-define-face eshell-ls-executable (t :weight bold))
2143 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2144 (mdw-define-face eshell-ls-readonly (t nil))
2145 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2147 ;;;--------------------------------------------------------------------------
2148 ;;; Messages-file mode.
2150 (defun messages-mode-guts ()
2151 (setq messages-mode-syntax-table (make-syntax-table))
2152 (set-syntax-table messages-mode-syntax-table)
2153 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2154 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2155 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2156 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2157 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2158 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2159 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2160 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2161 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2162 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2163 (make-local-variable 'comment-start)
2164 (make-local-variable 'comment-end)
2165 (make-local-variable 'indent-line-function)
2166 (setq indent-line-function 'indent-relative)
2167 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2168 (make-local-variable 'font-lock-defaults)
2169 (make-local-variable 'messages-mode-keywords)
2171 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2172 "export" "enum" "fixed-octetstring" "flags"
2173 "harmless" "map" "nested" "optional"
2174 "optional-tagged" "package" "primitive"
2175 "primitive-nullfree" "relaxed[ \t]+enum"
2176 "set" "table" "tagged-optional" "union"
2177 "variadic" "vector" "version" "version-tag")))
2178 (setq messages-mode-keywords
2180 (list (concat "\\<\\(" keywords "\\)\\>:")
2181 '(0 font-lock-keyword-face))
2182 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2183 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2184 (0 font-lock-variable-name-face))
2185 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2186 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2187 (0 mdw-punct-face)))))
2188 (setq font-lock-defaults
2189 '(messages-mode-keywords nil nil nil nil))
2190 (run-hooks 'messages-file-hook))
2192 (defun messages-mode ()
2195 (setq major-mode 'messages-mode)
2196 (setq mode-name "Messages")
2197 (messages-mode-guts)
2198 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2199 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2200 (setq comment-start "# ")
2201 (setq comment-end "")
2202 (run-hooks 'messages-mode-hook))
2204 (defun cpp-messages-mode ()
2207 (setq major-mode 'cpp-messages-mode)
2208 (setq mode-name "CPP Messages")
2209 (messages-mode-guts)
2210 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2211 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2212 (setq comment-start "/* ")
2213 (setq comment-end " */")
2214 (let ((preprocessor-keywords
2215 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2216 "ident" "if" "ifdef" "ifndef" "import" "include"
2217 "line" "pragma" "unassert" "undef" "warning")))
2218 (setq messages-mode-keywords
2219 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2220 "\\(include\\|import\\)"
2221 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2222 '(2 font-lock-string-face))
2223 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2224 preprocessor-keywords
2225 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2226 '(1 font-lock-keyword-face)))
2227 messages-mode-keywords)))
2228 (run-hooks 'cpp-messages-mode-hook))
2230 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2231 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2232 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2234 ;;;--------------------------------------------------------------------------
2235 ;;; Messages-file mode.
2237 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2238 "Face to use for subsittution directives.")
2239 (make-face 'mallow-driver-substitution-face)
2240 (defvar mallow-driver-text-face 'mallow-driver-text-face
2241 "Face to use for body text.")
2242 (make-face 'mallow-driver-text-face)
2244 (defun mallow-driver-mode ()
2247 (setq major-mode 'mallow-driver-mode)
2248 (setq mode-name "Mallow driver")
2249 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2250 (set-syntax-table mallow-driver-mode-syntax-table)
2251 (make-local-variable 'comment-start)
2252 (make-local-variable 'comment-end)
2253 (make-local-variable 'indent-line-function)
2254 (setq indent-line-function 'indent-relative)
2255 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2256 (make-local-variable 'font-lock-defaults)
2257 (make-local-variable 'mallow-driver-mode-keywords)
2259 (mdw-regexps "each" "divert" "file" "if"
2260 "perl" "set" "string" "type" "write")))
2261 (setq mallow-driver-mode-keywords
2263 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2264 '(0 font-lock-keyword-face))
2265 (list "^%\\s *\\(#.*\\|\\)$"
2266 '(0 font-lock-comment-face))
2268 '(0 font-lock-keyword-face))
2269 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2271 '(0 mallow-driver-substitution-face t)))))
2272 (setq font-lock-defaults
2273 '(mallow-driver-mode-keywords nil nil nil nil))
2274 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2275 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2276 (setq comment-start "%# ")
2277 (setq comment-end "")
2278 (run-hooks 'mallow-driver-mode-hook))
2280 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2282 ;;;--------------------------------------------------------------------------
2285 (defun nfast-debug-mode ()
2288 (setq major-mode 'nfast-debug-mode)
2289 (setq mode-name "NFast debug")
2290 (setq messages-mode-syntax-table (make-syntax-table))
2291 (set-syntax-table messages-mode-syntax-table)
2292 (make-local-variable 'font-lock-defaults)
2293 (make-local-variable 'nfast-debug-mode-keywords)
2294 (setq truncate-lines t)
2295 (setq nfast-debug-mode-keywords
2297 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2298 (0 font-lock-keyword-face))
2299 (list (concat "^[ \t]+\\(\\("
2300 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2301 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2303 "[0-9a-fA-F]+\\)[ \t]*$")
2304 '(0 mdw-number-face))
2305 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2306 (1 font-lock-keyword-face))
2307 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2308 (1 font-lock-warning-face))
2309 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2311 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2312 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2313 '(1 font-lock-keyword-face))
2314 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2315 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2316 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2317 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2318 (setq font-lock-defaults
2319 '(nfast-debug-mode-keywords nil nil nil nil))
2320 (run-hooks 'nfast-debug-mode-hook))
2322 ;;;--------------------------------------------------------------------------
2323 ;;; Other languages.
2327 (defun mdw-setup-smalltalk ()
2328 (and mdw-auto-indent
2329 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2330 (make-local-variable 'mdw-auto-indent)
2331 (setq mdw-auto-indent nil)
2332 (local-set-key "\C-i" 'smalltalk-reindent))
2334 (defun mdw-fontify-smalltalk ()
2335 (make-local-variable 'font-lock-keywords)
2336 (setq font-lock-keywords
2338 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2339 '(0 font-lock-keyword-face))
2340 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2341 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2342 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2343 '(0 mdw-number-face))
2344 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2345 '(0 mdw-punct-face))))
2346 (mdw-post-config-mode-hack))
2350 ;; Unpleasant bodge.
2351 (unless (boundp 'slime-repl-mode-map)
2352 (setq slime-repl-mode-map (make-sparse-keymap)))
2354 (defun mdw-indent-newline-and-indent ()
2356 (indent-for-tab-command)
2357 (newline-and-indent))
2359 (eval-after-load "cl-indent"
2361 (mapc #'(lambda (pair)
2363 'common-lisp-indent-function
2365 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2366 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2368 (defun mdw-common-lisp-indent ()
2369 (make-local-variable 'lisp-indent-function)
2370 (setq lisp-indent-function 'common-lisp-indent-function))
2372 (setq lisp-simple-loop-indentation 2
2373 lisp-loop-keyword-indentation 6
2374 lisp-loop-forms-indentation 6)
2376 (defun mdw-fontify-lispy ()
2379 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2381 ;; Not much fontification needed.
2382 (make-local-variable 'font-lock-keywords)
2383 (setq font-lock-keywords
2385 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2386 '(0 mdw-punct-face))))
2388 (mdw-post-config-mode-hack))
2390 (defun comint-send-and-indent ()
2393 (and mdw-auto-indent
2394 (indent-for-tab-command)))
2396 (defun mdw-setup-m4 ()
2397 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2399 ;;;--------------------------------------------------------------------------
2402 (defun mdw-text-mode ()
2403 (setq fill-column 72)
2405 (mdw-standard-fill-prefix
2406 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2409 ;;;--------------------------------------------------------------------------
2410 ;;; Outline and hide/show modes.
2412 (defun mdw-outline-collapse-all ()
2413 "Completely collapse everything in the entire buffer."
2416 (goto-char (point-min))
2417 (while (< (point) (point-max))
2421 (setq hs-hide-comments-when-hiding-all nil)
2423 (defadvice hs-hide-all (after hide-first-comment activate)
2424 (save-excursion (hs-hide-initial-comment-block)))
2426 ;;;--------------------------------------------------------------------------
2429 (defun mdw-sh-mode-setup ()
2430 (local-set-key [?\C-a] 'comint-bol)
2431 (add-hook 'comint-output-filter-functions
2432 'comint-watch-for-password-prompt))
2434 (defun mdw-term-mode-setup ()
2435 (setq term-prompt-regexp shell-prompt-pattern)
2436 (make-local-variable 'mouse-yank-at-point)
2437 (make-local-variable 'transient-mark-mode)
2438 (setq mouse-yank-at-point t)
2442 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2443 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2444 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2445 (defun term-send-meta-meta-something ()
2447 (term-send-raw-string "\e\e")
2449 (eval-after-load 'term
2451 (define-key term-raw-map [?\e ?\e] nil)
2452 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2453 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2454 (define-key term-raw-map [M-right] 'term-send-meta-right)
2455 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2456 (define-key term-raw-map [M-left] 'term-send-meta-left)
2457 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2459 ;;;--------------------------------------------------------------------------
2460 ;;; Inferior Emacs Lisp.
2462 (setq comint-prompt-read-only t)
2464 (eval-after-load "comint"
2466 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2467 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2469 (eval-after-load "ielm"
2471 (define-key ielm-map "\C-w" 'comint-kill-region)
2472 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2474 ;;;----- That's all, folks --------------------------------------------------
2476 (provide 'dot-emacs)