From 8c9b09dd5f861e52590a154b2ad8ee0f0dc4e89f Mon Sep 17 00:00:00 2001
From: Neil
Date: Tue, 31 Dec 2019 20:19:24 +1100
Subject: Backport: Implement SCI_SETILEXER.
Backport of changeset 7871:ff54e1fc74f3, but with the ability to distinguish
between ILexer and ILexer5 interfaces.
---
doc/ScintillaDoc.html | 11 ++++++++++-
doc/ScintillaHistory.html | 11 +++++++++++
include/Scintilla.h | 1 +
include/Scintilla.iface | 3 +++
src/ScintillaBase.cxx | 49 ++++++++++++++++++++++++++++++++---------------
src/ScintillaBase.h | 5 -----
win32/DepGen.py | 3 +++
win32/deps.mak | 9 +++++++++
win32/makefile | 18 ++++++++++++++---
win32/nmdeps.mak | 9 +++++++++
win32/scintilla.mak | 14 +++++++++++++-
11 files changed, 108 insertions(+), 25 deletions(-)
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index b3fe1e553..e9f3471c0 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -6857,6 +6857,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
SCI_SETLEXERLANGUAGE(<unused>, const char
*language)
SCI_GETLEXERLANGUAGE(<unused>, char *language) → int
+ SCI_SETILEXER(bool iLexer5, pointer lexer)
SCI_LOADLEXERLIBRARY(bool iLexer5, const char
*path)
SCI_COLOURISE(position start, position end)
@@ -6907,7 +6908,15 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
Lex*.cxx file and search for LexerModule. The third argument in the
LexerModule constructor is the name to use.
- To test if your lexer assignment worked, use SCI_SETILEXER(bool iLexer5, pointer lexer)
+ SCI_SETILEXER allows setting a lexer as an ILexer*.
+ The lexer may be implemented by an application or a shared library such as Lexilla.
+ iLexer5 indicates whether or not the library contains Scintilla lexers that implement
+ the ILexer5 interface defined in Scintilla 4.3+ (e.g. Lexilla). The default is to assume lexers
+ implement the ILexer interface defined in Scintilla 3.x. This flag must be set explicitly and
+ cannot be inferred.
+
+ To test if your lexer assignment worked, use SCI_GETLEXER before and after setting the new lexer to
see if the lexer number changed.
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 0f515ca91..ecc299dcd 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -559,6 +559,17 @@
+
+ -
+ Released 9 May 2020.
+
+ -
+ SCI_SETILEXER implemented to use lexers from Lexilla or other sources.
+
+
+
-
Released 9 May 2020.
diff --git a/include/Scintilla.h b/include/Scintilla.h
index cea4983e3..c2d289bab 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -1041,6 +1041,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_NAMEOFSTYLE 4030
#define SCI_TAGSOFSTYLE 4031
#define SCI_DESCRIPTIONOFSTYLE 4032
+#define SCI_SETILEXER 4033
#define SC_MOD_NONE 0x0
#define SC_MOD_INSERTTEXT 0x1
#define SC_MOD_DELETETEXT 0x2
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 05a0ed2ce..a3354de40 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -2963,6 +2963,9 @@ fun int TagsOfStyle=4031(int style, stringresult tags)
# Result is NUL-terminated.
fun int DescriptionOfStyle=4032(int style, stringresult description)
+# Set the lexer from an ILexer*.
+set void SetILexer=4033(, pointer ilexer)
+
# Notifications
# Type of modification and the action which caused the modification.
# These are defined as a bit mask to make it easy to specify which notifications are wanted.
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index 09736d9f7..af1a6f52e 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -23,9 +23,7 @@
#include "ILexer.h"
#include "Scintilla.h"
-#ifdef SCI_LEXER
#include "SciLexer.h"
-#endif
#include "PropSetSimple.h"
#include "CharacterCategory.h"
@@ -61,9 +59,7 @@
#include "AutoComplete.h"
#include "ScintillaBase.h"
-#ifdef SCI_LEXER
#include "ExternalLexer.h"
-#endif
using namespace Scintilla;
@@ -548,8 +544,6 @@ void ScintillaBase::RightButtonDownWithModifiers(Point pt, unsigned int curTime,
Editor::RightButtonDownWithModifiers(pt, curTime, modifiers);
}
-#ifdef SCI_LEXER
-
namespace Scintilla {
class LexState : public LexInterface {
@@ -561,6 +555,7 @@ public:
int lexLanguage;
explicit LexState(Document *pdoc_);
+ void SetInstance(ILexer *instance_);
// Deleted so LexState objects can not be copied.
LexState(const LexState &) = delete;
LexState(LexState &&) = delete;
@@ -569,8 +564,10 @@ public:
~LexState() override;
void SetLexer(uptr_t wParam);
void SetLexerLanguage(const char *languageName);
+
const char *DescribeWordListSets();
void SetWordList(int n, const char *wl);
+ int GetIdentifier() const;
const char *GetName() const;
void *PrivateCall(int operation, void *pointer);
const char *PropertyNames();
@@ -609,8 +606,25 @@ LexState::LexState(Document *pdoc_) : LexInterface(pdoc_) {
LexState::~LexState() {
if (instance) {
instance->Release();
+ LexillaLexer *iLexer5 = dynamic_cast(instance);
+ if (iLexer5) {
+ delete iLexer5;
+ }
+ instance = nullptr;
+ }
+}
+
+void LexState::SetInstance(ILexer *instance_) {
+ if (instance) {
+ instance->Release();
+ LexillaLexer *iLexer5 = dynamic_cast(instance);
+ if (iLexer5) {
+ delete iLexer5;
+ }
instance = nullptr;
}
+ instance = instance_;
+ pdoc->LexerChanged();
}
LexState *ScintillaBase::DocumentLexState() {
@@ -624,6 +638,10 @@ void LexState::SetLexerModule(const LexerModule *lex) {
if (lex != lexCurrent) {
if (instance) {
instance->Release();
+ LexillaLexer *iLexer5 = dynamic_cast(instance);
+ if (iLexer5) {
+ delete iLexer5;
+ }
instance = nullptr;
}
interfaceVersion = lvOriginal;
@@ -841,10 +859,7 @@ const char *LexState::DescriptionOfStyle(int style) {
}
}
-#endif
-
void ScintillaBase::NotifyStyleToNeeded(Sci::Position endStyleNeeded) {
-#ifdef SCI_LEXER
if (DocumentLexState()->lexLanguage != SCLEX_CONTAINER) {
const Sci::Line lineEndStyled =
pdoc->SciLineFromPosition(pdoc->GetEndStyled());
@@ -853,14 +868,11 @@ void ScintillaBase::NotifyStyleToNeeded(Sci::Position endStyleNeeded) {
DocumentLexState()->Colourise(endStyled, endStyleNeeded);
return;
}
-#endif
Editor::NotifyStyleToNeeded(endStyleNeeded);
}
void ScintillaBase::NotifyLexerChanged(Document *, void *) {
-#ifdef SCI_LEXER
vs.EnsureStyle(0xff);
-#endif
}
sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
@@ -1058,7 +1070,6 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara
displayPopupMenu = static_cast(wParam);
break;
-#ifdef SCI_LEXER
case SCI_SETLEXER:
DocumentLexState()->SetLexer(static_cast(wParam));
break;
@@ -1066,6 +1077,14 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara
case SCI_GETLEXER:
return DocumentLexState()->lexLanguage;
+ case SCI_SETILEXER:
+ if (wParam == 0) {
+ DocumentLexState()->SetInstance(reinterpret_cast(lParam));
+ } else {
+ DocumentLexState()->SetInstance(new LexillaLexer(reinterpret_cast(lParam)));
+ }
+ return 0;
+
case SCI_COLOURISE:
if (DocumentLexState()->lexLanguage == SCLEX_CONTAINER) {
pdoc->ModifiedAt(static_cast(wParam));
@@ -1102,9 +1121,11 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara
case SCI_GETLEXERLANGUAGE:
return StringResult(lParam, DocumentLexState()->GetName());
+#ifdef SCI_LEXER
case SCI_LOADLEXERLIBRARY:
ExternalLexerLoad(ConstCharPtrFromSPtr(lParam), wParam != 0);
break;
+#endif
case SCI_PRIVATELEXERCALL:
return reinterpret_cast(
@@ -1176,8 +1197,6 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara
return StringResult(lParam, DocumentLexState()->
DescriptionOfStyle(static_cast(wParam)));
-#endif
-
default:
return Editor::WndProc(iMessage, wParam, lParam);
}
diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h
index e922ab057..fcb1c9796 100644
--- a/src/ScintillaBase.h
+++ b/src/ScintillaBase.h
@@ -10,10 +10,7 @@
namespace Scintilla {
-#ifdef SCI_LEXER
class LexState;
-#endif
-
/**
*/
class ScintillaBase : public Editor, IListBoxDelegate {
@@ -44,12 +41,10 @@ protected:
int maxListWidth; /// Maximum width of list, in average character widths
int multiAutoCMode; /// Mode for autocompleting when multiple selections are present
-#ifdef SCI_LEXER
LexState *DocumentLexState();
void SetLexer(uptr_t wParam);
void SetLexerLanguage(const char *languageName);
void Colourise(int start, int end);
-#endif
ScintillaBase();
// Deleted so ScintillaBase objects can not be copied.
diff --git a/win32/DepGen.py b/win32/DepGen.py
index c255574b0..6196720e2 100644
--- a/win32/DepGen.py
+++ b/win32/DepGen.py
@@ -22,6 +22,9 @@ def Generate():
# Add ScintillaBaseL as the same as ScintillaBase
deps = Dependencies.InsertSynonym(deps, "ScintillaBase.o", "ScintillaBaseL.o")
+ # Add CatalogueL as the same as Catalogue
+ deps = Dependencies.InsertSynonym(deps, "Catalogue.o", "CatalogueL.o")
+
Dependencies.UpdateDependencies("../win32/deps.mak", deps, topComment)
# Create the dependencies file for MSVC
diff --git a/win32/deps.mak b/win32/deps.mak
index 3dbe89399..4b921238c 100644
--- a/win32/deps.mak
+++ b/win32/deps.mak
@@ -96,6 +96,15 @@ Catalogue.o: \
../lexlib/LexerModule.h \
../lexlib/CatalogueModules.h \
../src/Catalogue.h
+CatalogueL.o: \
+ ../src/Catalogue.cxx \
+ ../include/ILexer.h \
+ ../include/Sci_Position.h \
+ ../include/Scintilla.h \
+ ../include/SciLexer.h \
+ ../lexlib/LexerModule.h \
+ ../lexlib/CatalogueModules.h \
+ ../src/Catalogue.h
CellBuffer.o: \
../src/CellBuffer.cxx \
../include/Platform.h \
diff --git a/win32/makefile b/win32/makefile
index 1b5ce451b..0bb3d0d8f 100644
--- a/win32/makefile
+++ b/win32/makefile
@@ -117,6 +117,7 @@ SRC_OBJS = \
MarginView.o \
PerLine.o \
PositionCache.o \
+ PropSetSimple.o \
RESearch.o \
RunStyles.o \
Selection.o \
@@ -129,13 +130,12 @@ SRC_OBJS = \
# Required by lexers
LEXLIB_OBJS = \
Accessor.o \
- Catalogue.o \
+ CatalogueL.o \
DefaultLexer.o \
ExternalLexer.o \
LexerBase.o \
LexerModule.o \
LexerSimple.o \
- PropSetSimple.o \
StyleContext.o \
WordList.o
@@ -152,12 +152,18 @@ SCILEX_OBJS=\
COMPONENT_OBJS = \
$(SRC_OBJS) \
+ Accessor.o \
+ Catalogue.o \
HanjaDic.o \
+ LexerBase.o \
+ LexerModule.o \
+ LexerSimple.o \
PlatWin.o \
ScintillaBase.o \
ScintillaDLL.o \
ScintillaWin.o \
- ScintRes.o
+ ScintRes.o \
+ WordList.o
LEXCOMPONENT_OBJS = \
$(SCILEX_OBJS) \
@@ -180,6 +186,12 @@ include deps.mak
ScintillaBaseL.o:
$(CXX) $(CXX_ALL_FLAGS) $(CXXFLAGS) -D SCI_LEXER -c $< -o $@
+Catalogue.o: Catalogue.cxx
+ $(CXX) $(CXX_ALL_FLAGS) $(CXXFLAGS) -D SCI_LEXER -D SCI_EMPTYCATALOGUE -c $< -o $@
+
+CatalogueL.o: Catalogue.cxx
+ $(CXX) $(CXX_ALL_FLAGS) $(CXXFLAGS) -D SCI_LEXER -c $< -o $@
+
ScintRes.o: ScintRes.rc
$(WINDRES) ScintRes.rc $@
diff --git a/win32/nmdeps.mak b/win32/nmdeps.mak
index 79cc0ab45..8a886b517 100644
--- a/win32/nmdeps.mak
+++ b/win32/nmdeps.mak
@@ -96,6 +96,15 @@ $(DIR_O)/Catalogue.obj: \
../lexlib/LexerModule.h \
../lexlib/CatalogueModules.h \
../src/Catalogue.h
+$(DIR_O)/CatalogueL.obj: \
+ ../src/Catalogue.cxx \
+ ../include/ILexer.h \
+ ../include/Sci_Position.h \
+ ../include/Scintilla.h \
+ ../include/SciLexer.h \
+ ../lexlib/LexerModule.h \
+ ../lexlib/CatalogueModules.h \
+ ../src/Catalogue.h
$(DIR_O)/CellBuffer.obj: \
../src/CellBuffer.cxx \
../include/Platform.h \
diff --git a/win32/scintilla.mak b/win32/scintilla.mak
index f9b0a4bdf..d446bb262 100644
--- a/win32/scintilla.mak
+++ b/win32/scintilla.mak
@@ -230,7 +230,7 @@ LEX_OBJS=\
# Required by lexers
LEXLIB_OBJS = \
$(DIR_O)\Accessor.obj \
- $(DIR_O)\Catalogue.obj \
+ $(DIR_O)\CatalogueL.obj \
$(DIR_O)\ExternalLexer.obj \
$(DIR_O)\DefaultLexer.obj \
$(DIR_O)\LexerBase.obj \
@@ -250,11 +250,17 @@ SCILEX_OBJS = \
$(DIR_O)\ScintillaWin.obj
COMPONENT_OBJS = \
+ $(DIR_O)\Accessor.obj \
+ $(DIR_O)\Catalogue.obj \
$(DIR_O)\HanjaDic.obj \
+ $(DIR_O)\LexerBase.obj \
+ $(DIR_O)\LexerModule.obj \
+ $(DIR_O)\LexerSimple.obj \
$(DIR_O)\PlatWin.obj \
$(DIR_O)\ScintillaBase.obj \
$(DIR_O)\ScintillaDLL.obj \
$(DIR_O)\ScintillaWin.obj \
+ $(DIR_O)\WordList.obj \
$(SRC_OBJS)
LEXCOMPONENT_OBJS = \
@@ -288,6 +294,12 @@ $(LIBSCI): $(SCILEX_OBJS)
$(DIR_O)\ScintillaBaseL.obj: ..\src\ScintillaBase.cxx
$(CXX) $(CXXFLAGS) -DSCI_LEXER -c $(NAME)$@ ..\src\ScintillaBase.cxx
+$(DIR_O)\CatalogueL.obj: ..\src\Catalogue.cxx
+ $(CXX) $(CXXFLAGS) -DSCI_LEXER -c $(NAME)$@ ..\src\Catalogue.cxx
+
+$(DIR_O)\Catalogue.obj: ..\src\Catalogue.cxx
+ $(CXX) $(CXXFLAGS) -DSCI_LEXER -DSCI_EMPTYCATALOGUE -c $(NAME)$@ ..\src\Catalogue.cxx
+
# Dependencies
!IF EXISTS(nmdeps.mak)
--
cgit v1.2.3