Skip to content

Commit f56d32f

Browse files
committed
Throw exception for pyreplace/pymlreplace
1 parent 91638a7 commit f56d32f

3 files changed

Lines changed: 10 additions & 19 deletions

File tree

PythonScript/src/ScintillaPython.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ BOOST_PYTHON_MODULE(Npp)
7474
" def myIncrement(m):\n"
7575
" return int(m.group(1)) + 1\n\n"
7676
"And call rereplace('([0-9]+)', myIncrement) and it will increment all the integers.")
77+
.def("pyreplace", boost::python::raw_function(&deprecated_replace_function), "Deprecated in this version of PythonScript for Notepad++. Use the new rereplace() instead")
78+
.def("pymlreplace", boost::python::raw_function(&deprecated_replace_function), "Deprecated in this version of PythonScript for Notepad++. Use the new rereplace() instead")
7779
.def("getWord", &ScintillaWrapper::getWord, "getWord([position[, useOnlyWordChars]])\nGets the word at position. If position is not given or None, the current caret position is used.\nuseOnlyWordChars is a bool that is passed to Scintilla - see Scintilla rules on what is match. If not given or None, it is assumed to be true.")
7880
.def("getWord", &ScintillaWrapper::getWordNoFlags, "getWord([position[, useOnlyWordChars]])\nGets the word at position. If position is not given or None, the current caret position is used.\nuseOnlyWordChars is a bool that is passed to Scintilla - see Scintilla rules on what is match. If not given or None, it is assumed to be true.")
7981
.def("getWord", &ScintillaWrapper::getCurrentWord, "getWord([position[, useOnlyWordChars]])\nGets the word at position. If position is not given or None, the current caret position is used.\nuseOnlyWordChars is a bool that is passed to Scintilla - see Scintilla rules on what is match. If not given or None, it is assumed to be true.")

PythonScript/src/ScintillaWrapper.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Replacer.h"
77
#include "Match.h"
88
#include "ReplacementContainer.h"
9+
#include "NotSupportedException.h"
910
#include "PythonScript/NppPythonScript.h"
1011

1112

@@ -30,30 +31,14 @@ ScintillaWrapper::~ScintillaWrapper()
3031
// m_handle isn't allocated here. Let's just NULL out reference to it, then.
3132
m_handle = NULL;
3233
}
33-
/*
34-
void ScintillaWrapper::addText(str s)
35-
{
36-
const char *raw = extract<const char*>(s);
37-
call(SCI_ADDTEXT, len(s), reinterpret_cast<LPARAM>(raw));
38-
}
3934

4035

41-
void ScintillaWrapper::AddStyledText(ScintillaCells s)
36+
boost::python::object deprecated_replace_function(boost::python::tuple /* args */, boost::python::dict /* kwargs */)
4237
{
43-
call(SCI_ADDSTYLEDTEXT, s.length(), reinterpret_cast<LPARAM>(s.cells()));
38+
throw NppPythonScript::NotSupportedException("The pyreplace(), pymlreplace(), pysearch() and pymlsearch() functions have been deprecated.\n"
39+
"The new replace(), rereplace(), search(), and research() functions have all the same functionality, but are faster, more reliable and have better support for unicode.");
4440
}
4541

46-
str ScintillaWrapper::getLine(int lineNumber)
47-
{
48-
int resultLength = call(SCI_GETLINE, lineNumber, NULL);
49-
char * result = (char *)malloc(resultLength + 1);
50-
call(SCI_GETLINE, lineNumber, reinterpret_cast<LPARAM>(result));
51-
result[resultLength] = '\0';
52-
str o = str((const char *)result);
53-
free(result);
54-
return o;
55-
}
56-
*/
5742
void ScintillaWrapper::notify(SCNotification *notifyCode)
5843
{
5944
if (!m_notificationsEnabled)

PythonScript/src/ScintillaWrapper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ struct CallbackExecArgs
4343
boost::python::dict params;
4444
};
4545

46+
47+
// Function that throws a notsupported exception, with the message about the method being deprecated
48+
boost::python::object deprecated_replace_function(boost::python::tuple args, boost::python::dict kwargs);
49+
4650
class ScintillaWrapper : public NppPythonScript::PyProducerConsumer<CallbackExecArgs>
4751
{
4852
public:

0 commit comments

Comments
 (0)