Re: Bug: LaTeX output of numbered TODO plain list items lose numbering. [9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/27.0.50/lisp/org/)]

2019-11-09 Thread Brian Carlson
On 11/9/19 6:59 AM, Fraga, Eric wrote:

> On Friday,  8 Nov 2019 at 21:28, Brian Carlson wrote:
>> So it seems that the numbering of numbered items in a plain list are not
>> maintained when the numbered item is also a TODO plain list item.
> This is a "feature", not a bug.  The intention was to export check box
> lists nicely to LaTeX, showing which were done and which were not.  This
> doesn't mix well with any other type of list except for simple bullet
> points unfortunately.

This is, indeed, a very odd "feature." Why change the numbering to not match 
what the org file shows? 

This is especially problematic if you use internal links...

--8<---cut here---start->8---
* My tasks
  1. one item
  2. Something interesting
 1. [X] <> another item
  3. A note that isn't really a ToDo
 1. Here we refer to item [[target]] saying it's related.
 2. another item

--8<---cut here---end--->8---

That file give the following LaTeX output. (I've omitted the Table of 
Contents). 
Notice that the reference is to "2." The actual reference is to 2.1 but since 
it's a plain list todo so it references the WRONG item.
--8<---cut here---start->8---

1 My tasks
  1. one item
  2. Something interesting
[X] another item
  3. A note that isn't really a ToDo
(a) Here we refer to item 2 saying it's related
(b) another item
--8<---cut here---end--->8---

This is inconsistent with the org mode content. It is also inconsistent 
with the HTML output, which IMHO matches the intent of the org mode file:
--8<---cut here---start->8---

1 My tasks
  1. one item
  2. Something interesting
 1. [X] another item
  3. A note that isn't really a ToDo
 1. Here we refer to item 2.1 saying it's related.
 2. another item
--8<---cut here---end--->8---



This change in behavior, err 'feature', should at least be documented 
in that it is shocking to a user. The full ramification of the change
may require quite a few documented use cases. Perhaps the "feature creator"
or someone who understands the reasoning wouldn't mind documenting this 
inconsistency in LaTeX exports (but not other Export targets)?

In the mean time, I guess I'll just have to add some "override" lisp to my 
init file to do the sane and expected thing. This is very unfortunate since
org-latex-item is pretty big. I don't think I can easily just advise this
function. 

> The only way around it is to have them as separate lists (e.g. two empty
> lines between the check box item and the numbered items) and start the
> numbered list with the desired number ([@2], I believe).

But I don't want separate lists. I want a "todo list" that's numbered but 
doesn't change the numbering when I add a comment or wish to refer to another
 task in that list.  Having to constantly update the numbering every time I 
change my list seems sort of contrary to the whole simplicity of Org Mode.  

I find this a very odd exception to just the LaTeX export.

Thanks, 
;-b





Bug: LaTeX output of numbered TODO plain list items lose numbering. [9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/27.0.50/lisp/org/)]

2019-11-08 Thread Brian Carlson
Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.

So it seems that the numbering of numbered items in a plain list are not
maintained when the numbered item is also a TODO plain list item.

Here is how I produced the issue:

$ emacs -Q

I created a very simple org-mode file:
--8<---cut here---start->8---
* Test file
  1. [ ] item
  2. item 2
  3. item 3
--8<---cut here---end--->8---

I then used the export facilities to create a PDF: C-c C-e l o

I expected to see a PDF that looked like:
--8<---cut here---start->8---
Contents

1 Test File

1  Test File
   1. [] item
   2. item 2
   3. item 3
--8<---cut here---end--->8---

Instead I see a pdf that has the following:
--8<---cut here---start->8---
Contents

1 Test File

1  Test File
   [] item
   1. item 2
   2. item 3
--8<---cut here---end--->8---

Notice how the "1." was removed in the generated PDF from the first item
and the numbering started from 1. on "item 2"

This used to work, but I'm not exactly certain when it changed.

It *appears* that the generated \item for enumeration is incorrect?
The .tex file contains the following:
 \item[{$\square$}] item

I /think/ that this should be:
   \item{$\square$} item

Maybe the [ and ] are not being stripped and converted into the {$\square$}, 
but are rather being left and ending up
with [{$\square$}].

(The same thing happens with the \boxtimes for "completed" TODOs.


If that is the case then I /think/ that this patch would fix it:
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 832d9bf8..b9734443 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2208,9 +2208,9 @@ contextual information."
"\\item"
(cond
 ((and checkbox tag)
- (format "[{%s %s}] %s" checkbox tag tag-footnotes))
+ (format "{%s %s} %s" checkbox tag tag-footnotes))
 ((or checkbox tag)
- (format "[{%s}] %s" (or checkbox tag) tag-footnotes))
+ (format "{%s} %s" (or checkbox tag) tag-footnotes))
 ;; Without a tag or a check-box, if CONTENTS starts with
 ;; an opening square bracket, add "\relax" to "\item",
 ;; unless the brackets comes from an initial export

I haven't done any thorough testing, just looking where I thought the issue 
might be.

Thanks for all the great work on Org Mode,
;-b



Emacs  : GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
 of 2019-09-04
Package: Org mode version 9.1.9 (release_9.1.9-65-g5e4542 @ 
/usr/share/emacs/27.0.50/lisp/org/)

current state:
==
(setq
 org-src-mode-hook '(org-src-babel-configure-edit-buffer
 org-src-mode-configure-edit-buffer)
 org-after-todo-state-change-hook '(org-clock-out-if-current)
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 org-html-format-inlinetask-function 
'org-html-format-inlinetask-default-function
 org-odt-format-headline-function 'org-odt-format-headline-default-function
 org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default
 org-mode-hook '(#[0 "\300\301\302\303\304$\207"
   [add-hook change-major-mode-hook org-show-block-all append
local]
   5]
 #[0 "\300\301\302\303\304$\207"
   [add-hook change-major-mode-hook org-babel-show-result-all
append local]
   5]
 org-babel-result-hide-spec org-babel-hide-all-hashes)
 org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-confirm-elisp-link-function 'yes-or-no-p
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn 
ENTRY)"]
 org-latex-format-drawer-function #[514 "\207" [] 3 "\n\n(fn _ CONTENTS)"]
 org-babel-pre-tangle-hook '(save-buffer)
 org-tab-first-hook '(org-babel-hide-result-toggle-maybe
  org-babel-header-arg-expand)
 org-ascii-format-drawer-function #[771 "\207" [] 4 "\n\n(fn NAME CONTENTS 
WIDTH)"]
 org-occur-hook '(org-first-headline-recenter)
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers
  org-cycle-show-empty-lines
  org-optimize-window-after-visibility-change)
 org-speed-command-hook '(org-speed-command-activate

Re: [O] PATCH: ox: Starting source code export at non-zero (-n value)

2016-05-31 Thread Brian Carlson



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



Re: [O] PATCH: ox: Starting source code export at non-zero (-n value)

2016-05-29 Thread Brian Carlson


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


>From 466f0c755180f7475484abc6715accdf74a8a0f3 Mon Sep 17 00:00:00 2001
From: "Brian J. Carlson" 
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.,
 ~text~.
+ 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



Re: [O] PATCH: ox: Starting source code export at non-zero (-n value)

2016-05-29 Thread Brian Carlson



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

Hello,

Brian Carlson <hac...@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,






Re: [O] PATCH: ox: Starting source code export at non-zero (-n value)

2016-05-25 Thread Brian Carlson


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



[O] PATCH: ox: Starting source code export at non-zero (-n value)

2016-05-22 Thread Brian Carlson



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



>From dd01dada2c3c0ee0d8cc28184026720f8602680b Mon Sep 17 00:00:00 2001
From: Brian Carlson <hac...@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-strin

Re: [O] Starting source code export at non-zero (-n value)

2016-05-22 Thread Brian Carlson



On 2016-05-20 16:48, Nicolas Goaziou wrote:

Hello,

Brian Carlson <hac...@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 <hac...@abutilize.com>
Date: Mon, 16 May 2016 10:58:01 -0400
Subject: [PATCH] ox: provide [+-]n  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-nu

[O] Starting source code export at non-zero (-n value)

2016-05-16 Thread Brian Carlson
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
>From 6b4db0a978cc3492f0d0ac7e29008de6846fbe4a Mon Sep 17 00:00:00 2001
From: Brian Carlson <hac...@abutilize.com>
Date: Mon, 16 May 2016 10:58:01 -0400
Subject: [PATCH] ox: provide [+-]n  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 th