all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How can I change "buffer" to "string"
@ 2015-08-05  3:44 Navy Cheng
  2015-08-05  5:04 ` Ian Zimmerman
  2015-08-05 13:34 ` Drew Adams
  0 siblings, 2 replies; 9+ messages in thread
From: Navy Cheng @ 2015-08-05  3:44 UTC (permalink / raw)
  To: help-gnu-emacs

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




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

* Re: How can I change "buffer" to "string"
  2015-08-05  3:44 How can I change "buffer" to "string" Navy Cheng
@ 2015-08-05  5:04 ` Ian Zimmerman
  2015-08-05 13:34 ` Drew Adams
  1 sibling, 0 replies; 9+ messages in thread
From: Ian Zimmerman @ 2015-08-05  5:04 UTC (permalink / raw)
  To: help-gnu-emacs

On 2015-08-05 11:44 +0800, Navy Cheng wrote:

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

From lisp code or from the keyboard?

-- 
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.




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

* Re: How can I change "buffer" to "string"
       [not found] <mailman.7829.1438746287.904.help-gnu-emacs@gnu.org>
@ 2015-08-05  5:53 ` Pascal J. Bourguignon
  2015-08-05  6:35   ` Navy Cheng
       [not found]   ` <mailman.7833.1438756549.904.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Pascal J. Bourguignon @ 2015-08-05  5:53 UTC (permalink / raw)
  To: help-gnu-emacs

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


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

* Re: How can I change "buffer" to "string"
  2015-08-05  5:53 ` Pascal J. Bourguignon
@ 2015-08-05  6:35   ` Navy Cheng
  2015-08-05  6:49     ` Chunyang Xu
       [not found]   ` <mailman.7833.1438756549.904.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 9+ messages in thread
From: Navy Cheng @ 2015-08-05  6:35 UTC (permalink / raw)
  To: Pascal J. Bourguignon; +Cc: help-gnu-emacs

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




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

* Re: How can I change "buffer" to "string"
  2015-08-05  6:35   ` Navy Cheng
@ 2015-08-05  6:49     ` Chunyang Xu
  0 siblings, 0 replies; 9+ messages in thread
From: Chunyang Xu @ 2015-08-05  6:49 UTC (permalink / raw)
  To: Navy Cheng; +Cc: Pascal J. Bourguignon, help-gnu-emacs


Navy Cheng writes:

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

Move point on that path and M-x ffap, see more on ffap: (info "(emacs) FFAP").

-- 
Chunyang Xu



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

* Re: How can I change "buffer" to "string"
       [not found]   ` <mailman.7833.1438756549.904.help-gnu-emacs@gnu.org>
@ 2015-08-05  8:10     ` Pascal J. Bourguignon
  0 siblings, 0 replies; 9+ messages in thread
From: Pascal J. Bourguignon @ 2015-08-05  8:10 UTC (permalink / raw)
  To: help-gnu-emacs

Navy Cheng <navych@126.com> writes:

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

So the inverse of what I proposed :-)

You're still quite underspecifying.  
How do you select line 2? 
Why line 2 and not line 3?
So since you don't say, I'll assume that you already have the point on
the line you want.


Use:

    (buffer-substring (progn (beginning-of-line) (point))
                      (progn (end-of-line) (point)))

Don't be afraid by the syntax of the printed object, it IS a string.

But since your line contains more than just the path, you will want to
filter it out from the line.  You could do that with a regular
expression, matching the string with string-match, or directly the
buffer with re-search-forward.

For example:

 (progn
   (beginning-of-line)
   (when (re-search-forward "^[0-9]+\\. \\(.*\\)$" (point-max) t)
     (let ((path (match-string 1)))
       (find-file path))))

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


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

* RE: How can I change "buffer" to "string"
  2015-08-05  3:44 How can I change "buffer" to "string" Navy Cheng
  2015-08-05  5:04 ` Ian Zimmerman
@ 2015-08-05 13:34 ` Drew Adams
  2015-08-05 14:24   ` Navy Cheng
       [not found]   ` <mailman.7846.1438784713.904.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 9+ messages in thread
From: Drew Adams @ 2015-08-05 13:34 UTC (permalink / raw)
  To: Navy Cheng, help-gnu-emacs

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

As others have noted, your question is unclear, in particular,
what you mean by "change" is unclear.

My own wild guess is that you want to copy a line from a buffer
as a string.

To copy the current line as a string:
(buffer-substring (line-beginning-position) (line-end-position))



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

* Re: How can I change "buffer" to "string"
  2015-08-05 13:34 ` Drew Adams
@ 2015-08-05 14:24   ` Navy Cheng
       [not found]   ` <mailman.7846.1438784713.904.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Navy Cheng @ 2015-08-05 14:24 UTC (permalink / raw)
  To: help-gnu-emacs

Thank you for all of you. *buffer-substring* is what I want. Sorry again for
my poor English.

On Wed, Aug 05, 2015 at 06:34:18AM -0700, Drew Adams wrote:
> > I want to change one line in a *buffer* to *string*, How can I do that ?
> 
> As others have noted, your question is unclear, in particular,
> what you mean by "change" is unclear.
> 
> My own wild guess is that you want to copy a line from a buffer
> as a string.
> 
> To copy the current line as a string:
> (buffer-substring (line-beginning-position) (line-end-position))
> 




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

* Re: How can I change "buffer" to "string"
       [not found]   ` <mailman.7846.1438784713.904.help-gnu-emacs@gnu.org>
@ 2015-08-05 14:27     ` Rusi
  0 siblings, 0 replies; 9+ messages in thread
From: Rusi @ 2015-08-05 14:27 UTC (permalink / raw)
  To: help-gnu-emacs

On Wednesday, August 5, 2015 at 7:55:16 PM UTC+5:30, Navy Cheng wrote:
> Thank you for all of you. *buffer-substring* is what I want. Sorry again for
> my poor English.
> 
> On Wed, Aug 05, 2015 at 06:34:18AM -0700, Drew Adams wrote:
> > > I want to change one line in a *buffer* to *string*, How can I do that ?
> > 
> > As others have noted, your question is unclear, in particular,
> > what you mean by "change" is unclear.
> > 
> > My own wild guess is that you want to copy a line from a buffer
> > as a string.
> > 
> > To copy the current line as a string:
> > (buffer-substring (line-beginning-position) (line-end-position))
> >

Do check whether its buffer-substring-no-properties that you really want


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

end of thread, other threads:[~2015-08-05 14:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-05  3:44 How can I change "buffer" to "string" Navy Cheng
2015-08-05  5:04 ` Ian Zimmerman
2015-08-05 13:34 ` Drew Adams
2015-08-05 14:24   ` Navy Cheng
     [not found]   ` <mailman.7846.1438784713.904.help-gnu-emacs@gnu.org>
2015-08-05 14:27     ` Rusi
     [not found] <mailman.7829.1438746287.904.help-gnu-emacs@gnu.org>
2015-08-05  5:53 ` Pascal J. Bourguignon
2015-08-05  6:35   ` Navy Cheng
2015-08-05  6:49     ` Chunyang Xu
     [not found]   ` <mailman.7833.1438756549.904.help-gnu-emacs@gnu.org>
2015-08-05  8:10     ` Pascal J. Bourguignon

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.