emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Patch for numbering continuation in source blocks.
@ 2011-10-02 10:40 Niels Giesen
  2011-10-07 16:19 ` Carsten Dominik
  0 siblings, 1 reply; 3+ messages in thread
From: Niels Giesen @ 2011-10-02 10:40 UTC (permalink / raw)
  To: Orgmode

NOTE: I have tried earlier to send this patch with git send-email,
  but apparently failed; here's a new, inlined attempt.

  The documentation for numbering source code blocks says:

#+begin_quote
If you use a `+n' switch, the numbering from the previous
numbered snippet will be continued in the current one.
#+end_quote

  But that is not exactly what happens; what happens is that the
numbering from the previous snippet will be continued in the current
one. That is, when the previous snippet is numbered its numbering will
continue, but if there is a previous numbered snippet A with, say, 14
lines followed by an unnumbered snippet B followed by a numbered
snippet C, then the numbers for C will start at 1, regardless of the +
in the +n switch, whereas my reading of the documentation leads me to
think it ought to continue at 15, disregarding the presence any
unnumbered sections in between.

Reason for me for the +n switch to comply with (my reading of) the
documentation is that I would like to document a long, line-numbered,
function but intersperse it with short code samples without line
numbering that explain parts of the long function.

This patch of course may break existing org files where +n was
specified but -n intended.

#+begin_src diff
  From 4d34d5f2fe10a956d3359dfd40f19de25202df5f Mon Sep 17 00:00:00 2001
  From: Niels Giesen <niels.giesen@gmail.com>
  Date: Fri, 16 Sep 2011 17:22:47 +0200
  Subject: [PATCH] Continue numbering from any previous numbered snippet with +n, even when previous numbered snippet does not immediately precede it.
  
  ,* org-mode/lisp/org-exp.el (org-export-number-lines):
  
    Check whether number parameter (this is a numbered block!) is
    non-nil as well as whether cont is nil (this numbered block should
    *not* continue numbering where we left off before!) before resetting
    the count to zero.
  
    From the docs:
  
      If you use a `+n' switch, the numbering from the previous
      numbered snippet will be continued in the current one.
  
    With this change I believe the code complies with the docs.
  ---
   lisp/org-exp.el |    2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
  
  diff --git a/lisp/org-exp.el b/lisp/org-exp.el
  index 9884a31..12590e1 100644
  --- a/lisp/org-exp.el
  +++ b/lisp/org-exp.el
  @@ -2731,7 +2731,7 @@ INDENT was the original indentation of the block."
   (defun org-export-number-lines (text &optional skip1 skip2 number cont
                       replace-labels label-format)
     (setq skip1 (or skip1 0) skip2 (or skip2 0))
  -  (if (not cont) (setq org-export-last-code-line-counter-value 0))
  +  (if (and number (not cont)) (setq org-export-last-code-line-counter-value 0))
     (with-temp-buffer
       (insert text)
       (goto-char (point-max))
  -- 
  1.7.4.1
  
  
#+end_src

Regards,
niels
--
http://pft.github.com

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

* Re: Patch for numbering continuation in source blocks.
  2011-10-02 10:40 Patch for numbering continuation in source blocks Niels Giesen
@ 2011-10-07 16:19 ` Carsten Dominik
  2011-10-08  9:28   ` Niels Giesen
  0 siblings, 1 reply; 3+ messages in thread
From: Carsten Dominik @ 2011-10-07 16:19 UTC (permalink / raw)
  To: Niels Giesen; +Cc: Orgmode

Hi Niels,

is the purpose of this patch to be able to insert an unnumbered code block
between two numbered ones and to continue the numbering from the first in the third?

- Carsten

On 2.10.2011, at 12:40, Niels Giesen wrote:

> NOTE: I have tried earlier to send this patch with git send-email,
>  but apparently failed; here's a new, inlined attempt.
> 
>  The documentation for numbering source code blocks says:
> 
> #+begin_quote
> If you use a `+n' switch, the numbering from the previous
> numbered snippet will be continued in the current one.
> #+end_quote
> 
>  But that is not exactly what happens; what happens is that the
> numbering from the previous snippet will be continued in the current
> one. That is, when the previous snippet is numbered its numbering will
> continue, but if there is a previous numbered snippet A with, say, 14
> lines followed by an unnumbered snippet B followed by a numbered
> snippet C, then the numbers for C will start at 1, regardless of the +
> in the +n switch, whereas my reading of the documentation leads me to
> think it ought to continue at 15, disregarding the presence any
> unnumbered sections in between.
> 
> Reason for me for the +n switch to comply with (my reading of) the
> documentation is that I would like to document a long, line-numbered,
> function but intersperse it with short code samples without line
> numbering that explain parts of the long function.
> 
> This patch of course may break existing org files where +n was
> specified but -n intended.
> 
> #+begin_src diff
>  From 4d34d5f2fe10a956d3359dfd40f19de25202df5f Mon Sep 17 00:00:00 2001
>  From: Niels Giesen <niels.giesen@gmail.com>
>  Date: Fri, 16 Sep 2011 17:22:47 +0200
>  Subject: [PATCH] Continue numbering from any previous numbered snippet with +n, even when previous numbered snippet does not immediately precede it.
> 
>  ,* org-mode/lisp/org-exp.el (org-export-number-lines):
> 
>    Check whether number parameter (this is a numbered block!) is
>    non-nil as well as whether cont is nil (this numbered block should
>    *not* continue numbering where we left off before!) before resetting
>    the count to zero.
> 
>    From the docs:
> 
>      If you use a `+n' switch, the numbering from the previous
>      numbered snippet will be continued in the current one.
> 
>    With this change I believe the code complies with the docs.
>  ---
>   lisp/org-exp.el |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
> 
>  diff --git a/lisp/org-exp.el b/lisp/org-exp.el
>  index 9884a31..12590e1 100644
>  --- a/lisp/org-exp.el
>  +++ b/lisp/org-exp.el
>  @@ -2731,7 +2731,7 @@ INDENT was the original indentation of the block."
>   (defun org-export-number-lines (text &optional skip1 skip2 number cont
>                       replace-labels label-format)
>     (setq skip1 (or skip1 0) skip2 (or skip2 0))
>  -  (if (not cont) (setq org-export-last-code-line-counter-value 0))
>  +  (if (and number (not cont)) (setq org-export-last-code-line-counter-value 0))
>     (with-temp-buffer
>       (insert text)
>       (goto-char (point-max))
>  -- 
>  1.7.4.1
> 
> 
> #+end_src
> 
> Regards,
> niels
> --
> http://pft.github.com
> 

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

* Re: Patch for numbering continuation in source blocks.
  2011-10-07 16:19 ` Carsten Dominik
@ 2011-10-08  9:28   ` Niels Giesen
  0 siblings, 0 replies; 3+ messages in thread
From: Niels Giesen @ 2011-10-08  9:28 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Hi Niels,
>
> is the purpose of this patch to be able to insert an unnumbered code block
> between two numbered ones and to continue the numbering from the first in the third?

Yes, that is the precise purpose. How concise you can put it!

-- 
http://pft.github.com/

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

end of thread, other threads:[~2011-10-08  9:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-02 10:40 Patch for numbering continuation in source blocks Niels Giesen
2011-10-07 16:19 ` Carsten Dominik
2011-10-08  9:28   ` Niels Giesen

Code repositories for project(s) associated with this 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).