+ def append_local_layout(self, new_layout):
+ " Append `new_layout` to the local layouts."
+ # new_layout may be a string or a list of strings (lines)
+ try:
+ new_layout = new_layout.splitlines()
+ except AttributeError:
+ pass
+ i = find_token(self.header, "\\begin_local_layout", 0)
+ if i == -1:
+ k = find_token(self.header, "\\language", 0)
+ if k == -1:
+ # this should not happen
+ self.warning("Malformed LyX document! No \\language header found!")
+ return
+ self.header[k : k] = ["\\begin_local_layout", "\\end_local_layout"]
+ i = k
+
+ j = find_end_of(self.header, i, "\\begin_local_layout", "\\end_local_layout")
+ if j == -1:
+ # this should not happen
+ self.warning("Malformed LyX document: Can't find end of local layout!")
+ return
+
+ self.header[i+1 : i+1] = new_layout
+
+ def del_local_layout(self, layout_def):
+ " Delete `layout_def` from local layouts, return success."
+ i = find_complete_lines(self.header, layout_def)
+ if i == -1:
+ return False
+ j = i+len(layout_def)
+ if (self.header[i-1] == "\\begin_local_layout" and
+ self.header[j] == "\\end_local_layout"):
+ i -=1
+ j +=1
+ self.header[i:j] = []
+ return True
+
+ def del_from_header(self, lines):
+ " Delete `lines` from the document header, return success."
+ i = find_complete_lines(self.header, lines)
+ if i == -1:
+ return False
+ j = i + len(lines)
+ self.header[i:j] = []
+ return True
+