Permalink
Browse files

Fixed #801: language keywords are now set using classprefs only

* replaced SetKeyWordsFromDict with SetKeyWordsFromClassprefs
* added keyword_set_[0-7] to FundamentalMode classprefs, defaulting to hidden
* added keyword_set_* classprefs to each mode that has keywords
* updated major modes using make-major-modes-from-editra.py to add keywords to classprefs defaults

svn-revision: r2413
  • Loading branch information...
robmcmullen committed Nov 30, 2009
1 parent 44c06a9 commit 60a7d87cbea6a8afa819b5a06f8e0e206e527762
Showing with 355 additions and 79 deletions.
  1. +77 −55 editra.in/make-major-modes-from-editra.py
  2. +11 −24 peppy/editra/stcmixin.py
  3. +8 −0 peppy/fundamental.py
  4. +5 −0 peppy/major_modes/_68k_assembly.py
  5. +3 −0 peppy/major_modes/actionscript.py
  6. +2 −0 peppy/major_modes/ada.py
  7. +3 −0 peppy/major_modes/apache_conf.py
  8. +2 −0 peppy/major_modes/bash.py
  9. +2 −0 peppy/major_modes/boo.py
  10. +4 −0 peppy/major_modes/c.py
  11. +4 −0 peppy/major_modes/caml.py
  12. +4 −0 peppy/major_modes/cascading_style_sheet.py
  13. +2 −0 peppy/major_modes/cobra.py
  14. +3 −0 peppy/major_modes/coldfusion.py
  15. +4 −0 peppy/major_modes/cpp.py
  16. +2 −0 peppy/major_modes/csh.py
  17. +4 −0 peppy/major_modes/csharp.py
  18. +4 −0 peppy/major_modes/d.py
  19. +1 −0 peppy/major_modes/diffedit.py
  20. +2 −0 peppy/major_modes/django.py
  21. +2 −0 peppy/major_modes/dos_batch_script.py
  22. +2 −0 peppy/major_modes/editra_style_sheet.py
  23. +3 −0 peppy/major_modes/edje.py
  24. +2 −0 peppy/major_modes/eiffel.py
  25. +2 −0 peppy/major_modes/erlang.py
  26. +4 −0 peppy/major_modes/ferite.py
  27. +5 −0 peppy/major_modes/flagship.py
  28. +4 −0 peppy/major_modes/fortran_77.py
  29. +4 −0 peppy/major_modes/fortran_95.py
  30. +3 −0 peppy/major_modes/graphviz.py
  31. +3 −0 peppy/major_modes/groovy.py
  32. +6 −0 peppy/major_modes/gui4cli.py
  33. +2 −0 peppy/major_modes/haskell.py
  34. +4 −0 peppy/major_modes/haxe.py
  35. +4 −0 peppy/major_modes/html.py
  36. +6 −0 peppy/major_modes/inno_setup_script.py
  37. +1 −0 peppy/major_modes/issuelist.py
  38. +4 −0 peppy/major_modes/java.py
  39. +2 −0 peppy/major_modes/javascript.py
  40. +4 −0 peppy/major_modes/kix.py
  41. +2 −0 peppy/major_modes/ksh.py
  42. +2 −0 peppy/major_modes/latex.py
  43. +3 −0 peppy/major_modes/lisp.py
  44. +4 −0 peppy/major_modes/lout.py
  45. +5 −0 peppy/major_modes/lua.py
  46. +1 −0 peppy/major_modes/makefile.py
  47. +2 −0 peppy/major_modes/mako.py
  48. +7 −0 peppy/major_modes/masm.py
  49. +2 −0 peppy/major_modes/matlab.py
  50. +1 −0 peppy/major_modes/microsoft_sql.py
  51. +6 −0 peppy/major_modes/netwide_assembler.py
  52. +3 −0 peppy/major_modes/newlisp.py
  53. +4 −0 peppy/major_modes/nullsoft_installer_script.py
  54. +4 −0 peppy/major_modes/objective_c.py
  55. +2 −0 peppy/major_modes/octave.py
  56. +3 −0 peppy/major_modes/pascal.py
  57. +2 −0 peppy/major_modes/perl.py
  58. +5 −0 peppy/major_modes/php.py
  59. +4 −0 peppy/major_modes/pike.py
  60. +9 −0 peppy/major_modes/pl_sql.py
  61. +3 −0 peppy/major_modes/postscript.py
  62. +4 −0 peppy/major_modes/progress_4gl.py
  63. +1 −0 peppy/major_modes/properties.py
  64. +3 −0 peppy/major_modes/python.py
  65. +2 −0 peppy/major_modes/r.py
  66. +2 −0 peppy/major_modes/ruby.py
  67. +2 −0 peppy/major_modes/s.py
  68. +2 −0 peppy/major_modes/scheme.py
  69. +2 −0 peppy/major_modes/smalltalk.py
  70. +8 −0 peppy/major_modes/sql.py
  71. +4 −0 peppy/major_modes/squirrel.py
  72. +4 −0 peppy/major_modes/system_verilog.py
  73. +5 −0 peppy/major_modes/tcl_tk.py
  74. +1 −0 peppy/major_modes/text.py
  75. +4 −0 peppy/major_modes/vala.py
  76. +2 −0 peppy/major_modes/vbscript.py
  77. +4 −0 peppy/major_modes/verilog.py
  78. +6 −0 peppy/major_modes/vhdl.py
  79. +5 −0 peppy/major_modes/visual_basic.py
  80. +2 −0 peppy/major_modes/xml.py
  81. +2 −0 peppy/major_modes/xtext.py
  82. +2 −0 peppy/major_modes/yaml.py
@@ -25,6 +25,7 @@
classprefs_template = ''' StrParam('extensions', '%(extensions)s', fullwidth=True),'''
keyword_set_template = ''' StrParam('keyword_set_%d', unique_keywords[%d], hidden=False, fullwidth=True),'''
template = '''# peppy Copyright (c) 2006-2009 Rob McMullen
@@ -49,6 +50,7 @@
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.fundamental import FundamentalMode
from peppy.editra.style_specs import unique_keywords
class %(class_name)sMode(FundamentalMode):
"""Stub major mode for editing %(keyword)s files.
@@ -73,6 +75,55 @@ def getMajorModes(self):
yield %(class_name)sMode
'''
# Global lists and dicts using my multiple processes
langs = facade.getAllEditraLanguages()
extra_properties = {}
syntax_style_specs = {}
keywords = {}
stc_lexer_id = {}
for lang in langs:
keyword = facade.getPeppyModeKeyword(lang)
#dprint(keyword)
extra_properties[keyword] = facade.getEditraExtraProperties(lang)
syntax_style_specs[keyword] = facade.getEditraSyntaxSpecs(lang)
keywords[keyword] = facade.getEditraLanguageKeywords(lang)
stc_lexer_id[keyword] = facade.getEditraSTCLexer(lang)
def findCommonKeywords(keywords):
unique_keywords = []
unique_id = 0
keywords_text = {}
keywords_mapping = {}
for lang, keyword_dict in keywords.iteritems():
if lang not in keywords_mapping:
dprint("adding %s" % lang)
keywords_mapping[lang] = {}
try:
for id, text in keyword_dict.iteritems():
# keyword_spec is a tuple of int and string
if text in keywords_text:
dprint("found common for %s, %d: %s" % (lang, id, keywords_text[text]))
keywords_mapping[lang][id] = keywords_text[text]
else:
keywords_text[text] = unique_id
unique_keywords.append(text)
keywords_mapping[lang][id] = unique_id
unique_id += 1
except (ValueError, TypeError):
dprint(lang)
dprint(keyword_spec_list)
raise
except KeyError:
dprint(keywords_mapping.keys())
raise
dprint(keywords_mapping)
return unique_keywords, keywords_mapping
unique_keywords, keywords_mapping = findCommonKeywords(keywords)
# Processing routines
def process(destdir):
missing, existing = getDefinedModes(destdir)
@@ -99,11 +150,10 @@ def getDefinedModes(destdir):
def getEditraInfo(lang):
module_name = facade.getPeppyFileName(lang)
syn = facade.getEditraSyntaxData(lang)
# if lang == "XML":
# dprint(syn)
keyword = facade.getPeppyModeKeyword(lang)
vals = {
'lang': lang,
'keyword': facade.getPeppyModeKeyword(lang),
'keyword': keyword,
'class_name': facade.getPeppyClassName(lang),
'module_name': module_name,
'extensions': " ".join(facade.getExtensionsForLanguage(lang)),
@@ -112,7 +162,12 @@ def getEditraInfo(lang):
'end_comment': repr(facade.getEditraCommentChars(lang)[1]),
}
vals['class_attrs'] = class_attr_template % vals
vals['classprefs'] = classprefs_template % vals
classprefs = classprefs_template % vals
order = sorted(keywords_mapping[keyword].iteritems())
for keyword_set_id, unique_id in order:
classprefs += "\n" + keyword_set_template % (keyword_set_id, unique_id)
vals['classprefs'] = classprefs
return module_name, vals
def convertEditraMode(destdir, lang):
@@ -186,9 +241,27 @@ def replace(self, vals):
"""Replace any class attributes or classprefs with the new values
"""
self.replaceImports()
self.replaceClassAttrs(vals)
self.replaceClassprefs(vals)
def replaceImports(self):
"""Special case to add the unique_keywords dict to the list of imports
In versions prior to r2412, the import statement for unique_keywords
from peppy.editra.style_specs didn't exist. Now that keywords can be
modified by the user, the import statement must be included because
the StrParams reference the unique_keywords dict to supply defaults
for the preferences.
"""
extra = "from peppy.editra.style_specs import unique_keywords"
try:
self.header.index(extra)
except ValueError:
dprint("Replacing imports for %s" % self.lang)
index = self.header.index("from peppy.fundamental import")
self.header = self.header[0:index] + extra + "\n" + self.header[index:]
def replaceClassAttrs(self, vals):
newattrs = vals['class_attrs']
keywords = {}
@@ -264,27 +337,6 @@ def processSampleText(filename):
def processStyleSpecs(filename):
#dprint("Processing style specs")
langs = facade.getAllEditraLanguages()
extra_properties = {}
syntax_style_specs = {}
keywords = {}
stc_lexer_id = {}
for lang in langs:
keyword = facade.getPeppyModeKeyword(lang)
#dprint(keyword)
extra_properties[keyword] = facade.getEditraExtraProperties(lang)
syntax_style_specs[keyword] = facade.getEditraSyntaxSpecs(lang)
keywords[keyword] = facade.getEditraLanguageKeywords(lang)
stc_lexer_id[keyword] = facade.getEditraSTCLexer(lang)
# for lang in langs:
# keyword = facade.getPeppyModeKeyword(lang)
# dprint(keyword)
# dprint(keywords[keyword])
# sys.exit()
unique_keywords, keywords_mapping = findCommonKeywords(keywords)
import pprint
pp = pprint.PrettyPrinter()
fh = open(filename, "w")
@@ -303,36 +355,6 @@ def processStyleSpecs(filename):
fh.write("\n")
fh.close()
def findCommonKeywords(keywords):
unique_keywords = []
unique_id = 0
keywords_text = {}
keywords_mapping = {}
for lang, keyword_dict in keywords.iteritems():
if lang not in keywords_mapping:
dprint("adding %s" % lang)
keywords_mapping[lang] = {}
try:
for id, text in keyword_dict.iteritems():
# keyword_spec is a tuple of int and string
if text in keywords_text:
dprint("found common for %s, %d: %s" % (lang, id, keywords_text[text]))
keywords_mapping[lang][id] = keywords_text[text]
else:
keywords_text[text] = unique_id
unique_keywords.append(text)
keywords_mapping[lang][id] = unique_id
unique_id += 1
except (ValueError, TypeError):
dprint(lang)
dprint(keyword_spec_list)
raise
except KeyError:
dprint(keywords_mapping.keys())
raise
dprint(keywords_mapping)
return unique_keywords, keywords_mapping
if __name__ == "__main__":
@@ -181,15 +181,7 @@ def ConfigureLexer(self, keyword):
self.SetLexer(lexer)
# Set or clear keywords used for extra highlighting
if self.stc_keywords is not None:
keywords = self.stc_keywords
else:
try:
keywords = style_specs.keywords_mapping[keyword]
except KeyError:
dprint("No keywords found for %s" % keyword)
keywords = []
self.SetKeyWordsFromDict(keywords)
self.SetKeyWordsFromClassprefs()
# Set or clear Editra style sheet info
if self.stc_syntax_style_specs is not None:
@@ -218,23 +210,18 @@ def ConfigureLexer(self, keyword):
self.dprint("GetLexer = %d" % self.GetLexer())
return True
def SetKeyWordsFromDict(self, kw_dict):
"""Sets the keywords from a dict of keyword sets
@param kw_dict: {KWSET1: "KEWORDS", KWSET2: "KEYWORDS2", etc...]
def SetKeyWordsFromClassprefs(self):
"""Sets the keywords from the classprefs
"""
# Parse Keyword Settings List simply ignoring bad values and badly
# formed lists
import peppy.editra.style_specs as style_specs
self.keywords = ""
for keyword_set, keywords in kw_dict.iteritems():
# If the keyword is an integer, assume that it references the
# list of unique keywords specified in the preprocessed editra
# style_specs
if isinstance(keywords, int):
keywords = style_specs.unique_keywords[keywords]
self.keywords += keywords
self.SetKeyWords(keyword_set, keywords)
prefname_template = "keyword_set_%d"
for set_num in range(8):
prefname = prefname_template % set_num
keywords = self.classprefs._get(prefname)
dprint("set number: %d keywords=%s" % (set_num, keywords))
if keywords:
self.keywords += keywords
self.SetKeyWords(set_num, keywords)
kwlist = self.keywords.split() # Split into a list of words
kwlist = list(set(kwlist)) # Uniqueify the list
@@ -158,6 +158,14 @@ class FundamentalMode(FoldExplorerMixin, EditraSTCMixin,
BoolParam('case_sensitive_search', False, 'Case of search string must match exactly if True; otherwise mixed case requires exact match and lower case matches all', local=True),
BoolParam('whole_word_search', False, 'Whole word between common separators must match if True; Otherwise matches every substring', local=True),
BoolParam('case_matching_replace', True, 'Case will be modified to match if True; otherwise case will be left as was found', local=True),
StrParam('keyword_set_0', "", 'Space separated list of keywords used for scintilla keyword set 0', hidden=True),
StrParam('keyword_set_1', "", 'Space separated list of keywords used for scintilla keyword set 1', hidden=True),
StrParam('keyword_set_2', "", 'Space separated list of keywords used for scintilla keyword set 2', hidden=True),
StrParam('keyword_set_3', "", 'Space separated list of keywords used for scintilla keyword set 3', hidden=True),
StrParam('keyword_set_4', "", 'Space separated list of keywords used for scintilla keyword set 4', hidden=True),
StrParam('keyword_set_5', "", 'Space separated list of keywords used for scintilla keyword set 5', hidden=True),
StrParam('keyword_set_6', "", 'Space separated list of keywords used for scintilla keyword set 6', hidden=True),
StrParam('keyword_set_7', "", 'Space separated list of keywords used for scintilla keyword set 7', hidden=True),
)
autoindent = NullAutoindent()
@@ -19,6 +19,7 @@
from peppy.lib.autoindent import *
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.editra.style_specs import unique_keywords
from peppy.fundamental import FundamentalMode
class _68kAssemblyMode(FundamentalMode):
@@ -37,6 +38,10 @@ class _68kAssemblyMode(FundamentalMode):
default_classprefs = (
StrParam('extensions', '68k', fullwidth=True),
StrParam('keyword_set_0', unique_keywords[81], hidden=False, fullwidth=True),
StrParam('keyword_set_1', unique_keywords[82], hidden=False, fullwidth=True),
StrParam('keyword_set_2', unique_keywords[83], hidden=False, fullwidth=True),
StrParam('keyword_set_3', unique_keywords[84], hidden=False, fullwidth=True),
)
@@ -19,6 +19,7 @@
from peppy.lib.autoindent import *
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.editra.style_specs import unique_keywords
from peppy.fundamental import FundamentalMode
class ActionScriptMode(FundamentalMode):
@@ -37,6 +38,8 @@ class ActionScriptMode(FundamentalMode):
default_classprefs = (
StrParam('extensions', 'as asc mx', fullwidth=True),
StrParam('keyword_set_0', unique_keywords[144], hidden=False, fullwidth=True),
StrParam('keyword_set_1', unique_keywords[145], hidden=False, fullwidth=True),
)
@@ -19,6 +19,7 @@
from peppy.lib.autoindent import *
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.editra.style_specs import unique_keywords
from peppy.fundamental import FundamentalMode
class AdaMode(FundamentalMode):
@@ -37,6 +38,7 @@ class AdaMode(FundamentalMode):
default_classprefs = (
StrParam('extensions', 'a ada adb ads', fullwidth=True),
StrParam('keyword_set_0', unique_keywords[24], hidden=False, fullwidth=True),
)
@@ -19,6 +19,7 @@
from peppy.lib.autoindent import *
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.editra.style_specs import unique_keywords
from peppy.fundamental import FundamentalMode
class ApacheConfMode(FundamentalMode):
@@ -37,6 +38,8 @@ class ApacheConfMode(FundamentalMode):
default_classprefs = (
StrParam('extensions', 'conf htaccess', fullwidth=True),
StrParam('keyword_set_0', unique_keywords[16], hidden=False, fullwidth=True),
StrParam('keyword_set_1', unique_keywords[17], hidden=False, fullwidth=True),
)
@@ -14,6 +14,7 @@
from peppy.lib.autoindent import *
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.editra.style_specs import unique_keywords
from peppy.fundamental import FundamentalMode
class BashMode(SimpleFoldFunctionMatchMixin, FundamentalMode):
@@ -31,6 +32,7 @@ class BashMode(SimpleFoldFunctionMatchMixin, FundamentalMode):
default_classprefs = (
StrParam('extensions', 'bsh configure sh', fullwidth=True),
StrParam('keyword_set_0', unique_keywords[74], hidden=False, fullwidth=True),
Param('indent_after', r'(\{(?![^\}]*\})|\b(then|elif|else)\b(?!.+fi)|\bdo\b(?!.+done)|\bcase\s+.+\s+in\b(?!.*esac)|\[\[)', fullwidth=True),
Param('indent', r'\$\{.*\}', fullwidth=True),
Param('unindent', r'([}]\s*$|\b(fi|elif|else)\b|\bdone\b|\besac\b|\]\])', fullwidth=True),
@@ -19,6 +19,7 @@
from peppy.lib.autoindent import *
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.editra.style_specs import unique_keywords
from peppy.fundamental import FundamentalMode
class BooMode(FundamentalMode):
@@ -37,6 +38,7 @@ class BooMode(FundamentalMode):
default_classprefs = (
StrParam('extensions', 'boo', fullwidth=True),
StrParam('keyword_set_0', unique_keywords[15], hidden=False, fullwidth=True),
)
@@ -15,6 +15,7 @@
from peppy.lib.autoindent import CStyleAutoindent
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.editra.style_specs import unique_keywords
from peppy.fundamental import FundamentalMode, ParagraphInfo
from peppy.paragraph import *
@@ -92,6 +93,9 @@ class CMode(SimpleCLikeFoldFunctionMatchMixin, FundamentalMode):
default_classprefs = (
StrParam('extensions', 'c h', fullwidth=True),
StrParam('keyword_set_0', unique_keywords[79], hidden=False, fullwidth=True),
StrParam('keyword_set_1', unique_keywords[80], hidden=False, fullwidth=True),
StrParam('keyword_set_2', unique_keywords[14], hidden=False, fullwidth=True),
)
autoindent = CStyleAutoindent()
@@ -19,6 +19,7 @@
from peppy.lib.autoindent import *
from peppy.yapsy.plugins import *
from peppy.major import *
from peppy.editra.style_specs import unique_keywords
from peppy.fundamental import FundamentalMode
class CamlMode(FundamentalMode):
@@ -37,6 +38,9 @@ class CamlMode(FundamentalMode):
default_classprefs = (
StrParam('extensions', 'ml mli', fullwidth=True),
StrParam('keyword_set_0', unique_keywords[109], hidden=False, fullwidth=True),
StrParam('keyword_set_1', unique_keywords[110], hidden=False, fullwidth=True),
StrParam('keyword_set_2', unique_keywords[111], hidden=False, fullwidth=True),
)
Oops, something went wrong.

0 comments on commit 60a7d87

Please sign in to comment.