unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* PATCH: Fix IDO interaction with uniquify.el
@ 2010-01-18 10:27 Óscar Fuentes
  2010-01-18 10:59 ` Juanma Barranquero
  0 siblings, 1 reply; 30+ messages in thread
From: Óscar Fuentes @ 2010-01-18 10:27 UTC (permalink / raw)
  To: emacs-devel

When `uniquify' is in effect, killing a buffer may cause the renaming of
others.

While switching buffers with ido-mode enabled, the user is presented
with a list of buffer names to choose. From the prompt he can kill the
first buffer list, which is removed from the list, and keeps waiting for
further user interaction. However, IDO does not take into account that
some buffers may have changed names.

This patch rebuilds the list of buffer names used by IDO after a buffer
is killed if some name contained in the list no longer maps to an
existing buffer.

BTW, iswitchb-mode suffers from the same problem.

2010-01-18  Óscar Fuentes  <ofv@wanadoo.es>

	* ido.el (ido-make-buffer-list): If `default' is a nonexistent
          buffer, ignore it, as per the documentation.
          (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-04 05:35:18 +0000
+++ lisp/ido.el	2010-01-18 10:25:26 +0000
@@ -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))
@@ -3830,6 +3830,31 @@
 	      ;;(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)))))
+
 ;;; KILL CURRENT BUFFER
 (defun ido-kill-buffer-at-head ()
   "Kill the buffer at the head of `ido-matches'.
@@ -3840,7 +3865,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 +3909,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






^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2010-05-06 20:43 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-18 10:27 PATCH: Fix IDO interaction with uniquify.el Óscar Fuentes
2010-01-18 10:59 ` Juanma Barranquero
2010-01-18 11:12   ` Juanma Barranquero
2010-01-18 14:13     ` Óscar Fuentes
2010-01-18 14:32       ` Juanma Barranquero
2010-01-18 14:41         ` Óscar Fuentes
2010-01-18 15:44           ` Chong Yidong
2010-01-18 17:35             ` Óscar Fuentes
2010-01-18 17:52               ` Óscar Fuentes
2010-01-18 18:06                 ` Chong Yidong
2010-01-18 19:17                   ` Juanma Barranquero
2010-05-05  8:27                     ` Leo
2010-05-05  9:56                       ` Juanma Barranquero
2010-05-05 12:40                         ` Leo
2010-05-05 16:47                           ` Juanma Barranquero
2010-05-05 17:35                             ` Leo
2010-05-05 19:12                               ` Leo
2010-05-05 19:48                                 ` Juanma Barranquero
2010-05-06 12:54                               ` Stefan Monnier
2010-05-05 17:56                             ` Leo
2010-05-05 19:25                               ` Juanma Barranquero
2010-05-05 18:14                         ` Stefan Monnier
2010-05-05 19:09                           ` Óscar Fuentes
2010-05-05 19:50                             ` Leo
2010-05-05 19:59                               ` Leo
2010-05-05 20:36                                 ` Óscar Fuentes
2010-05-06 20:43                                 ` Juri Linkov
2010-05-05 20:27                               ` Stefan Monnier
2010-05-05 20:38                                 ` Óscar Fuentes
2010-05-06 16:56                                   ` Kim F. Storm

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).