help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to get around deprecated function


From: Emanuel Berg
Subject: Re: how to get around deprecated function
Date: Fri, 01 May 2015 03:17:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

"B. T. Raven" <address@hidden> writes:

> Thanks, Emanuel and Rusi. GT signs are there because
> I copypasted out of gnus.help where I posted by
> mistake. I should have stripped them.

Well, quoting is an acquired craft. If you have the
attitude of learing, let me also advice you to not
quote the entire message replied-to but rather just
what you wish to provide as context for your latest
additions to the thread.

> (defun save-scratchtemp ();; M-x sch
>  (interactive)
>   (save-excursion
>  (with-current-buffer "*scratch*"
>       (mark-whole-buffer)
>    ;;(setq start (point) end (mark))
>      (append-to-file nil nil "c:/mydocu~1/scratchtemp.txt")))
> )

You don't have to use `save-excursion' because you
don't need `mark-whole-buffer'. You use save-excursion
when you move point, which indeed mark-whole-buffer
does, but since that isn't required, you don't need
save-excursion.

In general, try not to move the point from Elisp.
But there are many times when it is needed, and then,
yes, use save-excursion.

> which also "works." Also I may not need
> save-excursion even if my current buffer is not
> *scratch*.

You don't need save-excursion but it doesn't have
anything to do with the current buffer.
`with-current-buffer' is perhaps (?) misleading -
think of it as `do-with-buffer'. This is all you need:

    (with-current-buffer "test.txt"
      (append-to-file nil nil "test-log.txt") )

If you are to put it in a hook, you should check there
is such a buffer as well.

> I used nil nil for start, end maybe unnecessarily if
> append-to-file renumbers the argument list.

No, that is the right thing to do. In the help for
`append-to-file', it says

    If START is nil, that means to use the entire
    buffer contents.
    If START is a string, then output that string to
    the file instead of any buffer contents; END
    is ignored.

So though it isn't spelled out when "START is nil",
I think it is safe to assume "END is ignored" there as
well as when "START is a string". Besides, what else
could it (not) do? Feel free to verify this by
checking out the code. Perhaps it should be added to
the docs (one more "END is ignored") to rule out
confusion? (If that *isn't* the case that should
definitely be spelled out.)

> (add-hook 'lisp-interaction-mode-hook (function
> (lambda () (setq buffer-offer-save t))))

With `add-hook', you don't need `function'
before lambda. Just put the lambda there (unquoted).

    (add-hook 'lisp-interaction-mode-hook (lambda () ...)

But, what are you trying to do? I think you are better
of to tell Emacs to automatically save it on exit.

By the way, and people probably have different views
on this, but I think all that add-hook stuff is
confusing. It is better to find out what the hook is.
Offen it is empty or consists of a single or but a few
items. Examine what is there and decide if you want
it. Then set up the hook explicitly, e.g.

    (setq perl-mode-hook 'enable-line-mode) ; Perl

But there is nothing wrong with add-hook and I use it
sometimes dynamically. But in init files, I don't see
why not setting up the hooks explicitly offers
a higher degree of clarity and control.

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]