Re: [Cvslog] r21149 - in /lyx-devel/trunk: lib/lyx2lyx/LyX.py lib/lyx2...

2007-10-23 Thread Richard Heck


Some of what needs fixing here will be fixed in the next commit, e.g., 
whitespace, parentheses.


rh

[EMAIL PROTECTED] wrote:

Author: rgheck
Date: Tue Oct 23 17:02:15 2007
New Revision: 21149

URL: http://www.lyx.org/trac/changeset/21149
Log:
InsetInclude becomes an InsetCommand.

Modified:
lyx-devel/trunk/lib/lyx2lyx/LyX.py
lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py
lyx-devel/trunk/src/Buffer.cpp
lyx-devel/trunk/src/LyXFunc.cpp
lyx-devel/trunk/src/factory.cpp
lyx-devel/trunk/src/frontends/qt4/GuiInclude.cpp
lyx-devel/trunk/src/insets/InsetInclude.cpp
lyx-devel/trunk/src/insets/InsetInclude.h

Modified: lyx-devel/trunk/lib/lyx2lyx/LyX.py
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/lib/lyx2lyx/LyX.py?rev=21149
==
--- lyx-devel/trunk/lib/lyx2lyx/LyX.py (original)
+++ lyx-devel/trunk/lib/lyx2lyx/LyX.py Tue Oct 23 17:02:15 2007
@@ -80,7 +80,7 @@
(1_3, [221], minor_versions(1.3 , 7)),
(1_4, range(222,246), minor_versions(1.4 , 5)),
(1_5, range(246,277), minor_versions(1.5 , 2)),
-   (1_6, range(277,296), minor_versions(1.6 , 0))] # Uwe: 
htmlurl, href
+   (1_6, range(277,297), minor_versions(1.6 , 0))] # RGH: 
InsetInclude
 
 
 def formats_list():


Modified: lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py
URL: 
http://www.lyx.org/trac/file/lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py?rev=21149
==
--- lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py (original)
+++ lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py Tue Oct 23 17:02:15 2007
@@ -581,6 +581,73 @@
 [\\begin_inset CommandInset url, LatexCommand url]
   i = i + 2
 
+def convert_include(document):

+  'Converts include insets to new format.'
+  i = 0
+  r = re.compile(r'\\begin_inset Include\s+\\([^{]+){([^}]*)}(?:\[(.*)\])?')
+  while True:
+i = find_token(document.body, \\begin_inset Include, i)
+if i == -1:
+  return
+line = document.body[i]
+previewline = document.body[i + 1]
+m = r.match(line)
+if m == None:
+  document.warning(Unable to match line  + str(i) +  of body!)
+  i += 1
+  continue
+cmd = m.group(1)
+fn  = m.group(2)
+opt = m.group(3)
+insertion = [\\begin_inset CommandInset include, 
+   LatexCommand  + cmd, previewline,

+   filename \ + fn + \]
+newlines = 2
+if opt:
+  insertion.append(lstparams  + '' + opt + '')
+  newlines += 1
+document.body[i : i + 2] = insertion
+i += newlines
+
+def revert_include(document):
+  'Reverts include insets to old format.'
+  i = 0
+  r1 = re.compile('LatexCommand (.+)')
+  r2 = re.compile('filename (.+)')
+  r3 = re.compile('options (.*)')
+  while True:
+i = find_token(document.body, \\begin_inset CommandInset include, i)
+if i == -1:
+  return
+previewline = document.body[i + 1]
+m = r1.match(document.body[i + 2])
+if m == None:
+  document.warning(Malformed LyX document: No LatexCommand line for ` +
+document.body[i] + ' on line  + str(i) + .)
+  i += 1
+  continue
+cmd = m.group(1)
+m = r2.match(document.body[i + 3])
+if m == None:
+  document.warning(Malformed LyX document: No filename line for ` + \
+document.body[i] + ' on line  + str(i) + .)
+  i += 2
+  continue
+fn = m.group(1)
+options = 
+numlines = 4
+if (cmd == lstinputlisting):
+  m = r3.match(document.body[i + 4])
+  if m != None:
+options = m.group(1)
+numlines = 5
+newline = \\begin_inset Include \\ + cmd + { + fn + }
+if options:
+  newline += ([ + options + ])
+insertion = [newline, previewline]
+document.body[i : i + numlines] = insertion
+i += 2
+   
 
 ##

 # Conversion hub
@@ -605,10 +672,12 @@
[292, []],
[293, []],
[294, [convert_pdf_options]],
-   [295, [convert_htmlurl, convert_url]]
+   [295, [convert_htmlurl, convert_url]],
+   [296, [convert_include]]
   ]
 
-revert =  [[294, [revert_href]],

+revert =  [[295, [revert_include]],
+   [294, [revert_href]],
[293, [revert_pdf_options_2]],
[292, [revert_inset_info]],
[291, [revert_japanese, revert_japanese_encoding]],

Modified: lyx-devel/trunk/src/Buffer.cpp
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/Buffer.cpp?rev=21149
==
--- lyx-devel/trunk/src/Buffer.cpp (original)
+++ lyx-devel/trunk/src/Buffer.cpp Tue Oct 23 17:02:15 2007
@@ -156,7 +156,7 @@
 
 namespace {
 
-int const LYX_FORMAT = 295; //Uwe: htmlurl, href

+int const LYX_FORMAT = 296; //RGH: InsetInclude changes
 
 } // namespace anon
 
@@ -2173,7 +2173,7 @@

for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) 

Re: [Cvslog] r21149 - in /lyx-devel/trunk: lib/lyx2lyx/LyX.py lib/lyx2...

2007-10-23 Thread Andre Poenitz
On Tue, Oct 23, 2007 at 11:09:20AM -0400, Richard Heck wrote:
 
 Some of what needs fixing here will be fixed in the next commit, e.g., 
 whitespace, parentheses.

It usually works the other way round: First fix, then commit. At least
for whitespace etc. this should be easy to follow...

Andre'


Re: [Cvslog] r21149 - in /lyx-devel/trunk: lib/lyx2lyx/LyX.py lib/lyx2...

2007-10-23 Thread Richard Heck

Andre Poenitz wrote:

On Tue, Oct 23, 2007 at 11:09:20AM -0400, Richard Heck wrote:
  
Some of what needs fixing here will be fixed in the next commit, e.g., 
whitespace, parentheses.



It usually works the other way round: First fix, then commit. At least
for whitespace etc. this should be easy to follow...
  


Yes, I know, but I somehow managed to make the changes you'd suggested 
in my private branch rather than in trunk, so they didn't get committed 
with the main bit. Anyway, the rest is now committed, so it should be OK.


rh

--
==
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto



Re: [Cvslog] r21149 - in /lyx-devel/trunk: lib/lyx2lyx/LyX.py lib/lyx2...

2007-10-23 Thread Richard Heck


Some of what needs fixing here will be fixed in the next commit, e.g., 
whitespace, parentheses.


rh

[EMAIL PROTECTED] wrote:

Author: rgheck
Date: Tue Oct 23 17:02:15 2007
New Revision: 21149

URL: http://www.lyx.org/trac/changeset/21149
Log:
InsetInclude becomes an InsetCommand.

Modified:
lyx-devel/trunk/lib/lyx2lyx/LyX.py
lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py
lyx-devel/trunk/src/Buffer.cpp
lyx-devel/trunk/src/LyXFunc.cpp
lyx-devel/trunk/src/factory.cpp
lyx-devel/trunk/src/frontends/qt4/GuiInclude.cpp
lyx-devel/trunk/src/insets/InsetInclude.cpp
lyx-devel/trunk/src/insets/InsetInclude.h

Modified: lyx-devel/trunk/lib/lyx2lyx/LyX.py
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/lib/lyx2lyx/LyX.py?rev=21149
==
--- lyx-devel/trunk/lib/lyx2lyx/LyX.py (original)
+++ lyx-devel/trunk/lib/lyx2lyx/LyX.py Tue Oct 23 17:02:15 2007
@@ -80,7 +80,7 @@
("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 2)),
-   ("1_6", range(277,296), minor_versions("1.6" , 0))] # Uwe: 
htmlurl, href
+   ("1_6", range(277,297), minor_versions("1.6" , 0))] # RGH: 
InsetInclude
 
 
 def formats_list():


Modified: lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py
URL: 
http://www.lyx.org/trac/file/lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py?rev=21149
==
--- lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py (original)
+++ lyx-devel/trunk/lib/lyx2lyx/lyx_1_6.py Tue Oct 23 17:02:15 2007
@@ -581,6 +581,73 @@
 ["\\begin_inset CommandInset url", "LatexCommand url"]
   i = i + 2
 
+def convert_include(document):

+  'Converts include insets to new format.'
+  i = 0
+  r = re.compile(r'\\begin_inset Include\s+\\([^{]+){([^}]*)}(?:\[(.*)\])?')
+  while True:
+i = find_token(document.body, "\\begin_inset Include", i)
+if i == -1:
+  return
+line = document.body[i]
+previewline = document.body[i + 1]
+m = r.match(line)
+if m == None:
+  document.warning("Unable to match line " + str(i) + " of body!")
+  i += 1
+  continue
+cmd = m.group(1)
+fn  = m.group(2)
+opt = m.group(3)
+insertion = ["\\begin_inset CommandInset include", 
+   "LatexCommand " + cmd, previewline,

+   "filename \"" + fn + "\""]
+newlines = 2
+if opt:
+  insertion.append("lstparams " + '"' + opt + '"')
+  newlines += 1
+document.body[i : i + 2] = insertion
+i += newlines
+
+def revert_include(document):
+  'Reverts include insets to old format.'
+  i = 0
+  r1 = re.compile('LatexCommand (.+)')
+  r2 = re.compile('filename (.+)')
+  r3 = re.compile('options (.*)')
+  while True:
+i = find_token(document.body, "\\begin_inset CommandInset include", i)
+if i == -1:
+  return
+previewline = document.body[i + 1]
+m = r1.match(document.body[i + 2])
+if m == None:
+  document.warning("Malformed LyX document: No LatexCommand line for `" +
+document.body[i] + "' on line " + str(i) + ".")
+  i += 1
+  continue
+cmd = m.group(1)
+m = r2.match(document.body[i + 3])
+if m == None:
+  document.warning("Malformed LyX document: No filename line for `" + \
+document.body[i] + "' on line " + str(i) + ".")
+  i += 2
+  continue
+fn = m.group(1)
+options = ""
+numlines = 4
+if (cmd == "lstinputlisting"):
+  m = r3.match(document.body[i + 4])
+  if m != None:
+options = m.group(1)
+numlines = 5
+newline = "\\begin_inset Include \\" + cmd + "{" + fn + "}"
+if options:
+  newline += ("[" + options + "]")
+insertion = [newline, previewline]
+document.body[i : i + numlines] = insertion
+i += 2
+   
 
 ##

 # Conversion hub
@@ -605,10 +672,12 @@
[292, []],
[293, []],
[294, [convert_pdf_options]],
-   [295, [convert_htmlurl, convert_url]]
+   [295, [convert_htmlurl, convert_url]],
+   [296, [convert_include]]
   ]
 
-revert =  [[294, [revert_href]],

+revert =  [[295, [revert_include]],
+   [294, [revert_href]],
[293, [revert_pdf_options_2]],
[292, [revert_inset_info]],
[291, [revert_japanese, revert_japanese_encoding]],

Modified: lyx-devel/trunk/src/Buffer.cpp
URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/Buffer.cpp?rev=21149
==
--- lyx-devel/trunk/src/Buffer.cpp (original)
+++ lyx-devel/trunk/src/Buffer.cpp Tue Oct 23 17:02:15 2007
@@ -156,7 +156,7 @@
 
 namespace {
 
-int const LYX_FORMAT = 295; //Uwe: htmlurl, href

+int const LYX_FORMAT = 296; //RGH: InsetInclude changes
 
 } // namespace anon
 
@@ -2173,7 +2173,7 @@

 

Re: [Cvslog] r21149 - in /lyx-devel/trunk: lib/lyx2lyx/LyX.py lib/lyx2...

2007-10-23 Thread Andre Poenitz
On Tue, Oct 23, 2007 at 11:09:20AM -0400, Richard Heck wrote:
> 
> Some of what needs fixing here will be fixed in the next commit, e.g., 
> whitespace, parentheses.

It usually works the other way round: First fix, then commit. At least
for whitespace etc. this should be easy to follow...

Andre'


Re: [Cvslog] r21149 - in /lyx-devel/trunk: lib/lyx2lyx/LyX.py lib/lyx2...

2007-10-23 Thread Richard Heck

Andre Poenitz wrote:

On Tue, Oct 23, 2007 at 11:09:20AM -0400, Richard Heck wrote:
  
Some of what needs fixing here will be fixed in the next commit, e.g., 
whitespace, parentheses.



It usually works the other way round: First fix, then commit. At least
for whitespace etc. this should be easy to follow...
  


Yes, I know, but I somehow managed to make the changes you'd suggested 
in my private branch rather than in trunk, so they didn't get committed 
with the main bit. Anyway, the rest is now committed, so it should be OK.


rh

--
==
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto