(match . 1)
(pad . ,(or mat 2))))))
+;;;--------------------------------------------------------------------------
+;;; Printing.
+
+;; Arrange to strip overlays from the buffer before we print . This will
+;; prevent `flyspell' from interfering with the printout. (It would be less
+;; bad if `ps-print' could merge the `flyspell' overlay face with the
+;; underlying `font-lock' face, but it can't (and that seems hard). So
+;; instead we have this hack.
+;;
+;; The basic trick is to copy the relevant text from the buffer being printed
+;; into a temporary buffer and... just print that. The text properties come
+;; with the text and end up in the new buffer, and the overlays get lost
+;; along the way. Only problem is that the headers identifying the file
+;; being printed get confused, so remember the original buffer and reinstate
+;; it when constructing the headers.
+(defvar mdw-printing-buffer)
+
+(defadvice ps-generate-header
+ (around mdw-use-correct-buffer () activate compile)
+ "Print the correct name of the buffer being printed."
+ (with-current-buffer mdw-printing-buffer
+ ad-do-it))
+
+(defadvice ps-generate
+ (around mdw-strip-overlays (buffer from to genfunc) activate compile)
+ "Strip overlays -- in particular, from `flyspell' -- before printout."
+ (with-temp-buffer
+ (let ((mdw-printing-buffer buffer))
+ (insert-buffer-substring buffer from to)
+ (ad-set-arg 0 (current-buffer))
+ (ad-set-arg 1 (point-min))
+ (ad-set-arg 2 (point-max))
+ ad-do-it)))
+
;;;--------------------------------------------------------------------------
;;; Other common declarations.