1 # file prefs2prefs-lfuns.py
2 # This file is part of LyX, the document processor.
3 # Licence details can be found in the file COPYING.
5 # author Richard Kimberly Heck
7 # Full author contact details are available in file CREDITS
9 # This file houses conversion information for the bind and ui files,
10 # i.e., for files where we are converting lfuns.
12 # The converter functions take a line as argument and return a list:
14 # where the Bool says if we've modified anything and the NewLine is
15 # the new line, if so, which will be used to replace the old line.
20 ###########################################################
22 # Actual converter functions
24 # These accept a line as argument and should return a list:
26 # where the bool indicates whether we changed anything. If not,
27 # one normally returns: (False, "").
29 no_match = (False, "")
31 def simple_renaming(line, old, new):
32 if line.find(old) == -1:
34 line = line.replace(old, new)
38 def simple_remove(line, old):
39 if line.find(old) == -1:
44 def next_inset_modify(line):
45 return simple_renaming(line, "next-inset-modify", "inset-modify")
48 def next_inset_toggle(line):
49 return simple_renaming(line, "next-inset-toggle", "inset-toggle")
52 def optional_insert(line):
53 return simple_renaming(line, "optional-insert", "argument-insert")
56 re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
57 def notes_mutate(line):
58 m = re_nm.search(line)
66 newline = prefix + "inset-forall Note:" + source + \
67 " inset-modify note Note " + target + suffix
68 return (True, newline)
71 re_ait = re.compile(r'^(.*)all-insets-toggle\s+(\w+)(?:\s+(\w+))?(.*)$')
72 def all_insets_toggle(line):
73 m = re_ait.search(line)
82 # we need to transform the target to match the inset layout names
83 # this will not be perfect
88 elif target == "tabular":
89 # There does not seem to be an InsetLayout for tables, so
90 # I do not know what to do here. If anyone does, then please
91 # fix this. For now, we just have to remove this line.
94 target = target.capitalize()
96 newline = prefix + "inset-forall " + target + " inset-toggle " + \
98 return (True, newline)
101 re_li = re.compile(r'^(.*)\bline-insert\b(.*)$')
102 def line_insert(line):
103 m = re_li.search(line)
106 newline = m.group(1) + \
107 "inset-insert line rule height 0.25ex width 100col% \\end_inset" + \
109 return (True, newline)
112 def toc_insert(line):
113 return simple_renaming(line, "toc-insert", "inset-insert toc")
116 re_ps = re.compile(r'^(.*)paragraph-spacing\s+(default|single|onehalf|double)\b(.*)$')
117 re_psother = re.compile(r'^(.*)paragraph-spacing\s+other\s+(\d+\.\d?|\d?\.\d+|\d+)(.*)$')
118 def paragraph_spacing(line):
119 # possible args: default, single, onehalf, double, other FLOAT
120 m = re_ps.search(line)
123 newline = m.group(1) + "paragraph-params \\paragraph-spacing " + arg + \
125 return (True, newline)
127 m = re_psother.search(line)
132 newline = m.group(1) + "paragraph-params \\paragraph-spacing other " + \
134 return (True, newline)
137 def tabular_feature(line):
138 return simple_renaming(line, "tabular-feature", "inset-modify tabular")
141 re_tabular_feature = re.compile(r"inset-modify\s+tabular(\s+from-dialog)?")
142 def redo_tabular_feature(line):
143 # we change as follows:
144 # inset-modify tabular -> tabular-feature
146 # inset-modify tabular from-dialog -> inset-modify tabular
148 # "from-dialog" was never used directly but the user might do, if they
149 # followed the standard instructions to create a custom shortcut by looking
150 # at the message panel. The equivalent functionality is now provided by
151 # inset-modify tabular (without from-dialog).
154 return "inset-modify tabular"
156 return "tabular-feature"
158 result = re_tabular_feature.subn(change, line)
160 return (True, result[0])
165 re_Bar2bar = re.compile(r'^(\\(?:bind|unbind))\s+"([^"]*)Bar"(\s+"[^"]+")')
167 m = re_Bar2bar.search(line)
174 newline = btype + " \"" + mod + "bar\"" + rest
175 return (True, newline)
178 def paragraph_break(line):
179 return simple_renaming(line, "break-paragraph", "paragraph-break")
182 def tab_group_close(line):
183 return simple_renaming(line, "close-tab-group", "tab-group-close")
186 def view_split(line):
187 return simple_renaming(line, "split-view", "view-split")
190 def label_copy_as_reference(line):
191 return simple_renaming(line, "copy-label-as-reference", "label-copy-as-reference")
194 def remove_print_support(line):
195 return simple_remove(line, "dialog-show print")
198 def info_rename_vcsauthor(line):
199 return simple_renaming(line, "info-insert buffer vcs-author", "info-insert vcs author")
202 def info_rename_vcsdate(line):
203 return simple_renaming(line, "info-insert buffer vcs-date", "info-insert vcs date")
206 def info_rename_vcstime(line):
207 return simple_renaming(line, "info-insert buffer vcs-time", "info-insert vcs time")
210 def info_rename_vcsrevision(line):
211 return simple_renaming(line, "info-insert buffer vcs-revision", "info-insert vcs revision")
214 def info_rename_vcstreerevision(line):
215 return simple_renaming(line, "info-insert buffer vcs-tree-revision", "info-insert vcs tree-revision")
218 def remove_date_insert(line):
219 return simple_remove(line, "date-insert")
222 re_delete_force = re.compile(r"((char|word)-delete-(for|back)ward)(\s+force)?")
223 def delete_force(line):
224 # we change as follows:
225 # char-delete-forward -> char-delete-forward confirm
227 # char-delete-forward force -> char-delete-forward
231 return match.group(1)
233 return match.group(1) + " confirm"
235 result = re_delete_force.subn(change, line)
237 return (True, result[0])
244 ###########################################################
250 [ 1, [ # this will be a long list of conversions to format 1, LyX 2.0
262 [ 2, [ # list of conversions to format 2, LyX 2.1
266 label_copy_as_reference
268 [ 3, [ # list of conversions to format 3
271 [ 4, [ # list of conversions to format 4, LyX 2.2
274 [ 5, [ # list of conversions to format 5, LyX 2.4
275 info_rename_vcsauthor,
278 info_rename_vcsrevision,
279 info_rename_vcstreerevision,