From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How can I change "buffer" to "string"
Date: Wed, 05 Aug 2015 10:10:16 +0200 [thread overview]
Message-ID: <87wpxap34n.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.7833.1438756549.904.help-gnu-emacs@gnu.org
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
next prev parent reply other threads:[~2015-08-05 8:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.7829.1438746287.904.help-gnu-emacs@gnu.org>
2015-08-05 5:53 ` How can I change "buffer" to "string" 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 [this message]
2015-08-05 3:44 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wpxap34n.fsf@kuiper.lan.informatimago.com \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.