jEdit Community - Resources for users of the jEdit Text Editor
Markers and Line selection - Need Help.
Submitted by FatDog on Friday, 15 April, 2011 - 16:45
Hello. I am a developer trying to switch from Years of using Multi-Edit/Brief to JEdit.

I need a macro that will select a range of lines so I can then TAB or Shift-Tab or Delete or search within the selected area.

My old macro would do this:

* Look for the ending tag, set a marker.
* Search backwards for the starting tag, set a marker.
* Go to the end marker and start line text selection
* Jump to starting marker so that all lines from End to Start are selected.
* Stop

This then returns control to me, but leaves many lines selected so I can indent or tab or delete or copy, etc.

I am looking through the textArea API. I see deprecated calls like "getMarkLine()" which look like the functions I want - but it's deprecated.

Basically - interacting with Markers and selecting text - I'm just not getting how to do it. Any advice would be helpful.
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
a way
by Robert Schwenn on Sat, 16/04/2011 - 20:07
You don't need markers. If You have placed the caret at a desired position, You can get it's absolute offset (relative to buffer start) via textArea.getCaretPosition()...

You can create a selection via: textArea.setSelection(new Selection.Rect(StartOffset, EndOffset))
 
Thanks...
by FatDog on Sun, 17/04/2011 - 15:23

Thank you for the response.

I found the functions that give me the line numbers after I search (textArea.getCaretLine()).

(Rats - the jEdit 4.2 API link is giving me 404 errors)

From a macro I want to do a select Line Range (like the menu Edit - More Selections - Select Line Range).

BUT then I want to move the cursor to the startLine and center the scroll area so I can see the start of what is selected. (I often then have to create a Search/Replace regex and seeing the start helps me see what to look for).

Something like this:

SearchAndReplace.setSearchString("something");

..

SearchAndReplace.find(view);

startLine = textArea.getCaretLine();

SearchAndReplace.setSearchString("something_end");

endLine = textArea.getCaretLine();

// HERE IS WHERE I GET STUMPED

textArea.setSelection(new Selection.LineRange(startLine, endLine));

textArea.goToLine(startLine - 1);

textArea.scrollAndCenterCaret();

Any advice on how to create a new Selection with 2 line numbers - but let me move the caret to the start?

 
move first
by Robert Schwenn on Sun, 17/04/2011 - 15:51
One option is to move the caret to the desired position before the selection is done via:
...
endOffset = textArea.getLineStartOffset(textArea.getCaretLine());
textArea.setSelection(new Selection.Range(startOffset, endOffset));
 
Thank you
by FatDog on Tue, 28/02/2012 - 23:19
I do a reverse search for the starting "{--------" separator and do:

startLine = textArea.getLineStartOffset(textArea.getCaretLine());

Then I move down 1 line and do a forward search for the next "{-----" separator and do this:

endLine = textArea.getLineStartOffset(textArea.getCaretLine());

Then your suggestion works great:

textArea.setSelection(new Selection.Range(startLine, endLine));

Thank you.
User login
Browse archives
« August 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
31
 
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   95567
Context Free Art (*.cfdg)   0.31   46060
BBEdit scheme   1.0   18599
JBuilder scheme   .001   18500
ColdFusion scheme   1.0   18029
R Edit Mode - extensive version   0.1   17478
Advanced HTML edit mode   1.0   16211
Matlab Edit Mode   1.0   16073
jEdit XP icons   1.0   15234
XP icons for jEdit   1.1   14298