NISUS Archives

November 2015

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Mime-Version:
1.0 (Mac OS X Mail 8.2 \(2104\))
Content-Type:
text/plain; charset=us-ascii
Date:
Thu, 5 Nov 2015 09:42:23 +0900
Reply-To:
Subject:
From:
Nobumi Iyanaga <[log in to unmask]>
Message-ID:
In-Reply-To:
Content-Transfer-Encoding:
quoted-printable
Sender:
A discussion list for Nisus & NisusWriter <[log in to unmask]>
Parts/Attachments:
text/plain (98 lines)
Hello,

I would need two macros for indexing, and would like to ask your help...:

1. I asked Martin of Nisus to write for me a macro for indexing: what I was looking for was to find and select all the words (or chunks of strings) that are indexed with a specific topic name. I thought this would be useful for example to "Remove from index" all the occurrences of words, etc. indexed under a certain topic (this is often necessary because we often find that the topic names can be better after having indexed through all the file). He wrote me the following macro:

# Find Next In Index Topic
# This macro searches through all indexing topics in the document, ie: the "index as" text.
# It will select the next marked text whose indexing contains the given search.
# Matching is case insensitive.
# Martin Wierschin 15-11-02

$indexName = Active Text Index Name
$searchLoops = 0		# number of times the search has looped

# ask user what to search for, defaulting to the last search value
$registry = Registry.applicationRegistry
$registryKey = "com.nisus.findIndexTopic.searchString"
$findWhat = $registry.loadValueWithName($registryKey)
$findWhat = Prompt Input "Search for what indexing topics?", "", "Search", $findWhat
$registry.saveValueWithName($findWhat, $registryKey)

# Search from current location onward
$selected = TextSelection.active
$loc = $selected.bound
$text = $selected.text
$lim = $text.length

While $searchLoops < 2
	If $searchLoops == 0
		$loc = $selected.bound
	Else
		$loc = 0
		$lim = $selected.bound
	End
	$searchLoops += 1
	
	While $loc < $lim
		$attr = $text.attributesAtIndex($loc)
		$range = $text.rangeOfAttributesAtIndex($loc)
		$loc = $range.bound
		
		$topicsArray = $attr.textIndexTopicsForStyleName($indexName)
		If Defined $topicsArray
			# check for match
			$topicsStr = ""
			ForEach $topics in $topicsArray
				If 0 == $topics.count
					# auto topic
					$topicsStr &= $text.substringInRange($range)
				Else
					$topicsStr &= Cast to String $topics
				End
				$topicsStr &= "\n"
			End
			
			If $topicsStr.containsString($findWhat, 'i')
				$select = TextSelection.new($text, $range)
				$doc = Document.active
				$doc.setSelection $select
				Exit
			End
		End
	End
End

# no matches
Prompt "No matching indexing topics found.", "Indexing for '$indexName' does not contain: $findWhat"

# end of macro #

This works very well, but as I had failed to communicate the exact purpose of the macro, he wrote one which finds and selects only "the next occurrence" of a word indexed under a certain topic.

Wouldn't it be possible to modify this macro so that it would finds and selects *all* the occurrences of words, etc. indexed under a certain topic? (I ask this to this mailing list because Martin says that he is absent for some days, and I need this macro very soon...)

2. The second macro would be much more complicated. Here is the situation. I have files for several chapters (one file for each chapter), which are being written and will be finished successively. As the deadline is very soon, I began to work to create indices for each file, beginning with chapter one. These indices being done, I have to create indices for the next files (and finally join all the files, to make big a big file and big indices). To make coherent indices, I have to use those for the first chapter, that is take the same topics, and find the same words, and make indices of the subsequent chapter files with them -- and after that, add other words under other topics for these files...

So the macro should take a list of topics (which would be the selected text), and make a list of all the topics, and all the words, etc. associated with each of these topics in a file. Ideally, the result should be a file with a table of two columns, that would look like the following:

	words, etc.			topics
_____________________________________________________
  word1|word2|chunk_of_string3		topic
		etc.			etc.

When such a file would be created, I would be able to examine each entry, and make a list of words and topics, so that I would be able to index these words in the new chapter file, at once, with the macro "Index Using Word List (PowerfindPro)" that Philip created for me...

Would it be possible to write such a macro?

I would be very grateful for your help...!

Thank you very much in advance.

Best regard,

Nobumi Iyanaga
Tokyo,
Japan

ATOM RSS1 RSS2