abo-abo / ace-window

Quickly switch windows in Emacs
977 stars 87 forks source link

Feature request: add kill buffer and kill buffer and window functions #146

Closed scarab5q closed 5 years ago

scarab5q commented 5 years ago

I have been looking how to kill buffers in ace-window for a while. I've looked about and couldn't find anything. Just before I was about to post this I just decided to write them myself. They are really simple and haven't been rigorously tested but:

(defun aw-kill-buffer (window)
  (kill-buffer '(window-buffer window)))

  (defun aw-kill-buffer-and-window (window)
  "Delete window WINDOW."
  (let ((frame (window-frame window))
    (buffer (window-buffer window)))
    (when (and (frame-live-p frame)
               (not (eq frame (selected-frame))))
      (select-frame-set-input-focus (window-frame window)))
    (if (= 1 (length (window-list)))
        (delete-frame frame)
      (if (window-live-p window)
          (delete-window window)
      (kill-buffer buffer)
        (error "Got a dead window %S" window)))))

I'm still getting to grips with e-lisp and so the first one is really simple and the second one basically just copied your code for delete window but just added and extra variable. I was just wondering what you thought. If there is something else that does this then I am all ears :)

abo-abo commented 5 years ago

Thanks, I've added a new arg to aw-delete-window, see the commit message for an example.

Regarding aw-kill-buffer, I don't think it's that useful, since you don't really know which other buffer will take its place.

rdiaz02 commented 2 years ago

I have been looking how to kill buffers in ace-window for a while. I've looked about and couldn't find anything. Just before I was about to post this I just decided to write them myself. They are really simple and haven't been rigorously tested but:

(defun aw-kill-buffer (window)
  (kill-buffer '(window-buffer window)))

I do like this functionality (the buffer that takes place is often the one that was there right before). Thanks for the code! I think, though, there is a typo and the function should be

(defun aw-kill-buffer (window)
  (kill-buffer (window-buffer window)))
whatacold commented 2 years ago

Here is an advice that I came up to kill the buffer of the selected window:

(advice-add #'ace-window :around
            (lambda (oldfun &rest arg)
              "Prefixed with three C-u's, kill the buffer of that window."
              (if (/= 64 (car arg))
                  (apply oldfun arg)
                (save-window-excursion
                  (apply oldfun arg)
                  (kill-buffer))))
            '((name . kill-buffer)))
heiwiper commented 2 years ago

Regarding aw-kill-buffer, I don't think it's that useful, since you don't really know which other buffer will take its place.

As an example, I sometimes get the "*Warning*" buffer replacing the buffer in window 2 while I'm currently working on the buffer in window 1, so it would be more efficient if I could kill that buffer from where I am instead of having to switch to that window to kill it and then go back.

So instead of M-o 2 C-x k RET M-o 1 we use M-o k 2 (Assuming we have 3 windows visibles).

That being said, I'm not sure if this feature aligns with the purpose of this package since it would be interfering with buffers rather that windows, but that would definitely help avoiding switching between windows when killing a visible buffer is needed.