emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: Orgmode <emacs-orgmode@gnu.org>
Subject: Re: org-odt help
Date: Tue, 04 Oct 2011 23:59:04 +0530	[thread overview]
Message-ID: <81k48kpq4v.fsf@gmail.com> (raw)
In-Reply-To: <81wrcrhlsz.fsf@gmail.com> (Jambunathan K.'s message of "Thu, 29 Sep 2011 12:33:56 +0530")

[-- Attachment #1: Type: text/plain, Size: 345 bytes --]


> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-exp.el-Enhance-org-export-number-lines-to-suppor.patch --]
[-- Type: text/x-patch, Size: 5418 bytes --]

From 39ab2a263336ba077c7cd6627a3203c55c5bddba Mon Sep 17 00:00:00 2001
From: Jambunathan K <kjambunathan@gmail.com>
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	other threads:[~2011-10-04 18:29 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <81wrcrhlsz.fsf@gmail.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81k48kpq4v.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).