2 # -*- coding: utf-8 -*-
4 # file prefs2prefs-lfuns.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
10 # Full author contact details are available in file CREDITS
12 # This file houses conversion information for the preferences file.
14 # The converter functions take a line as argument and return a list:
16 # where the Bool says if we've modified anything and the NewLine is
17 # the new line, if so, which will be used to replace the old line.
19 # Incremented to format 2, r39670 by jrioux
20 # Support for multiple file extensions per format.
21 # No conversion necessary.
26 ###########################################################
30 def simple_renaming(line, old, new):
31 if line.find(old) == -1:
33 line = line.replace(old, new)
36 no_match = (False, [])
38 ########################
39 ### Format 1 conversions
41 def remove_obsolete(line):
42 tags = ("\\use_tempdir", "\\spell_command", "\\personal_dictionary",
43 "\\plaintext_roff_command", "\\use_alt_language",
44 "\\use_escape_chars", "\\use_input_encoding",
45 "\\use_personal_dictionary", "\\use_pspell",
49 if line.startswith(tag):
53 def language_use_babel(line):
54 if not line.startswith("\language_use_babel"):
56 re_lub = re.compile(r'^\\language_use_babel\s+"?(true|false)')
57 m = re_lub.match(line)
62 newline = "\\language_package_selection " + newval
63 return (True, newline)
65 def language_package(line):
66 return simple_renaming(line, "\\language_package", "\\language_custom_package")
68 lfre = re.compile(r'^\\converter\s+"?(\w+)"?\s+"?(\w+)"?\s+"([^"]*?)"\s+"latex"')
69 def latex_flavor(line):
70 if not line.startswith("\\converter"):
83 if conv in conv2fl.keys():
84 flavor = conv2fl[conv]
90 "\\converter \"%s\" \"%s\" \"%s\" \"latex=%s\"" % (conv, fmat, args, flavor))
92 emre = re.compile(r'^\\[Ff]ormat\s+(.*)\s+"(document[^"]*?)"')
93 def export_menu(line):
94 if not line.lower().startswith("\\format"):
102 "\\Format %s \"%s,menu=export\"" % (fmat, opts))
104 ########################
108 [ 1, [ # this will be a long list of conversions to format 1