EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     Automated S&R?
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
WmMitchell
Posted on: 11/7/2009 5:15 am
Just popping in
Joined: 11/1/2009
From:
Posts: 5
Automated S&R?
I posted this in the regex group, which might have been a mistake. I think that it might actually be better here.

I'm not getting consistent results with the S&R macro below. If I don't put:

document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");

a lot in the document to periodically force the cursor to the top of the document being edited, the macro doesn't replace _all_ items, even though I have put the option eeReplaceAll in every single S&R instance. Even forcing the cursor up to the top of doesn't make the S&R perform consistently and I have to manually invoke this script 2 or 3 times.

------------------------------------------------------------
document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");

document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace("? ","? ",eeFindNext | eeReplaceAll);
document.selection.Replace("? ","? ",eeFindNext | eeReplaceAll);
document.selection.Replace("! ","! ",eeFindNext | eeReplaceAll);
document.selection.Replace("! ","! ",eeFindNext | eeReplaceAll);
document.selection.Replace(": ",": ",eeFindNext | eeReplaceAll);
document.selection.Replace(": ",": ",eeFindNext | eeReplaceAll);
document.selection.Replace("Dr. ","Dr. ",eeFindNext | eeReplaceAll);
document.selection.Replace("Mr. ","Mr. ",eeFindNext | eeReplaceAll);
document.selection.Replace("Mrs. ","Mrs. ",eeFindNext | eeReplaceAll);
document.selection.Replace("Lt. ","Lt. ",eeFindNext | eeReplaceAll);

document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");
document.selection.Replace("1/4","¼",eeFindNext | eeReplaceAll);
document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");
document.selection.Replace("1/2","½",eeFindNext | eeReplaceAll);
document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");
document.selection.Replace("3/4","¾",eeFindNext | eeReplaceAll);
------------------------------------------------------------

I saw an example of a macro in what looks like an old forum for EmEditor and subsituted eeFindNext for eeFindReplaceQuiet, but that didn't make the macro work repeatedly until all instances found and fixed.

What can be done to ensure the macro "loops" through each function until done, pls?

Thanks!
Yutaka
Posted on: 11/8/2009 9:29 am
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2401
Re: Automated S&R?
Quote:

WmMitchell wrote:
I posted this in the regex group, which might have been a mistake. I think that it might actually be better here.

I'm not getting consistent results with the S&R macro below. If I don't put:

document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");

a lot in the document to periodically force the cursor to the top of the document being edited, the macro doesn't replace _all_ items, even though I have put the option eeReplaceAll in every single S&R instance. Even forcing the cursor up to the top of doesn't make the S&R perform consistently and I have to manually invoke this script 2 or 3 times.

------------------------------------------------------------
document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");

document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace(". ",". ",eeFindNext | eeReplaceAll);
document.selection.Replace("? ","? ",eeFindNext | eeReplaceAll);
document.selection.Replace("? ","? ",eeFindNext | eeReplaceAll);
document.selection.Replace("! ","! ",eeFindNext | eeReplaceAll);
document.selection.Replace("! ","! ",eeFindNext | eeReplaceAll);
document.selection.Replace(": ",": ",eeFindNext | eeReplaceAll);
document.selection.Replace(": ",": ",eeFindNext | eeReplaceAll);
document.selection.Replace("Dr. ","Dr. ",eeFindNext | eeReplaceAll);
document.selection.Replace("Mr. ","Mr. ",eeFindNext | eeReplaceAll);
document.selection.Replace("Mrs. ","Mrs. ",eeFindNext | eeReplaceAll);
document.selection.Replace("Lt. ","Lt. ",eeFindNext | eeReplaceAll);

document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");
document.selection.Replace("1/4","¼",eeFindNext | eeReplaceAll);
document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");
document.selection.Replace("1/2","½",eeFindNext | eeReplaceAll);
document.selection.StartOfDocument(false);
shell.SendKeys("{CTRL DOWN}{CTRL UP}");
document.selection.Replace("3/4","¾",eeFindNext | eeReplaceAll);
------------------------------------------------------------

I saw an example of a macro in what looks like an old forum for EmEditor and subsituted eeFindNext for eeFindReplaceQuiet, but that didn't make the macro work repeatedly until all instances found and fixed.

What can be done to ensure the macro "loops" through each function until done, pls?

Thanks!


"eeFindNext | eeReplaceAll" should be enough, and you shouldn't use shell.SendKeys("{CTRL DOWN}{CTRL UP}");.

Can you simplify your test program and a sample file, and email me at tech@emurasoft.com ? I will try to reproduce your problem, and fix it if it is a bug of EmEditor.
Thank you.


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

Threaded | Newest First Previous Topic | Next Topic | Top


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