--- woman.el.orig 2010-02-15 14:37:45.000000000 +0100 +++ woman.el 2010-02-17 15:47:29.000000000 +0100 @@ -3774,7 +3774,9 @@ (setq fn 'woman2-format-paragraphs)))) () ;; Find next control line: - (set-marker to (woman-find-next-control-line)) + (if (equal request "TS") + (set-marker to (woman-find-next-control-line "TE")) + (set-marker to (woman-find-next-control-line))) ;; Call the appropriate function: (funcall fn to))) (if (not (eobp)) ; This should not happen, but ... @@ -3785,12 +3787,13 @@ (fset 'insert-and-inherit insert-and-inherit) (set-marker to nil)))) -(defun woman-find-next-control-line () +(defun woman-find-next-control-line (&optional pat) "Find and return start of next control line." ; (let ((to (save-excursion ; (re-search-forward "^\\." nil t)))) ; (if to (1- to) (point-max))) - (let (to) + (let ((pattern (concat "\\(\\\\c\\)?\n[.']" (if pat pat ""))) + to) (save-excursion ;; Must handle ;; ...\c @@ -3799,12 +3802,12 @@ ;; BEWARE THAT THIS CODE MAY BE UNRELIABLE!!!!! (while (and - (setq to (re-search-forward "\\(\\\\c\\)?\n[.']" nil t)) + (setq to (re-search-forward pattern nil t)) (match-beginning 1) (looking-at "br")) (goto-char (match-beginning 0)) (woman-delete-line 2))) - (if to (1- to) (point-max)))) + (if to (- to (+ 1 (length pat))) (point-max)))) (defun woman2-PD (to) ".PD d -- Set the interparagraph distance to d. @@ -4560,7 +4563,6 @@ ".TS -- Start of table code for the tbl processor. Format paragraphs upto TO." ;; This is a preliminary hack that seems to suffice for lilo.8. - (woman-delete-line 1) ; ignore any arguments (when woman-emulate-tbl ;; Assumes column separator is \t and intercolumn spacing is 3. ;; The first line may optionally be a list of options terminated by @@ -4572,6 +4574,21 @@ (woman-delete-line 1) ;; For each column, find its width and align it: (let ((start (point)) (col 1)) + ;; change T{ T} to tabs + (while (search-forward "T{\n" to t) + (replace-match "") + (catch 'end + (while (search-forward "\n" to t) + (replace-match " ") + (if (looking-at "T}") + (progn + (delete-char 2) + (throw 'end t)))))) + (goto-char start) + ;; strip space and headers + (while (re-search-forward "^\\.TH\\|\\.sp" to t) + (woman-delete-whole-line)) + (goto-char start) (while (prog1 (search-forward "\t" to t) (goto-char start)) ;; Find current column width: (while (< (point) to) @@ -4587,7 +4604,24 @@ (delete-char -1) (insert-char ?\ (- col (current-column)))) (forward-line)) - (goto-char start)))) + (goto-char start)) + ;; find maximum width + (let ((max-col 0)) + (while (search-forward "\n" to t) + (backward-char) + (if (> (current-column) max-col) + (setq max-col (current-column))) + (forward-char)) + (goto-char start) + ;; break lines if they are too long + (when (and (> max-col woman-fill-column) + (> woman-fill-column col)) + (setq max-col woman-fill-column) + (woman-break-table col to) + (goto-char start)) + (while (re-search-forward "^_$" to t) + (replace-match (make-string max-col ?_))) + (goto-char start)))) ;; Format table with no filling or adjusting (cf. woman2-nf): (setq woman-nofill t) (woman2-format-paragraphs to)) @@ -4596,6 +4630,18 @@ ;; ".TE -- End of table code for the tbl processor." ;; Turn filling and adjusting back on. +(defun woman-break-table (start-column to) + (while (< (point) to) + (move-to-column woman-fill-column) + (if (eolp) + (forward-line) + (if (and (search-backward " " start t) + (> (current-column) start-column)) + (progn + (insert-char ?\n 1) + (insert-char ?\ (- start-column 5))) + (forward-line))))) + ;;; WoMan message logging: