From e0143335522bda205591cab09407e3bec41c9a40 Mon Sep 17 00:00:00 2001 From: Leo Liu Date: Sat, 21 Aug 2010 15:35:27 +0200 Subject: [PATCH] =?utf8?q?Fix=20buffer-list=20rename&refresh=20after=20aft?= =?utf8?q?er=20killing=20a=20buffer=20in=20ido.=20*=20lisp/ido.el:=20Rever?= =?utf8?q?t=20=C3=93scar's.=20(ido-kill-buffer-at-head):=20Exit=20the=20mi?= =?utf8?q?nibuffer=20with=20ido-exit=3Drefresh.=20Remember=20the=20buffers?= =?utf8?q?=20at=20head,=20rather=20than=20their=20name.=20*=20lisp/iswitch?= =?utf8?q?b.el=20(iswitchb-kill-buffer):=20Re-make=20the=20list.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lisp/ChangeLog | 8 ++++++ lisp/ido.el | 66 +++++++++++++++++++----------------------------- lisp/iswitchb.el | 10 +++++--- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f6aa59c2db5..2318ce84600 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2010-08-21 Leo + + Fix buffer-list rename&refresh after after killing a buffer in ido. + * lisp/ido.el: Revert Óscar's. + (ido-kill-buffer-at-head): Exit the minibuffer with ido-exit=refresh. + Remember the buffers at head, rather than their name. + * lisp/iswitchb.el (iswitchb-kill-buffer): Re-make the list. + 2010-08-21 Kirk Kelsey (tiny change) Stefan Monnier diff --git a/lisp/ido.el b/lisp/ido.el index 6cedccb3787..a4409775a86 100644 --- a/lisp/ido.el +++ b/lisp/ido.el @@ -1042,11 +1042,11 @@ Value is an integer which is number of chars to right of prompt.") ;; Stores the current list of items that will be searched through. ;; The list is ordered, so that the most interesting item comes first, ;; although by default, the files visible in the current frame are put -;; at the end of the list. -(defvar ido-cur-list nil) +;; at the end of the list. Created by `ido-make-item-list'. +(defvar ido-cur-list) ;; Stores the choice list for ido-completing-read -(defvar ido-choice-list nil) +(defvar ido-choice-list) ;; Stores the list of items which are ignored when building ;; `ido-cur-list'. It is in no specific order. @@ -3348,12 +3348,9 @@ for first matching file." (if ido-temp-list (nconc ido-temp-list ido-current-buffers) (setq ido-temp-list ido-current-buffers)) - (if (and default (buffer-live-p (get-buffer default))) - (progn - (setq ido-temp-list - (delete default ido-temp-list)) - (setq ido-temp-list - (cons default ido-temp-list)))) + (if default + (setq ido-temp-list + (cons default (delete default ido-temp-list)))) (run-hooks 'ido-make-buffer-list-hook) ido-temp-list)) @@ -3594,7 +3591,6 @@ for first matching file." ;; Used by `ido-get-buffers-in-frames' to walk through all windows (let ((buf (buffer-name (window-buffer win)))) (unless (or (member buf ido-bufs-in-frame) - (minibufferp buf) (member buf ido-ignore-item-temp-list)) ;; Only add buf if it is not already in list. ;; This prevents same buf in two different windows being @@ -3835,27 +3831,6 @@ for first matching file." ;;(add-hook 'completion-setup-hook 'completion-setup-function) (display-completion-list completion-list))))))) -(defun ido-kill-buffer-internal (buf) - "Kill buffer BUF and rebuild ido's buffer list if needed." - (if (not (kill-buffer buf)) - ;; buffer couldn't be killed. - (setq ido-rescan t) - ;; else buffer was killed so remove name from list. - (setq ido-cur-list (delq buf ido-cur-list)) - ;; Some packages, like uniquify.el, may rename buffers when one - ;; is killed, so we need to test this condition to avoid using - ;; an outdated list of buffer names. We don't want to always - ;; rebuild the list of buffers, as this alters the previous - ;; buffer order that the user was seeing on the prompt. However, - ;; when we rebuild the list, we try to keep the previous second - ;; buffer as the first one. - (catch 'update - (dolist (b ido-cur-list) - (unless (get-buffer b) - (setq ido-cur-list (ido-make-buffer-list (cadr ido-matches))) - (setq ido-rescan t) - (throw 'update nil)))))) - ;;; KILL CURRENT BUFFER (defun ido-kill-buffer-at-head () "Kill the buffer at the head of `ido-matches'. @@ -3864,15 +3839,26 @@ If cursor is not at the end of the user input, delete to end of input." (if (not (eobp)) (delete-region (point) (line-end-position)) (let ((enable-recursive-minibuffers t) - (buf (ido-name (car ido-matches)))) - (when buf - (ido-kill-buffer-internal buf) - ;; Check if buffer still exists. - (if (get-buffer buf) - ;; buffer couldn't be killed. + (buf (ido-name (car ido-matches))) + (nextbuf (cadr ido-matches))) + (when (get-buffer buf) + ;; If next match names a buffer use the buffer object; buffer + ;; name may be changed by packages such as uniquify; mindful + ;; of virtual buffers. + (when (and nextbuf (get-buffer nextbuf)) + (setq nextbuf (get-buffer nextbuf))) + (if (null (kill-buffer buf)) + ;; Buffer couldn't be killed. (setq ido-rescan t) - ;; else buffer was killed so remove name from list. - (setq ido-cur-list (delq buf ido-cur-list))))))) + ;; Else `kill-buffer' succeeds so re-make the buffer list + ;; taking into account packages like uniquify may rename + ;; buffers. + (if (bufferp nextbuf) + (setq nextbuf (buffer-name nextbuf))) + (setq ido-default-item nextbuf + ido-text-init ido-text + ido-exit 'refresh) + (exit-minibuffer)))))) ;;; DELETE CURRENT FILE (defun ido-delete-file-at-head () @@ -3910,7 +3896,7 @@ Record command in `command-history' if optional RECORD is non-nil." ((eq method 'kill) (if record (ido-record-command 'kill-buffer buffer)) - (ido-kill-buffer-internal buffer)) + (kill-buffer buffer)) ((eq method 'other-window) (if record diff --git a/lisp/iswitchb.el b/lisp/iswitchb.el index ea4b00dc90d..081897a89b3 100644 --- a/lisp/iswitchb.el +++ b/lisp/iswitchb.el @@ -1027,8 +1027,8 @@ Return the modified list with the last element prepended to it." (defun iswitchb-kill-buffer () "Kill the buffer at the head of `iswitchb-matches'." (interactive) - (let ( (enable-recursive-minibuffers t) - buf) + (let ((enable-recursive-minibuffers t) + buf) (setq buf (car iswitchb-matches)) ;; check to see if buf is non-nil. @@ -1042,8 +1042,10 @@ Return the modified list with the last element prepended to it." (if (get-buffer buf) ;; buffer couldn't be killed. (setq iswitchb-rescan t) - ;; else buffer was killed so remove name from list. - (setq iswitchb-buflist (delq buf iswitchb-buflist))))))) + ;; Else `kill-buffer' succeeds so re-make the buffer list + ;; taking into account packages like uniquify may rename + ;; buffers + (iswitchb-make-buflist iswitchb-default)))))) ;;; VISIT CHOSEN BUFFER (defun iswitchb-visit-buffer (buffer) -- 2.39.2