Function: woman2-TS

woman2-TS is a byte-compiled function defined in woman.el.gz.

Signature

(woman2-TS TO)

Documentation

.TS -- Start of table code for the tbl processor.

Format paragraphs upto TO.

Source Code

;; Defined in /usr/src/emacs/lisp/woman.el.gz
;;; Preliminary table support (.TS/.TE)

(defun woman2-TS (to)
  ".TS -- Start of table code for the tbl processor.
Format paragraphs upto TO."
  (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
    ;; a semicolon.  Currently, just delete it:
    (if (looking-at ".*;[ \t]*$") (woman-delete-line 1)) ;
    ;; The following lines must specify the format of each line of the
    ;; table and end with a period.  Currently, just delete them:
    (while (not (looking-at ".*\\.[ \t]*$")) (woman-delete-line 1))
    (woman-delete-line 1)
    ;; For each column, find its width and align it:
    (let ((start (point)) (col 1))
      (WoMan-log "%s" (buffer-substring start (+ start 40)))
      ;; 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)
	  (when (search-forward "\t" to t)
	    (backward-char)
	    (if (> (current-column) col) (setq col (current-column))))
	  (forward-line))
	;; Align current column:
	(goto-char start)
	(setq col (+ col 3))		; intercolumn space
	(while (< (point) to)
	  (when (search-forward "\t" to t)
	    (delete-char -1)
	    (insert-char ?\s (- col (current-column))))
	  (forward-line))
	(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 start)
	  (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))