Macro AltSearch

(Alternative dialog find and replace for Writer)

version 1.1


| What this extension offers | Searching | Replacing | Batch mode | Limitation | History of changes |



Author: Tomas Bilek – © 2007-2008
Licence: LGPL, see http://www.volny.cz/macrojtb/0gnu-lgpl_en.html

This macro is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.



What this extension offers in comparison with standard OOo dialogue :



Tip for keys shortcut for more frequent use:

1. Open dialogue Tools - Customize... - Keyboard

2. In the field of Category find by clicking to OpenOffice.org Macros - User - AltSearch - AltSearch

3. In the field of Function select and assign by Modify button:
_AltSearch and assign shortcut Ctrl+H (open Search dialogue);
_FindNext and assign shortcut Ctrl+L (finding next occur after of cursor point, without opened dialogue);
_FindBack and assign shortcut Ctrl+Shift+L (finding next occur in front of cursor point, without opened dialogue);



List box menu (above input field for setting searched and replace expression)

contain frequently used or complicated regular expressions or parameters for supplying. After choosing the entry the corresponding parameters are transferred to the input field (or of both fields). Those may be inserted in several ways: on start of, in the end, to cursor or original text wholly replaces. At the same time is enabled switch "Regular expressions".


Searching:

List box Regular

contains some helpful regular expressions. Their description is available in OOo help under title List of Regular Expressions.

Limitation: Syntax used regular expressions isn't fully compatibile with OOo original. Problems are especially with searching, when using wildcard * + ? {n,n} near past subexpression determinate by parenthesis ().
E.g . (Mi)?ster will not be found (however, when using [ Count ] will be returned true count - this function using compatabile mode only). Further, if it is searched subexpression type (.*)any or (.+)any so it is founded shortest suitable occurrence, contrary OOo standard, that will find out longest suitable occurrence. If it is necessary to preserve compatibility, it is possible to delimit whole searched expression to the extra pair of parenthesis: ((Mi)?ster). By it will be, of course, lost chance to cite the subexpression in replace expression as the reference, \# where # is reference number (max. 9) of subexpression. It is impossible also at the same time to use reference on the subexpression (determinate parenthesis ()) in searched as well as replaced expression. See also subexpressions.



Another, special wildcard parameters:

\l - represents any alphabetic character; same like [:alpha:]{1,1}.

\d - represents decimal digit; same like [0-9].

\p - represents termination sign of paragraph,

in contradiction to OOo standard $, is able to represent also empty paragraph. It is possible to use wildcard +, *, {min,max}.

\p{1,} - will find nearest end of paragraph followed by unlimited block of empty paragraphs. Same like \p*.

\p{2,4} - will find nearest end of paragraph followed by minimally one, maximally by three empty paragraphs, on the whole so minimally 2 maximally 4 paragraphs one after another.

Limitation: Slow at separate using. Sometimes problems with backward search direction.

\xhhhh - will enable to input character's code by hexadecimal number (as hhhh)

\#ddddd - will enable to input character's code by decimal number (as ddddd)

If next character isn't digit, it is not necessary to keep of all 5 position of ddddd. Otherwise it is necessary to fill in zeros from the left.

\c - search for manual column break. Limitation: Slow at separate using.

\m - search for manual page break.

Limitation: Slow at separate using. If subexpression () is used, so parameter \m must be on start of searched string, or may not be alone: \m(...) but no (...)\m.

\s - represents any space: space, non breaking space, tabulator, manual line break.

Same like [ \xA0\x9\xA].

\S - represents character non breaking space (\x00A0 or \#160)



List box Extended

[::BigBlock::] - searches block of paragraphs (unlimited long), delimited by some known text

start[::BigBlock::]end - at first, searches for start and after its finding it is searched for end. If both are found, the whole block is marked.

In replacing string is possibility to use parameters \b, &, \e for inserting contents of start, found block of paragraphs, end.

Limitation: Inside initial and final mark it is impossible to use sign || for multiple searching-replacing, see below.



[::Growe n1,n2::] - found block of text will be expanded about n1 character to the left and n2 character to the right

[::Growe -1,-1::]text - if word exists in text text so it will be found, but marked will be only ex.

Limitation: [::Growe... it is necessary to use always at the beginning of searched string and after that the searched expression. If set shifts will be on negative values, then may happen (depending on size and content of searched expression) so at the next search will be cyclic found the same place.



text1||text2||text3||… - multiple search-replace in one step

This option will add to the end of searching and replacing the expression sign ||, delimiting partial search and replace.

Search for: text1||text2||text3
Replace: neco1||neco2||neco3
Proceed search for text1 will replace by neco1, continue search for text2 will replace by neco2 etc.

Limitation: it is impossible to use parameter [::BigBlock::], here at the same time to it is impossible to use subexpressions.



Searching for some Objects

[::Note::] - searching text notes (yellow bubbles) according to their content

[::Note::] - will find out any text note

[::Note::]pozn. - will find out text note containing substring pozn.

Limitation: Searching only substring in content of note - it is impossible to use full regular expressions.



[::Field::] - search text fields according to their content

[::Field::] - will find out any usual text fields

[::Field::]obsah will find out text field displaying in document text obsah

Limitation: Are the same like for [::Note::]. See above.
Any special fields (e.g. hidden) is not found.



[::TextFrame::] - searching text frames according to their name

[::TextFrame::] - will find out any text frame

[::TextFrame::]rám1 - will find out text frame containing substring rám1 in name

Limitation: 1. while using [ Find ] button, will find out next text frame only if farme is selected or cursor costs inside frame. If it will be miles away in text, it is found always first text frame from the internal list of frames. Currently doesn't work option "Current selection only".

2. Practical usability [ Replace ] button is in consequence point 1. hard limited.

3. Order of searching matches (unfortunately, provisionally, I hope) order of insertion text frames to the document and not order from the start document to the end, according to pages.

4. Searching only substring in the name of frame - it is impossible to use full regular expressions.



Using [ Find all ] and [ Replace all ] would had be fully functional, inclusive option "Current selection only".



[::Picture::] - searching pictures according to their name

[::Picture::] - will find out any picture

[::Picture::]obr1 - will find out picture containing substring obr1 in name

Limitation: Are the same like for [::TextFrame::]. See above.



[::TextTable::] - searching tables according to their name

[::TextTable::] - will find out any table

[::TextTable::]tab1 - will find out table containing substring tab1 in name

Limitation: Are the same like for [::TextFrame::]. See above.



[::Footnote::] - searching of footnotes (FN)

[::Footnote::] will find out anchor of any FN

[::Footnote::]5 will find out anchor of FN which anchor contains substring 5

[::Footnote::]\\text will find out anchor of FN which text contains substring text. If button [ Find all ] is used, texts of all FN which contains substring text will be selected.

[::Footnote::]\\ with button [ Find all ] text of all FN (handy for multiple assign paragraph style to all FN) will be selected

Limitation: It works good from version OOo 2.3



[::Endnote::] - searching of endnotes

Using of parameters and limitations is the same for [::Footnote::]. See above.



[::ReferenceMark::] - searching for target marker of cross-references

[::ReferenceMark::] will find out any text set as references marker

[::ReferenceMark::]text will find out text set as references marker, which contains substring text

[::ReferenceMark::]\\ref1 will find out text set as references marker, which name contains substring ref1

[::ReferenceMark::]\\\\ will find out text set as references marker, which text is empty



[::Reference::] - searching for text field (cross-reference) referred to marker

[::Reference::] will find out all text fields of cross-reference type

[::Reference::]above will find out cross-reference which contains substring above

[::Reference::]\\ref1 will find out cross-reference which name contains substring ref1

[::Reference::]\\\\ will find out cross-reference, which text is empty

If Reference is choice from listbox Extended and at the same time cursor stands on any text, which is a Reference mark, then it will be corresponding source name added to box Search for automatically, and it is possible to search it immediately.



List box Properties

enables searching according to properties (attributes), eventually also their values.
Entry must begin by string
[:::, follows name of proprieties (more names separate by the help of sign | ) and ends string ::]. After it can follow specification of searched text. If concrete value of properties should be searched, construction name=value will be used.

[:::HyperLinkURL::] - searches part of text with setup attribute HyperLinkURL

[:::HyperLinkURL::] - will find out all hyperlink

[:::HyperLinkURL::]link - will find out part of hyperlink containing text link.

[:::HyperLinkURL=file:///c:/pokus.odt::] - will find out hyperlink in which URL is found substring file:///c:/pokus.odt.

[:::HyperLinkURL=file:///c:/pokus.odt::]link will find out part of hyperlink in which URL is found substring file:///c:/pokus.odt and containing text link.

List of available text attributes with their current values (according to current selection) it is possible to load by the help of buttons [ Pick properties ] and display in side list box. Their brief description is possible to find mostly here.



Similar character attribute - this function loads any manually changed character's attributes (according to current selection) for searching out alike formatted places. If e.g. cursor is on manually changed name of font, all places with changed name of font will be searched - will be searched for [:::CharFontName::].

Same characters attribute - this function loads any manually changed character's attributes (according to current selection) for searching out the same formatted places. If e.g. cursor is on manually changed name of font, all place with changed name of font and the same name of font will be searched - will be searched for [:::CharFontName=Arial::].



Limitation: Not all existing paragraph's and character's properties OOo search engine supports. Not all their combination work according to expectation and well.



Replacing:

List box Replace

& \0 - both these parameters means the same - at replacement they represent whole founding text

If the expression was searched by the help of [::BigBlock::] so these parameters

represent only block of paragraphs between starting and ending marks.

If the object was searched by the help of [::Note::], [::Field::], [::TextFrame::], [::Picture::], [::TextTable::] so these parameters represent directly these objects (put in through clipboard).



\b \e - If the expression was searched by the help of [::BigBlock::] so these parameters represent content of starting and ending marks. Limitation: it is impossible using subexpressions ().


\1 \2 \3 \4 \5 \6 \7 \8 \9 - content of subexpressions

If the search expression was searched by the help of parentheses (), so \1 represents content corresponding to the first pair of parentheses, similarly \2 corresponds to the second pair () etc., maximum \9 corresponds to the 9th pair. Valid is only 1st level parenthesis, next nested levels are ignored.

Example:
By the expression (\d{1,2})\. *(\d{1,2})\. *\d{2,2}(\d{2,2}) it is possible to find date in format 01. 12. 2007 and replace with 07-12-01 by replace expression \3-\2-\1.

If it is necessary to switch off processing subexpression (e.g. on the ground of compatibility with regular expressions in standard OOo) it is necessary to insert the whole search expression in additional pair of parentheses (). Herewith all other nesting levels of parenthesis for replacement wil be ignored.

Limitation: Using of subexpressions is relatively slow and not fully compatibile with original searching OOo.

Incompatibility with searchs wildcard immediately behind subexpression (opak)* is caused by principle sequential searching consequential blocks of texts, see here. In these cases returns function [ Count ] and [ Find all ] correct real count while other without switching to compatibility mode will not find anything. In more complicated cases it is necessary to examine behaviour, and experimentally verifyed.



\p - inserts empty paragraph

\t - inserts tabulator (\x0009 \#9)

\s - inserts non-breaking space (\x00A0 \#160)

\n - inserts manual line break (\x000A \#10)

\c - sets on manual column break "before" in founded paragraph(s)

\m - sets on manual page break "before" in founded paragraph(s)

\M - sets on manual page break "after" in founded paragraph(s)

\r - turns off manual column or page break in founded paragraph(s)

\xhhhh - inserts character by hexadecimal number's code (as hhhh)

\#ddddd - inserts character by decimal number's code (as ddddd).



\h{addressURL} - sets founded text as hyperlink to which URL sets to addressURL

\h{}, \h sets founded text as hyperlink to which URL sets to empty string - deletes hyperlink's URL (text of hyperlink of course stays unchanged).

\H{substr} - replaces substring in hyperlink's URL

It is necessary to use at the same time with searching by [:::HyperLinkURL=::].

If the expression was searched e.g. by the help of [:::HyperLinkURL=substr::], so will be found hypelinks whose URL includes substring substr only. Using \H{repl} in replacing expression will find in URL text substr and replaces it by repl.

\u - inserts in replacing expressinon URL address of founded text (if hypelink is found)

\P{Text} - sets up Paragraph style (Text) in founded paragraph(s)

Style is applied on the paragraph in which is text of replaced expression. For setting "Default" style it is possible to use \P or \P{}. If this parameter is used a number of time with inserted paragraph(s), so style is changed with every new parameter, and is valid as far as to the end of paragraph. Example: If the expression was replaced by the help of block1\P{Subtitle}\p block2\P{Heading 1} so in document will be inserted block1 and assigned style Subtitle and after it wil be inserted new paragraph with text block2 and assigned style Heading 1.

\C{Quotation} - sets up Characer style (Quotation) in founded text

Style is applied on the whole text of replaced expression. For setting "Default" style it is possible to use \C or \C{}. If this parameter is used a number of time, so character style is changed with every new parameter, and the last is valid as far as to the end of replacing expressions. Example: If the expression was replaced by the help of block1\C{Quotation}blok2\C{Example} so in document will be inserted block1 with character style Quotation, after it will be inserted text block2 and assigned character style Example.

\N{List 3} - sets up List style (List 3) in founded paragraph(s)

Applies anologous rules usage like for parameter \P{}. List style can be remove by using \N or \N{}.

\D - sets up default formating for founding text, like as Ctrl+Shift+Space

Applies anologous rules usage like for parameter \C{}.

\d - resets text attributes to defaut only in place of the use.

Contrary to \D it has no effect on the previous inserted text.

\F{New footnote} - inserts new footnote which contains New footnote on the place of replace

Inside curly brace it is possible to use any parameters as \i, \I, &, or \1

\E{New endnote} - inserts new endnote to place of replace, analogous to \F

\B{ref1|text} - inserts text text represents marker of name ref1 for cross-reference

Inside curly brace it is possible to use any parameters as \i, \I, &, or \1

\L{0,0,ref1} - inserts cross-reference (field) with 0,0 parameters and name of reference marker ref1

Meaning of numeral parameters

first number - typ of reference: 0 - arabic numbers of the page, 1 - number of the chapter, 2 - the reference text , 3 - above/below , 4 - page number using the numbering type defined in the page style, 5 - category and the number of a caption, 6 - the caption text, 7 - number of a sequence field (caption)

second number - type of the source of a reference field; the source is : 0 - a reference mark, 1 - a number sequence field, 2 - a bookmark, 3 - a footnote, 4 - an endnote



\o - inserts text content of founded object

If the expression was searched by the help of [::Note::], [::Footnote::], [::Endnote::], [::TextFrame::], [::Picture::], [::TextTable::] so will be inserted text which contains these object. Table is converted by the help of tabulators between columns and paragraphs between rows.

Limitation: Maximum size of conversion tables is limited on 65 kB resulting text at the whole.

If the expression was searched by the help of [::Field::], [::Reference::], [::ReferenceMark::] so displayed text of anchor or field will be inserted.



\O - inserts Name of founded object

If the expression was searched by the help of

[::TextFrame::], [::Picture::], [::TextTable::] - name of this objects will be inserted.

[::Note::], [::Field::] - specification of typ of text fields will be inserted

[::Reference::], [::ReferenceMark::] - name of reference mark will be inserted

[::Footnote::], [::Endnote::] - displayed text of anchor will be inserted



\i - inserts counter of found occurrence - if it is used only [ Replace all ]

\I - inserts number of page, on which search expression is found

If Redirect of replace expression (\R) is used, soiit will be inserted number of page starting position of founded text.

Limitation: It does not work correctly in footnotes, header and footer.

\v - inserts content of clipboard

\V - inserts content of clipboard as unformatted text

\f - preserves format

If in replaced expression is & or \0 used, so replace will be realize over clipboard. If founded text contains text field, notes, references etc, they would have preserved in original state.

\R - Redirects of replace expression to another text file

This option causes printout of replaced expression to the new file .ODT instead of replacing founded place. Original file should stay without changes. To enter the name of file frame is possible by \R{jmeno}. Name must have accurately format as OOo window including " - OpenOffice.org Writer". Records are added always to the end of file.

Example:
If the search expression was searched by the help of [:::HyperLinkURL::] and replaced expression was Link \i, page \I: & (URL: \u)\p\R, so after using [ Replace all ] button will be printed out in new file all hypelinks founded in original file, in following form: Link 1, page 1: textOfHyperlink (URL: URLaddress) in separate paragraphs.



Button and List box Pick properties

By the help of [ Pick properties ] button it is possible to update list of (some) properties and their values just selected object. Browse and choose it is possible from list box beside.

\A{properties=value} - sets up in replaced expression the value of specify property.

Applies anologous rules usage like for parameter \C{}.




Batch mode using: [ Batch >> ]

Batch mode enables saving and loading preset parameters of searching and replacing. It is possible to save several searching and replacing in sequence to the single sequence and that after the whole quickly load and execute.

Actual setting of all parameters is possible to save by the help of [ Save batch ] button. In the dialog, which will be showed, it is offered for renaming the last used name of batch. If enter already existing name, you can choose, whether old content will be rewrites, or will be preserve and new content will be add in the end. At the same time wil be automatically saved command "ReplaceAll" with which will be the batch subsequently executed. This command can be later changed with manually batch rule file edit.

Button [ Batch >> ] will switch to dialog Batch manager where it is possible to run and edit batches. To return back to the search dialogue it is possible over [ << Searching ] button.

All batch parameters are saved to the text file AltSearchScript.txt into user's directory /OpenOffice.org2/user/config/, which is possible by the help of [ Edit ] button, from dialogue Batch manager, to open and edit. For editing is preset text editor notepad, it is however possible to set up all other text editor, by editing file AltSearchEditor.ini in the same directory. After manual changes and saving the file with batch it is possible to freshen batch's name list by the help of [ Refresh ] button. Syntax used in file AltSearchScript.txt is described at its own beginning, encoding UTF-8 (from v1.1.1).

After double click on the item of list, or by [ Execute ] button, will be loaded the chosen sequence, and will be executed the searches and replaces. When using batchs on selected area I advise to leave at the beginning and after the end of selection 1 - 2 empty paragraphs.

The button [ Transfer ] is used for transferring the parameters of serching, replacing and setting to the dialogue of searching without real execution. If batch contains sequence of several searching and replacing it will be transfered only the last part of sequence.



Limitations:

If limitations are known, they are mostly cited near of the description of individual parameters. Generally applies:




History of changes:



Version 1.1.2   4/08

News:



Version 1.1.1   3/08

News:

Fixed bugs:



Version 1.1   2/08

News:



Fixed bugs:



Version 1.0   12/07 - First Public release