1 # -*- coding: utf-8 -*-
3 # file prefs2prefs-lfuns.py
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
7 # author Richard Kimberly Heck
9 # Full author contact details are available in file CREDITS
11 # This file houses conversion information for the bind and ui files,
12 # i.e., for files where we are converting lfuns.
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.
22 ###########################################################
24 # Actual converter functions
26 # These accept a line as argument and should return a list:
28 # where the bool indicates whether we changed anything. If not,
29 # one normally returns: (False, "").
31 no_match = (False, "")
33 def simple_renaming(line, old, new):
34 if line.find(old) == -1:
36 line = line.replace(old, new)
40 def simple_remove(line, old):
41 if line.find(old) == -1:
46 def next_inset_modify(line):
47 return simple_renaming(line, "next-inset-modify", "inset-modify")
50 def next_inset_toggle(line):
51 return simple_renaming(line, "next-inset-toggle", "inset-toggle")
54 def optional_insert(line):
55 return simple_renaming(line, "optional-insert", "argument-insert")
58 re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
59 def notes_mutate(line):
60 m = re_nm.search(line)
68 newline = prefix + "inset-forall Note:" + source + \
69 " inset-modify note Note " + target + suffix
70 return (True, newline)
73 re_ait = re.compile(r'^(.*)all-insets-toggle\s+(\w+)(?:\s+(\w+))?(.*)$')
74 def all_insets_toggle(line):
75 m = re_ait.search(line)
84 # we need to transform the target to match the inset layout names
85 # this will not be perfect
90 elif target == "tabular":
91 # There does not seem to be an InsetLayout for tables, so
92 # I do not know what to do here. If anyone does, then please
93 # fix this. For now, we just have to remove this line.
96 target = target.capitalize()
98 newline = prefix + "inset-forall " + target + " inset-toggle " + \
100 return (True, newline)
103 re_li = re.compile(r'^(.*)\bline-insert\b(.*)$')
104 def line_insert(line):
105 m = re_li.search(line)
108 newline = m.group(1) + \
109 "inset-insert line rule height 0.25ex width 100col% \\end_inset" + \
111 return (True, newline)
114 def toc_insert(line):
115 return simple_renaming(line, "toc-insert", "inset-insert toc")
118 re_ps = re.compile(r'^(.*)paragraph-spacing\s+(default|single|onehalf|double)\b(.*)$')
119 re_psother = re.compile(r'^(.*)paragraph-spacing\s+other\s+(\d+\.\d?|\d?\.\d+|\d+)(.*)$')
120 def paragraph_spacing(line):
121 # possible args: default, single, onehalf, double, other FLOAT
122 m = re_ps.search(line)
125 newline = m.group(1) + "paragraph-params \\paragraph-spacing " + arg + \
127 return (True, newline)
129 m = re_psother.search(line)
134 newline = m.group(1) + "paragraph-params \\paragraph-spacing other " + \
136 return (True, newline)
139 def tabular_feature(line):
140 return simple_renaming(line, "tabular-feature", "inset-modify tabular")
143 re_tabular_feature = re.compile(r"inset-modify\s+tabular(\s+from-dialog)?")
144 def redo_tabular_feature(line):
145 # we change as follows:
146 # inset-modify tabular -> tabular-feature
148 # inset-modify tabular from-dialog -> inset-modify tabular
150 # "from-dialog" was never used directly but the user might do, if they
151 # followed the standard instructions to create a custom shortcut by looking
152 # at the message panel. The equivalent functionality is now provided by
153 # inset-modify tabular (without from-dialog).
156 return "inset-modify tabular"
158 return "tabular-feature"
160 result = re_tabular_feature.subn(change, line)
162 return (True, result[0])
167 re_Bar2bar = re.compile(r'^(\\(?:bind|unbind))\s+"([^"]*)Bar"(\s+"[^"]+")')
169 m = re_Bar2bar.search(line)
176 newline = btype + " \"" + mod + "bar\"" + rest
177 return (True, newline)
180 def paragraph_break(line):
181 return simple_renaming(line, "break-paragraph", "paragraph-break")
184 def tab_group_close(line):
185 return simple_renaming(line, "close-tab-group", "tab-group-close")
188 def view_split(line):
189 return simple_renaming(line, "split-view", "view-split")
192 def label_copy_as_reference(line):
193 return simple_renaming(line, "copy-label-as-reference", "label-copy-as-reference")
196 def remove_print_support(line):
197 return simple_remove(line, "dialog-show print")
200 def info_rename_vcsauthor(line):
201 return simple_renaming(line, "info-insert buffer vcs-author", "info-insert vcs author")
204 def info_rename_vcsdate(line):
205 return simple_renaming(line, "info-insert buffer vcs-date", "info-insert vcs date")
208 def info_rename_vcstime(line):
209 return simple_renaming(line, "info-insert buffer vcs-time", "info-insert vcs time")
212 def info_rename_vcsrevision(line):
213 return simple_renaming(line, "info-insert buffer vcs-revision", "info-insert vcs revision")
216 def info_rename_vcstreerevision(line):
217 return simple_renaming(line, "info-insert buffer vcs-tree-revision", "info-insert vcs tree-revision")
220 def remove_date_insert(line):
221 return simple_remove(line, "date-insert")
225 ###########################################################
231 [ 1, [ # this will be a long list of conversions to format 1, LyX 2.0
243 [ 2, [ # list of conversions to format 2, LyX 2.1
247 label_copy_as_reference
249 [ 3, [ # list of conversions to format 3
252 [ 4, [ # list of conversions to format 4, LyX 2.2
255 [ 5, [ # list of conversions to format 5, LyX 2.4
256 info_rename_vcsauthor,
259 info_rename_vcsrevision,
260 info_rename_vcstreerevision,