From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Stewart Newsgroups: gmane.emacs.help Subject: Re: How delete Dired buffer automatically when select a file in Dired? Date: Tue, 09 Dec 2008 03:54:19 +0800 Message-ID: <87hc5ee93o.fsf@debian.domain> References: <6a632726-cf28-4acf-b78b-94fb68a0f278@d36g2000prf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1228766219 21145 80.91.229.12 (8 Dec 2008 19:56:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Dec 2008 19:56:59 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 08 20:58:03 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L9mEw-0003eA-8x for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Dec 2008 20:57:58 +0100 Original-Received: from localhost ([127.0.0.1]:34491 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L9mDl-0006pT-10 for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Dec 2008 14:56:45 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L9mCR-0005X6-BP for help-gnu-emacs@gnu.org; Mon, 08 Dec 2008 14:55:23 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L9mCO-0005T7-5u for help-gnu-emacs@gnu.org; Mon, 08 Dec 2008 14:55:22 -0500 Original-Received: from [199.232.76.173] (port=43019 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L9mCN-0005Sj-MG for help-gnu-emacs@gnu.org; Mon, 08 Dec 2008 14:55:19 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:51847 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L9mCN-0007E2-BB for help-gnu-emacs@gnu.org; Mon, 08 Dec 2008 14:55:19 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L9mCI-0005dj-Be for help-gnu-emacs@gnu.org; Mon, 08 Dec 2008 19:55:14 +0000 Original-Received: from 222.212.128.246 ([222.212.128.246]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Dec 2008 19:55:14 +0000 Original-Received: from lazycat.manatee by 222.212.128.246 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Dec 2008 19:55:14 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 66 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 222.212.128.246 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:dzGnKpUJ0oaGbyXZG6iqt+TRYis= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:60480 Archived-At: Hi, "seberino@spawar.navy.mil" writes: > When I select a file in Dired, it opens in a new buffer. > > The old Dired buffer still exists. > > How automatically delete the Dired buffer when I open a new buffer > with a new file from Dired? > > Chris Try to use my functions, `dired-up-directory-single' for up directory. `dired-find-file+' for open file or directory. My function will kill old buffer when current directory in only visible in current window, otherwise, stay current buffer. ,---- | | (defun dired-up-directory-single () | "Return up directory in single window. | When others visible window haven't current buffer, kill old buffer after `dired-up-directory'. | Otherwise, just `dired-up-directory'." | (interactive) | (let ((old-buffer (current-buffer)) | (current-window (selected-window))) | (dired-up-directory) | (catch 'found | (walk-windows | (lambda (w) | (with-selected-window w | (when (and (not (eq current-window (selected-window))) | (equal old-buffer (current-buffer))) | (throw 'found "Found current dired buffer in others visible window."))))) | (kill-buffer old-buffer)))) | | (defun dired-find-file+ () | "Like `dired-find-file'. | When open directory, if others visible window have this directory, do `find-file'. | Otherwise do `find-alternate-file'. | When open file, always use `find-file'." | (interactive) | (set-buffer-modified-p nil) | (let ((file (dired-get-file-for-visit)) | (old-buffer (current-buffer)) | (current-window (selected-window))) | (if (file-directory-p file) | (catch 'found | (walk-windows | (lambda (w) | (with-selected-window w | (when (and (not (eq current-window (selected-window))) | (equal old-buffer (current-buffer))) | (find-file file) | (throw 'found "Found current dired buffer in others visible window."))))) | (find-alternate-file file)) | (find-file file)))) `---- Enjoy! -- Andy