From f33e684cacba4ae791bd013438959834be43e5f5 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 20 May 2021 18:39:11 +0100 Subject: [PATCH] el/dot-emacs.el: Don't print `flyspell' overlays. --- el/dot-emacs.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 9810267..2a19ad1 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -1359,6 +1359,40 @@ case." (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. ;; Common mode settings. -- 2.11.0