]> git.lyx.org Git - lyx.git/blob - lib/scripts/prefs2prefs_lfuns.py
Increase tex2lyx output format to 273.
[lyx.git] / lib / scripts / prefs2prefs_lfuns.py
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
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.
7
8 # author Richard Heck
9
10 # Full author contact details are available in file CREDITS
11
12 # This file houses conversion information for the bind and ui files,
13 # i.e., for files where we are converting lfuns.
14
15 # The converter functions take a line as argument and return a list: 
16 #       (Bool, NewLine), 
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.
19
20
21 import sys, re
22
23 current_format = 1
24
25 ###########################################################
26 #
27 # Actual converter functions
28 #
29 # These accept a line as argument and should return a list:
30 #  (bool, newline)
31 # where the bool indicates whether we changed anything. In 
32 # that case, one normally returns: (False, []).
33
34 no_match = (False, [])
35
36 def simple_renaming(line, old, new):
37         if line.find(old) == -1:
38                 return no_match
39         line = line.replace(old, new)
40         return (True, line)
41
42
43 def next_inset_modify(line):
44         return simple_renaming(line, "next-inset-modify", "inset-modify")
45
46
47 def next_inset_toggle(line):
48         return simple_renaming(line, "next-inset-toggle", "inset-toggle")
49
50
51 def optional_insert(line):
52         return simple_renaming(line, "argument-insert", "optional-insert")
53
54
55 re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
56 def notes_mutate(line):
57         m = re_nm.search(line)
58         if not m:
59                 return no_match
60
61         prefix = m.group(1)
62         source = m.group(2)
63         target = m.group(3)
64         suffix = m.group(4)
65         newline = prefix + "inset-forall Note:" + source + \
66                 " inset-modify note Note " + target + suffix
67         return (True, newline)
68
69
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)
73         if not m:
74                 return no_match
75
76         prefix = m.group(1)
77         action = m.group(2)
78         target = m.group(3) 
79         suffix = m.group(4)
80
81         # we need to transform the target to match the inset layout names
82         # this will not be perfect
83         if target == "ert":
84                 target = "ERT"
85         elif target == None:
86                 target = "*"
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.
91                 return (True, "")
92         else:
93                 target = target.capitalize()
94         
95         newline = prefix + "inset-forall " + target + " inset-toggle " + \
96                 action + suffix
97         return (True, newline)
98
99
100 re_li = re.compile(r'^(.*)\bline-insert\b(.*)$')
101 def line_insert(line):
102         m = re_li.search(line)
103         if not m: 
104                 return no_match
105         newline = m.group(1) + \
106                 "inset-insert line rule height 0.25ex width 100col% \\end_inset" + \
107                 m.group(2)
108         return (True, newline)
109
110
111 def toc_insert(line):
112         return simple_renaming(line, "toc-insert", "inset-insert toc")
113
114
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)
120         if m:
121                 arg = m.group(2)
122                 newline = m.group(1) + "paragraph-params \\paragraph-spacing " + arg + \
123                         m.group(3)
124                 return (True, newline)
125
126         m = re_psother.search(line)
127         if not m:
128                 return no_match
129
130         arg = m.group(2)
131         newline = m.group(1) + "paragraph-params \\paragraph-spacing other " + \
132                 arg + m.group(3)
133         return (True, newline)
134
135
136 def tabular_feature(line):
137         return simple_renaming(line, "tabular-feature", "inset-modify tabular")
138
139
140 #
141 #
142 ###########################################################
143
144
145 # Conversion chain
146
147 conversions = [
148         [ # this will be a long list of conversions for format 0
149                 next_inset_toggle,
150                 next_inset_modify,
151                 optional_insert,
152                 notes_mutate,
153                 all_insets_toggle,
154                 line_insert,
155                 toc_insert,
156                 paragraph_spacing,
157                 tabular_feature
158         ] # end conversions for format 0
159 ]
160