Jump to content

SciTE - Continuouse Comment Mode, also for SciTE-RU


BugFix
 Share

Recommended Posts

I think, you know this: the script is ready and now u want to write all comments. But every line has a different length and so you must insert tabs and spaces to get all comments at the same column.

This LUA-script do that for you. Define a column for automatically line break (not really a break, if this position is reached the comment goes on on next line) and character(s) to start every comment line. Optionally also character(s) to mark automatically brakes - see my picture.

Edit 2012-02-15:

- It takes effect only after restart SciTE.

Edit 2012-02-17:

- problems with correct position solved

- also available a version for users with SciTE-RU

Edit 2012-02-18:

extended functionality:

- If the last word in line overrides the breakposition, this word will moved to next line.

- In addition, a manual break can generated with simultaneous insertion of a blank line by hit the <ENTER> key. The behaviour is like automatically brake. Additional entry in properties required, see install notes.

DESCRIPTION and INSTALLATION:

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 "ContinuousComments.lua".
    Save the script "ContinuousComments.lua" to folder "..SciTELUA".

    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 "..SciTELUASciTEStartup.lua"
        LoadLuaFile("ContinuousComments.lua")          <== Insert at end of file!!
----------------------------------------------------------------------------------------------------------------------------------

This is the script (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 #######  Seilenwechsel 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 ######
            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

Version for SciTE-RU is attached.

Here the picture and the files:

post-8176-0-18287300-1329492848_thumb.jp

ContinuousComments.txt

ContinuousCommentsRu.txt

Edited by Jos

Best Regards BugFix  

Link to comment
Share on other sites

How exactly do you use this? Do you hit the hotkey and then what? When I hit ctrl_shift_k it places a ; in the editor. Then do I just start typing my comment? I type a comment that is more than long enough but the comment line never breaks.

Edited by Jos
Link to comment
Share on other sites

Plese see my Edit at 1st post.

May it be, that you have not restart SciTE after installing the script? ( Sorry, i forgot to say, that's required. )

I've tested now again on an old PC and got the same behaviour without restart SciTE.

The Hotkey toggles the Continuouse Comment Mode ON/OFF.

While state is ON, you see the mouse cursor as hand. It changes back to default if state is off.

If mode starts, the defined comment character(s) inserted at cursor position and an space added. If cursor position is not at end of line, it skips to end of line!

Now you write comment words. With press the <space> key an function checks, if breakpoint is reached. Is it so, than with the next pressed key skips the cursor to next line, adds spaces if needed to got the same position, inserts comment character(s) and an space and than the pressed key-char.

If characters defined to mark end of lines with automatically break (and also for the next line), this chars are added after last line and in next line in front of your text. You see it in my posted picture.

Best Regards BugFix  

Link to comment
Share on other sites

I restarted scite and I hit the hotkey. The cursor turns to a hand and inserts a '; '. I then type a comment which exceeds the limit but it doesn't break it.

Link to comment
Share on other sites

Please change the following function to this:

local isLFpos = function()
local pos = posInLine()
print('current pos: '..tostring(pos), 'break pos: '..tostring(lfPos))  -- DebugToConsole
if pos >= lfPos then
print('break point reached')  -- DebugToConsole
  return true
else
  return false
end
end

Than try it again. In normal case, everytime if pressed <space> in console output should be seen the current position and the defined brake position.

Please check if the break position is the same, like defined in your properties.

Best Regards BugFix  

Link to comment
Share on other sites

Now it skips to next line? Only by inserting the debug lines? Hmmm, may be the script runs too fast... :)

Instead having debug lines, add one script line by position check:

function CommentHitKey:OnKey(_keycode)
    if fCommentModeOn then                                
        local fBreak = isLFpos()                                  -- this line is new
        if _keycode == 32 and fBreak then                -- changing in statement
            fNext = true                                             
        elseif _keycode == 40 then                      
            fNext = true  fIsNewLine = true              
        elseif fNext then                                         
            fNext = false
            if not fIsNewLine then                               
                editor:InsertText(editor.CurrentPos, charBreak1)   
            end
            ContinuousComment()
        end
    end
    return nil
end

After line break the comment is inside your autoit-code? Can not believe it. I use the command "editor:LineEnd()" and i've never seen that this does'nt work.

Please give me a screenshot of this.

Best Regards BugFix  

Link to comment
Share on other sites

  • Developers

Ok, after quite some messing around I managed to remove the file attachments and bottom spoiler which seemed to mess up the Forum.

Try adding stuff back in now.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

The problem is somewhere in that SciTE-RU code block I removed.

Maybe not post that code but attach it?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The problem is somewhere in that SciTE-RU code block I removed.

Maybe not post that code but attach it?

Was it non-english characters (letters) in them? I've noticed they mess up posts when in AutoIt tags

Edit: Edit

Edited by AdmiralAlkex
Link to comment
Share on other sites

  • Developers

Hmm, no luck by editing my 1st Post. Seems as if some characters break down the structure of the post.

Sorry, if i use a wrong char, but i don't know, which it is.

I have fixed it again. I have removed some strange characters on this line in your script in the last CODE box:

elseif _keycode == 32 and fBreak then                  -- Leerzeichen u. Position XXXXXXXXXXX

You last post is now merged with the first post and all looks good again.

Avoid posting code containing special characters.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks Jos.

Now i know the problem. By editing the script in SciTE-RU my comments are shown with another code page. Because that some special characters are used. I have saved the file, without considering that the wrong characters are saved too.

Sorry for this. :)

Best Regards BugFix  

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...