nisus.com
https://www.nisus.com/forum/

Find All in All Open Files and list it
https://www.nisus.com/forum/viewtopic.php?f=17&t=5568
Page 1 of 1

Author:  Matze [ 2013-12-02 23:21:36 ]
Post subject:  Find All in All Open Files and list it

Hi there,

I am trying to figure out how to change the "Find All and Show Context" Macro to work on all open documents and not only on the frontmost doc.

Can anyone help me, what to do?

Best Matze

Author:  phspaelti [ 2013-12-03 00:27:44 ]
Post subject:  Re: Find All in All Open Files and list it

Sure.

The macro was written by Kino. The first step is to figure out how it works. (Since Kino wrote we know it is (a) well written (b) not well commented :wink: )
The macro is quite complex, because he wanted many features and he wanted it to work for non-contiguous selections. Also he is very careful about making sure it will have "safeties" (abort properly if something goes wrong, etc.) There is also the bit about working across footnotes, etc. which was a big issue back then, but I am not sure requires all the extra overhead that he had. Nisus Macro language has become a bit more powerful, and so of this might be simplified, but I am not sure.

Once you understand this you have to decide whether you'll I need all of these extras, whether the things you don't need can easily be dropped and the remaining code adapted, or whether it might make more sense to start over.

Author:  phspaelti [ 2013-12-03 09:26:28 ]
Post subject:  Re: Find All in All Open Files and list it

Having taken I more careful look at that macro, I can add a few things. First here is my commented version of the macro:
Attachment:
Find All and Show Context.nwm [41.24 KiB]
Downloaded 172 times

The first thing to do is actually to update some of the constructs. In particular there is an elaborate part, where K uses Menu commands to select the sentence context for the find results. But the Nisus macro language now has a command . rangeOfSentenceAtIndex which will radically simplify that section. This will be particularly important, if you are trying to adapt the macro for multiple documents, since you will no longer have to call each document to the front to use the menu command, but instead can work directly with the text objects.
Similarly it is now possible to create bookmarks directly without needing to work on the active document, so that part should be rewritten as well.

Otherwise the basic approach to getting this to work will involve the following steps:
  1. Create an array of document objects
  2. Loop through the documents and do a "Find All" on each one
  3. Store the returned selection arrays in a hash with the documents as keys (similarly for other desired variables such as the original selections)
  4. Adapt the context specification to include the document name (or an abbreviation thereof) in addition to the page [and line] number
  5. Loop through the documents when bookmarking results
  6. Loop through the documents when collecting all the found contexts for output in a new document. In this case too, the output needs to be adapted to give the document name for each found context, or alternatively group the find results by document with headings.
Something like that should do it.

Author:  phspaelti [ 2013-12-05 06:34:40 ]
Post subject:  Re: Find All in All Open Files and list it

I have looked some more at Kino's macro, and have now written my own version of something similar.

This macro works a little different. It actually comes as 3 different macros. The first main macro works a bit like Kino's macro:
  • It prompts the user to specify a context (paragraph, sentence, none, or some number of characters)
  • It takes the info in the Find dialog and does a Find All in all open documents
  • It creates a new file which lists all the find hits with context, grouped by document, with some location information (similar to what Kino's macro does)
  • It saves find hit information in a macro registry
Attachment:
Find in All Open Documents (log).nwm [24.83 KiB]
Downloaded 157 times


The second macro works with the output file from the first. You can select a line from the output file and run it, and then the macro will bring that file to the front and select the find hit.
Attachment:
Jump to Find Hit.nwm [17.83 KiB]
Downloaded 169 times


The third macro allows you to bookmark any of the find results as listed by the first macro. If you want to bookmark all of them, select the whole result file. But you can also bookmark just a subset of them, if you prefer.
Attachment:
Bookmark Find Hits.nwm [17.57 KiB]
Downloaded 179 times


It should be noted that the second and third macro will only work correctly if the first macro has been run fairly recently, so that the results are still "fresh". If you edit any of the files, the results might be off. If you close any of the documents, the find results for that file will not work correctly, even if you reopen the file. If you quit Nisus, the find results are lost (even if you save the result file.)

Finally I should point out that I have really only done cursory testing, so if something doesn't work right, please let me know.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/