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.
25 ###########################################################
27 # Actual converter functions
29 # These accept a line as argument and should return a list:
31 # where the bool indicates whether we changed anything. If not,
32 # one normally returns: (False, []).
34 no_match = (False, [])
36 def simple_renaming(line, old, new):
37 if line.find(old) == -1:
39 line = line.replace(old, new)
43 def next_inset_modify(line):
44 return simple_renaming(line, "next-inset-modify", "inset-modify")
47 def next_inset_toggle(line):
48 return simple_renaming(line, "next-inset-toggle", "inset-toggle")
51 def optional_insert(line):
52 return simple_renaming(line, "argument-insert", "optional-insert")
55 re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
56 def notes_mutate(line):
57 m = re_nm.search(line)
65 newline = prefix + "inset-forall Note:" + source + \
66 " inset-modify note Note " + target + suffix
67 return (True, newline)
70 re_ait = re.compile(r'^(.*)all-insets-toggle\s+(\w+)(?:\s+(\w+))?(.*)$')
71 def all_insets_toggle(line):
72 m = re_ait.search(line)
81 # we need to transform the target to match the inset layout names
82 # this will not be perfect
87 elif target == "tabular":
88 # There does not seem to be an InsetLayout for tables, so
89 # I do not know what to do here. If anyone does, then please
90 # fix this. For now, we just have to remove this line.
93 target = target.capitalize()
95 newline = prefix + "inset-forall " + target + " inset-toggle " + \
97 return (True, newline)
100 re_li = re.compile(r'^(.*)\bline-insert\b(.*)$')
101 def line_insert(line):
102 m = re_li.search(line)
105 newline = m.group(1) + \
106 "inset-insert line rule height 0.25ex width 100col% \\end_inset" + \
108 return (True, newline)
111 def toc_insert(line):
112 return simple_renaming(line, "toc-insert", "inset-insert toc")
115 re_ps = re.compile(r'^(.*)paragraph-spacing\s+(default|single|onehalf|double)\b(.*)$')
116 re_psother = re.compile(r'^(.*)paragraph-spacing\s+other\s+(\d+\.\d?|\d?\.\d+|\d+)(.*)$')
117 def paragraph_spacing(line):
118 # possible args: default, single, onehalf, double, other FLOAT
119 m = re_ps.search(line)
122 newline = m.group(1) + "paragraph-params \\paragraph-spacing " + arg + \
124 return (True, newline)
126 m = re_psother.search(line)
131 newline = m.group(1) + "paragraph-params \\paragraph-spacing other " + \
133 return (True, newline)
136 def tabular_feature(line):
137 return simple_renaming(line, "tabular-feature", "inset-modify tabular")
142 ###########################################################
148 [ # this will be a long list of conversions for format 0
158 ] # end conversions for format 0