jEdit Community - Resources for users of the jEdit Text Editor
more sophisticated 'select between quotes'
Submitted by silverquick on Saturday, 29 April, 2006 - 05:17
I was playing around with Lee Turner's script (which appears to have started here: http://community.jedit.org/?q=node/view/1128), and because I work with PHP I wanted one to recognise both single and double quotes, and there's also the problem with his that if the caret is between quotations, the space between them gets selected. The latter's not that big of a problem, but trying to allow for both types of quotes is tough.

I thought I had it with this: basically track all openings and closings of quotes in the buffer prior to the caret (in PHP a ' inside "..." doesn't count and vice-versa), and if a quote is open at the caret, search after the caret to find its mate, and select between them. But then if a comment contains apostrophes or irregular double-quotes, this won't work! I could get very complicated and detect comments, but this is language-specific and what I've been thinking from the start is that it would be nice to abstract the searching from the quote syntax.

So my real question is: is there a way for a macro to interact with jEdit's syntax highlighter? It's a waste for my macro to do the work of finding quoted sections when jEdit has obviously already done the work. I'm envisioning methods get the token type of the text under the caret, get the boundaries of a given token section, etc. I've tried looking through the API docs, but (1) I'm don't really understand how the highlighting engine works, and (2) it all feels a little over my head. I am pretty green with Java.

Thanks for reading!
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
update
by silverquick on Sat, 29/04/2006 - 23:01
My goodness. I found the Token-related classes in the API docs and they are much clunkier than I expected (no offense, I could not have written them!). I learned enough to write a macro to step through the current line, select each token in turn and Macros.message() info about it.* This seems like a very inconvenient way to look for a multiline quotation though, I might be better off manually parsing quotes. Is there something I'm not getting?


* That macro, if you're interested:

DefaultTokenHandler testTH = new DefaultTokenHandler();
int curLine = textArea.getCaretLine();
int curLineStartOffset = textArea.getLineStartOffset(curLine);
buffer.markTokens(curLine, testTH);
Token testToken = testTH.getTokens();

while (testToken.id != Token.END) {
  textArea.setSelection(new Selection.Range(
    curLineStartOffset + testToken.offset,
    curLineStartOffset + testToken.offset + testToken.length
  ));
  Macros.message(view, Token.tokenToString(testToken.id) + " at " +
    testToken.offset + " for " + testToken.length);
  testToken = testToken.next;
}
User login
Browse archives
« November 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   101634
Context Free Art (*.cfdg)   0.31   46062
BBEdit scheme   1.0   18601
JBuilder scheme   .001   18502
ColdFusion scheme   1.0   18031
R Edit Mode - extensive version   0.1   17481
Advanced HTML edit mode   1.0   16213
Matlab Edit Mode   1.0   16075
jEdit XP icons   1.0   15236
XP icons for jEdit   1.1   14300