EmEditor (text editor) Forum Index
   Macro Samples
     Toggle Comments
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
Antnee
Posted on: 5/17/2011 1:38 am
Not too shy to talk
Joined: 6/16/2010
From: Nottinghamshire
Posts: 30
Toggle Comments
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?
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文