Robin
unread,Oct 1, 2011, 11:17:35 AM10/1/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scite-interest
Here is how I handled changing the non-ascii characters (below #32) to
non-black (i.e., non-reverse). The context was that I needed to mimic
the appearance and underlying control characters (i.e., hidden codes)
used by the Borland Sprint editor. That editor, dating from 1988, was/
is a fully programmable and customizable editor/formatter/printer
combination for which I have 20,000+ documents/programs in this
format. In moving to Windows 7, I needed a replacement editor - and
SciTE with Lua became the best option. These code changes below could
be abstracted to be customizable from properties and/or Lua, but I
needed the changes immediately so I just change the source and
recompile for each SciTE version. Here are the changes.
#1. The default control character is now a space (#32). In conjunction
with change #4 (below), an annoying flicker/change between states that
would otherwise happen when files are loaded and/or closed is avoided.
In Scintilla\Editor.cxx:
old:
controlCharSymbol = 0; /* Draw the control characters */
new:
controlCharSymbol = 32; /* Draw the control characters */
#2. The default control character text is replaced with a "^" version
(i.e., the hidden codes to be displayed) to mimic the Borland Sprint
edition (when revealing the underlying codes).
In Scintilla\Editor.cxx:
old:
const char *reps[] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
};
new:
const char *reps[] = {
"^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G",
"^H", "^I", "^J", "^K", "^L", "^M", "^N", "^O",
"^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W",
"^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_"
};
#3. The control characters should be in the same background style as
the other characters, so undo the reverse video (i.e., switch textBack
and textFore).
In Scintilla\Editor.cxx:
old:
if (controlCharSymbol < 32) {
// Draw the character
const char *ctrlChar = ControlCharacterString(ll->chars[i]);
DrawTextBlob(surface, vsDraw, rcSegment, ctrlChar, textBack,
textFore, twoPhaseDraw);
} else {
char cc[2] = { static_cast<char>(controlCharSymbol), '\0' };
surface->DrawTextNoClip(rcSegment, ctrlCharsFont, rcSegment.top +
vsDraw.maxAscent, cc, 1, textBack, textFore);
}
new:
if (controlCharSymbol < 32) {
// Draw the character
const char *ctrlChar = ControlCharacterString(ll->chars[i]);
DrawTextBlob(surface, vsDraw, rcSegment, ctrlChar, textFore,
textBack, twoPhaseDraw);
} else {
char cc[2] = { static_cast<char>(controlCharSymbol), '\0' };
surface->DrawTextNoClip(rcSegment, ctrlCharsFont, rcSegment.top +
vsDraw.maxAscent, cc, 1, textFore, textBack);
}
#4. The default is changed so as to not display control characters
except with a space, done in conjunction with change #1 (above) to
avoid unnecessary flicker between modes.
SciTEGlobal.properties:
old:
control.char.symbol=.
new:
control.char.symbol=
#5. The Lua function to switch between normal text and reveal codes is
the following. The only way I have found to reliably update the screen
is by calling ZoomIn and then ZoomOut.
function flipCodes()
local new1
-- #SCI_GETCONTROLCHARSYMBOL = 2389
local old1 = scite.SendEditor(2389)
if old1 == 32 then
new1 = 0
else
new1 = 32
end
-- #SCI_SETCONTROLCHARSYMBOL = 2388
scite.SendEditor(2388,new1)
-- hack to toggle to/from normal and reveal code
editor:ZoomIn()
editor:ZoomOut()
end
#6. A Lua lexer/styler is used to create the same nested control-
character text color coding as used in the original Borland Sprint
editor. It is somewhat tricky to retain state from text segment to
text segment, but it works pretty well. The main difference is that
the original Borland Sprint editor did not use a space for a control
character but the SciTE colorized space (when codes are hidden) is
actually an improvement in visual feedback.
Aside: The motivation for the underlying control characters is the
following.
Editor text (^B, ^E, ^N, etc., do not appear but the text is color-
coded):
The output can display ^Bbold^N and ^Eitalic^N text.
Example (simplified) formatter definitions:
@MACRO(B()=[<b>@EVAL()</b>])
@MACRO(E()=[<i>@EVAL()</i>])
The argument to such a macro is the text from the control character up
to the ^N in the text. The output through the formatter can then be
modified by changing the macro definitions for B, E, etc., to do quite
sophisticated formatting - and all this was possible in 1988! I use
different dynamically included definitions depending on whether the
output is HTML, Word, TeX, PostScript, etc. But the source document
(i.e., any of my 20,000+ documents) can remain the same over time.