unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Why adding this write-file-hook makes save-buffer not work anymore!??
@ 2003-08-28 19:14 Christian Seberino
  2003-08-28 20:06 ` Kai Großjohann
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Seberino @ 2003-08-28 19:14 UTC (permalink / raw)


I want to delete a lot of whitespace when I save a file so I make
following function be invoked when I write a file....

   (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 I set up hook like this

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


When I try to do save-buffer it does not work?? What is the problem?!?!

Chris

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

* Re: Why adding this write-file-hook makes save-buffer not work anymore!??
  2003-08-28 19:14 Why adding this write-file-hook makes save-buffer not work anymore!?? Christian Seberino
@ 2003-08-28 20:06 ` Kai Großjohann
  2003-08-29  2:46   ` Christian Seberino
  0 siblings, 1 reply; 5+ messages in thread
From: Kai Großjohann @ 2003-08-28 20:06 UTC (permalink / raw)


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

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

I think this returns non-nil, and as the docs say, "if one of them
returns non-nil, then ... the others are not called".

>From C-h v write-file-functions RET.
-- 
Two cafe au lait please, but without milk.

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

* Re: Why adding this write-file-hook makes save-buffer not work anymore!??
  2003-08-28 20:06 ` Kai Großjohann
@ 2003-08-29  2:46   ` Christian Seberino
  2003-08-29  8:24     ` Joakim Hove
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Seberino @ 2003-08-29  2:46 UTC (permalink / raw)


Kai

Thanks for your help.  What makes my function return non-nil
and how do I make it return nil???

Chris


kai.grossjohann@gmx.net (Kai Großjohann) wrote in message news:<84isohfsx0.fsf@slowfox.is.informatik.uni-duisburg.de>...
> seberino@spawar.navy.mil (Christian Seberino) writes:
> 
> >    (defun cs-delete-trailing-whitespace() (interactive)
> >       (delete-trailing-whitespace)
> >       (let ((original-pos (point)))
> >          (goto-char (point-max))
> >          (delete-blank-lines)
> >          (goto-char original-pos)))
> 
> I think this returns non-nil, and as the docs say, "if one of them
> returns non-nil, then ... the others are not called".
> 
> From C-h v write-file-functions RET.

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

* Re: Why adding this write-file-hook makes save-buffer not work anymore!??
  2003-08-29  2:46   ` Christian Seberino
@ 2003-08-29  8:24     ` Joakim Hove
  2003-08-31 11:50       ` Alan Mackenzie
  0 siblings, 1 reply; 5+ messages in thread
From: Joakim Hove @ 2003-08-29  8:24 UTC (permalink / raw)



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


> Thanks for your help.  What makes my function return non-nil
> and how do I make it return nil???

The last evaluated statement of your function is the return value,
i.e. in your function the return value is the result of:

   (goto-char original-pos)

The documentation of (goto-char ) does not say, but the little test
function:

  (defun testit ()
    (interactive)
    (message "Point-max: %s" (goto-char (point-max))) (sleep-for 5)
    (message "Point-min: %s" (goto-char (point-min))) (sleep-for 5))

quickly reveals that (goto-char ) returns the value of the point it
has moved to (at least when it succeeds), i.e. the value of
original-pos in your case.

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

To return 'nil just change the last lines:

;; snip
  (goto-char original-pos)
  'nil))

HTH - Joakim

-- 
  /--------------------------------------------------------------------\
 / Joakim Hove  / hove@bccs.no  /  (55 5) 84076       |                 \
 | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
 | CMU                                                | 5231 Paradis    |
 \ Thormøhlensgt.55, 5020 Bergen.                     | 55 91 28 18     /
  \--------------------------------------------------------------------/

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

* Re: Why adding this write-file-hook makes save-buffer not work anymore!??
  2003-08-29  8:24     ` Joakim Hove
@ 2003-08-31 11:50       ` Alan Mackenzie
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Mackenzie @ 2003-08-31 11:50 UTC (permalink / raw)


Joakim Hove <hove@bccs.no> wrote on Fri, 29 Aug 2003 10:24:05 +0200:

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

> To return 'nil just change the last lines:

> ;; snip
>   (goto-char original-pos)
>   'nil))

Or even

 (goto-char original-pos)
 nil))

You don't need to quote "nil".  :-)

> HTH - Joakim

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

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

end of thread, other threads:[~2003-08-31 11:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-28 19:14 Why adding this write-file-hook makes save-buffer not work anymore!?? Christian Seberino
2003-08-28 20:06 ` Kai Großjohann
2003-08-29  2:46   ` Christian Seberino
2003-08-29  8:24     ` Joakim Hove
2003-08-31 11:50       ` Alan Mackenzie

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).