On 05/28/2013 04:42 PM, Liviu Andronic wrote:
Richard,
On Tue, May 28, 2013 at 6:46 AM, Richard Heck <rgh...@lyx.org> wrote:
Try the attached. (The first patch is unchanged.)
I still have trouble with this patch (after removing EOL and
whitespace issues). When applying it fails on latest trunk:
sh>patch -p1 < "0002-A-start-on-lyx2lyx-for-chunks.patch" (28091)
patching file lib/lyx2lyx/lyx_2_1.py
Hunk #1 succeeded at 4180 with fuzz 1 (offset 28 lines).
Hunk #2 FAILED at 4313.
1 out of 2 hunks FAILED -- saving rejects to file lib/lyx2lyx/lyx_2_1.py.rej
patching file src/version.h
Hunk #1 FAILED at 30.
1 out of 1 hunk FAILED -- saving rejects to file src/version.h.rej
sh>patch -p1 < "0002-A-start-on-lyx2lyx-for-chunks.patch" (28091) returned '1'
Could you try rebasing it on latest trunk? Maybe this is causing the failure.
I think this is due to other format changes in trunk. New patch attached.
If this works, then we need to do the reversion. Is the idea there to
take an inset and put each paragraph into a Chunk paragraph? With the
optional argument going into the first one, stuck into <<=...>>?
rh
>From fc1771a0cf7d9a604a7f139c1630ad57dd7b2b97 Mon Sep 17 00:00:00 2001
From: Richard Heck <rgh...@lyx.org>
Date: Wed, 29 May 2013 09:35:48 -0400
Subject: [PATCH] Patch to convert Sweave chunk paragraphs to insets (bug
#8588). Work by Liviu (C++) and Richard (Python).
---
lib/Makefile.am | 1 +
lib/layouts/knitr.module | 27 +----------
lib/layouts/noweb.module | 23 +---------
lib/layouts/sweave.module | 27 +----------
lib/lyx2lyx/lyx_2_1.py | 111 +++++++++++++++++++++++++++++++++++++++++++++-
src/version.h | 2 +-
6 files changed, 115 insertions(+), 76 deletions(-)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index cfdbc94..39340a2 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1932,6 +1932,7 @@ dist_layouts_DATA =\
layouts/lettre.layout \
layouts/lilypond.module \
layouts/linguistics.module \
+ layouts/litinsets.inc \
layouts/llncs.layout \
layouts/logicalmkup.module \
layouts/ltugboat.layout \
diff --git a/lib/layouts/knitr.module b/lib/layouts/knitr.module
index 0203973..e7ccb34 100644
--- a/lib/layouts/knitr.module
+++ b/lib/layouts/knitr.module
@@ -7,35 +7,10 @@
#Excludes: lilypond | sweave
Format 45
+Input litinsets.inc
OutputType literate
OutputFormat knitr
-Style Chunk
- Category Sweave
- LatexType Paragraph
- LatexName dummy
- Margin static
- Align Left
- AlignPossible Block, Left, Right, Center
- TopSep 0.7
- BottomSep 0.7
- NewLine 0
- FreeSpacing 1
- PassThru 1
- ParbreakIsNewline 1
- Spellcheck 0
- ## What is LabelType used for?
- LabelType Static
- TextFont
- Color latex
- Family Typewriter
- EndFont
-End
-
-Style Scrap
- ObsoletedBy Chunk
-End
-
InsetLayout "Flex:Sweave Options"
LabelString "Sweave opts"
LatexType Command
diff --git a/lib/layouts/noweb.module b/lib/layouts/noweb.module
index fc105fd..da8e96b 100644
--- a/lib/layouts/noweb.module
+++ b/lib/layouts/noweb.module
@@ -5,30 +5,9 @@
#Category: literate
Format 45
+Input litinsets.inc
OutputType literate
AddToPreamble
\usepackage{noweb}
EndPreamble
-
-Style Chunk
- Margin First_Dynamic
- LatexType Paragraph
- LatexName dummy
- LeftMargin MMM
- Align Left
- AlignPossible Block,Left
- NewLine 0
- FreeSpacing 1
- PassThru 1
- ParbreakIsNewline 1
- Spellcheck 0
- LabelType Static
- LabelFont
- Color magenta
- EndFont
- TextFont
- Color latex
- Family Typewriter
- EndFont
-End
diff --git a/lib/layouts/sweave.module b/lib/layouts/sweave.module
index 9126420..dd0e642 100644
--- a/lib/layouts/sweave.module
+++ b/lib/layouts/sweave.module
@@ -7,6 +7,7 @@
#Excludes: lilypond
Format 45
+Input litinsets.inc
OutputType literate
OutputFormat sweave
@@ -20,32 +21,6 @@ AddToPreamble
@
EndPreamble
-Style Chunk
- Category Sweave
- LatexType Paragraph
- LatexName dummy
- Margin static
- Align Left
- AlignPossible Block, Left, Right, Center
- TopSep 0.7
- BottomSep 0.7
- NewLine 0
- FreeSpacing 1
- PassThru 1
- ParbreakIsNewline 1
- Spellcheck 0
- ## What is LabelType used for?
- LabelType Static
- TextFont
- Color latex
- Family Typewriter
- EndFont
-End
-
-Style Scrap
- ObsoletedBy Chunk
-End
-
InsetLayout "Flex:Sweave Options"
LabelString "Sweave opts"
LatexType Command
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index 0c38796..f8d344c 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -4229,6 +4229,113 @@ def revert_tibetan(document):
j = len(document.body)
+#############
+#
+# Chunk stuff
+#
+#############
+
+# the idea here is that we will have a sequence of chunk paragraphs
+# we want to convert them to paragraphs in a chunk inset
+# the last will be discarded
+# the first should look like: <<FROGS>>=
+# will will discard the delimiters, and put the contents into the
+# optional argument of the inset
+def convert_chunks(document):
+ first_re = re.compile(r'<<(.*)>>=')
+ k = 0
+ while True:
+ # the beginning of this sequence
+ i = k
+ # find start of a block of chunks
+ i = find_token(document.body, "\\begin_layout Chunk", i)
+ if i == -1:
+ return
+ start = i
+ end = -1
+ contents = []
+
+ while True:
+ # process the one we just found
+ j = find_end_of_layout(document.body, i)
+ if j == -1:
+ document.warning("Malformed LyX documents. Can't find end of Chunk layout!")
+ break
+ contents.append("".join(document.body[i + 1:j]))
+
+ # look for the next one
+ i = j
+ i = find_token(document.body, "\\begin_layout", i)
+ if i == -1:
+ break
+
+ layout = get_value(document.body, "\\begin_layout", i)
+ #sys.stderr.write(layout+ '\n')
+ if layout != "Chunk":
+ k = i
+ break
+
+ if j == -1:
+ # error, but we can try to continue
+ k = j + 1
+ continue
+
+ end = j + 1
+ k = end
+
+ sys.stderr.write('\n'.join(contents) + '\n\n')
+
+ # the last chunk should simply have an "@" in it
+ # we could check that
+ contents.pop()
+
+ # the first item should look like: <<FROGS>>=
+ # we want the inside
+ first = contents[0]
+ first.strip()
+ match = first_re.search(first)
+ if not match:
+ document.warning("Invalid first chunk!")
+ first = ""
+ else:
+ first = match.groups()[0]
+
+ # remove the first item
+ contents.pop(0)
+
+ newstuff = ['\\begin_layout Standard',
+ '\\begin_inset Flex Chunk',
+ 'status open', '',
+ '\\begin_layout Plain Layout', '']
+
+ if first:
+ newstuff.extend(
+ ['\\begin_inset Argument 1',
+ 'status open', '',
+ '\\begin_layout Plain Layout',
+ first,
+ '\\end_layout', '',
+ '\\end_inset', ''])
+
+ didone = False
+ for c in contents:
+ if didone:
+ newstuff.extend(['', '\\begin_layout Plain Layout', ''])
+ else:
+ didone = True
+ newstuff.extend([c, '\\end_layout'])
+
+ newstuff.extend(['', '\\end_inset', '', '\\end_layout', ''])
+
+ document.body[start:end] = newstuff
+
+ k += len(newstuff) - (end - start)
+
+
+def revert_chunks(document):
+ pass
+
+
##
# Conversion hub
#
@@ -4294,10 +4401,12 @@ convert = [
[470, []],
[471, [convert_cite_engine_type_default]],
[472, []],
- [473, []]
+ [473, []],
+ [474, [convert_chunks]],
]
revert = [
+ [473, [revert_chunks]],
[472, [revert_tibetan]],
[471, [revert_aa1,revert_aa2]],
[470, [revert_cite_engine_type_default]],
diff --git a/src/version.h b/src/version.h
index 3aa8ce8..99c4467 100644
--- a/src/version.h
+++ b/src/version.h
@@ -30,7 +30,7 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 473 // uwestoehr: support Tibetan as document language
+#define LYX_FORMAT_LYX 474 // rgh: dummy format change for Chunk switch
#define LYX_FORMAT_TEX2LYX 473
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
--
1.7.11.7