Fix First 2 letter when CApitalized?

Have a problem? A question? This is the place for answers from other Express users.
Post Reply
meiner
Posts: 1
Joined: 2006-11-25 09:26:35

Fix First 2 letter when CApitalized?

Post by meiner »

Hi, apparently I have a slow-acting left hand that likes to hang out on the shift key too long. Thus, I often have words with the first 2 letters capitalized and would like to do a (MS Word - like) QuickFix for this. Is there a way to do this without adding a bunch of typical examples to my QuickFix list? Thanks!
User avatar
martin
Official Nisus Person
Posts: 5228
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Post by martin »

I'm afraid there's no good way to accomplish what you'd like at this time, sorry.
Ruchama
Posts: 213
Joined: 2006-08-19 18:35:27

Post by Ruchama »

Even if you can not do it with quickfix, you could probably do it through find/replace. though this is not automatic..
HeatherKay
Posts: 78
Joined: 2004-04-13 04:44:40
Location: Chatham, UK
Contact:

Post by HeatherKay »

Can you not just select the errant word and choose Edit > Convert > Capitalize?

Not automatic, but it cures the double capital. I just tried it.

:wink:
Ruchama
Posts: 213
Joined: 2006-08-19 18:35:27

Post by Ruchama »

Sure you can, but if you would like to do it all together at a certain time, you need to select all and only all the CApitalized words..

It is even better to exercise that left hand.. :wink:
MacSailor
Posts: 290
Joined: 2003-04-03 08:38:41
Location: Linköping, Sweden

Post by MacSailor »

I believe (if I'm not mistaken) that this could be done with the help of SpellCatcher.

Have a look here:

Fix DOuble CApitals
Peter Edwardsson
..............................
ssampler
Posts: 85
Joined: 2006-06-29 07:56:30
Location: Hudson River Valley, NY

Post by ssampler »

Here are two Nisus Perl scripts (Macros) to solve meiner's problem. "Fix Caps in Selection" fixes the problem within selected text. "Fix Caps All" fixes the problem in an entire document.

To create these scripts, go to the Macro Menu and select "New Perl" Script." Copy the first script below into the new document and save it under the name "Fix Caps in Selection" into the Macros folder located in the Nisus Writer folder in Application Support in your home library. Make sure that the format for the new saved file is "Nisus Perl Macro." If so, Nisus will add a "pl" extension. Create Fix Caps All.pl in the same way. The new macros should appear in the Macro menu. (If not, either they were not saved into the Macros folder or were not saved as Nisus Perl Macro files. Assign a key combination to each script or run them from the Macro menu.

What the scripts do: If a word contains starts with a sequence of upper-case letters followed by lower-case letters, all upper-case letters but the first will be converted to lower case.

Examples:
"WHo was that MAsked Man?" changes to "Who was that Masked Man?" (Meiner's original problem)
"Who was that MASked Man?" changes to "Who was that Masked Man?" (Fixes three caps)
"EVERYONE knows!" does not change. (Word all caps)
"Please aSSist!" does not change. (Internal sequence of caps)
"AB2" does not change. (Caps followed by number)

Known problems:
1. These scripts work only in English. Perhaps it's because I have an English language version of Nisus. If anyone with a different language-version of NWE gets these scripts to work, please let us know how.

2. A word will not be fixed if it has more than one font, text size, or color; or if some letters, but not all, are bold, italic, or underlined.

I don't really know Perl and I'd welcome suggestions. I based the scripts on the Nisus macro "Common Regexp Processing," and on the section about macros in The Nisus Guide. Perl's expression syntax differs somewhat from that in Powerfind Pro. I learned about Perl's version from BBEdit's help and from some online tutorials. In the scripts' GREP line, "\b" is a word boundary and the expression "\L\2\E" converts the second found expression to lower-case.

Steve

1st Script:

#Nisus Macro Block #Fix Caps in Selection
#source front selection
#destination front selection
#{text as rtf}
#End Nisus Macro Block
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
while (my $line = <STDIN>) {
$line =~ s/\b([A-Z])([A-Z]+)([a-z]+)/\1\L\2\E\3/g; # GREP line
print "$line";
}

2nd Script:

#Nisus Macro Block #Fix Caps All
#source front selection
#destination front selection
#{text as rtf}
#Before Execution
#Select All
#End Nisus Macro Block
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
while (my $line = <STDIN>) {
$line =~ s/\b([A-Z])([A-Z]+)([a-z]+)/\1\L\2\E\3/g; # GREP line
print "$line";
}
Last edited by ssampler on 2006-12-04 07:42:10, edited 3 times in total.
Ruchama
Posts: 213
Joined: 2006-08-19 18:35:27

Post by Ruchama »

Steve,

to my knowledge, there is no NW for different languages. what you may mean is people who use NW with their main language (fonts/keyboard..) being not english.
I am also not a perl user, but earlier correpondance with Martin revealed to me that in the print line, one of the parameters could be the language for example I copy here a line which he wrote for me a few months ago:

print "{\\rtf1\\mac{\\lang1037\\fs$rtfSize $message}}";

in which lang1037 express the use of hebrew language- one could look for the codes for other languages and it should work. also in this line- spec of the fontsize($rtfSize). I am sure all parameters of the letters could be extracted by perl and re-printed but it looks a bit too much- I mean- if one takes the time to set a different characteristic for each letter, one could set it also to upper/lowercase..

Hopefully soon we will get back the attributed find/replace that will release us from problems like that...
ssampler
Posts: 85
Joined: 2006-06-29 07:56:30
Location: Hudson River Valley, NY

Post by ssampler »

Thanks, Ruchama.

I don't know enough to comment about working in a primary language other than English.

It might be worthwhile to point out that if the first Perl script "Fix Caps in Selection" is created, then the second script can be replaced by a two-line Nisus Menu Command Macro (file format "Nisus Macro" in the "Save As" dialogue):

Select All
Fix Caps in Selection

Steve
Post Reply