]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_0.py
Factor out some common code.
[lyx.git] / lib / lyx2lyx / lyx_2_0.py
index 164e4a1c483a062b9811194ed093dba98459dd1e..79f9f1be2f17c2fa826bf22c751038cbea3b0f8f 100644 (file)
@@ -25,7 +25,7 @@ import sys, os
 
 from parser_tools import find_token, find_end_of, find_tokens, \
   find_end_of_inset, find_end_of_layout, find_token_backwards, \
-  get_value, get_value_string
+  get_containing_inset, get_value, get_value_string
   
 from lyx2lyx_tools import add_to_preamble, insert_to_preamble, \
   put_cmd_in_ert, lyx2latex, latex_length, revert_flex_inset, \
@@ -1587,18 +1587,10 @@ def revert_nameref(document):
       i += 1
       # Make sure it is actually in an inset!
       # A normal line could begin with "LatexCommand nameref"!
-      # We could just check document.lines[i-1], but that relies
-      # upon something that might easily change.
-      # So let's see if we're in a ref inset...
-      stins = find_token_backwards(document.body, "\\begin_inset CommandInset ref", cmdloc)
+      stins, endins = get_containing_inset(document.body, cmdloc, \
+          "\\begin_inset CommandInset ref")
       if stins == -1:
         continue
-      endins = find_end_of_inset(document.body, stins)
-      if endins == -1:
-        document.warning("Can't find end of inset at line " + stins + "!!")
-        continue
-      if endins < cmdloc:
-        continue
 
       # ok, so it is in an InsetRef
       refline = find_token(document.body, "reference", stins, endins)
@@ -1631,20 +1623,9 @@ def remove_Nameref(document):
     i += 1
     
     # Make sure it is actually in an inset!
-    # We could just check document.lines[i-1], but that relies
-    # upon something that might easily change.
-    # We'll look back a few lines.
-    stins = cmdloc - 10
-    if stins < 0:
-      stins = 0
-    stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
-    if stins == -1 or stins > cmdloc:
-      continue
-    endins = find_end_of_inset(document.body, stins)
-    if endins == -1:
-      document.warning("Can't find end of inset at line " + stins + "!!")
-      continue
-    if endins < cmdloc:
+    stins, endins = get_containing_inset(document.body, \
+        cmdloc, "\\begin_inset CommandInset ref")
+    if stins == -1:
       continue
     document.body[cmdloc] = "LatexCommand nameref"