Discussion:
[Notepad-plus-plus] [notepad-plus - Open Discussion] Scripting Notepad++ with javascript
SourceForge.net
2008-07-13 13:40:23 UTC
Permalink
Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=5093153
By: d-wachss

I don't know if this will help others, but it made my life much easier.
I was frustrated with the limitations of the macro system, but didn't want to
program my own plugins for simple things, but I realized that the Run menu will
run anything that you can use in Shell.Run
(http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx), including script
files for Windows Script Host, and that script can use SendKeys
(http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx) to communicate
back to Notepad++.

So, for example, a simple script to wrap text in a <span> tag would be:

var s = WScript.Arguments(0);
WScript.CreateObject("WScript.Shell").SendKeys('<span>' + s + '</span>');

Save it as a .js file (say, "span.js") and enter the following in the Run...
dialog:

"path/to/span.js" "$(CURRENT_WORD)"

and save it, and voila! instant javascript macro.

Obviously, this is more useful with more sophisticated scripts, and you have
to read the SendKeys documentation for the special characters and escape codes.
You probably want to include a line like

s = s.replace(/([[+^%{}\]])/g, '{$1}').replace('\n', '{ENTER}').replace('\t',
'{TAB}');

to avoid problems.

You can use any language that WSH understands, like VBScript or even Perl
(http://www.xav.com/perl/Components/Windows/PerlScript.html)



______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=331753
SourceForge.net
2008-07-13 13:48:18 UTC
Permalink
Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=5093160
By: nobody

OMG, this is amazing, this should go right to the Notepad++ features/documentation,
along with some useful scripts.

______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=331753
SourceForge.net
2008-07-13 16:32:03 UTC
Permalink
Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=5093414
By: d-wachss

Playing with this I notice that $(CURRENT_WORD) uses \r\n for the line separator,
which gets turned into two separate line endings. Also, the 'replace's should
be global.

So the string should be
s = s.replace(/([[+^%{}\]])/g, '{$1}').replace(/\r/g,'').replace(/\n/g,
'{ENTER}').replace(/\t/g, '{TAB}');

______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=331753
SourceForge.net
2008-07-13 16:52:38 UTC
Permalink
This post might be inappropriate. Click to display it.
SourceForge.net
2008-07-15 06:47:50 UTC
Permalink
Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=5096916
By: nobody

interest.
but when i follow your instruction nothing happen to the selected word. i dont
know why.

______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=331753
Stas
2015-01-15 15:28:32 UTC
Permalink
Codelobster works better for me: http://www.codelobster.com

Loading...