From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: find-file-noselect Date: Thu, 30 Aug 2012 21:48:21 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1346377819 29440 80.91.229.3 (31 Aug 2012 01:50:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Aug 2012 01:50:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 31 03:50:18 2012 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 1T7GND-0000dD-KQ for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Aug 2012 03:50:15 +0200 Original-Received: from localhost ([::1]:34080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7GNB-0005T8-7p for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Aug 2012 21:50:13 -0400 Original-Path: usenet.stanford.edu!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe15.iad.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) Cancel-Lock: sha1:NDGEfMdhZrxGufM4LJKsSJE0DIc= Original-Lines: 27 Original-X-Complaints-To: abuse@UsenetServer.com Original-NNTP-Posting-Date: Fri, 31 Aug 2012 01:48:23 UTC X-Received-Bytes: 1619 Original-Xref: usenet.stanford.edu gnu.emacs.help:194256 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:86602 Archived-At: > (save-excursion > (let ((foo (get-buffer (find-file-noselect "/home/drain/foo.org")))) > (set-buffer foo) > (insert "test operation"))) To clarify: in the above, find-file-noselect returns a buffer, so `get-buffer' just returns its argument. And save-excursion + set-buffer is better replaced by with-current-buffer. All in all: (with-current-buffer (find-file-noselect "/home/drain/foo.org") (insert "test operation")) > I want to open a shell buffer, but do not want to select it (so I stay in > the current buffer). Just like the above, but with the shell instead of > foo.org. find-file-noselect re-uses an existing buffer (if there is one). So if you want the equivalent for a shell-style buffer, you could try (with-current-buffer (or (get-buffer "*shell*") (make-comint-in-buffer "shell" nil "/bin/bash")) (unless (derived-mode-p 'comint-mode) (shell-mode)) (insert "test operation")) -- Stefan