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

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

Re: How can I change "buffer" to "string"


From: Pascal J. Bourguignon
Subject: Re: How can I change "buffer" to "string"
Date: Wed, 05 Aug 2015 07:53:27 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Navy Cheng <navych@126.com> writes:

> Hi,
> I want to change one line in a *buffer* to *string*, How can I do that ?

Your question is ambiguous.

Assuming you have a current buffer and a variable bound to a string,
if you want to replace the line where the point is currently with the
contents of your string, you could do:

    (delete-region (progn (beginning-of-line) (point))
                   (progn (end-of-line) (point)))
    (insert string)

For example, to change the first line of the *scratch* buffer, you could
evaluate:

(let ((string ";; This is a new line for a lisp buffer."))
  (with-current-buffer "*scratch*"
    (goto-line 1)
    (delete-region (progn (beginning-of-line) (point))
                   (progn (end-of-line) (point)))
    (insert string)))


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

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