From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Navy Cheng Newsgroups: gmane.emacs.help Subject: Re: How can I change "buffer" to "string" Date: Wed, 5 Aug 2015 14:35:20 +0800 Message-ID: <20150805063520.GA22606@debian> References: <87a8u6qo14.fsf@kuiper.lan.informatimago.com> Reply-To: Navy Cheng NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1438756568 13903 80.91.229.3 (5 Aug 2015 06:36:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Aug 2015 06:36:08 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Pascal J. Bourguignon" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 05 08:35:59 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZMsIw-0005EB-Rf for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Aug 2015 08:35:58 +0200 Original-Received: from localhost ([::1]:39297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMsIv-0005ZH-P2 for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Aug 2015 02:35:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMsIi-0005Z8-IT for help-gnu-emacs@gnu.org; Wed, 05 Aug 2015 02:35:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZMsIc-0008T7-Ut for help-gnu-emacs@gnu.org; Wed, 05 Aug 2015 02:35:44 -0400 Original-Received: from m15-113.126.com ([220.181.15.113]:57950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMsIc-0008Sl-6E for help-gnu-emacs@gnu.org; Wed, 05 Aug 2015 02:35:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=0AAOW K3LwRB3O5haCGKgl62F/e3xxtEk/3jfhkzhMQE=; b=IbpGZgt/eWG5ffyuOWbh8 WpOXilw+KqC1NFJ4n3k/U9EzC723DfsMHjB8N3sEXYhJNOwDROa8x/PIJ0oUBoQR q+kFuUNPTqH9pixqS5pppqXYAb4Kmlxxcda5j57d2DvDYvoV/gIRy+Pk4NbA7suz DWLfaRwbXRP4ZlWY07nS1c= Original-Received: from localhost (unknown [140.207.196.4]) by smtp3 (Coremail) with SMTP id DcmowACntn2orsFV8BGGAQ--.45416S3; Wed, 05 Aug 2015 14:35:22 +0800 (CST) Content-Disposition: inline In-Reply-To: <87a8u6qo14.fsf@kuiper.lan.informatimago.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-CM-TRANSID: DcmowACntn2orsFV8BGGAQ--.45416S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zry3WF4ruF13Kw4DGF13CFg_yoW8Gr47pa ya9FyjkF4vkr97Ar9Fqw4fJFyaq3Z0yr13GFWrJrW7Aay3tFyUXr47KrZ8ZF4DuF129F4I q3yj9rykua15KFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j94SrUUUUU= X-Originating-IP: [140.207.196.4] X-CM-SenderInfo: 5qdy5ubk6rjloofrz/1tbijgtNDVGfUCDckAAAs3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.15.113 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106245 Archived-At: 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 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