Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bug#2042: Ido-mode : filtering does not keep ordering

3 views
Skip to first unread message

Leo

unread,
Sep 24, 2011, 12:20:27 PM9/24/11
to Antoine Levitt, 20...@debbugs.gnu.org
On 2009-01-25 21:54 +0800, Antoine Levitt wrote:
> Hi,
> When buffer switching in Ido, filtering the list of available buffers does
> not keep the original ordering of buffers (from most recent to oldest).
> Ie if I have for instance buffers foobar and barfoo, in this order, if I
> type bar, they are displayed to me as barfoo foobar. I understand this is a
> reasonable behavior in a number of case, but it's annoying when using ido to
> quickly toggle between working buffers, where I have old and forgotten
> buffers pop up as the first option in the completion list. Would it be
> possible to add a switch ?
>
> Antoine Levitt

I occasionally try iswitch-mode and find its buffer switching much more
pleasant to use than ido's. The trouble is ido tries to be smart in
ordering matches. Sadly that gets in the way most of the time.

I wonder if people are willing to try the following (preliminary) patch
and see if they miss anything.

diff --git a/lisp/ido.el b/lisp/ido.el
index aa6ad4aa..e0640eba 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -3735,7 +3735,7 @@ (defun ido-get-bufname (win)

;;; FIND MATCHING ITEMS

-(defun ido-set-matches-1 (items &optional do-full)
+(defun ido-set-matches-1 (items &optional ignore)
;; Return list of matches in items
(let* ((case-fold-search ido-case-fold)
(slash (and (not ido-enable-prefix) (ido-final-slash ido-text)))
@@ -3743,18 +3743,11 @@ (defun ido-set-matches-1 (items &optional do-full)
(rex0 (if ido-enable-regexp text (regexp-quote text)))
(rexq (concat rex0 (if slash ".*/" "")))
(re (if ido-enable-prefix (concat "\\`" rexq) rexq))
- (full-re (and do-full (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
- (concat "\\`" rex0 (if slash "/" "") "\\'")))
- (suffix-re (and do-full slash
- (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
- (concat rex0 "/\\'")))
- (prefix-re (and full-re (not ido-enable-prefix)
- (concat "\\`" rexq)))
(non-prefix-dot (or (not ido-enable-dot-prefix)
(not ido-process-ignore-lists)
ido-enable-prefix
(= (length ido-text) 0)))
- full-matches suffix-matches prefix-matches matches)
+ matches)
(setq ido-incomplete-regexp nil)
(condition-case error
(mapc
@@ -3771,12 +3764,6 @@ (defun ido-set-matches-1 (items &optional do-full)
(not (string= name ido-default-item)))
(string= name (buffer-name ido-entry-buffer)))
(setq matches (cons item matches)))
- ((and full-re (string-match full-re name))
- (setq full-matches (cons item full-matches)))
- ((and suffix-re (string-match suffix-re name))
- (setq suffix-matches (cons item suffix-matches)))
- ((and prefix-re (string-match prefix-re name))
- (setq prefix-matches (cons item prefix-matches)))
(t (setq matches (cons item matches))))))
t)
items)
@@ -3786,16 +3773,6 @@ (defun ido-set-matches-1 (items &optional do-full)
;; special-case single match, and handle appropriately
;; elsewhere.
matches (cdr error))))
- (when prefix-matches
- (ido-trace "prefix match" prefix-matches)
- ;; Bug#2042.
- (setq matches (nconc prefix-matches matches)))
- (when suffix-matches
- (ido-trace "suffix match" (list text suffix-re suffix-matches))
- (setq matches (nconc suffix-matches matches)))
- (when full-matches
- (ido-trace "full match" (list text full-re full-matches))
- (setq matches (nconc full-matches matches)))
(when (and (null matches)
ido-enable-flex-matching
(> (length ido-text) 1)



Antoine Levitt

unread,
Sep 25, 2011, 4:54:50 AM9/25/11
to 20...@debbugs.gnu.org
24/09/11 18:20, Leo
> On 2009-01-25 21:54 +0800, Antoine Levitt wrote:
>> Hi,
>> When buffer switching in Ido, filtering the list of available buffers does
>> not keep the original ordering of buffers (from most recent to oldest).
>> Ie if I have for instance buffers foobar and barfoo, in this order, if I
>> type bar, they are displayed to me as barfoo foobar. I understand this is a
>> reasonable behavior in a number of case, but it's annoying when using ido to
>> quickly toggle between working buffers, where I have old and forgotten
>> buffers pop up as the first option in the completion list. Would it be
>> possible to add a switch ?
>>
>> Antoine Levitt
>
> I occasionally try iswitch-mode and find its buffer switching much more
> pleasant to use than ido's. The trouble is ido tries to be smart in
> ordering matches. Sadly that gets in the way most of the time.
>
> I wonder if people are willing to try the following (preliminary) patch
> and see if they miss anything.

That's much better! Thanks!




Chong Yidong

unread,
Oct 1, 2011, 3:10:56 PM10/1/11
to Leo, Antoine Levitt, 20...@debbugs.gnu.org
Leo <sdl...@gmail.com> writes:

> I occasionally try iswitch-mode and find its buffer switching much
> more pleasant to use than ido's. The trouble is ido tries to be smart
> in ordering matches. Sadly that gets in the way most of the time.

Could you explain in words what the existing code tries to do?

Maybe it's indeed misguided and ought to be taken out, but it would be
good to first figure out what the original intention was.



Leo

unread,
Oct 1, 2011, 8:04:30 PM10/1/11
to Chong Yidong, Antoine Levitt, 20...@debbugs.gnu.org
The existing code gives different precedence to different match type:

full-matches > suffix matches > prefix matches > remaining matches

For example in switching buffers in ido:

input: ab

Buffer: ab[c]{abcd | abc | xabcd | xabc}

now when the user types c, it changes to:

Buffer: abc{abc | abcd | xabcd | xabc}

Note the different ordering of "abcd" and "abc". Because typing is so
much quicker than observing the new order, one usually mis-chooses a
match.

Thus, the above strategy may break down when the original ordering is
meaningful for example, (buffer-list) returns a list in order of
recency.

Leo



Chong Yidong

unread,
Oct 29, 2011, 2:38:01 AM10/29/11
to Leo, Antoine Levitt, 20...@debbugs.gnu.org
Leo <sdl...@gmail.com> writes:

> The existing code gives different precedence to different match type:
>
> full-matches > suffix matches > prefix matches > remaining matches
>
> For example in switching buffers in ido:
>
> input: ab
>
> Buffer: ab[c]{abcd | abc | xabcd | xabc}
>
> now when the user types c, it changes to:
>
> Buffer: abc{abc | abcd | xabcd | xabc}
>
> Note the different ordering of "abcd" and "abc". Because typing is so
> much quicker than observing the new order, one usually mis-chooses a
> match.

Thanks. I guess since at least two users of ido have complained about
this behavior, and no one else has chimed in, we can go ahead and make
this change after the release.



Leo

unread,
Oct 29, 2011, 3:06:11 AM10/29/11
to 20...@debbugs.gnu.org
On 2011-10-29 14:38 +0800, Chong Yidong wrote:
> Thanks. I guess since at least two users of ido have complained about
> this behavior, and no one else has chimed in, we can go ahead and make
> this change after the release.

OK. Maybe we can also add a user option.

Leo




Matthew Woodcraft

unread,
Sep 16, 2012, 5:29:06 AM9/16/12
to Chong Yidong, 20...@debbugs.gnu.org, Leo, Antoine Levitt
On 29 Oct 2011, Chong Yidong <c...@gnu.org> wrote:
> Thanks. I guess since at least two users of ido have complained about
> this behavior, and no one else has chimed in, we can go ahead and make
> this change after the release.

I've been running with Leo's patch from this bug report for a couple of
months.

I also think that the changed behaviour is an improvement, and I've seen
no problems.

So could this be considered before the 24.3 freeze?

-M-



Leo

unread,
Sep 16, 2012, 10:55:30 AM9/16/12
to Matthew Woodcraft, Chong Yidong, 20...@debbugs.gnu.org, Antoine Levitt
On 2012-09-16 17:29 +0800, Matthew Woodcraft wrote:
> I've been running with Leo's patch from this bug report for a couple of
> months.
>
> I also think that the changed behaviour is an improvement, and I've seen
> no problems.
>
> So could this be considered before the 24.3 freeze?

If Yidong doesn't object, I plan to commit something along these lines:

diff --git a/lisp/ido.el b/lisp/ido.el
index fe94c7f2..bb019574 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -493,6 +493,17 @@ (defcustom ido-enable-dot-prefix nil
:type 'boolean
:group 'ido)

+;; See http://debbugs.gnu.org/2042 for more info.
+(defcustom ido-buffer-disable-smart-matches t
+ "Non-nil means not to re-order matches for buffer switching.
+By default, ido aranges matches in the following order:
+
+ full-matches > suffix matches > prefix matches > remaining matches
+
+which can get in the way for buffer switching."
+ :type 'boolean
+ :group 'ido)
+
(defcustom ido-confirm-unique-completion nil
"Non-nil means that even a unique completion must be confirmed.
This means that \\[ido-complete] must always be followed by \\[ido-exit-minibuffer]
@@ -3688,10 +3699,15 @@ (defun ido-set-matches-1 (items &optional do-full)
(rex0 (if ido-enable-regexp text (regexp-quote text)))
(rexq (concat rex0 (if slash ".*/" "")))
(re (if ido-enable-prefix (concat "\\`" rexq) rexq))
- (full-re (and do-full (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
+ (full-re (and do-full
+ (not ido-buffer-disable-smart-matches)
+ (not ido-enable-regexp)
+ (not (string-match "\$\\'" rex0))
(concat "\\`" rex0 (if slash "/" "") "\\'")))
(suffix-re (and do-full slash
- (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
+ (not ido-buffer-disable-smart-matches)
+ (not ido-enable-regexp)
+ (not (string-match "\$\\'" rex0))
(concat rex0 "/\\'")))
(prefix-re (and full-re (not ido-enable-prefix)
(concat "\\`" rexq)))




Leo

unread,
Sep 16, 2012, 11:03:15 AM9/16/12
to 20...@debbugs.gnu.org
Use this patch instead:

diff --git a/lisp/ido.el b/lisp/ido.el
index fe94c7f2..512ac9d4 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -493,6 +493,17 @@ (defcustom ido-enable-dot-prefix nil
:type 'boolean
:group 'ido)

+;; See http://debbugs.gnu.org/2042 for more info.
+(defcustom ido-buffer-disable-smart-matches t
+ "Non-nil means not to re-order matches for buffer switching.
+By default, ido aranges matches in the following order:
+
+ full-matches > suffix matches > prefix matches > remaining matches
+
+which can get in the way for buffer switching."
+ :type 'boolean
+ :group 'ido)
+
(defcustom ido-confirm-unique-completion nil
"Non-nil means that even a unique completion must be confirmed.
This means that \\[ido-complete] must always be followed by \\[ido-exit-minibuffer]
@@ -3688,10 +3699,17 @@ (defun ido-set-matches-1 (items &optional do-full)
(rex0 (if ido-enable-regexp text (regexp-quote text)))
(rexq (concat rex0 (if slash ".*/" "")))
(re (if ido-enable-prefix (concat "\\`" rexq) rexq))
- (full-re (and do-full (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
+ (full-re (and do-full
+ (and (eq ido-cur-item 'buffer)
+ (not ido-buffer-disable-smart-matches))
+ (not ido-enable-regexp)
+ (not (string-match "\$\\'" rex0))
(concat "\\`" rex0 (if slash "/" "") "\\'")))
(suffix-re (and do-full slash
- (not ido-enable-regexp) (not (string-match "\$\\'" rex0))
+ (and (eq ido-cur-item 'buffer)
+ (not ido-buffer-disable-smart-matches))

Chong Yidong

unread,
Sep 16, 2012, 12:33:11 PM9/16/12
to Leo, 20...@debbugs.gnu.org
Leo <sdl...@gmail.com> writes:

> Use this patch instead:

Feel free to commit, and thanks for writing up the patch.



Leo

unread,
Sep 16, 2012, 6:28:21 PM9/16/12
to 2042...@debbugs.gnu.org
Fixed in emacs-24



0 new messages