From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Vehrs Newsgroups: gmane.emacs.devel Subject: Re: Slight improvement to WoMan tbl handling Date: Tue, 23 Feb 2010 17:24:01 +0100 Message-ID: <4B840121.2010905@gmx.de> References: <20100217145557.312080@gmx.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1266948155 23982 80.91.229.12 (23 Feb 2010 18:02:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 23 Feb 2010 18:02:35 +0000 (UTC) Cc: emacs-devel@gnu.org To: Glenn Morris Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Feb 23 19:02:26 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Njz5V-0000Lq-Le for ged-emacs-devel@m.gmane.org; Tue, 23 Feb 2010 19:02:26 +0100 Original-Received: from localhost ([127.0.0.1]:43371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Njz5V-0004pI-7v for ged-emacs-devel@m.gmane.org; Tue, 23 Feb 2010 13:02:25 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NjxYS-0006ro-Au for emacs-devel@gnu.org; Tue, 23 Feb 2010 11:24:12 -0500 Original-Received: from [140.186.70.92] (port=52648 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NjxYR-0006rC-3P for emacs-devel@gnu.org; Tue, 23 Feb 2010 11:24:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NjxYN-0001Tm-M3 for emacs-devel@gnu.org; Tue, 23 Feb 2010 11:24:11 -0500 Original-Received: from mail.gmx.net ([213.165.64.20]:52315) by eggs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1NjxYN-0001T3-73 for emacs-devel@gnu.org; Tue, 23 Feb 2010 11:24:07 -0500 Original-Received: (qmail invoked by alias); 23 Feb 2010 16:24:02 -0000 Original-Received: from p54BD9305.dip0.t-ipconnect.de (EHLO [192.168.178.21]) [84.189.147.5] by mail.gmx.net (mp070) with SMTP; 23 Feb 2010 17:24:02 +0100 X-Authenticated: #3878099 X-Provags-ID: V01U2FsdGVkX1/HzZQd6ezHiZ+rhGGxRJAuWACit40mi1LauchXMn JwQ3H17JwgTaIV User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) In-Reply-To: X-Y-GMX-Trusted: 0 X-FuHaFi: 0.46000000000000002 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Mailman-Approved-At: Tue, 23 Feb 2010 13:00:20 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:121298 Archived-At: Glenn Morris wrote: > Please could you provide an explanation of what this change is > supposed to do, and a suggested ChangeLog entry? (See etc/CONTRIBUTE > for more details of how to supply patches.) Thanks. > OK, next try. This patch adds support for the "T{ T}" tbl syntax. Since this syntax is mainly used for long lines within a table, the patch also adds support for filling the last column of a table if the line length would exceed fill-column. diff -cp woman.el.orig woman.el *** woman.el.orig 2010-02-23 17:16:26.000000000 +0100 --- woman.el 2010-02-23 17:16:34.000000000 +0100 *************** expression in parentheses. Leaves point *** 3774,3780 **** (setq fn 'woman2-format-paragraphs)))) () ;; Find next control line: ! (set-marker to (woman-find-next-control-line)) ;; Call the appropriate function: (funcall fn to))) (if (not (eobp)) ; This should not happen, but ... --- 3774,3782 ---- (setq fn 'woman2-format-paragraphs)))) () ;; 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 ... *************** expression in parentheses. Leaves point *** 3785,3796 **** (fset 'insert-and-inherit insert-and-inherit) (set-marker to nil)))) ! (defun woman-find-next-control-line () "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) (save-excursion ;; Must handle ;; ...\c --- 3787,3799 ---- (fset 'insert-and-inherit insert-and-inherit) (set-marker to nil)))) ! (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 ((pattern (concat "\\(\\\\c\\)?\n[.']" pat)) ! to) (save-excursion ;; Must handle ;; ...\c *************** expression in parentheses. Leaves point *** 3799,3810 **** ;; BEWARE THAT THIS CODE MAY BE UNRELIABLE!!!!! (while (and ! (setq to (re-search-forward "\\(\\\\c\\)?\n[.']" nil t)) (match-beginning 1) (looking-at "br")) (goto-char (match-beginning 0)) (woman-delete-line 2))) ! (if to (1- to) (point-max)))) (defun woman2-PD (to) ".PD d -- Set the interparagraph distance to d. --- 3802,3813 ---- ;; BEWARE THAT THIS CODE MAY BE UNRELIABLE!!!!! (while (and ! (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 (- to (+ 1 (length pat))) (point-max)))) (defun woman2-PD (to) ".PD d -- Set the interparagraph distance to d. *************** Needs doing properly!" *** 4560,4566 **** ".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 --- 4563,4568 ---- *************** Format paragraphs upto TO." *** 4572,4577 **** --- 4574,4595 ---- (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) *************** Format paragraphs upto TO." *** 4587,4593 **** (delete-char -1) (insert-char ?\ (- col (current-column)))) (forward-line)) ! (goto-char start)))) ;; Format table with no filling or adjusting (cf. woman2-nf): (setq woman-nofill t) (woman2-format-paragraphs to)) --- 4605,4628 ---- (delete-char -1) (insert-char ?\ (- 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) ! (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)) *************** Format paragraphs upto TO." *** 4596,4601 **** --- 4631,4648 ---- ;; ".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: