emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Starting source code export at non-zero (-n value)
@ 2016-05-17  3:33 Brian Carlson
  2016-05-20 20:48 ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Brian Carlson @ 2016-05-17  3:33 UTC (permalink / raw)
  To: emacs-orgmode

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

Hello other org mode aficionados! (I apologize for the errant email I 
send a minute ago. )

I have created a (possible) patch to the export (ox.el and other 
ox-XXX.el) files that allow for "source code" and "example" blocks to 
have line numbers starting at an arbitrary number. Before the 
(wonderful) ox redesign I used to have advice around some functions. I 
hadn't needed this functionality for a while, but now that I did I 
thought I would share.


The code is written with the following design:

-n   is the same as -n 1 : The functionality is unchanged
+n   is the same as +n 1 :  The functionality is unchanged

-n X   will "reset" and start new code block starting at line X
+n X   will "add" X to the last line of the block before.


========
example:
* Heading 1

   * ~-n 10~
     #+BEGIN_SRC emacs-lisp -n 10
       (save-excursion             ;; This is line 10
          (goto-char (point-min))) ;; 11
     #+END_SRC
   * ~-n~
     #+BEGIN_SRC emacs-lisp -n
       (save-excursion           ;; line 1
          (goto-char (point-min))) ;; line 2
     #+END_SRC
   * ~+n 155~
     #+BEGIN_SRC emacs-lisp +n 155
       (save-excursion            ;; line 157
          (goto-char (point-min))) ;; line 158
     #+END_SRC

Gives the following "Text - ascii output"


1 Heading 1
===========

   * `-n 10'
     ,----
     | 10  (save-excursion             ;; This is line 10
     | 11     (goto-char (point-min))) ;; 11
     `----
   * `-n'
     ,----
     | 1  (save-excursion           ;; line 1
     | 2     (goto-char (point-min))) ;; line 2
     `----
   * `+n 155'
     ,----
     | 157  (save-excursion            ;; line 157
     | 158     (goto-char (point-min))) ;; line 158
     `----


I have tested the code (using make test) and generated (hand verified) 
the LaTeX and HTML output. ODT has an issue already with +n in that each 
code block starts at line 1. (I did not address that).


I have included the git format patch output.

This is a fairly small set of changes, but I do assign the Copyright to 
the Free Software Foundation.


Thanks,
;-b

[-- Attachment #2: 0001-ox-provide-n-offset-functionality.patch --]
[-- Type: text/x-patch, Size: 7664 bytes --]

From 6b4db0a978cc3492f0d0ac7e29008de6846fbe4a Mon Sep 17 00:00:00 2001
From: Brian Carlson <hacker@abutilize.com>
Date: Mon, 16 May 2016 10:58:01 -0400
Subject: [PATCH] ox: provide [+-]n <offset> functionality

---
 contrib/lisp/ox-groff.el |  4 ++--
 lisp/org-element.el      | 16 +++++++++++-----
 lisp/ox-html.el          |  4 ++--
 lisp/ox-latex.el         |  4 ++--
 lisp/ox-odt.el           |  4 ++--
 lisp/ox.el               | 16 ++++++++++------
 6 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/contrib/lisp/ox-groff.el b/contrib/lisp/ox-groff.el
index b49edce..517da9a 100644
--- a/contrib/lisp/ox-groff.el
+++ b/contrib/lisp/ox-groff.el
@@ -1488,9 +1488,9 @@ contextual information."
          (custom-env (and lang
                           (cadr (assq (intern lang)
                                       org-groff-custom-lang-environments))))
-         (num-start (case (org-element-property :number-lines src-block)
+         (num-start (case (car (org-element-property :number-lines src-block))
                       (continued (org-export-get-loc src-block info))
-                      (new 0)))
+                      (new (or (cdr (org-element-property :number-lines src-block)) 0))))
          (retain-labels (org-element-property :retain-labels src-block))
          (caption (and (not (org-export-read-attribute
 			     :attr_groff src-block :disable-caption))
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 368da60..65f9833 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -1896,8 +1896,11 @@ containing `:begin', `:end', `:number-lines', `:preserve-indent',
 		 ;; Switches analysis
 		 (number-lines
 		  (cond ((not switches) nil)
-			((string-match "-n\\>" switches) 'new)
-			((string-match "+n\\>" switches) 'continued)))
+			((string-match "-n *\\([0-9]+\\)" switches) (cons 'new (- (string-to-number (match-string 1 switches)) 1 )))
+			((string-match "+n *\\([0-9]+\\)" switches) (cons 'continued (- (string-to-number (match-string 1 switches)) 1 )))
+			((string-match "-n" switches) (cons 'new 0))
+			((string-match "+n" switches) (cons 'continued 0))
+			))
 		 (preserve-indent
 		  (and switches (string-match "-i\\>" switches)))
 		 ;; Should labels be retained in (or stripped from) example
@@ -2393,7 +2396,7 @@ Assume point is at the beginning of the block."
 		    (looking-at
 		     (concat "^[ \t]*#\\+BEGIN_SRC"
 			     "\\(?: +\\(\\S-+\\)\\)?"
-			     "\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?"
+			     "\\(\\(?: +\\(?:-l \".+\"\\|[+-]n *[[:digit:]]+\\|[+-][[:alpha:]]\\)\\)+\\)?"
 			     "\\(.*\\)[ \t]*$"))
 		    (org-match-string-no-properties 1)))
 		 ;; Get switches.
@@ -2403,8 +2406,11 @@ Assume point is at the beginning of the block."
 		 ;; Switches analysis
 		 (number-lines
 		  (cond ((not switches) nil)
-			((string-match "-n\\>" switches) 'new)
-			((string-match "+n\\>" switches) 'continued)))
+			((string-match "-n *\\([0-9]+\\)" switches) (cons 'new (- (string-to-number (match-string 1 switches)) 1 )))
+			((string-match "+n *\\([0-9]+\\)" switches) (cons 'continued (- (string-to-number (match-string 1 switches)) 1 )))
+			((string-match "-n" switches) (cons 'new 0))
+			((string-match "+n" switches) (cons 'continued 0))
+			))
 		 (preserve-indent (and switches
 				       (string-match "-i\\>" switches)))
 		 (label-fmt
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index b188c38..5503d9e 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2209,9 +2209,9 @@ a plist used as a communication channel."
 	 ;; Does the src block contain labels?
 	 (retain-labels (org-element-property :retain-labels element))
 	 ;; Does it have line numbers?
-	 (num-start (case (org-element-property :number-lines element)
+	 (num-start (case (car (org-element-property :number-lines element))
 		      (continued (org-export-get-loc element info))
-		      (new 0))))
+		      (new (or (cdr (org-element-property :number-lines element)) 0)))))
     (org-html-do-format-code code lang refs retain-labels num-start)))
 
 \f
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 7fa68c5..0159d48 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2762,9 +2762,9 @@ contextual information."
 	   (custom-env (and lang
 			    (cadr (assq (intern lang)
 					org-latex-custom-lang-environments))))
-	   (num-start (case (org-element-property :number-lines src-block)
+	   (num-start (case (car (org-element-property :number-lines src-block))
 			(continued (org-export-get-loc src-block info))
-			(new 0)))
+			(new (or (cdr (org-element-property :number-lines src-block)) 0))))
 	   (retain-labels (org-element-property :retain-labels src-block))
 	   (attributes (org-export-read-attribute :attr_latex src-block))
 	   (float (plist-get attributes :float))
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index d996689..9acf3c6 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -3168,9 +3168,9 @@ and prefix with \"OrgSrc\".  For example,
 	 ;; Does the src block contain labels?
 	 (retain-labels (org-element-property :retain-labels element))
 	 ;; Does it have line numbers?
-	 (num-start (case (org-element-property :number-lines element)
+	 (num-start (case (car (org-element-property :number-lines element))
 		      (continued (org-export-get-loc element info))
-		      (new 0))))
+		      (new (or (cdr (org-element-property :number-lines element)) 0)))))
     (org-odt-do-format-code code info lang refs retain-labels num-start)))
 
 (defun org-odt-src-block (src-block _contents info)
diff --git a/lisp/ox.el b/lisp/ox.el
index 5ad17ec..c05f55e 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -4148,9 +4148,9 @@ error if no block contains REF."
 	      (when (re-search-backward ref-re nil t)
 		(cond
 		 ((org-element-property :use-labels el) ref)
-		 ((eq (org-element-property :number-lines el) 'continued)
+		 ((eq (car (org-element-property :number-lines el)) 'continued)
 		  (+ (org-export-get-loc el info) (line-number-at-pos)))
-		 (t (line-number-at-pos)))))))
+		 (t (+ (or (cdr (org-element-property :number-lines el)) 0) (line-number-at-pos))))))))
 	info 'first-match)
       (signal 'org-link-broken (list ref))))
 
@@ -4467,15 +4467,19 @@ ELEMENT is excluded from count."
 	 ;; Only count lines from src-block and example-block elements
 	 ;; with a "+n" or "-n" switch.  A "-n" switch resets counter.
 	 ((not (memq (org-element-type el) '(src-block example-block))) nil)
-	 ((let ((linums (org-element-property :number-lines el)))
+	 ((let* ((linums (org-element-property :number-lines el)))
 	    (when linums
 	      ;; Accumulate locs or reset them.
 	      (let ((lines (org-count-lines
 			    (org-trim (org-element-property :value el)))))
-		(setq loc (if (eq linums 'new) lines (+ loc lines))))))
+		(setq loc (if (eq (car linums) 'new)
+			      (+ lines (cdr linums))
+			    (+ loc lines (cdr linums)))))))
 	  ;; Return nil to stay in the loop.
 	  nil)))
       info 'first-match)
+    (if (eq (car (org-element-property :number-lines element)) 'continued)
+	(setq loc (+ (or (cdr (org-element-property :number-lines element)) 0) loc)))
     ;; Return value.
     loc))
 
@@ -4573,9 +4577,9 @@ code."
       (let* ((refs (and (org-element-property :retain-labels element)
 			(cdr code-info)))
 	     ;; Handle line numbering.
-	     (num-start (cl-case (org-element-property :number-lines element)
+	     (num-start (cl-case (car (org-element-property :number-lines element))
 			  (continued (org-export-get-loc element info))
-			  (new 0)))
+			  (new (or (cdr (org-element-property :number-lines element)) 0))))
 	     (num-fmt
 	      (and num-start
 		   (format "%%%ds  "
-- 
2.8.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: Starting source code export at non-zero (-n value)
  2016-05-17  3:33 Starting source code export at non-zero (-n value) Brian Carlson
@ 2016-05-20 20:48 ` Nicolas Goaziou
  2016-05-22 15:57   ` Brian Carlson
  2016-05-23  4:00   ` PATCH: ox: " Brian Carlson
  0 siblings, 2 replies; 12+ messages in thread
From: Nicolas Goaziou @ 2016-05-20 20:48 UTC (permalink / raw)
  To: Brian Carlson; +Cc: emacs-orgmode

Hello,

Brian Carlson <hacker@abutilize.com> writes:

> Hello other org mode aficionados! (I apologize for the errant email I 
> send a minute ago. )
>
> I have created a (possible) patch to the export (ox.el and other 
> ox-XXX.el) files that allow for "source code" and "example" blocks to 
> have line numbers starting at an arbitrary number. Before the 
> (wonderful) ox redesign I used to have advice around some functions. I 
> hadn't needed this functionality for a while, but now that I did I 
> thought I would share.
>
>
> The code is written with the following design:
>
> -n   is the same as -n 1 : The functionality is unchanged
> +n   is the same as +n 1 :  The functionality is unchanged
>
> -n X   will "reset" and start new code block starting at line X
> +n X   will "add" X to the last line of the block before.

Thank you for the patch. It looks like an useful addition to Org. Some
comments follow.

> From 6b4db0a978cc3492f0d0ac7e29008de6846fbe4a Mon Sep 17 00:00:00 2001
> From: Brian Carlson <hacker@abutilize.com>
> Date: Mon, 16 May 2016 10:58:01 -0400
> Subject: [PATCH] ox: provide [+-]n <offset> functionality

Here you need to specify all the functions being modified. You may want
to look at other commit messages in the repository.

> @@ -1488,9 +1488,9 @@ contextual information."
>           (custom-env (and lang
>                            (cadr (assq (intern lang)
>                                        org-groff-custom-lang-environments))))
> -         (num-start (case (org-element-property :number-lines src-block)
> +         (num-start (case (car (org-element-property :number-lines src-block))
>                        (continued (org-export-get-loc src-block info))
> -                      (new 0)))
> +                      (new (or (cdr (org-element-property :number-lines src-block)) 0))))

This pattern appears often in your patch, and, of course in the code
base. I suggest to factorize it out.  Indeed, we could take advantage of
the new behaviour of `org-export-get-loc' that your patch introduces.

IIUC, the new `org-export-get-loc' returns the number for the first line
of the current block, not the number of the last line in the previous
block, like it used to do. It can then includes the construct above:

  (pcase (org-element-property :number-lines src-block)
    ;; No need to compute line numbers before this one.
    (`(new . ,n) (or n 2))
    (`(continued . ,_)
     ;; Count all lines above, up to the first block that has "new" line
     ;; numbering.
     (let ((loc 0))
       (org-element-map (plist-get info :parse-tree)
           ...))))

Of course, tests would have to be changed or updated accordingly.

> -			((string-match "-n\\>" switches) 'new)
> -			((string-match "+n\\>" switches) 'continued)))
> +			((string-match "-n *\\([0-9]+\\)" switches) (cons 'new (- (string-to-number (match-string 1 switches)) 1 )))

There is a spurious white space after the last 1.

> +			((string-match "+n *\\([0-9]+\\)" switches) (cons 'continued (- (string-to-number (match-string 1 switches)) 1 )))

Ditto.

> +			((string-match "-n" switches) (cons 'new 0))
> +			((string-match "+n" switches) (cons 'continued 0))
> +			))

These parens should be moved at the end of the previous line.

>  		 (preserve-indent
>  		  (and switches (string-match "-i\\>" switches)))
>  		 ;; Should labels be retained in (or stripped from) example
> @@ -2393,7 +2396,7 @@ Assume point is at the beginning of the block."
>  		    (looking-at
>  		     (concat "^[ \t]*#\\+BEGIN_SRC"
>  			     "\\(?: +\\(\\S-+\\)\\)?"
> -			     "\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?"
> +			     "\\(\\(?: +\\(?:-l \".+\"\\|[+-]n *[[:digit:]]+\\|[+-][[:alpha:]]\\)\\)+\\)?"

I don't think "[-+][[:alpha:]]" is correct here and neither was [-+][A-Za-z].  We
only want to match valid switches: k, r and i. Besides, there is no +k,
+r or +i. Thus, it should be "-[iIkKrR]".

>  			     "\\(.*\\)[ \t]*$"))
>  		    (org-match-string-no-properties 1)))
>  		 ;; Get switches.
> @@ -2403,8 +2406,11 @@ Assume point is at the beginning of the block."
>  		 ;; Switches analysis
>  		 (number-lines
>  		  (cond ((not switches) nil)
> -			((string-match "-n\\>" switches) 'new)
> -			((string-match "+n\\>" switches) 'continued)))
> +			((string-match "-n *\\([0-9]+\\)" switches) (cons 'new (- (string-to-number (match-string 1 switches)) 1 )))
> +			((string-match "+n *\\([0-9]+\\)" switches) (cons 'continued (- (string-to-number (match-string 1 switches)) 1 )))
> +			((string-match "-n" switches) (cons 'new 0))
> +			((string-match "+n" switches) (cons 'continued 0))
> +			))

See above.

> diff --git a/lisp/ox.el b/lisp/ox.el
> index 5ad17ec..c05f55e 100644
> --- a/lisp/ox.el
> +++ b/lisp/ox.el
> @@ -4148,9 +4148,9 @@ error if no block contains REF."
>  	      (when (re-search-backward ref-re nil t)
>  		(cond
>  		 ((org-element-property :use-labels el) ref)
> -		 ((eq (org-element-property :number-lines el) 'continued)
> +		 ((eq (car (org-element-property :number-lines el)) 'continued)
>  		  (+ (org-export-get-loc el info) (line-number-at-pos)))
> -		 (t (line-number-at-pos)))))))
> +		 (t (+ (or (cdr (org-element-property :number-lines el)) 0) (line-number-at-pos))))))))

Here, the last two branches of the cond could be replaced with a single
one calling the new `org-export-get-loc'.

WDYT?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Starting source code export at non-zero (-n value)
  2016-05-20 20:48 ` Nicolas Goaziou
@ 2016-05-22 15:57   ` Brian Carlson
  2016-05-23  4:00   ` PATCH: ox: " Brian Carlson
  1 sibling, 0 replies; 12+ messages in thread
From: Brian Carlson @ 2016-05-22 15:57 UTC (permalink / raw)
  To: emacs-orgmode



On 2016-05-20 16:48, Nicolas Goaziou wrote:
> Hello,
>
> Brian Carlson <hacker@abutilize.com> writes:
>
>> Hello other org mode aficionados! (I apologize for the errant email I
>> send a minute ago. )

>
>>  From 6b4db0a978cc3492f0d0ac7e29008de6846fbe4a Mon Sep 17 00:00:00 2001
>> From: Brian Carlson <hacker@abutilize.com>
>> Date: Mon, 16 May 2016 10:58:01 -0400
>> Subject: [PATCH] ox: provide [+-]n <offset> functionality
>
> Here you need to specify all the functions being modified. You may want
> to look at other commit messages in the repository.

I'll make the appropriate commentary in my commit message in my branch.

>
>> @@ -1488,9 +1488,9 @@ contextual information."
>>            (custom-env (and lang
>>                             (cadr (assq (intern lang)
>>                                         org-groff-custom-lang-environments))))
>> -         (num-start (case (org-element-property :number-lines src-block)
>> +         (num-start (case (car (org-element-property :number-lines src-block))
>>                         (continued (org-export-get-loc src-block info))
>> -                      (new 0)))
>> +                      (new (or (cdr (org-element-property :number-lines src-block)) 0))))
>
> This pattern appears often in your patch, and, of course in the code
> base. I suggest to factorize it out.  Indeed, we could take advantage of
> the new behaviour of `org-export-get-loc' that your patch introduces.

I started doing that, and with your recommendation. I'll do just that.

>
> IIUC, the new `org-export-get-loc' returns the number for the first line
> of the current block, not the number of the last line in the previous
> block, like it used to do. It can then includes the construct above:
>
>    (pcase (org-element-property :number-lines src-block)
>      ;; No need to compute line numbers before this one.
>      (`(new . ,n) (or n 2))
>      (`(continued . ,_)
>       ;; Count all lines above, up to the first block that has "new" line
>       ;; numbering.
>       (let ((loc 0))
>         (org-element-map (plist-get info :parse-tree)
>             ...))))
>
> Of course, tests would have to be changed or updated accordingly.

A very nice recommendation. I'll look into this.

>
>> -			((string-match "-n\\>" switches) 'new)
>> -			((string-match "+n\\>" switches) 'continued)))
>> +			((string-match "-n *\\([0-9]+\\)" switches) (cons 'new (- (string-to-number (match-string 1 switches)) 1 )))
>
> There is a spurious white space after the last 1.
>> +			((string-match "+n *\\([0-9]+\\)" switches) (cons 'continued (- (string-to-number (match-string 1 switches)) 1 )))
>
> Ditto.
>> +			((string-match "+n" switches) (cons 'continued 0))
>> +			))
>
> These parens should be moved at the end of the previous line.
Nice catch. Before I resubmit the patch. I'll clean up this and the 
other non-standard coding conventions. I haven't submitted patches to 
emacs code before, so I really do appreciate bringing my attention to 
areas where I fail to follow the coding conventions.


>
>>   		 (preserve-indent
>>   		  (and switches (string-match "-i\\>" switches)))
>>   		 ;; Should labels be retained in (or stripped from) example
>> @@ -2393,7 +2396,7 @@ Assume point is at the beginning of the block."
>>   		    (looking-at
>>   		     (concat "^[ \t]*#\\+BEGIN_SRC"
>>   			     "\\(?: +\\(\\S-+\\)\\)?"
>> -			     "\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?"
>> +			     "\\(\\(?: +\\(?:-l \".+\"\\|[+-]n *[[:digit:]]+\\|[+-][[:alpha:]]\\)\\)+\\)?"
>
> I don't think "[-+][[:alpha:]]" is correct here and neither was [-+][A-Za-z].  We
> only want to match valid switches: k, r and i. Besides, there is no +k,
> +r or +i. Thus, it should be "-[iIkKrR]".

I agree with this. I'll fix this, as well. I think we actually need 
-[iIkKrRnN]|+[nN]
The first part of the regular expression catches [-+][Nn] *[0-9]+ but 
not [-+][Nn] in isolation (which obviously we still need).

>>   			     "\\(.*\\)[ \t]*$"))
>>   		    (org-match-string-no-properties 1)))
>>   		 ;; Get switches.
>> @@ -2403,8 +2406,11 @@ Assume point is at the beginning of the block."
>>   		 ;; Switches analysis
>>   		 (number-lines
>>   		  (cond ((not switches) nil)
>> -			((string-match "-n\\>" switches) 'new)
>> -			((string-match "+n\\>" switches) 'continued)))
>> +			((string-match "-n *\\([0-9]+\\)" switches) (cons 'new (- (string-to-number (match-string 1 switches)) 1 )))
>> +			((string-match "+n *\\([0-9]+\\)" switches) (cons 'continued (- (string-to-number (match-string 1 switches)) 1 )))
>> +			((string-match "-n" switches) (cons 'new 0))
>> +			((string-match "+n" switches) (cons 'continued 0))
>> +			))
>
> See above.
I'll do some testing and tinkering. The "problem" is that -n  is equal 
to -n 1, and not -n 0.

The cons cell actually holds ('type . (- starting_number 1)). This may 
not be ideal, but seemed the simplest.  There's probably a very simple 
lisp expression that can reduce the cond back to a 3 conditional clause 
to get what I need. (If "see above" was in regards to the regular 
expressions comment).

Unless you were only talking about the extra space, then that's a really 
easy fix. ;)

>> diff --git a/lisp/ox.el b/lisp/ox.el
>> index 5ad17ec..c05f55e 100644
>> --- a/lisp/ox.el
>> +++ b/lisp/ox.el
>> @@ -4148,9 +4148,9 @@ error if no block contains REF."
>>   	      (when (re-search-backward ref-re nil t)
>>   		(cond
>>   		 ((org-element-property :use-labels el) ref)
>> -		 ((eq (org-element-property :number-lines el) 'continued)
>> +		 ((eq (car (org-element-property :number-lines el)) 'continued)
>>   		  (+ (org-export-get-loc el info) (line-number-at-pos)))
>> -		 (t (line-number-at-pos)))))))
>> +		 (t (+ (or (cdr (org-element-property :number-lines el)) 0) (line-number-at-pos))))))))
>
> Here, the last two branches of the cond could be replaced with a single
> one calling the new `org-export-get-loc'.
Okay.

> WDYT?
Very Helpful. Thanks for the direction. I'll make the changes/re-write 
to fix these issues and re-submit a patch. Because this goes past (or 
might go past) the 15-line FSF limitation for a "patch." I've got the 
paperwork from the FSF for copyright assignment and will be submitting 
this next week. (Even if a patch would fit into the limit, having the 
paperwork on file won't hurt).


Thanks,
;-b

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-20 20:48 ` Nicolas Goaziou
  2016-05-22 15:57   ` Brian Carlson
@ 2016-05-23  4:00   ` Brian Carlson
  2016-05-24 19:44     ` Nicolas Goaziou
  1 sibling, 1 reply; 12+ messages in thread
From: Brian Carlson @ 2016-05-23  4:00 UTC (permalink / raw)
  To: emacs-orgmode

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



On 2016-05-20 16:48, Nicolas Goaziou wrote:
>> The code is written with the following design:
>>
>> -n   is the same as -n 1 : The functionality is unchanged
>> +n   is the same as +n 1 :  The functionality is unchanged
>>
>> -n X   will "reset" and start new code block starting at line X
>> +n X   will "add" X to the last line of the block before.
>
> Thank you for the patch. It looks like an useful addition to Org. Some
> comments follow.

I believe that I addressed all your review comments/recommendations. I 
am submitting the latest patch. This patch also include some additions 
to /testing/lisp/test-ox.el to test the feature. All of the existing 
tests pass (without modification).


In general the main change was to (org-export-get-loc) which returns
the number of lines "before" the first line of a block (as it always 
has) regardless of the type (new/continued) (or nil if the block does 
not provide +/-n option (as it always has).


Thanks,
;-b




[-- Attachment #2: 0001-ox-Provide-offset-to-n-in-SRC-EXAMPLE-export.patch --]
[-- Type: text/x-patch, Size: 14398 bytes --]

From dd01dada2c3c0ee0d8cc28184026720f8602680b Mon Sep 17 00:00:00 2001
From: Brian Carlson <hacker@abutilize.com>
Date: Mon, 16 May 2016 10:58:01 -0400
Subject: [PATCH] ox: Provide offset to [+-]n in SRC/EXAMPLE export

* lisp/org-element.el (org-element-example-block-parser): Use cons cell
  for :number-lines specifying offset in addition to type (new/continue).
  ('continue . offset) for :number-lines will add this offset count to
  the last line number. ('new . offset) for :number-lines will reset the
  line number counting starting at offset
(org-element-src-block-parser): same for SRC block as EXAMPLE block

* lisp/ox-html.el (org-html-format-code): Use cons cell :number-lines

* lisp/ox-latex.el (org-latex-src-block): Use cons cell :number-lines

* lisp/ox-odt.el (org-odt-format-code): Use cons cell for :number-lines

* lisp/ox.el (org-export-resolve-coderef): Use cons cell for :number-lines
(org-export-get-loc): Use new cons cell for :number-lines
(org-export-format-code-default): Use new cons cell for :number-lines

* testing/lisp/test-ox.el  (ert-deftest test-org-export/get-loc): Tests for
changes
(test-org-gen-loc-list): helper function for test-org-export/get-loc

* contrib/lisp/ox-groff.el (org-groff-src-block): Use new cons cell for
  :number-lines
---
 contrib/lisp/ox-groff.el |   4 +-
 lisp/org-element.el      |  26 ++++++++---
 lisp/ox-html.el          |   4 +-
 lisp/ox-latex.el         |   4 +-
 lisp/ox-odt.el           |   4 +-
 lisp/ox.el               |  20 +++++----
 testing/lisp/test-ox.el  | 109 +++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 146 insertions(+), 25 deletions(-)

diff --git a/contrib/lisp/ox-groff.el b/contrib/lisp/ox-groff.el
index b49edce..25ed8b0 100644
--- a/contrib/lisp/ox-groff.el
+++ b/contrib/lisp/ox-groff.el
@@ -1488,9 +1488,7 @@ contextual information."
          (custom-env (and lang
                           (cadr (assq (intern lang)
                                       org-groff-custom-lang-environments))))
-         (num-start (case (org-element-property :number-lines src-block)
-                      (continued (org-export-get-loc src-block info))
-                      (new 0)))
+         (num-start (org-export-get-loc src-block info))
          (retain-labels (org-element-property :retain-labels src-block))
          (caption (and (not (org-export-read-attribute
 			     :attr_groff src-block :disable-caption))
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 368da60..5f62a7e 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -1896,8 +1896,16 @@ containing `:begin', `:end', `:number-lines', `:preserve-indent',
 		 ;; Switches analysis
 		 (number-lines
 		  (cond ((not switches) nil)
-			((string-match "-n\\>" switches) 'new)
-			((string-match "+n\\>" switches) 'continued)))
+			((string-match "-n *\\([0-9]+\\)\\>" switches)
+			 ;; subtract 1 to give number of lines before first line
+			 (cons 'new (- (string-to-number (match-string 1 switches)) 1)))
+			((string-match "-n\\>" switches)
+			 (cons 'new 0))
+			((string-match "+n *\\([0-9]+\\)\\>" switches)
+			 ;; subtract 1 to give number of lines between last number and first line
+			 (cons 'continued (- (string-to-number (match-string 1 switches)) 1)))
+			((string-match "+n\\>" switches)
+			 (cons 'continued 0))))
 		 (preserve-indent
 		  (and switches (string-match "-i\\>" switches)))
 		 ;; Should labels be retained in (or stripped from) example
@@ -2393,7 +2401,7 @@ Assume point is at the beginning of the block."
 		    (looking-at
 		     (concat "^[ \t]*#\\+BEGIN_SRC"
 			     "\\(?: +\\(\\S-+\\)\\)?"
-			     "\\(\\(?: +\\(?:-l \".*?\"\\|[-+][A-Za-z]\\)\\)+\\)?"
+			     "\\(\\(?: +\\(?:-l \".+\"\\|[+-]n *[0-9]+\\|-[iIkKrRnN]\\|+[nN]\\)\\)+\\)?"
 			     "\\(.*\\)[ \t]*$"))
 		    (org-match-string-no-properties 1)))
 		 ;; Get switches.
@@ -2403,8 +2411,16 @@ Assume point is at the beginning of the block."
 		 ;; Switches analysis
 		 (number-lines
 		  (cond ((not switches) nil)
-			((string-match "-n\\>" switches) 'new)
-			((string-match "+n\\>" switches) 'continued)))
+			((string-match "-n *\\([0-9]+\\)\\>" switches)
+			 ;; subtract 1 to give number of lines before first line
+			 (cons 'new (- (string-to-number (match-string 1 switches)) 1)))
+			((string-match "-n\\>" switches)
+			 (cons 'new 0))
+			((string-match "+n *\\([0-9]+\\)\\>" switches)
+			 ;; subtract 1 to give number of lines between last number and first line
+			 (cons 'continued (- (string-to-number (match-string 1 switches)) 1)))
+			((string-match "+n\\>" switches)
+			 (cons 'continued 0))))
 		 (preserve-indent (and switches
 				       (string-match "-i\\>" switches)))
 		 (label-fmt
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index e33d91e..3f5802a 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2207,9 +2207,7 @@ a plist used as a communication channel."
 	 ;; Does the src block contain labels?
 	 (retain-labels (org-element-property :retain-labels element))
 	 ;; Does it have line numbers?
-	 (num-start (case (org-element-property :number-lines element)
-		      (continued (org-export-get-loc element info))
-		      (new 0))))
+	 (num-start (org-export-get-loc element info)))
     (org-html-do-format-code code lang refs retain-labels num-start)))
 
 \f
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9c31645..41a238e 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2762,9 +2762,7 @@ contextual information."
 	   (custom-env (and lang
 			    (cadr (assq (intern lang)
 					org-latex-custom-lang-environments))))
-	   (num-start (case (org-element-property :number-lines src-block)
-			(continued (org-export-get-loc src-block info))
-			(new 0)))
+	   (num-start (org-export-get-loc src-block info))
 	   (retain-labels (org-element-property :retain-labels src-block))
 	   (attributes (org-export-read-attribute :attr_latex src-block))
 	   (float (plist-get attributes :float))
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index d996689..548445c 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -3168,9 +3168,7 @@ and prefix with \"OrgSrc\".  For example,
 	 ;; Does the src block contain labels?
 	 (retain-labels (org-element-property :retain-labels element))
 	 ;; Does it have line numbers?
-	 (num-start (case (org-element-property :number-lines element)
-		      (continued (org-export-get-loc element info))
-		      (new 0))))
+	 (num-start (org-export-get-loc element info)))
     (org-odt-do-format-code code info lang refs retain-labels num-start)))
 
 (defun org-odt-src-block (src-block _contents info)
diff --git a/lisp/ox.el b/lisp/ox.el
index 5ad17ec..714000b 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -4148,9 +4148,7 @@ error if no block contains REF."
 	      (when (re-search-backward ref-re nil t)
 		(cond
 		 ((org-element-property :use-labels el) ref)
-		 ((eq (org-element-property :number-lines el) 'continued)
-		  (+ (org-export-get-loc el info) (line-number-at-pos)))
-		 (t (line-number-at-pos)))))))
+		 (t (+ (or (org-export-get-loc el info) 0) (line-number-at-pos))))))))
 	info 'first-match)
       (signal 'org-link-broken (list ref))))
 
@@ -4457,7 +4455,8 @@ objects of the same type."
 INFO is the plist used as a communication channel.
 
 ELEMENT is excluded from count."
-  (let ((loc 0))
+  (let ((loc 0)
+        (linum (org-element-property :number-lines element)))
     (org-element-map (plist-get info :parse-tree)
 	`(src-block example-block ,(org-element-type element))
       (lambda (el)
@@ -4472,10 +4471,17 @@ ELEMENT is excluded from count."
 	      ;; Accumulate locs or reset them.
 	      (let ((lines (org-count-lines
 			    (org-trim (org-element-property :value el)))))
-		(setq loc (if (eq linums 'new) lines (+ loc lines))))))
+		(if (eq (car linums) 'new)
+		    (setq loc 0))
+		(setq loc (+ loc lines (cdr linums))))))
 	  ;; Return nil to stay in the loop.
 	  nil)))
       info 'first-match)
+    ;; Add the offset from [+-]n to the loc for the final starting
+    ;; number of lines before the first starting line.
+    (setq loc (cl-case (car linum)
+		(continued (+ (cdr linum) loc))
+		(new (cdr linum))))
     ;; Return value.
     loc))
 
@@ -4573,9 +4579,7 @@ code."
       (let* ((refs (and (org-element-property :retain-labels element)
 			(cdr code-info)))
 	     ;; Handle line numbering.
-	     (num-start (cl-case (org-element-property :number-lines element)
-			  (continued (org-export-get-loc element info))
-			  (new 0)))
+	     (num-start (org-export-get-loc element info))
 	     (num-fmt
 	      (and num-start
 		   (format "%%%ds  "
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index e27954c..209dc64 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -2586,6 +2586,70 @@ Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
        (lambda (link) (org-export-resolve-fuzzy-link link info))
        info t))))
 
+(defun test-org-gen-loc-list(text type)
+    (org-test-with-parsed-data text
+			       (org-element-map tree type
+				 (lambda(el) (or (org-export-get-loc el info) "nil")))))
+
+(ert-deftest test-org-export/get-loc ()
+  "Test `org-export-get-loc' specifications."
+  (should
+   ;; "-n" resets line number.
+   (equal '(0)
+	  (test-org-gen-loc-list  "#+BEGIN_EXAMPLE -n\n  Text\n#+END_EXAMPLE" 'example-block)))
+  ;; The first "+n" has 0 lines before it
+  (should
+   (equal '(0)
+	  (test-org-gen-loc-list "#+BEGIN_EXAMPLE +n\n  Text\n#+END_EXAMPLE" 'example-block)))
+  ;; "-n 10" resets line number but has "9 lines" before it.
+  (should
+   (equal '(9)
+	  (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n  Text\n#+END_EXAMPLE" 'example-block)))
+  ;; -n10 with two lines then +n 15
+  (should
+   (equal '(9 25)
+	  (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n  Text_10\n  Second line(11)\n#+END_EXAMPLE
+#+BEGIN_EXAMPLE +n 15\n  Text line (11 + 15)\n#+END_EXAMPLE"  'example-block)))
+  (should
+   (equal '(9 19 0)
+	  (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n  Text\n#+END_EXAMPLE
+#+BEGIN_EXAMPLE +n 10\n  Text \n#+END_EXAMPLE\n
+#+BEGIN_EXAMPLE -n\n  Text \n#+END_EXAMPLE" 'example-block)))
+  (should
+   ;; an Example Block without -n does not add to the line count
+   (equal '(9 "nil" 19)
+	  (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n  Text\n#+END_EXAMPLE
+#+BEGIN_EXAMPLE\n  Text\n#+END_EXAMPLE
+#+BEGIN_EXAMPLE +n 10\n  Text\n#+END_EXAMPLE" 'example-block)))
+  (should
+   ;; "-n" resets line number.
+   (equal '(0)
+	  (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n \n  (- 1 1) \n#+END_SRC" 'src-block)))
+  (should
+   ;; The first "+n" has 0 lines before it
+   (equal '(0)
+	  (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp +n \n  (+ 0 (- 1 1))\n#+END_SRC" 'src-block)))
+  (should
+   ;; "-n 10" resets line number but has "9 lines" before it.
+   (equal '(9)
+	  (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n 10\n  (- 10 1)\n#+END_SRC" 'src-block)))
+  (should
+   (equal '(9 25)
+	  (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n 10\n  (- 10 1)\n  (+ (- 10 1) 1)\n#+END_SRC
+#+BEGIN_SRC emacs-lisp +n 15\n  (+ (- 10 1) 2 (- 15 1))\n#+END_SRC" 'src-block)))
+  (should
+   (equal '(9 19 0)
+	  (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n 10\n  (- 10 1)\n#+END_SRC
+#+BEGIN_SRC emacs-lisp +n 10\n  (+ (- 10 1) 1 (- 10 1))\n#+END_SRC
+#+BEGIN_SRC emacs-lisp -n\n  (- 1 1)\n#+END_SRC" 'src-block)))
+  (should
+   ;; an SRC Block without -n does not add to the line count
+   (equal '(9 "nil" 19)
+	  (test-org-gen-loc-list
+	   "#+BEGIN_SRC emacs-lisp -n 10\n  (+ (-10 1) 1)\n#+END_SRC
+#+BEGIN_SRC emacs-lisp \n  (+ 2 2) \n#+END_SRC
+#+BEGIN_SRC emacs-lisp +n 10\n  (+ (- 10 1) 1 (- 10 1))\n#+END_SRC" 'src-block))))
+
 (ert-deftest test-org-export/resolve-coderef ()
   "Test `org-export-resolve-coderef' specifications."
   (let ((org-coderef-label-format "(ref:%s)"))
@@ -2596,10 +2660,32 @@ Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
 	    "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
 	  (org-export-resolve-coderef "coderef" info))))
     (should
+     (= 10
+	(org-test-with-parsed-data
+	 "#+BEGIN_EXAMPLE -n 10 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
+	 (org-export-resolve-coderef "coderef" info))))
+    (should
+     (= 135
+	(org-test-with-parsed-data
+	 "#+BEGIN_EXAMPLE -n 10 -k -r\nText \n#+END_EXAMPLE\n
+#+BEGIN_EXAMPLE +n 125 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
+	 (org-export-resolve-coderef "coderef" info))))
+    (should
      (= 1
 	(org-test-with-parsed-data
 	    "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
 	  (org-export-resolve-coderef "coderef" info))))
+    (should
+     (= 10
+	(org-test-with-parsed-data
+	 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
+	 (org-export-resolve-coderef "coderef" info))))
+    (should
+     (= 135
+	(org-test-with-parsed-data
+	 "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) \n#+END_SRC\n
+#+BEGIN_SRC emacs-lisp +n 125 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
+	 (org-export-resolve-coderef "coderef" info))))
     ;; A link to a "-n -r" block returns line number.
     (should
      (= 1
@@ -2607,10 +2693,33 @@ Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
 	    "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
 	  (org-export-resolve-coderef "coderef" info))))
     (should
+     (= 10
+	(org-test-with-parsed-data
+	 "#+BEGIN_EXAMPLE -n 10 -r\nText (ref:coderef)\n#+END_EXAMPLE"
+	 (org-export-resolve-coderef "coderef" info))))
+    (should
+     (= 135
+	(org-test-with-parsed-data
+	 "#+BEGIN_EXAMPLE +n 10 -r\nText \n#+END_EXAMPLE
+#+BEGIN_EXAMPLE +n 125 -r\nText (ref:coderef)\n#+END_EXAMPLE"
+	 (org-export-resolve-coderef "coderef" info))))
+
+    (should
      (= 1
 	(org-test-with-parsed-data
 	    "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
 	  (org-export-resolve-coderef "coderef" info))))
+    (should
+     (= 10
+	(org-test-with-parsed-data
+	 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
+	 (org-export-resolve-coderef "coderef" info))))
+    (should
+     (= 135
+	(org-test-with-parsed-data
+	 "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) \n#+END_SRC
+#+BEGIN_SRC emacs-lisp +n125 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
+	 (org-export-resolve-coderef "coderef" info))))
     ;; A link to a "-n" block returns coderef.
     (should
      (equal "coderef"
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-23  4:00   ` PATCH: ox: " Brian Carlson
@ 2016-05-24 19:44     ` Nicolas Goaziou
  2016-05-24 20:33       ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2016-05-24 19:44 UTC (permalink / raw)
  To: Brian Carlson; +Cc: emacs-orgmode

Hello,

Brian Carlson <hacker@abutilize.com> writes:

> I believe that I addressed all your review comments/recommendations.
> I am submitting the latest patch. This patch also include some
> additions to /testing/lisp/test-ox.el to test the feature. All of the
> existing tests pass (without modification).

Applied, with a small refactoring. Thank you.

Please let us know when the FSF paperwork is done


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-24 19:44     ` Nicolas Goaziou
@ 2016-05-24 20:33       ` Nicolas Goaziou
  2016-05-26  3:06         ` Brian Carlson
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2016-05-24 20:33 UTC (permalink / raw)
  To: Brian Carlson; +Cc: emacs-orgmode

Completing myself

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Applied, with a small refactoring. Thank you.
>
> Please let us know when the FSF paperwork is done

Also, could you provide and ORG-NEWS entry for that patch?

Thank you.

Regards,

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-24 20:33       ` Nicolas Goaziou
@ 2016-05-26  3:06         ` Brian Carlson
  2016-05-26  6:52           ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Brian Carlson @ 2016-05-26  3:06 UTC (permalink / raw)
  To: emacs-orgmode


On 2016-05-24 16:33, Nicolas Goaziou wrote:
 > Completing myself

Great. Thanks! Very much appreciated. I went back and forth on the tests
with the "string formatting." I should have gone with my original thoughts ;)
The fixes to (org-export-get-loc) were a bit beyond my skill level.
I don't work in lisp/scheme/emacs-lisp too much. Usually I know just enough
to be dangerous ;)

So Thanks!

 >> Applied, with a small refactoring. Thank you.

No problem. Hope it helps others.

 >> Please let us know when the FSF paperwork is done

I put the signed paperwork into the mail this evening.


 > Also, could you provide and ORG-NEWS entry for that patch?

Sure. I'll use previous entries as a starting point.
I was thinking that the entry should go under: Version 9.0/New Features/Export/
unless there's a more appropriate place in the Document.

Here's what I thought about putting. I can make a patch if that is preferred
means of submission. If what I've written doesn't make sense let me know.

--8<---------------cut here---------------start------------->8---
**** Line Numbering in SRC/EXAMPLE blocks support arbitrary start number
The -n option to SRC and EXAMPLE blocks can now take an numeric argument to specify
the staring line number for the source or example block. The +n option can now
take a numeric argument that will be added to the last line number from the
previous block as the starting point for the SRC/EXAMPLE block.
#+BEGIN_SRC emacs-lisp -n 20
;; this will export with line number 20
(message "This is line 21")
#+END_SRC

#+BEGIN_SRC emacs-lisp +n 10
;; This will be listed as line 31
(message "This is line 32")
#+END_SRC
--8<---------------cut here---------------end--------------->8---

I realize that the org texinfo manual probably needs to be updated, as well. I'll take a stab at updating that unless 
someone else wants to take that on.

Thanks,
;-b

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-26  3:06         ` Brian Carlson
@ 2016-05-26  6:52           ` Nicolas Goaziou
  2016-05-30  2:42             ` Brian Carlson
                               ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Nicolas Goaziou @ 2016-05-26  6:52 UTC (permalink / raw)
  To: Brian Carlson; +Cc: emacs-orgmode

Hello,

Brian Carlson <hacker@abutilize.com> writes:

> I put the signed paperwork into the mail this evening.

Great.

> Sure. I'll use previous entries as a starting point.
> I was thinking that the entry should go under: Version 9.0/New Features/Export/
> unless there's a more appropriate place in the Document.

I also think this is the correct location.

> Here's what I thought about putting. I can make a patch if that is preferred
> means of submission. If what I've written doesn't make sense let me know.
>
> **** Line Numbering in SRC/EXAMPLE blocks support arbitrary start number
> The -n option to SRC and EXAMPLE blocks can now take an numeric argument to specify

"a numeric argument"

> the staring line number for the source or example block. The +n option can now
> take a numeric argument that will be added to the last line number from the
> previous block as the starting point for the SRC/EXAMPLE block.
> #+BEGIN_SRC emacs-lisp -n 20
> ;; this will export with line number 20
> (message "This is line 21")
> #+END_SRC
>
> #+BEGIN_SRC emacs-lisp +n 10
> ;; This will be listed as line 31
> (message "This is line 32")
> #+END_SRC
>
> I realize that the org texinfo manual probably needs to be updated, as well. I'll take a stab at updating that unless 
> someone else wants to take that on.

You're right. You can merge ORG-NEWS modifications into the
documentation patch.

Thank you !

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-26  6:52           ` Nicolas Goaziou
@ 2016-05-30  2:42             ` Brian Carlson
  2016-05-30  2:45             ` Brian Carlson
  2016-05-31 16:47             ` Brian Carlson
  2 siblings, 0 replies; 12+ messages in thread
From: Brian Carlson @ 2016-05-30  2:42 UTC (permalink / raw)
  To: emacs-orgmode



On 2016-05-26 02:52, Nicolas Goaziou wrote:
> Hello,
>
> Brian Carlson <hacker@abutilize.com> writes:
>
>> I put the signed paperwork into the mail this evening.
> Great.
>
>> Sure. I'll use previous entries as a starting point.
>> I was thinking that the entry should go under: Version 9.0/New Features/Export/
>> unless there's a more appropriate place in the Document.
> I also think this is the correct location.
>
>> Here's what I thought about putting. I can make a patch if that is preferred
>> means of submission. If what I've written doesn't make sense let me know.
>>
>> **** Line Numbering in SRC/EXAMPLE blocks support arbitrary start number
>> The -n option to SRC and EXAMPLE blocks can now take an numeric argument to specify
> "a numeric argument"
>
>> the staring line number for the source or example block. The +n option can now
>> take a numeric argument that will be added to the last line number from the
>> previous block as the starting point for the SRC/EXAMPLE block.
>> #+BEGIN_SRC emacs-lisp -n 20
>> ;; this will export with line number 20
>> (message "This is line 21")
>> #+END_SRC
>>
>> #+BEGIN_SRC emacs-lisp +n 10
>> ;; This will be listed as line 31
>> (message "This is line 32")
>> #+END_SRC
>>
>> I realize that the org texinfo manual probably needs to be updated, as well. I'll take a stab at updating that unless
>> someone else wants to take that on.
> You're right. You can merge ORG-NEWS modifications into the
> documentation patch.
>
> Thank you !
>
> Regards,
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-26  6:52           ` Nicolas Goaziou
  2016-05-30  2:42             ` Brian Carlson
@ 2016-05-30  2:45             ` Brian Carlson
  2016-05-31 16:47             ` Brian Carlson
  2 siblings, 0 replies; 12+ messages in thread
From: Brian Carlson @ 2016-05-30  2:45 UTC (permalink / raw)
  To: emacs-orgmode

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


On 2016-05-26 02:52, Nicolas Goaziou wrote:
>> I realize that the org texinfo manual probably needs to be updated, as well. I'll take a stab at updating that unless
>> someone else wants to take that on.
>
> You're right. You can merge ORG-NEWS modifications into the
> documentation patch.


Here is the patch for both doc/org.texi and etc/ORG-NEWS. I apologize for the delay in getting this to the list.


Thanks!
;-b



[-- Attachment #2: 0001-org.texi-Updated-doc-for-n-in-SRC-EXAMPLE-export.patch --]
[-- Type: text/x-patch, Size: 3594 bytes --]

From 466f0c755180f7475484abc6715accdf74a8a0f3 Mon Sep 17 00:00:00 2001
From: "Brian J. Carlson" <hacker@briancarlson.org>
Date: Sun, 29 May 2016 22:37:18 -0400
Subject: [PATCH] org.texi: Updated doc for [+-]n in SRC/EXAMPLE export

* doc/org.texi (Timers): Added information about optional argument to
  -n/+n line-numbering
* etc/ORG-NEWS: Added infomation for "Provide offset to [+-]n in
  SRC/EXAMPLE export"  (commit af8e3d8)
---
 doc/org.texi | 29 ++++++++++++++++++++++-------
 etc/ORG-NEWS | 16 ++++++++++++++++
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 9d89975..0d0d30f 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -10045,13 +10045,28 @@ shortcuts to easily insert code blocks.
 
 Both in @code{example} and in @code{src} snippets, you can add a @code{-n}
 switch to the end of the @code{BEGIN} line, to get the lines of the example
-numbered.  If you use a @code{+n} switch, the numbering from the previous
-numbered snippet will be continued in the current one.  In literal examples,
-Org will interpret strings like @samp{(ref:name)} as labels, and use them as
-targets for special hyperlinks like @code{[[(name)]]} (i.e., the reference name
-enclosed in single parenthesis).  In HTML, hovering the mouse over such a
-link will remote-highlight the corresponding code line, which is kind of
-cool.
+numbered.  The @code{-n} takes an optional numeric argument specifying the starting
+line number of the block. If you use a @code{+n} switch, the numbering from
+the previous numbered snippet will be continued in the current one.  The
+@code{+n} can also take a numeric argument. The value of the argument will be
+added to the last line of the previous block to determine the starting line
+number. 
+@example
+#+BEGIN_SRC emacs-lisp -n 20
+ ;; this will export with line number 20
+ (message "This is line 21")
+#+END_SRC
+#+BEGIN_SRC emacs-lisp +n 10
+ ;; This will be listed as line 31
+ (message "This is line 32")
+#+END_SRC
+@end example
+
+In literal examples, Org will interpret strings like @samp{(ref:name)} as
+labels, and use them as targets for special hyperlinks like @code{[[(name)]]}
+(i.e., the reference name enclosed in single parenthesis).  In HTML, hovering
+the mouse over such a link will remote-highlight the corresponding code line,
+which is kind of cool.
 
 You can also add a @code{-r} switch which @i{removes} the labels from the
 source code@footnote{Adding @code{-k} to @code{-n -r} will @i{keep} the
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 72f8d5c..34eb9ab 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -159,6 +159,22 @@ If the block has a =#+NAME:= attribute assigned, then the HTML element
 will have an ~id~ attribute with that name in the HTML export. This
 enables one to create links to these elements in other places, e.g.,
 ~<a href="#name">text</a>~.
+**** Line Numbering in SRC/EXAMPLE blocks support arbitrary start number
+The ~-n~ option to ~SRC~ and ~EXAMPLE~ blocks can now take a numeric
+argument to specify the staring line number for the source or example
+block. The ~+n~ option can now take a numeric argument that will be
+added to the last line number from the previous block as the starting
+point for the SRC/EXAMPLE block.
+#+BEGIN_SRC org
+  ,#+BEGIN_SRC emacs-lisp -n 20
+    ;; this will export with line number 20
+    (message "This is line 21")
+  ,#+END_SRC
+  ,#+BEGIN_SRC emacs-lisp +n 10
+    ;; This will be listed as line 31
+    (message "This is line 32")
+  ,#+END_SRC
+#+END_SRC
 
 *** Babel
 **** Support for SLY in Lisp blocks
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-26  6:52           ` Nicolas Goaziou
  2016-05-30  2:42             ` Brian Carlson
  2016-05-30  2:45             ` Brian Carlson
@ 2016-05-31 16:47             ` Brian Carlson
  2016-05-31 20:37               ` Nicolas Goaziou
  2 siblings, 1 reply; 12+ messages in thread
From: Brian Carlson @ 2016-05-31 16:47 UTC (permalink / raw)
  To: emacs-orgmode



On 2016-05-26 02:52, Nicolas Goaziou wrote:

>> I realize that the org texinfo manual probably needs to be updated, as well. I'll take a stab at updating that unless
>> someone else wants to take that on.
>
> You're right. You can merge ORG-NEWS modifications into the
> documentation patch.

I just realized. I the patch I submitted had modifications to doc/org.texi.

Should I have made the changes to contrib/orgmanual.org rather than doc/org.texi. Or should I have made changes to both?



Thanks,
;-b

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: ox: Starting source code export at non-zero (-n value)
  2016-05-31 16:47             ` Brian Carlson
@ 2016-05-31 20:37               ` Nicolas Goaziou
  0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Goaziou @ 2016-05-31 20:37 UTC (permalink / raw)
  To: Brian Carlson; +Cc: emacs-orgmode

Hello,

Brian Carlson <hacker@abutilize.com> writes:

> Should I have made the changes to contrib/orgmanual.org rather than
> doc/org.texi. Or should I have made changes to both?

Changes to both is fine.

I applied your patch. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-05-31 20:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-17  3:33 Starting source code export at non-zero (-n value) Brian Carlson
2016-05-20 20:48 ` Nicolas Goaziou
2016-05-22 15:57   ` Brian Carlson
2016-05-23  4:00   ` PATCH: ox: " Brian Carlson
2016-05-24 19:44     ` Nicolas Goaziou
2016-05-24 20:33       ` Nicolas Goaziou
2016-05-26  3:06         ` Brian Carlson
2016-05-26  6:52           ` Nicolas Goaziou
2016-05-30  2:42             ` Brian Carlson
2016-05-30  2:45             ` Brian Carlson
2016-05-31 16:47             ` Brian Carlson
2016-05-31 20:37               ` Nicolas Goaziou

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