jEdit Community - Resources for users of the jEdit Text Editor
SearchAndReplace problem
Submitted by turtlecove on Wednesday, 15 March, 2006 - 18:57
I am writing a Macro that enables a simple kind of Wiki link in any text file. Basically if I run my macro, it finds the nearest words in [brackets] and uses that as a file name to open. It works well, but I added the feature to jump to an anchor [filename#anchor] and I cannot figure out how to get it to jump to text in a document. Here is what I have:

newbuffer=jEdit.openFile( view, WikiWord);
if (hasAnchor) {
SearchAndReplace.setSearchString(anchor);
SearchAndReplace.find( view, newbuffer, 0, true, false);
}

It behaves very erratically. It always opens the new file ok. But then it sometimes finds the anchor text, but usually does not. I've tried resetting the cursor to the top of the file to make sure it isn't past the anchor text:

view.getTextArea.setCaretPosition(0);

But that didn't help.
Strangely, if I add this:

Macros.message(view, "finding " + anchor);

before the find, it works! I suspect the popup window causes the interface to 'refresh' in some way bringing the newly opened file to some displayed state, as opposed to some open-but-not-yet-displayed-state... but I'm just guessing here...

Any help?
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Add one line
by fixedsys on Tue, 21/03/2006 - 07:11
Add the following line after newbuffer=... and if (hasAnchor)...:
VFSManager.waitForRequests();

jEdit waits then for the file to be completely loaded before continuing.

Hope it helps,
Lars
 
Worked like a charm!
by turtlecove on Wed, 22/03/2006 - 02:40
Thank you.
I've uploaded the macro to the site.

I'm getting a lot of use out of it for linking my documents together and making 'table of contents' across my documents.
 
Hi Lars, Should this also
by Robert Schwenn on Tue, 21/03/2006 - 21:07
Hi Lars,

Should this also work for file save operations?

Robert
 
Yes, it does
by fixedsys on Thu, 23/03/2006 - 08:14
Hi Robert,

yes, it works for file save operations too. It's designed for waiting on all "pending I/O requests".

Lars
 
Good to know. Thanks, Robert
by Robert Schwenn on Thu, 23/03/2006 - 20:46
Good to know. Thanks,
Robert
User login
Browse archives
« April 2024  
MoTuWeThFrSaSu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   82348
Context Free Art (*.cfdg)   0.31   46055
JBuilder scheme   .001   18495
BBEdit scheme   1.0   18116
ColdFusion scheme   1.0   18024
R Edit Mode - extensive version   0.1   17473
Advanced HTML edit mode   1.0   16206
Matlab Edit Mode   1.0   16068
jEdit XP icons   1.0   15229
XP icons for jEdit   1.1   14293