- Subject: [jed-users] Re: Word wrap / paragraph fill for Python comments?
- From: Morten Bo Johansen <mbj@xxxxxxxxx>
- Date: Wed, 30 Apr 2025 18:16:39 +0200
Tom Culliton <tom.culliton@xxxxxxxxx> wrote:
> Before I go off and reinvent the wheel:
>
> - Does anyone have a tweaked Python mode in their back pocket that does
> good word wrap for comment blocks?
Take a look at slmode.sl. Therein is an example of the use of the
wrapok_hook.
Unfortunately, it is not generally usable, i.e. you can't just autoload
these functions from another mode.
I attach a small file, "wrap_hooks.sl", where I have tweaked the functions
from slmode.sl slightly so they should work universally with any mode.
Then you may simply "require" or "evalfile" it from your ~/.jedrc and then
in any mode's definition function, insert the two lines
set_buffer_hook("wrapok_hook", &wrapok_hook);
set_buffer_hook("wrap_hook", &wrap_hook);
Then comment lines will wrap with any such mode and the comment prefix will
be inserted automatically at the beginning of the new line.
Of course it would be better if this solution - or perhaps a better solution
that I don't know of - were distributed with Jed.
Regards,
Morten
private variable Cmt_Prefix = "#";
private define skip_comment_whitespace ()
{
skip_white ();
skip_chars (Cmt_Prefix);
if (looking_at ("//!") || looking_at ("///")) % doxygen
go_right (3);
skip_white ();
}
private define mark_comment_whitespace ()
{
bol ();
push_mark ();
skip_comment_whitespace ();
}
define wrapok_hook ()
{
Cmt_Prefix = get_comment_info(get_mode_name).cbeg;
push_spot ();
bol_skip_white ();
looking_at(Cmt_Prefix);
pop_spot();
}
define wrap_hook ()
{
push_spot ();
go_up_1 ();
mark_comment_whitespace ();
variable prefix = bufsubstr ();
go_down_1 ();
insert (prefix);
pop_spot ();
}
[2025 date index]
[2025 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]