From 0fd4e39641ab17ae1586747396acbe1e9fa48321 Mon Sep 17 00:00:00 2001 From: Achim Gratz Date: Sun, 16 Jan 2011 19:06:13 +0100 Subject: [PATCH] Allow headings inside tables without splicing them. *EXPERIMENTAL* This patch is an incomplete implementation, most notably, table (re-)alignment does not work. --- lisp/org-html.el | 15 +++++++++++++-- lisp/org-table.el | 30 +++++++++++++++--------------- lisp/org.el | 4 ++-- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lisp/org-html.el b/lisp/org-html.el index 9a5d225..d69d037 100644 --- a/lisp/org-html.el +++ b/lisp/org-html.el @@ -1899,7 +1899,7 @@ for formatting. This is required for the DocBook exporter." html-table-tag attributes)) (head (and org-export-highlight-first-table-line (delq nil (mapcar - (lambda (x) (string-match "^[ \t]*|-" x)) + (lambda (x) (string-match "^[ \t]*|[-~]" x)) (cdr lines))))) (nline 0) fnum nfields i (cnt 0) tbopen line fields html gr colgropen rowstart rowend @@ -1913,7 +1913,7 @@ for formatting. This is required for the DocBook exporter." (setq tbopen t) (while (setq line (pop lines)) (catch 'next-line - (if (string-match "^[ \t]*|-" line) + (if (string-match "^[ \t]*|[-]" line) (progn (unless splice (push (if head "" "") html) @@ -1921,6 +1921,16 @@ for formatting. This is required for the DocBook exporter." (setq head nil) ;; head ends here, first time around ;; ignore this line (throw 'next-line t))) + ; interspersed heading + (if (string-match "^[ \t]*|[~]" line) + (progn + (unless splice + (push (if head "" "") html) + (push "" html) + (setq tbopen nil)) + (setq head t) ; head starts again here, until the next |- hline + ;; ignore this line + (throw 'next-line t))) ;; Break the line into fields (setq fields (org-split-string line "[ \t]*|[ \t]*")) (unless fnum (setq fnum (make-vector (length fields) 0) @@ -1955,6 +1965,7 @@ for formatting. This is required for the DocBook exporter." fields "") rowend) html))) + (unless splice (if head (push "" html))) (unless splice (if tbopen (push "" html))) (unless splice (push "\n" html)) (setq html (nreverse html)) diff --git a/lisp/org-table.el b/lisp/org-table.el index 951bff7..9437ae1 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -567,7 +567,7 @@ property, locally or anywhere up in the hierarchy." (if (string-match org-table-hline-regexp x) 'hline (org-remove-by-index - (org-split-string (org-trim x) "\\s-*|\\s-*") + (org-split-string (org-trim x) "\\s[-~]*|\\s[-~]*") skipcols i0))) lines)) (fun (if (= i0 2) 'cdr 'identity)) @@ -680,7 +680,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.") ;; Mark the hlines by setting the corresponding element to nil ;; At the same time, we remove trailing space. (setq lines (mapcar (lambda (l) - (if (string-match "^ *|-" l) + (if (string-match "^ *|[-~]" l) nil (if (string-match "[ \t]+$" l) (substring l 0 (match-beginning 0)) @@ -897,9 +897,9 @@ Before doing so, re-align the table if necessary." (re-search-forward "|" end)) (if (and (looking-at "-") org-table-tab-jumps-over-hlines - (re-search-forward "^[ \t]*|\\([^-]\\)" end t)) + (re-search-forward "^[ \t]*|\\([^-~]\\)" end t)) (goto-char (match-beginning 1))) - (if (looking-at "-") + (if (looking-at "[-~]") (progn (beginning-of-line 0) (org-table-insert-row 'below)) @@ -1417,7 +1417,7 @@ With prefix ABOVE, insert above the current line." (org-table-maybe-recalculate-line) (org-table-insert-hline) (end-of-line 2) - (if (looking-at "\n[ \t]*|-") + (if (looking-at "\n[ \t]*|[-~]") (progn (insert "\n|") (org-table-align)) (org-table-next-field)) (if same-column (org-table-goto-column col)))) @@ -1425,7 +1425,7 @@ With prefix ABOVE, insert above the current line." (defun org-table-clean-line (s) "Convert a table line S into a string with only \"|\" and space. In particular, this does handle wide and invisible characters." - (if (string-match "^[ \t]*|-" s) + (if (string-match "^[ \t]*|[-~]" s) ;; It's a hline, just map the characters (setq s (mapconcat (lambda (x) (if (member x '(?| ?+)) "|" " ")) s "")) (while (string-match "|\\([ \t]*?[^ \t\r\n|][^\r\n|]*\\)|" s) @@ -1630,7 +1630,7 @@ blindly applies a recipe that works for simple tables." (end (move-marker (make-marker) (org-table-end)))) ;; first, get rid of all horizontal lines (goto-char beg) - (while (re-search-forward "^\\([ \t]*\\)|-.*\n" end t) + (while (re-search-forward "^\\([ \t]*\\)|[-~].*\n" end t) (replace-match "")) ;; insert a hline before first (goto-char beg) @@ -1642,11 +1642,11 @@ blindly applies a recipe that works for simple tables." (goto-char beg) (setq end (move-marker end (org-table-end))) ;; replace "+" at beginning and ending of hlines - (while (re-search-forward "^\\([ \t]*\\)|-" end t) - (replace-match "\\1+-")) + (while (re-search-forward "^\\([ \t]*\\)|\\([-~]\\)" end t) + (replace-match "\\1+\\2")) (goto-char beg) - (while (re-search-forward "-|[ \t]*$" end t) - (replace-match "-+")) + (while (re-search-forward "\\([-~]\\)|[ \t]*$" end t) + (replace-match "\\1+")) (goto-char beg))))) (defun org-table-wrap-region (arg) @@ -1801,12 +1801,12 @@ If NLAST is a number, only the NLAST fields will actually be summed." (t (setq col (org-table-current-column)) (goto-char (org-table-begin)) - (unless (re-search-forward "^[ \t]*|[^-]" nil t) + (unless (re-search-forward "^[ \t]*|[^-~]" nil t) (error "No table data")) (org-table-goto-column col) (setq beg (point)) (goto-char (org-table-end)) - (unless (re-search-backward "^[ \t]*|[^-]" nil t) + (unless (re-search-backward "^[ \t]*|[^-~]" nil t) (error "No table data")) (org-table-goto-column col) (setq end (point)))) @@ -2067,7 +2067,7 @@ For all numbers larger than LIMIT, shift them by DELTA." (setq org-table-current-begin-line (org-current-line) org-table-current-begin-pos (point) l org-table-current-begin-line) - (while (looking-at "[ \t]*|\\(-\\)?") + (while (looking-at "[ \t]*|\\([-~]\\)?") (push (if (match-end 1) 'hline 'dline) types) (if (match-end 1) (push l hlines) (push l dlines)) (beginning-of-line 2) @@ -2142,7 +2142,7 @@ of the new mark." (have-col (save-excursion (goto-char beg) - (not (re-search-forward "^[ \t]*|[^-|][^|]*[^#!$*_^| \t][^|]*|" end t)))) + (not (re-search-forward "^[ \t]*|[^-~|][^|]*[^#!$*_^| \t][^|]*|" end t)))) (col (org-table-current-column)) (forcenew (car (assoc newchar org-recalc-marks))) epos new) diff --git a/lisp/org.el b/lisp/org.el index 6e8aeac..5721b53 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -3599,9 +3599,9 @@ Normal means, no org-mode-specific context." "Detect an org-type or table-type table.") (defconst org-table-line-regexp "^[ \t]*|" "Detect an org-type table line.") -(defconst org-table-dataline-regexp "^[ \t]*|[^-]" +(defconst org-table-dataline-regexp "^[ \t]*|[^-~]" "Detect an org-type table line.") -(defconst org-table-hline-regexp "^[ \t]*|-" +(defconst org-table-hline-regexp "^[ \t]*|[-~]" "Detect an org-type table hline.") (defconst org-table1-hline-regexp "^[ \t]*\\+-[-+]" "Detect a table-type table hline.") -- 1.7.1