src/eric7/QScintilla/Lexers/__init__.py

branch
eric7
changeset 9599
dc0666634751
parent 9563
8ee667840224
child 9609
c2f9c10c47cc
--- a/src/eric7/QScintilla/Lexers/__init__.py	Thu Dec 08 20:06:32 2022 +0100
+++ b/src/eric7/QScintilla/Lexers/__init__.py	Fri Dec 09 17:07:18 2022 +0100
@@ -7,6 +7,7 @@
 Package implementing lexers for the various supported programming languages.
 """
 
+import contextlib
 import importlib
 
 from PyQt6.QtCore import QCoreApplication
@@ -41,17 +42,25 @@
     """
     Module function to register a custom QScintilla lexer.
 
-    @param name lexer language name (string)
-    @param displayString display string (string)
-    @param filenameSample dummy filename to derive lexer name (string)
+    @param name lexer language name
+    @type str
+    @param displayString display string
+    @type str
+    @param filenameSample dummy filename to derive lexer name
+    @type str
     @param getLexerFunc reference to a function instantiating the specific
         lexer. This function must take a reference to the parent as its only
         argument.
-    @param openFilters list of open file filters (list of strings)
-    @param saveFilters list of save file filters (list of strings)
-    @param defaultAssocs default lexer associations (list of strings of
-        filename wildcard patterns to be associated with the lexer)
-    @param iconFileName name of an icon file (string)
+    @type function
+    @param openFilters list of open file filters
+    @type list of str
+    @param saveFilters list of save file filters
+    @type list of str
+    @param defaultAssocs default lexer associations (list of filename wildcard
+        patterns to be associated with the lexer)
+    @type list of str
+    @param iconFileName name of an icon file
+    @type str
     @exception KeyError raised when the given name is already in use
     """
     global LexerRegistry
@@ -68,14 +77,25 @@
             iconFileName,
         ]
 
+        textFilePatterns = Preferences.getUI("TextFilePatterns")
+        textFilePatterns.extend([p for p in defaultAssocs if p not in textFilePatterns])
+        Preferences.setUI("TextFilePatterns", textFilePatterns)
+
 
 def unregisterLexer(name):
     """
     Module function to unregister a custom QScintilla lexer.
 
-    @param name lexer language name (string)
+    @param name lexer language name
+    @type str
     """
     if name in LexerRegistry:
+        textFilePatterns = Preferences.getUI("TextFilePatterns")
+        for pat in LexerRegistry[name][5]:
+            with contextlib.suppress(ValueError):
+                textFilePatterns.remove(pat)
+        Preferences.setUI("TextFilePatterns", textFilePatterns)
+
         del LexerRegistry[name]
 
 

eric ide

mercurial