hi.
I want to use SCI command which selects a whole word from the current caret position - actually- imitating double click behavior on a word.
any ideas how do that with SCI?
moreover, I want to be able to use the word for later use and add more character to it.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
// position of caret (or start of selection)
SCI_SENDMSG SCI_GETSELECTIONSTART
set pos = $(MSG_RESULT)
// start position of nearest word
SCI_SENDMSG SCI_WORDSTARTPOSITION $(pos) 1
set word_start = $(MSG_RESULT)
// end position of nearest word
SCI_SENDMSG SCI_WORDENDPOSITION $(word_start) 1
set word_end = $(MSG_RESULT)
// set selection
SCI_SENDMSG SCI_SETSEL $(word_start) $(word_end)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks DV!
now i only need to get selected text and i can't seem to do that with: SCI_GETSELTEXT.
I don't understand the explanation in scintillaDoc.
Please assist.
Thanks :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As "help sci_sendmsg" says, NppExec reserves a buffer of (4 MB)*sizeof(char) for @"<str>". So you don't need to care about the buffer allocation when requesting text from Scintilla. (Additionally, if the buffer of 4*1024*1024 symbols is not OK for you, you can specify the value of 'SendMsg_MaxBufLength' - see "NppExec_TechInfo.txt").
So, to get the text from Scintilla, you just need to specify a "pointer to string" in terms of NppExec which has the following form:
@"initial text of the string"
I.e.
// get selected text
SCI_SENDMSG SCI_GETSELTEXT 4000000 @""
// do something with selected text stored in $(MSG_LPARAM)
echo $(MSG_LPARAM)
Explanation:
We have the following description of SCI_GETSELTEXT:
SCI_GETSELTEXT(<unused>, char *text)
It means the first parameter of SCI_SENDMSG should be SCI_GETSELTEXT,
the second parameter - WPARAM - is unused integer value,
and the third parameter - LPARAM - is a pointer to string buffer.
So we pass 4000000 as unused WPARAM (just in case, if Scintilla will require it in future as buffer size - you can specify up to 4*1024*1024-1) and @"" as LPARAM (it means NppExec creates a string buffer of 4*1024*1024 symbols and passes it to Scintilla).
As a result, $(MSG_LPARAM) will contain the selected text.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi dv.
thanks again for helping me out.
is there a page where there are examples of using SCI_SENDMSG commands?
I'm lost with how to use other commands.
I want to imitate this behavior:
1. select a whole word in the cursor position - save it in a variable "SEARCH_CLASS"
2. add the characters " =" to the "SEARCH_CLASS".
3. search for the term in SEARCH_CLASS variable.
I wanted to learn how to use SCI commands through this.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In NppExec's Manual: see "4.6.2. Calculating" (at the end) and "4.6.6. Grab Console output to new editor pane".
IMHO (in my horrific opinion) it's enough to understand the idea, especially together with the examples above in this topic.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi dv.
the manual is very details. However, I couldn't find any reference for performing a search or a reference for sepcial sci messages such as SCI_FINDTEXT - which suppose to get a second parameter *ttf (type of sci_texttofind).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, SCI_FINDTEXT requires a structure as LPARAM, so this message can not be handled by NppExec. Instead, you can use pairs of SCI_SEARCHANCHOR and SCI_SEARCHNEXT - as described inside ScintillaDoc.html. As for WPARAM of SCI_SEARCHNEXT, you can use 0 or set the sum of the search-flags e.g.:
set searchFlags ~ SCFIND_WHOLEWORD + SCFIND_MATCHCASE
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi dv.
sorry for nudging - i can't seem to succeed in it:
SCI_SENDMSG SCI_SEARCHANCHOR
SCI_SENDMSG SCI_SEARCHNEXT "$(MSG_LPARAM)" 0
I'm missing with these to complete my script:
2. add the characters " =" to the "SEARCH_CLASS".
3. search for the term in SEARCH_CLASS variable and go to the result line
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This command sets the following variables:
$(MSG_RESULT) - LRESULT as int
$(MSG_WPARAM) - int or string for @<int> or @"<str>", otherwise empty
$(MSG_LPARAM) - int or string for @<int> or @"<str>", otherwise empty
It means that each SCI_SENDMSG (or NPP_SENDMSG) either sets or empties these three variables. So, if you want to keep the value (in our case it is MSG_LPARAM), you should assign (copy) it to another user variable e.g.
SCI_SENDMSG SCI_GETSELTEXT 4000000 @""
set SELECTED_TEXT = $(MSG_LPARAM)
Stupid? Yes, but if we would keep the values of MSG_LRESULT, WPARAM and LPARAM between different calls to SCI_SENDMSG, it would be incorrect with respect to SendMessage behaviour. (You actually send a new message, and I think it should affect the three return variables).
Now, to add " =", you just use
$(SELECTED_TEXT) " ="
to continue with searching.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi dv.
I managed to handle with adding the characters( my mistake in the reply when adding step 2).
however, i cannot handle the SCI search operation as I tried with:
SCI_SENDMSG SCI_SEARCHANCHOR
SCI_SENDMSG SCI_SEARCHNEXT "$(MSG_LPARAM)" 0
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Seems either my explanations are bad or you are completely frustrating by NppExec.
OK, here is the final part of the script which searches for a selected word plus tariling " =".
// get selected text
SCI_SENDMSG SCI_GETSELTEXT 4000000 @""
set text2find = $(MSG_LPARAM) =
// set selection after current selected text
SCI_SENDMSG SCI_GETSELECTIONEND
SCI_SENDMSG SCI_SETSEL $(MSG_RESULT) $(MSG_RESULT)
// search for the text
SCI_SENDMSG SCI_SEARCHANCHOR
SCI_SENDMSG SCI_SEARCHNEXT 0 "$(text2find)"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
dv - thank you very much.
you've been very helpful thus far.
it's the integration of scintilla commands and NPPEXE that is hard (for me) to understand.
This is the final script which finds a javascript class declaration in the current file:
NPP_CONSOLE0// position of caret (or start of selection) setjsClassPreviousLine=$(CURRENT_LINE)SCI_SENDMSGSCI_GETSELECTIONSTARTsetpos=$(MSG_RESULT)// start position of nearest word SCI_SENDMSGSCI_WORDSTARTPOSITION$(pos)1setword_start=$(MSG_RESULT)// end position of nearest word SCI_SENDMSGSCI_WORDENDPOSITION$(word_start)1setword_end=$(MSG_RESULT)// set selection SCI_SENDMSGSCI_SETSEL$(word_start)$(word_end)// get selected textSCI_SENDMSGSCI_GETSELTEXT4000000@""settext2find=$(MSG_LPARAM)// set selection after current selected textSCI_SENDMSGSCI_GETSELECTIONENDSCI_SENDMSGSCI_SETSEL$(MSG_RESULT)$(MSG_RESULT)// search for the textSCI_SENDMSGSCI_GOTOLINE0SCI_SENDMSGSCI_SEARCHANCHORSCI_SENDMSGSCI_SEARCHNEXT0"$(text2find) ="SCI_SENDMSGSCI_SCROLLCARET
Thanks again.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi.
I want to use SCI command which selects a whole word from the current caret position - actually- imitating double click behavior on a word.
any ideas how do that with SCI?
moreover, I want to be able to use the word for later use and add more character to it.
Thanks.
I believe it must be something like this:
// position of caret (or start of selection)
SCI_SENDMSG SCI_GETSELECTIONSTART
set pos = $(MSG_RESULT)
// start position of nearest word
SCI_SENDMSG SCI_WORDSTARTPOSITION $(pos) 1
set word_start = $(MSG_RESULT)
// end position of nearest word
SCI_SENDMSG SCI_WORDENDPOSITION $(word_start) 1
set word_end = $(MSG_RESULT)
// set selection
SCI_SENDMSG SCI_SETSEL $(word_start) $(word_end)
thanks DV!
now i only need to get selected text and i can't seem to do that with: SCI_GETSELTEXT.
I don't understand the explanation in scintillaDoc.
Please assist.
Thanks :-)
As "help sci_sendmsg" says, NppExec reserves a buffer of (4 MB)*sizeof(char) for @"<str>". So you don't need to care about the buffer allocation when requesting text from Scintilla. (Additionally, if the buffer of 4*1024*1024 symbols is not OK for you, you can specify the value of 'SendMsg_MaxBufLength' - see "NppExec_TechInfo.txt").
So, to get the text from Scintilla, you just need to specify a "pointer to string" in terms of NppExec which has the following form:
@"initial text of the string"
I.e.
// get selected text
SCI_SENDMSG SCI_GETSELTEXT 4000000 @""
// do something with selected text stored in $(MSG_LPARAM)
echo $(MSG_LPARAM)
Explanation:
We have the following description of SCI_GETSELTEXT:
SCI_GETSELTEXT(<unused>, char *text)
It means the first parameter of SCI_SENDMSG should be SCI_GETSELTEXT,
the second parameter - WPARAM - is unused integer value,
and the third parameter - LPARAM - is a pointer to string buffer.
So we pass 4000000 as unused WPARAM (just in case, if Scintilla will require it in future as buffer size - you can specify up to 4*1024*1024-1) and @"" as LPARAM (it means NppExec creates a string buffer of 4*1024*1024 symbols and passes it to Scintilla).
As a result, $(MSG_LPARAM) will contain the selected text.
Hi dv.
thanks again for helping me out.
is there a page where there are examples of using SCI_SENDMSG commands?
I'm lost with how to use other commands.
I want to imitate this behavior:
1. select a whole word in the cursor position - save it in a variable "SEARCH_CLASS"
2. add the characters " =" to the "SEARCH_CLASS".
3. search for the term in SEARCH_CLASS variable.
I wanted to learn how to use SCI commands through this.
Thanks.
In NppExec's Console, type:
help sci_sendmsg
and also:
help npp_sendmsg
and also:
help help
In NppExec's Manual: see "4.6.2. Calculating" (at the end) and "4.6.6. Grab Console output to new editor pane".
IMHO (in my horrific opinion) it's enough to understand the idea, especially together with the examples above in this topic.
hi dv.
the manual is very details. However, I couldn't find any reference for performing a search or a reference for sepcial sci messages such as SCI_FINDTEXT - which suppose to get a second parameter *ttf (type of sci_texttofind).
Yes, SCI_FINDTEXT requires a structure as LPARAM, so this message can not be handled by NppExec. Instead, you can use pairs of SCI_SEARCHANCHOR and SCI_SEARCHNEXT - as described inside ScintillaDoc.html. As for WPARAM of SCI_SEARCHNEXT, you can use 0 or set the sum of the search-flags e.g.:
set searchFlags ~ SCFIND_WHOLEWORD + SCFIND_MATCHCASE
Hi dv.
sorry for nudging - i can't seem to succeed in it:
SCI_SENDMSG SCI_SEARCHANCHOR
SCI_SENDMSG SCI_SEARCHNEXT "$(MSG_LPARAM)" 0
I'm missing with these to complete my script:
2. add the characters " =" to the "SEARCH_CLASS".
3. search for the term in SEARCH_CLASS variable and go to the result line
As "help sci_sendmsg" says:
It means that each SCI_SENDMSG (or NPP_SENDMSG) either sets or empties these three variables. So, if you want to keep the value (in our case it is MSG_LPARAM), you should assign (copy) it to another user variable e.g.
SCI_SENDMSG SCI_GETSELTEXT 4000000 @""
set SELECTED_TEXT = $(MSG_LPARAM)
Stupid? Yes, but if we would keep the values of MSG_LRESULT, WPARAM and LPARAM between different calls to SCI_SENDMSG, it would be incorrect with respect to SendMessage behaviour. (You actually send a new message, and I think it should affect the three return variables).
Now, to add " =", you just use
$(SELECTED_TEXT) " ="
to continue with searching.
hi dv.
I managed to handle with adding the characters( my mistake in the reply when adding step 2).
however, i cannot handle the SCI search operation as I tried with:
SCI_SENDMSG SCI_SEARCHANCHOR
SCI_SENDMSG SCI_SEARCHNEXT "$(MSG_LPARAM)" 0
Seems either my explanations are bad or you are completely frustrating by NppExec.
OK, here is the final part of the script which searches for a selected word plus tariling " =".
// get selected text
SCI_SENDMSG SCI_GETSELTEXT 4000000 @""
set text2find = $(MSG_LPARAM) =
// set selection after current selected text
SCI_SENDMSG SCI_GETSELECTIONEND
SCI_SENDMSG SCI_SETSEL $(MSG_RESULT) $(MSG_RESULT)
// search for the text
SCI_SENDMSG SCI_SEARCHANCHOR
SCI_SENDMSG SCI_SEARCHNEXT 0 "$(text2find)"
dv - thank you very much.
you've been very helpful thus far.
it's the integration of scintilla commands and NPPEXE that is hard (for me) to understand.
This is the final script which finds a javascript class declaration in the current file:
Thanks again.