emacs-devel
[Top][All Lists]
Advanced

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

Re: PATCH: Fix IDO interaction with uniquify.el


From: Óscar Fuentes
Subject: Re: PATCH: Fix IDO interaction with uniquify.el
Date: Mon, 18 Jan 2010 15:13:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.91 (gnu/linux)

Hello Juanma.

Thanks for testing. Comments and a new patch follows.

Juanma Barranquero <address@hidden> writes:

> Nice. A problem, though:
>
>  emacs -Q -f ido-mode
>  C-x k <RET>
>
>  => Symbol's value as variable is void: ido-cur-list

This is solved by using

(defvar ido-cur-list nil)

instead of

(defvar ido-cur-list)

Hope it's acceptable.

> Another weirdness:
>
>   cd c:\emacs\trunk
>   emacs -Q -l uniquify -f ido-mode --eval "(setq
> uniquify-buffer-name-style 'forward)"
>   C-x C-f ChangeLog <RET>
>   C-x C-f src/ChangeLog <RET>
>   C-x b     =>   "buffer: {trunk/ChangeLog | *scratch* | *Messages* |
> src/ChangeLog}"
>   C-k       => "buffer: {*scratch* | *Messages* |  *Minibuf-1* | ChangeLog}"
>
> " *Minibuf-1*" is unexpected.

This is solved by explicitly ignoring minibuffers while gathering the
list of buffers.

2010-01-18  Óscar Fuentes  <address@hidden>

        * ido.el (ido-cur-list): Initialize as nil. Remove obsolete
          information from its commentary.
          (ido-choice-list): Initialize as nil.
          (ido-get-bufname): Reject minibuffers.
          (ido-make-buffer-list): If "default" is a nonexistent
          buffer, ignore it, as per the docstring.
          (ido-kill-buffer-internal): New function.
          (ido-kill-buffer-at-head): Use it.
          (ido-visit-buffer): Likewise.

=== modified file 'lisp/ido.el'
--- lisp/ido.el 2010-01-13 08:35:10 +0000
+++ lisp/ido.el 2010-01-18 14:06:20 +0000
@@ -1042,11 +1042,11 @@
 ;; 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.  Created by `ido-make-item-list'.
-(defvar ido-cur-list)
+;; at the end of the list.
+(defvar ido-cur-list nil)
 
 ;; Stores the choice list for ido-completing-read
-(defvar ido-choice-list)
+(defvar ido-choice-list nil)
 
 ;; Stores the list of items which are ignored when building
 ;; `ido-cur-list'.  It is in no specific order.
@@ -3344,7 +3344,7 @@
     (if ido-temp-list
        (nconc ido-temp-list ido-current-buffers)
       (setq ido-temp-list ido-current-buffers))
-    (if default
+    (if (and default (buffer-live-p (get-buffer default)))
        (progn
          (setq ido-temp-list
                (delete default ido-temp-list))
@@ -3590,6 +3590,7 @@
   ;; 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
@@ -3830,6 +3831,32 @@
              ;;(add-hook 'completion-setup-hook 'completion-setup-function)
              (display-completion-list completion-list)))))))
 
+(defun ido-kill-buffer-internal (buf)
+  "Actually kill the buffer and check if it is needed to rebuild
+the list of known buffers."
+  (kill-buffer buf)
+  (if (get-buffer buf)
+      ;; buffer couldn't be killed.
+      (setq ido-rescan t)
+    (let ((next-buf (cadr ido-matches))
+         (needs-update nil))
+      ;; 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.
+      (dolist (b ido-cur-list)
+       (if (not (get-buffer b))
+           (setq needs-update t)))
+      (when needs-update
+       (setq ido-cur-list (ido-make-buffer-list next-buf))
+       (setq ido-rescan t)
+       (ido-set-matches)))))
+
 ;;; KILL CURRENT BUFFER
 (defun ido-kill-buffer-at-head ()
   "Kill the buffer at the head of `ido-matches'.
@@ -3840,7 +3867,7 @@
     (let ((enable-recursive-minibuffers t)
          (buf (ido-name (car ido-matches))))
       (when buf
-       (kill-buffer buf)
+       (ido-kill-buffer-internal buf)
        ;; Check if buffer still exists.
        (if (get-buffer buf)
            ;; buffer couldn't be killed.
@@ -3884,7 +3911,7 @@
      ((eq method 'kill)
       (if record
          (ido-record-command 'kill-buffer buffer))
-      (kill-buffer buffer))
+      (ido-kill-buffer-internal buffer))
 
      ((eq method 'other-window)
       (if record






reply via email to

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