jEdit Community - Resources for users of the jEdit Text Editor
Buffer selection within a macro
Submitted by Anonym on Wednesday, 28 March, 2007 - 11:30
Hello all,

first of all I would like to thank the developers. jEdit is a brilliant tool. The opportunity to write own java based macros is an excellent feature. Unfortunately I have some problems in regard to pick up the right buffer for an automatic safe. But before I go into detail I have to mention, that I am not an experienced Java programmer.

What I try to do is to manipulate data from file A and try to safe it in file B.
For this purpose I take the data out of buffer A use the tokenizer to extract the needed data and write that into buffer B.
Therefore I have written the following code:

editPane.prevBuffer();
textArea.setSelectedText(sNewLine+"\n");
textArea.goToNextLine(false);
editPane.nextBuffer();

The pitty is, that I have to ensure that the order in the buffer selector is correct. That is a little bit unconvienient. Does anyone know if there is an opportunity to select the right buffer by its path or filename?

Anything like: editPane.selectBuffer(string filename/path);

I went through the whole helpfile and online wiki, but didn't found anything how I can manage that task. I also tried to record a macro but the file selection was not recorded.

Thank you for your response.

Best wishes, Andre
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
jEdit.getBuffer
by Robert Schwenn on Wed, 28/03/2007 - 22:24
jEdit.getBuffer("G:\\Tools\\jEdit_43pre9\\macros\\_test\\Funktionen.bsh");
Macros.message(view, buffer.getPath().toString());

For details see help->jEdit API Reference->org.gjp.sp.jedit->jEdit.

Robert
 
Hello Robert, thank you fo
by Anonym on Fri, 30/03/2007 - 19:20
Hello Robert,

thank you for your reply it helped me a lot and solved my problem. First I was a little bit worried, because the message dialog (Macros.message(view, buffer.getPath().toString())) displayed the path of the macro and not the one of my testfile.

But I made some tries and have written following lines to be sure that the right buffer is chosen. jEdit.getBuffer was indeed the key for success Eye-wink And it worked excellent. Now my intended task will become much more convenient.

For those who might run into the same problem, here are some lines to test if the right buffer is chosen:

Buffer TestBuffer=jEdit.getBuffer("F:\\Data\\testfile.txt");
String sPath=TestBuffer.getPath().toString();
String sFirstLine=TestBuffer.getLineText(0);
Macros.message(view, sPath);
Macros.message(view, sFirstLine);

Thank you Robert for your help.

Greetings, Andre

P.S.: You should create a testfile.txt with some dummy lines in it and save it at the correct path (as mentioned in the getBuffer method).
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   82349
Context Free Art (*.cfdg)   0.31   46055
BBEdit scheme   1.0   18595
JBuilder scheme   .001   18495
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