Creating a List of all Capitalsied words

Get help using and writing Nisus Writer Pro macros.
Post Reply
GKS
Posts: 1
Joined: 2021-04-25 06:52:00

Creating a List of all Capitalsied words

Post by GKS »

I'm working through a document where I would like to find a way to extract and have in a new list all that document's words which are written in ALL CAPS. I would then use that list to prepare an annex of Acronyms used in this document.

Is there a macro that could help reduce the tedious chore of manually selecting and cutting/pasting each entry?

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

Re: Creating a List of all Capitalsied words

Post by martin »

Here's a macro that should do what you like:

Code: Select all

# This macro finds all words that are in all caps in the frontmost document
$minLength = 2
If ! Find All @string<\p{Upper}{$minLength,}>, 'E-i'
	Prompt "No matches found.", "Did not find any words in all caps with at least $minLength characters."
	Exit
End

# gather list of matching words, de-duplicate them, and sort
$doc = Document.active
$wordList = Array.new
$wordMap = Hash.new
ForEach $selection in $doc.textSelections
	$word = $selection.substring
	If ! $wordMap{$word} # ensure unique
		$wordMap{$word} = @true
		$wordList.appendValue($word)
	End
End
$wordList.sort

# open a new document showing all matches
$wordText = $wordList.join("\n")
Document.newWithText($wordText)
Menu 'View:Draft View'
The only thing you might want to adjust is the $minLength variable. It's a threshold that controls the minimum number of characters in a single word. Two is a good default so you can avoid matching words like "I", or "A" at the start of a sentence.
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Creating a List of all Capitalsied words

Post by phspaelti »

While Martin' macro will work fine for this, one might mention that you don't really need a macro for this at all. Just create an appropriate Find expression, do "Find All" to get a non-contiguous selection and then you can copy them directly to the clipboard.
Attachments
Screen Shot 2021-04-27 at 3.11.44.png
Screen Shot 2021-04-27 at 3.11.44.png (112.77 KiB) Viewed 9533 times
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Creating a List of all Capitalsied words

Post by phspaelti »

I would have used PowerFind for the screen-shot, but it seems that PowerFind won't let you insert a repeat bubble with (3 or more). It creates the bubble, but it just beeps and won't insert it in the Find dialog. :(
philip
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Creating a List of all Capitalsied words

Post by martin »

phspaelti wrote: 2021-04-26 10:15:11 I would have used PowerFind for the screen-shot, but it seems that PowerFind won't let you insert a repeat bubble with (3 or more). It creates the bubble, but it just beeps and won't insert it in the Find dialog. :(
This looks like a bug, if you leave the upper bound blank. If you enter a real number (like 999) the repetition bubble inserts correctly.
Post Reply