New option to turn off export of the email address
[org-mode/org-jambu.git] / lisp / org-ascii.el
blob633958c79d7c05770829f026b48fa3e7da8f956a
1 ;;; org-ascii.el --- ASCII export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 6.34trans
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 (require 'org-exp)
30 (eval-when-compile
31 (require 'cl))
33 (defgroup org-export-ascii nil
34 "Options specific for ASCII export of Org-mode files."
35 :tag "Org Export ASCII"
36 :group 'org-export)
38 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
39 "Characters for underlining headings in ASCII export.
40 In the given sequence, these characters will be used for level 1, 2, ..."
41 :group 'org-export-ascii
42 :type '(repeat character))
44 (defcustom org-export-ascii-bullets '(?* ?+ ?-)
45 "Bullet characters for headlines converted to lists in ASCII export.
46 The first character is used for the first lest level generated in this
47 way, and so on. If there are more levels than characters given here,
48 the list will be repeated.
49 Note that plain lists will keep the same bullets as the have in the
50 Org-mode file."
51 :group 'org-export-ascii
52 :type '(repeat character))
54 (defcustom org-export-ascii-links-to-notes t
55 "Non-nil means convert links to notes before the next headline.
56 When nil, the link will be exported in place. If the line becomes long
57 in this way, it will be wrapped."
58 :group 'org-export-ascii
59 :type 'boolean)
61 (defcustom org-export-ascii-table-keep-all-vertical-lines nil
62 "Non-nil means keep all vertical lines in ASCII tables.
63 When nil, vertical lines will be removed except for those needed
64 for column grouping."
65 :group 'org-export-ascii
66 :type 'boolean)
68 (defcustom org-export-ascii-table-widen-columns t
69 "Non-nil means widen narrowed columns for export.
70 When nil, narrowed columns will look in ASCII export just like in org-mode,
71 i.e. with \"=>\" as ellipsis."
72 :group 'org-export-ascii
73 :type 'boolean)
75 ;;; Hooks
77 (defvar org-export-ascii-final-hook nil
78 "Hook run at the end of ASCII export, in the new buffer.")
80 ;;; ASCII export
82 (defvar org-ascii-current-indentation nil) ; For communication
84 ;;;###autoload
85 (defun org-export-as-ascii-to-buffer (arg)
86 "Call `org-export-as-ascii` with output to a temporary buffer.
87 No file is created. The prefix ARG is passed through to `org-export-as-ascii'."
88 (interactive "P")
89 (org-export-as-ascii arg nil nil "*Org ASCII Export*")
90 (when org-export-show-temporary-export-buffer
91 (switch-to-buffer-other-window "*Org ASCII Export*")))
93 ;;;###autoload
94 (defun org-replace-region-by-ascii (beg end)
95 "Assume the current region has org-mode syntax, and convert it to plain ASCII.
96 This can be used in any buffer. For example, you could write an
97 itemized list in org-mode syntax in a Mail buffer and then use this
98 command to convert it."
99 (interactive "r")
100 (let (reg ascii buf pop-up-frames)
101 (save-window-excursion
102 (if (org-mode-p)
103 (setq ascii (org-export-region-as-ascii
104 beg end t 'string))
105 (setq reg (buffer-substring beg end)
106 buf (get-buffer-create "*Org tmp*"))
107 (with-current-buffer buf
108 (erase-buffer)
109 (insert reg)
110 (org-mode)
111 (setq ascii (org-export-region-as-ascii
112 (point-min) (point-max) t 'string)))
113 (kill-buffer buf)))
114 (delete-region beg end)
115 (insert ascii)))
117 ;;;###autoload
118 (defun org-export-region-as-ascii (beg end &optional body-only buffer)
119 "Convert region from BEG to END in org-mode buffer to plain ASCII.
120 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
121 contents, and only produce the region of converted text, useful for
122 cut-and-paste operations.
123 If BUFFER is a buffer or a string, use/create that buffer as a target
124 of the converted ASCII. If BUFFER is the symbol `string', return the
125 produced ASCII as a string and leave not buffer behind. For example,
126 a Lisp program could call this function in the following way:
128 (setq ascii (org-export-region-as-ascii beg end t 'string))
130 When called interactively, the output buffer is selected, and shown
131 in a window. A non-interactive call will only return the buffer."
132 (interactive "r\nP")
133 (when (interactive-p)
134 (setq buffer "*Org ASCII Export*"))
135 (let ((transient-mark-mode t) (zmacs-regions t)
136 ext-plist rtn)
137 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
138 (goto-char end)
139 (set-mark (point)) ;; to activate the region
140 (goto-char beg)
141 (setq rtn (org-export-as-ascii
142 nil nil ext-plist
143 buffer body-only))
144 (if (fboundp 'deactivate-mark) (deactivate-mark))
145 (if (and (interactive-p) (bufferp rtn))
146 (switch-to-buffer-other-window rtn)
147 rtn)))
149 ;;;###autoload
150 (defun org-export-as-ascii (arg &optional hidden ext-plist
151 to-buffer body-only pub-dir)
152 "Export the outline as a pretty ASCII file.
153 If there is an active region, export only the region.
154 The prefix ARG specifies how many levels of the outline should become
155 underlined headlines, default is 3. Lower levels will become bulleted
156 lists. When HIDDEN is non-nil, don't display the ASCII buffer.
157 EXT-PLIST is a property list with external parameters overriding
158 org-mode's default settings, but still inferior to file-local
159 settings. When TO-BUFFER is non-nil, create a buffer with that
160 name and export to that buffer. If TO-BUFFER is the symbol
161 `string', don't leave any buffer behind but just return the
162 resulting ASCII as a string. When BODY-ONLY is set, don't produce
163 the file header and footer. When PUB-DIR is set, use this as the
164 publishing directory."
165 (interactive "P")
166 (run-hooks 'org-export-first-hook)
167 (setq-default org-todo-line-regexp org-todo-line-regexp)
168 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
169 ext-plist
170 (org-infile-export-plist)))
171 (region-p (org-region-active-p))
172 (rbeg (and region-p (region-beginning)))
173 (rend (and region-p (region-end)))
174 (subtree-p
175 (if (plist-get opt-plist :ignore-subtree-p)
177 (when region-p
178 (save-excursion
179 (goto-char rbeg)
180 (and (org-at-heading-p)
181 (>= (org-end-of-subtree t t) rend))))))
182 (level-offset (if subtree-p
183 (save-excursion
184 (goto-char rbeg)
185 (+ (funcall outline-level)
186 (if org-odd-levels-only 1 0)))
188 (opt-plist (setq org-export-opt-plist
189 (if subtree-p
190 (org-export-add-subtree-options opt-plist rbeg)
191 opt-plist)))
192 (custom-times org-display-custom-times)
193 (org-ascii-current-indentation '(0 . 0))
194 (level 0) line txt
195 (umax nil)
196 (umax-toc nil)
197 (case-fold-search nil)
198 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
199 (filename (if to-buffer
201 (concat (file-name-as-directory
202 (or pub-dir
203 (org-export-directory :ascii opt-plist)))
204 (file-name-sans-extension
205 (or (and subtree-p
206 (org-entry-get (region-beginning)
207 "EXPORT_FILE_NAME" t))
208 (file-name-nondirectory bfname)))
209 ".txt")))
210 (filename (and filename
211 (if (equal (file-truename filename)
212 (file-truename bfname))
213 (concat filename ".txt")
214 filename)))
215 (buffer (if to-buffer
216 (cond
217 ((eq to-buffer 'string)
218 (get-buffer-create "*Org ASCII Export*"))
219 (t (get-buffer-create to-buffer)))
220 (find-file-noselect filename)))
221 (org-levels-open (make-vector org-level-max nil))
222 (odd org-odd-levels-only)
223 (date (plist-get opt-plist :date))
224 (author (plist-get opt-plist :author))
225 (title (or (and subtree-p (org-export-get-title-from-subtree))
226 (plist-get opt-plist :title)
227 (and (not
228 (plist-get opt-plist :skip-before-1st-heading))
229 (org-export-grab-title-from-buffer))
230 (and (buffer-file-name)
231 (file-name-sans-extension
232 (file-name-nondirectory bfname)))
233 "UNTITLED"))
234 (email (plist-get opt-plist :email))
235 (language (plist-get opt-plist :language))
236 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
237 (todo nil)
238 (lang-words nil)
239 (region
240 (buffer-substring
241 (if (org-region-active-p) (region-beginning) (point-min))
242 (if (org-region-active-p) (region-end) (point-max))))
243 (lines (org-split-string
244 (org-export-preprocess-string
245 region
246 :for-ascii t
247 :skip-before-1st-heading
248 (plist-get opt-plist :skip-before-1st-heading)
249 :drawers (plist-get opt-plist :drawers)
250 :tags (plist-get opt-plist :tags)
251 :priority (plist-get opt-plist :priority)
252 :footnotes (plist-get opt-plist :footnotes)
253 :timestamps (plist-get opt-plist :timestamps)
254 :todo-keywords (plist-get opt-plist :todo-keywords)
255 :verbatim-multiline t
256 :select-tags (plist-get opt-plist :select-tags)
257 :exclude-tags (plist-get opt-plist :exclude-tags)
258 :archived-trees
259 (plist-get opt-plist :archived-trees)
260 :add-text (plist-get opt-plist :text))
261 "\n"))
262 thetoc have-headings first-heading-pos
263 table-open table-buffer link-buffer link desc desc0 rpl wrap)
264 (let ((inhibit-read-only t))
265 (org-unmodified
266 (remove-text-properties (point-min) (point-max)
267 '(:org-license-to-kill t))))
269 (setq org-min-level (org-get-min-level lines level-offset))
270 (setq org-last-level org-min-level)
271 (org-init-section-numbers)
272 (setq lang-words (or (assoc language org-export-language-setup)
273 (assoc "en" org-export-language-setup)))
274 (set-buffer buffer)
275 (erase-buffer)
276 (fundamental-mode)
277 (org-install-letbind)
278 ;; create local variables for all options, to make sure all called
279 ;; functions get the correct information
280 (mapc (lambda (x)
281 (set (make-local-variable (nth 2 x))
282 (plist-get opt-plist (car x))))
283 org-export-plist-vars)
284 (org-set-local 'org-odd-levels-only odd)
285 (setq umax (if arg (prefix-numeric-value arg)
286 org-export-headline-levels))
287 (setq umax-toc (if (integerp org-export-with-toc)
288 (min org-export-with-toc umax)
289 umax))
291 ;; File header
292 (unless body-only
293 (when (and title (not (string= "" title)))
294 (org-insert-centered title ?=)
295 (insert "\n"))
297 (if (and (or author email)
298 org-export-author-info)
299 (insert(concat (nth 1 lang-words) ": " (or author "")
300 (if (and org-export-email-info
301 email (string-match "\\S-" email))
302 (concat " <" email ">") "")
303 "\n")))
305 (cond
306 ((and date (string-match "%" date))
307 (setq date (format-time-string date)))
308 (date)
309 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
311 (if (and date org-export-time-stamp-file)
312 (insert (concat (nth 2 lang-words) ": " date"\n")))
314 (unless (= (point) (point-min))
315 (insert "\n\n")))
317 (if (and org-export-with-toc (not body-only))
318 (progn
319 (push (concat (nth 3 lang-words) "\n") thetoc)
320 (push (concat (make-string (string-width (nth 3 lang-words)) ?=)
321 "\n") thetoc)
322 (mapc '(lambda (line)
323 (if (string-match org-todo-line-regexp
324 line)
325 ;; This is a headline
326 (progn
327 (setq have-headings t)
328 (setq level (- (match-end 1) (match-beginning 1)
329 level-offset)
330 level (org-tr-level level)
331 txt (match-string 3 line)
332 todo
333 (or (and org-export-mark-todo-in-toc
334 (match-beginning 2)
335 (not (member (match-string 2 line)
336 org-done-keywords)))
337 ; TODO, not DONE
338 (and org-export-mark-todo-in-toc
339 (= level umax-toc)
340 (org-search-todo-below
341 line lines level))))
342 (setq txt (org-html-expand-for-ascii txt))
344 (while (string-match org-bracket-link-regexp txt)
345 (setq txt
346 (replace-match
347 (match-string (if (match-end 2) 3 1) txt)
348 t t txt)))
350 (if (and (memq org-export-with-tags '(not-in-toc nil))
351 (string-match
352 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
353 txt))
354 (setq txt (replace-match "" t t txt)))
355 (if (string-match quote-re0 txt)
356 (setq txt (replace-match "" t t txt)))
358 (if org-export-with-section-numbers
359 (setq txt (concat (org-section-number level)
360 " " txt)))
361 (if (<= level umax-toc)
362 (progn
363 (push
364 (concat
365 (make-string
366 (* (max 0 (- level org-min-level)) 4) ?\ )
367 (format (if todo "%s (*)\n" "%s\n") txt))
368 thetoc)
369 (setq org-last-level level))
370 ))))
371 lines)
372 (setq thetoc (if have-headings (nreverse thetoc) nil))))
374 (org-init-section-numbers)
375 (while (setq line (pop lines))
376 (when (and link-buffer (string-match "^\\*+ " line))
377 (org-export-ascii-push-links (nreverse link-buffer))
378 (setq link-buffer nil))
379 (setq wrap nil)
380 ;; Remove the quoted HTML tags.
381 (setq line (org-html-expand-for-ascii line))
382 ;; Replace links with the description when possible
383 (while (string-match org-bracket-link-regexp line)
384 (setq link (match-string 1 line)
385 desc0 (match-string 3 line)
386 desc (or desc0 (match-string 1 line)))
387 (if (and (> (length link) 8)
388 (equal (substring link 0 8) "coderef:"))
389 (setq line (replace-match
390 (format (org-export-get-coderef-format (substring link 8) desc)
391 (cdr (assoc
392 (substring link 8)
393 org-export-code-refs)))
394 t t line))
395 (setq rpl (concat "["
396 (or (match-string 3 line) (match-string 1 line))
397 "]"))
398 (when (and desc0 (not (equal desc0 link)))
399 (if org-export-ascii-links-to-notes
400 (push (cons desc0 link) link-buffer)
401 (setq rpl (concat rpl " (" link ")")
402 wrap (+ (length line) (- (length (match-string 0 line)))
403 (length desc)))))
404 (setq line (replace-match rpl t t line))))
405 (when custom-times
406 (setq line (org-translate-time line)))
407 (cond
408 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
409 ;; a Headline
410 (setq first-heading-pos (or first-heading-pos (point)))
411 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
412 level-offset))
413 txt (match-string 2 line))
414 (org-ascii-level-start level txt umax lines))
416 ((and org-export-with-tables
417 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
418 (if (not table-open)
419 ;; New table starts
420 (setq table-open t table-buffer nil))
421 ;; Accumulate lines
422 (setq table-buffer (cons line table-buffer))
423 (when (or (not lines)
424 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
425 (car lines))))
426 (setq table-open nil
427 table-buffer (nreverse table-buffer))
428 (insert (mapconcat
429 (lambda (x)
430 (org-fix-indentation x org-ascii-current-indentation))
431 (org-format-table-ascii table-buffer)
432 "\n") "\n")))
434 (if (string-match "^\\([ \t]*\\)\\([-+*][ \t]+\\)\\(.*?\\)\\( ::\\)" line)
435 (setq line (replace-match "\\1\\3:" t nil line)))
436 (setq line (org-fix-indentation line org-ascii-current-indentation))
437 ;; Remove forced line breaks
438 (if (string-match "\\\\\\\\[ \t]*$" line)
439 (setq line (replace-match "" t t line)))
440 (if (and org-export-with-fixed-width
441 (string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line))
442 (setq line (replace-match "\\1" nil nil line))
443 (if wrap (setq line (org-export-ascii-wrap line wrap))))
444 (insert line "\n"))))
446 (org-export-ascii-push-links (nreverse link-buffer))
448 (normal-mode)
450 ;; insert the table of contents
451 (when thetoc
452 (goto-char (point-min))
453 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t)
454 (progn
455 (goto-char (match-beginning 0))
456 (replace-match ""))
457 (goto-char first-heading-pos))
458 (mapc 'insert thetoc)
459 (or (looking-at "[ \t]*\n[ \t]*\n")
460 (insert "\n\n")))
462 ;; Convert whitespace place holders
463 (goto-char (point-min))
464 (let (beg end)
465 (while (setq beg (next-single-property-change (point) 'org-whitespace))
466 (setq end (next-single-property-change beg 'org-whitespace))
467 (goto-char beg)
468 (delete-region beg end)
469 (insert (make-string (- end beg) ?\ ))))
471 ;; remove display and invisible chars
472 (let (beg end)
473 (goto-char (point-min))
474 (while (setq beg (next-single-property-change (point) 'display))
475 (setq end (next-single-property-change beg 'display))
476 (delete-region beg end)
477 (goto-char beg)
478 (insert "=>"))
479 (goto-char (point-min))
480 (while (setq beg (next-single-property-change (point) 'org-cwidth))
481 (setq end (next-single-property-change beg 'org-cwidth))
482 (delete-region beg end)
483 (goto-char beg)))
484 (run-hooks 'org-export-ascii-final-hook)
485 (or to-buffer (save-buffer))
486 (goto-char (point-min))
487 (or (org-export-push-to-kill-ring "ASCII")
488 (message "Exporting... done"))
489 ;; Return the buffer or a string, according to how this function was called
490 (if (eq to-buffer 'string)
491 (prog1 (buffer-substring (point-min) (point-max))
492 (kill-buffer (current-buffer)))
493 (current-buffer))))
495 (defun org-export-ascii-preprocess (parameters)
496 "Do extra work for ASCII export"
498 ;; Realign tables to get rid of narrowing
499 (when org-export-ascii-table-widen-columns
500 (let ((org-table-do-narrow nil))
501 (goto-char (point-min))
502 (org-table-map-tables
503 (lambda ()
504 (org-if-unprotected
505 (org-table-align))))))
506 ;; Put quotes around verbatim text
507 (goto-char (point-min))
508 (while (re-search-forward org-verbatim-re nil t)
509 (org-if-unprotected-at (match-beginning 4)
510 (goto-char (match-end 2))
511 (backward-delete-char 1) (insert "'")
512 (goto-char (match-beginning 2))
513 (delete-char 1) (insert "`")
514 (goto-char (match-end 2))))
515 ;; Remove target markers
516 (goto-char (point-min))
517 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t)
518 (org-if-unprotected-at (match-beginning 1)
519 (replace-match "\\1\\2"))))
521 (defun org-html-expand-for-ascii (line)
522 "Handle quoted HTML for ASCII export."
523 (if org-export-html-expand
524 (while (string-match "@<[^<>\n]*>" line)
525 ;; We just remove the tags for now.
526 (setq line (replace-match "" nil nil line))))
527 line)
529 (defun org-export-ascii-wrap (line where)
530 "Wrap LINE at or before WHERE."
531 (let ((ind (org-get-indentation line))
532 pos)
533 (catch 'found
534 (loop for i from where downto (/ where 2) do
535 (and (equal (aref line i) ?\ )
536 (setq pos i)
537 (throw 'found t))))
538 (if pos
539 (concat (substring line 0 pos) "\n"
540 (make-string ind ?\ )
541 (substring line (1+ pos)))
542 line)))
544 (defun org-export-ascii-push-links (link-buffer)
545 "Push out links in the buffer."
546 (when link-buffer
547 ;; We still have links to push out.
548 (insert "\n")
549 (let ((ind ""))
550 (save-match-data
551 (if (save-excursion
552 (re-search-backward
553 "^\\(\\([ \t]*\\)\\|\\(\\*+ \\)\\)[^ \t\n]" nil t))
554 (setq ind (or (match-string 2)
555 (make-string (length (match-string 3)) ?\ )))))
556 (mapc (lambda (x) (insert ind "[" (car x) "]: " (cdr x) "\n"))
557 link-buffer))
558 (insert "\n")))
560 (defun org-ascii-level-start (level title umax &optional lines)
561 "Insert a new level in ASCII export."
562 (let (char (n (- level umax 1)) (ind 0))
563 (if (> level umax)
564 (progn
565 (insert (make-string (* 2 n) ?\ )
566 (char-to-string (nth (% n (length org-export-ascii-bullets))
567 org-export-ascii-bullets))
568 " " title "\n")
569 ;; find the indentation of the next non-empty line
570 (catch 'stop
571 (while lines
572 (if (string-match "^\\* " (car lines)) (throw 'stop nil))
573 (if (string-match "^\\([ \t]*\\)\\S-" (car lines))
574 (throw 'stop (setq ind (org-get-indentation (car lines)))))
575 (pop lines)))
576 (setq org-ascii-current-indentation (cons (* 2 (1+ n)) ind)))
577 (if (or (not (equal (char-before) ?\n))
578 (not (equal (char-before (1- (point))) ?\n)))
579 (insert "\n"))
580 (setq char (nth (- umax level) (reverse org-export-ascii-underline)))
581 (unless org-export-with-tags
582 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
583 (setq title (replace-match "" t t title))))
584 (if org-export-with-section-numbers
585 (setq title (concat (org-section-number level) " " title)))
586 (insert title "\n" (make-string (string-width title) char) "\n")
587 (setq org-ascii-current-indentation '(0 . 0)))))
589 (defun org-insert-centered (s &optional underline)
590 "Insert the string S centered and underline it with character UNDERLINE."
591 (let ((ind (max (/ (- fill-column (string-width s)) 2) 0)))
592 (insert (make-string ind ?\ ) s "\n")
593 (if underline
594 (insert (make-string ind ?\ )
595 (make-string (string-width s) underline)
596 "\n"))))
598 (defvar org-table-colgroup-info nil)
599 (defun org-format-table-ascii (lines)
600 "Format a table for ascii export."
601 (if (stringp lines)
602 (setq lines (org-split-string lines "\n")))
603 (if (not (string-match "^[ \t]*|" (car lines)))
604 ;; Table made by table.el - test for spanning
605 lines
607 ;; A normal org table
608 ;; Get rid of hlines at beginning and end
609 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
610 (setq lines (nreverse lines))
611 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
612 (setq lines (nreverse lines))
613 (when org-export-table-remove-special-lines
614 ;; Check if the table has a marking column. If yes remove the
615 ;; column and the special lines
616 (setq lines (org-table-clean-before-export lines)))
617 ;; Get rid of the vertical lines except for grouping
618 (if org-export-ascii-table-keep-all-vertical-lines
619 lines
620 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info))
621 rtn line vl1 start)
622 (while (setq line (pop lines))
623 (if (string-match org-table-hline-regexp line)
624 (and (string-match "|\\(.*\\)|" line)
625 (setq line (replace-match " \\1" t nil line)))
626 (setq start 0 vl1 vl)
627 (while (string-match "|" line start)
628 (setq start (match-end 0))
629 (or (pop vl1) (setq line (replace-match " " t t line)))))
630 (push line rtn))
631 (nreverse rtn)))))
633 (defun org-colgroup-info-to-vline-list (info)
634 (let (vl new last)
635 (while info
636 (setq last new new (pop info))
637 (if (or (memq last '(:end :startend))
638 (memq new '(:start :startend)))
639 (push t vl)
640 (push nil vl)))
641 (setq vl (nreverse vl))
642 (and vl (setcar vl nil))
643 vl))
645 (provide 'org-ascii)
647 ;; arch-tag: aa96f882-f477-4e13-86f5-70d43e7adf3c
648 ;;; org-ascii.el ends here