Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add electric dedent to lua mode
The lua mode currently adds a level of indentation when opening up a new
scope, but closing the scope doesn't remove a level. This change gives
opening scope indents a respective dedent.
  • Loading branch information
azufluup committed May 23, 2018
commit 0d2e239777c96e3b78a138bf3879b8ab9d735166
6 changes: 4 additions & 2 deletions mode/lua/lua.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
"while", "repeat", "until", "for", "in", "local" ]);

var indentTokens = wordRE(["function", "if","repeat","do", "\\(", "{"]);
var dedentTokens = wordRE(["end", "until", "\\)", "}"]);
var dedentPartial = prefixRE(["end", "until", "\\)", "}", "else", "elseif"]);
var dedentKeywords = ["end", "until", "\\)", "}", "else", "elseif"];
var dedentTokens = wordRE(dedentKeywords);
var dedentPartial = prefixRE(dedentKeywords);

function readBracket(stream) {
var level = 0;
Expand Down Expand Up @@ -148,6 +149,7 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
return state.basecol + indentUnit * (state.indentDepth - (closing ? 1 : 0));
},

electricInput: new RegExp("\\b" + dedentKeywords.join("|") + "\\b", "gi"),
lineComment: "--",
blockCommentStart: "--[[",
blockCommentEnd: "]]"
Expand Down