unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How delete whitespace at END of file automatically when save and exit file?
@ 2003-08-20 22:52 Christian Seberino
  2003-08-20 23:55 ` Jose A. Ortega Ruiz
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Seberino @ 2003-08-20 22:52 UTC (permalink / raw)


delete-trailing-whitespace deletes whitespace at LEFT but not at
BOTTOM!? How do BOTTOM too?


In other words... if I have a bunch of newlines at the end, e.g.
\n\n\n\n\n

...How replace them with just one \n?

chris

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How delete whitespace at END of file automatically when save and exit file?
  2003-08-20 22:52 How delete whitespace at END of file automatically when save and exit file? Christian Seberino
@ 2003-08-20 23:55 ` Jose A. Ortega Ruiz
  2003-08-21  6:39   ` Lute Kamstra
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jose A. Ortega Ruiz @ 2003-08-20 23:55 UTC (permalink / raw)



hi,

(defun my-delete-trailing-lines ()
  (goto-char (point-max))
  (delete-blank-lines))

(add-hook 'write-file-hooks 'my-delete-trailing-lines)

warning: untested :)

hth,
jao

seberino@spawar.navy.mil (Christian Seberino) writes:

> delete-trailing-whitespace deletes whitespace at LEFT but not at
> BOTTOM!? How do BOTTOM too?
>
>
> In other words... if I have a bunch of newlines at the end, e.g.
> \n\n\n\n\n
>
> ...How replace them with just one \n?
>
> chris

-- 
An eye for an eye leaves everyone blind. -Mohandas Karamchand Gandhi
(1869-1948)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How delete whitespace at END of file automatically when save and exit file?
  2003-08-20 23:55 ` Jose A. Ortega Ruiz
@ 2003-08-21  6:39   ` Lute Kamstra
  2003-08-25 23:55   ` Christian Seberino
  2003-08-28 19:11   ` Christian Seberino
  2 siblings, 0 replies; 6+ messages in thread
From: Lute Kamstra @ 2003-08-21  6:39 UTC (permalink / raw)


Jose A. Ortega Ruiz <jao@member.fsf.org> writes:

> (defun my-delete-trailing-lines ()
>   (goto-char (point-max))
>   (delete-blank-lines))
>
> (add-hook 'write-file-hooks 'my-delete-trailing-lines)

In addition,

(setq next-line-add-newlines nil)

helps to prevent inserting empty lines at the end of files.

  Lute

-- 
(spook) => "Compsec USDOJ CIDA"
(insert-file-contents "~/.signature") => (error "`~/.signature' too rude")

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How delete whitespace at END of file automatically when save and exit file?
  2003-08-20 23:55 ` Jose A. Ortega Ruiz
  2003-08-21  6:39   ` Lute Kamstra
@ 2003-08-25 23:55   ` Christian Seberino
  2003-08-28 19:11   ` Christian Seberino
  2 siblings, 0 replies; 6+ messages in thread
From: Christian Seberino @ 2003-08-25 23:55 UTC (permalink / raw)


I tried your function and it worked!! Thanks! Very useful.

Chris


Jose A. Ortega Ruiz <jao@member.fsf.org> wrote in message news:<8765kr995j.fsf@member.fsf.org>...
> hi,
> 
> (defun my-delete-trailing-lines ()
>   (goto-char (point-max))
>   (delete-blank-lines))
> 
> (add-hook 'write-file-hooks 'my-delete-trailing-lines)
> 
> warning: untested :)
> 
> hth,
> jao
> 
> seberino@spawar.navy.mil (Christian Seberino) writes:
> 
> > delete-trailing-whitespace deletes whitespace at LEFT but not at
> > BOTTOM!? How do BOTTOM too?
> >
> >
> > In other words... if I have a bunch of newlines at the end, e.g.
> > \n\n\n\n\n
> >
> > ...How replace them with just one \n?
> >
> > chris

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How delete whitespace at END of file automatically when save and exit file?
  2003-08-20 23:55 ` Jose A. Ortega Ruiz
  2003-08-21  6:39   ` Lute Kamstra
  2003-08-25 23:55   ` Christian Seberino
@ 2003-08-28 19:11   ` Christian Seberino
  2003-08-29 14:51     ` Thien-Thi Nguyen
  2 siblings, 1 reply; 6+ messages in thread
From: Christian Seberino @ 2003-08-28 19:11 UTC (permalink / raw)


Jose

Don't you have to add (delete-trailing-whitespace) to
your write-file-hook??

I made a version based on yours that is almost perfect...

   (defun cs-delete-trailing-whitespace() (interactive)
      (delete-trailing-whitespace)
      (let ((original-pos (point)))
         (goto-char (point-max))
         (delete-blank-lines)
         (goto-char original-pos)))
 
and

(add-hook            'write-file-hooks        'cs-delete-trailing-whitespace)


For some reason these additions make me unable to do save-buffer!!!
I can't do M-x save-buffer anymore!!

M-x save-buffers-kill-emacs still works for some reason.

Chris


Jose A. Ortega Ruiz <jao@member.fsf.org> wrote in message news:<8765kr995j.fsf@member.fsf.org>...
> hi,
> 
> (defun my-delete-trailing-lines ()
>   (goto-char (point-max))
>   (delete-blank-lines))
> 
> (add-hook 'write-file-hooks 'my-delete-trailing-lines)
> 
> warning: untested :)
> 
> hth,
> jao
> 
> seberino@spawar.navy.mil (Christian Seberino) writes:
> 
> > delete-trailing-whitespace deletes whitespace at LEFT but not at
> > BOTTOM!? How do BOTTOM too?
> >
> >
> > In other words... if I have a bunch of newlines at the end, e.g.
> > \n\n\n\n\n
> >
> > ...How replace them with just one \n?
> >
> > chris

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How delete whitespace at END of file automatically when save and exit file?
  2003-08-28 19:11   ` Christian Seberino
@ 2003-08-29 14:51     ` Thien-Thi Nguyen
  0 siblings, 0 replies; 6+ messages in thread
From: Thien-Thi Nguyen @ 2003-08-29 14:51 UTC (permalink / raw)


seberino@spawar.navy.mil (Christian Seberino) writes:

> For some reason these additions make me unable to do save-buffer!!!
> I can't do M-x save-buffer anymore!!

see docstring for var `write-file-hooks'.

thi

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-08-29 14:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-20 22:52 How delete whitespace at END of file automatically when save and exit file? Christian Seberino
2003-08-20 23:55 ` Jose A. Ortega Ruiz
2003-08-21  6:39   ` Lute Kamstra
2003-08-25 23:55   ` Christian Seberino
2003-08-28 19:11   ` Christian Seberino
2003-08-29 14:51     ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).