From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jambunathan K Subject: Re: org-odt help Date: Tue, 04 Oct 2011 23:59:04 +0530 Message-ID: <81k48kpq4v.fsf@gmail.com> References: <81wrcrhlsz.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:60114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB9kM-0007FA-QP for emacs-orgmode@gnu.org; Tue, 04 Oct 2011 14:29:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RB9kL-0000E4-5V for emacs-orgmode@gnu.org; Tue, 04 Oct 2011 14:29:42 -0400 Received: from mail-qy0-f176.google.com ([209.85.216.176]:36911) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RB9kL-0000Dw-2O for emacs-orgmode@gnu.org; Tue, 04 Oct 2011 14:29:41 -0400 Received: by qyk27 with SMTP id 27so894251qyk.0 for ; Tue, 04 Oct 2011 11:29:40 -0700 (PDT) In-Reply-To: <81wrcrhlsz.fsf@gmail.com> (Jambunathan K.'s message of "Thu, 29 Sep 2011 12:33:56 +0530") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Orgmode --=-=-= Content-Type: text/plain > 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-exp.el-Enhance-org-export-number-lines-to-suppor.patch >From 39ab2a263336ba077c7cd6627a3203c55c5bddba Mon Sep 17 00:00:00 2001 From: Jambunathan K 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 "" ref)) (end-of-line 1) - (insert ""))))) + (insert ""))) + (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 --=-=-=--