]> git.lyx.org Git - lyx.git/blobdiff - development/tools/gen_lfuns.py
Add support for mixed-encoded biblatex files
[lyx.git] / development / tools / gen_lfuns.py
index f5d903d7b2bd1e18ad7d629395cdd0daec259ed4..6162bbb3dfca39ea9cea99ec56792d14d07091a0 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/python3
 # -*- coding: utf-8 -*-
 
 # file gen_lfuns.py
@@ -39,11 +39,11 @@ LFUN_SAMPLE_ID = u"\\li Sample: "
 LFUN_ORIGIN_ID = u"\\li Origin: "
 LFUN_ENDVAR = u"\\endvar"
 
-ID_DICT = dict(name=LFUN_NAME_ID, action=LFUN_ACTION_ID, notion=LFUN_NOTION_ID, 
+ID_DICT = dict(name=LFUN_NAME_ID, action=LFUN_ACTION_ID, notion=LFUN_NOTION_ID,
                 syntax=LFUN_SYNTAX_ID, params=LFUN_PARAMS_ID, sample=LFUN_SAMPLE_ID, origin=LFUN_ORIGIN_ID)
 
 LFUNS_HEADER = u"""# gen_lfuns.py generated this file. For more info see http://www.lyx.org/
-\\lyxformat 506
+\\lyxformat 509
 \\begin_document
 \\begin_header
 \\save_transient_properties true
@@ -81,6 +81,7 @@ End
 \\font_osf false
 \\font_sf_scale 100 100
 \\font_tt_scale 100 100
+\\use_microtype 0
 \\graphics default
 \\default_output_format default
 \\output_sync 0
@@ -152,7 +153,7 @@ About this manual
 \\end_layout
 
 \\begin_layout Standard
-This manual documents the 
+This manual documents the
 \\begin_inset Quotes eld
 \\end_inset
 
@@ -174,7 +175,7 @@ LFUNs are also used in the files that define keyboard shortcuts, menu or
  So if you want to change\\SpecialChar breakableslash
 customize the user interface, you need to deal
  with LFUNs.
- Furthermore, external programs can use LFUNs to communicate with and 
+ Furthermore, external programs can use LFUNs to communicate with and
 \\begin_inset Quotes eld
 \\end_inset
 
@@ -185,7 +186,7 @@ remote-control
  \\SpecialChar LyX
  .
  Finally, you can also issue LFUNs directly via the so called mini-buffer
- which can be opened via 
+ which can be opened via
 \\begin_inset Info
 type  "shortcuts"
 arg   "command-execute"
@@ -207,15 +208,15 @@ LFUNS_FOOTER = u"""\\end_body
 
 def parse_lfun(str):
     """Takes a comment block (str) and parses it for fields describing the LFUN. Returns a dict containing the fields."""
-    
+
     lfun = dict(action="", notion="", syntax="", params="", sample="", origin="")
     field = ""
     lines = str.splitlines()
-    # strip leading whitespace and * from the lines of the comment to get 
+    # strip leading whitespace and * from the lines of the comment to get
     # rid of unimportant characters
     for i in range(0, len(lines)):
         lines[i] = lines[i].strip(" *")
-    
+
     for i in range(0, len(lines) - 1):
         # work out what field is being read if none of these is found, the line will be added
         #     to the last field edited
@@ -256,11 +257,11 @@ def parse_lfun(str):
                 pre_space = ""
             else:
                 pre_space = " "
-        
+
         # add the line to the field, processing it for \ characters and \n
         # which, if occurring at the end of a line, must become a LYX_NEWLINE
         line = lines[i][skip:]
-        
+
         # deal with \htmlonly
         # TODO: convert chars found in htmlonly to unicode
         start = line.find(HTMLONLY_START)
@@ -275,7 +276,7 @@ def parse_lfun(str):
             #else:
             # TODO: if HTMLONLY_END is not found, look on the next line
             # TODO: in the current LyXAction.cpp there are no htmlonly fields which go over a line break
-        
+
         # deal with \ but leave \n if at the end of the line
         slash_idx = line.find("\\")
         while slash_idx >= 0:
@@ -283,7 +284,7 @@ def parse_lfun(str):
             or slash_idx == len(line)-1:
                 # true when the \ is not the last or second last char
                 #      or when the slash is the last char of the line
-                
+
                 # slash must be interpreted literaly so swap it for a LYX_BACKSLASH
                 line = line[:slash_idx] + LYX_BACKSLASH + line[slash_idx+1:]
                 # skip the index ahead beyond the added text
@@ -291,10 +292,10 @@ def parse_lfun(str):
             elif line[slash_idx+1] != "n": # only evaluated if the line ends "\x" where 'x' != 'n'
                 line = line[:slash_idx] + LYX_BACKSLASH + line[slash_idx+1:]
                 # skip the index ahead beyond the added text
-                slash_idx = slash_idx + len(LYX_BACKSLASH) 
+                slash_idx = slash_idx + len(LYX_BACKSLASH)
             # look for the next \
             slash_idx = line.find("\\", slash_idx+1)
-            
+
         # \n at the end of lines will not be processed by the above while loop
         # so sort those out now
         # sometime lines end " \n" so chop the space if its there
@@ -302,11 +303,11 @@ def parse_lfun(str):
             line = line[:len(line)-3] + LYX_NEWLINE
         elif line.endswith("\\n"):
             line = line[:len(line)-2] + LYX_NEWLINE
-        
+
         # any references to other LFUNs need the # removing
         # TODO: actually insert a cross-reference here
         line = line.replace("#LFUN", "LFUN")
-        
+
         # handle the few #lyx:: cases
         line = line.replace("#lyx::", "lyx::")
 
@@ -315,9 +316,9 @@ def parse_lfun(str):
         # to avoid an error
         if field != "":
             lfun[field] = lfun[field] + pre_space + line
-        
+
         # TODO: sort out chopping lines of more that 80 chars in length
-        
+
     return lfun
 
 def write_fields(file, lfun):
@@ -378,7 +379,7 @@ def write_sections(file,lfuns):
         for lf in lfuns:
             if lf["type"] == val:
                 write_fields(file, lf)
-    
+
 def main(argv):
     # parse command line arguments
     script_path, script_name = os.path.split(argv[0])
@@ -407,7 +408,7 @@ def main(argv):
     lyxaction_text = lyxaction_file.read()
 
     lfuns_file.write(LFUNS_HEADER)
-    
+
     # An introductory section
     lfuns_file.write(LFUNS_INTRO)
 
@@ -451,7 +452,7 @@ def main(argv):
             done = 1
 
     lfun_list = sorted(lfun_list_unsorted, key=lambda k: k['name'])
-    
+
     # write the lfuns to the file
     write_sections(lfuns_file, lfun_list)
 
@@ -459,11 +460,11 @@ def main(argv):
 
     # write the last part of LFUNs.lyx
     lfuns_file.write(LFUNS_FOOTER)
-    
+
     lyxaction_file.close()
     lfuns_file.close()
-    
+
     sys.stderr.write(script_name + ": Finished\n")
-    
+
 if __name__ == "__main__":
     main(sys.argv)