NISUS Archives

July 2016

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show HTML 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:
Thu, 28 Jul 2016 02:36:32 +0900
Content-Type:
multipart/alternative
Parts/Attachments:
text/plain (4 kB) , text/html (13 kB)
Hello Abdassamad
that is of course not a helpful result, because it may simply mean that the find expression didn’t find anything, and therefore that it did nothing. I’ll send you a second version of the macro, which will end with a report. The new macro should end with a report like this:

Statistics:
Total Stretches found: xxx
Total words reversed: yyy

If the xxx and yyy are ‘0’ then you will know that the macro doesn’t find anything. This will probably mean (as Knut suggests) that either the spaces are not “spaces” or that there are intervening gremlins everywhere.

Philip



> On Jul 27, 2016, at 22:07 , Abdassamad Clarke <[log in to unmask]> wrote:
> 
> Dear Philip,
> 
> Thank you so much. I ran it but nothing happened at all.
> 
> A friend opened the file on his PC Windows machine with MS Word, and it opened perfectly. He sent me a screen shot.
> 
> The puzzle deepens.
> 
> Abdassamad
> 
>> On 27 Jul 2016, at 03:40, spaelti <[log in to unmask] <mailto:[log in to unmask]>> wrote:
>> 
>> What I meant by “not difficult” is that it’s not a problem to create a macro which will reverse the words. The question is whether that will solve the problem. The macro will be a solution if the words are indeed physically reversed. Just as others pointed out, I would have suspected that this is somehow the result of some special characters which cause the words to appear reversed.
>> 
>> But now taking the cue from Bob’s suggestion, I’m providing here a macro which looks for stretches of words separated by spaces. For each stretch, it will reverse the words in that stretch. It *will* modify the file, so use it on a copy. (But running it twice, should restore the file, knock on wood). Here’s the macro. I’ll send a macro file to Abdassamad directly.
>> 
>> [Caveat: I’m assuming that the ‘\w’ wildcard works for the relevant script(s). Same for the space. Otherwise the find expression will need to be adjusted. Arabists feel free to let me know whether this works or not.]
>> 
>> /* Macro Reverse Words in Sentence
>> written for Abdassamad Clarke from the Nisus List
>> p. spaelti, 2016.7.27
>> */
>> $doc = Document.active
>> # Extract the stretches of words separated by spaces
>> # The stretch should start and end with a word and have at least two words
>> $sels = $doc.text.find '\w+ [\w ]*\w', 'Ea'
>> $stretches = $sels.arrayByMakingValuesDoCommand 'subtext'
>> # Reverse all the stretches
>> $results = Array.new
>> foreach $stretch in $stretches
>> $words = $stretch.split(' ')
>> $revWords = Array.new
>> while $words.count
>> $revWords.push $words.pop
>> end
>> $results.push $revWords.join(' ')
>> end
>> # Replace each stretch with the reversed stretch
>> foreach $i, $sel in $sels
>> $sel.text.replaceInRange $sel.range, $results[$i]
>> end
>> /* End of macro */
>> 
>> 
>> 
>> 
>>> On 2016 Jul 27, at 08:18, Bob Stern <[log in to unmask] <mailto:[log in to unmask]>> wrote:
>>> 
>>>> On Jul 21, 2016, at 7:36 PM, Philip Spaelti <[log in to unmask] <mailto:[log in to unmask]>> wrote:
>>>> 
>>>> it is not difficult to write a macro to reverse the order of words on a line, but one really wonders how such a file came about.
>>> 
>>> 
>>> Philip:  If you're feeling more ambitious than me and want to tackle this for Abdassamad, his and Erik Richard's subsequent posts state that the delimiter is an "end of sentence character".   One approach would be to use the Find command to step through the document one sentence at a time; use the split command, with a space as delimiter, to create an array; then output the array in reverse order.
>>> 
>>> Abdassamad:  I expect Martin could write such a macro much faster than any of us if you post your question on the Nisus Macros web forum.  Be sure to clarify what "end of sentence" characters may occur in the document.
>>> 
>>> http://www.nisus.com/forum/viewforum.php?f=17 <http://www.nisus.com/forum/viewforum.php?f=17>
>>> 
>>> Bob
>> 
>> Philip Spaelti
>> [log in to unmask] <mailto:[log in to unmask]>
>> 
>> 
>> 
>> 
>> 
> 

Philip Spaelti
[log in to unmask]







ATOM RSS1 RSS2