Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

WAD Anomaly With %_selected

Jun
562
4
I just noticed something that is not right with the variable _selected for use in toolbar buttons. To illustrate the problem, I have created a button labeled TEST with the following command to be sent to the current tab:

esc "echo %%@quote[%_selected]" enter

It clears the command line and then echos the text selected in the tab window with unquoted text to be quoted. In the following, I created a line of quoted text, selected it, and then used my TEST button. Note the funny thing that happened with the selected text. The quotation marks got messed up, and spaces in the text were removed.

TCC(30.00.22): C:\>echo "this is a test"
"this is a test"

TCC(30.00.22): C:\>echo %@quote[thisisatest"]"
TCC: Syntax error "@quote[thisisatest"]""

There should have been no problem; the command works fine if the text is entered manually.

TCC(30.00.22): C:\>echo %@quote["this is a test"]
"this is a test"

It appears that some processing is being done on the contents of _selected before it is put into the command line. Another way to see this is to select some text that contains a percent sign. Variable expansion seems to be performed on the selected text before _selected is set.

TCC(30.00.22): C:\>echo `%junkvar`
%junkvar

TCC(30.00.22): C:\>echo %@quote[]
ECHO is OFF

Even if the variable is defined, _selected seems to get nothing.

TCC(30.00.22): C:\>set junkvar
value of junkvar

TCC(30.00.22): C:\>echo %@quote[]
ECHO is OFF

However, if I select %_ip in the TCC window, its value is stored in _selected.

TCC(30.00.22): C:\>echo `%_ip` = %_ip
%_ip = 192.168.1.9

TCC(30.00.22): C:\>echo %@quote[ 192.168.1.9]
" 192.168.1.9"

I just launched Take Command 27, and the behavior seems to be the same there. I guess it is something I just never tripped over before.

TCC(27.01.24): C:\>echo "this is a test"
"this is a test"

TCC(27.01.24): C:\>echo %@quote[thisisatest"]"
TCC: Syntax error "@quote[thisisatest"]""

P. S. Rex, I just noticed that in version 30, %_ip returns a string with a leading space, which it did not do in version 27.

TCC(27.01.24): C:\>echo "%_ip"
"192.168.1.9"

TCC(30.00.22): C:\>echo "%_ip"
" 192.168.1.9"

Was that intentional?
 
I just noticed something that is not right with the variable _selected for use in toolbar buttons. To illustrate the problem, I have created a button labeled TEST with the following command to be sent to the current tab:

esc "echo %%@quote[%_selected]" enter

It clears the command line and then echos the text selected in the tab window with unquoted text to be quoted. In the following, I created a line of quoted text, selected it, and then used my TEST button. Note the funny thing that happened with the selected text. The quotation marks got messed up, and spaces in the text were removed.

There should have been no problem; the command works fine if the text is entered manually.

WAD - The problem is either with your syntax or your expectations.

What the button is actually doing is calling the variable expansion routine which reads the selected text and makes the substitution. What you now have is the string:

esc "echo %@quote["this is a test"]" enter

(since you used two %'s for @QUOTE - not sure what your intentions were there).

Take Command then takes that string and passes it to the routine to send keystrokes to the tab. That routine has no knowledge of variable expansion (and never has), so it thinks you're trying to send:

esc(the escape character)
echo %@quote[(because that's where the first double quotes match up)
thisisatest(because there are no double quotes around this string, characters are sent as-is and spaces are ignored as delimiters)
](because this was double-quoted)
enter
 
Thanks for the explanation. It's a real struggle to deal with characters that have special meaning, especially in multiple ways. I did realize that the extra quotation marks had something to do with the problem; I just didn't understand the details.

I try very hard to avoid file names with spaces in them, but sometimes I have no control. Now I'm trying the following approach for feeding file names to alias commands in toolbar buttons. I changed the button definition for my text editor, for example, to

esc "edit %%@quote%@unquote[[%_selected]]" enter

Now if the selected text is surrounded by quotation marks, %@unquote[] removes them. Then the command line ends up with %@quote[] around the unquoted text, which puts the quotation marks back, if needed, when the command line runs (when the key stack output supplies 'enter'). It seems to be working (except for one program that, I discovered, seems unable to handle quoted file names).

An alternative is to never select quoted text. However, with my INI file name displayed on the screen as

"C:\ProgramData\JP Software\Take Command 30\TCMD.INI"

I can now select either the entire string, including the quotation marks, or only the part inside the quotation marks, and the file opens successfully.

Another approach might make use of the function @sfn[]. I just discovered that the argument does not have to be quoted. Aha, that solved the problem with the program that cannot handle quoted file names. It accepts the short file name.
 
Back
Top