- AuthorPosts
- December 15, 2012 at 5:20 pm #10664QiaoJiaoParticipant
Is it possible to jump to a given line in macros/scripts?
I only found
editor.ExecuteCommandByID(4139);
But where do I write line’s number?
Or is it possible to open file and jump to a given line with arguments?
December 15, 2012 at 6:13 pm #10665QiaoJiaoParticipantThe closest way is:
clipboardData.setData("Text", line_number);
editor.ExecuteCommandByID(4139);Then you have to press “ctrl+v” and “enter”.
December 16, 2012 at 1:25 am #10666Yutaka EmuraKeymasterHello,
The following macro will move the cursor to the n-th line.
document.selection.SetActivePoint(eePosLogical, 1, n);
Thanks!
December 16, 2012 at 8:23 am #10667QiaoJiaoParticipantThank you, it is exactly what I am looking for.
Actually, I need to jump to a random line. Here is a code for it:
var lines_total = document.GetLines();
var line_random = Math.floor((Math.random()*lines_total)+1);
document.selection.SetActivePoint(eePosLogical, 1, line_random);
January 3, 2013 at 7:37 am #10703QiaoJiaoParticipantI’ve just found that it is possible to use command line options for this:
EmEditor /l 1234 D:file.txt
It is not a macro, but it is much more powerful for my case. I am using it with Python script that counts lines, selects random line and starts a program.
One difference is that SetActivePoint macro sets pointer to the bottom edge of a screen. And /l sets it to the middle.
- AuthorPosts
- You must be logged in to reply to this topic.