Pārlūkot izejas kodu

Eliminate explicit version check for Emacs bug #27807

ido-cr+ now checks for the bug's occurrence directly rather than
relying on the version number to determine whether the bug is present.

Fixes #171.
Ryan C. Thompson 5 gadi atpakaļ
vecāks
revīzija
03175a5af5
1 mainītis faili ar 22 papildinājumiem un 2 dzēšanām
  1. 22 2
      ido-completing-read+.el

+ 22 - 2
ido-completing-read+.el

@@ -234,6 +234,26 @@ Each element is a cons cell of (REMOVEP . TEXT), where REMOVEP is
 the prefix argument to `ido-restrict-to-matches' and TEXT is the
 pattern used to restrict.")
 
+(defvar ido-cr+-need-bug27807-workaround
+  (cl-letf*
+      ((ido-trace-enable t)
+       (ido-exit ido-exit)
+       ((symbol-function 'read-from-minibuffer)
+        (lambda (prompt &optional initial-contents &rest remaining-args)
+          (setq ido-exit 'takeprompt) ; Emulate pressing C-j in ido
+          (if (consp initial-contents)
+              (substring (car initial-contents) 0 (1- (cdr initial-contents)))
+            initial-contents)))
+       (input-before-point
+        (ido-completing-read "Pick: " '("aaa" "aab" "aac") nil nil '("aa" . 1))))
+    ;; If an initial position of 1 yields a 0-length string, then this
+    ;; Emacs does not have the bug fix and requires the workaround.
+    (= (length input-before-point) 0))
+  "If non-nil enable the workaround for Emacs bug #27807.
+
+This variable is normally set when ido-cr+ is loaded, and should
+not need to be modified by users.")
+
 (defgroup ido-completing-read-plus nil
   "Extra features and compatibility for `ido-completing-read'."
   :group 'ido)
@@ -707,9 +727,9 @@ See `completing-read' for the meaning of the arguments."
                     '("ido cannot handle the empty string as an option when `ido-enable-dot-prefix' is non-nil; see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26997")))
 
           ;; Fix ido's broken handling of cons-style INITIAL-INPUT on
-          ;; Emacsen older than 27.
+          ;; Emacsen older than 27. See Emacs bug #27807.
           (when (and (consp initial-input)
-                     (< emacs-major-version 27))
+                     ido-cr+-need-bug27807-workaround)
             ;; `completing-read' uses 0-based index while
             ;; `read-from-minibuffer' uses 1-based index.
             (cl-incf (cdr initial-input)))