/usr/share/lyx/scripts/prefs2prefs_lfuns.py is in lyx-common 2.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | # -*- coding: utf-8 -*-
# file prefs2prefs-lfuns.py
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.
# author Richard Heck
# Full author contact details are available in file CREDITS
# This file houses conversion information for the bind and ui files,
# i.e., for files where we are converting lfuns.
# The converter functions take a line as argument and return a list:
# (Bool, NewLine),
# where the Bool says if we've modified anything and the NewLine is
# the new line, if so, which will be used to replace the old line.
import sys, re
###########################################################
#
# Actual converter functions
#
# These accept a line as argument and should return a list:
# (bool, newline)
# where the bool indicates whether we changed anything. If not,
# one normally returns: (False, "").
no_match = (False, "")
def simple_renaming(line, old, new):
if line.find(old) == -1:
return no_match
line = line.replace(old, new)
return (True, line)
def simple_remove(line, old):
if line.find(old) == -1:
return no_match
return (True, "")
def next_inset_modify(line):
return simple_renaming(line, "next-inset-modify", "inset-modify")
def next_inset_toggle(line):
return simple_renaming(line, "next-inset-toggle", "inset-toggle")
def optional_insert(line):
return simple_renaming(line, "optional-insert", "argument-insert")
re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
def notes_mutate(line):
m = re_nm.search(line)
if not m:
return no_match
prefix = m.group(1)
source = m.group(2)
target = m.group(3)
suffix = m.group(4)
newline = prefix + "inset-forall Note:" + source + \
" inset-modify note Note " + target + suffix
return (True, newline)
re_ait = re.compile(r'^(.*)all-insets-toggle\s+(\w+)(?:\s+(\w+))?(.*)$')
def all_insets_toggle(line):
m = re_ait.search(line)
if not m:
return no_match
prefix = m.group(1)
action = m.group(2)
target = m.group(3)
suffix = m.group(4)
# we need to transform the target to match the inset layout names
# this will not be perfect
if target == "ert":
target = "ERT"
elif target == None:
target = "*"
elif target == "tabular":
# There does not seem to be an InsetLayout for tables, so
# I do not know what to do here. If anyone does, then please
# fix this. For now, we just have to remove this line.
return (True, "")
else:
target = target.capitalize()
newline = prefix + "inset-forall " + target + " inset-toggle " + \
action + suffix
return (True, newline)
re_li = re.compile(r'^(.*)\bline-insert\b(.*)$')
def line_insert(line):
m = re_li.search(line)
if not m:
return no_match
newline = m.group(1) + \
"inset-insert line rule height 0.25ex width 100col% \\end_inset" + \
m.group(2)
return (True, newline)
def toc_insert(line):
return simple_renaming(line, "toc-insert", "inset-insert toc")
re_ps = re.compile(r'^(.*)paragraph-spacing\s+(default|single|onehalf|double)\b(.*)$')
re_psother = re.compile(r'^(.*)paragraph-spacing\s+other\s+(\d+\.\d?|\d?\.\d+|\d+)(.*)$')
def paragraph_spacing(line):
# possible args: default, single, onehalf, double, other FLOAT
m = re_ps.search(line)
if m:
arg = m.group(2)
newline = m.group(1) + "paragraph-params \\paragraph-spacing " + arg + \
m.group(3)
return (True, newline)
m = re_psother.search(line)
if not m:
return no_match
arg = m.group(2)
newline = m.group(1) + "paragraph-params \\paragraph-spacing other " + \
arg + m.group(3)
return (True, newline)
def tabular_feature(line):
return simple_renaming(line, "tabular-feature", "inset-modify tabular")
re_tabular_feature = re.compile(r"inset-modify\s+tabular(\s+from-dialog)?")
def redo_tabular_feature(line):
# we change as follows:
# inset-modify tabular -> tabular-feature
# but:
# inset-modify tabular from-dialog -> inset-modify tabular
#
# "from-dialog" was never used directly but the user might do, if they
# followed the standard instructions to create a custom shortcut by looking
# at the message panel. The equivalent functionality is now provided by
# inset-modify tabular (without from-dialog).
def change(match):
if match.group(1):
return "inset-modify tabular"
else:
return "tabular-feature"
result = re_tabular_feature.subn(change, line)
if result[1]:
return (True, result[0])
else:
return no_match
re_Bar2bar = re.compile(r'^(\\(?:bind|unbind))\s+"([^"]*)Bar"(\s+"[^"]+")')
def Bar2bar(line):
m = re_Bar2bar.search(line)
if not m:
return no_match
btype = m.group(1)
mod = m.group(2)
rest = m.group(3)
newline = btype + " \"" + mod + "bar\"" + rest
return (True, newline)
def paragraph_break(line):
return simple_renaming(line, "break-paragraph", "paragraph-break")
def tab_group_close(line):
return simple_renaming(line, "close-tab-group", "tab-group-close")
def view_split(line):
return simple_renaming(line, "split-view", "view-split")
def label_copy_as_reference(line):
return simple_renaming(line, "copy-label-as-reference", "label-copy-as-reference")
def remove_print_support(line):
return simple_remove(line, "dialog-show print")
#
###########################################################
# Conversion chain
conversions = [
[ 1, [ # this will be a long list of conversions to format 1, LyX 2.0
next_inset_toggle,
next_inset_modify,
optional_insert,
notes_mutate,
all_insets_toggle,
line_insert,
toc_insert,
paragraph_spacing,
tabular_feature,
Bar2bar
]],
[ 2, [ # list of conversions to format 2, LyX 2.1
paragraph_break,
tab_group_close,
view_split,
label_copy_as_reference
]],
[ 3, [ # list of conversions to format 3
remove_print_support
]],
[ 4, [ # list of conversions to format 4, LyX 2.2
redo_tabular_feature
]]
]
|