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
Find All in All Open Files and list it
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
)
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.
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

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.
philip
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:
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:
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:
- Create an array of document objects
- Loop through the documents and do a "Find All" on each one
- Store the returned selection arrays in a hash with the documents as keys (similarly for other desired variables such as the original selections)
- Adapt the context specification to include the document name (or an abbreviation thereof) in addition to the page [and line] number
- Loop through the documents when bookmarking results
- 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.
philip
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:
Finally I should point out that I have really only done cursory testing, so if something doesn't work right, please let me know.
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
Finally I should point out that I have really only done cursory testing, so if something doesn't work right, please let me know.
philip