From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wes Hardaker Subject: here's a working version of org-generic Date: Wed, 15 Apr 2009 12:23:56 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LuAiN-0005xd-1C for emacs-orgmode@gnu.org; Wed, 15 Apr 2009 15:24:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LuAiI-0005wB-T3 for emacs-orgmode@gnu.org; Wed, 15 Apr 2009 15:24:06 -0400 Received: from [199.232.76.173] (port=54838 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LuAiI-0005w3-M9 for emacs-orgmode@gnu.org; Wed, 15 Apr 2009 15:24:02 -0400 Received: from dcn236-43.dcn.davis.ca.us ([168.150.236.43]:34592 helo=wes.hardakers.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LuAiH-0000YD-9c for emacs-orgmode@gnu.org; Wed, 15 Apr 2009 15:24:02 -0400 Received: from localhost (wlap.dyn.hardakers.net [127.0.0.1]) by wes.hardakers.net (Postfix) with ESMTP id 177A839A106 for ; Wed, 15 Apr 2009 12:23:56 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= I have a bunch of random things that I'd like to export org stuff too and it seemed to me that much of the work of writing code to export stuff from org-mode into external documents could be conquered by simple string specifiers. So yesterday I hacked something together that is actually working enough I should be able to use it to other random xml formats, etc. It's far from complete but it's usable by the average elisp hacker. See the todo list at the top for all the things it *doesn't* do (sigh). EG, the demo specifier in the example specifier list (see the code) can be used to take this: Test * level 1 text level 1 *** level 2 text level 2 : this : is : critical ***** level 3 text [[file:foo2.org][level 3]] ***** Another 3 more text level 3 *** level 2 again more text level 2 ******* jump to level 4 level 4 text *** back to 2 To produce this: ====

Test

====
Date: 2009-04-15 12:21:42 PDT
__Table of Contents__ #(1)--level 1 -- #(1.1)--level 2 -- #(1.1.1)--level 3 -- #(1.1.2)--Another 3 -- #(1.2)--level 2 again -- #(1.3)--back to 2 -- #(2)--back to 1 --

1 level 1

text level 1

1.1 level 2

text level 2

   this
  
    is
  
     critical
  

level 3

... -- "In the bathtub of history the truth is harder to hold than the soap, and much more difficult to find." -- Terry Pratchett --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=org-generic.el Content-Transfer-Encoding: quoted-printable ;;; org-generic.el --- ASCII export for Org-mode ;; Copyright (C) 2009 ;; Free Software Foundation, Inc. ;; Author: Wes Hardaker ;; Keywords: outlines, hypermedia, calendar, wp, export ;; Homepage: http://orgmode.org ;; Version: 6.25trans ;; Acks: Much of this code was stolen form the ascii export from Carsten ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;; ---------------------------------------------------------------------- ;; ;; TODO (non-ordered) ;; * handle function references ;; * handle other types of multi-complex-things to do ;; ideas: (t ?- "%s" ?-) ;; * handle indent specifiers better ;; ideas: (4 ?\ "%s") ;; * need flag to remove indents from body text ;; * handle links ;; * handle internationalization strings better ;; * date/author/etc needs improvment ;; * allow specifying of section ordering ;; ideas: :ordering ("header" "toc" "body" "footer") ;; ^ matches current hard coded ordering ;; * err, actually *do* a footer ;; * deal with usage of org globals. ;; *** should we even consider them, or let the per-section specifiers do= it ;; * deal with interactive support for picking a export specifier label ;; * char specifiers that need extra length because of formatting ;; idea: (?- 4) for 4-longer ;; * centering specifier ;; idea: ('center " -- %s -- ") ;; * remove more of the unneeded export-to-ascii copy code ;; * tags ;; * properties ;; * drawers ;; * oh my ;; * optmization (many plist extracts should be in (let) vars ;; * define defcustom spec for the specifier list ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;; ;; ;;; Commentary: (require 'org-exp) (defgroup org-export-generic nil "Options specific for ASCII export of Org-mode files." :tag "Org Export ASCII" :group 'org-export) (defcustom org-export-generic-links-to-notes t "Non-nil means, convert links to notes before the next headline. When nil, the link will be exported in place. If the line becomes long in this way, it will be wrapped." :group 'org-export-generic :type 'boolean) ;;; ASCII export (defvar org-generic-current-indentation nil) ; For communication (defvar org-generic-alist "A assoc list of property lists to specify export definitions" '(("ascii" ;; close to the original ascii specifier. :file-suffix ".txt" :header-prefix "" :header-suffix "" :title-prefix ?=3D :title-format "%s\n" :title-suffix ?=3D :date-export t :date-prefix "" :date-format "Date: %s\n" :date-suffix "" :toc-header-prefix "" :toc-header-format "%s\n" :toc-header-suffix ?=3D :toc-export t :toc-section-numbers t :toc-section-number-format "%s " :toc-format "%s\n"=20=20=20=20 :toc-format-with-todo "%s (*)\n" :toc-indent-char ?\=20 :toc-indent-depth 4=20=20=20=20=20=20=20=20=20 :body-header-section-numbers 3 :body-section-prefix "\n" ; :body-section-header-prefix "\n" ; :body-section-header-format "%s\n" ; :body-section-header-suffix (?\$ ?\# ?^ ?\~ ?\=3D ?\-) :body-section-header-prefix ("" "" "" "* " " + " " - ") :body-section-header-format "%s\n" :body-section-header-suffix (?~ ?=3D ?- "\n" "\n" "\n") ; :body-section-marker-prefix "" ; :body-section-marker-chars (?\$ ?\# ?^ ?\~ ?\=3D ?\-) ; :body-section-marker-suffix "\n" :body-line-export-preformated t :body-line-format "%s\n" :body-line-wrap 75 ; :body-text-prefix "\n" ; :body-text-suffix "\n" :body-bullet-list-prefix (?* ?+ ?-) ; :body-bullet-list-suffix (?* ?+ ?-) :body-bullet-indent-size 4 ) ("html" ;; simple html output :file-suffix ".html" :header-prefix "" :title-format "

%s

\n\n" :date-export t :date-format "
Date: %s
\n\n" :toc-export nil :body-header-section-numbers 3 :body-section-header-prefix ("

" "

" "

" "

" "

" "
") :body-section-header-format "%s" :body-section-header-suffix ("
\n" "\n" "\n" "\n" "\n" "\n") :body-section-prefix "\n" :body-section-suffix "\n" ; :body-section-prefix ("\n" "\n" "\n") ; :body-section-suffix ("\n" "\n" "\n") :body-line-export-preformated t :body-line-format "%s\n" :body-text-prefix "

\n" :body-text-suffix "

\n" :body-bullet-list-prefix (?* ?+ ?-) ; :body-bullet-list-suffix (?* ?+ ?-) :body-bullet-indent-size 4 ) ("demo" ;; this tries to use every specifier for demo purposes :file-suffix ".txt" :header-prefix "
\n" :header-suffix "
\n" :title-prefix ?=3D :title-format "

%s

\n" :title-suffix ?=3D :date-export t :date-prefix "" :date-format "
Date: %s
\n\n" :date-suffix "
" :toc-export t :toc-header-prefix "\n" :toc-header-format "__%s__\n" :toc-header-suffix "\n\n" :toc-suffix "\n" :toc-section-numbers t :toc-section-number-format "\#(%s)" :toc-format "--%s--\n"=20=20=20=20 :toc-format-with-todo "!!%s!!\n" :toc-indent-char ?\=20 :toc-indent-depth 4=20=20=20=20=20=20=20=20=20 :body-header-section-numbers 3 ; t =3D all, nil =3D none ; lists indicate different things per level ; list contents or straight value can either be a ; ?x char reference for printing strings that match the header len ; "" string to print directly :body-section-header-prefix ("

" "

" "

" "

" "

" "
") :body-section-header-format "%s" :body-section-header-suffix ("
\n" "\n" "\n" "\n" "\n" "\n") ; section prefixes/suffixes can be direct strings or lists as well :body-section-prefix "\n" :body-section-suffix "\n" ; :body-section-prefix ("\n" "\n" "\n") ; :body-section-suffix ("\n" "\n" "\n") ; if preformated text should be included (eg, : prefixed) :body-line-export-preformated t :body-line-fixed-format "
\n%s\n
\n" ; other body lines :body-line-format "%s" :body-line-wrap 60 ; wrap at 60 chars ; print above and below all body parts :body-text-prefix "

\n" :body-text-suffix "

\n" ) )) (setq org-generic-export-type "demo") ;;;###autoload (defun org-export-as-generic (arg) "Export the outline as generic output. If there is an active region, export only the region. The prefix ARG specifies how many levels of the outline should become underlined headlines. The default is 3." (interactive "P") (setq-default org-todo-line-regexp org-todo-line-regexp) (let* ((opt-plist (org-combine-plists (org-default-export-plist) (org-infile-export-plist))) (region-p (org-region-active-p)) (rbeg (and region-p (region-beginning))) (rend (and region-p (region-end))) (subtree-p (when region-p (save-excursion (goto-char rbeg) (and (org-at-heading-p) (>=3D (org-end-of-subtree t t) rend))))) (level-offset (if subtree-p (save-excursion (goto-char rbeg) (+ (funcall outline-level) (if org-odd-levels-only 1 0))) 0)) (opt-plist (setq org-export-opt-plist (if subtree-p (org-export-add-subtree-options opt-plist rbeg) opt-plist))) (export-plist (cdr (assoc org-generic-export-type org-generic-alist))) (custom-times org-display-custom-times) (org-generic-current-indentation '(0 . 0)) (level 0) (old-level 0) line txt lastwastext (umax nil) (umax-toc nil) (case-fold-search nil) (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer)))) (filesuffix (or (plist-get export-plist :file-suffix) ".foo")) (filename (concat (file-name-as-directory (org-export-directory :ascii opt-plist)) (file-name-sans-extension (or (and subtree-p (org-entry-get (region-beginning) "EXPORT_FILE_NAME" t)) (file-name-nondirectory bfname))) filesuffix)) (filename (if (equal (file-truename filename) (file-truename bfname)) (concat filename filesuffix) filename)) (buffer (find-file-noselect filename)) (org-levels-open (make-vector org-level-max nil)) (odd org-odd-levels-only) (date (plist-get opt-plist :date)) (author (plist-get opt-plist :author)) (title (or (and subtree-p (org-export-get-title-from-subtree)) (plist-get opt-plist :title) (and (not (plist-get opt-plist :skip-before-1st-heading)) (org-export-grab-title-from-buffer)) (file-name-sans-extension (file-name-nondirectory bfname)))) (email (plist-get opt-plist :email)) (language (plist-get opt-plist :language)) (quote-re0 (concat "^[ \t]*" org-quote-string "\\>")) ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)")) (todo nil) (lang-words nil) (region (buffer-substring (if (org-region-active-p) (region-beginning) (point-min)) (if (org-region-active-p) (region-end) (point-max)))) (lines (org-split-string (org-export-preprocess-string region :for-ascii t :skip-before-1st-heading (plist-get opt-plist :skip-before-1st-heading) :drawers (plist-get opt-plist :drawers) :tags (plist-get opt-plist :tags) :priority (plist-get opt-plist :priority) :footnotes (plist-get opt-plist :footnotes) :timestamps (plist-get opt-plist :timestamps) :todo-keywords (plist-get opt-plist :todo-keywords) :verbatim-multiline t :select-tags (plist-get opt-plist :select-tags) :exclude-tags (plist-get opt-plist :exclude-tags) :archived-trees (plist-get opt-plist :archived-trees) :add-text (plist-get opt-plist :text)) "\n")) thetoc have-headings first-heading-pos table-open table-buffer link-buffer link desc desc0 rpl wrap) (let ((inhibit-read-only t)) (org-unmodified (remove-text-properties (point-min) (point-max) '(:org-license-to-kill t)))) (setq org-min-level (org-get-min-level lines level-offset)) (setq org-last-level org-min-level) (org-init-section-numbers) (find-file-noselect filename) (setq lang-words (or (assoc language org-export-language-setup) (assoc "en" org-export-language-setup))) (switch-to-buffer-other-window buffer) (erase-buffer) (fundamental-mode) ;; create local variables for all options, to make sure all called ;; functions get the correct information (mapc (lambda (x) (set (make-local-variable (nth 2 x)) (plist-get opt-plist (car x)))) org-export-plist-vars) (org-set-local 'org-odd-levels-only odd) (setq umax (if arg (prefix-numeric-value arg) org-export-headline-levels)) (setq umax-toc (if (integerp org-export-with-toc) (min org-export-with-toc umax) umax)) ;; File header (if title (insert (org-export-generic-header title export-plist :title-prefix :title-format :title-suffix))) (if (and (or author email) org-export-author-info) (insert (concat (nth 1 lang-words) ": " (or author "") (if email (concat " <" email ">") "") "\n"))) (cond ((and date (string-match "%" date)) (setq date (format-time-string date))) (date) (t (setq date (format-time-string "%Y-%m-%d %T %Z")))) (if (and date org-export-time-stamp-file (plist-get export-plist :date-export)) (insert (org-export-generic-header date export-plist :date-prefix :date-format :date-suffix))) (if (and org-export-with-toc (plist-get export-plist :toc-export)) (progn (push (org-export-generic-header (nth 3 lang-words) export-plist :toc-header-prefix :toc-header-format :toc-header-suffix) thetoc) (mapc '(lambda (line) (if (string-match org-todo-line-regexp line) ;; This is a headline (progn (setq have-headings t) (setq level (- (match-end 1) (match-beginning 1) level-offset) level (org-tr-level level) txt (match-string 3 line) todo (or (and org-export-mark-todo-in-toc (match-beginning 2) (not (member (match-string 2 line) org-done-keywords))) ; TODO, not DONE (and org-export-mark-todo-in-toc (=3D level umax-toc) (org-search-todo-below line lines level)))) (setq txt (org-html-expand-for-generic txt)) (while (string-match org-bracket-link-regexp txt) (setq txt (replace-match (match-string (if (match-end 2) 3 1) txt) t t txt))) (if (and (memq org-export-with-tags '(not-in-toc nil)) (string-match (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$") txt)) (setq txt (replace-match "" t t txt))) (if (string-match quote-re0 txt) (setq txt (replace-match "" t t txt))) (if (<=3D level umax-toc) (progn (push (concat (make-string (* (max 0 (- level org-min-level)) (plist-get export-plist :toc-indent-depth)) (plist-get export-plist :toc-indent-char)) (if (and org-export-with-section-numbers (plist-get export-plist :toc-section-numbers)) (format (plist-get export-plist :toc-section-number-format) (org-section-number level)) "") (format (if todo (plist-get export-plist :toc-format-with-todo) (plist-get export-plist :toc-format))=20 txt)) thetoc) (setq org-last-level level)) )))) lines) (if (plist-get export-plist :toc-suffix) (push (plist-get export-plist :toc-suffix) thetoc)) (setq thetoc (if have-headings (nreverse thetoc) nil)))) (org-init-section-numbers) (while (setq line (pop lines)) (when (and link-buffer (string-match "^\\*+ " line)) (org-export-generic-push-links (nreverse link-buffer)) (setq link-buffer nil)) (setq wrap nil) ;; Remove the quoted HTML tags. ;; XXX (setq line (org-html-expand-for-generic line)) ;; Replace links with the description when possible ;; XXX (while (string-match org-bracket-link-regexp line) (setq link (match-string 1 line) desc0 (match-string 3 line) desc (or desc0 (match-string 1 line))) (if (and (> (length link) 8) (equal (substring link 0 8) "coderef:")) (setq line (replace-match (format (org-export-get-coderef-format (substring link 8) desc) (cdr (assoc (substring link 8) org-export-code-refs))) t t line)) (setq rpl (concat "["=20 (or (match-string 3 line) (match-string 1 line)) "]")) (when (and desc0 (not (equal desc0 link))) (if org-export-generic-links-to-notes (push (cons desc0 link) link-buffer) (setq rpl (concat rpl " (" link ")") wrap (+ (length line) (- (length (match-string 0))) (length desc))))) (setq line (replace-match rpl t t line)))) (when custom-times (setq line (org-translate-time line))) (cond ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line) (if (and lastwastext (plist-get export-plist :body-text-suffix)) (insert (plist-get export-plist :body-text-suffix))) ;; a Headline (setq first-heading-pos (or first-heading-pos (point))) (setq level (org-tr-level (- (match-end 1) (match-beginning 1) level-offset)) txt (match-string 2 line)) (org-generic-level-start level old-level txt umax export-plist lines) (setq old-level level) (setq lastwastext nil)) ((and org-export-with-tables (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line)) ;; a Table (if (not table-open) ;; New table starts (setq table-open t table-buffer nil)) ;; Accumulate lines (setq table-buffer (cons line table-buffer)) (when (or (not lines) (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" (car lines)))) (setq table-open nil table-buffer (nreverse table-buffer)) (insert (mapconcat (lambda (x) (org-fix-indentation x org-generic-current-indentation)) (org-format-table-generic table-buffer) "\n") "\n"))) (t (if (string-match "^\\([ \t]*\\)\\([-+*][ \t]+\\)\\(.*?\\)\\( ::\\)" line) (setq line (replace-match "\\1\\3:" t nil line))) (setq line (org-fix-indentation line org-generic-current-indentation)) ;; Remove forced line breaks (if (string-match "\\\\\\\\[ \t]*$" line) (setq line (replace-match "" t t line))) (when (not lastwastext) (if (plist-get export-plist :body-text-prefix) (insert (plist-get export-plist :body-text-prefix))) (setq lastwastext t)) (if (and org-export-with-fixed-width (plist-get export-plist :body-line-export-preformated) (string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line)) ;; pre-formated string (progn (setq line (replace-match "\\1" nil nil line)) (setq line (format=20 (or (plist-get export-plist :body-line-fixed-format) "%s") line))) ;; possibly wrap string (if (plist-get export-plist :body-line-wrap) ;; XXX: was dependent on wrap var which was calculated by??? (if (> (length line) (plist-get export-plist :body-line-wrap)) (setq line (org-export-generic-wrap line (plist-get export-plist :body-line-wrap))) (setq line line)))) (insert=20 (format (or (plist-get export-plist :body-line-format) "%s") line))))) (org-export-generic-push-links (nreverse link-buffer)) (normal-mode) ;; insert the table of contents (when thetoc (goto-char (point-min)) (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t) (progn (goto-char (match-beginning 0)) (replace-match "")) (goto-char first-heading-pos)) (mapc 'insert thetoc) (or (looking-at "[ \t]*\n[ \t]*\n") (insert "\n\n"))) ;; Convert whitespace place holders (goto-char (point-min)) (let (beg end) (while (setq beg (next-single-property-change (point) 'org-whitespace= )) (setq end (next-single-property-change beg 'org-whitespace)) (goto-char beg) (delete-region beg end) (insert (make-string (- end beg) ?\ )))) (save-buffer) ;; remove display and invisible chars (let (beg end) (goto-char (point-min)) (while (setq beg (next-single-property-change (point) 'display)) (setq end (next-single-property-change beg 'display)) (delete-region beg end) (goto-char beg) (insert "=3D>")) (goto-char (point-min)) (while (setq beg (next-single-property-change (point) 'org-cwidth)) (setq end (next-single-property-change beg 'org-cwidth)) (delete-region beg end) (goto-char beg))) (goto-char (point-min)))) (defun org-export-generic-format (export-plist prop &optional len n reverse) "converts a property specification to a string given types of properties" (let* ((prefixtype (plist-get export-plist prop)) subtype) (cond ((null prefixtype) "") ((and len (characterp prefixtype)) ;; sequence of chars (concat (make-string len prefixtype) "\n")) ((stringp prefixtype) prefixtype) ((and n (listp prefixtype)) (if reverse (setq prefixtype (reverse prefixtype))) (setq subtype (if (> n (length prefixtype)) (car (last prefixtype)) (nth (1- n) prefixtype))) (if (stringp subtype) subtype (concat (make-string len subtype) "\n"))) (t "")) )) (defun org-export-generic-header (header export-plist prefixprop formatprop postfixprop &optional n reverse) "convert a header to an output string given formatting property names" (let* ((formatspec (plist-get export-plist formatprop)) (len (length header))) (concat (org-export-generic-format export-plist prefixprop len n reverse) (format (or formatspec "%s") header) (org-export-generic-format export-plist postfixprop len n reverse)) )) (defun org-export-generic-preprocess (parameters) "Do extra work for ASCII export" ;; Put quotes around verbatim text (goto-char (point-min)) (while (re-search-forward org-verbatim-re nil t) (goto-char (match-end 2)) (backward-delete-char 1) (insert "'") (goto-char (match-beginning 2)) (delete-char 1) (insert "`") (goto-char (match-end 2))) ;; Remove target markers (goto-char (point-min)) (while (re-search-forward "<<]*\\)>>>?\\([ \t]*\\)" nil t) (replace-match "\\1\\2"))) (defun org-html-expand-for-generic (line) "Handle quoted HTML for ASCII export." (if org-export-html-expand (while (string-match "@<[^<>\n]*>" line) ;; We just remove the tags for now. (setq line (replace-match "" nil nil line)))) line) (defun org-export-generic-wrap (line where) "Wrap LINE at or before WHERE." (let* ((ind (org-get-indentation line)) (indstr (make-string ind ?\ )) (len (length line)) (result "") pos didfirst) (while (> len where) (catch 'found (loop for i from where downto (/ where 2) do (and (equal (aref line i) ?\ ) (setq pos i) (throw 'found t)))) (if pos (progn (setq result (concat result (if didfirst indstr "") (substring line 0 pos) "\n")) (setq didfirst t) (setq line (substring line (1+ pos))) (setq len (length line))) (setq result (concat result line)) (setq len 0))) (concat result indstr line))) =09=09=09=20=20=20 (defun org-export-generic-push-links (link-buffer) "Push out links in the buffer." (when link-buffer ;; We still have links to push out. (insert "\n") (let ((ind "")) (save-match-data (if (save-excursion (re-search-backward "^\\(\\([ \t]*\\)\\|\\(\\*+ \\)\\)[^ \t\n]" nil t)) (setq ind (or (match-string 2) (make-string (length (match-string 3)) ?\ ))))) (mapc (lambda (x) (insert ind "[" (car x) "]: " (cdr x) "\n")) link-buffer)) (insert "\n"))) (defun org-generic-level-start (level old-level title umax export-plist &optional lines) "Insert a new level in a generic export." (let ((n (- level umax 1)) (ind 0) (diff (- level old-level)) (counter 0) (secnums (plist-get export-plist :body-header-section-numbers)) char) (unless org-export-with-tags (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") tit= le) (setq title (replace-match "" t t title)))) (cond ;; going deeper ((> level old-level) (while (< (+ old-level counter) (1- level)) (insert (org-export-generic-format export-plist :body-section-prefix 0 (+ old-level counter))) (setq counter (1+ counter)) )) ;; going up ((< level old-level) (while (> (- old-level counter) (1- level)) (insert (org-export-generic-format export-plist :body-section-suffix 0 (- old-level counter))) (setq counter (1+ counter)) )) ;; same level ((=3D level old-level) (insert=20 (org-export-generic-format export-plist :body-section-suffix 0 level= )) ) ) (insert (org-export-generic-format export-plist :body-section-prefix 0 level)) (if (and org-export-with-section-numbers secnums (or (not (numberp secnums)) (< level secnums))) (setq title (concat (org-section-number level) " " title))) (insert (org-export-generic-header title export-plist :body-section-header-prefix :body-section-header-format :body-section-header-suffix level)) (setq org-generic-current-indentation '(0 . 0)))) (defun org-insert-centered (s &optional underline) "Insert the string S centered and underline it with character UNDERLINE." (let ((ind (max (/ (- fill-column (string-width s)) 2) 0))) (insert (make-string ind ?\ ) s "\n") (if underline (insert (make-string ind ?\ ) (make-string (string-width s) underline) "\n")))) (defvar org-table-colgroup-info nil) (defun org-format-table-generic (lines) "Format a table for ascii export." (if (stringp lines) (setq lines (org-split-string lines "\n"))) (if (not (string-match "^[ \t]*|" (car lines))) ;; Table made by table.el - test for spanning lines ;; A normal org table ;; Get rid of hlines at beginning and end (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines))) (setq lines (nreverse lines)) (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines))) (setq lines (nreverse lines)) (when org-export-table-remove-special-lines ;; Check if the table has a marking column. If yes remove the ;; column and the special lines (setq lines (org-table-clean-before-export lines))) ;; Get rid of the vertical lines except for grouping (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info)) rtn line vl1 start) (while (setq line (pop lines)) (if (string-match org-table-hline-regexp line) (and (string-match "|\\(.*\\)|" line) (setq line (replace-match " \\1" t nil line))) (setq start 0 vl1 vl) (while (string-match "|" line start) (setq start (match-end 0)) (or (pop vl1) (setq line (replace-match " " t t line))))) (push line rtn)) (nreverse rtn)))) (defun org-colgroup-info-to-vline-list (info) (let (vl new last) (while info (setq last new new (pop info)) (if (or (memq last '(:end :startend)) (memq new '(:start :startend))) (push t vl) (push nil vl))) (setq vl (nreverse vl)) (and vl (setcar vl nil)) vl)) (provide 'org-generic) ;;; org-generic.el ends here --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--