- Subject: Re: Paragraph reformatting functionality
- From: "G. Milde" <g.milde@xxxxxx>
- Date: Fri, 20 Jan 2006 14:48:02 +0100
Sorry for my last post, it was an accident. While experimenting with the
par_sep buffer hook I got a segfault and insted of "edit" I hit the "send"
button.
On 19.01.06, John E. Davis wrote:
> Roey Katz <roey@xxxxxxxxxxxxxxxx> wrote:
> > I want this:
> >
> > - this is an item. It goes on and on and on and on and on and on and on
> >and on and on and on and on.
> > - this is another item. It, too goes on and on and on and on and on and
> >on and on and on and on.
> >
> >to look like this:
> >
> > - this is an item. It goes on and on and on and on and on and on and on
> > and on and on and on and on.
> > - this is another item. It, too goes on and on and on and on and on and
> > on and on and on and on.
>
> You can use hooks to achieve this effect. For example, consider
>
> define my_wrap_hook ()
...
> Keep in mind that the format_paragraph function knows nothing about
> this hook.
The attached structured_text.sl tries to expand this idea also for
formatting of paragraphs.
There is a problem, though:
* If I want to have "condensed" lists without separating empty lines, I
need to define a line with list marker as paragraph separator.
* By default, a line which is a paragraph separator doesnot get
formatted :-(
So maybe I have to write a format_paragraph from scratch.
Is there a way to call the standard hooks for wrapping and-or indenting?
Günter
--
Milde ife.et.tu-dresden.de
% structured_text: formatting hooks for "ASCII markup"
%
% Copyright (c) 2006 Günter Milde
% Released under the terms of the GNU General Public License (ver. 2 or later)
%
% Versions:
%
% 0.1 first version published together with rst.sl
% 2006-01-20 0.2 including the regular expressions from JED
% documentation
%
% TODO: Lines that are marked as paragraph separator don't get
% formatted when calling format_paragraph :-(
% the set of regular expressions matching a list mark
custom_variable("Text_List_Patterns",
["[0-9]+\\. ", % enumeration
% "[a-z]+\\) ", % enumeration
"[*+-] " % itemize (bullet list)
]);
%!%+
%\function{line_is_list}
%\synopsis{Return length of a list marker}
%\usage{ line_is_list()}
%\description
% Check if the current line starts with a list marker matching one of the
% regular expressions defined in \var{Rst_List_Patterns}.
% Return length of the list marker (excluding leading whitespace)
%\notes
% Thanks to JED for the regular expressions variant
%\seealso{line_is_empty, Text_List_Patterns}
%!%-
define line_is_list()
{
variable len = 0, re;
% get the current line without leading whitespace
push_spot();
bol_skip_white();
push_mark_eol();
variable line = bufsubstr();
pop_spot();
foreach (Text_List_Patterns)
{
re = ();
if (1 != string_match(line, re, 1))
continue;
(,len) = string_match_nth(0);
}
return len;
}
%!%+
%\function{line_is_empty}
%\synopsis{Check if the line is empty (not counting whitespace)}
%\usage{ line_is_empty()}
%\description
% This is the same as the default is_paragraph_separator test.
%\seealso{line_is_list}
%!%-
define line_is_empty()
{
push_spot();
EXIT_BLOCK {pop_spot();}
bol_skip_white();
return eolp();
}
%
%!%+
%\function{st_is_paragraph_separator}
%\synopsis{paragraph separator hook for structured text}
%\usage{st_is_paragraph_separator()}
%\description
% Return 1 if the current line separates a paragraph, i.e. it
% is empty or a list item
%\seealso{line_is_empty, line_is_list}
%!%-
define st_is_paragraph_separator()
{
% show("line", what_line, "calling st_is_paragraph_separator");
return orelse{line_is_empty()}{line_is_list()>0};
% attention: there is a segfault if the paragraph_separator_hook returns
% values higher than 1!
}
%!%+
%\function{st_indent}
%\synopsis{indent-line for structured text}
%\usage{st_indent()}
%\description
% Indent the current line, taking care of list markers as defined in
% \var{Text_List_Patterns}.
%\notes
% Expanded from example in hooks.txt
%\seealso{st_is_paragraph_separator, line_is_list, Text_List_Patterns}
%!%-
define st_indent()
{
variable indent;
% show("line", what_line, "calling st_indent");
% get indendation of previous line
push_spot();
go_up_1;
bol_skip_white();
indent = what_column - 1 + line_is_list();
go_down_1;
indent -= line_is_list(); % de-dent the list marker
bol_trim();
whitespace(indent);
pop_spot();
if (bolp)
skip_white();
}
%!%+
%\function{st_newline_and_indent}
%\synopsis{newline_and_indent for structured text}
%\usage{ st_newline_and_indent ()}
%\description
% Indent to level of preceding line
%\notes
% We need a separate definition, as by default newline_and_indent() uses the
% indent_hook (which structured_text.sl sets to st_indent (considering list
% markers) while with Enter we want more likely to start a new list topic.
%\seealso{st_indent, st_indent_relative}
%!%-
define st_newline_and_indent()
{
% show("line", what_line, "calling st_newline_and_indent");
variable indent, col = what_column();
% get number of leading spaces
push_spot();
bol_skip_white();
indent = what_column();
pop_spot();
newline();
if (indent > col) % more whitespace than the calling points column
indent = col;
whitespace(indent-1);
}
public define text_mode_hook()
{
set_buffer_hook("wrap_hook", &st_indent);
set_buffer_hook("indent_hook", &st_indent);
set_buffer_hook("newline_indent_hook", &st_newline_and_indent);
set_buffer_hook("par_sep", &st_is_paragraph_separator);
}
[2006 date index]
[2006 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]