瀏覽代碼

Merge pull request #33 from masad-frost/fm-py-indent

Add auto-indentation for python
Alexandru Dima 7 年之前
父節點
當前提交
c09fd5d81d
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      src/python/python.ts

+ 9 - 0
src/python/python.ts

@@ -8,6 +8,9 @@
 import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
 import ILanguage = monaco.languages.IMonarchLanguage;
 
+// Allow for running under nodejs/requirejs in tests
+const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (<any>self).monaco : monaco);
+
 export const conf: IRichLanguageConfiguration = {
 	comments: {
 		lineComment: '#',
@@ -32,6 +35,12 @@ export const conf: IRichLanguageConfiguration = {
 		{ open: '"', close: '"' },
 		{ open: '\'', close: '\'' },
 	],
+	onEnterRules: [
+		{
+			beforeText: new RegExp("^\\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async).*?:\\s*$"),
+			action: { indentAction: _monaco.languages.IndentAction.Indent }
+		}
+	],
 	folding: {
 		offSide: true,
 		markers: {