- Offizieller Beitrag
Hier ein kleines Tool, dass es ermöglicht, einen markierten Bereich (auch Blockmarkierung - z.B. in Zeilen 3-6 jeweils Spalten 10-17) mit paarigen Zeichen: ( ), { }, [ ], ' ', " " einzufassen.
Bei Blockmarkierung wird in jeder Zeile des Blocks am Beginn und Ende der Markierung das entsprechende Zeichen gesetzt.
Steht der Cursor nach der Markierung vor der Auswahl ist das öffnende Symbol zu wählen, steht er am Ende ist das schließende Symbol zu wählen. Dass paarige Symbol wird dann entsprechend zugeordnet.
Also:
- Bereich markieren
- öffnendes oder schließendes Symbol eingeben
Dieses Tool ersetzt auch die Funktion "AutoCloseBraces.lua". Sofern ihr diese verwendet, muß sie im Lua-Startup Skript ( SciTEStartup.lua ) deaktiviert werden.
Kopiert die Datei EdgingSelection.lua in den Pfad: "..SciTE\LUA\"
Öffnet die SciTEStartup.lua und ergänzt sie um den Eintrag "LoadLuaFile("EdgingSelection.lua")".
Die Datei sollte dann etwa so aussehen:
Spoiler anzeigen
-- TIME_STAMP 2011-10-27 20:24:06 v 0.1
--------------------------------------------------------------------------------
-- SciTE startup script.
--------------------------------------------------------------------------------
-- A table listing all loaded files.
LoadLuaFileList = { }
--------------------------------------------------------------------------------
-- LoadLuaFile(file, directory)
--
-- Helper function for easily loading Lua files.
--
-- Parameters:
-- file - The name of a Lua file to load.
-- directory - If specified, file is looked for in that directory. By default,
-- this directory is $(SciTEDefaultHome)\Lua.
--------------------------------------------------------------------------------
function LoadLuaFile(file, directory)
if directory == nil then
directory = props["SciteDefaultHome"] .. "\\Lua\\"
end
table.insert(LoadLuaFileList, directory .. file)
dofile(directory .. file)
end -- LoadLuaFile()
-- Load all the Lua files.
LoadLuaFile("Class.lua") -- Always load first.
LoadLuaFile("Common.lua") -- Always load second.
LoadLuaFile("AutoItPixmap.lua")
LoadLuaFile("AutoHScroll.lua")
LoadLuaFile("AutoItAutoComplete.lua")
LoadLuaFile("LoadSession.lua")
LoadLuaFile("AutoItIndentFix.lua")
LoadLuaFile("EdgeMode.lua")
LoadLuaFile("SmartAutoCompleteHide.lua")
LoadLuaFile("Tools.lua")
LoadLuaFile("AutoItTools.lua")
LoadLuaFile("AutoItGotoDefinition.lua")
--~ LoadLuaFile("AutoCloseBraces.lua") -- wenn diese Datei nicht verwendet wird ==> mit '--' auskommentieren oder löschen
-- Start up the events (Calls OnStartup()).
EventClass:BeginEvents()
-- Erst nach Registrierung der EventClass werden eigene Dateien geladen
LoadLuaFile("AutoStampSaveVersion.lua") -- enthält Event: "OnBeforeSave"
LoadLuaFile("MyDebug.lua")
LoadLuaFile("EdgingSelection.lua")
Alles anzeigen
Falls ihr die Funktion zum Neuladen der Properties aktiviert habt - einmal ausführen, ansonsten Neustart SciTE.
Edit 28.10.2011: Hab das Tool noch etwas verändert und auch umbenannt.
- Im Überschreib-Modus ist das Tool jetzt deaktiviert
- kleinen Bug behoben
Edit 29.10.2011:
Manchmal macht man es sich unnütz schwer. Da hatte ich doch glatt übersehen, dass das OnKey-Event gleich den Status für SHIFT, CTRL, ALT mitliefert, das vereinfacht natürlich den Code.
Weiterhin habe ich es jetzt 'internationalisiert' (auch für englisches Keyboardlayout wirksam).
Die Variablengestaltung ist nun auch übersichtlicher.Aktuelle Version: 1.3
Edit 30.10.2011:
Kleine Erweiterung: Es können einzelne Dateitypen von der Funktion ausgeschlossen werden. Dazu für jede der auszuschließenden Dateitypen einen Eintrag erstellen in "SciTEUser.properties":
"NoPairs.ext=1" (ext = Erweiterung in Kleinbuchstaben)
Aktuelle Version: 1.4
Edit 05.10.2012 NEU
Ich habe folgende Funktion hinzugefügt:
- Deklaration von Arrays mit Wertzuweisung
dazu:
- in jede Zeile einen Arraywert eintragen (Strings ohne Gänsefüßchen)
- Blockauswahl dieser Zeilen- für Strings: Strg+Alt+S (bzw. AltGr+S)
- für Zahlen, Variablen: Strg+Alt+A (bzw. AltGr+A)
- Gültigkeitsbereich wird festgelegt über die Verwendung der Buchstaben "d", "g" oder "l" ( Dim, Global oder Local )
- für Strings: "Strg+Alt+Shift+Buchstabe"
- für Zahlen, Variablen: "Strg+Alt+Buchstabe"
- statt "Strg+Alt" kann natürlich auch "AltGr" genutzt werden
Aktuelle Version: 1.6
Bsp.:
[autoit]
; vorher:
10
20
30
40
; mit "Strg+Alt+d" :
Dim $a[4] = [10,20,30,40]
; mit "Strg+Alt+Shift+L" :
Local $a[4] = ["10","20","30","40"]
EdgingSelection.lua (v1.6)
-- TIME_STAMP 2012-10-06 11:31:14 v 1.6
----------------- EdgingSelection.LUA ------------------------------------
-- Edge selected text with paired chars or set an empty pair --
-- on hit this char. --
-- Paired chars are: " ", ' ', ( ), { }, [ ] --
-- * Set edging always in multiple selected lines or in block --
-- selected areas (i.e. from line 3 to 8 in columns 20 to 30). --
-- * If caret position are left from selection hit the opening --
-- char, on position at the end hit the closing char. --
-- * It also works without selection, so you got empty pairs. The --
-- opening char must hit! (like AutoCloseBraces.lua) --
-- Hit closing char without selection inserts only this char. --
-- * ! If you want to set empty pairs on multiple lines, you must --
-- select 0 columns (hit SHIFT+ALT + n-times DOWN) and the --
-- closing char must hit. Downward selection is required for this. --
-- * NEW! --
-- Now you can declare arrays with assignment by this way: --
-- • write one value in every line (strings without quotation mark) --
-- • make block selection of this --
-- • declare the array with assignment by hotkey: --
-- the letter determines the scope to use: --
-- Letters: D = Dim, G = Global, L = Local --
-- STRG+ALT+SHIFT+(Letter) values will marked as strings in array --
-- STRG+ALT+(Letter) other values (numbers, variables) --
-- NOTE: --
-- * If you always use an script like 'AutoCloseBraces.lua', you --
-- must disable it. --
-- * The paired mode is disabled on using OVERWRITE in editor. --
-- * Keycodes for english and german keyboard layout implemented. --
-- Set your language in variable "lang". For other languages add --
-- own entries in table "tCode". To get right values uncomment the --
-- "print"-line in function "HitKey", hit the keys with pairing --
-- chars and read values from console. All entries('SHIFT', 'RAW', --
-- 'CTRL_ALT') must created, to avoid errors. --
-- * To exclude some file-types from this function, needs entry for --
-- every file-type that should excluded in "SciTEUser.properties" --
-- "NoPairs.ext=1" (.ext with lower chars!). --
--------------------------------------------------------------------------
----------------- create new EventClass, event: OnKey ------------------
HitKey = EventClass:new(Common)
------------------------------------------------------------------------
----------------- declare vars -----------------------------------------
-- set your language and add table with values
local lang = 'GE' -- 'EN' -- language identifier, used in char-table
-- virtual keycode
local tCode = {}
-- german keyboard
tCode['GE'] = {}
tCode['GE']['SHIFT'] = { [50] = '"', [191] = "'", [56] = '(', [57] = ')' } -- chars on hit SHIFT (german)
tCode['GE']['CTRL_ALT'] = { [55] = '{', [56] = '[', [57] = ']', [48] = '}', [68] = 'd', [71] = 'g', [76] = 'l' } -- chars on hit CTRL+ALT (german)
tCode['GE']['CTRL_ALT_SHIFT'] = { [68] = 'd', [71] = 'g', [76] = 'l' } -- chars on hit CTRL+ALT+SHIFT (declare array with strings)
tCode['GE']['RAW'] = {} -- empty table required to avoid errors
-- US/ english keyboard
tCode['EN'] = {}
tCode['EN']['SHIFT'] = { [48] = ')', [57] = '(', [219] = '{', [221] = '}', [222] = '"' } -- chars on hit SHIFT (english)
tCode['EN']['CTRL_ALT'] = { [68] = 'd', [71] = 'g', [76] = 'l' } -- chars on hit CTRL+ALT (only keys for array declaration)
tCode['GE']['CTRL_ALT_SHIFT'] = { [68] = 'd', [71] = 'g', [76] = 'l' } -- chars on hit CTRL+ALT+SHIFT (declare array with strings)
tCode['EN']['RAW'] = { [219] = '[', [221] = ']', [222] = "'" } -- chars hit alone (english)
-- paired chars
local tPairs = {}
tPairs['Left'] = { ['('] = ')', ['{'] = '}', ['['] = ']', ['"'] = '"', ["'"] = "'", ['d'] = 'd', ['g'] = 'g', ['l'] = 'l', ['D'] = 'D', ['G'] = 'G', ['L'] = 'L' } -- left/opening chars + trigger array declaration
tPairs['Right'] = { [')'] = '(', ['}'] = '{', [']'] = '[', ['"'] = '"', ["'"] = "'", ['d'] = 'd', ['g'] = 'g', ['l'] = 'l', ['D'] = 'D', ['G'] = 'G', ['L'] = 'L' } -- right/closing chars + trigger array declaration
-- insert key state
local stateINS = 0
------------------------------------------------------------------------
------------------ get pairs -------------------------------------------
function sibling(_sChar)
local leftChar, rightChar
if tPairs['Left'][_sChar] ~= nil then
rightChar = tPairs['Left'][_sChar]
leftChar = tPairs['Right'][rightChar]
elseif tPairs['Right'][_sChar] ~= nil then
leftChar = tPairs['Right'][_sChar]
rightChar = tPairs['Left'][leftChar]
end
return leftChar, rightChar
end --> sibling
------------------------------------------------------------------------
----------------- set edging -------------------------------------------
function EdgeSelection(_hitChar)
local leftChar, rightChar = sibling(_hitChar)
local selStart = editor.SelectionStart
local selEnd = editor.SelectionEnd
local firstLine = editor:LineFromPosition(selStart)
local lastLine = editor:LineFromPosition(selEnd)
local aPos, n, sSelection = {}, 0
local caret, sSelection, fLeft, sScope
if leftChar:find('[Dd]') then sScope = 'Dim' -- using 'd g l' sets scope for array declaration as 'Dim Global Local'
elseif leftChar:find('[Ll]') then sScope = 'Local'
elseif leftChar:find('[Gg]') then sScope = 'Global' end
caret = editor.CurrentPos
if caret <= selStart then fLeft = 1 else fLeft = 0 end -- is caret left from selection?
if (selStart == selEnd) and (tPairs['Right'][_hitChar] ~= nil) and (_hitChar ~= "'" and _hitChar ~= '"') then return nil end
-- store selected area (start- /endposition in used lines)
-- from 2nd line add to position the count of chars to insert
for i = firstLine, lastLine do
aPos[i] = {}
aPos[i][1] = editor:GetLineSelStartPosition(i) + n*2
aPos[i][2] = editor:GetLineSelEndPosition(i) + n*2
n = n +1
end
-- insert edging chars at start- /endposition
editor:BeginUndoAction()
local sAsString, sDeclaration = '', ''
if leftChar:find('[DGL]') then sAsString = '"' end n = 0
-- 'd g l' creates an array declaration, every line as one entry; with 'D G L' all entries will marked as string
if firstLine == lastLine then
if leftChar:find('[DGLdgl]') then
local sTxt = editor:GetLine(firstLine)
sTxt = sTxt:gsub('[\r\n]', '')
sDeclaration = sScope .. ' $a[1] = [' .. sAsString .. sTxt .. sAsString .. ']'
editor:DeleteBackNotLine()
editor:InsertText(editor.CurrentPos, sDeclaration)
editor:GotoPos(editor.CurrentPos +sScope:len() +3)
else
if fLeft == 1 then editor:InsertText(aPos[firstLine][2], rightChar) end
if fLeft == 0 then editor:InsertText(aPos[firstLine][1], leftChar) editor:GotoPos(caret +1) end
end
else
if leftChar:find('[DGLdgl]') then
for i = firstLine, lastLine do
local sTxt = editor:GetLine(i)
sTxt = sTxt:gsub('[\r\n]', '')
sDeclaration = sDeclaration .. sAsString .. sTxt .. sAsString .. ','
n = n +1
end
sDeclaration = sScope .. ' $a[' .. n .. '] = [' .. sDeclaration
sDeclaration = sDeclaration:gsub(',$', ']')
editor:DeleteBackNotLine()
editor:InsertText(editor.CurrentPos, sDeclaration)
editor:GotoPos(editor.CurrentPos +sScope:len() +3)
else
n = 0
for i = firstLine, lastLine do
if fLeft == 1 and i == firstLine then
editor:InsertText(aPos[i][2], rightChar)
elseif fLeft == 0 and i == lastLine then
editor:InsertText(aPos[i][1], leftChar) editor:GotoPos(caret +n*2 +1)
else
if fLeft == 1 and n > 0 then aPos[i][1] = aPos[i][1] -1 aPos[i][2] = aPos[i][2] -1 end
editor:InsertText(aPos[i][2], rightChar)
editor:InsertText(aPos[i][1], leftChar)
end
n = n +1
end
end
end
editor:EndUndoAction()
end --> EdgeSelection
------------------------------------------------------------------------
----------------- Event: OnKey -----------------------------------------
function HitKey:OnKey(_keycode, _shift, _ctrl, _alt)
--~ print('_keycode: '..tostring(_keycode)..', _shift: '..tostring(_shift)..', _ctrl: '..tostring(_ctrl)..', _alt: '..tostring(_alt)) -- DebugToConsole
if tonumber(props['NoPairs.'..props['FileExt']:lower()]) == 1 then return nil end -- to exclude file-types from this function
if _keycode == 45 then if stateINS == 0 then stateINS = 1 else stateINS = 0 end end -- on hit INSERT-key change key-state
if stateIns == 1 then return nil end -- INSERT-key in OVERWRITE-mode
if tCode[lang]['SHIFT'][_keycode] ~= nil and _shift == true then return EdgeSelection(tCode[lang]['SHIFT'][_keycode]) end
if tCode[lang]['CTRL_ALT_SHIFT'][_keycode] ~= nil and _ctrl == true and _alt == true and _shift == true then return EdgeSelection(tCode[lang]['CTRL_ALT_SHIFT'][_keycode]:upper()) end
if tCode[lang]['CTRL_ALT'][_keycode] ~= nil and _ctrl == true and _alt == true then return EdgeSelection(tCode[lang]['CTRL_ALT'][_keycode]) end
if tCode[lang]['RAW'][_keycode] ~= nil then return EdgeSelection(tCode[lang]['RAW'][_keycode]) end
return nil
end --> HitKey
------------------------------------------------------------------------
Alles anzeigen
Über mehrere Zeilen mit einem Rutsch Klammernpaare setzen:
Zeilen 0 Spalten breit markieren (SHIFT+ALT+n-mal PFEIL_AB) [Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_emptyblock1.JPG] Schließende Klammer eingeben [Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_emptyblock2.JPG]
Blockmarkierung, in jeder Zeile wird am Beginn und am Ende der Markierung mit Gänsefüßchen eingefaßt:
[Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_block1.JPG] [Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_block2.JPG] [Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_block3.JPG]
Der markierte Bereich wird mit eckigen Klammern eingefaßt (z.B. um Variablen nachträglich als Arrayinhalt zu deklarieren):
[Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_braces1.JPG] [Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_braces2.JPG] [Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_braces3.JPG]
String mit Gänsefüßchen einfassen:
[Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_string1.JPG] [Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_string2.JPG] [Blockierte Grafik: http://www.imgbox.de/users/BugFix/edge_string3.JPG]
DL bisher: 15