Writing a custom mode for CodeMirror, for use in Brackets

前端 未结 1 1117
感情败类
感情败类 2021-02-06 13:24

I am trying to write a plugin/extension for Brackets that will handle PowerShell. Well after looking into it, I found that CodeMirror also doesn\'t have a PowerShell mode, so I

1条回答
  •  忘了有多久
    2021-02-06 13:27

    General answer - there actually are some fairly detailed resources for this:

    • Writing a CodeMirror mode
    • Defining a new language in Brackets - see the subsection "Custom CodeMirror modes" for how to load your new CodeMirror mode

    Specific answer - I can spot a few issues in your sample code that will definitely cause problems:

    1. Use require("powershell") without the .js -- this is the format JS module loaders expect
    2. powershell.js should contain the same define(...) wrapper as your main.js. And it should use brackets.getModule() to get a reference to CodeMirror, same as main.js. (Using JSLint, which is built into Brackets, is helpful for warning you when you reference globals that you have forgotten to explicitly load as module dependencies).
    3. Your CM mode has a typo: startStat -> startState
    4. You need to call CodeMirror.defineMode() before calling LanguageManager.defineLanguage() - see "Custom CodeMirror modes" docs linked above. You could either do this in your powershell.js module, or early in main.js.

    0 讨论(0)
提交回复
热议问题