Macro AltSearch

(Alternative dialog find and replace for Writer)

version 1.4.2


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



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

The version [v1.2] of help file edited by Anna Sharman 2008.

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



What this extension offers in comparison with the standard OOo Find dialog:



Here is a tip for setting up keyboard shortcuts if you use AltSearch frequently:

1. Open the dialog Tools - Customize... - Keyboard

2. In the Category field, navigate to OpenOffice.org Macros - User - AltSearch - AltSearch

3. In the Function field, select and assign the following (suggested) shortcuts using the Modify button:
_AltSearch: Ctrl+H (to open the Search dialog);
_FindNext: Ctrl+L (to find the next occurrence of the search string after the cursor point, without opening the search dialog);
_FindBack: Ctrl+Shift+L (to find the occurrence of the search string before the cursor point, without opening the search dialog).

[v1.2] From version 1.2 onwards you also can assign shortcuts directly from the AltSearch dialog - see Batch mode





The List box menu (above the search string input field)

This contains frequently used or complicated regular expressions or search parameters that can be used in the search field. After choosing an entry, the corresponding parameters are transferred to the input field (or to both the search and replace fields if this is specified). These may be inserted in several ways: before or after the cursor or replacing the text in the input box. At the same time, the "Regular expressions" checkbox is ticked.


Searching

List box 'Regular'

This box contains some helpful regular expressions. They are described in the OOo help under the title List of Regular Expressions.

Limitation: The syntax using regular expressions isn't fully compatible with OOo original. There are problems especially with searching when using the wildcard *, +, ? or {n,n} just after subexpressions determined by parentheses ().
E.g . (Mi)?ster will not be found (however, when using [ Count ] the true count will be returned - this function works only when using the compatible mode). Further, subexpression of the type (.*)any or (.+)any are searched for, the shortest matching occurrence is found, contrary to the OOo standard search, which will find the longest matching occurrence. If it is necessary to preserve compatibility, you can delimit the whole search expression with an extra pair of parentheses: ((Mi)?ster). But this will, of course, lose you the chance to cite the subexpression in the replace expression as a reference, i.e. \# where # is a reference number (max. 9) of the subexpression. It is also not possible to use a reference on the subexpression (determined by parentheses ()) in the search expression at the same time as in the replace expression. See also subexpressions.



Other special wildcard parameters:

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

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

\p - represents the paragraph termination sign,

in contrast to the OOo standard search, $ also represents an empty paragraph. It is possible to use wildcards such as +, *, or {min,max} with $.

\p{1,} - will find the next end of paragraph followed by an unlimited block of empty paragraphs. Same as \p*.

\p{2,4} - will find the next end of paragraph followed by at least one and at most three empty paragraphs, i.e. a total of 2-4 paragraphs one after each other.

Limitation: Slow when used separately. Sometimes there are problems when searching backwards.

\xhhhh - will enable the input of a character's code as a hexadecimal number (hhhh)

\#ddddd - will enable the input of a character's code as a decimal number (ddddd)

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

\c - represents a manual column break.

Limitation: Slow when used separately.

\m - represents a manual page break.

Limitation: Slow when used separately. If subexpression () is used, the parameter \m must be at the start of the search string, and it must not be alone: \m(...) but not (...)\m.

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

Same as [ \xA0\x9\xA].

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



List box 'Extended'

[::BigBlock::] - searches for a block of paragraphs (of unlimited length) delimited by some known text:

start[::BigBlock::]end – first, start is searched for, and when it is found, end is searched for. If both are found, the whole block between them is selected.

In the replace string you can use the parameters \b, & or \e for inserting the contents of start, found block of paragraphs, or end, respectively.

Limitation: In the initial and final strings you cannot use the || sign for multiple searching and replacing; see below.



[::Grow n1,n2::] - the found block of text will be expanded by n1 characters to the left and n2 characters to the right:

[::Grow -1,-1::]text - if the word text exists in the text it will be found, but only ex will be selected.

Limitation: it is necessary to always use [::Grow... at the beginning of the search string and put the search expression after it. If n1 or n2 are negative values, then (depending on size and content of the search expression) the next search may cyclically find the same place.



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

Add the sign || to the end of the search and replace expressions to delimit the partial searches and replacements.

Search for: text1||text2||text3
Replace: neco1||neco2||neco3
This will search for text1 and will replace it with neco1, then continue the search for text2, replace it by neco2, etc.

Limitation: you cannot use the parameter [::BigBlock::] with ||, nor can you use subexpressions.



Searching for Objects:

[::Note::] - searches text notes (yellow bubbles) according to their contents.

[::Note::] - will find the next text note

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

Limitation: you can only search for substrings in the contents of notes - you cannot use full regular expressions.



[::Field::] - searches text fields according to their contents.

[::Field::] - will find any normal text fields

[::Field::]obsah will find text fields in the document that display the text obsah

Limitation: the same as for [::Note::]; see above.
Any special fields (e.g. hidden) are not found.



[::TextFrame::] - searches text frames according to their name.

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

[::TextFrame::]rám1 - will find text frames containing the substring rám1 in their name

Limitations:

1. When using the [ Find ] button, you will find the next text frame only if the frame is selected or if the cursor is inside the frame. If the cursor is a long way away in the text, the first text frame from the internal list of frames in the document is found. The option "Current selection only" currently doesn't work.

2. The practical usability of the [ Replace ] button is, as a consequence of point 1, very limited.

3. The order of searching matches (unfortunately, provisionally, I hope) the order in which the text frames have been inserted into the document and not the order within the pages of the document from the start to the end.

4. You can search only for a substring in the name of frame - you cannot use full regular expressions.



[ Find all ] and [ Replace all ] are fully functional, including when used with the option "Current selection only".



[::Picture::] - searches pictures according to their name.

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

[::Picture::]obr1 - will find pictures containing the substring obr1 in their name

[::Picture::]\\text - will find substring text inside pictures Title text. [v1.4]

[::Picture::]\\ - will find all pictures with empty Title text. [v1.4]

Limitation: the same as for [::TextFrame::]; see above.



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

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

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

Limitation: the same as for [::TextFrame::]; see above.



[::Footnote::] - searches footnotes (FN)

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

[::Footnote::]5 will find the anchor of a FN whose anchor contains the substring 5

[::Footnote::]\\text will find the anchor of FN whose text contains the substring text. If the button [ Find all ] is used, the text of all FNs that contain the substring text will be selected.

Using [::Footnote::]\\ with the button [ Find all ], the text of all FNs will be selected (handy for assigning a paragraph style to all FNs at once)

Limitation: It works well only from OOo version 2.3.



[::Endnote::] - searches endnotes

Use of parameters and limitations are the same as for [::Footnote::]; see above.



[::ReferenceMark::] - searches for the target marker of cross-references

[::ReferenceMark::] will find any text set as a reference marker

[::ReferenceMark::]text will find any text set as a reference marker that contains substring text

[::ReferenceMark::]\\ref1 will find any text set as a reference marker whose name contains the substring ref1

[::ReferenceMark::]\\\\ will find any text set as a reference marker whose text is empty



[::Reference::] - searches for text fields (cross-reference) by their markers

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

[::Reference::]above will find cross-references that contain the substring above

[::Reference::]\\ref1 will find cross-references whose name contain the substring ref1

[::Reference::]\\\\ will find cross-references whose text is empty

If Reference is chosen from the list box Extended and at the same time the cursor is positioned in text that is a Reference mark, then the corresponding source name will be added to the Search for box automatically, and it is possible to search it immediately.



[::Bookmark::] - searches for Bookmarks [v1.4]

[::Bookmark::] will find place in the text or a block of text marked as bookmark

[::Bookmark::]text will find text if it is inside a text block who is marked as bookmark

[::Bookmark::]\\RefHeading will find a place in the text or a block of text marked as bookmark only when if name of bookmark contains substring RefHeading (searches substring in names of bookmarks)



List box 'Properties'

This enables searching according to properties (attributes), and also according to the values of these properties.
The search entry must begin with the string
[:::, followed by a name of a property (more than one name can be separated using the | sign) and must end with the string ::]. After this can follow the specification of some search text. If the value of the property is to be searched, the construction name=value should be used.

[:::ParaStyleName::] - searches for paragraph style [v1.3.1]

[:::ParaStyleName=::] will find all whole paragraph with paragraph style another than the Default style

[:::ParaStyleName=Example::] will find whole paragraph with paragraph style Example

[:::ParaStyleName=Example::] something will find text something if it is formatted through paragraph style Example



Limitation: Not find some parts of the text with zero length, for example, an empty paragraph.
Can not simultaneously combine with other text properties.



[:::CharStyleName::] - searches for character style [v1.3]

[:::CharStyleName=::] will find part of the text with character style another than the Default style

[:::CharStyleName=Example::] will find part of the text with character style Example

[:::CharStyleName=Example::] something will find text something if it is formatted through character style Example



Limitation: It works just ahead - Backward switch does not work (message: not found).
Not find some parts of the text with zero length, for example, an empty paragraph. [v1.3.1]
Can not simultaneously combine with other text properties. [v1.3.1]



[:::NumberingStyleName::] - searches for list style - use similar to searches for paragraph style, see above. [v1.3.1]





[:::HyperLinkURL::] - searches for text with the attribute HyperLinkURL

[:::HyperLinkURL::] will find all hyperlinks

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

[:::HyperLinkURL=file:///c:/pokus.odt::] will find a hyperlink in which the URL is the substring file:///c:/pokus.odt.

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

A list of available text attributes (with the values they have in the current selection) can be loaded using the button [ Pick properties ]; this is displayed in the list box next to this button. A brief description of most of these properties can be found here.



Similar character attribute - this function loads any of the character attributes of the current selection that have been manually changed and searches for similarly formatted places. If e.g. the cursor is on text for which the name of the font has been manually changed, all places with a changed name of font will be found. The search box will contain e.g. [:::CharFontName::].

Same characters attribute - this function loads any of the character attributes of the current selection that have been manually changed and searches for identically formatted places. If e.g. the cursor is on text for which the name of the font has been manually changed, all places with a changed font name and the same font name will be searched for. The search box will contain e.g. [:::CharFontName=Arial::].

Limitation: The OOo search engine does not support all the existing paragraph and character properties. Not all combinations work as might be expected.



Replacing

List box 'Replace'

& \0 - both these parameters mean the same thing: on replacement they represent the whole found text

If the expression was searched for using [::BigBlock::], these parameters represent only the block of paragraphs between the start and end marks.

If the object was searched for using [::Note::], [::Field::], [::TextFrame::], [::Picture::], or [::TextTable::], these parameters represent exactly these objects (which are inserted using the clipboard).



\b \e - If the expression was searched for using [::BigBlock::], these parameters represent content of the start and end marks. Limitation: these cannot be used together with subexpressions ().


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

If the search expression was searched for using parentheses (), \1 represents the contents of the first pair of parentheses, \2 corresponds to the contents of the second pair (), etc., up to \9, which corresponds to contents of the 9th pair. Only 1st level parentheses are valid; nested levels inside them are ignored.

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

If you need to switch off the processing of subexpressions (e.g. to preserve compatibility with the regular expressions in standard OOo), you must put the whole search expression within an additional pair of parentheses. Then all other nesting levels of parentheses for replacement will be ignored.

Limitation: Using subexpressions is relatively slow and not fully compatible with the original search function in OOo.

There is an in incompatibility with search wildcards placed immediately after a subexpression, such as (opak)*, which is caused by the principle of sequential searching of sequential blocks of text; see here. In these cases the functions [ Count ] and [ Find all ] return the correct counts, but other functions (without switching to compatibility mode) will not find anything. In more complicated cases you will need to examine what happens,and experiment to get the best results.



\p - inserts an empty paragraph

\t - inserts a tab (\x0009 \#9)

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

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

\c - inserts a manual column break before the found paragraph(s)

\m - inserts a manual page break before the found text

\M - inserts a manual page break after the found paragraph(s)

\r - removes manual column or page breaks in the found paragraph(s)

\xhhhh - inserts a character using the hexadecimal character code (as hhhh)

\#ddddd - inserts character using the decimal character code (as ddddd).



\h{addressURL} - changes the found text to a hyperlink with the URL addressURL

\h{}, \h changes the found text to a hyperlink with a URL of an empty string - this has the effect of deleting a hyperlink's URL (the text of hyperlink of course stays unchanged).

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

This should be used at the same time as searching using [:::HyperLinkURL=::].

If the expression was searched for e.g. using[:::HyperLinkURL=substr::], only hyperlinks will be found whose URLs includes the substring substr. Using \H{repl} in the replace expression will find the text substr in the URL and replace it with repl.

\u - inserts in the replacing expression the URL address of the found text (if a hyperlink is found)

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

The style is applied to the paragraph containing the text of the replaced expression. To set the style to "Default", use \P or \P{}. If this parameter is used a number of times with inserted paragraph(s), the style is changed with every new parameter, and is valid as far as the end of the paragraph. Example: If the expression is replaced using block1\P{Subtitle}\p block2\P{Heading 1} so block1 will be inserted and assigned the style Subtitle, and after it a new paragraph with text block2 will be inserted and assigned the style Heading 1.

\C{Quotation} - sets up the Character style Quotation in the found text

The style is applied on the whole text of the replaced expression. To set to the "Default" style use \C or \C{}. If this parameter is used a number of times, the character style is changed with every new parameter, and the last is valid as far as the end of replacing expression. Example: If the expression was replaced using block1\C{Quotation}block2\C{Example}, block1 will be inserted with the character style Quotation, and after it block2 will be inserted and assigned the character style Example.

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

Applies analogous usage rules to those for the parameter \P{}. List style can be removed with \N or \N{}.

\D - sets up the default formatting for the found text, just like using Ctrl+Shift+Space

Applies analogous usage rules to those for the parameter \C{}.

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

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

\F{New footnote} - inserts a new footnote that contains the text New footnote in the place of replacement

Inside the curly brace it is possible to use any of following parameters: \i, \I, &, or \1

\E{New endnote} - inserts a new endnote in the place of replacement ; analogous to \F

\B{ref1|text} - inserts the text text with the marker ref1 for a cross-reference

Inside the curly brace it is possible to use any of following parameters: \i, \I, &, or \1

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

Meaning of numeral parameters:

first number - type of reference: 0 - page number in Arabic numerals, 1 - chapter number, 2 - the reference text , 3 - above/below , 4 - page number using the numbering type defined in the page style, 5 - category and number of a caption, 6 - 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



\K{w,bookmark_name} - insert bookmark named bookmark_name. [v1.4]

First parameter is mode of anchore:

w - bookmark on whole selected text block

b - bookmark anchored on start of text block

e - bookmark anchored on end of text block

\K{}, \K - remove bookmak if is present in selected text block. It remove only bookmark, text block remain.
\K{w,new_name}\K - rename bookmark - it must be find by [::Bookmark::] or on place with bookmark is present.



\o - inserts the text content of the found object

If the expression was searched for using [::Note::], [::Footnote::], [::Endnote::], [::TextFrame::], [::Picture::], or [::TextTable::], the text inside this object will be inserted. Tables come out with tabs between columns and paragraphs between rows.

Limitation: The maximum size of the whole resulting text after converting a table is limited to 65 kB.

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



\O - inserts the name of the found object

If the expression was searched for using:

[::TextFrame::], [::Picture::], or [::TextTable::], the name of this object will be inserted.

[::Note::] or [::Field::], the type of the text field will be inserted

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

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



\i - inserts the occurrence number of the found object or text in a count of the occurrences in the text - this works only if [ Replace all ] is used

\i{start,digit} - formatted counter: \i{9,4} - count from 9, for 4 digits (0009, 0010, 0011,...) [v1.4]

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

If redirection of the replace expression to another file (\R) is used (see below), the number of the page containing the starting position of the found text is inserted in the other file.

Limitation: this does not work correctly in footnotes, headers and footers.

\v - inserts the contents of the clipboard

\V - inserts contents of the clipboard as unformatted text

\f - preserves format

If & or \0 is used in the replace expression, replacement will be realized using the clipboard. If the found text contains text fields, notes, references etc, they will be preserved in their original state.

\R - redirects the replace expression to another text file

This option causes the replace expression to be inserted into new .odt file instead of replacing the found text. The original file will stay as it is, without changes. To enter the name of the output file, use the format \R{filename}. The name must have the accurate OOo window header format, including the text " - OpenOffice.org Writer". New records from this redirection are always added to the end of the file.

Example:

If the search expression was searched for using [:::HyperLinkURL::] and the replace expression is Link \i, page \I: & (URL: \u)\p\R, when you click the [ Replace all ] button all the hyperlinks found in original file will be listed in a new file in the form Link 1, page 1: textOfHyperlink (URL: URLaddress) in separate paragraphs.



Button and List box 'Pick properties'

Using the [ Pick properties ] button you can update the list of (some) properties and their values for the currently selected object. Then you can browse the list and choose one from the list box next to the button.

\A{properties=value} - sets in the replace expression the value of the specified property.

Uses rules analogous to those for the parameter \C{}.



Batch mode using: [ Batch >> ]

Batch mode enables saving and loading of preset search and replace parameters. It is possible to save several search and replace operations in sequence to a single sequence and then quickly load and execute the whole set.

You can set all parameters using the [ Save batch ] button. In the dialog that is then shown, you will be offered the name used for the last batch, which can be renamed. If you enter an name that already exists, you can choose whether the old content will be overwritten or whether it will be preserved and new content added onto the end. At the same time, the command "ReplaceAll" will automatically be saved, with which the batch will be subsequently executed. This command can later be changed by manually editing the batch rule file.

The button [ Batch >> ] switches to the dialog 'Batch manager', where you can run and edit batches. To return back to the search dialog, use the [ << Searching ] button.

All batch parameters are saved to the text file AltSearchScript.txt into the user's directory /OpenOffice.org2/user/config/, and you can open and edit it using the [ Edit ] button in the Batch manager dialog. For editing the text, the program notepad is used by default, but you can set it to use any other text editor by editing the file AltSearchEditor.ini in the same directory. After manual changing and saving the file using the batch manager you can then refresh the list of batch names using the [ Refresh ] button. The syntax used in the file AltSearchScript.txt is described at the beginning of the same file, using UTF-8 encoding (from v1.1.1).

When you double-click on an item in the list, or click the [ Execute ] button, the chosen sequence will be loaded and the search and replace operations will be executed. When using batches on selections I advise leaving 1-2 empty paragraphs at the beginning and the end of the selection.

The button [ Transfer ] is used for transferring the parameters for searching, replacing and setting to the search dialog without executing them. If the batch contains a sequence of several searches and replacements, only the last part of the sequence will be transferred.

[v1.2] The button [ Key shortcut ] opens a dialog that allows you to assign a keyboard shortcut to an existing batch. To use this:
First select the name of batch from the drop-down menu box
Second, if required, change the name of the auxiliary subroutine for OOo Basic
Third set the desired keyboard shortcut
Finally press the button [ Assign  ]


In order for the shortcut to function, at the time of assignment an auxiliary procedure is created in the Basic module Standard.AltSearchBatchs with a name that is adjusted according to Basic syntax. This name is displayed in the second drop-down menu box of the dialog. When this auxiliary procedure is run, the AltSearch dialog will be opened and immediately the specified batch will be executed. Correct functioning depends on the compliance of the batch name listed inside the procedure and the name of existing batch. If you change the name of batch to which a shortcut key was previously assigned, you will need to re-assign a key shortcut (the old auxiliary procedure to the original name can be deleted by selecting it in the second drop-down box and using the side button ]). Any keyboard shortcut that is used in OOo writer can be released using the lower button [ x ]. So be careful not to inadvertently remove an important shortcut.



[v1.4]

Multiple execute

The selected batch in the Batch manager dialog can be applied to several currently open text files at once:

1st Select Batch in the Batch manager dialog

2nd Click on the button [Multiple execute >>]

3rd Select files for multiple executing from list (using Ctrl + mouse click). The list shows only the currently open files of the "writer" type.

4th Press button [Start] for start of execute. Recommend: During the processing in Ooo You do nothing.

The "Disable message" suppress messages about executed changes after each file. Soon as processing is over, the final report will be displayed.





Limitations:

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




History of changes:

Version 1.4.2   3/2017 [v1.4.2]



Version 1.4.1   11/2015 [v1.4.1]

Version 1.4   12/2013 [v1.4]

News:

Fixed bugs:



Version 1.3.2   6/10 [v1.3.2]

Fixed bugs:



Version 1.3.1   4/10 [v1.3.1]

News:

Fixed bugs:



Version 1.3   11/09 [v1.3]

News:

Fixed bugs:



Version 1.2.2   5/09 [v1.2]

News:

Fixed bugs:





Version 1.2.1   7/08 [v1.2]

News:



Version 1.2   7/08 [v1.2]

News:

Fixed bugs:



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