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 bind and ui files,
13 # i.e., for files where we are converting lfuns.
15 # The converter functions take a line as argument and return a list:
17 # where the Bool says if we've modified anything and the NewLine is
18 # the new line, if so, which will be used to replace the old line.
23 ###########################################################
25 # Actual converter functions
27 # These accept a line as argument and should return a list:
29 # where the bool indicates whether we changed anything. If not,
30 # one normally returns: (False, []).
32 no_match = (False, [])
34 def simple_renaming(line, old, new):
35 if line.find(old) == -1:
37 line = line.replace(old, new)
41 def next_inset_modify(line):
42 return simple_renaming(line, "next-inset-modify", "inset-modify")
45 def next_inset_toggle(line):
46 return simple_renaming(line, "next-inset-toggle", "inset-toggle")
49 def optional_insert(line):
50 return simple_renaming(line, "optional-insert", "argument-insert")
53 re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
54 def notes_mutate(line):
55 m = re_nm.search(line)
63 newline = prefix + "inset-forall Note:" + source + \
64 " inset-modify note Note " + target + suffix
65 return (True, newline)
68 re_ait = re.compile(r'^(.*)all-insets-toggle\s+(\w+)(?:\s+(\w+))?(.*)$')
69 def all_insets_toggle(line):
70 m = re_ait.search(line)
79 # we need to transform the target to match the inset layout names
80 # this will not be perfect
85 elif target == "tabular":
86 # There does not seem to be an InsetLayout for tables, so
87 # I do not know what to do here. If anyone does, then please
88 # fix this. For now, we just have to remove this line.
91 target = target.capitalize()
93 newline = prefix + "inset-forall " + target + " inset-toggle " + \
95 return (True, newline)
98 re_li = re.compile(r'^(.*)\bline-insert\b(.*)$')
99 def line_insert(line):
100 m = re_li.search(line)
103 newline = m.group(1) + \
104 "inset-insert line rule height 0.25ex width 100col% \\end_inset" + \
106 return (True, newline)
109 def toc_insert(line):
110 return simple_renaming(line, "toc-insert", "inset-insert toc")
113 re_ps = re.compile(r'^(.*)paragraph-spacing\s+(default|single|onehalf|double)\b(.*)$')
114 re_psother = re.compile(r'^(.*)paragraph-spacing\s+other\s+(\d+\.\d?|\d?\.\d+|\d+)(.*)$')
115 def paragraph_spacing(line):
116 # possible args: default, single, onehalf, double, other FLOAT
117 m = re_ps.search(line)
120 newline = m.group(1) + "paragraph-params \\paragraph-spacing " + arg + \
122 return (True, newline)
124 m = re_psother.search(line)
129 newline = m.group(1) + "paragraph-params \\paragraph-spacing other " + \
131 return (True, newline)
134 def tabular_feature(line):
135 return simple_renaming(line, "tabular-feature", "inset-modify tabular")
137 re_Bar2bar = re.compile(r'^(\\(?:bind|unbind))\s+"([^"]*)Bar"(\s+"[^"]+")')
139 m = re_Bar2bar.search(line)
146 newline = btype + " \"" + mod + "bar\"" + rest
147 return (True, newline)
151 ###########################################################
157 [ 1, [ # this will be a long list of conversions to format 1