emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org-odt help


From: Jambunathan K
Subject: Re: [O] org-odt help
Date: Tue, 04 Oct 2011 23:59:04 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (windows-nt)

> I would like to submit 2 more patches - one to the manual and other to
> org-exp.el.

I am attaching the promised patch to org-exp.el. Can someone review and
commit this change? 

Please note that I have withheld the changes to org-odt & co which make
use of this change.

ps: The patch to org.texi will follow soon - maybe in a day or two.

>From 39ab2a263336ba077c7cd6627a3203c55c5bddba Mon Sep 17 00:00:00 2001
From: Jambunathan K <address@hidden>
Date: Tue, 4 Oct 2011 23:32:35 +0530
Subject: [PATCH] org-exp.el: Enhance `org-export-number-lines' to support odt 
export

* lisp/org-exp.el (org-export-number-lines): Modified.  Add a
new parameter `preprocess' and use this for backend-agnostic
handling of literal examples.

This parameter is currently exercised only by the odt exporter.  Hint:
See future commits.
---
 lisp/org-exp.el |   71 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 9884a31..c62333e 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -46,7 +46,7 @@
 (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
 (declare-function org-table-cookie-line-p "org-table" (line))
 (declare-function org-table-colgroup-line-p "org-table" (line))
-(declare-function org-pop-to-buffer-same-window "org-compat" 
+(declare-function org-pop-to-buffer-same-window "org-compat"
                  (&optional buffer-or-name norecord label))
 
 (autoload 'org-export-generic "org-export-generic" "Export using the generic 
exporter" t)
@@ -2729,7 +2729,54 @@ INDENT was the original indentation of the block."
       (org-add-props rtn nil 'original-indentation indent))))
 
 (defun org-export-number-lines (text &optional skip1 skip2 number cont
-                                    replace-labels label-format)
+                                    replace-labels label-format preprocess)
+  "Apply line numbers to literal examples and handle code references.
+Handle user-specified options under info node `(org)Literal
+examples' and return the modified source block.
+
+TEXT contains the source or example block.
+
+SKIP1 and SKIP2 are the number of lines that are to be skipped at
+the beginning and end of TEXT.  Use these to skip over
+backend-specific lines pre-pended or appended to the original
+source block.
+
+NUMBER is non-nil if the literal example specifies \"+n\" or
+\"-n\" switch. If NUMBER is non-nil add line numbers.
+
+CONT is non-nil if the literal example specifies \"+n\" switch.
+If CONT is nil, start numbering this block from 1.  Otherwise
+continue numbering from the last numbered block.
+
+REPLACE-LABELS is dual-purpose.
+1. It controls the retention of labels in the exported block.
+2. It specifies in what manner the links (or references) to a
+   labelled line be formatted.
+
+REPLACE-LABELS is the symbol `keep' if the literal example
+specifies \"-k\" option, is numeric if the literal example
+specifies \"-r\" option and is nil otherwise.
+
+Handle REPLACE-LABELS as below:
+- If nil, retain labels in the exported block and use
+  user-provided labels for referencing the labelled lines.
+- If it is a number, remove labels in the exported block and use
+  one of line numbers or labels for referencing labelled lines based
+  on NUMBER option.
+- If it is a keep, retain labels in the exported block and use
+  one of line numbers or labels for referencing labelled lines
+  based on NUMBER option.
+
+LABEL-FORMAT is the value of \"-l\" switch associated with
+literal example.  See `org-coderef-label-format'.
+
+PREPROCESS is intended for backend-agnostic handling of source
+block numbering.  When non-nil do the following:
+- do not number the lines
+- always strip the labels from exported block
+- do not make the labelled line a target of an incoming link.
+  Instead mark the labelled line with `org-coderef' property and
+  store the label in it."
   (setq skip1 (or skip1 0) skip2 (or skip2 0))
   (if (not cont) (setq org-export-last-code-line-counter-value 0))
   (with-temp-buffer
@@ -2768,9 +2815,10 @@ INDENT was the original indentation of the block."
 
       (org-goto-line (1+ skip1))
       (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
-       (if number
-           (insert (format fm (incf n)))
-         (forward-char 1))
+       (when number (incf n))
+       (if (or preprocess (not number))
+           (forward-char 1)
+         (insert (format fm n)))
        (when (looking-at lbl-re)
          (setq ref (match-string 3))
          (cond ((numberp replace-labels)
@@ -2783,7 +2831,8 @@ INDENT was the original indentation of the block."
                 ;; lines are numbered, use labels otherwise
                 (goto-char (match-beginning 2))
                 (delete-region (match-beginning 2) (match-end 2))
-                (insert "(" ref ")")
+                (unless preprocess
+                  (insert "(" ref ")"))
                 (push (cons ref (if (> n 0) n (concat "(" ref ")")))
                       org-export-code-refs))
                (t
@@ -2791,15 +2840,19 @@ INDENT was the original indentation of the block."
                 ;; references
                 (goto-char (match-beginning 2))
                 (delete-region (match-beginning 2) (match-end 2))
-                (insert "(" ref ")")
+                (unless preprocess
+                  (insert "(" ref ")"))
                 (push (cons ref (concat "(" ref ")")) org-export-code-refs)))
-         (when (eq org-export-current-backend 'html)
+         (when (and (eq org-export-current-backend 'html) (not preprocess))
            (save-excursion
              (beginning-of-line 1)
              (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
                              ref))
              (end-of-line 1)
-             (insert "</span>")))))
+             (insert "</span>")))
+         (when preprocess
+           (add-text-properties
+            (point-at-bol) (point-at-eol) (list 'org-coderef ref)))))
       (setq org-export-last-code-line-counter-value n)
       (goto-char (point-max))
       (newline)
-- 
1.7.2.3


reply via email to

[Prev in Thread] Current Thread [Next in Thread]