comparison lisp/ido.el @ 109945:c5974968dea9

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.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 21 Aug 2010 15:35:27 +0200
parents cf183258f1db
children 53205019b195 8e856214e6e5
comparison
equal deleted inserted replaced
109944:48114bfd2ed3 109945:c5974968dea9
1040 (defvar ido-default-item) 1040 (defvar ido-default-item)
1041 1041
1042 ;; Stores the current list of items that will be searched through. 1042 ;; Stores the current list of items that will be searched through.
1043 ;; The list is ordered, so that the most interesting item comes first, 1043 ;; The list is ordered, so that the most interesting item comes first,
1044 ;; although by default, the files visible in the current frame are put 1044 ;; although by default, the files visible in the current frame are put
1045 ;; at the end of the list. 1045 ;; at the end of the list. Created by `ido-make-item-list'.
1046 (defvar ido-cur-list nil) 1046 (defvar ido-cur-list)
1047 1047
1048 ;; Stores the choice list for ido-completing-read 1048 ;; Stores the choice list for ido-completing-read
1049 (defvar ido-choice-list nil) 1049 (defvar ido-choice-list)
1050 1050
1051 ;; Stores the list of items which are ignored when building 1051 ;; Stores the list of items which are ignored when building
1052 ;; `ido-cur-list'. It is in no specific order. 1052 ;; `ido-cur-list'. It is in no specific order.
1053 (defvar ido-ignored-list) 1053 (defvar ido-ignored-list)
1054 1054
3346 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current)) 3346 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current))
3347 (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers))) 3347 (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers)))
3348 (if ido-temp-list 3348 (if ido-temp-list
3349 (nconc ido-temp-list ido-current-buffers) 3349 (nconc ido-temp-list ido-current-buffers)
3350 (setq ido-temp-list ido-current-buffers)) 3350 (setq ido-temp-list ido-current-buffers))
3351 (if (and default (buffer-live-p (get-buffer default))) 3351 (if default
3352 (progn 3352 (setq ido-temp-list
3353 (setq ido-temp-list 3353 (cons default (delete default ido-temp-list))))
3354 (delete default ido-temp-list))
3355 (setq ido-temp-list
3356 (cons default ido-temp-list))))
3357 (run-hooks 'ido-make-buffer-list-hook) 3354 (run-hooks 'ido-make-buffer-list-hook)
3358 ido-temp-list)) 3355 ido-temp-list))
3359 3356
3360 (defun ido-make-choice-list (default) 3357 (defun ido-make-choice-list (default)
3361 ;; Return the current list of choices. 3358 ;; Return the current list of choices.
3592 3589
3593 (defun ido-get-bufname (win) 3590 (defun ido-get-bufname (win)
3594 ;; Used by `ido-get-buffers-in-frames' to walk through all windows 3591 ;; Used by `ido-get-buffers-in-frames' to walk through all windows
3595 (let ((buf (buffer-name (window-buffer win)))) 3592 (let ((buf (buffer-name (window-buffer win))))
3596 (unless (or (member buf ido-bufs-in-frame) 3593 (unless (or (member buf ido-bufs-in-frame)
3597 (minibufferp buf)
3598 (member buf ido-ignore-item-temp-list)) 3594 (member buf ido-ignore-item-temp-list))
3599 ;; Only add buf if it is not already in list. 3595 ;; Only add buf if it is not already in list.
3600 ;; This prevents same buf in two different windows being 3596 ;; This prevents same buf in two different windows being
3601 ;; put into the list twice. 3597 ;; put into the list twice.
3602 (setq ido-bufs-in-frame 3598 (setq ido-bufs-in-frame
3833 '(lambda (x y z) (message "Doesn't work yet, sorry!")))) 3829 '(lambda (x y z) (message "Doesn't work yet, sorry!"))))
3834 ;; else running Emacs 3830 ;; else running Emacs
3835 ;;(add-hook 'completion-setup-hook 'completion-setup-function) 3831 ;;(add-hook 'completion-setup-hook 'completion-setup-function)
3836 (display-completion-list completion-list))))))) 3832 (display-completion-list completion-list)))))))
3837 3833
3838 (defun ido-kill-buffer-internal (buf)
3839 "Kill buffer BUF and rebuild ido's buffer list if needed."
3840 (if (not (kill-buffer buf))
3841 ;; buffer couldn't be killed.
3842 (setq ido-rescan t)
3843 ;; else buffer was killed so remove name from list.
3844 (setq ido-cur-list (delq buf ido-cur-list))
3845 ;; Some packages, like uniquify.el, may rename buffers when one
3846 ;; is killed, so we need to test this condition to avoid using
3847 ;; an outdated list of buffer names. We don't want to always
3848 ;; rebuild the list of buffers, as this alters the previous
3849 ;; buffer order that the user was seeing on the prompt. However,
3850 ;; when we rebuild the list, we try to keep the previous second
3851 ;; buffer as the first one.
3852 (catch 'update
3853 (dolist (b ido-cur-list)
3854 (unless (get-buffer b)
3855 (setq ido-cur-list (ido-make-buffer-list (cadr ido-matches)))
3856 (setq ido-rescan t)
3857 (throw 'update nil))))))
3858
3859 ;;; KILL CURRENT BUFFER 3834 ;;; KILL CURRENT BUFFER
3860 (defun ido-kill-buffer-at-head () 3835 (defun ido-kill-buffer-at-head ()
3861 "Kill the buffer at the head of `ido-matches'. 3836 "Kill the buffer at the head of `ido-matches'.
3862 If cursor is not at the end of the user input, delete to end of input." 3837 If cursor is not at the end of the user input, delete to end of input."
3863 (interactive) 3838 (interactive)
3864 (if (not (eobp)) 3839 (if (not (eobp))
3865 (delete-region (point) (line-end-position)) 3840 (delete-region (point) (line-end-position))
3866 (let ((enable-recursive-minibuffers t) 3841 (let ((enable-recursive-minibuffers t)
3867 (buf (ido-name (car ido-matches)))) 3842 (buf (ido-name (car ido-matches)))
3868 (when buf 3843 (nextbuf (cadr ido-matches)))
3869 (ido-kill-buffer-internal buf) 3844 (when (get-buffer buf)
3870 ;; Check if buffer still exists. 3845 ;; If next match names a buffer use the buffer object; buffer
3871 (if (get-buffer buf) 3846 ;; name may be changed by packages such as uniquify; mindful
3872 ;; buffer couldn't be killed. 3847 ;; of virtual buffers.
3848 (when (and nextbuf (get-buffer nextbuf))
3849 (setq nextbuf (get-buffer nextbuf)))
3850 (if (null (kill-buffer buf))
3851 ;; Buffer couldn't be killed.
3873 (setq ido-rescan t) 3852 (setq ido-rescan t)
3874 ;; else buffer was killed so remove name from list. 3853 ;; Else `kill-buffer' succeeds so re-make the buffer list
3875 (setq ido-cur-list (delq buf ido-cur-list))))))) 3854 ;; taking into account packages like uniquify may rename
3855 ;; buffers.
3856 (if (bufferp nextbuf)
3857 (setq nextbuf (buffer-name nextbuf)))
3858 (setq ido-default-item nextbuf
3859 ido-text-init ido-text
3860 ido-exit 'refresh)
3861 (exit-minibuffer))))))
3876 3862
3877 ;;; DELETE CURRENT FILE 3863 ;;; DELETE CURRENT FILE
3878 (defun ido-delete-file-at-head () 3864 (defun ido-delete-file-at-head ()
3879 "Delete the file at the head of `ido-matches'. 3865 "Delete the file at the head of `ido-matches'.
3880 If cursor is not at the end of the user input, delete to end of input." 3866 If cursor is not at the end of the user input, delete to end of input."
3908 (let (win newframe) 3894 (let (win newframe)
3909 (cond 3895 (cond
3910 ((eq method 'kill) 3896 ((eq method 'kill)
3911 (if record 3897 (if record
3912 (ido-record-command 'kill-buffer buffer)) 3898 (ido-record-command 'kill-buffer buffer))
3913 (ido-kill-buffer-internal buffer)) 3899 (kill-buffer buffer))
3914 3900
3915 ((eq method 'other-window) 3901 ((eq method 'other-window)
3916 (if record 3902 (if record
3917 (ido-record-command 'switch-to-buffer buffer)) 3903 (ido-record-command 'switch-to-buffer buffer))
3918 (switch-to-buffer-other-window buffer)) 3904 (switch-to-buffer-other-window buffer))