# From http://nedit.gmxhome.de/macros/better_fill_par.nm # # Improvements by Volker Kuhlmann : # * 29 Oct 2006 # - Make par handle tabs in the input as per current tab size (par's default: 1). # Unfortunately par always converts tabs in the output to spaces. # * 6 Jan 2004 # - Turned into a callable function # - Post-operation cursor position and selection status compatible with ^J # (for none and simple selection, not yet for rectangular selection) # # .-"""-. # / .===. \ # / / a a \ \ # / ( \___/ ) \ # _________________ooo\__\_____/__/____________________ # / \ # | Better fill_paragraph() with the help of the external | # | paragraph formatter par, by Adam M. Costello. | # | http://www.nicemice.net/par/ | # | Hopefully such things can be integrated into NEdit | # | some day. | # \_________________________________ooo_________________/ # / \ # /:.:.:.:.:.:.:\ # | | | # \==|==/ # /-'Y'-\ # (__/ \__) define better_fill_par { # This warning isn't really appropriate if this function is to replace ^J -VK if ($wrap_text=="continuous") { dialog("This kind of formatting doesn't really make sense\n"\ "in continuous wrapping mode") return } # Options for the par program. See man par for their meanings. # Unfortunately par refuses to handle tabs in its output. options = "T"$tab_dist" B+.,:\\;\\?_A_a Q+_s\\>\\|" if ($selection_start == -1) { pos = $cursor if ($column == 0) forward_character() backward_paragraph() start = $cursor forward_paragraph() end = $cursor - 1 if (end == start + 1) end = start set_cursor_pos(pos) newpar = shell_command("par " $wrap_margin options, get_range(start,end)) replace_range(start, end, newpar) end = start + length(newpar) if (pos > end) pos = end set_cursor_pos(pos) } else { # test for rectangle if ($selection_left == -1) { # no rectangle start = $selection_start newpar = shell_command("par " $wrap_margin options, get_selection()) replace_selection(newpar) end = start + length(newpar) select(start, end) set_cursor_pos(end) } else { # rectangular selection # Final cursor position and maintaining the selection (as in above 2 # cases) not yet implemented -VK width = $selection_right - $selection_left set_cursor_pos($selection_end) select_rectangle($selection_start, $selection_end,\ $selection_left, 10*$wrap_margin) replace_selection(shell_command("par " width options, get_selection())) delete_previous_character() } } }