jEdit Community - Resources for users of the jEdit Text Editor
How to fetch current Keyword/Token?
Submitted by uhuebner on Tuesday, 2 March, 2010 - 10:54
I'm trying to change my existing macro of uppercasing keywords to use exactly the case that is given by the Keyword-XML file, e.g. gettext -> getText instead of GETTEXT.
I get the next token bei using Token.next. But I only get the representation in my TextArea. How can I retrieve the corresponding original Keyword as given by the XML file?

Thanks
uhuebner
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
My source so far - no indenting :o(
by uhuebner on Tue, 02/03/2010 - 10:57
/**
* Converts keyword token types to correct case.
*/
void keywords2case(View view)
{
// declarations run faster than doing Token.KEYWORDx comparison
byte KEYWORD1 = Token.KEYWORD1;
JEditBuffer buffer = view.getBuffer();
JEditTextArea textArea = view.getTextArea();
Token token = null;

Selection[] selection = textArea.getSelection();
Buffer.TokenList info = null;
int pos = 0;
int lineStart = 0;

for(int line = 0; line < textArea.getLineCount(); ++line)
{
info = buffer.markTokens(line);
token = info.getFirstToken();
lineStart = buffer.getLineStartOffset(line);
pos = lineStart;
while(token != null)
{
if (KEYWORD1 == token.id)
{
// old mimic for using upper case
String word = buffer.getText(pos,token.length);
buffer.remove(pos,token.length);
// !!! HERE the original keyword should be inserted !!!
buffer.insert(pos,word.toUpperCase());
}
pos += token.length;
token = token.next;
}
}
view.getTextArea().setSelection(selection);
view.getStatus().setMessageAndClear("Converted Keywords to correct Case");
}
keywords2case(view);
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