Viewing 1 post (of 1 total)
  • Author
    Posts
  • #9398

    Antnee
    Member

    Hi guys,

    For my first attempt at macros, I decided to try a PHP comment toggler. This is because I can only find existing functions in EmEditor to comment or uncomment, but not to do both in one keypress.

    It basically just adds // to the beginning of the line if it’s not there, and removes it if it is. It should put the cursor back where it was before hand.

    xPos = document.selection.GetActivePointX(eePosView);
    document.selection.StartOfLine();
    document.selection.SelectWord();
    str = document.selection.Text;
    if (str == '//'){
    document.selection.Delete();
    document.selection.CharRight(false, xPos-3)
    } else {
    document.selection.Text = "//" + str;
    document.selection.CharRight(false, xPos-5)
    }

    I have NO idea if this is the best way to do it or not, but it works perfect for me. What it doesn’t do however is check every line – It only does the first. If anyone can extend its functionality to do that too it would be perfect for me. I suspect there’s also a function somewhere to get the current configuration’s comment and add that instead of the hard coded // that I’ve put in this?

    I hope it’s of some use to some people?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

Share with friends... Tweet about this on TwitterShare on FacebookShare on Google+Email this to someone