jEdit Community - Resources for users of the jEdit Text Editor
Select text in quotes - can macro do this?
Submitted by paulflory on Wednesday, 10 March, 2004 - 20:14
Here's what I'd like to do:

Assign a shortcut key to a macro that selects all the text within whatever quotes my cursor happens to be sitting between.

For example, say the cursor is sitting within the following line:

"How do you go to the stockyards?"

Does anyone an idea how I could write a macro that would select everything within the quotes? This would be quite convenient for doing quick replacements.

Thanks,
Paul
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
Quick attempt.
by lturner on Thu, 11/03/2004 - 15:15
Hi

Not sure if this is the best way to do this but it seems to work OK:

// find starting point i.e where the cursor is.
int currentPosition = textArea.getCaretPosition();
int startPosition = 0;

// keep going back until we find a quote
do
{
textArea.goToPrevCharacter(false);
}
while((textArea.getCaretPosition() != 0) && !(textArea.getText(textArea.getCaretPosition(), 1).equals("\"")));

// if no quote found, move caret back and forget it
if(textArea.getCaretPosition() == 0)
{
textArea.moveCaretPosition(currentPosition);
}
else
{
startPosition = textArea.getCaretPosition() + 1;

// now move forwards to see if we can find a quote.
do
{
textArea.goToNextCharacter(false);
}
while((textArea.getCaretPosition() != buffer.getLength()) &&!(textArea.getText(textArea.getCaretPosition(), 1).equals("\"")));

// no forward matching quote.
if(textArea.getCaretPosition() == buffer.getLength())
{
textArea.moveCaretPosition(currentPosition);
}
else
{
textArea.setSelection(new Selection.Range(startPosition, textArea.getCaretPosition()));
}

textArea.moveCaretPosition(currentPosition);
}
 
A different Version.....
by rmshb on Wed, 10/11/2004 - 11:12
I'm new to jEdit. Please let me know how my code worked....

//Macro Starts here
currentPosition = textArea.getCaretPosition();

SearchAndReplace.setSearchString("\"");
if(!SearchAndReplace.find(view, buffer, currentPosition, true, true)) return;
startPos = textArea.getCaretPosition();

SearchAndReplace.setSearchString("\"");
if(!SearchAndReplace.find(view, buffer, currentPosition, true, false)) return;
endPos = textArea.getCaretPosition();

if(endPos - startPos == 1) return;

textArea.setSelection(new Selection.Range(startPos+1, endPos-1));
textArea.moveCaretPosition(currentPosition);
//Macro ends here
 
your example worked!
by paulflory on Thu, 11/03/2004 - 16:17
Lee,

Thanks a ton! This worked for me. I'll play with the code some, try to get it to do some more (like match other quotes/symbols as well).


Paul
 
Select word or Enclosed macro
by takeshin on Thu, 19/06/2008 - 09:11
This one is even more useful:
Select word or enclosed macro

regards,
takeshin
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