Mir fehlen im VSCode/VSCodium - Editor so einige in SciTE lieb gewonnene Konfigurationsmöglichkeiten. Sicher kann man Einiges mit JS - Funktionen nachbilden, wenn man da fit ist. Aber einige Dinge sind aufgrund der Architektur auch generell nicht möglich. Z.B. gibt es nicht die Möglichkeit auf das Ereignis "BeforeSave" zu reagieren. Das ist aber für viele Tools, die ich nutze Bedingung. Reaktion auf z.B. "AfterSave" würde entweder zu einem nicht gespeicherten neuen Inhalt oder zu einem Speicher-Loop führen, wenn man jede Änderung wieder speichert.
Deshalb habe ich mal getestet, inwieweit sich SciTE zur Nim-Programmierung eignet.
Das ist jetzt also eine Erprobungsphase.
Was mir wichtig war:
Ich benötige i.d.R. für die Programme unterschiedliche Compileranweisungen. Der Code Runner ist da nicht sehr flexibel (oder ich habe noch nicht alle Konfigurationsmöglichkeiten entdeckt).
Ich habe mir angewöhnt in eine der ersten Programmzeilen als Kommentar die Kompilierzeile zu speichern, z.B. # compile: nim c --app:gui TestGui.nim .
Nun wäre es natürlich schick, wenn ich das nicht händisch ins Terminal kopieren muss, sondern per Hotkey.
Das habe ich hier mit dem Lua-Skript CompileNimByUserline.lua umgesetzt.
Wie geht's?
Zwei Schritte sind erforderlich:
- Ein Hotkey eurer Wahl ruft "CompileNimByUserline.lua" auf. (Im Bsp. "Ctrl+1")
Die Kompilierzeile wird extrahiert und als Property "nim.compile.line" gespeichert - Ein weiterer Hotkey ("F5") ruft den Befehl "Go" auf.
"Go" führt nun die in der Property "nim.compile.line" gespeicherte Anweisung aus
Ist keine benutzerdefinierte Kompilierzeile vorhanden, wird als Standard: nim c -r "$(FileNameExt)" verwendet.
Die erforderlichen Anpassungen für die SciTEUser.properties sind im Lua-Skript aufgeführt.
-- TIME_STAMP 2022-02-08 10:50:16
--[[ CompileNimByUserline.lua by BugFix
Nim compiler user guide: https://nim-lang.org/docs/nimc.html
Insert the compilation line into one of the first programme lines:
# compile: nim command [options] [projectfile] [arguments]
example compile:
# compile: nim c --app:console Test.nim
example compile & run:
# compile: nim c -r --app:console Test.nim
This line is used for compilation.
The Lua script works in a different subsystem than Nim-Go.
This means that an execution of the menu command IDM_GO from the Lua script is not successful.
If no compilation line is included in the script, is used as default:
nim c -r "$(FileNameExt)"
Two steps for using required:
1. One Hotkey calls "CompileNimByUserline.lua"
The compile line is extracted and saved as property "nim.compile.line"
2. Another Hotkey calls command "Go".
The command "Go" executes the property "nim.compile.line".
REQUIRED CHANGES IN "SciTEUser.properties":
# ======================================================== N I M ====
# F5
#~ command.go.*.nim=nim c -r "$(FileNameExt)"
command.go.*.nim=$(nim.compile.line)
command.go.subsystem.*.nim=1
command.name.1.*.nim=Syntax Check
command.1.*.nim=nim check "$(FilePath)"
command.mode.1.*.nim=savebefore:yes
command.shortcut.1.*.nim=Ctrl+F5
command.name.2.*.nim=Compile / Go by User Line
command.2.*.nim=dofile $(Lua.User.Scripts.Path)/CompileNimByUserline.lua <<== Modify your path !!
command.mode.2.*.nim=subsystem:lua,savebefore:yes
command.shortcut.2.*.nim=Ctrl+1
# compile Ctrl+F7
command.compile.*.nim=nim c "$(FilePath)"
# build F7
command.build.*.nim=nim --forcebuild "$(FilePath)"
command.build.subsystem.*.nim=1
comment.block.nimrod=#
# ======================================================= /N I M ====
--]]
local function getCompileLine()
local text = editor:GetText()
local match, kind, go = nil, '> Compile & Go Nim by Default\n', ''
for m in text:gmatch('#%scompile:%s+([^\r\n]+)') do
match = m break
end
if match ~= nil then
if match:find('%-r') then go = '& Go ' end
kind = '> Compile '..go..'Nim by UserLine\n'
props['nim.compile.line'] = match
else
props['nim.compile.line'] = 'nim c -r '..props['FileNameExt']
end
return kind
end
if props['FileExt']:lower() == 'nim' then
local kind = getCompileLine()
output:ClearAll()
output:AppendText(kind)
-- scite.MenuCommand(IDM_GO) doesn't work, syntax error: too many chunks
end
Alles anzeigen
Natürlich ist Nim mit SciTE noch deutlich entfernt von der Funktionsvielfalt in VSCode. Ich weiß auch nicht, ob es wirklich sinnvoll ist, die Anpassung zu versuchen. Aber ein Aspekt spricht deutlich für SciTE: Die Ausführungsgeschwindigkeit. Ich habe nim check für dasselbe Programm (mit vielen Includes) einmal in VSCode und einmal in SciTE ausgeführt. Ergebnis: 21 s : 14 s - SciTE benötigt also 30% weniger Zeit, DAS spricht deutlich für SciTE.
Ich halte euch auf dem Laufenden, sofern ich hier weiter bastele (das Farbschema ist per default nicht so der Brüller - aber das ist eher zweitrangig, Funktionalität geht vor).