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: B . T . Raven
Subject: Re: how to get around deprecated function
Date: 5 May 2015 08:41:57 -0700
User-agent: Direct Read News 5.60

<87y4l9p04r.fsf@debian.uxu>Emanuel BergFri, 01 May 2015 03:17:08 +0200
>
>"B. T. Raven" <btraven@nihilo.net> writes:

[See bottom post]

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

Thanks again Emanuel. Some of that is over my head but at least now I have:

(defun save-scratchtemp () ;; M-x sch
(interactive)
(with-current-buffer "*scratch*"
   (append-to-file nil nil "c:/mydocu~1/scratchtemp.txt")))


The following related function might also benefit from some "subtractional
betterment" in case you care to comment. This just appends the line where cursor
(or maybe more accurately 'point') happens to be to the *scratch* buffer. I know
I can make beg, end local to function by using let instead of setq but I always
re-initialize beg and end:


(defun append-line-to-starscratch ();; M-x asl
(interactive)
(move-beginning-of-line nil)
(set-mark-command nil) (setq beg (point))
(move-end-of-line nil) (setq end (point))
(kill-ring-save beg end)
(with-current-buffer "*scratch*"
     (end-of-buffer) (insert "\n")
     (yank)))



reply via email to

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