[Script] WhiteSpaceCtxMenu

Discuss and share scripts and script files...
bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: [Script] WhiteSpaceCtxMenu

Post by bdeshi »

the middledots are spaces<br />the horizontal lines are tabs
the middledots are spaces
the horizontal lines are tabs
2015-07-15_112549.png (2.29 KiB) Viewed 3890 times
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: [Script] WhiteSpaceCtxMenu

Post by highend »

Whitespaces:
Unbenannt.png
Unbenannt.png (938 Bytes) Viewed 3889 times
Highlighted trailing whitespaces:
Unbenannt1.png
Unbenannt1.png (647 Bytes) Viewed 3889 times
A plugin to highlight trailing spaces:
https://github.com/SublimeText/TrailingSpaces
One of my scripts helped you out? Please donate via Paypal

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

klownboy wrote::eh:
highend wrote:You have a trailing space at the end of this line...
2 days ago here http://www.xyplorer.com/xyfc/viewtopic. ... 75#p126058 I said,
When copying/pasting make sure you don't have extra spaces in there as you did after the initial heredoc statement.
Why, because I spotted one. :(
At the end of line 8, if so I removed that and it further broke the script ?

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hi CookieMonster, it was exactly the same space that highend referred to $psd = <<<PSD . Certainly removing it wouldn't have further broken the script. Something else did I would imagine.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

klownboy wrote:Hi CookieMonster, it was exactly the same space that highend referred to $psd = <<<PSD . Certainly removing it wouldn't have further broken the script. Something else did I would imagine.
I'm sorry but the :idea: lightbulb is not going off in my head; as to this white space issue, if you could explain a little more as to the problem related to the white space problem in the script that you guys have been telling me numerous times, I would appreciate it. :)

To me the script looks fine, I'm looking at the script though Javascript eyes :) HighEnd and you KlownBoy are telling me, no, no, no you have white spaces :) :veryconfused:

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: [Script] WhiteSpaceCtxMenu

Post by bdeshi »

Please post the script in it's current state.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hey CookieMonster, I initially mentioned be careful on spaces after the heredoc was on July 11 (5 days ago). I would think between all the comments and posts since then this would not be an issue any longer. I only re-mentioned it since highend said the same thing a few days ago...hopefully, it's all fixed now and working properly. Only worry about what you have for a script at this point. Is it working alright for you? If not, as Sammay suggested, post it. And by the way, :)
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

Code: Select all

/*** text file menu ***/
$txt = <<<DOC
"NotePad++|C:\Tools\NotePad++\notepad++.exe" openwith "D:\Tools\NotePad++\notepad++.exe";
"PSPad|C:\Tools\PSPad\PSPad.exe" openwith "D:\Tools\PSPad\PSPad.exe";
"Notepad|C:\Windows\notepad.exe" openwith "C:\Windows\notepad.exe";
DOC;

$psd =<<<PSD 
"Photoshop|C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe" openwith "C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe";
PSD;

   if(exists("<selitem>") == 1) {
   $selext = getpathcomponent("<selitem>", "ext");
        if(gettokenindex($selext, "ini|txt|nfo|inf|reg|ps1|vbs", '|', 'i')) {load "$txt", , s; end(1);}   //load textfile menu
        elseif($selext LikeI "xys") {load("<selitem>"); end(1);}  //no menu - example showing how you can automatically run an XY script on a right click on white
        elseif($selext LikeI "ahk") {openwith "C:\Windows\notepad.exe"; end(1);}   //no menu - example to open an AHK file for editing
        elseif($selext LikeI "psd") {openwith "C:\Program Files\Adobe\Adobe Photoshop CC 2015\Photoshop.exe"; end(1);}
        else {#550; end(1);}
   }
   else {
        #550
        }
The script, once again :)

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hey again CookieMonster, if you click Select all above the code box that you just posted or simply highlight the text, you'll see there's an extra space after "$psd =<<<PSD ". Compare it to the heredoc for txt files, you'll see no space after "$txt = <<<DOC". Is what you posted working for you or not?
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: [Script] WhiteSpaceCtxMenu

Post by highend »

NO TWO NORMAL CODE LINES ARE ALLOWED TO BE NON INDENTED...

There are exceptions,
BUT YOUR SCRIPT DOESN'T CONTAIN ANY OF THEM (apart from what's inside the two heredocs).

I'm shouting? For a reason (it was correct beforehand...)

Now go and figure out what's wrong in your script!
One of my scripts helped you out? Please donate via Paypal

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

I really do believe this time I got it, let me tinker with this for a bit, yes, I will post my results soon ! I'm heading out the door so soon will be a little while :)

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hey highend I noticed what you mentioned also. I then went to the help file and noticed Don did not indent his first example. The second example in help is indented. I always indent my heredocs unless it's using the alternate heredoc syntax #<<< . His first example in the help file does work with or without the indent. Regardless of my confusion with the help file, I should have went ahead and mentioned that in my post as well. OK, it's because it's only one heredoc - one line of code not indented that it works if there two it will not work. I think Don should have indented that first example even if just for consistently - it can be misleading?
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: [Script] WhiteSpaceCtxMenu

Post by highend »

Hi Ken,
I then went to the help file and noticed Don did not indent his first example
Because it doesn't need to be indented as long as no other code is involved.
The second example in help is indented
Because it needs to be :)
OK, it's because it's only one heredoc - one line of code not indented that it works if there two it will not work. I think Don should have indented that first example even if just for consistently - it can be misleading?
I don't find it misleading. The second "real" line (echo $str;) is indented.

The general rule is in the help file as well:
Multi-line Scripts and Multi-Scripts

A script can have more than one line (multi-line script), and a script resource can have more than one script (multi-script). There is one important formatting rule for multi-line scripts:

In a multi-line script all lines apart from the first line have to be indented by at least one space.
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

highend wrote:Because it doesn't need to be indented as long as no other code is involved.
Yeah, I realize that now. It's the general rule for XY scripting -
highend wrote:In a multi-line script all lines apart from the first line have to be indented by at least one space.
that applies and not a specific one for heredocs. Duh. :oops: Thanks highend for clarifying. :whistle: In any case both before and after spaces were mentioned previously...
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

CookieMonster

Re: [Script] WhiteSpaceCtxMenu

Post by CookieMonster »

It is working beautifully, it was the indent, I had it known this morning but no time to post :)

Post Reply