help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Killing Buffers


From: Brian Palmer
Subject: Re: Killing Buffers
Date: 02 Jan 2004 12:54:49 -0800
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Portable Code)

Bruce Ingalls <bingalls@fit-zones.NO-SPAM.com> 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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]