Reply to topic  [ 5 posts ] 
Japanese in find/replace perl macro 
Author Message

Joined: 2007-03-28 07:30:34
Posts: 139
I've been working on learning NWE macros, and wrote one yesterday that does a global find/replace to remove new line codes from selected lines globally.

The problem is that the find/replace strings contain Japanese characters. After saving and reopening the macro to work on it some more, the Japanese characters are garbage, the macro is unreadable, and it cannot be saved.

Is it not possible to have Japanese in a grep expression in Perl or a NWE macro? If so, how? I assume I am simply doing something wrong.

If not, wow.

Thank you.

Cliff Bender


2007-03-28 07:42:28
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
Hello Cliff, there are a couple of things which could trigger problems with Japanese (or other non-ASCII) characters in macros. Make sure that:

1. You always use straight quotes rather than curly quotes (eg: in a print statement). They can creep in by accident quite easily if you have QuickFix set to curl your quotes automatically.

2. When you save your Macro, make sure the Encoding is set to UTF-8.

3. You should have these lines somewhere at the top of your Macro:

use utf8;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");

This will tell Perl that the file is encoded using UTF-8 and that you wish to treat both the input and output for the macro as UTF-8.

4. Make sure you have your Plain Text Encoding set to UTF-8 as well, not just Automatic. This setting is located in your General Nisus Writer Express preferences.

If you follow these steps, and re-save your macro, hopefully all should be well.


2007-03-28 13:44:40
Profile WWW

Joined: 2007-03-28 07:30:34
Posts: 139
Post 
Martin,

Thank you for the reply. Your suggestions worked in that I can now save Japanese in the macro.

The problem now is that the text written back to the document after the replace is garbage and is inserted at the cursor instead of overwriting the old text.

The same thing happens running the included Insert Line Numbers macro.

The document language is set to Japanese, and all text is in Hiragino Mincho Pro.

Any idea what the problem is?

For reference, the basic macro is pasted below.

Thank you.

Cliff Bender

*********
#Nisus Macro Block
#source front selection
#destination front selection
#End Nisus Macro Block
use utf8;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");


#This macro template lets you replace text with other text
#You can use regular expressions to do text pattern matching
while (my $line = <STDIN>) { #Reads each line of the selection from the clipboard

$line =~ s/\n【/zxq【/ig; #replaces CR+[Jpn bracket]
$line =~ s/\n /zxq /ig; #CR+[Jpn space]

$line =~ s/\n//ig;
$line =~ s/zxq/\n/ig;

print $line; #writes out each line to the clipboard
}


2007-04-11 17:20:17
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
Cliff- I've not tested your macro, but I think this may be a bug in NWX. If you can, please download the Nisus Writer Pro public beta. I believe the problem may be fixed. Thanks, please let me know how it goes.


2007-04-12 14:58:48
Profile WWW

Joined: 2007-03-28 07:30:34
Posts: 139
Post 
Martin,

I had already downloaded the Pro beta, and fairly quickly and easily did what i wanted to do using the new macro capability, specifically the Finda and Replace command. Much faster, too.

Thank you for your help. I will use Pro from now on, likely.

Cliff Bender


2007-04-16 18:32:38
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software