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.
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 next_inset_modify(line):
41 return simple_renaming(line, "next-inset-modify", "inset-modify")
44 def next_inset_toggle(line):
45 return simple_renaming(line, "next-inset-toggle", "inset-toggle")
48 def optional_insert(line):
49 return simple_renaming(line, "optional-insert", "argument-insert")
52 re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
53 def notes_mutate(line):
54 m = re_nm.search(line)
62 newline = prefix + "inset-forall Note:" + source + \
63 " inset-modify note Note " + target + suffix
64 return (True, newline)
67 re_ait = re.compile(r'^(.*)all-insets-toggle\s+(\w+)(?:\s+(\w+))?(.*)$')
68 def all_insets_toggle(line):
69 m = re_ait.search(line)
78 # we need to transform the target to match the inset layout names
79 # this will not be perfect
84 elif target == "tabular":
85 # There does not seem to be an InsetLayout for tables, so
86 # I do not know what to do here. If anyone does, then please
87 # fix this. For now, we just have to remove this line.
90 target = target.capitalize()
92 newline = prefix + "inset-forall " + target + " inset-toggle " + \
94 return (True, newline)
97 re_li = re.compile(r'^(.*)\bline-insert\b(.*)$')
98 def line_insert(line):
99 m = re_li.search(line)
102 newline = m.group(1) + \
103 "inset-insert line rule height 0.25ex width 100col% \\end_inset" + \
105 return (True, newline)
108 def toc_insert(line):
109 return simple_renaming(line, "toc-insert", "inset-insert toc")
112 re_ps = re.compile(r'^(.*)paragraph-spacing\s+(default|single|onehalf|double)\b(.*)$')
113 re_psother = re.compile(r'^(.*)paragraph-spacing\s+other\s+(\d+\.\d?|\d?\.\d+|\d+)(.*)$')
114 def paragraph_spacing(line):
115 # possible args: default, single, onehalf, double, other FLOAT
116 m = re_ps.search(line)
119 newline = m.group(1) + "paragraph-params \\paragraph-spacing " + arg + \
121 return (True, newline)
123 m = re_psother.search(line)
128 newline = m.group(1) + "paragraph-params \\paragraph-spacing other " + \
130 return (True, newline)
133 def tabular_feature(line):
134 return simple_renaming(line, "tabular-feature", "inset-modify tabular")
136 re_Bar2bar = re.compile(r'^(\\(?:bind|unbind))\s+"([^"]*)Bar"(\s+"[^"]+")')
138 m = re_Bar2bar.search(line)
145 newline = btype + " \"" + mod + "bar\"" + rest
146 return (True, newline)
148 def paragraph_break(line):
149 return simple_renaming(line, "break-paragraph", "paragraph-break")
151 def tab_group_close(line):
152 return simple_renaming(line, "close-tab-group", "tab-group-close")
154 def view_split(line):
155 return simple_renaming(line, "split-view", "view-split")
157 def label_copy_as_reference(line):
158 return simple_renaming(line, "copy-label-as-reference", "label-copy-as-reference")
162 ###########################################################
168 [ 1, [ # this will be a long list of conversions to format 1, LyX 2.0
180 [ 2, [ # list of conversions to format 2, LyX 2.1
184 label_copy_as_reference