Why is this code incorrect?
Why is this code incorrect?
I have a macro that has always worked flawlessly. Today I keep getting an error message regarding "unexpected text in macro source code":
It's the orange colored part that is the culprit. Is this due to some new changes in the macro language? Is this not anymore part of the macro language?
I checked "&=" and "&" in Nisus Macro Reference (ca. p. 5), but their use seem not to have changed from previous versions.
It's the orange colored part that is the culprit. Is this due to some new changes in the macro language? Is this not anymore part of the macro language?
I checked "&=" and "&" in Nisus Macro Reference (ca. p. 5), but their use seem not to have changed from previous versions.
Re: Why is this code incorrect?
This has never been part of the macro language. In fact it doesn't even make sense. It looks that somehow an accidental '=' snuck in there. The "&=" should just be an "&".
I might also note that after that correction this piece of code will work fine in NW 2.1. but not in earlier versions. In earlier versions, one could have written something like this:
(At least, I'm pretty sure that would have worked. Don't have an older version around to test it.) But this will work fine in 2.1 as well.
So from that you can see how the wrong code might have come about.
Code: Select all
$path = $path & '/' & $fileName
I might also note that after that correction this piece of code will work fine in NW 2.1. but not in earlier versions. In earlier versions, one could have written something like this:
Code: Select all
$path &= '/' & $fileName
So from that you can see how the wrong code might have come about.
philip
Re: Why is this code incorrect?
A second thought:
What happens before the offending line? How is $path set? I'm wondering if the original code was something like this:
where '???' and (the return) have somehow gone missing…
In pre-NW 2.1. this kind of code was the common way to write what one can now write as:
NB: '???' might be something like a variable $folderName.
What happens before the offending line? How is $path set? I'm wondering if the original code was something like this:
Code: Select all
$path = ???
$path &= '/' & $fileName
In pre-NW 2.1. this kind of code was the common way to write what one can now write as:
Code: Select all
$path = ??? & '/' & $fileName
philip
Re: Why is this code incorrect?
Here is the whole macro. It's based on a macro written by Kino, but I guess I must have screwed it up. A little knowledge is a dangerous thing.phspaelti wrote:This has never been part of the macro language. In fact it doesn't even make sense.
To achieve the same goal, a much shorter and simpler macro would of course be enough:
Code: Select all
$myAnswer = Prompt 'Achtung! Achtung!', 'Do you really want to save this file as Nisus New File.dot?', 'No', 'Yes'
If $myAnswer == "No"
Exit
else
Save As '/Users/Homefolder/Library/Application Support/Nisus Writer Pro/Nisus New File.dot'
End
- Attachments
-
- Save As %22Nisus New File%22 Template in Library.nwm.zip
- (4.23 KiB) Downloaded 792 times
Re: Why is this code incorrect?
I changed this one line, and happy days are here again!!!phspaelti wrote:The "&=" should just be an "&".Code: Select all
$path = $path & '/' & $fileName
https://www.youtube.com/watch?v=UH01FhqMdc8
Re: Why is this code incorrect?
I see. Looking at the code, the macro does seem to have to some history
And in fact there is quite a bit of stale code, including some that may have unintended consequences. So I would recommend that you trash it and replace it with your simpler version. That way you can be sure you know what it's doing.
But one last point, in NW 2.1 the location of the Nisus New File is now in the ~/Nisus Documents/Templates/' folder…
And in fact there is quite a bit of stale code, including some that may have unintended consequences. So I would recommend that you trash it and replace it with your simpler version. That way you can be sure you know what it's doing.
But one last point, in NW 2.1 the location of the Nisus New File is now in the ~/Nisus Documents/Templates/' folder…
philip
Re: Why is this code incorrect?
It's good that you mention this. Is the "Nisus Documents" folder also not more inside the Documents folder? Mine is here:phspaelti wrote:in NW 2.1 the location of the Nisus New File is now in the ~/Nisus Documents/Templates/' folder…
/Users/Home/Documents/Nisus Documents
Which files should now be in the "Nisus Writer Pro" folder (< Application Support < Library < Home)?
I have:
1 Icons folder (with icons used for the Toolbar)
2 Idiomas (empty folder)
3 InputMethodIcons (folder with PNG image files to display the input method)
4 Języki (empty folder)
5 Languages (Unix Executable Files) and Hyphenation subfolder
6 LibreImporter (with two subfolders: LibreOffice and a folder called NisusInputFiles, which is empty)
7 Sprachen (folder with Unix Executable files)
8 Document Manager Settings
9 Document Manager Window Settings
10 Font Menu Cache
(8-10 are all Unix Executable Files)
11 Plain Text Template.dot
12 Recently Opened Documents.plist
13 Recently Saved Documents.plist
14 Reopen Documents.plist
15 Special Characters.plist
16 uniqueSequenceNumber.txt
Re: Why is this code incorrect?
Hi Þorvarður,
Sorry. I didn't mean to confuse things, I was just being casual. Yes, my 'Nisus Documents folder' is also in 'Documents' (not in the home folder.)
As to the Application Support folder; I wouldn't worry about it. NWP takes care of it. The contents is basically as you say:
The extra folders you are seeing ('Idiomas', 'Sprachen', 'Języki') are presumably the result of you starting up Nisus with different localizations (Spanish, German, Polish).
Sorry. I didn't mean to confuse things, I was just being casual. Yes, my 'Nisus Documents folder' is also in 'Documents' (not in the home folder.)
As to the Application Support folder; I wouldn't worry about it. NWP takes care of it. The contents is basically as you say:
- 3 folders (Languages, LibreImporter, InputMethodIcons)
- The plist files for the document manager and the font cache
- 'Original' versions of the template files, and a 'Macros' folder
The extra folders you are seeing ('Idiomas', 'Sprachen', 'Języki') are presumably the result of you starting up Nisus with different localizations (Spanish, German, Polish).
philip
Re: Why is this code incorrect?
Philip, you say the operator "&=" does not exist and would make no sense; but what does it then mean in the Macro Reference when it says:phspaelti wrote:This has never been part of the macro language. In fact it doesn't even make sense.
"both values are treated as strings and concatenated (eg: the string on the right of the operator is appended to the string on the left)" ?
Is "&=" perhaps an old, not more valid operator that they have just forgotten to remove from the Macro Reference?
I looked through my old macro notes and found this (see screenshot). Since the Reference gives no examples, I made up my own, and we can see on the screenshot that it worked as described. But you are right, now it doesn't function anymore.
https://copy.com/1FacId7kFt4DnBQA
Re: Why is this code incorrect?
No, I never said that. What doesn't exist/make sense is the sequence of operators:Þorvarður wrote:Philip, you say the operator "&=" does not exist and would make no sense;
Code: Select all
$a = $a &= …
The "&=" operator is perfectly valid. It's a string append operator.Þorvarður wrote:Is "&=" perhaps an old, not more valid operator that they have just forgotten to remove from the Macro Reference?
philip
Re: Why is this code incorrect?
Thank you Philip for the clarification.The "&=" operator is perfectly valid.
Could you give me examples of how to use this correctly? It would be very helpful.It's a string append operator.
Actually, I assumed I was appending one string to another string, but neither [1] nor [2] work.
[1]
$a = 'The Macro Reference is poorly written. '
$b = 'There are no examples.'
$addition = $a &= $b
Prompt $addition
[2]
$addition = "The Macro Reference is poorly written. " &= "There are no examples."
Prompt $addition
Re: Why is this code incorrect?
Þorvarður wrote:Could you give me examples of how to use this correctly? It would be very helpful.
Actually, I assumed I was appending one string to another string, but neither [1] nor [2] work.
[1]
$a = 'The Macro Reference is poorly written. '
$b = 'There are no examples.'
$addition = $a &= $b
Prompt $addition
Code: Select all
$a = 'The Macro Reference is poorly written. '
$b = 'There are no examples.'
$a &= $b
Prompt $a
Þorvarður wrote: [2]
$addition = "The Macro Reference is poorly written. " &= "There are no examples."
Prompt $addition
Code: Select all
$addition = "The Macro Reference is poorly written. "
$addition &= "There are no examples."
Prompt $addition
With versions of Nisus before 2.1 this operator was very important, because the macro language had a rule that limited one to a single operator per line. So if you wanted to add three or more strings together, you always needed to do it in steps:
Code: Select all
$example = 'This ' & 'is a '
$example &= 'stupid ' & 'example!'
But now in 2.1 you can write this directly as a single assignment, so the importance of '&=' is reduced:
Code: Select all
$example = 'This ' & 'is a ' & 'stupid ' & 'example!'
philip
Re: Why is this code incorrect?
So that was the crux of the matter! Now I understand. I think the Nisus people may have forgotten to make this clear in the Macro Reference.So the line always has to start '$variable &='
Thank you also very much for the example, which, by the way, was not so stupid at all.