From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Bruce Ingalls Newsgroups: gmane.emacs.help Subject: Killing Buffers Date: Fri, 02 Jan 2004 18:49:08 GMT Organization: Road Runner - NYC Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1073070034 5934 80.91.224.253 (2 Jan 2004 19:00:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 2 Jan 2004 19:00:34 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 02 20:00:30 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AcUX8-0008LL-00 for ; Fri, 02 Jan 2004 20:00:30 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AcVTs-0007ZY-29 for geh-help-gnu-emacs@m.gmane.org; Fri, 02 Jan 2004 15:01:12 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!nntp.cs.ubc.ca!cyclone.bc.net!newsfeed.telusplanet.net!newsfeed.telus.net!news3.optonline.net!cyclone.rdc-nyc.rr.com!news-out.nyc.rr.com!twister.nyc.rr.com.POSTED!not-for-mail User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en Original-Newsgroups: gnu.emacs.help,gnu.emacs.sources Original-Followup-To: gnu.emacs.help In-Reply-To: Original-Lines: 45 Original-NNTP-Posting-Host: 24.168.135.183 Original-X-Complaints-To: abuse@rr.com Original-X-Trace: twister.nyc.rr.com 1073069348 24.168.135.183 (Fri, 02 Jan 2004 13:49:08 EST) Original-NNTP-Posting-Date: Fri, 02 Jan 2004 13:49:08 EST Original-Xref: shelby.stanford.edu gnu.emacs.help:119724 gnu.emacs.sources:9921 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 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 Xref: main.gmane.org gmane.emacs.help:15667 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:15667 ;I believe I have merged recent posts of buffer killing code into the ;best practices of all, combined here. ;Since the code works, I am too lazy to re-use ;kill-all-other-buffer-frames() to call kill-buffer-frame() but will ;gladly accept patches. Happy Holidays, Bruce ;;__________________________________________________________________________ ;;;;;; kill-buffer-frame (defun kill-buffer-frame () "Tries `delete-frame', then `delete-window', then `kill-buffer' to close the current file, only." (interactive) (condition-case err ;Handle any exceptions (delete-frame) (error (let ((buffer (current-buffer))) (or (one-window-p) (delete-window)) (kill-buffer buffer))))) ;;__________________________________________________________________________ ;;;;;; kill-all-other-buffer-frames (defun kill-all-other-buffer-frames (&optional prefix) "Closes all open files, except current buffer, window and frame. If prefixed with 'C-u', leaves only *scratch* buffer, instead." (interactive "P") (let ((cur-buf-name (buffer-name nil)) (buf-list (buffer-list))) (mapcar (lambda (x) (delete-frame x)) ;close all frames but one, first (cdr (visible-frame-list))) (or (one-window-p) (delete-window)) ;close all windows but one, next (if prefix ;C-u prefix: leave only *scratch* (progn (mapcar (lambda (x) (kill-buffer x)) (buffer-list)) (delete-other-windows)) ;;else leave the current window (setf buf-list (delete-if #'(lambda (buf) (string= (buffer-name buf) cur-buf-name)) buf-list)) (map 'nil #'kill-buffer buf-list)))) ;;__________________________________________________________________________ (global-set-key [(control f4)] 'kill-buffer-frame) ;cua binding ;;Note: C-u prefix leaves only the *scratch* buffer, instead of current ;;buffer (global-set-key [(meta control f4)] 'kill-all-other-buffer-frames)