- (save-excursion
- (let ((page-start (Man-linepos 'bob))
- (page-end (Man-linepos 'eob))
- (regexp Man-first-heading-regexp))
- (goto-char (point-min))
- (re-search-forward regexp (point-max) t)
- (while (not (eobp))
- (if (re-search-forward regexp (point-max) t)
- (progn
- (setq page-end (Man-linepos 'bol))
- (end-of-line))
- (goto-char (point-max))
- (setq page-end (point)))
- (setq Man-page-list (append Man-page-list
- (list (cons page-start page-end)))
- page-start page-end)
+ (let ((page-start (point-min))
+ (page-end (point-max))
+ (header ""))
+ (goto-char page-start)
+ ;; (switch-to-buffer (current-buffer))(debug)
+ (while (not (eobp))
+ (setq header
+ (if (looking-at Man-page-header-regexp)
+ (Man-match-substring 1)
+ nil))
+ ;; Go past both the current and the next Man-first-heading-regexp
+ (if (re-search-forward Man-first-heading-regexp nil 'move 2)
+ (let ((p (progn (beginning-of-line) (point))))
+ ;; We assume that the page header is delimited by blank
+ ;; lines and that it contains at most one blank line. So
+ ;; if we back by three blank lines we will be sure to be
+ ;; before the page header but not before the possible
+ ;; previous page header.
+ (search-backward "\n\n" nil t 3)
+ (if (re-search-forward Man-page-header-regexp p 'move)
+ (beginning-of-line))))
+ (setq page-end (point))
+ (setq Man-page-list (append Man-page-list
+ (list (list (copy-marker page-start)
+ (copy-marker page-end)
+ header))))
+ (setq page-start page-end)
+ )))
+
+(defun Man-strip-page-headers ()
+ "Strip all the page headers but the first from the manpage."
+ (let ((buffer-read-only nil)
+ (case-fold-search nil)
+ (page-list Man-page-list)
+ (page ())
+ (header ""))
+ (while page-list
+ (setq page (car page-list))
+ (and (nth 2 page)
+ (goto-char (car page))
+ (re-search-forward Man-first-heading-regexp nil t)
+ (setq header (buffer-substring (car page) (match-beginning 0)))
+ ;; Since the awk script collapses all successive blank
+ ;; lines into one, and since we don't want to get rid of
+ ;; the fast awk script, one must choose between adding
+ ;; spare blank lines between pages when there were none and
+ ;; deleting blank lines at page boundaries when there were
+ ;; some. We choose the first, so we comment the following
+ ;; line.
+ ;; (setq header (concat "\n" header)))
+ (while (search-forward header (nth 1 page) t)
+ (replace-match "")))
+ (setq page-list (cdr page-list)))))
+
+(defun Man-unindent ()
+ "Delete the leading spaces that indent the manpage."
+ (let ((buffer-read-only nil)
+ (case-fold-search nil)
+ (page-list Man-page-list))
+ (while page-list
+ (let ((page (car page-list))
+ (indent "")
+ (nindent 0))
+ (narrow-to-region (car page) (car (cdr page)))
+ (if Man-uses-untabify-flag
+ (untabify (point-min) (point-max)))
+ (if (catch 'unindent
+ (goto-char (point-min))
+ (if (not (re-search-forward Man-first-heading-regexp nil t))
+ (throw 'unindent nil))
+ (beginning-of-line)
+ (setq indent (buffer-substring (point)
+ (progn
+ (skip-chars-forward " ")
+ (point))))
+ (setq nindent (length indent))
+ (if (zerop nindent)
+ (throw 'unindent nil))
+ (setq indent (concat indent "\\|$"))
+ (goto-char (point-min))
+ (while (not (eobp))
+ (if (looking-at indent)
+ (forward-line 1)
+ (throw 'unindent nil)))
+ (goto-char (point-min)))
+ (while (not (eobp))
+ (or (eolp)
+ (delete-char nindent))
+ (forward-line 1)))
+ (setq page-list (cdr page-list))