A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
# file prefs2prefs-lfuns.py
|
|
|
|
# This file is part of LyX, the document processor.
|
|
|
|
# Licence details can be found in the file COPYING.
|
|
|
|
|
2020-11-01 23:08:18 +00:00
|
|
|
# author Richard Kimberly Heck
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
|
|
|
|
# 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)
|
2011-01-16 03:59:43 +00:00
|
|
|
# where the bool indicates whether we changed anything. If not,
|
2015-11-27 03:40:39 +00:00
|
|
|
# one normally returns: (False, "").
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
|
2015-11-27 03:40:39 +00:00
|
|
|
no_match = (False, "")
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
|
|
|
|
def simple_renaming(line, old, new):
|
|
|
|
if line.find(old) == -1:
|
2010-09-18 14:27:12 +00:00
|
|
|
return no_match
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
line = line.replace(old, new)
|
|
|
|
return (True, line)
|
|
|
|
|
|
|
|
|
2015-11-27 03:40:39 +00:00
|
|
|
def simple_remove(line, old):
|
|
|
|
if line.find(old) == -1:
|
|
|
|
return no_match
|
|
|
|
return (True, "")
|
|
|
|
|
|
|
|
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
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")
|
|
|
|
|
|
|
|
|
2010-09-18 14:27:12 +00:00
|
|
|
def optional_insert(line):
|
2011-01-18 15:40:07 +00:00
|
|
|
return simple_renaming(line, "optional-insert", "argument-insert")
|
2010-09-18 14:27:12 +00:00
|
|
|
|
|
|
|
|
2010-09-18 14:42:38 +00:00
|
|
|
re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
|
2010-09-18 14:27:12 +00:00
|
|
|
def notes_mutate(line):
|
|
|
|
m = re_nm.search(line)
|
|
|
|
if not m:
|
|
|
|
return no_match
|
|
|
|
|
2010-09-18 14:42:38 +00:00
|
|
|
prefix = m.group(1)
|
2010-09-18 14:27:12 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2010-09-18 14:42:38 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2010-09-18 14:56:25 +00:00
|
|
|
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)
|
|
|
|
|
2010-09-18 14:42:38 +00:00
|
|
|
|
2010-09-18 14:57:59 +00:00
|
|
|
def toc_insert(line):
|
|
|
|
return simple_renaming(line, "toc-insert", "inset-insert toc")
|
|
|
|
|
|
|
|
|
2010-09-18 15:13:13 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2010-09-18 15:16:04 +00:00
|
|
|
def tabular_feature(line):
|
|
|
|
return simple_renaming(line, "tabular-feature", "inset-modify tabular")
|
|
|
|
|
2015-11-27 03:08:43 +00:00
|
|
|
|
2015-12-11 03:08:33 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2011-04-14 18:31:39 +00:00
|
|
|
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)
|
2010-09-18 15:16:04 +00:00
|
|
|
|
2015-11-27 03:08:43 +00:00
|
|
|
|
2012-09-29 18:04:56 +00:00
|
|
|
def paragraph_break(line):
|
|
|
|
return simple_renaming(line, "break-paragraph", "paragraph-break")
|
|
|
|
|
2015-11-27 03:08:43 +00:00
|
|
|
|
2012-09-29 18:04:56 +00:00
|
|
|
def tab_group_close(line):
|
|
|
|
return simple_renaming(line, "close-tab-group", "tab-group-close")
|
|
|
|
|
2015-11-27 03:08:43 +00:00
|
|
|
|
2012-09-29 18:04:56 +00:00
|
|
|
def view_split(line):
|
|
|
|
return simple_renaming(line, "split-view", "view-split")
|
|
|
|
|
2015-11-27 03:08:43 +00:00
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
def label_copy_as_reference(line):
|
|
|
|
return simple_renaming(line, "copy-label-as-reference", "label-copy-as-reference")
|
|
|
|
|
2015-11-27 03:40:39 +00:00
|
|
|
|
|
|
|
def remove_print_support(line):
|
|
|
|
return simple_remove(line, "dialog-show print")
|
|
|
|
|
2018-08-18 14:11:08 +00:00
|
|
|
|
|
|
|
def info_rename_vcsauthor(line):
|
|
|
|
return simple_renaming(line, "info-insert buffer vcs-author", "info-insert vcs author")
|
|
|
|
|
|
|
|
|
|
|
|
def info_rename_vcsdate(line):
|
|
|
|
return simple_renaming(line, "info-insert buffer vcs-date", "info-insert vcs date")
|
|
|
|
|
|
|
|
|
|
|
|
def info_rename_vcstime(line):
|
|
|
|
return simple_renaming(line, "info-insert buffer vcs-time", "info-insert vcs time")
|
|
|
|
|
|
|
|
|
|
|
|
def info_rename_vcsrevision(line):
|
|
|
|
return simple_renaming(line, "info-insert buffer vcs-revision", "info-insert vcs revision")
|
|
|
|
|
|
|
|
|
|
|
|
def info_rename_vcstreerevision(line):
|
|
|
|
return simple_renaming(line, "info-insert buffer vcs-tree-revision", "info-insert vcs tree-revision")
|
|
|
|
|
|
|
|
|
2018-08-20 07:25:22 +00:00
|
|
|
def remove_date_insert(line):
|
|
|
|
return simple_remove(line, "date-insert")
|
|
|
|
|
|
|
|
|
2022-02-21 13:00:14 +00:00
|
|
|
re_delete_force = re.compile(r"((char|word)-delete-(for|back)ward)(\s+force)?")
|
|
|
|
def delete_force(line):
|
|
|
|
# we change as follows:
|
|
|
|
# char-delete-forward -> char-delete-forward confirm
|
|
|
|
# but:
|
|
|
|
# char-delete-forward force -> char-delete-forward
|
|
|
|
#
|
|
|
|
def change(match):
|
|
|
|
if match.group(4):
|
|
|
|
return match.group(1)
|
|
|
|
else:
|
|
|
|
return match.group(1) + " confirm"
|
|
|
|
|
|
|
|
result = re_delete_force.subn(change, line)
|
|
|
|
if result[1]:
|
|
|
|
return (True, result[0])
|
|
|
|
else:
|
|
|
|
return no_match
|
|
|
|
|
|
|
|
|
|
|
|
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
#
|
|
|
|
###########################################################
|
|
|
|
|
|
|
|
|
|
|
|
# Conversion chain
|
|
|
|
|
|
|
|
conversions = [
|
2012-09-29 18:04:56 +00:00
|
|
|
[ 1, [ # this will be a long list of conversions to format 1, LyX 2.0
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
next_inset_toggle,
|
2010-09-18 14:27:12 +00:00
|
|
|
next_inset_modify,
|
|
|
|
optional_insert,
|
2010-09-18 14:42:38 +00:00
|
|
|
notes_mutate,
|
2010-09-18 14:56:25 +00:00
|
|
|
all_insets_toggle,
|
2010-09-18 14:57:59 +00:00
|
|
|
line_insert,
|
2010-09-18 15:13:13 +00:00
|
|
|
toc_insert,
|
2010-09-18 15:16:04 +00:00
|
|
|
paragraph_spacing,
|
2011-04-14 18:31:39 +00:00
|
|
|
tabular_feature,
|
|
|
|
Bar2bar
|
2011-09-12 20:43:06 +00:00
|
|
|
]],
|
2012-09-29 18:04:56 +00:00
|
|
|
[ 2, [ # list of conversions to format 2, LyX 2.1
|
|
|
|
paragraph_break,
|
|
|
|
tab_group_close,
|
2014-02-11 10:00:20 +00:00
|
|
|
view_split,
|
|
|
|
label_copy_as_reference
|
2012-09-29 18:04:56 +00:00
|
|
|
]],
|
2015-12-11 03:08:33 +00:00
|
|
|
[ 3, [ # list of conversions to format 3
|
2015-11-27 03:40:39 +00:00
|
|
|
remove_print_support
|
2015-12-11 03:08:33 +00:00
|
|
|
]],
|
|
|
|
[ 4, [ # list of conversions to format 4, LyX 2.2
|
|
|
|
redo_tabular_feature
|
2018-08-18 14:11:08 +00:00
|
|
|
]],
|
|
|
|
[ 5, [ # list of conversions to format 5, LyX 2.4
|
|
|
|
info_rename_vcsauthor,
|
|
|
|
info_rename_vcsdate,
|
|
|
|
info_rename_vcstime,
|
|
|
|
info_rename_vcsrevision,
|
2018-08-20 07:25:22 +00:00
|
|
|
info_rename_vcstreerevision,
|
2022-02-21 13:00:14 +00:00
|
|
|
remove_date_insert,
|
|
|
|
delete_force
|
2015-11-27 03:40:39 +00:00
|
|
|
]]
|
A go at creating a prefs2prefs framework. There's a main file, prefs2prefs.py, and two subsidiary files,
prefs2prefs_lfuns.py and prefs2prefs_prefs.py. I've organized it this way because, in many ways, these are
the same task. It's very line-by-line, unlike lyx2lyx and layout2layout, where things can be more "global".
So we read the file, line by line, and give a bunch of converter functions a chance to see if they want to
modify that line.
The converter functions are all in the subsidiary files. (Only the lfun one has anything in it now.) They
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.
The format of the existing files is format 0, and we'll introduce new format numbers as we proceed,
just as with layout2layout. So the conversion from format 0 to format 1 will be huge; others will
generally be simple.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35426 a592a061-630c-0410-9148-cb99ea01b6c8
2010-09-17 14:44:38 +00:00
|
|
|
]
|