#! /usr/bin/env python # -*- 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 current_format = 1 ########################################################### # # Actual converter functions # # These accept a line as argument and should return a list: # (bool, newline) # where the bool indicates whether we changed anything. In # that case, 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 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, "argument-insert", "optional-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) # # ########################################################### # Conversion chain conversions = [ [ # this will be a long list of conversions for format 0 next_inset_toggle, next_inset_modify, optional_insert, notes_mutate, all_insets_toggle ] # end conversions for format 0 ]