How to use SCI_GETTEXTRANGE in NppExec script?
-
Hi!
Please can anybody help with syntax, how to use SCI_GETTEXTRANGE in NppExec script?
If file is:abcdefghijklmnopqrstuvw
How to get “defghi” i.e. text range 4…9 (or 3…8 if 0-based)?
Regards
Andi -
I am not sure that’s possible. SCI_GETTEXTRANGE uses the Sci_TextRange structure as an in/out in the LPARAM position. (BTW: Scintilla recommends the SCI_GETTEXTRANGEFULL and Sci_TextRangeFull instead, to ensure it’s always 64bit compatible.)
I tried using
set local str_range_min ~ strfromhex 03 00 00 00 00 00 00 00 set local str_range_max ~ strfromhex 09 00 00 00 00 00 00 00 set local str_buffer_extrachar ~ strfromhex 40 00 40 00 40 00 40 00 40 00 40 00 40 00 40 00 40 00 40 00 set local struct_textrangefull = $(str_range_min)$(str_range_max)$(str_buffer_extrachar)
to set up a structure that has 64bit integers for the min and max positions, and then 10 wide characters (20 bytes) for the resulting string… but with the NUL bytes, I am not sure that the “struct” has the right number of bytes, because the “string” may have ended at the first NUL thus causing the structure to not contain all 36 bytes.
but
sci_sendmsg SCI_GETTEXTRANGEFULL 0 @"$(struct_textrangefull)" echo echo $(MSG_LPARAM)
doesn’t output anything… and I think that’s the right syntax for sending the reference to the “string” and then getting back the contents.
If you don’t care about keeping the active text the same as it was, you could do:
================ READY ================ sci_sendmsg SCI_SETSELECTIONSTART 3 sci_sendmsg SCI_SETSELECTIONEND 9 sci_sendmsg SCI_GETSELTEXT 0 @"" echo $(MSG_LPARAM) SCI_SENDMSG: SCI_SETSELECTIONSTART 3 SCI_SENDMSG: SCI_SETSELECTIONEND 9 SCI_SENDMSG: SCI_GETSELTEXT 0 @"" defghi ================ READY ================
Or you could use the TARGET features:
================ READY ================ sci_sendmsg SCI_SETTARGETRANGE 3 9 sci_sendmsg SCI_GETTARGETTEXT 0 @"" echo $(MSG_LPARAM) SCI_SENDMSG: SCI_SETTARGETRANGE 3 9 SCI_SENDMSG: SCI_GETTARGETTEXT 0 @"" defghi ================ READY ================
Note: for ranges, the “start” is 0-based, so a start of 3 will make
d
the first character. The “end” is actually the 0-based for the character after the end (which is equivalent to the 1-based for the character at the end), so I used 3 to 9 to get characters at 0-based positions 3,4,5,6,7,8.If you really need SCI_GETTEXTRANGE, rather than one of the alternatives I showed, I don’t know how to make it work (and I don’t know whether the problem is the NUL bytes or that I don’t know how to extract the string’s characters back out of the structure that ended up in
$(MSG_LPARAM)
). I know that @michael-vincent uses NppExec to a lot more depth than I do, so he may have insight. Also, the author, @vitalli-dovgan, occasionally looks at the forum, so I’m @-mentioning him and he might respond. -
Thanks for such a thorough investigation.
Knowing that something is impossible is better than assuming it may be.
The alternative with TARGET suits me very well, I’ll take it.Thank you!