Sign in to follow this  
Followers 0
dcop

Remove Trailing White Space

3 posts in this topic

This feature is missing now in tools and I'm almost sure I had it recently and didnt upgrade. I'm using

SciTE

Version 1.76

Mar 30 2008 21:05:14

TIA, Dennis

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

We left it out after the total rewrite of the LUA functions, but I never use it anyways because Tidy does that for you as well.

Here is the old info when you want to use it for yourself:

Additional Tools option you could add to SciteUSer.properties:

# 39 Clean up script by resetting indents and removing trailing spaces
command.name.39.$(au3)=Cleanup Script WhiteSpace
command.subsystem.39.$(au3)=3
command.39.$(au3)=InvokeTool AutoItTools.cleanDocWhitespace
command.shortcut.39.$(au3)=
command.save.before.39.$(au3)=2

Lua Functions (add at the bottom of file AutoItTools.LUA:

--++++++++++++++++++++++++++++++++++++++++++++++++++
-- Clean up document option by Bruce Dodson
-- 
function AutoItTools:cleanDocWhitespace()
    local trailingSpacesCount = self:stripTrailingSpaces(false)
    local fixedIndentationCount = self:fixIndentation(false)

    if (fixedIndentationCount == 0) and (trailingSpacesCount == 0) then
        print("Document was clean already; nothing to do.")
    end
end
--
function AutoItTools:stripTrailingSpaces(reportNoMatch)
    local count = 0
    local fs,fe = editor:findtext("[ \\t]+$", SCFIND_REGEXP)
    if fe then
        repeat
            count = count + 1
            editor:remove(fs,fe)
            fs,fe = editor:findtext("[ \\t]+$", SCFIND_REGEXP, fs)
        until not fe
        print("Removed trailing spaces from " .. count .. " line(s).")
    elseif reportNoMatch then
        print("Document was clean already; nothing to do.")
    end
    return count
end
--
function AutoItTools:fixIndentation(reportNoMatch)
    local tabWidth = editor.TabWidth
    print("Tabsize:" .. tabWidth) 
    local count = 0
    if editor.UseTabs then
        -- for each piece of indentation that includes at least one space
        for m in editor:match("^[\\t ]* [\\t ]*", SCFIND_REGEXP) do
            -- figure out the indentation size
            local indentSize = editor.LineIndentation[editor:LineFromPosition(m.pos)]
            local spaceCount = math.mod(indentSize, tabWidth)
            local tabCount = (indentSize - spaceCount) / tabWidth
            local fixedIndentation = string.rep('\t', tabCount) .. string.rep(' ', spaceCount)

            if fixedIndentation ~= m.text then
                m:replace(fixedIndentation)
                count = count + 1
            end
        end
    else
        -- for each piece of indentation that includes at least one tab
        for m in editor:match("^[\\t ]*\t[\\t ]*", SCFIND_REGEXP) do
            -- just change all of the indentation to spaces
            m:replace(string.rep(' ', editor.LineIndentation[editor:LineFromPosition(m.pos)]))
            count = count + 1
        end
    end
    if count > 0 then
        print("Fixed indentation for " .. count .. " line(s).")
    elseif reportNoMatch then
        print("Document was clean already; nothing to do.")
    end
    return count
end

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Great, thanx Jos....I thought it mysteriosly walked away. I'll use Tidy.

Dennis

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0