Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate |
![]() Toolbox for WordPerfect |
||
Macros, tips, and
templates for Corel® WordPerfect® for Windows® |
Page updated Dec 3, 2020 |
|
DeSpacer - Reduces multiple adjacent spaces to single spaces. It can optionally relocate/remove stray single spaces. | |||
• Alternative - If you are not concerned with relocating some single spaces or possibly removing some adjacent format or bookmark codes (see DeSpacer's description in the next column), see the simpler macro below in Footnote 1. • Alternative - If you just need to remove an extra space next to a footnote number or endnote number (to "close up" the preceding text and the number), see the macros in Footnote 2. • Similar "clean up" macro for removing extra hard returns - DelExtraHR.wcm deletes all multiple adjacent hard return codes ([HRt]) and replaces them with a single hard return. Extra hard returns can be caused by pasting material, overuse of the <Enter> key to separate text, etc. The macro is included as part of a small suite of macros that remove unwanted format codes. See DELCODES in the Library. • To find multiple adjacent periods (full stops), commas, etc. use Grammtik (on the Tools menu). It will flag these items -- as well as duplicate adjacent words
-- which are often left behind after lots of cut/copy and paste
operations. Once flagged you can delete the extra ones directly from
the Grammatik dialog. |
DeSpacer.wcm (v1.07) Purposes
But why use this macro instead of (e.g.) Edit, Find and Replace (multiple spaces with a single space)?
Instructions [1] Download the
DESPACER.ZIP archive file (click the link at top of the left column on
this page) to any convenient folder or to your Windows desktop. DESPACER.ZIP is merely a "container" that holds the actual macros. [2] Extract the
macros from that ZIP file and place them in your WordPerfect default
(or supplemental) macro folder so the program can find them. [If you
need help with this see the instructions in the "Downloading..." link.] [3] Open the document that you want to
"despace." Play the Despacer.wcm macro with Tools, Macro, Play
(or Alt+F10). You can choose various options on the menu that pops up:
[4] Click OK. A "Working ... Please wait" message will appear and you can cancel operation from it as well as from the main menu. Tips ☼ Recommended:
If you choose to relocate extra spaces adjacent to format codes — the
first option on the pop up menu — it is recommended that you first clean up "empty" code pairs (e.g., [BoldOn][BoldOff]) with the DelPairs macro in the Library. This should make DeSpacer more accurate with respect to the first option.
☼ You can play the macro on a copy of your document (File, Open, <name>, Open as Copy), then do a comparison (File, Document, Compare) of the copy with the original document to see what has been changed. (File, Document, Compare is not available in the some editions.) ☼ You can assign the macro to a toolbar, keyboard shortcut, or menu for easy access. See here. Notes ¤ If
your document contains hard spaces (i.e., [HSpace] codes, entered from
your keyboard with Ctrl+spacebar), the macro will not treat them as
spaces and thus will not remove them. You can use Reveal Codes to
determine if any remaining (and unexpected) extra spaces are hard
spaces and not normal (spacebar) space characters.
¤ If the macro processes a lot of spaces, you may not be able to undo the change with Edit, Undo (which is limited to 300 levels of undo). Normally, the macro will process the document with just one or a few levels of Undo — but there may be circumstances where this is not true. Therefore you should either abandon the changes and Close without saving (then re-open the document), or use File, Save As, and save it with a different name. ¤ Processing a large document can take time, given the way the macro operates. You may want to play it on a copy of the final draft of your document, after all other edits are done. ¤ Extraneous spaces can be almost anywhere in a document. While the author has tested this macro "nine ways from Sunday," there may be cases where spaces are not removed, or are relocated improperly. If so, please contact the author and he will try to solve the problem and make the macro more robust. In light of this, however, it is recommended that you always work on a copy or a backup of your document.(See disclaimer.) Note: This macro is based on the first option in the DeSpacer.wcm macro above (screen shot of DeSpacer menu), which can relocate solitary spaces that might be misplaced adjacent to many paired format codes. If you use DeSpacer with that option enabled, you don't need to use Relocator on the same document (unless you want to). [You can also download just the Relocator macro here.] Purpose
Notes ¤ It is recommended that you first clean up "empty" code pairs (e.g., [BoldOn][BoldOff]) with the DelPairs macro in the Library. This should make Relocator more accurate.
¤ The exceptions to relocating spaces in the above manner are spaces adjacent to Font (type or size) codes, where users may want spaces in specific locations when a new font or size is applied. Therefore, spaces adjacent to [Font] and [Font Size] codes are skipped during macro play. ¤ Only single spaces are relocated since it must be assumed that some users actually desire multiple spaces in certain locations. If you want to remove all extra spaces use the author's DeSpacer macro (see above). Instructions
|
||
Footnote 1 If you are not concerned with relocating some single spaces, or possibly removing some adjacent format or bookmark codes (see the DeSpacer description above), here's a much simpler macro that should do the job that DeSpacer does. It can also optionally retain all double spaces (see the Note below) as well as single spaces, but it does not have the options included in DeSpacer (see the DeSpacer menu here). To copy the macro below into your WordPerfect program, see the simple instructions here. Note: If you want to retain all double spaces in the current (working) document, you need to add an extra space character to the SearchString() command below (the default is 2 spaces, so change it to 3 spaces with your spacebar). // Macro code begins pResetFindReplace () // (call a procedure to set search parameters to the default) PosDocVeryTop // (start at the top of the document before all other codes and text) OnNotFound(EndNow@) // (when NOT found, jump down and exit) MatchPositionBefore // (when found, place the cursor to the left of the item) SearchString(" ") // <= 2 space characters between the quotes While(True) // (creates an endless loop until a Not Found condition exists) SearchNext(Extended!) // (searches in headers, footers, graphic boxes, etc.) DeleteCharNext pExitSubstructures () // (call another procedure) Endwhile Label(EndNow@) pResetFindReplace () // Macro exits here: Return Procedure pResetFindReplace () SearchString("") ReplaceString("") // Only one Match* command can be active at any one time: // MatchPositionAfter() // MatchExtendSelection() // MatchPositionBefore() MatchSelection() SearchFindWholeWordsOnly(No!) MatchWithAttributes(No!) ReplaceWithAttributes(No!) SearchCaseSensitive(No!) ReplaceWithCase(No!) MatchWithFont(No!) ReplaceWithFont(No!) MatchWithFontSize(No!) ReplaceWithFontSize(No!) SearchInSelection(No!) SearchWordForms(No!) SearchWrap(No!) MatchLimit(No!) EndProcedure Procedure pExitSubstructures () // Exit from any header, footer, footnote, endnote, text box, graphic caption, etc.: While(?Substructure) vSubDoc:=?CurrentSubDoc SubstructureExit If((vSubDoc=10) or (vSubDoc=11)) BoxEnd(Save!) EndIf EndWhile vBoxType:=?BoxContentType // If the cursor is in an image or a text box is selected, exit from it: If(vBoxType=1 or vBoxType=3) BoxEnd(Save!) Endif EndProc // Macro code ends Footnote 2 If you just need to remove any space to the left of a footnote number or endnote number in the main body text area (to "close up" the preceding text characters and the number), here are two simple macros — one to work with footnote numbers and the other to work with endnote numbers. When played, it should change something like ...blah blah 1 to ...blah blah1 To copy the macro below into your WordPerfect program, see the simple instructions here. Notes: [1] Each macro, when played, makes one pass through the document (starting at the bottom of the main document area and working backward). It does this very quickly. It simply searches for each code and, when found, tests to see if there's a space on the left side of the code, and if so, it deletes that space character. (Please note that the test will fail if there's a format code on the left side. The macro will simply continue to the next items, if any.) Tip:
If you might have more than one space preceding one or more
footnote/endnote numbers, simply play the macro more than once as
needed, to remove the remaining single spaces. The message that
displays the result of the pass will return "Processed 0 items" when no more such items are found.
[2] The SearchString() command in each macro below uses the code's 5-digit numerical equivalent instead of the binary code you could insert using your macro toolbar's Codes button. This makes it easier for you to copy the macro into your program and create a functioning macro. [Macro writers: A two-page list of such numerical equivalents to "macro function" [Macro Func] codes can be downloaded here (PDF file).] The alternative is to delete the NToC(nnnn) characters from the SearchString() command and insert the desired binary Code surrounded by double quote marks instead. // Macro #1 code begins: // Remove a space character if it precedes a [Footnote] code - pExitSubstructures () pResetFindReplace () vCount:=0 PosDocBottom PosLineVeryEnd OnNotFound(EndNow@) MatchPositionBefore SearchString(NToC(64427)) // <= [Footnote] code While(True) SearchPrevious(Regular!) If(?LeftChar=" ") // <= space character DeleteCharPrevious vCount:=vCount+1 Endif Endwhile // Exit macro: Label(EndNow@) pResetFindReplace () // (reset Search to defaults) Display(On!) Messagebox(;;"Processed "+vCount+" items") Return Procedure pExitSubstructures () // Exit from any header, footer, footnote, endnote, text box, graphic caption, etc.: While(?Substructure) vSubDoc:=?CurrentSubDoc SubstructureExit If((vSubDoc=10) or (vSubDoc=11)) BoxEnd(Save!) EndIf EndWhile vBoxType:=?BoxContentType // If the cursor is in an image or a text box is selected, exit from it: If(vBoxType=1 or vBoxType=3) BoxEnd(Save!) Endif EndProc Procedure pResetFindReplace () SearchString("") ReplaceString("") // Only one Match* command can be active at any one time: // MatchPositionAfter() // MatchExtendSelection() // MatchPositionBefore() MatchSelection() SearchFindWholeWordsOnly(No!) MatchWithAttributes(No!) ReplaceWithAttributes(No!) SearchCaseSensitive(No!) ReplaceWithCase(No!) MatchWithFont(No!) ReplaceWithFont(No!) MatchWithFontSize(No!) ReplaceWithFontSize(No!) SearchInSelection(No!) SearchWordForms(No!) SearchWrap(No!) MatchLimit(No!) EndProcedure // Macro code ends And to process spaces next to [Endnote] codes - // Macro #2 code begins: // Remove a space character if it precedes an [Endnote] code - pExitSubstructures () pResetFindReplace () vCount:=0 PosDocBottom PosLineVeryEnd OnNotFound(EndNow@) MatchPositionBefore SearchString(NToC(64428)) // <= [Endnote] code While(True) SearchPrevious(Regular!) If(?LeftChar=" ") // <= space character DeleteCharPrevious vCount:=vCount+1 Endif Endwhile // Exit macro: Label(EndNow@) pResetFindReplace () // (reset Search to defaults) Display(On!) Messagebox(;;"Processed "+vCount+" items") Return Procedure pExitSubstructures () // Exit from any header, footer, footnote, endnote, text box, graphic caption, etc.: While(?Substructure) vSubDoc:=?CurrentSubDoc SubstructureExit If((vSubDoc=10) or (vSubDoc=11)) BoxEnd(Save!) EndIf EndWhile vBoxType:=?BoxContentType // If the cursor is in an image or a text box is selected, exit from it: If(vBoxType=1 or vBoxType=3) BoxEnd(Save!) Endif EndProc Procedure pResetFindReplace () SearchString("") ReplaceString("") // Only one Match* command can be active at any one time: // MatchPositionAfter() // MatchExtendSelection() // MatchPositionBefore() MatchSelection() SearchFindWholeWordsOnly(No!) MatchWithAttributes(No!) ReplaceWithAttributes(No!) SearchCaseSensitive(No!) ReplaceWithCase(No!) MatchWithFont(No!) ReplaceWithFont(No!) MatchWithFontSize(No!) ReplaceWithFontSize(No!) SearchInSelection(No!) SearchWordForms(No!) SearchWrap(No!) MatchLimit(No!) EndProcedure // Macro code ends |