1.How can I limmit the undo actions in a specific number?
2.When I am writting keywords, the last keyword does not colorized,
unless I type a space or other symbol or I press enter,that is, the
last keyword in the last line does not colorized.
Example:
mov edx,ecx
If the above is the last line and after the keyword 'ecx' there is
nothing character, this keyword does not colorize.
Thank you,
Manos.
Out of curiosity, why do you want to limit that number? To save memory?
I don't think you can limit that without changing Scintilla's source.
If you want to do that, you can look at CellBuffer.cxx, starting at
UndoHistory::EnsureUndoRoom and around, I think.
> 2.When I am writting keywords, the last keyword does not colorized,
> unless I type a space or other symbol or I press enter,that is, the
> last keyword in the last line does not colorized.
Yes, it is a bug shared by many lexers...
Lot of them use a loop like:
StyleContext sc(startPos, length, initStyle, styler);
for (; sc.More(); sc.Forward()) {
// [...]
}
When reaching the end of the document (eg. when typing a keyword on the
last line, in the case that interest us), we can have a pending
changeState. We can complete it there. For example, the Lua lexer does
it like:
if (setWord.Contains(sc.chPrev)) {
char s[100];
sc.GetCurrent(s, sizeof(s));
if (keywords.InList(s)) {
sc.ChangeState(SCE_LUA_WORD);
} else if (keywords2.InList(s)) {
sc.ChangeState(SCE_LUA_WORD2);
} else if (keywords3.InList(s)) {
sc.ChangeState(SCE_LUA_WORD3);
} else if (keywords4.InList(s)) {
sc.ChangeState(SCE_LUA_WORD4);
} else if (keywords5.InList(s)) {
sc.ChangeState(SCE_LUA_WORD5);
} else if (keywords6.InList(s)) {
sc.ChangeState(SCE_LUA_WORD6);
} else if (keywords7.InList(s)) {
sc.ChangeState(SCE_LUA_WORD7);
} else if (keywords8.InList(s)) {
sc.ChangeState(SCE_LUA_WORD8);
}
}
sc.Complete();
my AHK lexer (unofficial) does that like:
if (sc.state == SCE_AHK_IDENTIFIER) {
sc.GetCurrentLowered(currentWord, sizeof(currentWord));
HighlightKeyword(currentWord, sc, keywordlists, styler);
} else if (sc.state == SCE_AHK_STRING && bInExprString) {
sc.ChangeState(SCE_AHK_ERROR);
} else if (sc.state == SCE_AHK_VARREF) {
sc.ChangeState(SCE_AHK_ERROR);
}
sc.Complete();
etc.
C++ lexer doesn't do it...
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --
2.Here is the the LexAsm.cxx as I adapt this for my settings,
but I dont know how can I solve the problem.
static inline bool IsAWordChar(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '.' ||
ch == '_' || ch == '?');
}
static inline bool IsAWordStart(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.' ||
ch == '%' || ch == '@' || ch == '$' || ch == '?');
}
static inline bool IsAsmOperator(const int ch) {
if ((ch < 0x80) && (isalnum(ch)))
return false;
// '.' left out as it is used to make up numbers
if (ch == '*' || ch == '/' || ch == '-' || ch == '+' ||
ch == '(' || ch == ')' || ch == '=' || ch == '^' ||
ch == '[' || ch == ']' || ch == '<' || ch == '&' ||
ch == '>' || ch == ',' || ch == '|' || ch == '~' ||
ch == '%' || ch == ':')
return true;
return false;
}
static void ColouriseAsmDoc(unsigned int startPos, int length, int
initStyle, WordList *keywordlists[],
Accessor &styler) {
WordList &cpuInstruction = *keywordlists[0];
WordList &mmxInstruction = *keywordlists[1];
WordList ®isters = *keywordlists[2];
WordList &directive = *keywordlists[3];
WordList &directiveOperand = *keywordlists[4];
WordList &fpuInstruction = *keywordlists[5];
WordList &hiInstruction = *keywordlists[6];
WordList &resInstruction = *keywordlists[7];
WordList &extInstruction = *keywordlists[8];
// Do not leak onto next line
if (initStyle == SCE_ASM_STRINGEOL)
initStyle = SCE_ASM_DEFAULT;
StyleContext sc(startPos, length, initStyle, styler);
for (; sc.More(); sc.Forward())
{
// Prevent SCE_ASM_STRINGEOL from leaking back to previous line
if (sc.atLineStart && (sc.state == SCE_ASM_STRING))
{
sc.SetState(SCE_ASM_STRING);
}
else if (sc.atLineStart && (sc.state == SCE_ASM_CHARACTER))
{
sc.SetState(SCE_ASM_CHARACTER);
}
// Handle line continuation generically.
if (sc.ch == '\\')
{
if (sc.chNext == '\n' || sc.chNext == '\r')
{
sc.Forward();
if (sc.ch == '\r' && sc.chNext == '\n')
{
sc.Forward();
}
continue;
}
}
// Determine if the current state should terminate.
if (sc.state == SCE_ASM_OPERATOR)
{
if (!IsAsmOperator(sc.ch))
{
sc.SetState(SCE_ASM_DEFAULT);
}
}
else if (sc.state == SCE_ASM_NUMBER)
{
if (!IsAWordChar(sc.ch))
{
sc.SetState(SCE_ASM_DEFAULT);
}
}
else if (sc.state == SCE_ASM_IDENTIFIER)
{
if (!IsAWordChar(sc.ch))
{
char s[100];
sc.GetCurrentLowered(s, sizeof(s));
HighlightKeyword(currentWord, sc, keywordlists, styler);
if (cpuInstruction.InList(s))
{
sc.ChangeState(SCE_ASM_CPUINSTRUCTION);
}
else if (mmxInstruction.InList(s))
{
sc.ChangeState(SCE_ASM_MMXINSTRUCTION);
}
else if (registers.InList(s))
{
sc.ChangeState(SCE_ASM_REGISTER);
}
else if (directive.InList(s))
{
sc.ChangeState(SCE_ASM_DIRECTIVE);
}
else if (directiveOperand.InList(s))
{
sc.ChangeState(SCE_ASM_DIRECTIVEOPERAND);
}
else if (fpuInstruction.InList(s))
{
sc.ChangeState(SCE_ASM_FPUINSTRUCTION);
}
else if (hiInstruction.InList(s))
{
sc.ChangeState(SCE_ASM_HILEVELINSTRUCTION);
}
else if (resInstruction.InList(s))
{
sc.ChangeState(SCE_ASM_RESOURCE);
}
else if (extInstruction.InList(s))
{
sc.ChangeState(SCE_ASM_EXTINSTRUCTION);
}
sc.SetState(SCE_ASM_DEFAULT);
}
}
else if (sc.state == SCE_ASM_COMMENT )
{
if (sc.atLineEnd)
{
sc.SetState(SCE_ASM_DEFAULT);
}
}
else if (sc.state == SCE_ASM_STRING)
{
if (sc.ch == '\\') {
if (sc.chNext == '\"' || sc.chNext == '\'' || sc.chNext == '\\')
{
sc.Forward();
}
}
else if (sc.ch == '\"')
{
sc.ForwardSetState(SCE_ASM_DEFAULT);
}
else if (sc.atLineEnd)
{
sc.ChangeState(SCE_ASM_STRINGEOL);
sc.ForwardSetState(SCE_ASM_DEFAULT);
}
}
else if (sc.state == SCE_ASM_CHARACTER)
{
if (sc.ch == '\\')
{
if (sc.chNext == '\"' || sc.chNext == '\'' || sc.chNext == '\\')
{
sc.Forward();
}
}
else if (sc.ch == '\'')
{
sc.ForwardSetState(SCE_ASM_DEFAULT);
}
else if (sc.atLineEnd)
{
sc.ChangeState(SCE_ASM_STRINGEOL);
sc.ForwardSetState(SCE_ASM_DEFAULT);
}
}
// Determine if a new state should be entered.
if (sc.state == SCE_ASM_DEFAULT)
{
if (sc.ch == ';')
{
sc.SetState(SCE_ASM_COMMENT);
}
else if (isascii(sc.ch) && (isdigit(sc.ch) || (sc.ch == '.' &&
isascii(sc.chNext) && isdigit(sc.chNext))))
{
sc.SetState(SCE_ASM_NUMBER);
}
else if (IsAWordStart(sc.ch))
{
sc.SetState(SCE_ASM_IDENTIFIER);
}
else if (sc.ch == '\"')
{
sc.SetState(SCE_ASM_STRING);
}
else if (sc.ch == '\'')
{
sc.SetState(SCE_ASM_CHARACTER);
}
else if (IsAsmOperator(sc.ch))
{
sc.SetState(SCE_ASM_OPERATOR);
}
}
}
sc.Complete();
}
static const char * const asmWordListDesc[] = {
"CPU instructions",
"MMX instructions",
"Registers",
"Directives",
"Directive operands",
"FPU instructions",
"HiLevel instructions",
"Res instructions"
"Extended instructions",
0
};
LexerModule lmAsm(SCLEX_ASM, ColouriseAsmDoc, "asm", 0,
asmWordListDesc);
For the last LexAsm patch I submitted, I have a test file for
LexAsm with samples for most lexed elements, and x86 instructions.
It's 6 years old, but you can easily adapt it for your own testing
efforts. I've uploaded it at:
http://groups.google.com/group/scintilla-interest/files
The filename is: asm-test-khman.zip
> On 29 οΏ½οΏ½οΏ½, 22:54, Manos <manos...@otenet.gr> wrote:
>> I am a C/C++ and Assembly programmer.
>> I would like to use the Scintilla component in my IDE for assembly
>> language because this control is excellent.
>> But I have two questions:
>>
>> 1.How can I limmit the undo actions in a specific number?
>>
>> 2.When I am writting keywords, the last keyword does not colorized,
>> unless I type a space or other symbol or I press enter,that is, the
>> last keyword in the last line does not colorized.
>> Example:
>>
>> mov edx,ecx
>>
>> If the above is the last line and after the keyword 'ecx' there is
>> nothing character, this keyword does not colorize.
Yep, it's one of those little glitches that drive perfectionists
mad. I suppose you can post it in the bug tracker, and I think it
would be left to someone in the community to contribute a fix. I
did some work on LexAsm a long while ago, but I'd rather not
commit to this as I have too many items gathering dust in my TODO
list right now... :-)
--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia
Why? Do you need to do that in a memory constrained environment? Do you
plan to hack the same file for days without ever closing the buffer?
I doubt you will gain much memory by doing that. Beside, Scintilla in
general prefers to trade memory for speed, ie. it eats big chunks of
memory in order to make processing of document faster.
Which is rarely an issue: it wasn't years ago, when the project started,
it is even less today.
Unless you try to open a plain text file of 1GB... (eg. a Thunderbird
mailbox!). You must know that Scintilla allocates (at least) one byte of
memory for each character of the file: it stores the style of the cell,
even if there is no styler.
That, and line information and some other stuff.
> 2.Here is the the LexAsm.cxx as I adapt this for my settings,
> but I dont know how can I solve the problem.
You can try and put:
if (sc.state == SCE_ASM_IDENTIFIER) {
char s[100];
sc.GetCurrentLowered(s, sizeof(s));
if (cpuInstruction.InList(s)) {
sc.ChangeState(SCE_ASM_CPUINSTRUCTION);
} else if (mathInstruction.InList(s)) {
sc.ChangeState(SCE_ASM_MATHINSTRUCTION);
} else if (registers.InList(s)) {
sc.ChangeState(SCE_ASM_REGISTER);
} else if (directive.InList(s)) {
sc.ChangeState(SCE_ASM_DIRECTIVE);
} else if (directiveOperand.InList(s)) {
sc.ChangeState(SCE_ASM_DIRECTIVEOPERAND);
} else if (extInstruction.InList(s)) {
sc.ChangeState(SCE_ASM_EXTINSTRUCTION);
}
}
just before the sc.Complete();
(untested, can be improved... Code from real LexAsm...)
Manos.
Where is your HighlightKeyword(currentWord, sc, keywordlists,
styler); ?
Thank you,
Manos.