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 10:10:16 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Navy Cheng <address@hidden> 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


reply via email to

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