]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/prefs2prefs_lfuns.py
Fix typo
[lyx.git] / lib / scripts / prefs2prefs_lfuns.py
index 55a95edc8a430349a6d6b131877302df67ec9e1b..ec65f97925d8ebd69babbb45ab67a07845d47ff6 100644 (file)
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 # file prefs2prefs-lfuns.py
@@ -20,8 +19,6 @@
 
 import sys, re
 
-current_format = 1
-
 ###########################################################
 #
 # Actual converter functions
@@ -29,9 +26,9 @@ current_format = 1
 # 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, []).
+# one normally returns: (False, "").
 
-no_match = (False, [])
+no_match = (False, "")
 
 def simple_renaming(line, old, new):
        if line.find(old) == -1:
@@ -40,6 +37,12 @@ def simple_renaming(line, 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")
 
@@ -49,7 +52,7 @@ def next_inset_toggle(line):
 
 
 def optional_insert(line):
-       return simple_renaming(line, "argument-insert", "optional-insert")
+       return simple_renaming(line, "optional-insert", "argument-insert")
 
 
 re_nm = re.compile(r'^(.*)notes-mutate\s+(\w+)\s+(\w+)(.*)$')
@@ -137,7 +140,87 @@ 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")
+
+
+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")
+
+
+def remove_date_insert(line):
+       return simple_remove(line, "date-insert")
+
+
 #
 ###########################################################
 
@@ -145,7 +228,7 @@ def tabular_feature(line):
 # Conversion chain
 
 conversions = [
-       [ # this will be a long list of conversions for format 0
+       [  1, [ # this will be a long list of conversions to format 1, LyX 2.0
                next_inset_toggle,
                next_inset_modify,
                optional_insert,
@@ -154,7 +237,27 @@ conversions = [
                line_insert,
                toc_insert,
                paragraph_spacing,
-               tabular_feature
-       ] # end conversions for format 0
+               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
+       ]],
+       [ 5, [ # list of conversions to format 5, LyX 2.4
+               info_rename_vcsauthor,
+               info_rename_vcsdate,
+               info_rename_vcstime,
+               info_rename_vcsrevision,
+               info_rename_vcstreerevision,
+               remove_date_insert
+       ]]
 ]
-