comparison lisp/ido.el @ 106901:ee670d4f8293

ido.el: Consider the possibility of buffer names changing after kill-buffer.
author Juanma Barranquero <lekktu@gmail.com>
date Mon, 18 Jan 2010 20:34:55 +0100
parents 1d1d5d9bd884
children 13c077500eb3 cf183258f1db
comparison
equal deleted inserted replaced
106900:e3970f7c14d4 106901:ee670d4f8293
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. Created by `ido-make-item-list'. 1045 ;; at the end of the list.
1046 (defvar ido-cur-list) 1046 (defvar ido-cur-list nil)
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) 1049 (defvar ido-choice-list nil)
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
3342 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current)) 3342 (let* ((ido-current-buffers (ido-get-buffers-in-frames 'current))
3343 (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers))) 3343 (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers)))
3344 (if ido-temp-list 3344 (if ido-temp-list
3345 (nconc ido-temp-list ido-current-buffers) 3345 (nconc ido-temp-list ido-current-buffers)
3346 (setq ido-temp-list ido-current-buffers)) 3346 (setq ido-temp-list ido-current-buffers))
3347 (if default 3347 (if (and default (buffer-live-p (get-buffer default)))
3348 (progn 3348 (progn
3349 (setq ido-temp-list 3349 (setq ido-temp-list
3350 (delete default ido-temp-list)) 3350 (delete default ido-temp-list))
3351 (setq ido-temp-list 3351 (setq ido-temp-list
3352 (cons default ido-temp-list)))) 3352 (cons default ido-temp-list))))
3588 3588
3589 (defun ido-get-bufname (win) 3589 (defun ido-get-bufname (win)
3590 ;; Used by `ido-get-buffers-in-frames' to walk through all windows 3590 ;; Used by `ido-get-buffers-in-frames' to walk through all windows
3591 (let ((buf (buffer-name (window-buffer win)))) 3591 (let ((buf (buffer-name (window-buffer win))))
3592 (unless (or (member buf ido-bufs-in-frame) 3592 (unless (or (member buf ido-bufs-in-frame)
3593 (minibufferp buf)
3593 (member buf ido-ignore-item-temp-list)) 3594 (member buf ido-ignore-item-temp-list))
3594 ;; Only add buf if it is not already in list. 3595 ;; Only add buf if it is not already in list.
3595 ;; This prevents same buf in two different windows being 3596 ;; This prevents same buf in two different windows being
3596 ;; put into the list twice. 3597 ;; put into the list twice.
3597 (setq ido-bufs-in-frame 3598 (setq ido-bufs-in-frame
3828 '(lambda (x y z) (message "Doesn't work yet, sorry!")))) 3829 '(lambda (x y z) (message "Doesn't work yet, sorry!"))))
3829 ;; else running Emacs 3830 ;; else running Emacs
3830 ;;(add-hook 'completion-setup-hook 'completion-setup-function) 3831 ;;(add-hook 'completion-setup-hook 'completion-setup-function)
3831 (display-completion-list completion-list))))))) 3832 (display-completion-list completion-list)))))))
3832 3833
3834 (defun ido-kill-buffer-internal (buf)
3835 "Kill buffer BUF and rebuild ido's buffer list if needed."
3836 (if (not (kill-buffer buf))
3837 ;; buffer couldn't be killed.
3838 (setq ido-rescan t)
3839 ;; else buffer was killed so remove name from list.
3840 (setq ido-cur-list (delq buf ido-cur-list))
3841 ;; Some packages, like uniquify.el, may rename buffers when one
3842 ;; is killed, so we need to test this condition to avoid using
3843 ;; an outdated list of buffer names. We don't want to always
3844 ;; rebuild the list of buffers, as this alters the previous
3845 ;; buffer order that the user was seeing on the prompt. However,
3846 ;; when we rebuild the list, we try to keep the previous second
3847 ;; buffer as the first one.
3848 (catch 'update
3849 (dolist (b ido-cur-list)
3850 (unless (get-buffer b)
3851 (setq ido-cur-list (ido-make-buffer-list (cadr ido-matches)))
3852 (setq ido-rescan t)
3853 (throw 'update nil))))))
3854
3833 ;;; KILL CURRENT BUFFER 3855 ;;; KILL CURRENT BUFFER
3834 (defun ido-kill-buffer-at-head () 3856 (defun ido-kill-buffer-at-head ()
3835 "Kill the buffer at the head of `ido-matches'. 3857 "Kill the buffer at the head of `ido-matches'.
3836 If cursor is not at the end of the user input, delete to end of input." 3858 If cursor is not at the end of the user input, delete to end of input."
3837 (interactive) 3859 (interactive)
3838 (if (not (eobp)) 3860 (if (not (eobp))
3839 (delete-region (point) (line-end-position)) 3861 (delete-region (point) (line-end-position))
3840 (let ((enable-recursive-minibuffers t) 3862 (let ((enable-recursive-minibuffers t)
3841 (buf (ido-name (car ido-matches)))) 3863 (buf (ido-name (car ido-matches))))
3842 (when buf 3864 (when buf
3843 (kill-buffer buf) 3865 (ido-kill-buffer-internal buf)
3844 ;; Check if buffer still exists. 3866 ;; Check if buffer still exists.
3845 (if (get-buffer buf) 3867 (if (get-buffer buf)
3846 ;; buffer couldn't be killed. 3868 ;; buffer couldn't be killed.
3847 (setq ido-rescan t) 3869 (setq ido-rescan t)
3848 ;; else buffer was killed so remove name from list. 3870 ;; else buffer was killed so remove name from list.
3882 (let (win newframe) 3904 (let (win newframe)
3883 (cond 3905 (cond
3884 ((eq method 'kill) 3906 ((eq method 'kill)
3885 (if record 3907 (if record
3886 (ido-record-command 'kill-buffer buffer)) 3908 (ido-record-command 'kill-buffer buffer))
3887 (kill-buffer buffer)) 3909 (ido-kill-buffer-internal buffer))
3888 3910
3889 ((eq method 'other-window) 3911 ((eq method 'other-window)
3890 (if record 3912 (if record
3891 (ido-record-command 'switch-to-buffer buffer)) 3913 (ido-record-command 'switch-to-buffer buffer))
3892 (switch-to-buffer-other-window buffer)) 3914 (switch-to-buffer-other-window buffer))