From 1345c899da0cdfb5f39e8941587cde011945ddfc Mon Sep 17 00:00:00 2001 From: dail8859 Date: Mon, 27 Mar 2017 19:04:10 -0400 Subject: [PATCH 01/62] Fix ordering of npp constants --- src/NppIFaceTable.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/NppIFaceTable.cpp b/src/NppIFaceTable.cpp index 90e9ecf..107fcde 100644 --- a/src/NppIFaceTable.cpp +++ b/src/NppIFaceTable.cpp @@ -514,13 +514,13 @@ static std::vector ifaceConstants = { { "NPPM_SETCURRENTLANGTYPE", NPPM_SETCURRENTLANGTYPE }, { "NPPM_SETEDITORBORDEREDGE", NPPM_SETEDITORBORDEREDGE }, { "PRIMARY_VIEW", PRIMARY_VIEW }, + { "SECOND_VIEW", SECOND_VIEW }, { "STATUSBAR_CUR_POS", STATUSBAR_CUR_POS }, { "STATUSBAR_DOC_SIZE", STATUSBAR_DOC_SIZE }, { "STATUSBAR_DOC_TYPE", STATUSBAR_DOC_TYPE }, { "STATUSBAR_EOF_FORMAT", STATUSBAR_EOF_FORMAT }, { "STATUSBAR_TYPING_MODE", STATUSBAR_TYPING_MODE }, { "STATUSBAR_UNICODE_TYPE", STATUSBAR_UNICODE_TYPE }, - { "SECOND_VIEW", SECOND_VIEW }, { "SUB_VIEW", SUB_VIEW }, { "WV_95", WV_95 }, { "WV_98", WV_98 }, @@ -553,7 +553,7 @@ static std::vector ifaceFunctions = { { "GetFileName", NPPM_GETFILENAME, iface_void, { iface_length, iface_tstringresult } }, { "GetFileNameAtCursor", NPPM_GETFILENAMEATCURSOR, iface_void, { iface_length, iface_tstringresult } }, { "GetFullCurrentPath", NPPM_GETFULLCURRENTPATH, iface_void, { iface_length, iface_tstringresult } }, - { "GetFullPathFromBufferID", NPPM_GETFULLPATHFROMBUFFERID, iface_void, { iface_int, iface_tstringresult} }, + { "GetFullPathFromBufferID", NPPM_GETFULLPATHFROMBUFFERID, iface_void, { iface_int, iface_tstringresult } }, { "GetNamePart", NPPM_GETNAMEPART, iface_void, { iface_length, iface_tstringresult } }, { "GetNbOpenFiles", NPPM_GETNBOPENFILES, iface_int, { iface_void, iface_int } }, { "GetNbSessionFiles", NPPM_GETNBSESSIONFILES, iface_int, { iface_void, iface_tstring } }, @@ -570,7 +570,7 @@ static std::vector ifaceFunctions = { { "IsStatusBarHidden", NPPM_ISSTATUSBARHIDDEN, iface_bool, { iface_void, iface_void } }, { "IsTabBarHidden", NPPM_ISTABBARHIDDEN, iface_bool, { iface_void, iface_void } }, { "IsToolBarHidden", NPPM_ISTOOLBARHIDDEN, iface_bool, { iface_void, iface_void } }, - { "LaunchFindInFilesDlg", NPPM_LAUNCHFINDINFILESDLG, iface_void, { iface_tstring, iface_tstring} }, + { "LaunchFindInFilesDlg", NPPM_LAUNCHFINDINFILESDLG, iface_void, { iface_tstring, iface_tstring } }, { "LoadSession", NPPM_LOADSESSION, iface_void, { iface_void, iface_tstring } }, { "MakeCurrentBufferDirty", NPPM_MAKECURRENTBUFFERDIRTY, iface_void, { iface_void, iface_void } }, { "MenuCommand", NPPM_MENUCOMMAND, iface_void, { iface_void, iface_int } }, @@ -580,10 +580,10 @@ static std::vector ifaceFunctions = { { "SaveCurrentFile", NPPM_SAVECURRENTFILE, iface_bool, { iface_void, iface_void } }, { "SaveCurrentFileAs", NPPM_SAVECURRENTFILEAS, iface_bool, { iface_bool, iface_tstring } }, { "SaveCurrentSession", NPPM_SAVECURRENTSESSION, iface_void, { iface_void, iface_tstring } }, - { "SaveFile", NPPM_SAVEFILE, iface_void, { iface_void, iface_tstring} }, - { "SetEditorBorderEdge", NPPM_SETEDITORBORDEREDGE, iface_void, { iface_void, iface_bool} }, - { "SetSmoothFont", NPPM_SETSMOOTHFONT, iface_void, { iface_void, iface_bool} }, - { "ShowDocSwitcher", NPPM_SHOWDOCSWITCHER, iface_void, { iface_void, iface_bool} }, + { "SaveFile", NPPM_SAVEFILE, iface_void, { iface_void, iface_tstring } }, + { "SetEditorBorderEdge", NPPM_SETEDITORBORDEREDGE, iface_void, { iface_void, iface_bool } }, + { "SetSmoothFont", NPPM_SETSMOOTHFONT, iface_void, { iface_void, iface_bool } }, + { "ShowDocSwitcher", NPPM_SHOWDOCSWITCHER, iface_void, { iface_void, iface_bool } }, { "SwitchToFile", NPPM_SWITCHTOFILE, iface_bool, { iface_void, iface_tstring } }, { "TriggerTabbarContextMenu", NPPM_TRIGGERTABBARCONTEXTMENU, iface_void, { iface_int, iface_int } }, }; From e8e5e14189289ba68c392999707c32880b103fc9 Mon Sep 17 00:00:00 2001 From: ethanpil Date: Fri, 10 Mar 2017 14:38:41 -0500 Subject: [PATCH 02/62] Update README.md Closes #58, Closes #56 --- README.md | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index e6c8812..6558e4d 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,31 @@ # LuaScript -Notepad++ plugin for [Lua](http://www.lua.org/) scripting capabilities. Provides control over all of Scintilla's features and options with a light-weight, fully-functional programming language. Download it from the [Release](https://github.com/dail8859/LuaScript/releases) page. +Notepad++ plugin for [Lua](http://www.lua.org/) scripting capabilities. This provides control over all of Scintilla's features and options with a light-weight, fully-functional programming language. Major features include: - Assign Lua functions to shortcut keys -- Register callbacks to specific events +- Register callback functions for events - Full Lua 5.3 functionality - Interactive console with auto-completion - Requires no special permissions -## Documentation -The full API documentation can be found [here](http://dail8859.github.io/LuaScript/). +## Getting Started +Install the plugin using the Notepad++ Plugin Manager, or download it from the [Release](https://github.com/dail8859/LuaScript/releases) page and copy `LuaScript.dll` to your `\plugins` folder. -## Examples -Just show me what it can do! Also, check out the [examples](/examples/) directory. +#### Lua Console +LuaScript provides an interactive console for running Lua commands. This can be shown by `Plugins > LuaScript > Show Console`. -- Change Notepad++'s ugly marker symbols: -```lua --- Notepad++ uses 24 internally -editor:MarkerDefine(24, SC_MARK_BOOKMARK) -editor.MarkerFore[24] = 0x0000EE -editor.MarkerBack[24] = 0x6060F2 -``` +#### Startup Script +LuaScript looks for the `\plugins\config\startup.lua` file and automatically runs it on Notepad++ startup. You can easily edit this file via `Plugins > LuaScript > Edit Startup Script`. You can include any commands you want to immediately execute on program startup, as well as register any additional shortcuts or callbacks. -- Find all instances of `image345.jpg`, `image123.png`, etc and modify the number: -```lua -for m in editor:match("(image)(\\d+)(\\.(jpg|png))", SCFIND_REGEXP) do - i = tonumber(editor.Tag[2]) - m:replace(editor.Tag[1] .. i + 1 .. editor.Tag[3]) -end -``` +#### Registering New Shortcuts +New functions can be added as shortcuts by using [AddShortcut](https://dail8859.github.io/LuaScript/classes/Notepad.html#Notepad.AddShortcut). The new menu items are listed under the `Plugins > LuaScript` menu. For example [this script](https://dail8859.github.io/LuaScript/examples/visualstudiolinecopy.lua.html) adds 2 new menu items. -- Get some of Visual Studio's copy and paste functionality: -```lua --- Mimic Visual Studio's "Ctrl+C" that copies the entire line if nothing is selected -npp.AddShortcut("Copy Allow Line", "Ctrl+C", function() - editor:CopyAllowLine() -end) +#### Registering Callback Functions +Scripts can also register functions to be called when certain events occur, such as a file being opened, text being modified, etc. Each callback provides a different set of parameters. See the documentation for [callbacks](https://dail8859.github.io/LuaScript/topics/callbacks.md.html) to see the entire list of possible events and parameters provided. --- Mimic Visual Studio's "Ctrl+X" that cuts the line if nothing is selected -npp.AddShortcut("Cut Allow Line", "Ctrl+X", function() - if editor.SelectionEmpty then - editor:CopyAllowLine() - editor:LineDelete() - else - editor:Cut() - end -end) -``` +## Documentation +The full API documentation can be found [here](http://dail8859.github.io/LuaScript/). Also be sure to check out the [examples](/examples/) directory. ## Development The code has been developed using MSVC 2013. To compile the code: From c5d70e9870c345adca1c3afa6ec37dd6a83a787c Mon Sep 17 00:00:00 2001 From: dail8859 Date: Mon, 3 Apr 2017 20:53:42 -0400 Subject: [PATCH 03/62] Fix OnPainted documentation --- docs/topics/callbacks.md.html | 2 +- docs_gen/Callbacks.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/topics/callbacks.md.html b/docs/topics/callbacks.md.html index ab588f2..c271686 100644 --- a/docs/topics/callbacks.md.html +++ b/docs/topics/callbacks.md.html @@ -76,7 +76,7 @@

Callbacks

  • OnModification(modType, position, length, text, linesAdded)
  • OnMarginClick(position, margin, modifiers)
  • OnNeedShown(position, length)
  • -
  • OnPainted(listType, position, text)
  • +
  • OnPainted()
  • OnUserListSelection(listType, position, text)
  • OnDwellStart(position, x, y)
  • OnDwellEnd(position, x, y)
  • diff --git a/docs_gen/Callbacks.md b/docs_gen/Callbacks.md index 539e1d2..5b10b7e 100644 --- a/docs_gen/Callbacks.md +++ b/docs_gen/Callbacks.md @@ -13,7 +13,7 @@ Scintilla related callbacks: - `OnModification(modType, position, length, text, linesAdded)` - `OnMarginClick(position, margin, modifiers)` - `OnNeedShown(position, length)` -- `OnPainted(listType, position, text)` +- `OnPainted()` - `OnUserListSelection(listType, position, text)` - `OnDwellStart(position, x, y)` - `OnDwellEnd(position, x, y)` From 4c987ba14dc3550324f72e42bd39494c12a15411 Mon Sep 17 00:00:00 2001 From: ethanpil Date: Wed, 12 Apr 2017 17:45:19 -0400 Subject: [PATCH 04/62] Add randomize lines example --- examples/randomizelines.lua | 97 +++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 examples/randomizelines.lua diff --git a/examples/randomizelines.lua b/examples/randomizelines.lua new file mode 100644 index 0000000..9d1f966 --- /dev/null +++ b/examples/randomizelines.lua @@ -0,0 +1,97 @@ +--------------------------------------------------------------- +-- randomizelines.lua for Notepad++ LuaScript plugin +-- +-- This script will randomize the lines within a document. +-- +-- Activate it on all text in the editor by running without a +-- selection, or select a group of lines to randomize only +-- the selected lines. +--------------------------------------------------------------- + +-- helper function to split lines +local function split(str, sep) + local result = {} + local regex = ("([^%s]+)"):format(sep) + for each in str:gmatch(regex) do + table.insert(result, each) + end + return result +end + +-- helper function to shuffle a table +local function shuffle(t) + math.randomseed( os.time() ) + local rand = math.random + local iterations = #t + local j + + for i = iterations, 2, -1 do + j = rand(i) + t[i], t[j] = t[j], t[i] + end + return t +end + +-------------------------------------------------------------------- + +npp.AddShortcut("Randomize Lines", "", function() + + local result --placeholder to store the processed text for return to editor + local SelectionStart, SelectionEnd --placeholder to store selection points + + -- Preserve Undo Capability + editor:BeginUndoAction() + + -- Get any selected text + local seltext = editor:GetSelText() + local seltextlen = #seltext + + -- read selected text or entire document + local rawtext + if seltextlen >= 1 then + rawtext = seltext + --read the selection points for restore after operation + SelectionStart = editor.SelectionStart + SelectionEnd = editor.SelectionEnd + else + rawtext = editor:GetText() + end + + -- Preserve EOL Mode when we send back the reordered lines + local EOLchar + if editor.EOLMode == 0 then + EOLchar = "\r\n" + elseif editor.EOLMode == 1 then + EOLchar = "\r" + elseif editor.EOLMode == 2 then + EOLchar = "\n" + end + -------------------- + -- process the text + -------------------- + + -- split the text into an array of lines + local rawtextlines = split(rawtext,EOLchar); + + -- randomize the lines + rawtextlines = shuffle(rawtextlines) + + -- output to result var + result = table.concat(rawtextlines, EOLchar) + + -------------------- + -- end processing + -------------------- + + -- replace selected text or entire document + if seltextlen >= 1 then + editor:ReplaceSel(result) + -- restore selection + editor:SetSel(SelectionStart, SelectionEnd) + else + editor:SetText(result) + end + + editor:EndUndoAction() + +end) From ce4ef08a4717d0c56af96f7ea31b20eb74d93ea4 Mon Sep 17 00:00:00 2001 From: dail8859 Date: Tue, 18 Apr 2017 19:50:30 -0400 Subject: [PATCH 05/62] Update to VS2015 Fix 64bit warnings and use std algorithms for doing binary searches --- .gitignore | 211 ++++++++++++++---- LuaScript.sln | 4 +- ...{randomizelines.lua => RandomizeLines.lua} | 0 src/Lua.vcxproj | 11 +- src/LuaConsole.cpp | 10 +- src/LuaScript.cpp | 10 +- src/LuaScript.vcxproj | 11 +- src/SciTE/IFaceTable.cpp | 66 ++---- src/SciTE/LuaExtension.cpp | 2 +- 9 files changed, 214 insertions(+), 111 deletions(-) rename examples/{randomizelines.lua => RandomizeLines.lua} (100%) diff --git a/.gitignore b/.gitignore index 0b28d53..61e8800 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,56 @@ -## From https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.suo *.user +*.userosscache *.sln.docstates -# Build results +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs +# Build results [Dd]ebug/ +[Dd]ebugPublic/ [Rr]elease/ +[Rr]eleases/ x64/ -build/ +x86/ +bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + *_i.c *_p.c +*_i.h *.ilk *.meta *.obj @@ -42,21 +70,31 @@ build/ *.vssscc .builds *.pidb -*.log +*.svclog *.scc +# Chutzpah Test files +_Chutzpah* + # Visual C++ cache files ipch/ *.aps *.ncb +*.opendb *.opensdf *.sdf *.cachefile +*.VC.db +*.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ # Guidance Automation Toolkit *.gpState @@ -64,6 +102,10 @@ ipch/ # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode # TeamCity is a build add-in _TeamCity* @@ -71,9 +113,21 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch -*.ncrunch* +_NCrunch_* .*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ # Installshield output folder [Ee]xpress/ @@ -92,69 +146,146 @@ DocProject/Help/html publish/ # Publish Web Output -*.Publish.xml +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted *.pubxml +*.publishproj -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ -# Windows Azure Build Output -csx +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ *.build.csdef -# Windows Store app package directory +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ # Others -sql/ -*.Cache ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl -*.[Pp]ublish.xml +*.dbproj.schemaview +*.jfm *.pfx *.publishsettings +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ # RIA/Silverlight projects Generated_Code/ -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm # SQL Server files -App_Data/*.mdf -App_Data/*.ldf +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg -# ========================= -# Windows detritus -# ========================= +# Visual Studio 6 workspace options file +*.opt -# Windows image file caches -Thumbs.db -ehthumbs.db +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw -# Folder config file -Desktop.ini +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions -# Recycle Bin used on file shares -$RECYCLE.BIN/ +# Paket dependency manager +.paket/paket.exe +paket-files/ -# Mac crap -.DS_Store +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs -/Unicode Release -/Unicode Debug -/Release -/Debug -/ResEdit-x64 LuaDist -gh-pages /docs_gen/Editor.lua -*.pyc diff --git a/LuaScript.sln b/LuaScript.sln index 10bf81f..77d32ec 100644 --- a/LuaScript.sln +++ b/LuaScript.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LuaScript", "src\LuaScript.vcxproj", "{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}" ProjectSection(ProjectDependencies) = postProject diff --git a/examples/randomizelines.lua b/examples/RandomizeLines.lua similarity index 100% rename from examples/randomizelines.lua rename to examples/RandomizeLines.lua diff --git a/src/Lua.vcxproj b/src/Lua.vcxproj index 3367686..8afcded 100644 --- a/src/Lua.vcxproj +++ b/src/Lua.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -84,28 +84,29 @@ {FCFBB3B0-8628-4CD0-A9B7-1BFB34E31E2A} LuaScript Win32Proj + 8.1 StaticLibrary Unicode - v120 + v140_xp StaticLibrary Unicode - v120 + v140_xp StaticLibrary Unicode - v120 + v140_xp true StaticLibrary Unicode - v120 + v140_xp true diff --git a/src/LuaConsole.cpp b/src/LuaConsole.cpp index 9c7cdf3..f9150c2 100644 --- a/src/LuaConsole.cpp +++ b/src/LuaConsole.cpp @@ -65,16 +65,16 @@ struct Sorter { Sorter(bool ignoreCase_) : ignoreCase(ignoreCase_) {} inline bool operator()(const std::string& a, const std::string& b) { - int lenA = a.length(); - int lenB = b.length(); - int len = min(lenA, lenB); + auto lenA = a.length(); + auto lenB = b.length(); + auto len = min(lenA, lenB); int cmp; if (ignoreCase) cmp = CompareNCaseInsensitive(a.c_str(), b.c_str(), len); else cmp = strncmp(a.c_str(), b.c_str(), len); if (cmp == 0) - cmp = lenA - lenB; + cmp = static_cast(lenA - lenB); return cmp < 0; } }; @@ -344,7 +344,7 @@ void LuaConsole::showAutoCompletion() { // Back up past the partial word prevCh = m_sciInput->Call(SCI_GETCHARAT, curPos - 1 - partialWord.size()); - curPos = curPos - partialWord.size(); + curPos = curPos - static_cast(partialWord.size()); } if (prevCh == '.' || prevCh == ':') { diff --git a/src/LuaScript.cpp b/src/LuaScript.cpp index e46a6dd..352e0e3 100644 --- a/src/LuaScript.cpp +++ b/src/LuaScript.cpp @@ -181,7 +181,7 @@ extern "C" __declspec(dllexport) const wchar_t *getName() { } extern "C" __declspec(dllexport) FuncItem *getFuncsArray(int *nbF) { - *nbF = funcItems.size(); + *nbF = static_cast(funcItems.size()); return funcItems.data(); } @@ -195,16 +195,16 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode) { case NPPN_READONLYCHANGED: // Note: hwndFrom is the bufferID SendNpp(NPPM_GETFULLPATHFROMBUFFERID, (WPARAM)nh.hwndFrom, (LPARAM)fname); - LuaExtension::Instance().OnReadOnlyChanged(GUI::UTF8FromString(fname).c_str(), (uptr_t)nh.hwndFrom, nh.idFrom); + LuaExtension::Instance().OnReadOnlyChanged(GUI::UTF8FromString(fname).c_str(), (uptr_t)nh.hwndFrom, (int)nh.idFrom); return; case NPPN_DOCORDERCHANGED: SendNpp(NPPM_GETFULLPATHFROMBUFFERID, nh.idFrom, (LPARAM)fname); - LuaExtension::Instance().OnDocOrderChanged(GUI::UTF8FromString(fname).c_str(), nh.idFrom, (int)nh.hwndFrom); + LuaExtension::Instance().OnDocOrderChanged(GUI::UTF8FromString(fname).c_str(), nh.idFrom, static_cast(reinterpret_cast(nh.hwndFrom))); return; case NPPN_SNAPSHOTDIRTYFILELOADED: // Note: hwndFrom is NULL SendNpp(NPPM_GETFULLPATHFROMBUFFERID, nh.idFrom, (LPARAM)fname); - LuaExtension::Instance().OnSnapshotDirtyFileLoaded(GUI::UTF8FromString(fname).c_str(), nh.idFrom); + LuaExtension::Instance().OnSnapshotDirtyFileLoaded(GUI::UTF8FromString(fname).c_str(), (uptr_t)nh.idFrom); return; } @@ -455,7 +455,7 @@ void editStartupScript() { const char *s = "-- Startup script\r\n-- Changes will take effect once Notepad++ is restarted\r\n\r\n"; DWORD dwBytesWritten; HANDLE h = CreateFile(buff, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); - WriteFile(h, s, strlen(s), &dwBytesWritten, NULL); + WriteFile(h, s, static_cast(strlen(s)), &dwBytesWritten, NULL); CloseHandle(h); } SendNpp(NPPM_DOOPEN, 0, (LPARAM)buff); diff --git a/src/LuaScript.vcxproj b/src/LuaScript.vcxproj index 9bf648e..42240ab 100644 --- a/src/LuaScript.vcxproj +++ b/src/LuaScript.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -22,28 +22,29 @@ {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D} LuaScript Win32Proj + 8.1 DynamicLibrary Unicode - v120 + v140_xp DynamicLibrary Unicode - v120 + v140_xp DynamicLibrary Unicode - v120 + v140_xp true DynamicLibrary Unicode - v120 + v140_xp true diff --git a/src/SciTE/IFaceTable.cpp b/src/SciTE/IFaceTable.cpp index 0afc22d..3ee3ac1 100644 --- a/src/SciTE/IFaceTable.cpp +++ b/src/SciTE/IFaceTable.cpp @@ -23,41 +23,26 @@ #include #include -const IFaceConstant *IFaceTable::FindConstant(const char *name) const { - int lo = 0; - int hi = constants.size() - 1; - do { - int idx = (lo+hi)/2; - int cmp = strcmp(name, constants[idx].name); - - if (cmp > 0) { - lo = idx + 1; - } else if (cmp < 0) { - hi = idx - 1; - } else { - return &constants[idx]; - } - } while (lo <= hi); +template +static typename const std::iterator_traits::value_type *binary_find(Iter begin, Iter end, const char *name) { + auto it = std::lower_bound(begin, end, name, [](const auto &lhs, const char *rhs) { + return strcmp(lhs.name, rhs) < 0; + }); - return nullptr; + if (it == end || strcmp(name, it->name) != 0) { + return nullptr; + } + else { + return &(*it); + } } -const IFaceFunction *IFaceTable::FindFunction(const char *name) const { - int lo = 0; - int hi = functions.size() - 1; - do { - int idx = (lo+hi)/2; - int cmp = strcmp(name, functions[idx].name); - if (cmp > 0) { - lo = idx + 1; - } else if (cmp < 0) { - hi = idx - 1; - } else { - return &functions[idx]; - } - } while (lo <= hi); +const IFaceConstant *IFaceTable::FindConstant(const char *name) const { + return binary_find(constants.cbegin(), constants.cend(), name); +} - return nullptr; +const IFaceFunction *IFaceTable::FindFunction(const char *name) const { + return binary_find(functions.cbegin(), functions.cend(), name); } const IFaceFunction *IFaceTable::FindFunctionByConstantName(const char *name) const { @@ -90,22 +75,7 @@ const IFaceFunction *IFaceTable::FindFunctionByValue(int value) const { } const IFaceProperty *IFaceTable::FindProperty(const char *name) const { - int lo = 0; - int hi = properties.size() - 1; - do { - int idx = (lo+hi)/2; - int cmp = strcmp(name, properties[idx].name); - - if (cmp > 0) { - lo = idx + 1; - } else if (cmp < 0) { - hi = idx - 1; - } else { - return &properties[idx]; - } - } while (lo <= hi); - - return nullptr; + return binary_find(properties.cbegin(), properties.cend(), name); } int IFaceTable::GetConstantName(int value, char *nameOut, unsigned nameBufferLen, const char *hint) const { @@ -116,7 +86,7 @@ int IFaceTable::GetConstantName(int value, char *nameOut, unsigned nameBufferLen // Look in both the constants table and the functions table. Start with functions. for (const auto &func : functions) { if (func.value == value) { - int len = static_cast(strlen(func.name)) + strlen(prefix); + int len = static_cast(strlen(func.name) + strlen(prefix)); if (nameOut && (static_cast(nameBufferLen) > len)) { strcpy(nameOut, prefix); strcat(nameOut, func.name); diff --git a/src/SciTE/LuaExtension.cpp b/src/SciTE/LuaExtension.cpp index d96b886..e195d55 100644 --- a/src/SciTE/LuaExtension.cpp +++ b/src/SciTE/LuaExtension.cpp @@ -997,7 +997,7 @@ static bool CallNamedFunction(const char *name, const char *varfmt, ...) { } va_end(vl); } - handled = call_function(luaState, varfmt != NULL ? strlen(varfmt) : 0); + handled = call_function(luaState, varfmt != NULL ? static_cast(strlen(varfmt)) : 0); // call_function removes the function for us, the key stays on the stack } } From 122c800ecb7fb71c7a49ce9bb42f7839b496c64c Mon Sep 17 00:00:00 2001 From: dail8859 Date: Thu, 20 Apr 2017 19:59:56 -0400 Subject: [PATCH 06/62] Change VS build output paths --- .gitignore | 2 ++ src/Lua.vcxproj | 16 ++++++++-------- src/LuaScript.vcxproj | 34 ++++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 61e8800..28a90c4 100644 --- a/.gitignore +++ b/.gitignore @@ -289,3 +289,5 @@ __pycache__/ LuaDist /docs_gen/Editor.lua +bin/ +src/build/ diff --git a/src/Lua.vcxproj b/src/Lua.vcxproj index 8afcded..edef34a 100644 --- a/src/Lua.vcxproj +++ b/src/Lua.vcxproj @@ -131,17 +131,17 @@ <_ProjectFileVersion>10.0.30319.1 - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ + ..\bin\$(Configuration)_$(Platform)\ + build\$(Configuration)_$(Platform)\$(ProjectName)\ false - $(Platform)\$(Configuration)\$(ProjectName)\ - $(Platform)\$(Configuration)\$(ProjectName)\ + ..\bin\$(Configuration)_$(Platform)\ + build\$(Configuration)_$(Platform)\$(ProjectName)\ false - $(Configuration)\$(ProjectName)\ - $(Configuration)\$(ProjectName)\ + ..\bin\$(Configuration)_$(Platform)\ + build\$(Configuration)_$(Platform)\$(ProjectName)\ true - $(Platform)\$(Configuration)\$(ProjectName)\ - $(Platform)\$(Configuration)\$(ProjectName)\ + ..\bin\$(Configuration)_$(Platform)\ + build\$(Configuration)_$(Platform)\$(ProjectName)\ true diff --git a/src/LuaScript.vcxproj b/src/LuaScript.vcxproj index 42240ab..3b23c54 100644 --- a/src/LuaScript.vcxproj +++ b/src/LuaScript.vcxproj @@ -69,19 +69,25 @@ <_ProjectFileVersion>10.0.30319.1 - bin\$(Configuration)\ - $(Configuration)\$(ProjectName)\ + ..\bin\$(Configuration)_$(Platform)\ + build\$(Configuration)_$(Platform)\$(ProjectName)\ false - bin\$(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\$(ProjectName)\ + ..\bin\$(Configuration)_$(Platform)\ + build\$(Configuration)_$(Platform)\$(ProjectName)\ false - bin\$(Configuration)\ - $(Configuration)\$(ProjectName)\ + ..\bin\$(Configuration)_$(Platform)\ + build\$(Configuration)_$(Platform)\$(ProjectName)\ true - bin\$(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\$(ProjectName)\ + ..\bin\$(Configuration)_$(Platform)\ + build\$(Configuration)_$(Platform)\$(ProjectName)\ true + + $(ProjectName)_64 + + + $(ProjectName)_64 + .\SciTE;.\lua\src;.\Dialogs;.\Npp;.\Utilities;.\;%(AdditionalIncludeDirectories) @@ -112,7 +118,7 @@ true $(OutDir)LuaScript.lib MachineX86 - $(Configuration)\Lua\;%(AdditionalLibraryDirectories) + $(SolutionDir)bin\$(Configuration)_$(Platform)\;%(AdditionalLibraryDirectories) copy "$(TargetPath)" "C:\Program Files (x86)\Notepad++\plugins" @@ -139,7 +145,7 @@ Lua.lib;shlwapi.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll + $(OutDir)$(ProjectName)_64.dll true Windows true @@ -147,7 +153,7 @@ false true $(OutDir)LuaScript.lib - $(Platform)\$(Configuration)\Lua\;%(AdditionalLibraryDirectories) + $(SolutionDir)bin\$(Configuration)_$(Platform)\;%(AdditionalLibraryDirectories) copy "$(TargetPath)" "C:\Program Files\Notepad++\plugins" @@ -178,7 +184,7 @@ true $(OutDir)LuaScript.lib MachineX86 - $(Configuration)\Lua\;%(AdditionalLibraryDirectories) + $(SolutionDir)bin\$(Configuration)_$(Platform)\;%(AdditionalLibraryDirectories) copy "$(TargetPath)" "C:\Program Files (x86)\Notepad++\plugins" @@ -200,14 +206,14 @@ Lua.lib;shlwapi.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll + $(OutDir)$(ProjectName)_64.dll true $(OutDir)LuaScript.pdb Windows false true $(OutDir)LuaScript.lib - $(Platform)\$(Configuration)\Lua\;%(AdditionalLibraryDirectories) + $(SolutionDir)bin\$(Configuration)_$(Platform)\;%(AdditionalLibraryDirectories) copy "$(TargetPath)" "C:\Program Files\Notepad++\plugins" From 3cf2d4b44d5b694f646b6425702ddefa18f6b1c5 Mon Sep 17 00:00:00 2001 From: dail8859 Date: Thu, 20 Apr 2017 19:13:35 -0400 Subject: [PATCH 07/62] Bump version to v0.7.0 --- README.md | 5 +- docs/classes/Editor.html | 47 ++++-- docs/classes/Match.html | 15 +- docs/classes/Notepad.html | 36 +++- docs/classes/Styler.html | 8 +- docs/examples/bookmark.lua.html | 8 +- docs/examples/highlightoccurrences.lua.html | 8 +- docs/examples/luaautoindent.lua.html | 19 ++- docs/examples/luasyntaxchecker.lua.html | 8 +- docs/examples/randomizelines.lua.html | 175 ++++++++++++++++++++ docs/examples/selectionaddnext.lua.html | 8 +- docs/examples/sessionmanager.lua.html | 8 +- docs/examples/stylecsv.lua.html | 8 +- docs/examples/stylecustom.lua.html | 8 +- docs/examples/visualstudiolinecopy.lua.html | 8 +- docs/index.html | 16 +- docs/topics/callbacks.md.html | 8 +- docs/topics/externalpluginsupport.md.html | 125 ++++++++++++++ docs_gen/config.ld | 2 +- src/Version.h | 8 +- 20 files changed, 458 insertions(+), 70 deletions(-) create mode 100644 docs/examples/randomizelines.lua.html create mode 100644 docs/topics/externalpluginsupport.md.html diff --git a/README.md b/README.md index 6558e4d..44ed55f 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,10 @@ Scripts can also register functions to be called when certain events occur, such The full API documentation can be found [here](http://dail8859.github.io/LuaScript/). Also be sure to check out the [examples](/examples/) directory. ## Development -The code has been developed using MSVC 2013. To compile the code: +The code has been developed using MSVC 2015. To compile the code: 1. Open the `LuaScript.sln` file -2. Select the `Win32` platform (x64 is currently experimental) -3. Press `F7` and that's it! +1. Press `F7` and that's it! For convenience, MSVC automatically copies the DLL into the Notepad++ plugin directory. diff --git a/docs/classes/Editor.html b/docs/classes/Editor.html index d2236c3..f0baa9e 100644 --- a/docs/classes/Editor.html +++ b/docs/classes/Editor.html @@ -23,7 +23,7 @@
    -Generated by LDoc 1.4.3 +generated by LDoc 1.4.6