aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Vehrs2012-04-21 13:54:39 +0800
committerChong Yidong2012-04-21 13:54:39 +0800
commit081e8d653d004b6c78e1ceea25eb9d31f4652ecd (patch)
treecc43ed11f2df2aa9775c502f5d9a82a489f70028
parent2f38dff7b3e82b8b054927cda25620b4eac3239c (diff)
downloademacs-081e8d653d004b6c78e1ceea25eb9d31f4652ecd.tar.gz
emacs-081e8d653d004b6c78e1ceea25eb9d31f4652ecd.zip
Improve tbl support in woman.el.
* lisp/woman.el (woman-find-next-control-line): New arg, specifying an additional regexp component for the control line. (woman2-roff-buffer): Use it. (woman-break-table): New function. (woman2-TS): Use it. And some cleanups: * lisp/woman.el (woman-set-buffer-display-table, woman-decode-region) (woman-horizontal-escapes, woman-negative-vertical-space) (woman-tab-to-tab-stop, woman2-fc, woman2-TS) (WoMan-warn-ignored): Use ?\s instead of ?\ . Fixes: debbugs:5635
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/woman.el97
2 files changed, 90 insertions, 24 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 132aee66a9f..004a52c8d36 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,20 @@
12012-04-21 Michael Vehrs <Michael.Burschik@gmx.de>
2
3 * woman.el: Add support for "T{ T}" tbl syntax, and fix the
4 filling of the last column of a table (Bug#5635).
5 (woman-find-next-control-line): New arg, specifying an additional
6 regexp component for the control line.
7 (woman2-roff-buffer): Use it.
8 (woman-break-table): New function.
9 (woman2-TS): Use it.
10
112012-04-21 Chong Yidong <cyd@gnu.org>
12
13 * woman.el (woman-set-buffer-display-table, woman-decode-region)
14 (woman-horizontal-escapes, woman-negative-vertical-space)
15 (woman-tab-to-tab-stop, woman2-fc, woman2-TS)
16 (WoMan-warn-ignored): Use ?\s instead of ?\ .
17
12012-04-20 Stefan Monnier <monnier@iro.umontreal.ca> 182012-04-20 Stefan Monnier <monnier@iro.umontreal.ca>
2 19
3 * minibuffer.el (completion-file-name-table): Complete user names. 20 * minibuffer.el (completion-file-name-table): Complete user names.
diff --git a/lisp/woman.el b/lisp/woman.el
index 98ab27716a1..3ab06a5dd73 100644
--- a/lisp/woman.el
+++ b/lisp/woman.el
@@ -2133,7 +2133,7 @@ European characters."
2133 (copy-sequence standard-display-table) 2133 (copy-sequence standard-display-table)
2134 (make-display-table))) 2134 (make-display-table)))
2135 ;; Display the following internal chars correctly: 2135 ;; Display the following internal chars correctly:
2136 (aset buffer-display-table woman-unpadded-space-char [?\ ]) 2136 (aset buffer-display-table woman-unpadded-space-char [?\s])
2137 (aset buffer-display-table woman-escaped-escape-char [?\\])) 2137 (aset buffer-display-table woman-escaped-escape-char [?\\]))
2138 2138
2139 2139
@@ -2393,10 +2393,12 @@ Currently set only from '\" t in the first line of the source file.")
2393 (progn 2393 (progn
2394 (goto-char from) 2394 (goto-char from)
2395 (while (search-forward woman-escaped-escape-string nil t) 2395 (while (search-forward woman-escaped-escape-string nil t)
2396 (delete-char -1) (insert ?\\)) 2396 (delete-char -1)
2397 (insert ?\\))
2397 (goto-char from) 2398 (goto-char from)
2398 (while (search-forward woman-unpadded-space-string nil t) 2399 (while (search-forward woman-unpadded-space-string nil t)
2399 (delete-char -1) (insert ?\ )))) 2400 (delete-char -1)
2401 (insert ?\s))))
2400 2402
2401 ;; Must return the new end of file if used in format-alist. 2403 ;; Must return the new end of file if used in format-alist.
2402 (point-max))) 2404 (point-max)))
@@ -2437,9 +2439,9 @@ Preserves location of `point'."
2437 ;; first backwards then forwards: 2439 ;; first backwards then forwards:
2438 (while (and 2440 (while (and
2439 (<= (setq N (1+ N)) 0) 2441 (<= (setq N (1+ N)) 0)
2440 (cond ((memq (preceding-char) '(?\ ?\t)) 2442 (cond ((memq (preceding-char) '(?\s ?\t))
2441 (delete-char -1) t) 2443 (delete-char -1) t)
2442 ((memq (following-char) '(?\ ?\t)) 2444 ((memq (following-char) '(?\s ?\t))
2443 (delete-char 1) t) 2445 (delete-char 1) t)
2444 (t nil)))) 2446 (t nil))))
2445 (if (<= N 0) 2447 (if (<= N 0)
@@ -3376,7 +3378,7 @@ Ignore the default face and underline only word characters."
3376;; this used to be globally bound to nil, to avoid an error. Instead 3378;; this used to be globally bound to nil, to avoid an error. Instead
3377;; we can use bound-and-true-p in woman-translate. 3379;; we can use bound-and-true-p in woman-translate.
3378(defvar woman-translations) 3380(defvar woman-translations)
3379;; A list of the form (\"[ace]\" (a . b) (c . d) (e . ?\ )) or nil. 3381;; A list of the form (\"[ace]\" (a . b) (c . d) (e . ?\s)) or nil.
3380 3382
3381(defun woman-get-next-char () 3383(defun woman-get-next-char ()
3382 "Return and delete next char in buffer, including special chars." 3384 "Return and delete next char in buffer, including special chars."
@@ -3711,7 +3713,9 @@ expression in parentheses. Leaves point after the value."
3711 (setq fn 'woman2-format-paragraphs)))) 3713 (setq fn 'woman2-format-paragraphs))))
3712 () 3714 ()
3713 ;; Find next control line: 3715 ;; Find next control line:
3714 (set-marker to (woman-find-next-control-line)) 3716 (if (equal woman-request "TS")
3717 (set-marker to (woman-find-next-control-line "TE"))
3718 (set-marker to (woman-find-next-control-line)))
3715 ;; Call the appropriate function: 3719 ;; Call the appropriate function:
3716 (funcall fn to))) 3720 (funcall fn to)))
3717 (if (not (eobp)) ; This should not happen, but ... 3721 (if (not (eobp)) ; This should not happen, but ...
@@ -3722,12 +3726,13 @@ expression in parentheses. Leaves point after the value."
3722 (fset 'insert-and-inherit insert-and-inherit) 3726 (fset 'insert-and-inherit insert-and-inherit)
3723 (set-marker to nil)))) 3727 (set-marker to nil))))
3724 3728
3725(defun woman-find-next-control-line () 3729(defun woman-find-next-control-line (&optional pat)
3726 "Find and return start of next control line." 3730 "Find and return start of next control line.
3727; (let ((to (save-excursion 3731PAT, if non-nil, specifies an additional component of the control
3728; (re-search-forward "^\\." nil t)))) 3732line regexp to search for, which is appended to the default
3729; (if to (1- to) (point-max))) 3733regexp, \"\\(\\\\c\\)?\\n[.']\"."
3730 (let (to) 3734 (let ((pattern (concat "\\(\\\\c\\)?\n[.']" pat))
3735 to)
3731 (save-excursion 3736 (save-excursion
3732 ;; Must handle 3737 ;; Must handle
3733 ;; ...\c 3738 ;; ...\c
@@ -3736,12 +3741,14 @@ expression in parentheses. Leaves point after the value."
3736 ;; BEWARE THAT THIS CODE MAY BE UNRELIABLE!!!!! 3741 ;; BEWARE THAT THIS CODE MAY BE UNRELIABLE!!!!!
3737 (while 3742 (while
3738 (and 3743 (and
3739 (setq to (re-search-forward "\\(\\\\c\\)?\n[.']" nil t)) 3744 (setq to (re-search-forward pattern nil t))
3740 (match-beginning 1) 3745 (match-beginning 1)
3741 (looking-at "br")) 3746 (looking-at "br"))
3742 (goto-char (match-beginning 0)) 3747 (goto-char (match-beginning 0))
3743 (woman-delete-line 2))) 3748 (woman-delete-line 2)))
3744 (if to (1- to) (point-max)))) 3749 (if to
3750 (- to (+ 1 (length pat)))
3751 (point-max))))
3745 3752
3746(defun woman2-PD (to) 3753(defun woman2-PD (to)
3747 ".PD d -- Set the interparagraph distance to d. 3754 ".PD d -- Set the interparagraph distance to d.
@@ -3885,18 +3892,18 @@ Leave 1 blank line. Format paragraphs upto TO."
3885 (insert (substring overlap i eol)) 3892 (insert (substring overlap i eol))
3886 (setq i (or eol imax))) 3893 (setq i (or eol imax)))
3887 ) 3894 )
3888 ((eq c ?\ ) ; skip 3895 ((eq c ?\s) ; skip
3889 (forward-char)) 3896 (forward-char))
3890 ((eq c ?\t) ; skip 3897 ((eq c ?\t) ; skip
3891 (if (eq (following-char) ?\t) 3898 (if (eq (following-char) ?\t)
3892 (forward-char) ; both tabs, just skip 3899 (forward-char) ; both tabs, just skip
3893 (dotimes (i woman-tab-width) 3900 (dotimes (i woman-tab-width)
3894 (if (eolp) 3901 (if (eolp)
3895 (insert ?\ ) ; extend line 3902 (insert ?\s) ; extend line
3896 (forward-char)) ; skip 3903 (forward-char)) ; skip
3897 ))) 3904 )))
3898 (t 3905 (t
3899 (if (or (eq (following-char) ?\ ) ; overwrite OK 3906 (if (or (eq (following-char) ?\s) ; overwrite OK
3900 overwritten) ; warning only once per ".sp -" 3907 overwritten) ; warning only once per ".sp -"
3901 () 3908 ()
3902 (setq overwritten t) 3909 (setq overwritten t)
@@ -4400,7 +4407,7 @@ tab stop columns or pairs (COLUMN . TYPE) where TYPE is R or C."
4400 tab (- tab (if (eq type ?C) (/ n 2) n))) ) 4407 tab (- tab (if (eq type ?C) (/ n 2) n))) )
4401 (setq n (- tab (current-column))) 4408 (setq n (- tab (current-column)))
4402 (insert-char ?\s n)) 4409 (insert-char ?\s n))
4403 (insert ?\ )))) 4410 (insert ?\s))))
4404 4411
4405(defun woman2-DT (to) 4412(defun woman2-DT (to)
4406 ".DT -- Restore default tabs. Format paragraphs upto TO. 4413 ".DT -- Restore default tabs. Format paragraphs upto TO.
@@ -4418,7 +4425,7 @@ Needs doing properly!"
4418 (if (eolp) 4425 (if (eolp)
4419 (woman-delete-whole-line) ; ignore! 4426 (woman-delete-whole-line) ; ignore!
4420 (let ((delim (following-char)) 4427 (let ((delim (following-char))
4421 (pad ?\ ) end) ; pad defaults to space 4428 (pad ?\s) end) ; pad defaults to space
4422 (forward-char) 4429 (forward-char)
4423 (skip-chars-forward " \t") 4430 (skip-chars-forward " \t")
4424 (or (eolp) (setq pad (following-char))) 4431 (or (eolp) (setq pad (following-char)))
@@ -4449,8 +4456,6 @@ Needs doing properly!"
4449(defun woman2-TS (to) 4456(defun woman2-TS (to)
4450 ".TS -- Start of table code for the tbl processor. 4457 ".TS -- Start of table code for the tbl processor.
4451Format paragraphs upto TO." 4458Format paragraphs upto TO."
4452 ;; This is a preliminary hack that seems to suffice for lilo.8.
4453 (woman-delete-line 1) ; ignore any arguments
4454 (when woman-emulate-tbl 4459 (when woman-emulate-tbl
4455 ;; Assumes column separator is \t and intercolumn spacing is 3. 4460 ;; Assumes column separator is \t and intercolumn spacing is 3.
4456 ;; The first line may optionally be a list of options terminated by 4461 ;; The first line may optionally be a list of options terminated by
@@ -4462,6 +4467,22 @@ Format paragraphs upto TO."
4462 (woman-delete-line 1) 4467 (woman-delete-line 1)
4463 ;; For each column, find its width and align it: 4468 ;; For each column, find its width and align it:
4464 (let ((start (point)) (col 1)) 4469 (let ((start (point)) (col 1))
4470 (WoMan-log "%s" (buffer-substring start (+ start 40)))
4471 ;; change T{ T} to tabs
4472 (while (search-forward "T{\n" to t)
4473 (replace-match "")
4474 (catch 'end
4475 (while (search-forward "\n" to t)
4476 (replace-match " ")
4477 (if (looking-at "T}")
4478 (progn
4479 (delete-char 2)
4480 (throw 'end t))))))
4481 (goto-char start)
4482 ;; strip space and headers
4483 (while (re-search-forward "^\\.TH\\|\\.sp" to t)
4484 (woman-delete-whole-line))
4485 (goto-char start)
4465 (while (prog1 (search-forward "\t" to t) (goto-char start)) 4486 (while (prog1 (search-forward "\t" to t) (goto-char start))
4466 ;; Find current column width: 4487 ;; Find current column width:
4467 (while (< (point) to) 4488 (while (< (point) to)
@@ -4475,8 +4496,25 @@ Format paragraphs upto TO."
4475 (while (< (point) to) 4496 (while (< (point) to)
4476 (when (search-forward "\t" to t) 4497 (when (search-forward "\t" to t)
4477 (delete-char -1) 4498 (delete-char -1)
4478 (insert-char ?\ (- col (current-column)))) 4499 (insert-char ?\s (- col (current-column))))
4479 (forward-line)) 4500 (forward-line))
4501 (goto-char start))
4502 ;; find maximum width
4503 (let ((max-col 0))
4504 (while (search-forward "\n" to t)
4505 (backward-char)
4506 (if (> (current-column) max-col)
4507 (setq max-col (current-column)))
4508 (forward-char))
4509 (goto-char start)
4510 ;; break lines if they are too long
4511 (when (and (> max-col woman-fill-column)
4512 (> woman-fill-column col))
4513 (setq max-col woman-fill-column)
4514 (woman-break-table col to start)
4515 (goto-char start))
4516 (while (re-search-forward "^_$" to t)
4517 (replace-match (make-string max-col ?_)))
4480 (goto-char start)))) 4518 (goto-char start))))
4481 ;; Format table with no filling or adjusting (cf. woman2-nf): 4519 ;; Format table with no filling or adjusting (cf. woman2-nf):
4482 (setq woman-nofill t) 4520 (setq woman-nofill t)
@@ -4486,6 +4524,17 @@ Format paragraphs upto TO."
4486 ;; ".TE -- End of table code for the tbl processor." 4524 ;; ".TE -- End of table code for the tbl processor."
4487 ;; Turn filling and adjusting back on. 4525 ;; Turn filling and adjusting back on.
4488 4526
4527(defun woman-break-table (start-column to start)
4528 (while (< (point) to)
4529 (move-to-column woman-fill-column)
4530 (if (eolp)
4531 (forward-line)
4532 (if (and (search-backward " " start t)
4533 (> (current-column) start-column))
4534 (progn
4535 (insert-char ?\n 1)
4536 (insert-char ?\s (- start-column 5)))
4537 (forward-line)))))
4489 4538
4490;;; WoMan message logging: 4539;;; WoMan message logging:
4491 4540
@@ -4523,7 +4572,7 @@ IGNORED is a string appended to the log message."
4523 (buffer-substring (point) 4572 (buffer-substring (point)
4524 (line-end-position)))) 4573 (line-end-position))))
4525 (if (and (> (length tail) 0) 4574 (if (and (> (length tail) 0)
4526 (/= (string-to-char tail) ?\ )) 4575 (/= (string-to-char tail) ?\s))
4527 (setq tail (concat " " tail))) 4576 (setq tail (concat " " tail)))
4528 (WoMan-log-1 4577 (WoMan-log-1
4529 (concat "** " request tail " request " ignored)))) 4578 (concat "** " request tail " request " ignored))))