Scite Tabs To Spaces Observe Tabstop

lua-users home
wiki

Converts tabs to spaces while obeying tabstops (your current scite setting), so what you see doesn't change

The script (which you add to ext.lua.startup.script ):

function tabs_to_spaces_obey_tabstop()

    -- replace one tab tab followed by one or more (space or tab)

    -- but obey tabstops (preserves alignment)

        for m in editor:match("[\\t][\\t ]*", SCFIND_REGEXP) do

            local posColumn = ( scite.SendEditor(SCI_GETCOLUMN, (m.pos ) ) ) 

            local poslenColumn = ( scite.SendEditor(SCI_GETCOLUMN, (m.pos + m.len) ) ) 

            m:replace(string.rep(' ', poslenColumn - posColumn ))

		end

end

To configure:


ext.lua.startup.script=$(SciteUserHome)/test.lua

command.name.17.*=tabs_to_spaces_obey_tabstop

command.17.*=tabs_to_spaces_obey_tabstop

command.subsystem.17.*=3

command.mode.17.*=subsystem:lua,savebefore:no,groupundo



Example input:


Age 	Pull-Ups 	Crunches 	3-Mile Run

17-26 	    3 	        50 	        28:00

27-39 	    3 	        45 	        29:00

40-45 	    3 	        45 	        30:00

46+ 	    3 	        40 	        33:00 

converting all tabs to spaces turns input into:


Age     Pull-Ups     Crunches     3-Mile Run

17-26         3             50             28:00

27-39         3             45             29:00

40-45         3             45             30:00

46+         3             40             33:00 

notice how the alignment changed. With tabs_to_spaces_obey_tabstop, we use your current scite settings to obey tabstops:


Age     Pull-Ups    Crunches    3-Mile Run

17-26       3           50          28:00

27-39       3           45          29:00

40-45       3           45          30:00

46+         3           40          33:00 


RecentChanges · preferences
edit · history
Last edited May 16, 2010 12:20 am GMT (diff)