From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Brian Palmer Newsgroups: gmane.emacs.help Subject: Re: Killing Buffers Date: 02 Jan 2004 12:54:49 -0800 Organization: Stanford University, CA, USA Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <0whr7yim5pi.fsf@rescomp.Stanford.EDU> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1073077222 19399 80.91.224.253 (2 Jan 2004 21:00:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 2 Jan 2004 21:00:22 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 02 22:00:17 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 1AcWP3-0006Fm-00 for ; Fri, 02 Jan 2004 22:00:17 +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 1AcXLp-0003ui-Mr for geh-help-gnu-emacs@m.gmane.org; Fri, 02 Jan 2004 17:01:01 -0500 Original-Path: shelby.stanford.edu!not-for-mail Original-Newsgroups: gnu.emacs.help,gnu.emacs.sources Original-Lines: 57 Original-NNTP-Posting-Host: rescomp.stanford.edu Original-X-Trace: news.Stanford.EDU 1073076892 12230 171.64.136.254 (2 Jan 2004 20:54:52 GMT) Original-X-Complaints-To: news@news.stanford.edu User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Portable Code) Original-Xref: shelby.stanford.edu gnu.emacs.help:119726 gnu.emacs.sources:9922 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:15669 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:15669 Bruce Ingalls writes: > ;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 Interesting; I doubt I'll use these, since I'm relatively content with just C-x C-b and marking all the buffers to delete, but here are some revisions I've made to the code. Feel free to accept any changes you like (I release any part belonging to me into the public domain, if possible, and license it for any and all use if not). The big changes I made were shortening the first sentence in the docstring so that apropos kill.*buffer is meaningful, and eliminating some of your lambdas (mapcar (lambda (x) (f x)) l) is the same as (mapcar 'f l) in elisp, I believe, and even in cl it only makes a difference if you're trying to capture existing variables). Similarly, I replaced (map nil ....) with mapcar, and used delete instead of delete-if (since string= is a special form of equal, which is what delete uses). At any rate, lightly tested on xemacs 21.4.8 (defun kill-buffer-frame () "Kill the current frame, or current buffer and delete its window." (interactive) (condition-case nil (delete-frame) (error (let ((buffer (current-buffer))) (or (one-window-p) (delete-window)) (kill-buffer buffer))))) (defun kill-all-other-buffer-frames (&optional prefix) "Close other open files, and kill other frames and windows. With prefix argument, kill all buffers, leaving only the default *scratch* buffer." (interactive "P") (let ((cur-buf-name (buffer-name)) (buffers-to-kill (buffer-list))) (if (null prefix) (setf buffers-to-kill (delete cur-buf-name buffers-to-kill))) (mapcar 'delete-frame (cdr (visible-frame-list))) (or (one-window-p) (delete-window)) (mapcar 'kill-buffer buffers-to-kill) (delete-other-windows))) ;;__________________________________________________________________________ (global-set-key [(control f4)] 'kill-buffer-frame) ;cua binding (global-set-key [(meta control f4)] 'kill-all-other-buffer-frames) -- I'm awfully glad I'm a Beta, because I don't work so hard.