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

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

Killing Buffers


From: Bruce Ingalls
Subject: Killing Buffers
Date: Fri, 02 Jan 2004 18:49:08 GMT
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4

;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)


reply via email to

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