- Offizieller Beitrag
Ein Tool für eine komfortablere Kommentierung im Skript.
- Aktivierung und Deaktivierung per Hotkey, Modus ist sichtbar durch geändertes Cursor-Symbol (Hand)
- Fortlaufend schreiben und der Kommentar bricht automatisch um und setzt hinter dem Code in der Folgezeile spaltengleich positioniert fort.
- Bei automatischem Umbruch können für Zeilenende und -Fortsetzung optional Zeichen/-folgen festgelegt werden um optisch sofort zusammenhängende Zeilen zu erkennen
- Umbruch automatisch an definierter Spaltenposition oder manuell durch Pfeil-ab
- Es muß nicht fortlaufend jede Zeile beschrieben werden, sondern es können auch Zeilen übersprungen werden
- Um wirksam zu werden ist ein Neustart von SciTE erforderlich
Edit 14.02.2012: kleine Ergänzung, s. blaue Markierung
Edit 15.02.2012: Falls es nicht wie gewollt klappt, werft mal einen Blick hier hin. Dort könnten schon einige Hinweise zur Lösung sein.
Edit 16.02.2012: Wie ihr hier im Thread seht, gab es bei Pitter Probleme. Deshalb noch Folgendes:
- Der Eintrag in der "SciTEStartup.lua" MUSS am Ende, also hinter EventClass:BeginEvents() erfolgen.
- Sollten trotzdem die Ereignisse Pfeiltaste-Ab und Lerzeichen nicht erkannt werden, hilft i.A. einen zusätzlichen, sinnlosen Befehl im Skript zu verbauen, der die Funktion etwas 'bremst'
Bsp.:
Spoiler anzeigen
function CommentHitKey:OnKey(_keycode)
local Keycode = _keycode or nil -- Sinnfrei, nur zum Abbremsen <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if fCommentModeOn then -- fortsetzender Kommentarmodus ist aktiv
local fBreak = isLFpos()
if _keycode == 32 and fBreak then -- Leerzeichen u. Position für Zeilenwechsel erreicht (automatischer Zeilenwechsel)
fNext = true -- Marker neue Zeile
elseif _keycode == 40 then -- Pfeil_ab (manueller Zeilenwechsel)
fNext = true fIsNewLine = true -- Marker neue Zeile und Marker in-neuer-Zeile
elseif fNext then -- in neuer Zeile ==> Kommentarzeichen einfügen
fNext = false
if not fIsNewLine then -- bei automatischem Wechsel (wenn in den properties ein Umbruchsymbol definiert):
editor:InsertText(editor.CurrentPos, charBreak1) -- am Ende Umbruchsymbol aus den properties anhängen
end
ContinuousComment()
end
end
return nil
end
Alles anzeigen
Edit 17.02.2012
- Ich habe die Positionsabfrage jetzt verändert, mit der vorigen Methode wurden auch 'halbe Tabs', also Tabs, die z.B. nach 2 Leerzeichen gesetzt wurden, voll mit 4 Leerzeichen ersetzt, was zu Verschiebungen führt.
Nun erhalte ich direkt die Spaltenposition aus der Zeile. Version: 0.6
- Und für die Nutzer von SciTE-RU habe ich auch die entsprechende Version erstellt.
Edit 18.02.2012: [NEUE FUNKTIONEN]
- Bei Auto-Umbruch wird das letzte Wort einer Zeile, wenn es die Umbruchmarkierung überschreitet, in die Folgezeile übernommen.
- Manuell kann auch mit ENTER umgebrochen werden. Dann wird hinter der aktuellen Zeile eine Leerzeile eingefügt und genauso positioniert der Kommentar fortgeschrieben. Die Umbruchmarkierungen werden wie beim Auto-Umbruch gesetzt. Dazu ist ein weiterer Eintrag in den properties erforderlich um diese Funktion optional zu de/aktivieren (s. Installationshinweise).
Und hier ein kleines Bild dazu:
autoit.de/wcf/attachment/15105/
Beschreibung
FUNKTION: Kontinuierlicher Kommentar Modus
----------------------------------------------------------------------------------------------------------------------------------
BESCHREIBUNG
Per Hotkey wird die Funktion aktiviert. Dabei wird an der aktuellen Cursorposition die in den properties
('ContinuousComment.Chars.*.au3') festgelegte Zeichenfolge gesetzt (z.B. "; ==").
AUTO UMBRUCH:
In den properties 'ContinuousComment.LFpos.*.au3' wird festgelegt an welcher Spaltenposition ein automatischer Wechsel auf die
nächste Zeile erfolgen soll (Trigger: Leerzeichen an Position gleich od. größer Spaltenangabe aus den properties). Man kann
also einfach fortlaufend seinen Kommentar schreiben und er wird automatisch in der Folgezeile hinter dem Code, an derselben
Spaltenposition wie in der vorigen Zeile, fortgesetzt. Ist der Code in der Folgezeile länger, beginnt der Kommentar erst
dahinter.
Überschreitet der Code die Umbruchposition, so wird das letzte Wort mit in die neue Zeile übernommen
MANUELLER UMBRUCH:
Manuell kann jeder Zeit mit "Pfeil ab" auf die Folgezeile gewechselt werden. Soll in der Folgezeile kein Kommentar erscheinen,
kann wiederum mit "Pfeil ab" zur nächsten Zeile gewechselt werden (in der momentanen Zeile wird dann kein Kommentarzeichen
gesetzt).
Ausserdem kann mit <ENTER> ein manueller Umbruch erzeugt werden mit gleichzeitigem Einfügen einer Leerzeile. Dabei wird die
Umbruchmarkierung (sofern in den properties festgelegt) genau wie beim manuellen Umbruch erzeugt. Der Kommentar wird wiederum
spaltengenau fortgesetzt.
Beendet wird der Kontinuierliche-Kommentar-Modus wiederum mit dem Hotkey, das auch zum Start verwendet wird.
----------------------------------------------------------------------------------------------------------------------------------
INSTALLATION
Das Skript "ContinuousComments.lua" im Ordner "..\SciTE\LUA\" speichern.
Einträge in "SciTEUser.properties":
ContinuousComment.LFpos.*.au3=170 <== gewünschte Position für automatischen Zeilenwechsel beim Kommentar schreiben
ContinuousComment.Chars.*.au3=; <== Zeichenfolge mit der jede Kommentarzeile beginnt (Leerzeichen wird automatisch angefügt)
ContinuousComment.BreakCharsLast.*.au3=˜ ˜ › <== [optional] Zeichen am Zeilenende bei automatischem Umbruch
ContinuousComment.BreakCharsNext.*.au3=› <== [optional] Zeichen am Anfang der Folgezeile bei automatischem Umbruch
ContinuousComment.NewLine.WithEnter.Enable.*.au3' <== neue Zeile (mit Kommentar an derselben Position) einfügen mit Enter im Kommentar-Modus (=1)
# 36 Comment Continuous
command.name.36.*=Kommentarmodus aktivieren
command.36.*=CommentModeActivate
command.mode.36.*=subsystem:lua,savebefore:no
command.shortcut.36.*=Ctrl+Shift+K <== gewünschter Hotkey
Eintrag in "..\SciTE\LUA\SciTEStartup.lua"
LoadLuaFile("ContinuousComments.lua") <== Am Dateiende einfügen!!
----------------------------------------------------------------------------------------------------------------------------------
Alles anzeigen
So sieht das Skript dazu aus:
v 0.7
-- TIME_STAMP 2012-02-18 00:16:13 v 0.7
CommentHitKey = EventClass:new(Common)
local ext = props['FileExt']
local lfPos = tonumber(props['ContinuousComment.LFpos.*.' .. ext])
local charComm = props['ContinuousComment.Chars.*.' .. ext]..' '
local charBreak1 = props['ContinuousComment.BreakCharsLast.*.' .. ext]
local charBreak2 = props['ContinuousComment.BreakCharsNext.*.' .. ext]
local fNewLine = false
if tonumber(props['ContinuousComment.NewLine.WithEnter.Enable.*.' .. ext]) == 1 then fNewLine = true end
local fCommentModeOn, fNext, fIsNewLine, fIsEnter = false, false, false, false
local lastLine, column, col
local getSpaces = function()
col = editor.Column[editor.CurrentPos]
local s = ''
if col < column then
s = string.rep(' ', column - col)
end
return s
end
local isLFpos = function()
local pos = editor.Column[editor.CurrentPos]
if pos >= lfPos then
return true
else
return false
end
end
local ContinuousComment = function()
local autoBreak, w = '', ''
if not fIsNewLine then
local pos = editor.Column[editor.CurrentPos]
if pos > lfPos then
editor:WordLeftExtend()
w = editor:GetSelText()
editor:ReplaceSel('')
end
editor:GotoLine(editor:LineFromPosition(editor.CurrentPos) +1)
if charBreak2:len() > 0 then autoBreak = charBreak2..' ' end
else
fIsNewLine = false
end
local strAdd = ' '
editor:LineEnd()
strAdd = getSpaces() or strAdd
editor:InsertText(editor.CurrentPos, strAdd..charComm..autoBreak..w)
editor:LineEnd()
end
function CommentHitKey:OnKey(_keycode)
if fCommentModeOn then -- fortsetzender Kommentarmodus ist aktiv
local fBreak = isLFpos()
if fIsEnter then
fIsEnter = false
local s, e = getSpaces(), ''
if charBreak2:len() > 0 then e = charBreak2..' ' end
editor:InsertText(editor.CurrentPos, s..charComm..e)
editor:LineEnd()
end
if _keycode == 13 then
fIsEnter = true
editor:InsertText(editor.CurrentPos, ' '..charBreak1)
editor:LineEnd()
elseif _keycode == 32 and fBreak then -- Leerzeichen u. Position fð² šeilenwechsel erreicht (automatischer Zeilenwechsel)
fNext = true -- Marker neue Zeile
elseif _keycode == 40 then -- Pfeil_ab (manueller Zeilenwechsel)
fNext = true fIsNewLine = true -- Marker neue Zeile und Marker in-neuer-Zeile
elseif fNext then -- in neuer Zeile ==> Kommentarzeichen einf𧥮
fNext = false
if not fIsNewLine then -- bei automatischem Wechsel (wenn in den properties ein Umbruchsymbol definiert):
editor:InsertText(editor.CurrentPos, charBreak1) -- am Ende Umbruchsymbol aus den properties anh寧en
end
ContinuousComment()
end
end
return nil
end
function CommentModeActivate()
if not fCommentModeOn then
editor:LineEnd()
column = editor.Column[editor.CurrentPos]
editor.Cursor = 8 -- Cursor wechseln (Hand)
editor:InsertText(editor.CurrentPos, charComm)
editor:LineEnd()
else
editor.Cursor = -1 -- Cursor zurück auf Standard
end
fCommentModeOn = not fCommentModeOn
end
Alles anzeigen
Version für SciTE-RU
v 0.2
-- TIME_STAMP 2012-02-18 00:16:28 v 0.2
--[[ FUNCTION: Continuous Comment Mode
----------------------------------------------------------------------------------------------------------------------------------
DESCRIPTION
The function is activated using a hotkey. If the mode is active, the cursor appears as a hand. At the current cursor position
will inserted chars from properties ('ContinuousComment.Chars.*.au3') e.g. "; ==".
AUTO BRAKE:
In properties 'ContinuousComment.LFpos.*.au3' is determinate at which position should skip to next line.
It's triggered by press key <space> and position is greater than or equal to position from properties. So you can continuous
write comments and if the breakpoint is reached - automatically jumps the cursor to next line and inserts command-char at the
same position like in line before. If length of code in next line greather than the comment start position before, the comment
in this line starts behind the code.
Optional, contiguous comment with automatic line breaks are marked by additional break character.
If the last word in line overrides the breakposition, this word will moved to next line.
MANUALLY BRAKE:
You can manually skip to next line by press key <arrow down>. To appear in the next line no comment can turn "down arrow"
to the next line to be changed (in the current row will be no comment character set).
In addition, a manual break can generated with simultaneous insertion of a blank line by hit the <ENTER> key. Markers are set,
as with a manual break. The comment is continued at the same position like before.
Stops the continuous-comment mode again with the hotkey, which is also used for launch. The cursor is reset.
----------------------------------------------------------------------------------------------------------------------------------
INSTALLATION
Rename the attached file to "ContinuousCommentsRu.lua".
Save the script "ContinuousCommentsRu.lua" to folder "..\SciTE-RU\tools\".
entries in "SciTEUser.properties":
ContinuousComment.LFpos.*.au3=170 <== line position for automatically line break
ContinuousComment.Chars.*.au3=; <== Character(s) that begins each comment line
ContinuousComment.BreakCharsLast.*.au3=˜ ˜ › <== [optional] Character(s) at line end on rows with automatically line break
ContinuousComment.BreakCharsNext.*.au3=› <== [optional] Character(s) at next line on rows with automatically line break (in front of your text)
ContinuousComment.NewLine.WithEnter.Enable.*.au3' <== insert new line (with comment at same position) by hit ENTER in comment mode (=1)
# 36 Comment Continuous
command.name.36.*=Activate Comment Mode
command.36.*=CommentModeActivate
command.mode.36.*=subsystem:lua,savebefore:no
command.shortcut.36.*=Ctrl+Shift+K <== desired hotkey
entrie in "..\SciTE-RU\tools\SciTEStartup.lua"
dofile (props["SciteDefaultHome"].."\\tools\\ContinuousCommentsRu.lua") <== at the end of the file !!
----------------------------------------------------------------------------------------------------------------------------------
]]
--[[ FUNKTION: Kontinuierlicher Kommentar Modus
----------------------------------------------------------------------------------------------------------------------------------
BESCHREIBUNG
Per Hotkey wird die Funktion aktiviert. Dabei wird an der aktuellen Cursorposition die in den properties
('ContinuousComment.Chars.*.au3') festgelegte Zeichenfolge gesetzt (z.B. "; ==").
AUTO UMBRUCH:
In den properties 'ContinuousComment.LFpos.*.au3' wird festgelegt an welcher Spaltenposition ein automatischer Wechsel auf die
nächste Zeile erfolgen soll (Trigger: Leerzeichen an Position gleich od. größer Spaltenangabe aus den properties). Man kann
also einfach fortlaufend seinen Kommentar schreiben und er wird automatisch in der Folgezeile hinter dem Code, an derselben
Spaltenposition wie in der vorigen Zeile, fortgesetzt. Ist der Code in der Folgezeile länger, beginnt der Kommentar erst
dahinter.
Überschreitet der Code die Umbruchposition, so wird das letzte Wort mit in die neue Zeile übernommen
MANUELLER UMBRUCH:
Manuell kann jeder Zeit mit "Pfeil ab" auf die Folgezeile gewechselt werden. Soll in der Folgezeile kein Kommentar erscheinen,
kann wiederum mit "Pfeil ab" zur nächsten Zeile gewechselt werden (in der momentanen Zeile wird dann kein Kommentarzeichen
gesetzt).
Ausserdem kann mit <ENTER> ein manueller Umbruch erzeugt werden mit gleichzeitigem Einfügen einer Leerzeile. Dabei wird die
Umbruchmarkierung (sofern in den properties festgelegt) genau wie beim manuellen Umbruch erzeugt. Der Kommentar wird wiederum
spaltengenau fortgesetzt.
Beendet wird der Kontinuierliche-Kommentar-Modus wiederum mit dem Hotkey, das auch zum Start verwendet wird.
----------------------------------------------------------------------------------------------------------------------------------
INSTALLATION
Das Skript "ContinuousCommentsRu.lua" im Ordner "..\SciTE-RU\tools\" speichern.
Einträge in "SciTEUser.properties":
ContinuousComment.LFpos.*.au3=150 <== gewünschte Position für automatischen Zeilenwechsel beim Kommentar schreiben
ContinuousComment.Chars.*.au3=; <== Zeichenfolge mit der jede Kommentarzeile beginnt (Leerzeichen wird automatisch angefügt)
ContinuousComment.BreakCharsLast.*.au3=˜ ˜ › <== [optional] Zeichen am Zeilenende bei automatischem Umbruch
ContinuousComment.BreakCharsNext.*.au3=› <== [optional] Zeichen am Anfang der Folgezeile bei automatischem Umbruch
ContinuousComment.NewLine.WithEnter.Enable.*.au3' <== neue Zeile (mit Kommentar an derselben Position) einfügen mit Enter im Kommentar-Modus (=1)
# 36 Comment Continuous
command.name.36.*=Kommentarmodus aktivieren
command.36.*=CommentModeActivate
command.mode.36.*=subsystem:lua,savebefore:no
command.shortcut.36.*=Ctrl+Shift+K <== gewünschter Hotkey
Eintrag in "..\SciTE-RU\tools\SciTEStartup.lua"
dofile (props["SciteDefaultHome"].."\\tools\\ContinuousCommentsRu.lua") <== Am Dateiende anfügen!
----------------------------------------------------------------------------------------------------------------------------------
]]
local lfPos = tonumber(props['ContinuousComment.LFpos.*.au3'])
local charComm = props['ContinuousComment.Chars.*.au3']..' '
local charBreak1 = props['ContinuousComment.BreakCharsLast.*.au3']
local charBreak2 = props['ContinuousComment.BreakCharsNext.*.au3']
local fNewLine = false
if tonumber(props['ContinuousComment.NewLine.WithEnter.Enable.*.au3']) == 1 then fNewLine = true end
local fCommentModeOn, fNext, fIsNewLine, fIsEnter = false, false, false, false
local lastLine, column, col
local getSpaces = function()
col = editor.Column[editor.CurrentPos]
local s = ''
if col < column then
s = string.rep(' ', column - col)
end
return s
end
local isLFpos = function()
local pos = editor.Column[editor.CurrentPos]
if pos >= lfPos then
return true
else
return false
end
end
local ContinuousComment = function()
local autoBreak, w = '', ''
if not fIsNewLine then
local pos = editor.Column[editor.CurrentPos]
if pos > lfPos then
editor:WordLeftExtend()
w = editor:GetSelText()
editor:ReplaceSel('')
end
editor:GotoLine(editor:LineFromPosition(editor.CurrentPos) +1)
if charBreak2:len() > 0 then autoBreak = charBreak2..' ' end
else
fIsNewLine = false
end
local strAdd = ' '
editor:LineEnd()
strAdd = getSpaces() or strAdd
editor:InsertText(editor.CurrentPos, strAdd..charComm..autoBreak..w)
editor:LineEnd()
end
AddEventHandler("OnKey", function(_keycode)
if fCommentModeOn then -- fortsetzender Kommentarmodus ist aktiv
local fBreak = isLFpos()
if fIsEnter then
fIsEnter = false
local s, e = getSpaces(), ''
if charBreak2:len() > 0 then e = charBreak2..' ' end
editor:InsertText(editor.CurrentPos, s..charComm..e)
editor:LineEnd()
end
if _keycode == 13 then
fIsEnter = true
editor:InsertText(editor.CurrentPos, ' '..charBreak1)
editor:LineEnd()
elseif _keycode == 32 and fBreak then -- Leerzeichen u. Position fð² šeilenwechsel erreicht (automatischer Zeilenwechsel)
fNext = true -- Marker neue Zeile
elseif _keycode == 40 then -- Pfeil_ab (manueller Zeilenwechsel)
fNext = true fIsNewLine = true -- Marker neue Zeile und Marker in-neuer-Zeile
elseif fNext then -- in neuer Zeile ==> Kommentarzeichen einf𧥮
fNext = false
if not fIsNewLine then -- bei automatischem Wechsel (wenn in den properties ein Umbruchsymbol definiert):
editor:InsertText(editor.CurrentPos, charBreak1) -- am Ende Umbruchsymbol aus den properties anh寧en
end
ContinuousComment()
end
end
return nil
end)
function CommentModeActivate()
if not fCommentModeOn then
editor:LineEnd()
column = editor.Column[editor.CurrentPos]
editor.Cursor = 8 -- Cursor wechseln (Hand)
editor:InsertText(editor.CurrentPos, charComm)
editor:LineEnd()
else
editor.Cursor = -1 -- Cursor zurück auf Standard
end
fCommentModeOn = not fCommentModeOn
end
Alles anzeigen