Function: woman-man-buffer

woman-man-buffer is a byte-compiled function defined in woman.el.gz.

Signature

(woman-man-buffer)

Documentation

Post-process an nroff-preformatted man buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/woman.el.gz
(defun woman-man-buffer ()
  "Post-process an nroff-preformatted man buffer."
  ;; Kill all leading whitespace:
  (if (looking-at "\\s-+") (woman-delete-match 0))
  ;; Delete all page footer/header pairs:
  (re-search-forward ".*")		; match header
  ;; Footer conventionally has page number at right, so ...
  (let ((regex (concat
		"^.*[0-9]\n\\s-*"	; footer and following blank lines
		(regexp-quote (match-string 0))	; header
		"\\s-*\n")))		; following blank lines
    (while (re-search-forward regex nil 1) ; finish at eob
      (woman-delete-match 0)))
  ;; Delete last text line (footer) and all following blank lines:
  (re-search-backward "\\S-")
  (beginning-of-line)
  (if (looking-at ".*[0-9]$")
      (delete-region (point) (point-max)))

  ;; Squeeze multiple blank lines:
  (goto-char (point-min))
  (while (re-search-forward "^[ \t]*\n\\([ \t]*\n\\)+" nil t)
    (replace-match "\n" t t))

  ;; CJK characters are underlined by double-sized "__".
  ;; (Code lifted from man.el, with trivial changes.)
  (if (< (buffer-size) (position-bytes (point-max)))
      ;; Multibyte characters exist.
      (progn
	(goto-char (point-min))
	(while (search-forward "__\b\b" nil t)
	  (delete-char -4)
	  (woman-set-face (point) (1+ (point)) 'woman-italic))
	(goto-char (point-min))
	(while (search-forward "\b\b__" nil t)
	  (delete-char -4)
	  (woman-set-face (1- (point)) (point) 'woman-italic))))

  ;; Interpret overprinting to indicate bold face:
  (goto-char (point-min))
  (while (re-search-forward "\\(.\\)\\(\\(\^H+\\1\\)+\\)" nil t)
    (woman-delete-match 2)
    (woman-set-face (1- (point)) (point) 'woman-bold))

  ;; Interpret underlining to indicate italic face:
  ;; (Must be AFTER emboldening to interpret bold _ correctly!)
  (goto-char (point-min))
  (while (search-forward "_\^H" nil t)
    (delete-char -2)
    (woman-set-face (point) (1+ (point)) 'woman-italic))

  ;; Leave any other uninterpreted ^H's in the buffer for now!  (They
  ;; might indicate composite special characters, which could be
  ;; interpreted if I knew what to expect.)

  ;; Optionally embolden section and subsection headings
  ;; (cf. `woman-imenu-generic-expression'):
  (cond
   (woman-bold-headings
    (goto-char (point-min))
    (forward-line)
    (while (re-search-forward "^\\(   \\)?\\([A-Z].*\\)" nil t)
      (woman-set-face (match-beginning 2) (match-end 2) 'woman-bold)))))