jed-users mailing list

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

Re: [jed-users] rm trailing whitespace on write


On 16.02.17, Bernhard Seckinger wrote:
> Hi pdg,

> > Anybody have a mechanism to remove trailing whitespace
> > on buffer write (or read I guess).

> I'm not sure, if this is, what you're looking for, but I use the following in
> my .jedrc to remove trailing whitespaces, whenever I save the buffer:

> define my_trim_buffer()
> {
>     push_spot();
>     while (up_1()) { eol_trim(); bol(); }
>     pop_spot();
>     push_spot();
>     while (down_1()) { eol_trim(); bol(); }
>     pop_spot();
> }

> add_to_hook("_jed_save_buffer_before_hooks",&my_trim_buffer);

> Note, that it does not remove empty lines at the end of the buffer.

Here is another variant, that also removes trailing multiple empty lines
(but leaves the newline char on the last line intact):

% Trim buffer but keep multiple blank lines:
public define trim_buffer_lines()
{
   % remove whitespace at end of lines
   push_spot_bob();
   do {
      eol_trim();
   }
   while (down_1());
   % remove empty lines at end of buffer
   eob();
   do {
      go_left_1();
      if (bolp() and eolp())
	 del();
   }
   while (bolp());

   pop_spot();
   !if (BATCH) message ("done.");
}
_______________________________________________
For list information, visit <http://jedsoft.org/jed/mailinglists.html>.


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