diff --git a/src/NotepadNext/NotepadNextApplication.cpp b/src/NotepadNext/NotepadNextApplication.cpp index 49f317687..871928e3f 100644 --- a/src/NotepadNext/NotepadNextApplication.cpp +++ b/src/NotepadNext/NotepadNextApplication.cpp @@ -321,44 +321,7 @@ void NotepadNextApplication::setEditorLanguage(ScintillaNext *editor, const QStr getLuaState()->execute(QString("skip_tabs = %1").arg(editor->QObject::property("nn_skip_usetabs").isValid() ? "true" : "false").toLatin1().constData()); getLuaState()->execute(QString("skip_tabwidth = %1").arg(editor->QObject::property("nn_skip_tabwidth").isValid() ? "true" : "false").toLatin1().constData()); - getLuaState()->execute(R"( - local L = languages[languageName] - - if not skip_tabs then - editor.UseTabs = (L.tabSettings or "tabs") == "tabs" - end - if not skip_tabwidth then - editor.TabWidth = L.tabSize or 4 - end - - editor.MarginWidthN[2] = L.disableFoldMargin and 0 or 16 - if L.styles then - for name, style in pairs(L.styles) do - editor.StyleFore[style.id] = style.fgColor - editor.StyleBack[style.id] = style.bgColor - - if style.fontStyle then - editor.StyleBold[style.id] = (style.fontStyle & 1 == 1) - editor.StyleItalic[style.id] = (style.fontStyle & 2 == 2) - editor.StyleUnderline[style.id] = (style.fontStyle & 4 == 4) - editor.StyleEOLFilled[style.id] = (style.fontStyle & 8 == 8) - end - end - end - if L.keywords then - for id, kw in pairs(L.keywords) do - editor.KeyWords[id] = kw - end - end - if L.properties then - for p,v in pairs(L.properties) do - editor.Property[p] = v - end - end - - editor.Property["fold"] = "1" - editor.Property["fold.compact"] = "0" - )"); + getLuaState()->execute(QString("SetLanguage(languageName)").toLatin1().constData()); } QString NotepadNextApplication::detectLanguage(ScintillaNext *editor) const @@ -407,7 +370,7 @@ QString NotepadNextApplication::detectLanguageFromContents(ScintillaNext *editor -- Grab a small chunk if editor.Length > 0 then editor:SetTargetRange(0, math.min(64, editor.Length)) - return detectLanguageFromContents(editor.TargetText) + return DetectLanguageFromContents(editor.TargetText) end return "Text" diff --git a/src/NotepadNext/languages/php.lua b/src/NotepadNext/languages/php.lua index cb1b302c4..d72344d64 100644 --- a/src/NotepadNext/languages/php.lua +++ b/src/NotepadNext/languages/php.lua @@ -1,6 +1,6 @@ local L = {} -L.lexer = "phpscript" +L.lexer = "hypertext" L.singleLineComment = "// " @@ -87,4 +87,9 @@ L.styles = { bgColor = rgb(0xFEFCF5), }, } + +L.additionalLanguages = { + "HTML" +} + return L diff --git a/src/NotepadNext/scripts/init.lua b/src/NotepadNext/scripts/init.lua index f595f9553..27678429b 100644 --- a/src/NotepadNext/scripts/init.lua +++ b/src/NotepadNext/scripts/init.lua @@ -2,11 +2,7 @@ function rgb(x) return ((x & 0xFF) << 16) | (x & 0xFF00) | ((x & 0xFF0000) >> 16) end -function starts_with(str, start) - return str:sub(1, #start) == start -end - -function detectLanguageFromContents(contents) +function DetectLanguageFromContents(contents) for name, L in pairs(languages) do if L.first_line then for _, pattern in ipairs(L.first_line) do @@ -52,6 +48,60 @@ function DialogFilters() return table.concat(filters, ";;") end +function SetStyle(L) + if L.styles then + for _, style in pairs(L.styles) do + editor.StyleFore[style.id] = style.fgColor + editor.StyleBack[style.id] = style.bgColor + + if style.fontStyle then + editor.StyleBold[style.id] = (style.fontStyle & 1 == 1) + editor.StyleItalic[style.id] = (style.fontStyle & 2 == 2) + editor.StyleUnderline[style.id] = (style.fontStyle & 4 == 4) + editor.StyleEOLFilled[style.id] = (style.fontStyle & 8 == 8) + end + end + end + + if L.keywords then + for id, kw in pairs(L.keywords) do + editor.KeyWords[id] = kw + end + end + + if L.properties then + for p, v in pairs(L.properties) do + editor.Property[p] = v + end + end +end + +function SetLanguage(languageName) + local L = languages[languageName] + + if not skip_tabs then + editor.UseTabs = (L.tabSettings or "tabs") == "tabs" + end + + if not skip_tabwidth then + editor.TabWidth = L.tabSize or 4 + end + + editor.MarginWidthN[2] = L.disableFoldMargin and 0 or 16 + + SetStyle(L) + + if L.additionalLanguages then + for _, language in pairs(L.additionalLanguages) do + SetStyle(languages[language]) + end + end + + + editor.Property["fold"] = "1" + editor.Property["fold.compact"] = "0" +end + languages = {} languages["ActionScript"] = require("actionscript") languages["ADA"] = require("ada")