From 99938dd821efb4b920db029a509b1a42ef86ea3c Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Mon, 18 Jan 2016 04:22:26 +0100 Subject: [PATCH] Update Scintilla to version 3.6.3 Includes improvements for Lua 5.3 and Perl 5.22. --- scintilla/gtk/PlatGTK.cxx | 2 +- scintilla/gtk/ScintillaGTK.cxx | 138 ++++++++++++++----------------- scintilla/include/Platform.h | 2 +- scintilla/include/Scintilla.h | 6 ++ scintilla/include/Scintilla.iface | 20 ++++- scintilla/include/ScintillaWidget.h | 27 ++++-- scintilla/lexers/LexBash.cxx | 82 +++++++++++++------ scintilla/lexers/LexCPP.cxx | 6 +- scintilla/lexers/LexCaml.cxx | 6 +- scintilla/lexers/LexCmake.cxx | 2 +- scintilla/lexers/LexLaTeX.cxx | 10 +-- scintilla/lexers/LexLua.cxx | 2 +- scintilla/lexers/LexMatlab.cxx | 10 +-- scintilla/lexers/LexPO.cxx | 32 ++++---- scintilla/lexers/LexPerl.cxx | 134 ++++++++++++++++++++++++------ scintilla/lexers/LexRust.cxx | 6 +- scintilla/lexers/LexSQL.cxx | 10 +-- scintilla/scintilla_changes.patch | 16 ++-- scintilla/src/CellBuffer.cxx | 19 +++++ scintilla/src/CellBuffer.h | 1 + scintilla/src/Document.cxx | 42 ++++++++-- scintilla/src/Document.h | 8 +- scintilla/src/EditModel.h | 2 +- scintilla/src/EditView.cxx | 21 +++-- scintilla/src/Editor.cxx | 158 +++++++++++++++++++++++++++--------- scintilla/src/Editor.h | 8 +- scintilla/src/Indicator.cxx | 2 +- scintilla/src/PerLine.cxx | 3 +- scintilla/src/ScintillaBase.cxx | 4 +- scintilla/src/UniConversion.cxx | 4 - scintilla/src/UniConversion.h | 4 + scintilla/version.txt | 2 +- 32 files changed, 528 insertions(+), 261 deletions(-) diff --git a/scintilla/gtk/PlatGTK.cxx b/scintilla/gtk/PlatGTK.cxx index 58b0e1364..063c42b3a 100644 --- a/scintilla/gtk/PlatGTK.cxx +++ b/scintilla/gtk/PlatGTK.cxx @@ -1608,7 +1608,7 @@ void ListBoxX::Create(Window &, int, Point, int, bool, int) { cssProvider = gtk_css_provider_new(); } #endif - + wid = widCached = gtk_window_new(GTK_WINDOW_POPUP); frame = gtk_frame_new(NULL); diff --git a/scintilla/gtk/ScintillaGTK.cxx b/scintilla/gtk/ScintillaGTK.cxx index 127d6cbe3..37f1e0730 100644 --- a/scintilla/gtk/ScintillaGTK.cxx +++ b/scintilla/gtk/ScintillaGTK.cxx @@ -296,8 +296,6 @@ private: static void PreeditChanged(GtkIMContext *context, ScintillaGTK *sciThis); void MoveImeCarets(int pos); void DrawImeIndicator(int indicator, int len); - static void GetImeUnderlines(PangoAttrList *attrs, bool *normalInput); - static void GetImeBackgrounds(PangoAttrList *attrs, bool *targetInput); void SetCandidateWindowPos(); static void StyleSetText(GtkWidget *widget, GtkStyle *previous, void*); @@ -306,7 +304,7 @@ private: static void Destroy(GObject *object); static void SelectionReceived(GtkWidget *widget, GtkSelectionData *selection_data, guint time); - static void ClipboardReceived(GtkClipboard *clipboard, GtkSelectionData *selection_data, + static void ClipboardReceived(GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data); static void SelectionGet(GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint time); @@ -1930,7 +1928,7 @@ gint ScintillaGTK::ScrollEvent(GtkWidget *widget, GdkEventScroll *event) { // intensity of scrolling info in the native message, gtk doesn't // support this so we simulate similarly adaptive scrolling) // Note that this is disabled on OS X (Darwin) with the X11 backend - // where the X11 server already has an adaptive scrolling algorithm + // where the X11 server already has an adaptive scrolling algorithm // that fights with this one int cLineScroll; #if defined(__APPLE__) && !defined(GDK_WINDOWING_QUARTZ) @@ -2328,24 +2326,28 @@ void ScintillaGTK::DrawImeIndicator(int indicator, int len) { } } -void ScintillaGTK::GetImeUnderlines(PangoAttrList *attrs, bool *normalInput) { - // Whether single underlines attribute is or not - // attr position is counted by the number of UTF-8 bytes +static std::vector MapImeIndicators(PangoAttrList *attrs, const char *u8Str) { + // Map input style to scintilla ime indicator. + // Attrs position points between UTF-8 bytes. + // Indicator index to be returned is character based though. + glong charactersLen = g_utf8_strlen(u8Str, strlen(u8Str)); + std::vector indicator(charactersLen, SC_INDICATOR_UNKNOWN); + PangoAttrIterator *iterunderline = pango_attr_list_get_iterator(attrs); if (iterunderline) { do { PangoAttribute *attrunderline = pango_attr_iterator_get(iterunderline, PANGO_ATTR_UNDERLINE); if (attrunderline) { - glong start = attrunderline->start_index; - glong end = attrunderline->end_index; + glong start = g_utf8_strlen(u8Str, attrunderline->start_index); + glong end = g_utf8_strlen(u8Str, attrunderline->end_index); PangoUnderline uline = (PangoUnderline)((PangoAttrInt *)attrunderline)->value; for (glong i=start; i < end; ++i) { switch (uline) { case PANGO_UNDERLINE_NONE: - normalInput[i] = false; + indicator[i] = SC_INDICATOR_UNKNOWN; break; case PANGO_UNDERLINE_SINGLE: // normal input - normalInput[i] = true; + indicator[i] = SC_INDICATOR_INPUT; break; case PANGO_UNDERLINE_DOUBLE: case PANGO_UNDERLINE_LOW: @@ -2357,25 +2359,22 @@ void ScintillaGTK::GetImeUnderlines(PangoAttrList *attrs, bool *normalInput) { } while (pango_attr_iterator_next(iterunderline)); pango_attr_iterator_destroy(iterunderline); } -} -void ScintillaGTK::GetImeBackgrounds(PangoAttrList *attrs, bool *targetInput) { - // Whether background color attribue is or not - // attr position is measured in UTF-8 bytes PangoAttrIterator *itercolor = pango_attr_list_get_iterator(attrs); if (itercolor) { do { PangoAttribute *backcolor = pango_attr_iterator_get(itercolor, PANGO_ATTR_BACKGROUND); if (backcolor) { - glong start = backcolor->start_index; - glong end = backcolor->end_index; + glong start = g_utf8_strlen(u8Str, backcolor->start_index); + glong end = g_utf8_strlen(u8Str, backcolor->end_index); for (glong i=start; i < end; ++i) { - targetInput[i] = true; // target converted + indicator[i] = SC_INDICATOR_TARGET; // target converted } } } while (pango_attr_iterator_next(itercolor)); pango_attr_iterator_destroy(itercolor); } + return indicator; } void ScintillaGTK::SetCandidateWindowPos() { @@ -2401,23 +2400,13 @@ void ScintillaGTK::CommitThis(char *commitStr) { glong uniStrLen = 0; gunichar *uniStr = g_utf8_to_ucs4_fast(commitStr, strlen(commitStr), &uniStrLen); for (glong i = 0; i < uniStrLen; i++) { + gchar u8Char[UTF8MaxBytes+2] = {0}; + gint u8CharLen = g_unichar_to_utf8(uniStr[i], u8Char); + std::string docChar = u8Char; + if (!IsUnicodeMode()) + docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true); - gunichar uniChar[1] = {0}; - uniChar[0] = uniStr[i]; - - glong oneCharLen = 0; - gchar *oneChar = g_ucs4_to_utf8(uniChar, 1, NULL, &oneCharLen, NULL); - - if (IsUnicodeMode()) { - // Do nothing ; - } else { - std::string oneCharSTD = ConvertText(oneChar, oneCharLen, charSetSource, "UTF-8", true); - oneCharLen = oneCharSTD.copy(oneChar,oneCharSTD.length(), 0); - oneChar[oneCharLen] = '\0'; - } - - AddCharUTF(oneChar, oneCharLen); - g_free(oneChar); + AddCharUTF(docChar.c_str(), docChar.size()); } g_free(uniStr); ShowCaretAtCurrentPosition(); @@ -2434,6 +2423,11 @@ void ScintillaGTK::PreeditChangedInlineThis() { // Copy & paste by johnsonj with a lot of helps of Neil // Great thanks for my foreruners, jiniya and BLUEnLIVE try { + if (pdoc->IsReadOnly() || SelectionContainsProtected()) { + gtk_im_context_reset(im_context); + return; + } + view.imeCaretBlockOverride = false; // If backspace. if (pdoc->TentativeActive()) { @@ -2461,64 +2455,38 @@ void ScintillaGTK::PreeditChangedInlineThis() { pdoc->TentativeStart(); // TentativeActive() from now on // Get preedit string attribues - bool normalInput[maxLenInputIME*3+1] = {false}; - bool targetInput[maxLenInputIME*3+1] = {false}; - GetImeUnderlines(preeditStr.attrs, normalInput); - GetImeBackgrounds(preeditStr.attrs, targetInput); + std::vector indicator = MapImeIndicators(preeditStr.attrs, preeditStr.str); // Display preedit characters, one by one glong imeCharPos[maxLenInputIME+1] = { 0 }; - glong attrPos = -1; // Start at -1 to designate the last byte of one character. glong charWidth = 0; bool tmpRecordingMacro = recordingMacro; recordingMacro = false; for (glong i = 0; i < preeditStr.uniStrLen; i++) { + gchar u8Char[UTF8MaxBytes+2] = {0}; + gint u8CharLen = g_unichar_to_utf8(preeditStr.uniStr[i], u8Char); + std::string docChar = u8Char; + if (!IsUnicodeMode()) + docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true); - gunichar uniChar[1] = {0}; - uniChar[0] = preeditStr.uniStr[i]; - - glong oneCharLen = 0; - gchar *oneChar = g_ucs4_to_utf8(uniChar, 1, NULL, &oneCharLen, NULL); + AddCharUTF(docChar.c_str(), docChar.size()); - // Record attribute positions in UTF-8 bytes - attrPos += oneCharLen; - - if (IsUnicodeMode()) { - // Do nothing - } else { - std::string oneCharSTD = ConvertText(oneChar, oneCharLen, charSetSource, "UTF-8", true); - oneCharLen = oneCharSTD.copy(oneChar,oneCharSTD.length(), 0); - oneChar[oneCharLen] = '\0'; - } + // Draw an indicator on the character, + DrawImeIndicator(indicator[i], docChar.size()); // Record character positions in UTF-8 or DBCS bytes - - charWidth += oneCharLen; + charWidth += docChar.size(); imeCharPos[i+1] = charWidth; - - // Display one character - AddCharUTF(oneChar, oneCharLen); - - // Draw an indicator on the character, - // Overlapping allowed - if (normalInput[attrPos]) { - DrawImeIndicator(SC_INDICATOR_INPUT, oneCharLen); - } - if (targetInput[attrPos]) { - DrawImeIndicator(SC_INDICATOR_TARGET, oneCharLen); - } - g_free(oneChar); } recordingMacro = tmpRecordingMacro; // Move caret to ime cursor position. + MoveImeCarets( - (imeCharPos[preeditStr.uniStrLen]) + imeCharPos[preeditStr.cursor_pos]); + if (KoreanIME()) { + MoveImeCarets( - imeCharPos[1]); // always 2 bytes for DBCS or 3 bytes for UTF8. view.imeCaretBlockOverride = true; - MoveImeCarets( - (imeCharPos[preeditStr.uniStrLen])); - - } else { - MoveImeCarets( - (imeCharPos[preeditStr.uniStrLen]) + imeCharPos[preeditStr.cursor_pos]); } EnsureCaretVisible(); @@ -3077,28 +3045,34 @@ sptr_t ScintillaGTK::DirectFunction( return reinterpret_cast(ptr)->WndProc(iMessage, wParam, lParam); } +/* legacy name for scintilla_object_send_message */ GEANY_API_SYMBOL sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) { ScintillaGTK *psci = static_cast(sci->pscin); return psci->WndProc(iMessage, wParam, lParam); } +sptr_t scintilla_object_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) { + return scintilla_send_message(sci, iMessage, wParam, lParam); +} + static void scintilla_class_init(ScintillaClass *klass); static void scintilla_init(ScintillaObject *sci); extern void Platform_Initialise(); extern void Platform_Finalise(); +/* legacy name for scintilla_object_get_type */ GEANY_API_SYMBOL GType scintilla_get_type() { static GType scintilla_type = 0; try { if (!scintilla_type) { - scintilla_type = g_type_from_name("Scintilla"); + scintilla_type = g_type_from_name("ScintillaObject"); if (!scintilla_type) { static GTypeInfo scintilla_info = { - (guint16) sizeof (ScintillaClass), + (guint16) sizeof (ScintillaObjectClass), NULL, //(GBaseInitFunc) NULL, //(GBaseFinalizeFunc) (GClassInitFunc) scintilla_class_init, @@ -3109,9 +3083,8 @@ GType scintilla_get_type() { (GInstanceInitFunc) scintilla_init, NULL //(GTypeValueTable*) }; - scintilla_type = g_type_register_static( - GTK_TYPE_CONTAINER, "Scintilla", &scintilla_info, (GTypeFlags) 0); + GTK_TYPE_CONTAINER, "ScintillaObject", &scintilla_info, (GTypeFlags) 0); } } @@ -3120,6 +3093,10 @@ GType scintilla_get_type() { return scintilla_type; } +GType scintilla_object_get_type() { + return scintilla_get_type(); +} + void ScintillaGTK::ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_class, GtkContainerClass *container_class) { Platform_Initialise(); #ifdef SCI_LEXER @@ -3135,8 +3112,8 @@ void ScintillaGTK::ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_ // of the signal handlers here (those that currently attached to wDraw // in Initialise() may require coordinate translation?) - object_class->finalize = Destroy; object_class->dispose = Dispose; + object_class->finalize = Destroy; #if GTK_CHECK_VERSION(3,0,0) widget_class->get_preferred_width = GetPreferredWidth; widget_class->get_preferred_height = GetPreferredHeight; @@ -3224,6 +3201,7 @@ static void scintilla_init(ScintillaObject *sci) { } } +/* legacy name for scintilla_object_new */ GEANY_API_SYMBOL GtkWidget* scintilla_new() { GtkWidget *widget = GTK_WIDGET(g_object_new(scintilla_get_type(), NULL)); @@ -3232,6 +3210,10 @@ GtkWidget* scintilla_new() { return widget; } +GtkWidget *scintilla_object_new() { + return scintilla_new(); +} + void scintilla_set_id(ScintillaObject *sci, uptr_t id) { ScintillaGTK *psci = static_cast(sci->pscin); psci->ctrlID = id; diff --git a/scintilla/include/Platform.h b/scintilla/include/Platform.h index 4ef7e2aab..63269d003 100644 --- a/scintilla/include/Platform.h +++ b/scintilla/include/Platform.h @@ -145,7 +145,7 @@ public: (pt.y >= top) && (pt.y <= bottom); } bool ContainsWholePixel(Point pt) const { - // Does the rectangle contain all of the pixel to left/below the point + // Does the rectangle contain all of the pixel to left/below the point return (pt.x >= left) && ((pt.x+1) <= right) && (pt.y >= top) && ((pt.y+1) <= bottom); } diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index e3443409b..c985cea77 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -506,6 +506,12 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_WORDSTARTPOSITION 2266 #define SCI_WORDENDPOSITION 2267 #define SCI_ISRANGEWORD 2691 +#define SC_IDLESTYLING_NONE 0 +#define SC_IDLESTYLING_TOVISIBLE 1 +#define SC_IDLESTYLING_AFTERVISIBLE 2 +#define SC_IDLESTYLING_ALL 3 +#define SCI_SETIDLESTYLING 2692 +#define SCI_GETIDLESTYLING 2693 #define SC_WRAP_NONE 0 #define SC_WRAP_WORD 1 #define SC_WRAP_CHAR 2 diff --git a/scintilla/include/Scintilla.iface b/scintilla/include/Scintilla.iface index ad50a2aaf..91b3066b5 100644 --- a/scintilla/include/Scintilla.iface +++ b/scintilla/include/Scintilla.iface @@ -249,11 +249,11 @@ enu IMEInteraction=SC_IME_ val SC_IME_WINDOWED=0 val SC_IME_INLINE=1 -# Is the IME displayed in a winow or inline? +# Is the IME displayed in a window or inline? get int GetIMEInteraction=2678(,) # Choose to display the the IME in a winow or inline. -set void SetIMEInteraction=2679(int imeInteraction,) +set void SetIMEInteraction=2679(int imeInteraction,) enu MarkerSymbol=SC_MARK_ val MARKER_MAX=31 @@ -1260,6 +1260,18 @@ fun int WordEndPosition=2267(position pos, bool onlyWordCharacters) # Is the range start..end considered a word? fun bool IsRangeWord=2691(position start, position end) +enu IdleStyling=SC_IDLESTYLING_ +val SC_IDLESTYLING_NONE=0 +val SC_IDLESTYLING_TOVISIBLE=1 +val SC_IDLESTYLING_AFTERVISIBLE=2 +val SC_IDLESTYLING_ALL=3 + +# Sets limits to idle styling. +set void SetIdleStyling=2692(int idleStyling,) + +# Retrieve the limits to idle styling. +get int GetIdleStyling=2693(,) + enu Wrap=SC_WRAP_ val SC_WRAP_NONE=0 val SC_WRAP_WORD=1 @@ -1408,7 +1420,7 @@ val SC_MULTIPASTE_EACH=1 # Change the effect of pasting when there are multiple selections. set void SetMultiPaste=2614(int multiPaste,) -# Retrieve the effect of pasting when there are multiple selections.. +# Retrieve the effect of pasting when there are multiple selections. get int GetMultiPaste=2615(,) # Retrieve the value of a tag from a regular expression search. @@ -1977,7 +1989,7 @@ val SC_MULTIAUTOC_EACH=1 # Change the effect of autocompleting when there are multiple selections. set void AutoCSetMulti=2636(int multi,) -# Retrieve the effect of autocompleting when there are multiple selections.. +# Retrieve the effect of autocompleting when there are multiple selections. get int AutoCGetMulti=2637(,) enu Ordering=SC_ORDER_ diff --git a/scintilla/include/ScintillaWidget.h b/scintilla/include/ScintillaWidget.h index f8cd212b0..2c3d12dbe 100644 --- a/scintilla/include/ScintillaWidget.h +++ b/scintilla/include/ScintillaWidget.h @@ -1,8 +1,9 @@ /* Scintilla source code edit control */ -/** @file ScintillaWidget.h - ** Definition of Scintilla widget for GTK+. - ** Only needed by GTK+ code but is harmless on other platforms. - **/ +/* @file ScintillaWidget.h + * Definition of Scintilla widget for GTK+. + * Only needed by GTK+ code but is harmless on other platforms. + * This comment is not a doc-comment as that causes warnings from g-ir-scanner. + */ /* Copyright 1998-2001 by Neil Hodgson * The License.txt file describes the conditions under which this software may be distributed. */ @@ -19,8 +20,15 @@ extern "C" { #define SCINTILLA_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, scintilla_get_type (), ScintillaClass) #define IS_SCINTILLA(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, scintilla_get_type ()) +#define SCINTILLA_TYPE_OBJECT (scintilla_object_get_type()) +#define SCINTILLA_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SCINTILLA_TYPE_OBJECT, ScintillaObject)) +#define SCINTILLA_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SCINTILLA_TYPE_OBJECT)) +#define SCINTILLA_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SCINTILLA_TYPE_OBJECT, ScintillaObjectClass)) +#define SCINTILLA_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SCINTILLA_TYPE_OBJECT)) +#define SCINTILLA_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), SCINTILLA_TYPE_OBJECT, ScintillaObjectClass)) + typedef struct _ScintillaObject ScintillaObject; -typedef struct _ScintillaClass ScintillaClass; +typedef struct _ScintillaClass ScintillaObjectClass; struct _ScintillaObject { GtkContainer cont; @@ -34,11 +42,20 @@ struct _ScintillaClass { void (* notify) (ScintillaObject *ttt); }; +GType scintilla_object_get_type (void); +GtkWidget* scintilla_object_new (void); +long scintilla_object_send_message (ScintillaObject *sci, unsigned int iMessage, guintptr wParam, gintptr lParam); + +#ifndef G_IR_SCANNING +/* The legacy names confuse the g-ir-scanner program */ +typedef struct _ScintillaClass ScintillaClass; + GType scintilla_get_type (void); GtkWidget* scintilla_new (void); void scintilla_set_id (ScintillaObject *sci, uptr_t id); sptr_t scintilla_send_message (ScintillaObject *sci,unsigned int iMessage, uptr_t wParam, sptr_t lParam); void scintilla_release_resources(void); +#endif #define SCINTILLA_NOTIFY "sci-notify" diff --git a/scintilla/lexers/LexBash.cxx b/scintilla/lexers/LexBash.cxx index 21c47e577..af8507d7d 100644 --- a/scintilla/lexers/LexBash.cxx +++ b/scintilla/lexers/LexBash.cxx @@ -96,6 +96,19 @@ static int opposite(int ch) { return ch; } +static int GlobScan(StyleContext &sc) { + // forward scan for a glob-like (...), no whitespace allowed + int c, sLen = 0; + while ((c = sc.GetRelativeCharacter(++sLen)) != 0) { + if (IsASpace(c)) { + return 0; + } else if (c == ')') { + return sLen; + } + } + return 0; +} + static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], Accessor &styler) { @@ -113,9 +126,9 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in CharacterSet setBashOperator(CharacterSet::setNone, "^&%()-+=|{}[]:;>,*/ 1) { + sc.SetState(SCE_SH_IDENTIFIER); + sc.Forward(i); + continue; + } + } // handle opening delimiters for test/arithmetic expressions - ((,[[,[ if (cmdState == BASH_CMD_START || cmdState == BASH_CMD_BODY) { diff --git a/scintilla/lexers/LexCPP.cxx b/scintilla/lexers/LexCPP.cxx index 628672b9e..fc9b5b86b 100644 --- a/scintilla/lexers/LexCPP.cxx +++ b/scintilla/lexers/LexCPP.cxx @@ -374,7 +374,7 @@ struct OptionSetCPP : public OptionSet { DefineProperty("lexer.cpp.verbatim.strings.allow.escapes", &OptionsCPP::verbatimStringsAllowEscapes, "Set to 1 to allow verbatim strings to contain escape sequences."); - + DefineProperty("lexer.cpp.triplequoted.strings", &OptionsCPP::triplequotedStrings, "Set to 1 to enable highlighting of triple-quoted strings."); @@ -1467,7 +1467,7 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl } iMacro++; } - + // Insert results back into tokens tokens.insert(tokens.begin() + i, macroTokens.begin(), macroTokens.end()); @@ -1481,7 +1481,7 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl tokens.insert(tokens.begin() + i, macroTokens.begin(), macroTokens.end()); } } else { - // Identifier not found + // Identifier not found tokens.erase(tokens.begin() + i); } } else { diff --git a/scintilla/lexers/LexCaml.cxx b/scintilla/lexers/LexCaml.cxx index 593e05522..df8781541 100644 --- a/scintilla/lexers/LexCaml.cxx +++ b/scintilla/lexers/LexCaml.cxx @@ -112,7 +112,7 @@ long Platform::SendScintillaPointer(WindowID w, unsigned int msg, unsigned long void EXT_LEXER_DECL Fold(unsigned int lexer, Sci_PositionU startPos, Sci_Position length, int initStyle, char *words[], WindowID window, char *props) { - // below useless evaluation(s) to suppress "not used" warnings + // below useless evaluation(s) to supress "not used" warnings lexer; // build expected data structures and do the Fold InternalLexOrFold(1, startPos, length, initStyle, words, window, props); @@ -126,7 +126,7 @@ int EXT_LEXER_DECL GetLexerCount() void EXT_LEXER_DECL GetLexerName(unsigned int Index, char *name, int buflength) { - // below useless evaluation(s) to suppress "not used" warnings + // below useless evaluation(s) to supress "not used" warnings Index; // return as much of our lexer name as will fit (what's up with Index?) if (buflength > 0) { @@ -141,7 +141,7 @@ void EXT_LEXER_DECL GetLexerName(unsigned int Index, char *name, int buflength) void EXT_LEXER_DECL Lex(unsigned int lexer, Sci_PositionU startPos, Sci_Position length, int initStyle, char *words[], WindowID window, char *props) { - // below useless evaluation(s) to suppress "not used" warnings + // below useless evaluation(s) to supress "not used" warnings lexer; // build expected data structures and do the Lex InternalLexOrFold(0, startPos, length, initStyle, words, window, props); diff --git a/scintilla/lexers/LexCmake.cxx b/scintilla/lexers/LexCmake.cxx index 148ace697..1cbca3611 100644 --- a/scintilla/lexers/LexCmake.cxx +++ b/scintilla/lexers/LexCmake.cxx @@ -54,7 +54,7 @@ static bool CmakeNextLineHasElse(Sci_PositionU start, Sci_PositionU end, Accesso } } - if ( nNextLine == -1 ) // We never found the next line... + if ( nNextLine == -1 ) // We never foudn the next line... return false; for ( Sci_PositionU firstChar = nNextLine; firstChar < end; firstChar++ ) { diff --git a/scintilla/lexers/LexLaTeX.cxx b/scintilla/lexers/LexLaTeX.cxx index 7e03a9c4c..6dc0617e1 100644 --- a/scintilla/lexers/LexLaTeX.cxx +++ b/scintilla/lexers/LexLaTeX.cxx @@ -60,7 +60,7 @@ private: if (static_cast(modes.size()) > numLines * 2 + 256) modes.resize(numLines + 128); } - + vector saves; void setSave(Sci_Position line, const latexFoldSave &save) { if (line >= static_cast(saves.size())) saves.resize(line + 1); @@ -192,7 +192,7 @@ void SCI_METHOD LexerLaTeX::Lex(Sci_PositionU startPos, Sci_Position length, int int state = initStyle; if (state == SCE_L_ERROR || state == SCE_L_SHORTCMD || state == SCE_L_SPECIAL) // should not happen latexStateReset(mode, state); - + char chNext = styler.SafeGetCharAt(startPos); char chVerbatimDelim = '\0'; styler.StartSegment(startPos); @@ -207,7 +207,7 @@ void SCI_METHOD LexerLaTeX::Lex(Sci_PositionU startPos, Sci_Position length, int chNext = styler.SafeGetCharAt(i + 1); continue; } - + if (ch == '\r' || ch == '\n') setMode(styler.GetLine(i), mode); @@ -256,7 +256,7 @@ void SCI_METHOD LexerLaTeX::Lex(Sci_PositionU startPos, Sci_Position length, int state = SCE_L_COMMENT; break; } - break; + break; // These 3 will never be reached. case SCE_L_ERROR: case SCE_L_SPECIAL: @@ -400,7 +400,7 @@ void SCI_METHOD LexerLaTeX::Lex(Sci_PositionU startPos, Sci_Position length, int chNext = styler.SafeGetCharAt(i + 1); mode = 0; state = SCE_L_DEFAULT; - } else { // This may not be an error, e.g. \begin{equation}\text{$a$}\end{equation} + } else { // This may not be an error, e.g. \begin{equation}\text{$a$}\end{equation} styler.ColourTo(i, SCE_L_SHORTCMD); } break; diff --git a/scintilla/lexers/LexLua.cxx b/scintilla/lexers/LexLua.cxx index b62e69a35..1e115ad18 100644 --- a/scintilla/lexers/LexLua.cxx +++ b/scintilla/lexers/LexLua.cxx @@ -64,7 +64,7 @@ static void ColouriseLuaDoc( // but probably enough in most cases. [pP] is for hex floats. CharacterSet setNumber(CharacterSet::setDigits, ".-+abcdefpABCDEFP"); CharacterSet setExponent(CharacterSet::setNone, "eEpP"); - CharacterSet setLuaOperator(CharacterSet::setNone, "*/-+()={}~[];<>,.^%:#"); + CharacterSet setLuaOperator(CharacterSet::setNone, "*/-+()={}~[];<>,.^%:#&|"); CharacterSet setEscapeSkip(CharacterSet::setNone, "\"'\\"); Sci_Position currentLine = styler.GetLine(startPos); diff --git a/scintilla/lexers/LexMatlab.cxx b/scintilla/lexers/LexMatlab.cxx index 563b31b46..6b4b2a92a 100644 --- a/scintilla/lexers/LexMatlab.cxx +++ b/scintilla/lexers/LexMatlab.cxx @@ -67,7 +67,7 @@ static void ColouriseMatlabOctaveDoc( styler.StartAt(startPos); - // boolean for when the ' is allowed to be transpose vs the start/end + // boolean for when the ' is allowed to be transpose vs the start/end // of a string bool transpose = false; @@ -86,13 +86,13 @@ static void ColouriseMatlabOctaveDoc( for (; sc.More(); sc.Forward(), column++) { if(sc.atLineStart) { - // set the line state to the current commentDepth + // set the line state to the current commentDepth curLine = styler.GetLine(sc.currentPos); styler.SetLineState(curLine, commentDepth); // reset the column to 0, nonSpace to -1 (not set) column = 0; - nonSpaceColumn = -1; + nonSpaceColumn = -1; } // save the column position of first non space character in a line @@ -111,7 +111,7 @@ static void ColouriseMatlabOctaveDoc( sc.ForwardSetState(SCE_MATLAB_DEFAULT); transpose = true; } else if(sc.ch == '.' && sc.chNext == '.') { - // we werent an operator, but a '...' + // we werent an operator, but a '...' sc.ChangeState(SCE_MATLAB_COMMENT); transpose = false; } else { @@ -165,7 +165,7 @@ static void ColouriseMatlabOctaveDoc( // end or start of a nested a block comment? if( IsCommentChar(sc.ch) && sc.chNext == '}' && nonSpaceColumn == column) { if(commentDepth > 0) commentDepth --; - + curLine = styler.GetLine(sc.currentPos); styler.SetLineState(curLine, commentDepth); sc.Forward(); diff --git a/scintilla/lexers/LexPO.cxx b/scintilla/lexers/LexPO.cxx index 61e601126..fcf886d6c 100644 --- a/scintilla/lexers/LexPO.cxx +++ b/scintilla/lexers/LexPO.cxx @@ -41,7 +41,7 @@ static void ColourisePODoc(Sci_PositionU startPos, Sci_Position length, int init Sci_Position curLine = styler.GetLine(startPos); // the line state holds the last state on or before the line that isn't the default style int curLineState = curLine > 0 ? styler.GetLineState(curLine - 1) : SCE_PO_DEFAULT; - + for (; sc.More(); sc.Forward()) { // whether we should leave a state switch (sc.state) { @@ -57,19 +57,19 @@ static void ColourisePODoc(Sci_PositionU startPos, Sci_Position length, int init // on its own like a keyword rather than changing the whole flags style sc.ChangeState(SCE_PO_FUZZY); break; - + case SCE_PO_MSGCTXT: case SCE_PO_MSGID: case SCE_PO_MSGSTR: if (isspacechar(sc.ch)) sc.SetState(SCE_PO_DEFAULT); break; - + case SCE_PO_ERROR: if (sc.atLineEnd) sc.SetState(SCE_PO_DEFAULT); break; - + case SCE_PO_MSGCTXT_TEXT: case SCE_PO_MSGID_TEXT: case SCE_PO_MSGSTR_TEXT: @@ -92,7 +92,7 @@ static void ColourisePODoc(Sci_PositionU startPos, Sci_Position length, int init } break; } - + // whether we should enter a new state if (sc.state == SCE_PO_DEFAULT) { // forward to the first non-white character on the line @@ -103,11 +103,11 @@ static void ColourisePODoc(Sci_PositionU startPos, Sci_Position length, int init // and anyway the styling don't use line state for comments if (curLineState == SCE_PO_COMMENT) curLineState = SCE_PO_DEFAULT; - + while (sc.More() && ! sc.atLineEnd && isspacechar(sc.ch)) sc.Forward(); } - + if (atLineStart && sc.ch == '#') { if (sc.chNext == '.') sc.SetState(SCE_PO_PROGRAMMER_COMMENT); @@ -134,11 +134,11 @@ static void ColourisePODoc(Sci_PositionU startPos, Sci_Position length, int init sc.SetState(SCE_PO_ERROR); } else if (! isspacechar(sc.ch)) sc.SetState(SCE_PO_ERROR); - + if (sc.state != SCE_PO_DEFAULT) curLineState = sc.state; } - + if (sc.atLineEnd) { // Update the line state, so it can be seen by next line curLine = styler.GetLine(sc.currentPos); @@ -163,7 +163,7 @@ static void FoldPODoc(Sci_PositionU startPos, Sci_Position length, int, WordList return; bool foldCompact = styler.GetPropertyInt("fold.compact") != 0; bool foldComment = styler.GetPropertyInt("fold.comment") != 0; - + Sci_PositionU endPos = startPos + length; Sci_Position curLine = styler.GetLine(startPos); int lineState = styler.GetLineState(curLine); @@ -172,17 +172,17 @@ static void FoldPODoc(Sci_PositionU startPos, Sci_Position length, int, WordList int nextLevel; int visible = 0; int chNext = styler[startPos]; - + for (Sci_PositionU i = startPos; i < endPos; i++) { int ch = chNext; chNext = styler.SafeGetCharAt(i+1); - + if (! isspacechar(ch)) { visible++; } else if ((ch == '\r' && chNext != '\n') || ch == '\n' || i+1 >= endPos) { int lvl = level; Sci_Position nextLine = curLine + 1; - + nextLineState = styler.GetLineState(nextLine); if ((lineState != SCE_PO_COMMENT || foldComment) && nextLineState == lineState && @@ -190,14 +190,14 @@ static void FoldPODoc(Sci_PositionU startPos, Sci_Position length, int, WordList nextLevel = SC_FOLDLEVELBASE + 1; else nextLevel = SC_FOLDLEVELBASE; - + if (nextLevel > level) lvl |= SC_FOLDLEVELHEADERFLAG; if (visible == 0 && foldCompact) lvl |= SC_FOLDLEVELWHITEFLAG; - + styler.SetLevel(curLine, lvl); - + lineState = nextLineState; curLine = nextLine; level = nextLevel; diff --git a/scintilla/lexers/LexPerl.cxx b/scintilla/lexers/LexPerl.cxx index df6cc9d3e..3b10b47e6 100644 --- a/scintilla/lexers/LexPerl.cxx +++ b/scintilla/lexers/LexPerl.cxx @@ -52,10 +52,10 @@ using namespace Scintilla; #define HERE_DELIM_MAX 256 // maximum length of HERE doc delimiter -#define PERLNUM_BINARY 1 // order is significant: 1-4 cannot have a dot -#define PERLNUM_HEX 2 -#define PERLNUM_OCTAL 3 -#define PERLNUM_FLOAT_EXP 4 // exponent part only +#define PERLNUM_BINARY 1 // order is significant: 1-3 cannot have a dot +#define PERLNUM_OCTAL 2 +#define PERLNUM_FLOAT_EXP 3 // exponent part only +#define PERLNUM_HEX 4 // may be a hex float #define PERLNUM_DECIMAL 5 // 1-5 are numbers; 6-7 are strings #define PERLNUM_VECTOR 6 #define PERLNUM_V_VECTOR 7 @@ -65,6 +65,12 @@ using namespace Scintilla; #define BACK_OPERATOR 1 // whitespace/comments are insignificant #define BACK_KEYWORD 2 // operators/keywords are needed for disambiguation +#define SUB_BEGIN 0 // states for subroutine prototype scan: +#define SUB_HAS_PROTO 1 // only 'prototype' attribute allows prototypes +#define SUB_HAS_ATTRIB 2 // other attributes can exist leftward +#define SUB_HAS_MODULE 3 // sub name can have a ::identifier part +#define SUB_HAS_SUB 4 // 'sub' keyword + // all interpolated styles are different from their parent styles by a constant difference // we also assume SCE_PL_STRING_VAR is the interpolated style with the smallest value #define INTERPOLATE_SHIFT (SCE_PL_STRING_VAR - SCE_PL_STRING) @@ -105,9 +111,11 @@ static int disambiguateBareword(LexAccessor &styler, Sci_PositionU bk, Sci_Posit // &bareword: subroutine call || styler.Match(bk - 1, "->") // ->bareword: part of variable spec + || styler.Match(bk - 1, "::") + // ::bareword: part of module spec || styler.Match(bk - 2, "sub")) { - // sub bareword: subroutine declaration - // (implied BACK_KEYWORD, no keywords end in 'sub'!) + // sub bareword: subroutine declaration + // (implied BACK_KEYWORD, no keywords end in 'sub'!) result |= 1; } // next, scan forward after word past tab/spaces only; @@ -121,7 +129,7 @@ static int disambiguateBareword(LexAccessor &styler, Sci_PositionU bk, Sci_Posit if ((ch == '}' && brace) // {bareword}: variable spec || styler.Match(fw, "=>")) { - // [{(, bareword=>: hash literal + // [{(, bareword=>: hash literal result |= 2; } } @@ -136,6 +144,22 @@ static void skipWhitespaceComment(LexAccessor &styler, Sci_PositionU &p) { p--; } +static int findPrevLexeme(LexAccessor &styler, Sci_PositionU &bk, int &style) { + // scan backward past whitespace and comments to find a lexeme + skipWhitespaceComment(styler, bk); + if (bk == 0) + return 0; + int sz = 1; + style = styler.StyleAt(bk); + while (bk > 0) { // find extent of lexeme + if (styler.StyleAt(bk - 1) == style) { + bk--; sz++; + } else + break; + } + return sz; +} + static int styleBeforeBracePair(LexAccessor &styler, Sci_PositionU bk) { // backtrack to find open '{' corresponding to a '}', balanced // return significant style to be tested for '/' disambiguation @@ -214,20 +238,59 @@ static int podLineScan(LexAccessor &styler, Sci_PositionU &pos, Sci_PositionU en static bool styleCheckSubPrototype(LexAccessor &styler, Sci_PositionU bk) { // backtrack to identify if we're starting a subroutine prototype - // we also need to ignore whitespace/comments: - // 'sub' [whitespace|comment] [whitespace|comment] + // we also need to ignore whitespace/comments, format is like: + // sub abc::pqr :const :prototype(...) + // lexemes are tested in pairs, e.g. '::'+'pqr', ':'+'const', etc. + // and a state machine generates legal subroutine syntax matches styler.Flush(); - skipWhitespaceComment(styler, bk); - if (bk == 0 || styler.StyleAt(bk) != SCE_PL_IDENTIFIER) // check identifier - return false; - while (bk > 0 && (styler.StyleAt(bk) == SCE_PL_IDENTIFIER)) { - bk--; - } - skipWhitespaceComment(styler, bk); - if (bk < 2 || styler.StyleAt(bk) != SCE_PL_WORD // check "sub" keyword - || !styler.Match(bk - 2, "sub")) // assume suffix is unique! - return false; - return true; + int state = SUB_BEGIN; + do { + // find two lexemes, lexeme 2 follows lexeme 1 + int style2 = SCE_PL_DEFAULT; + Sci_PositionU pos2 = bk; + int len2 = findPrevLexeme(styler, pos2, style2); + int style1 = SCE_PL_DEFAULT; + Sci_PositionU pos1 = pos2; + if (pos1 > 0) pos1--; + int len1 = findPrevLexeme(styler, pos1, style1); + if (len1 == 0 || len2 == 0) // lexeme pair must exist + break; + + // match parts of syntax, if invalid subroutine syntax, break off + if (style1 == SCE_PL_OPERATOR && len1 == 1 && + styler.SafeGetCharAt(pos1) == ':') { // ':' + if (style2 == SCE_PL_IDENTIFIER || style2 == SCE_PL_WORD) { + if (len2 == 9 && styler.Match(pos2, "prototype")) { // ':' 'prototype' + if (state == SUB_BEGIN) { + state = SUB_HAS_PROTO; + } else + break; + } else { // ':' + if (state == SUB_HAS_PROTO || state == SUB_HAS_ATTRIB) { + state = SUB_HAS_ATTRIB; + } else + break; + } + } else + break; + } else if (style1 == SCE_PL_OPERATOR && len1 == 2 && + styler.Match(pos1, "::")) { // '::' + if (style2 == SCE_PL_IDENTIFIER) { // '::' + state = SUB_HAS_MODULE; + } else + break; + } else if (style1 == SCE_PL_WORD && len1 == 3 && + styler.Match(pos1, "sub")) { // 'sub' + if (style2 == SCE_PL_IDENTIFIER) { // 'sub' + state = SUB_HAS_SUB; + } else + break; + } else + break; + bk = pos1; // set position for finding next lexeme pair + if (bk > 0) bk--; + } while (state != SUB_HAS_SUB); + return (state == SUB_HAS_SUB); } static int actualNumStyle(int numberStyle) { @@ -537,7 +600,8 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int CharacterSet &setPOD = setModifiers; CharacterSet setNonHereDoc(CharacterSet::setDigits, "=$@"); CharacterSet setHereDocDelim(CharacterSet::setAlphaNum, "_"); - CharacterSet setSubPrototype(CharacterSet::setNone, "\\[$@%&*+];"); + CharacterSet setSubPrototype(CharacterSet::setNone, "\\[$@%&*+];_ \t"); + CharacterSet setRepetition(CharacterSet::setDigits, ")\"'"); // for format identifiers CharacterSet setFormatStart(CharacterSet::setAlpha, "_="); CharacterSet &setFormat = setHereDocDelim; @@ -555,13 +619,12 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int int Quote; // the char after '<<' bool Quoted; // true if Quote in ('\'','"','`') int DelimiterLength; // strlen(Delimiter) - char *Delimiter; // the Delimiter, 256: sizeof PL_tokenbuf + char Delimiter[HERE_DELIM_MAX]; // the Delimiter HereDocCls() { State = 0; Quote = 0; Quoted = false; DelimiterLength = 0; - Delimiter = new char[HERE_DELIM_MAX]; Delimiter[0] = '\0'; } void Append(int ch) { @@ -569,7 +632,6 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int Delimiter[DelimiterLength] = '\0'; } ~HereDocCls() { - delete []Delimiter; } }; HereDocCls HereDoc; // TODO: FIFO for stacked here-docs @@ -762,6 +824,14 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int break; } // number then dot (go through) + } else if (numState == PERLNUM_HEX) { + if (dotCount <= 1 && IsADigit(sc.chNext, 16)) { + break; // hex with one dot is a hex float + } else { + sc.SetState(SCE_PL_OPERATOR); + break; + } + // hex then dot (go through) } else if (IsADigit(sc.chNext)) // vectors break; // vector then dot (go through) @@ -780,8 +850,15 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int break; // number then word (go through) } else if (numState == PERLNUM_HEX) { - if (IsADigit(sc.ch, 16)) + if (sc.ch == 'P' || sc.ch == 'p') { // hex float exponent, sign + numState = PERLNUM_FLOAT_EXP; + if (sc.chNext == '+' || sc.chNext == '-') { + sc.Forward(); + } + break; + } else if (IsADigit(sc.ch, 16)) break; + // hex or hex float then word (go through) } else if (numState == PERLNUM_VECTOR || numState == PERLNUM_V_VECTOR) { if (IsADigit(sc.ch)) // vector break; @@ -1265,7 +1342,7 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int fw++; } else if (sc.ch == 'x' && (sc.chNext == '=' || // repetition !setWord.Contains(sc.chNext) || - (IsADigit(sc.chPrev) && IsADigit(sc.chNext)))) { + (setRepetition.Contains(sc.chPrev) && IsADigit(sc.chNext)))) { sc.ChangeState(SCE_PL_OPERATOR); } // if potentially a keyword, scan forward and grab word, then check @@ -1438,7 +1515,10 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int } backFlag = BACK_NONE; if (isHereDoc) { // handle '<<', HERE doc - if (preferRE) { + if (sc.Match("<<>>")) { // double-diamond operator (5.22) + sc.SetState(SCE_PL_OPERATOR); + sc.Forward(3); + } else if (preferRE) { sc.SetState(SCE_PL_HERE_DELIM); HereDoc.State = 0; } else { // << operator diff --git a/scintilla/lexers/LexRust.cxx b/scintilla/lexers/LexRust.cxx index f98296bb3..ca5f3c7f1 100644 --- a/scintilla/lexers/LexRust.cxx +++ b/scintilla/lexers/LexRust.cxx @@ -287,7 +287,7 @@ static void ScanNumber(Accessor& styler, Sci_Position& pos) { } else if (!error) { /* If there's a period, it's a floating point literal unless it's * followed by an identifier (meaning this is a method call, e.g. - * `1.foo()`) or another period, in which case it's a range (e.g. 1..2) + * `1.foo()`) or another period, in which case it's a range (e.g. 1..2) */ n = styler.SafeGetCharAt(pos + 1, '\0'); if (c == '.' && !(IsIdentifierStart(n) || n == '.')) { @@ -308,7 +308,7 @@ static void ScanNumber(Accessor& styler, Sci_Position& pos) { /* It is invalid to have no digits in the exponent. */ error |= !ScanDigits(styler, pos, 10); } - + /* Scan the floating point suffix. */ c = styler.SafeGetCharAt(pos, '\0'); if (c == 'f') { @@ -620,7 +620,7 @@ static void ResumeRawString(Accessor &styler, Sci_Position& pos, Sci_Position ma } else if (pos >= max) { break; } else { - if (ascii_only && !IsASCII((char)c)) + if (ascii_only && !IsASCII((char)c)) break; pos++; } diff --git a/scintilla/lexers/LexSQL.cxx b/scintilla/lexers/LexSQL.cxx index 34b601fba..1d0091806 100644 --- a/scintilla/lexers/LexSQL.cxx +++ b/scintilla/lexers/LexSQL.cxx @@ -567,8 +567,8 @@ void SCI_METHOD LexerSQL::Lex(Sci_PositionU startPos, Sci_Position length, int i break; } } - - char qComplement = 0x00; + + char qComplement = 0x00; if (qOperator == '<') { qComplement = '>'; @@ -580,8 +580,8 @@ void SCI_METHOD LexerSQL::Lex(Sci_PositionU startPos, Sci_Position length, int i qComplement = ']'; } else { qComplement = qOperator; - } - + } + if (sc.Match(qComplement, '\'')) { sc.Forward(); sc.ForwardSetState(SCE_SQL_DEFAULT); @@ -592,7 +592,7 @@ void SCI_METHOD LexerSQL::Lex(Sci_PositionU startPos, Sci_Position length, int i // Determine if a new state should be entered. if (sc.state == SCE_SQL_DEFAULT) { if (sc.Match('q', '\'') || sc.Match('Q', '\'')) { - sc.SetState(SCE_SQL_QOPERATOR); + sc.SetState(SCE_SQL_QOPERATOR); sc.Forward(); } else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext)) || ((sc.ch == '-' || sc.ch == '+') && IsADigit(sc.chNext) && !IsADigit(sc.chPrev))) { diff --git a/scintilla/scintilla_changes.patch b/scintilla/scintilla_changes.patch index 49cd91892..bac740cae 100644 --- a/scintilla/scintilla_changes.patch +++ b/scintilla/scintilla_changes.patch @@ -4,26 +4,26 @@ diff --git scintilla/gtk/ScintillaGTK.cxx scintilla/gtk/ScintillaGTK.cxx index 0871ca2..49dc278 100644 --- scintilla/gtk/ScintillaGTK.cxx +++ scintilla/gtk/ScintillaGTK.cxx -@@ -3104,6 +3104,7 @@ sptr_t ScintillaGTK::DirectFunction( - return reinterpret_cast(ptr)->WndProc(iMessage, wParam, lParam); +@@ -3046,6 +3046,7 @@ sptr_t ScintillaGTK::DirectFunction( } + /* legacy name for scintilla_object_send_message */ +GEANY_API_SYMBOL sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) { ScintillaGTK *psci = static_cast(sci->pscin); return psci->WndProc(iMessage, wParam, lParam); -@@ -3115,6 +3116,7 @@ static void scintilla_init(ScintillaObject *sci); - extern void Platform_Initialise(); +@@ -3062,6 +3062,7 @@ extern void Platform_Initialise(); extern void Platform_Finalise(); + /* legacy name for scintilla_object_get_type */ +GEANY_API_SYMBOL GType scintilla_get_type() { static GType scintilla_type = 0; try { -@@ -3252,6 +3254,7 @@ static void scintilla_init(ScintillaObject *sci) { - } +@@ -3200,6 +3200,7 @@ static void scintilla_init(ScintillaObject *sci) { } + /* legacy name for scintilla_object_new */ +GEANY_API_SYMBOL GtkWidget* scintilla_new() { GtkWidget *widget = GTK_WIDGET(g_object_new(scintilla_get_type(), NULL)); @@ -57,10 +57,10 @@ index be57b7c..cee3e73 100644 { typedef void (*GMarshalFunc_VOID__INT_POINTER) (gpointer data1, diff --git scintilla/src/Catalogue.cxx scintilla/src/Catalogue.cxx -index b02a010..400d423 100644 +index ed47aa8..e58f1ab 100644 --- scintilla/src/Catalogue.cxx +++ scintilla/src/Catalogue.cxx -@@ -76,120 +76,50 @@ int Scintilla_LinkLexers() { +@@ -77,120 +77,50 @@ int Scintilla_LinkLexers() { //++Autogenerated -- run scripts/LexGen.py to regenerate //**\(\tLINK_LEXER(\*);\n\) diff --git a/scintilla/src/CellBuffer.cxx b/scintilla/src/CellBuffer.cxx index f43a0c302..6ad990a63 100644 --- a/scintilla/src/CellBuffer.cxx +++ b/scintilla/src/CellBuffer.cxx @@ -496,6 +496,25 @@ void CellBuffer::SetLineEndTypes(int utf8LineEnds_) { } } +bool CellBuffer::ContainsLineEnd(const char *s, int length) const { + unsigned char chBeforePrev = 0; + unsigned char chPrev = 0; + for (int i = 0; i < length; i++) { + const unsigned char ch = s[i]; + if ((ch == '\r') || (ch == '\n')) { + return true; + } else if (utf8LineEnds) { + unsigned char back3[3] = { chBeforePrev, chPrev, ch }; + if (UTF8IsSeparator(back3) || UTF8IsNEL(back3 + 1)) { + return true; + } + } + chBeforePrev = chPrev; + chPrev = ch; + } + return false; +} + void CellBuffer::SetPerLine(PerLine *pl) { lv.SetPerLine(pl); } diff --git a/scintilla/src/CellBuffer.h b/scintilla/src/CellBuffer.h index 5e4fc7c8c..1c53d14e6 100644 --- a/scintilla/src/CellBuffer.h +++ b/scintilla/src/CellBuffer.h @@ -177,6 +177,7 @@ public: void Allocate(int newSize); int GetLineEndTypes() const { return utf8LineEnds; } void SetLineEndTypes(int utf8LineEnds_); + bool ContainsLineEnd(const char *s, int length) const; void SetPerLine(PerLine *pl); int Lines() const; int LineStart(int line) const; diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index 9201e162f..b0744a21c 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -109,6 +109,7 @@ Document::Document() { useTabs = true; tabIndents = true; backspaceUnindents = false; + durationStyleOneLine = 0.00001; matchesValid = false; regex = 0; @@ -270,7 +271,7 @@ void Document::TentativeUndo() { bool endSavePoint = cb.IsSavePoint(); if (startSavePoint != endSavePoint) NotifySavePoint(endSavePoint); - + cb.TentativeCommit(); } enteredModification--; @@ -1276,7 +1277,7 @@ int Document::SetLineIndentation(int line, int indent) { int indentPos = GetLineIndentPosition(line); UndoGroup ug(this); DeleteChars(thisLineStart, indentPos - thisLineStart); - return thisLineStart + InsertString(thisLineStart, linebuf.c_str(), + return thisLineStart + InsertString(thisLineStart, linebuf.c_str(), static_cast(linebuf.length())); } else { return GetLineIndentPosition(line); @@ -1892,6 +1893,33 @@ void Document::EnsureStyledTo(int pos) { } } +void Document::StyleToAdjustingLineDuration(int pos) { + // Place bounds on the duration used to avoid glitches spiking it + // and so causing slow styling or non-responsive scrolling + const double minDurationOneLine = 0.000001; + const double maxDurationOneLine = 0.0001; + + // Alpha value for exponential smoothing. + // Most recent value contributes 25% to smoothed value. + const double alpha = 0.25; + + const Sci_Position lineFirst = LineFromPosition(GetEndStyled()); + ElapsedTime etStyling; + EnsureStyledTo(pos); + const double durationStyling = etStyling.Duration(); + const Sci_Position lineLast = LineFromPosition(GetEndStyled()); + if (lineLast >= lineFirst + 8) { + // Only adjust for styling multiple lines to avoid instability + const double durationOneLine = durationStyling / (lineLast - lineFirst); + durationStyleOneLine = alpha * durationOneLine + (1.0 - alpha) * durationStyleOneLine; + if (durationStyleOneLine < minDurationOneLine) { + durationStyleOneLine = minDurationOneLine; + } else if (durationStyleOneLine > maxDurationOneLine) { + durationStyleOneLine = maxDurationOneLine; + } + } +} + void Document::LexerChanged() { // Tell the watchers the lexer has changed. for (std::vector::iterator it = watchers.begin(); it != watchers.end(); ++it) { @@ -2187,7 +2215,7 @@ int Document::BraceMatch(int position, int /*maxReStyle*/) { char chSeek = BraceOpposite(chBrace); if (chSeek == '\0') return - 1; - char styBrace = static_cast(StyleAt(position)); + const int styBrace = StyleIndexAt(position); int direction = -1; if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<') direction = 1; @@ -2195,7 +2223,7 @@ int Document::BraceMatch(int position, int /*maxReStyle*/) { position = NextPosition(position, direction); while ((position >= 0) && (position < Length())) { char chAtPos = CharAt(position); - char styAtPos = static_cast(StyleAt(position)); + const int styAtPos = StyleIndexAt(position); if ((position > GetEndStyled()) || (styAtPos == styBrace)) { if (chAtPos == chBrace) depth++; @@ -2526,10 +2554,10 @@ public: return doc != other.doc || position != other.position; } int Pos() const { - return position; + return position; } int PosRoundUp() const { - return position; + return position; } }; @@ -2626,7 +2654,7 @@ long Cxx11RegexFindText(Document *doc, int minPos, int maxPos, const char *s, std::wregex regexp; #if defined(__APPLE__) // Using a UTF-8 locale doesn't change to Unicode over a byte buffer so '.' - // is one byte not one character. + // is one byte not one character. // However, on OS X this makes wregex act as Unicode std::locale localeU("en_US.UTF-8"); regexp.imbue(localeU); diff --git a/scintilla/src/Document.h b/scintilla/src/Document.h index ea8ddfbed..cc3873f59 100644 --- a/scintilla/src/Document.h +++ b/scintilla/src/Document.h @@ -246,6 +246,7 @@ public: bool useTabs; bool tabIndents; bool backspaceUnindents; + double durationStyleOneLine; DecorationList decorations; @@ -272,6 +273,7 @@ public: Sci_Position SCI_METHOD LineFromPosition(Sci_Position pos) const; int ClampPositionIntoDocument(int pos) const; + bool ContainsLineEnd(const char *s, int length) const { return cb.ContainsLineEnd(s, length); } bool IsCrLf(int pos) const; int LenChar(int pos); bool InGoodUTF8(int pos, int &start, int &end) const; @@ -339,6 +341,7 @@ public: cb.GetCharRange(buffer, position, lengthRetrieve); } char SCI_METHOD StyleAt(Sci_Position position) const { return cb.StyleAt(position); } + int StyleIndexAt(Sci_Position position) const { return static_cast(cb.StyleAt(position)); } void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const { cb.GetStyleRange(buffer, position, lengthRetrieve); } @@ -375,7 +378,7 @@ public: struct CharacterExtracted { unsigned int character; unsigned int widthBytes; - CharacterExtracted(unsigned int character_, unsigned int widthBytes_) : + CharacterExtracted(unsigned int character_, unsigned int widthBytes_) : character(character_), widthBytes(widthBytes_) { } }; @@ -400,6 +403,7 @@ public: bool SCI_METHOD SetStyles(Sci_Position length, const char *styles); int GetEndStyled() const { return endStyled; } void EnsureStyledTo(int pos); + void StyleToAdjustingLineDuration(int pos); void LexerChanged(); int GetStyleClock() const { return styleClock; } void IncrementStyleClock(); @@ -425,7 +429,7 @@ public: void AnnotationSetStyles(int line, const unsigned char *styles); int AnnotationLines(int line) const; void AnnotationClearAll(); - + bool AddWatcher(DocWatcher *watcher, void *userData); bool RemoveWatcher(DocWatcher *watcher, void *userData); diff --git a/scintilla/src/EditModel.h b/scintilla/src/EditModel.h index 33c1ac0df..021bf6770 100644 --- a/scintilla/src/EditModel.h +++ b/scintilla/src/EditModel.h @@ -42,7 +42,7 @@ public: Selection sel; bool primarySelection; - enum IMEInteraction { imeWindowed, imeInline } imeInteraction; + enum IMEInteraction { imeWindowed, imeInline } imeInteraction; int foldFlags; ContractionState cs; diff --git a/scintilla/src/EditView.cxx b/scintilla/src/EditView.cxx index 04b94a815..fc98c3d6d 100644 --- a/scintilla/src/EditView.cxx +++ b/scintilla/src/EditView.cxx @@ -376,14 +376,14 @@ void EditView::LayoutLine(const EditModel &model, int line, Surface *surface, co // See if chars, styles, indicators, are all the same bool allSame = true; // Check base line layout - char styleByte = 0; + int styleByte = 0; int numCharsInLine = 0; while (numCharsInLine < lineLength) { int charInDoc = numCharsInLine + posLineStart; char chDoc = model.pdoc->CharAt(charInDoc); - styleByte = model.pdoc->StyleAt(charInDoc); + styleByte = model.pdoc->StyleIndexAt(charInDoc); allSame = allSame && - (ll->styles[numCharsInLine] == static_cast(styleByte)); + (ll->styles[numCharsInLine] == styleByte); if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseMixed) allSame = allSame && (ll->chars[numCharsInLine] == chDoc); @@ -394,7 +394,7 @@ void EditView::LayoutLine(const EditModel &model, int line, Surface *surface, co allSame = allSame && (ll->chars[numCharsInLine] == static_cast(toupper(chDoc))); else { // Style::caseCamel - if ((model.pdoc->WordCharClass(ll->chars[numCharsInLine]) == CharClassify::ccWord) && + if ((model.pdoc->WordCharClass(ll->chars[numCharsInLine]) == CharClassify::ccWord) && ((numCharsInLine == 0) || (model.pdoc->WordCharClass(ll->chars[numCharsInLine - 1]) != CharClassify::ccWord))) { allSame = allSame && (ll->chars[numCharsInLine] == static_cast(toupper(chDoc))); } else { @@ -444,13 +444,13 @@ void EditView::LayoutLine(const EditModel &model, int line, Surface *surface, co else if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseLower) ll->chars[charInLine] = static_cast(tolower(chDoc)); else if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseCamel) { - if ((model.pdoc->WordCharClass(ll->chars[charInLine]) == CharClassify::ccWord) && + if ((model.pdoc->WordCharClass(ll->chars[charInLine]) == CharClassify::ccWord) && ((charInLine == 0) || (model.pdoc->WordCharClass(ll->chars[charInLine - 1]) != CharClassify::ccWord))) { ll->chars[charInLine] = static_cast(toupper(chDoc)); } else { ll->chars[charInLine] = static_cast(tolower(chDoc)); } - } + } } } ll->xHighlightGuide = 0; @@ -986,11 +986,10 @@ static void DrawIndicators(Surface *surface, const EditModel &model, const ViewS startPos = deco->rs.EndRun(startPos); } while ((startPos < posLineEnd) && (deco->rs.ValueAt(startPos))) { - int endPos = deco->rs.EndRun(startPos); - if (endPos > posLineEnd) - endPos = posLineEnd; + const Range rangeRun(deco->rs.StartRun(startPos), deco->rs.EndRun(startPos)); + const int endPos = std::min(rangeRun.end, posLineEnd); const bool hover = vsDraw.indicators[deco->indicator].IsDynamic() && - ((hoverIndicatorPos >= startPos) && (hoverIndicatorPos <= endPos)); + rangeRun.ContainsCharacter(hoverIndicatorPos); const int value = deco->rs.ValueAt(startPos); Indicator::DrawState drawState = hover ? Indicator::drawHover : Indicator::drawNormal; DrawIndicator(deco->indicator, startPos - posLineStart, endPos - posLineStart, @@ -1476,7 +1475,7 @@ void EditView::DrawForeground(Surface *surface, const EditModel &model, const Vi if (indicatorValue) { const Indicator &indicator = vsDraw.indicators[deco->indicator]; const bool hover = indicator.IsDynamic() && - ((model.hoverIndicatorPos >= ts.start + posLineStart) && + ((model.hoverIndicatorPos >= ts.start + posLineStart) && (model.hoverIndicatorPos <= ts.end() + posLineStart)); if (hover) { if (indicator.sacHover.style == INDIC_TEXTFORE) { diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 6141b0628..08248a3d9 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -173,6 +173,8 @@ Editor::Editor() { paintAbandonedByStyling = false; paintingAllText = false; willRedrawAll = false; + idleStyling = SC_IDLESTYLING_NONE; + needIdleStyling = false; modEventMask = SC_MODEVENTMASKALL; @@ -762,7 +764,7 @@ bool Editor::RangeContainsProtected(int start, int end) const { end = t; } for (int pos = start; pos < end; pos++) { - if (vs.styles[pdoc->StyleAt(pos)].IsProtected()) + if (vs.styles[pdoc->StyleIndexAt(pos)].IsProtected()) return true; } } @@ -792,15 +794,15 @@ SelectionPosition Editor::MovePositionOutsideChar(SelectionPosition pos, int mov pos.SetPosition(posMoved); if (vs.ProtectionActive()) { if (moveDir > 0) { - if ((pos.Position() > 0) && vs.styles[pdoc->StyleAt(pos.Position() - 1)].IsProtected()) { + if ((pos.Position() > 0) && vs.styles[pdoc->StyleIndexAt(pos.Position() - 1)].IsProtected()) { while ((pos.Position() < pdoc->Length()) && - (vs.styles[pdoc->StyleAt(pos.Position())].IsProtected())) + (vs.styles[pdoc->StyleIndexAt(pos.Position())].IsProtected())) pos.Add(1); } } else if (moveDir < 0) { - if (vs.styles[pdoc->StyleAt(pos.Position())].IsProtected()) { + if (vs.styles[pdoc->StyleIndexAt(pos.Position())].IsProtected()) { while ((pos.Position() > 0) && - (vs.styles[pdoc->StyleAt(pos.Position() - 1)].IsProtected())) + (vs.styles[pdoc->StyleIndexAt(pos.Position() - 1)].IsProtected())) pos.Add(-1); } } @@ -919,7 +921,7 @@ void Editor::ScrollTo(int line, bool moveThumb) { SetTopLine(topLineNew); // Optimize by styling the view as this will invalidate any needed area // which could abort the initial paint if discovered later. - StyleToPositionInView(PositionAfterArea(GetClientRectangle())); + StyleAreaBounded(GetClientRectangle(), true); #ifndef UNDER_CE // Perform redraw rather than scroll if many lines would be redrawn anyway. if (performBlit) { @@ -1692,7 +1694,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { paintAbandonedByStyling = false; - StyleToPositionInView(PositionAfterArea(rcArea)); + StyleAreaBounded(rcArea, false); PRectangle rcClient = GetClientRectangle(); //Platform::DebugPrintf("Client: (%3d,%3d) ... (%3d,%3d) %d\n", @@ -1954,6 +1956,8 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) { void Editor::ClearBeforeTentativeStart() { // Make positions for the first composition string. + FilterSelections(); + UndoGroup ug(pdoc, (sel.Count() > 1) || !sel.Empty() || inOverstrike); for (size_t r = 0; r