create new tag
, view all tags
A Nedit macro by Michael Collette and Joachim Lous to "undo hard word wrap" by removing \n characters.


Undoing Hard Word Wrap (removing \n)

 Subject: Re: Some macro/regex help needed
    Date: Tue, 20 Nov 2001 10:51:58 +0100 (MET)
    From: Joachim Lous
Reply-To: discuss@nedit.org
      To: NEdit <discuss@nedit.org>

On Mon, 19 Nov 2001, Michael Collette wrote:

> Aside from this just being kinda messy, it still has one outstanding bug.
> It's unable to clean up spaces to the left of text on the very first line.
> For everything past the first line it cleans up the text pretty well.
> Anyboy have a nicer way of doing this?

Well, just as messy, but fixing your problems:

Use $ and ^ for what they're worth, rather than \n. Also always use
double escapes (\\) in regexes in macros, since there are two rounds
of escape processing: one for parsing the literal code to a string and
one more when parsing the string as a regex. (This is just the sort of
thing I'd like my single-quote patch incorporated for)

So you end up with something like:

    # Remove all extra spaces to the left
    replace_all("^\\s*", "", "regex")

    # Change blank lines to @@@@@
    replace_all("^$", "@@@@@", "regex")

    # Remove all line feeds
    replace_all("\\n", " ", "regex")

    # Now go back and replace any @@@@@ with dbl line feeds
    replace_all("@@@@@", "\\n\\n", "regex")

    # Clean up extra blank space to the right and left of text
    replace_all("^\\s*", "", "regex")
    replace_all("\\s*$", "", "regex")

If you don't need to handle indented paragraphs you can replace the
first two comands with:

    replace_all("^\\s*$", "@@@@@", "regex")

Joachim Lous                                        


  • () TWikiGuest - 2017-10-04
  • If you edit this page: add your name here; move this to the next line; and if you've used a comment marker (your initials in parenthesis), include it before your WikiName.

Page Ratings

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2005-04-06 - RandyKramer
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look