From d64c72f50cb5acefb806c53dfc965ff5b22e8ac9 Mon Sep 17 00:00:00 2001 From: "Aaron S. Hawley" Date: Thu, 27 Jun 2019 13:55:04 +0200 Subject: [PATCH] Allow generating wiki and mediawiki tables * lisp/textmodes/table.el (table--generate-source-prologue) (table--generate-source-epilogue) (table--generate-source-scan-rows) (table--generate-source-cells-in-a-row): Insert the wiki/mediawiki separators. * lisp/textmodes/table.el (table-source-languages): Add support for wiki and mediawiki tables (bug#13287). 2019-06-27 Lars Ingebrigtsen * doc/emacs/text.texi (Table Misc): Mention the new wiki and mediawiki formats. --- doc/emacs/text.texi | 11 ++++++----- etc/NEWS | 4 ++++ lisp/textmodes/table.el | 40 ++++++++++++++++++++++++++++------------ 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi index 59423feeeae..ffebf39f331 100644 --- a/doc/emacs/text.texi +++ b/doc/emacs/text.texi @@ -2851,11 +2851,12 @@ cell interval, and the justification of the text in each cell. @findex table-generate-source @kbd{M-x table-generate-source} generates a table formatted for a specific markup language. It asks for a language (which must be one -of @code{html}, @code{latex}, or @code{cals}), a destination buffer in -which to put the result, and a table caption, and then inserts the -generated table into the specified buffer. The default destination -buffer is @code{table.@var{lang}}, where @var{lang} is the language -you specified. +of @code{html}, @code{latex}, @code{cals}, @code{wiki} or +@code{mediawiki}), a destination buffer in which to put the result, +and a table caption, and then inserts the generated table into the +specified buffer. The default destination buffer is +@code{table.@var{lang}}, where @var{lang} is the language you +specified. @node Two-Column @section Two-Column Editing diff --git a/etc/NEWS b/etc/NEWS index 10882e4ec45..6b38b81d4ab 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -475,6 +475,10 @@ current and the previous or the next line, as before. * Changes in Specialized Modes and Packages in Emacs 27.1 +** table +** `table-generate-source' and friends now support outputting wiki and +mediawiki format tables. + --- ** telnet-mode *** Reverting a buffer in `telnet-mode' will restart a closed diff --git a/lisp/textmodes/table.el b/lisp/textmodes/table.el index ef688f129fa..1f185e0f216 100644 --- a/lisp/textmodes/table.el +++ b/lisp/textmodes/table.el @@ -882,7 +882,7 @@ This is always set to nil at the entry to `table-with-cache-buffer' before execu (push '(table-mode-indicator (table-fixed-width-mode " Fixed-Table" " Table")) minor-mode-alist)) -(defconst table-source-languages '(html latex cals) +(defconst table-source-languages '(html latex cals wiki mediawiki) "Supported source languages.") (defvar table-source-info-plist nil "General storage for temporary information used while generating source.") @@ -3053,7 +3053,11 @@ CALS (DocBook DTD): (table-put-source-info 'row-type (if (zerop table-cals-thead-rows) "tbody" "thead")) (set-marker-insertion-type (table-get-source-info 'colspec-marker) nil) ;; insert after (insert (format " <%s valign=\"top\">\n" (table-get-source-info 'row-type)))) - ))) + ((eq language 'mediawiki) + (insert (format + "\n" + emacs-version)) + (insert "{|\n"))))) (defun table--generate-source-epilogue (dest-buffer language _col-list _row-list) "Generate and insert source epilogue into DEST-BUFFER." @@ -3070,7 +3074,8 @@ CALS (DocBook DTD): (dolist (col (sort (table-get-source-info 'colnum-list) '<)) (insert (format " \n" col col)))) (insert (format " \n \n\n" (table-get-source-info 'row-type)))) - ))) + ((eq language 'mediawiki) + (insert "|}\n"))))) (defun table--generate-source-scan-rows (dest-buffer language _origin-cell col-list row-list) "Generate and insert source rows into DEST-BUFFER." @@ -3082,7 +3087,11 @@ CALS (DocBook DTD): (insert " \n")) ((eq language 'cals) (insert " \n")) - )) + ((eq language 'wiki) + (insert "|")) + ((and (eq language 'mediawiki) + (> (table-get-source-info 'current-row) 1)) + (insert "|-\n")))) (table--generate-source-cells-in-a-row dest-buffer language col-list row-list) (with-current-buffer dest-buffer (cond @@ -3092,7 +3101,9 @@ CALS (DocBook DTD): (insert " \n") (unless (/= (table-get-source-info 'current-row) table-cals-thead-rows) (insert (format " \n" (table-get-source-info 'row-type))) - (insert (format " <%s valign=\"top\">\n" (table-put-source-info 'row-type "tbody"))))))) + (insert (format " <%s valign=\"top\">\n" (table-put-source-info 'row-type "tbody"))))) + ((eq language 'wiki) + (insert "|\n")))) (table-put-source-info 'current-row (1+ (table-get-source-info 'current-row))) (setq row-list (cdr row-list)))) @@ -3161,7 +3172,8 @@ CALS (DocBook DTD): (not (memq valign '(top none)))) (insert " valign=\"" (symbol-name valign) "\"")) (insert ">\n")) - )) + ((memq language '(wiki mediawiki)) + (insert "|")))) (table--generate-source-cell-contents dest-buffer language cell) (with-current-buffer dest-buffer (cond @@ -3169,7 +3181,10 @@ CALS (DocBook DTD): (insert (format" \n" (table-get-source-info 'cell-type)))) ((eq language 'cals) (insert " \n")) - )) + ((eq language 'wiki) + (insert "|")) + ((eq language 'mediawiki) + (insert ?\n)))) (table-forward-cell 1 t) (table-put-source-info 'current-column (table-get-source-info 'next-column)) )))) @@ -3208,11 +3223,12 @@ CALS (DocBook DTD): (with-current-buffer dest-buffer (let ((beg (point))) (insert cell-contents) - (indent-rigidly beg (point) - (cond - ((eq language 'html) 6) - ((eq language 'cals) 10))) - (insert ?\n))))) + (when (memq language '(html cals)) + (indent-rigidly beg (point) + (cond + ((eq language 'html) 6) + ((eq language 'cals) 10))) + (insert ?\n)))))) (defun table--cell-horizontal-char-p (c) "Test if character C is one of the horizontal characters" -- 2.39.2