The question is: how can you pass the selected text to external program?
The only way I see is the following: you need to save your selection to a temporary file, then pass this temporary file to your external program, and, finally, replace the selected text by results of your external program.
All you can do is to automatize this process in some way (writing new plugin, for example), but you still need to work with temporary files.
Regarding upper/lower subtitution, these functions work with internal Notepad++'s memory - you can not do this with ordinary external program.
So, your idea is interesting, but is not easy to implement.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It would be nice if CURRENT_WORD accepted much longer selections. At least when I try it after selecting a certain number of characters, it no longer contains anything. If the selection is small enough (?), it works fine.
CURRENT_WORD is a neat feature that I thought would work for my use. I'd like to "select" (SQL like) text, and have LogParser process it. If my selection is small enough it works great. But once I try to do anything more complex, it fails.
Can CURRENT_WORD be made much longer? Maybe CURRENT_SELECTION would be better?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To follow-up with more information on long CURRENT_WORD selections: after increasing the selection size a number of times, trying to find out how long a selection it will reliably accept, I'm often getting this message: "Notepad++ ... encountered a problem and needs to close. We are sorry for the inconvenience."
Then Notepad++ disappears.
Ouch. I hope this feature can get more attention.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hmm... Seems like a request to Don.
Regarding the modification of selection text, I can try to implement it in NppExec plugin.
For example, we can use such approach:
1) create new environment variable:
$(SELECTED_TEXT) which will handle any size of selected text
2) add new functions:
selection.save <file> which will save current selection to specified file
selection.read <file> which will replace current selection by file's content
selection.replace <text> which will replace current selection with specified text
selection.setpos <begin, end> which will set selection's position
Anyway, new features need some time. A lot of time for me, because now I don't have much free time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>So, your idea is interesting, but is not easy to implement.
It is not mine. I have seen this functionality in the "text editor" of old SUN Unix station with openwin, and I have used it a lot, because I found it very interesting too ! ;-)
Would it be possible to get the selected text in "input stream" instead of a static environment variable ?
Otherwise, your last propositions of functions seem to be a good help for me. I will be patient !
best regards
Roseline
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, SCI_SCI_GETSELTEXT is exactly what I meant - except one thing: current file can be UCS2 or UTF8. And our $(SELECTED_TEXT) variable must be an ANSI text, isn't it? That's why additional conversion between ANSI and UTF8 may be needed.
Or maybe it's better to implement an interface for any supported encoding? E.g.
sel.text - the same as sel.text_ansi
sel.text_ansi - current selection in ANSI encoding
sel.text_utf8 - current selection in UTF8 encoding
sel.text_ucs2le - current selection in UCS2LE encoding
sel.text_ucs2be - current selection in UCS2BE encoding
sel.save <file> - the same as sel.save_ansi
sel.save_ansi <file> - save selection in ANSI encoding
sel.save_utf8 <file> - save selection in UTF8 encoding
sel.save_ucs2le <file> - save selection in UCS2LE encoding
sel.save_ucs2be <file> - save selection in UCS2BE encoding
+ the same for sel.read <file> operations
+ the same for sel.replace <text> operations
You will get always bytes from Scintilla. In case of USC2 two for one char, in case of UTF8 1-3 and in case of ANSI one char ;). I have in HexEditor a convertion implemented. If you would like to have an example to convert, please let me know.
The decision of converting is IMO only dependend from Notepad. In any case there is only the need to convert from sel.text_xxx -> ANSI and vice versa if you want to replace text automatically.
BTW: + the same for sel.replace with RegEx could be also interesting
Best Regards
Jens
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't know lua, so I don't know if you can avoid the temp file song and dance. I often "echo" input to programs via a pipe. But, if the program is expecting a newline, I don't know a way around the temp file.
See if this is something you can use: consider using the Windows clipboard. If lua does not have a Windows clipboard module, perhaps use just enough of something else to read and write the clipboard, then shell out to lua.
Perl and Python both have Windows modules that read and write to the clipboard (I am sure RUby does as well):
use Win32::Clipboard; # Perl
import win32clipboard # Python
Perl and Python can run system commands, and read the output of system commands. Perl is particularly handy for this with its back-tick operator. Python, on the other hand, has an excellent interactive shell: I have a script that reads the clipboard, then remains in the shell ('-i' command line option). I have some predefined functions, one of which writes back to the clipboard. Then I can just enter Python commands in the shell to work with a string of text that came from the clipboard, and when I am finished, write it back to the clipboard and paste it into Notepad++ (or any other application, for that matter).
Perl, on the other hand, has the advantage of its built-in regular expression support, so I use it for find and replace. And Perl has a great module for formatting text (Text::Autoformat) which I use for most of my word-wrapping.
There are some tricky issues regarding line endings; I did a lot of trial and error, and I am not at all sure I have it right.
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
For personal use (and train), I develop in Perl a small program to indent program lines (for html language in a first step (language which use tags)).
I'd like to open with NPP a html program (to modify it for example), then select a zone and apply my program to re-indent my modifications.
So my question is : is it possible to apply an external program to a selected area in NPP ? (the title ;-)
Thanks for advance
Roseline
What about this environment variable: $(CURRENT_WORD) ? Refer to http://notepad-plus.sourceforge.net/uk/run-HOWTO.php for more details.
I can select all the file in absolute.
This variable does not contain enough characters. It is too short for my need.
And I want to replace my selected text by the result of my external program. I don't know how to do that with this variable.
How does the upper/lower subtitution work, for example ?
The question is: how can you pass the selected text to external program?
The only way I see is the following: you need to save your selection to a temporary file, then pass this temporary file to your external program, and, finally, replace the selected text by results of your external program.
All you can do is to automatize this process in some way (writing new plugin, for example), but you still need to work with temporary files.
Regarding upper/lower subtitution, these functions work with internal Notepad++'s memory - you can not do this with ordinary external program.
So, your idea is interesting, but is not easy to implement.
It would be nice if CURRENT_WORD accepted much longer selections. At least when I try it after selecting a certain number of characters, it no longer contains anything. If the selection is small enough (?), it works fine.
CURRENT_WORD is a neat feature that I thought would work for my use. I'd like to "select" (SQL like) text, and have LogParser process it. If my selection is small enough it works great. But once I try to do anything more complex, it fails.
Can CURRENT_WORD be made much longer? Maybe CURRENT_SELECTION would be better?
Thanks
To follow-up with more information on long CURRENT_WORD selections: after increasing the selection size a number of times, trying to find out how long a selection it will reliably accept, I'm often getting this message: "Notepad++ ... encountered a problem and needs to close. We are sorry for the inconvenience."
Then Notepad++ disappears.
Ouch. I hope this feature can get more attention.
Hmm... Seems like a request to Don.
Regarding the modification of selection text, I can try to implement it in NppExec plugin.
For example, we can use such approach:
1) create new environment variable:
$(SELECTED_TEXT) which will handle any size of selected text
2) add new functions:
selection.save <file> which will save current selection to specified file
selection.read <file> which will replace current selection by file's content
selection.replace <text> which will replace current selection with specified text
selection.setpos <begin, end> which will set selection's position
Anyway, new features need some time. A lot of time for me, because now I don't have much free time.
>So, your idea is interesting, but is not easy to implement.
It is not mine. I have seen this functionality in the "text editor" of old SUN Unix station with openwin, and I have used it a lot, because I found it very interesting too ! ;-)
Would it be possible to get the selected text in "input stream" instead of a static environment variable ?
Otherwise, your last propositions of functions seem to be a good help for me. I will be patient !
best regards
Roseline
Hello Vitaly,
there is no need to change this in Notepad++. You could provide this macro in NppExec easy. Add only this lines:
UINT uStartPos = ::SendMessage(nppData.main/secondWindow, SCI_GETSELECTIONSTART, 0, 0);
UINT uEndPos = ::SendMessage(nppData.main/secondWindow, SCI_GETSELECTIONEND, 0, 0);
UINT uLength = uEndPos - uStartPos + 1;
char* pszText = new[uLength];
::SendMessage(nppData.main/secondWindow, SCI_SCI_GETSELTEXT, 0, (LPARAM)pszText);
...
delete[] pszText;
You have only to request from Notepad the current selected Scintilla handle.
Best Regards
Jens
Yes, SCI_SCI_GETSELTEXT is exactly what I meant - except one thing: current file can be UCS2 or UTF8. And our $(SELECTED_TEXT) variable must be an ANSI text, isn't it? That's why additional conversion between ANSI and UTF8 may be needed.
Or maybe it's better to implement an interface for any supported encoding? E.g.
sel.text - the same as sel.text_ansi
sel.text_ansi - current selection in ANSI encoding
sel.text_utf8 - current selection in UTF8 encoding
sel.text_ucs2le - current selection in UCS2LE encoding
sel.text_ucs2be - current selection in UCS2BE encoding
sel.save <file> - the same as sel.save_ansi
sel.save_ansi <file> - save selection in ANSI encoding
sel.save_utf8 <file> - save selection in UTF8 encoding
sel.save_ucs2le <file> - save selection in UCS2LE encoding
sel.save_ucs2be <file> - save selection in UCS2BE encoding
+ the same for sel.read <file> operations
+ the same for sel.replace <text> operations
In this case you could use:
non_unicode_app.exe /params sel.text_ansi
unicode_app.exe /params sel.text_ucs2le
Anyway, it is just ideas so far.
And what is "input stream"? What is the difference between "input stream" and a command-line input parameter?
You will get always bytes from Scintilla. In case of USC2 two for one char, in case of UTF8 1-3 and in case of ANSI one char ;). I have in HexEditor a convertion implemented. If you would like to have an example to convert, please let me know.
The decision of converting is IMO only dependend from Notepad. In any case there is only the need to convert from sel.text_xxx -> ANSI and vice versa if you want to replace text automatically.
BTW: + the same for sel.replace with RegEx could be also interesting
Best Regards
Jens
Any follow-up thoughts on this?
I'm wanting to pipe selected text to lua for testing. I can easily run the whole lua file via a saved Run command:
cmd /k lua "$(FULL_CURRENT_PATH)"
I was trying to test only selected text by pushing it to a temp file with something like this:
cmd /k "$(CURRENT_WORD) > E:\lua\_test.lua"
DOS or CURRENT_WORD won't recognize line breaks however, so this quick little concept is dead in the water.
Any thoughts?
I don't know lua, so I don't know if you can avoid the temp file song and dance. I often "echo" input to programs via a pipe. But, if the program is expecting a newline, I don't know a way around the temp file.
See if this is something you can use: consider using the Windows clipboard. If lua does not have a Windows clipboard module, perhaps use just enough of something else to read and write the clipboard, then shell out to lua.
Perl and Python both have Windows modules that read and write to the clipboard (I am sure RUby does as well):
use Win32::Clipboard; # Perl
import win32clipboard # Python
Perl and Python can run system commands, and read the output of system commands. Perl is particularly handy for this with its back-tick operator. Python, on the other hand, has an excellent interactive shell: I have a script that reads the clipboard, then remains in the shell ('-i' command line option). I have some predefined functions, one of which writes back to the clipboard. Then I can just enter Python commands in the shell to work with a string of text that came from the clipboard, and when I am finished, write it back to the clipboard and paste it into Notepad++ (or any other application, for that matter).
Perl, on the other hand, has the advantage of its built-in regular expression support, so I use it for find and replace. And Perl has a great module for formatting text (Text::Autoformat) which I use for most of my word-wrapping.
There are some tricky issues regarding line endings; I did a lot of trial and error, and I am not at all sure I have it right.
Mike
I'll give it a shot! Thanks for the Clipboard suggestion Mike