Subject: Re: bug#26360: 26.0.50; ido-mode doesn't enable IDO for C-x 4 d

From: Philipp Stephani <[email-masked]>
Date: Thu, 20 Apr 2017 13:45:09 +0000

Philipp Stephani <[email-masked]> schrieb am Di., 4. Apr. 2017 um
14:22 Uhr:

>
> M-x ido-mode
>
> Then try
> C-x C-f
> C-x d
> C-x 4 f
> C-x 4 d
>
> In the first three cases, IDO will be used, but not in the fourth case.
> That's a weird inconsistency.
>
>
Here's a patch (which includes a couple of other commands).
From 0a5cb56a55fea6668e50822f37fe90c2cebc4441 Mon Sep 17 00:00:00 2001
From: Philipp Stephani <[email-masked]>
Date: Thu, 20 Apr 2017 15:41:15 +0200
Subject: [PATCH] Add missing remappings for Ido mode

Among others, add a remapping for C-x 4 d, cf. Bug#26360.

* lisp/ido.el (ido-mode): Remap missing commands.
(ido-file-internal, ido-visit-buffer): Add support for new
methods.
(ido-display-buffer-other-frame)
(ido-find-alternate-file-other-window, ido-dired-other-window)
(ido-dired-other-frame): New commands.

* test/lisp/ido-tests.el (ido-tests--other-window-frame): Add unit
test for the bindings.
---
 etc/NEWS               |  7 ++++++
 lisp/ido.el            | 61 +++++++++++++++++++++++++++++++++++++++++++++++---
 test/lisp/ido-tests.el | 47 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 112 insertions(+), 3 deletions(-)
 create mode 100644 test/lisp/ido-tests.el

diff --git a/etc/NEWS b/etc/NEWS
index e351abc159..6d1643d2dd 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -545,6 +545,13 @@ replaced by the real images asynchronously, which will also now
 respect width/height HTML specs (unless they specify widths/heights
 bigger than the current window).
 
+** Ido
+
+*** The commands 'find-alternate-file-other-window',
+'dired-other-window', 'dired-other-frame', and
+'display-buffer-other-window' are now remapped to Ido equivalents if
+Ido mode is active.
+
 ** Images
 
 +++
diff --git a/lisp/ido.el b/lisp/ido.el
index 293c8e2857..318f2fe082 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -1640,10 +1640,14 @@ ido-mode
           'ido-find-file-other-window)
 	(define-key map [remap find-file-read-only-other-window]
           'ido-find-file-read-only-other-window)
+        (define-key map [remap find-alternate-file-other-window]
+          #'ido-find-alternate-file-other-window)
+        (define-key map [remap dired-other-window] #'ido-dired-other-window)
 	(define-key map [remap find-file-other-frame]
           'ido-find-file-other-frame)
 	(define-key map [remap find-file-read-only-other-frame]
-          'ido-find-file-read-only-other-frame))
+          'ido-find-file-read-only-other-frame)
+        (define-key map [remap dired-other-frame] #'ido-dired-other-frame))
 
       (when (memq ido-mode '(buffer both))
 	(define-key map [remap switch-to-buffer] 'ido-switch-buffer)
@@ -1653,7 +1657,9 @@ ido-mode
           'ido-switch-buffer-other-frame)
 	(define-key map [remap insert-buffer] 'ido-insert-buffer)
 	(define-key map [remap kill-buffer] 'ido-kill-buffer)
-	(define-key map [remap display-buffer] 'ido-display-buffer))
+	(define-key map [remap display-buffer] 'ido-display-buffer)
+        (define-key map [remap display-buffer-other-frame]
+          #'ido-display-buffer-other-frame))
 
       (if ido-minor-mode-map-entry
 	  (setcdr ido-minor-mode-map-entry map)
@@ -2443,7 +2449,14 @@ ido-file-internal
 	(ido-record-work-directory)
 	(find-alternate-file filename))
 
-       ((memq method '(dired list-directory))
+       ((eq method 'alt-file-other-window)
+        (ido-record-work-file filename)
+        (setq default-directory ido-current-directory)
+        (ido-record-work-directory)
+        (find-alternate-file-other-window filename))
+
+       ((memq method '(dired dired-other-window dired-other-frame
+                             list-directory))
 	(if (equal filename ".")
 	    (setq filename ""))
 	(let* ((dirname (ido-final-slash
@@ -4108,6 +4121,9 @@ ido-visit-buffer
       (switch-to-buffer-other-frame buffer)
       (select-frame-set-input-focus (selected-frame)))
 
+     ((eq method 'display-other-frame)
+      (display-buffer-other-frame buffer))
+
      ((and (memq method '(raise-frame maybe-frame))
 	   window-system
 	   (setq win (ido-buffer-window-other-frame buffer))
@@ -4193,6 +4209,15 @@ ido-display-buffer
   (ido-buffer-internal 'display 'display-buffer nil nil nil 'ignore))
 
 ;;;###autoload
+(defun ido-display-buffer-other-frame ()
+  "Display a buffer preferably in another frame.
+The buffer name is selected interactively by typing a substring.
+For details of keybindings, see `ido-switch-buffer'."
+  (interactive)
+  (ido-buffer-internal 'display-other-frame #'display-buffer-other-frame
+                       nil nil nil #'ignore))
+
+;;;###autoload
 (defun ido-kill-buffer ()
   "Kill a buffer.
 The buffer name is selected interactively by typing a substring.
@@ -4291,6 +4316,14 @@ ido-find-alternate-file
   (ido-file-internal 'alt-file 'find-alternate-file nil "Find alternate file: "))
 
 ;;;###autoload
+(defun ido-find-alternate-file-other-window ()
+  "Find file as a replacement for the file in the next window.
+The file name is selected interactively by typing a substring.
+For details of keybindings, see `ido-find-file'."
+  (interactive)
+  (ido-file-internal 'alt-file-other-window #'find-alternate-file-other-window))
+
+;;;###autoload
 (defun ido-find-file-read-only ()
   "Edit file read-only with name obtained via minibuffer.
 The file name is selected interactively by typing a substring.
@@ -4364,6 +4397,28 @@ ido-dired
 	(ido-auto-merge-work-directories-length -1))
     (ido-file-internal 'dired 'dired nil "Dired: " 'dir)))
 
+;;;###autoload
+(defun ido-dired-other-window ()
+  "\"Edit\" a directory.  Like `ido-dired' but selects in another window.
+The directory is selected interactively by typing a substring.
+For details of keybindings, see `ido-find-file'."
+  (interactive)
+  (let ((ido-report-no-match nil)
+	(ido-auto-merge-work-directories-length -1))
+    (ido-file-internal 'dired-other-window #'dired-other-window nil
+                       "Dired: " 'dir)))
+
+;;;###autoload
+(defun ido-dired-other-frame ()
+  "\"Edit\" a directory.  Like `ido-dired' but makes a new frame.
+The directory is selected interactively by typing a substring.
+For details of keybindings, see `ido-find-file'."
+  (interactive)
+  (let ((ido-report-no-match nil)
+	(ido-auto-merge-work-directories-length -1))
+    (ido-file-internal 'dired-other-frame #'dired-other-frame nil
+                       "Dired: " 'dir)))
+
 (defun ido-list-directory ()
   "Call `list-directory' the Ido way.
 The directory is selected interactively by typing a substring.
diff --git a/test/lisp/ido-tests.el b/test/lisp/ido-tests.el
new file mode 100644
index 0000000000..df11096931
--- /dev/null
+++ b/test/lisp/ido-tests.el
@@ -0,0 +1,47 @@
+;;; ido-tests.el --- unit tests for ido.el           -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2017  Free Software Foundation, Inc.
+
+;; Author: Philipp Stephani <[email-masked]>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for ido.el.
+
+;;; Code:
+
+(ert-deftest ido-tests--other-window-frame ()
+  "Verifies that Bug#26360 is fixed."
+  (should-not ido-mode)
+  (unwind-protect
+      (progn
+        (ido-mode)
+        (should (equal ido-mode 'both))
+        (should (equal (key-binding [remap find-alternate-file-other-window])
+                       #'ido-find-alternate-file-other-window))
+        (should (commandp #'ido-find-alternate-file-other-window))
+        (should (equal (key-binding (kbd "C-x 4 d")) #'ido-dired-other-window))
+        (should (commandp #'ido-dired-other-window))
+        (should (equal (key-binding (kbd "C-x 5 d")) #'ido-dired-other-frame))
+        (should (commandp #'ido-dired-other-frame))
+        (should (equal (key-binding (kbd "C-x 5 C-o"))
+                       #'ido-display-buffer-other-frame))
+        (should (commandp #'ido-display-buffer-other-frame)))
+    (ido-mode 0)))
+
+;;; ido-tests.el ends here
-- 
2.12.2