jed-users mailing list

[2006 Date Index] [2006 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Paragraph reformatting functionality


Roey Katz <roey@xxxxxxxxxxxxxxxx> wrote:
>- I want to bind format_paragraph to a key (say, CTRL+semicolon, like 
>"^;")

   Whether or not you can do this depends upon the capabilities of
   your terminal.  If you are using Xjed it is easy.  If you are using
   an old vt100 terminal, it is probably not possible.

>indent.  That is, 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 ()
{
   push_spot (); go_up(1); 
   variable line = line_as_string ();
   pop_spot ();
   
   variable res = ["[0-9]+\\. ",      %  5. this is item 5
                   "[*+-] ",          %  * These are is a bullets
                   ""                 %  Simulates WRAP_INDENTS=1;
                  ];
   foreach (res)
     {
        variable re = ();
        re = strcat ("[ \t]*", re);
        if (1 != string_match (line, re, 1))
          continue;
        variable len;
        (,len) = string_match_nth (0);
        push_spot ();
        bol_trim ();
        whitespace (len);
        pop_spot ();
        return;
     }
}

define text_mode_hook ()
{
   set_buffer_hook ("wrap_hook", "my_wrap_hook");
}

In text-mode, the editor will call the wrap hook each time it wraps a
line while you are typing.  The above function simply checks to see if
the start of the previous line (the one that was just wrapped) matches
any of the regular expressions, and if so indents the current line
accordingly.

Keep in mind that the format_paragraph function knows nothing about
this hook.

--John

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2006 date index] [2006 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]