Part gripe, part feature request!

Get help using and writing Nisus Writer Pro macros.
Post Reply
Jeremy Drake
Posts: 14
Joined: 2007-04-19 08:01:12
Location: United Kingdom

Part gripe, part feature request!

Post by Jeremy Drake » 2007-04-23 14:14:20

This whole Perl macro language thing is a real bind :evil:. It is not just that the excellent NWClassic macro language (fond memories!) has had to be ditched and a new language learned, not even that it has proved curiously difficult and time-consuming to find clear beginner's guides on the web :x, but Perl is apparently quite inadequate for some pretty basic things like formatting and working with accented languages :cry: . [End of gripe.] That said I do appreciate the thinking behind the new approach of NWE and NWPro. Grep is dead, long live Perl :?! On to feature requests.

My main macro is a multiple search/replace tool to convert certain words or phrases (about 300 so far) from French to English as a preliminary to translating the text.

Now,

1. According to the official guide to NWPro:

"Although Nisus Writer Pro provides a way to maintain formatting when
changing text in a Perl Macro (through the option of including the RTF formatting
in the copied text) only the advanced Perl connoisseurs will be able to take
advantage of the feature. In future Nisus Writer Pro will make the Perl macros
aware of text formats."

In fact, it is easy to retain at least italics/bold/superscript and suchlike, as the next page in the guide reveals:

"#{Send Text as RTF | Send rtf | rtf | text as rtf}
If any variant of this option is present, then the text will be sent to Perl as RTF.
Anything returned from the Perl script will be treated as RTF and an attempt will
be made to convert it back into styled text before putting it into the destination."

I worked out where to put this line in my macro, so now I am an "advanced Perl connoisseur":D!? In fact I presume the formatting ignored by Perl is more sophisticated stuff, but at any rate, for my humble purpose, this is a problem solved. 8)

However,

2. Perl does not work with accented words :evil:! If I try to search/replace, for example, après/after, the word 'après' is simply ignored by the macro. FEATURE REQUEST: Please correct this, Mr Nisus, ASAP :P!! Or could one write an instruction similar to "#{Send Text as RTF | Send rtf | rtf | text as rtf}"? "Send Text as accented… as French Language…"?

And also,

3. Add, please, in the Find/Replace window, the possibility of saving a particular find/replace as a macro item that can be appended to a pre-existent macro. This was an extremely useful option in NWClassic.

Voilà! My two-penn'orth for a new and exciting version of a marvellous word processor! :D :shock: :D

User avatar
martin
Official Nisus Person
Posts: 4373
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin » 2007-04-23 21:59:08

You are most likely having trouble with the accented characters because they may be escaped in RTF as a character code. Eg: the accented "e" becomes "\'8e". This is one of those reasons that these situations are left to advanced Perl users- there are others.

I would instead recommend that you write a Nisus Menu Macro. With it you can do plenty of complex replace operations using grep/regex. For instance, to replace all words that end with "és" with x's:

Code: Select all

Find and Replace '\w+és', 'xxx', 'aE'
I hope that helps. Please feel free to ask more questions about the new macros!

Jeremy Drake
Posts: 14
Joined: 2007-04-19 08:01:12
Location: United Kingdom

Post by Jeremy Drake » 2007-04-25 02:12:20

Thank you, Martin, for reminding me about Nisus Menu Macros. With all the hullabaloo about Perl I had not fully realised that Menu Command Macros are still around in NWE and Pro. In my gripe about greps I was losing my grip. (Sorry, could not resist.)

My Perl problem with accents is solved by using Menu Commands. Hooray!

So,
at first I put all my find/replace arguments into Menu Command (MC) form, but, my goodness, an MC Macro is sooooo slow! It effects the commands one at a time, whereas Perl does everything at once and very quickly indeed. (This does not augur well if, as I understand, Perl is eventually to be phased out in favour of MC Macros. Also, if you have to undo the changes, you have do undo them one at a time, whereas a Perl macro, however long, is undone at one go.)

Anyway,
I now have a Perl macro for non-accented substitutions embedded in a Nisus Macro document with MC macros for any word with accents and also for any find terms of more than one word (as Perl clearly does not deal with spaces) and with terms using any kind of punctuation (which Perl similarly avoids). I did discover that for English quotes to figure literally as a find/replace term (for example in changing French quotes to English) the macro has to be in Powerfind Pro.

One final question (for the time being!):
Can the position of the cursor by controlled in a macro? I should simply like the cursor to be placed at the beginning of the document after all the macro commands have been effected.

Thank you, kind, nice Mr Nisus Man for all your help. :D

Jeremy Drake
Posts: 14
Joined: 2007-04-19 08:01:12
Location: United Kingdom

Post by Jeremy Drake » 2007-04-25 02:32:18

Martin,

Another question occurs to me:

Is it possible to find/replace a word and have the word retain the initial capital or initial minuscule as the case may be? For example, I should like with one command to substitute 'avant' by 'before' and 'Avant' by 'Before'.

User avatar
martin
Official Nisus Person
Posts: 4373
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin » 2007-04-25 22:15:59

Jeremy Drake wrote:This does not augur well if, as I understand, Perl is eventually to be phased out in favour of MC Macros. Also, if you have to undo the changes, you have do undo them one at a time, whereas a Perl macro, however long, is undone at one go.
Straight Perl macros are not going to be phased out, they are just depreciated. This is because Menu Command Macros can contain Perl blocks, eg:

Code: Select all

# whatever menu commands
Begin Perl
    # whatever perl code
End
# resume menu commands
As for the undo- this is a bug that needs fixing.
Can the position of the cursor by controlled in a macro? I should simply like the cursor to be placed at the beginning of the document after all the macro commands have been effected.
Sure:

Code: Select all

Select All
Select Start

User avatar
martin
Official Nisus Person
Posts: 4373
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin » 2007-04-25 22:17:22

Jeremy Drake wrote:Is it possible to find/replace a word and have the word retain the initial capital or initial minuscule as the case may be? For example, I should like with one command to substitute 'avant' by 'before' and 'Avant' by 'Before'.
There is no option for this at current time. You can however approximate the effect by running two case sensitive find commands.

Post Reply