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: Navy Cheng
Subject: Re: How can I change "buffer" to "string"
Date: Wed, 5 Aug 2015 14:35:20 +0800
User-agent: Mutt/1.5.23 (2014-03-12)

Sorry for my ambiguous question.

For example, I have a buffer *mybuf*. The buffer contain some lines. such as

1. ...
2. /home/navy/test.c
3. ...

Now, I want to assignment the path in line 2 to a variable, *path*. And I
to (find-file path).

Thank you.

On Wed, Aug 05, 2015 at 07:53:27AM +0200, Pascal J. Bourguignon wrote:
> 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]