|
Run par
[Back]
Here are two macros that will interface to the
par paragraph reformatter. Source code for Par can be
found here.
If no selection exists, they will select the current paragraph.
The first macro (Alt+Q) will simply run par with some
default options. The second (Shift+Alt+Q) will prompt you for
additional options.
Format paragraph:Alt+Q::: {
# If no selection, select paragraph
if ($selection_start == -1) {
# select paragraph
start = search("^$", $cursor, "regex", "backward")+1
end = search("^$", $cursor, "regex")
select(start,end)
}
# Get input and run par
input=get_selection()
result=shell_command("par -rTbgqR -B=.\\\\?_A_a -Q=_s\\\\>\\\\|",input)
# Check for errors and replace text
if ( $shell_cmd_status != 0 ) {
dialog(result,"Ok")
} else {
set_cursor_pos($selection_end+1)
replace_selection(result)
}
}
Format para. w/options:Shift+Alt+Q::: {
# If no selection, select paragraph
if ($selection_start == -1) {
# select paragraph
start = search("^$", $cursor, "regex", "backward")+1
end = search("^$", $cursor, "regex")
select(start,end)
}
# Get input and run par
input=get_selection()
options=string_dialog("Par Options:","Ok","Cancel")
if ( $string_dialog_button == 2 ) {
return
}
result=shell_command("par -rTbgqR -B=.\\\\?_A_a -Q=_s\\\\>\\\\| " options,input)
# Check for errors and replace text
if ( $shell_cmd_status != 0 ) {
dialog(result,"Ok")
} else {
set_cursor_pos($selection_end+1)
replace_selection(result)
}
}
[Back]
Released on Wed, 21 Nov 2001
by
C. Denat
|
|