NISUS Archives

January 2011

NISUS@LISTSERV.DARTMOUTH.EDU

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

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

Print Reply
Subject:
From:
Reply To:
Date:
Wed, 5 Jan 2011 03:01:47 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (55 lines)
On 2011-01-04 +0900 (JST), at 11:40 PM, Nobumi Iyanaga wrote:

> In Classic Nisus macro language, it was the line
> 
> 	s -> push (Starts)
> 
> which seemed (to me...) strange, difficult to understand, almost a magic.

You too? I used to be wondering why it is 's->push(Starts)' and not 's<-push(Starts)'??? Those who are familiar with C language and its sisters may find 's->push(Starts)' natural, though.
<http://en.wikipedia.org/wiki/Stack_(data_structure)>

> But otherwise, it was rather easy to understand, because, I think, all was done, so to speak, in the screen: we could always follow the location of the insertion point (or selection), and verify, if we wanted, where it was.

> but even if we stopped the macro just before "$start.text.insertAtIndex $start.location, $num", we don't see where the insertion point is...

You can add '$doc.setSelection $start' before '$start.text.insertAtIndex $start.location, $num' for debugging... but I (believe) understand what you want to mean.

> But this is certainly the reason why the new NWP macro is much faster than the Classic NW macro (because it does not "move" the insertion point).

Well, I was told that making selection(s) is very expensive. I have never compared the performance of a NWP macro with that of an equivalent NW Classic macro but there would/might be another factor. NWP macro language is more primordial (of a lower level) than that of NW Classic. It's just my impression but, while the latter seems to simulate our manual operations (except when it does maths or something rare), the former manipulates Text object directly.

Then, perhaps it might be helpful to know that, while Document object, Text object and TextSelection object are essential for NWP macro language (if we speak about manipulating text objects only, ignoring Image object for example), Range.object and Character Index are something secondary and made available just for convenience, I guess. For example and roughly speaking, 'TextSelection.setActiveRange $range' can be regarded as a kind of shorthand, equivalent to...

	$doc = Document.active
	$text = TextSelection.activeText
	$sel = TextSelection.new $text, $range
	$doc.setSelection $sel


Then, the hierarchy of various kinds of objects would be

	Document object > Text object > TextSelection object (> Range.object > Character Index)

Perhaps it would be better (for [self-]educational purpose) to try to write macros without using any Range.object and Character Index. None of commands requiring them solely seems to be essential. None of them is really indispensable, I think.

And a yet another version of insert paragraph number macro.

$prefix = Cast to String ''
$suffix = Cast to String ".\t"
$doc = Document.active
$i = $n = 0
while $i < $doc.text.length
	$n += 1
	$doc.text.insertAtIndex $i, $prefix.textByAppending($n, $suffix)
	$range = $doc.text.rangeOfParagraphAtIndex $i
	$i = $range.bound
end

# I had been forgetting about textByAppending command until yesterday, oh well...

This one does not work properly for a document having a table in its main body and I sent them a bug report (may not be a real bug in reality but what *might* look a bug is a bug for me).


Kino

ATOM RSS1 RSS2