-;; into a new buffer, makes that buffer current,
-;; and sets start and end to the buffer bounds.
-;; start and end are used free.
-(defun print-region-new-buffer (start end)
- (or (string= (buffer-name) " *spool temp*")
- (let ((oldbuf (current-buffer)))
- (set-buffer (get-buffer-create " *spool temp*"))
- (widen) (erase-buffer)
- (insert-buffer-substring oldbuf start end)
- (setq start (point-min) end (point-max)))))
+;; into a new buffer, makes that buffer current.
+;; It returns the new range to print from the new current buffer
+;; as (START . END).
+
+(defun print-region-new-buffer (ostart oend)
+ (if (string= (buffer-name) " *spool temp*")
+ (cons ostart oend)
+ (let ((oldbuf (current-buffer)))
+ (set-buffer (get-buffer-create " *spool temp*"))
+ (widen) (erase-buffer)
+ (insert-buffer-substring oldbuf ostart oend)
+ (cons (point-min) (point-max)))))
+
+(defun printify-region (begin end)
+ "Turn nonprinting characters (other than TAB, LF, SPC, RET, and FF)
+in the current buffer into printable representations as control or
+hexadecimal escapes."
+ (interactive "r")
+ (save-excursion
+ (goto-char begin)
+ (let (c)
+ (while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" end t)
+ (setq c (preceding-char))
+ (delete-backward-char 1)
+ (insert
+ (if (< c ?\ )
+ (format "\\^%c" (+ c ?@))
+ (format "\\%02x" c)))))))
+
+(provide 'lpr)