emacs-diffs
[Top][All Lists]
Advanced

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

scratch/icomplete-vertical-mode-improvements 82f8a3d 03/10: Fix an edge


From: João Távora
Subject: scratch/icomplete-vertical-mode-improvements 82f8a3d 03/10: Fix an edge case bug in icomplete.el where base-size wasn't restored
Date: Fri, 28 May 2021 06:10:05 -0400 (EDT)

branch: scratch/icomplete-vertical-mode-improvements
commit 82f8a3db343fa0d135a4bcbf76017cb476919680
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Fix an edge case bug in icomplete.el where base-size wasn't restored
    
    * lisp/icomplete.el (icomplete-completions): Fix edge case.
---
 lisp/icomplete.el | 116 +++++++++++++++++++++++++++---------------------------
 1 file changed, 59 insertions(+), 57 deletions(-)

diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index f6291fc..8e811c0 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -792,17 +792,18 @@ matches exist."
       (if icomplete-vertical-mode
          (icomplete--render-vertical comps)
        (let* ((last (if (consp comps) (last comps)))
-              (base-size (cdr last))
+               ;; Save the "base size" encoded in `comps' then
+               ;; removing making `comps' a proper list.
+              (base-size (prog1 (cdr last)
+                            (if last (setcdr last nil))))
               (most-try
-               (progn
-                 (if last (setcdr last nil))
-                 (if (and base-size (> base-size 0))
-                     (completion-try-completion
-                      name candidates predicate (length name) md)
-                   ;; If the `comps' are 0-based, the result should be
-                   ;; the same with `comps'.
-                   (completion-try-completion
-                    name comps nil (length name) md))))
+               (if (and base-size (> base-size 0))
+                    (completion-try-completion
+                     name candidates predicate (length name) md)
+                  ;; If the `comps' are 0-based, the result should be
+                  ;; the same with `comps'.
+                  (completion-try-completion
+                   name comps nil (length name) md)))
               (most (if (consp most-try) (car most-try)
                       (if most-try (car comps) "")))
               ;; Compare name and most, so we can determine if name is
@@ -853,54 +854,55 @@ matches exist."
                     (string-prefix-p prefix most t)
                     (length prefix))) ;;)
               prospects comp limit)
-         (if (or (eq most-try t) (and icomplete-rotate
-                                      (not (consp (cdr comps)))))
-             (concat determ " [Matched]")
-           (when (member name comps)
-             ;; NAME is complete but not unique.  This scenario poses
-             ;; following UI issues:
-             ;;
-             ;; - When `icomplete-hide-common-prefix' is non-nil, NAME
-             ;;   is stripped empty.  This would make the entry
-             ;;   inconspicuous.
-             ;;
-             ;; - Due to sorting of completions, NAME may not be the
-             ;;   first of the prospects and could be hidden deep in
-             ;;   the displayed string.
-             ;;
-             ;; - Because of `icomplete-prospects-height' , NAME may
-             ;;   not even be displayed to the user.
-             ;;
-             ;; To circumvent all the above problems, provide a visual
-             ;; cue to the user via an "empty string" in the try
-             ;; completion field.
-             (setq determ (concat open-bracket "" close-bracket)))
-           (while (and comps (not limit))
-             (setq comp
-                   (if prefix-len (substring (car comps) prefix-len) (car 
comps))
-                   comps (cdr comps))
-             (setq prospects-len
-                   (+ (string-width comp)
-                      (string-width icomplete-separator)
-                      prospects-len))
-             (if (< prospects-len prospects-max)
-                 (push comp prospects)
-               (setq limit t)))
-           (setq prospects (nreverse prospects))
-           ;; Decorate first of the prospects.
-           (when prospects
-             (let ((first (copy-sequence (pop prospects))))
-               (put-text-property 0 (length first)
-                                  'face 'icomplete-first-match first)
-               (push first prospects)))
-            ;; Restore the base-size info, since 
completion-all-sorted-completions
+         (prog1
+             (if (or (eq most-try t) (and icomplete-rotate
+                                          (not (consp (cdr comps)))))
+                 (concat determ " [Matched]")
+               (when (member name comps)
+                 ;; NAME is complete but not unique.  This scenario poses
+                 ;; following UI issues:
+                 ;;
+                 ;; - When `icomplete-hide-common-prefix' is non-nil, NAME
+                 ;;   is stripped empty.  This would make the entry
+                 ;;   inconspicuous.
+                 ;;
+                 ;; - Due to sortinvg of completions, NAME may not be the
+                 ;;   first of the prospects and could be hidden deep in
+                 ;;   the displayed string.
+                 ;;
+                 ;; - Because of `icomplete-prospects-height' , NAME may
+                 ;;   not even be displayed to the user.
+                 ;;
+                 ;; To circumvent all the above problems, provide a visual
+                 ;; cue to the user via an "empty string" in the try
+                 ;; completion field.
+                 (setq determ (concat open-bracket "" close-bracket)))
+               (while (and comps (not limit))
+                 (setq comp
+                       (if prefix-len (substring (car comps) prefix-len) (car 
comps))
+                       comps (cdr comps))
+                 (setq prospects-len
+                       (+ (string-width comp)
+                          (string-width icomplete-separator)
+                          prospects-len))
+                 (if (< prospects-len prospects-max)
+                     (push comp prospects)
+                   (setq limit t)))
+               (setq prospects (nreverse prospects))
+               ;; Decorate first of the prospects.
+               (when prospects
+                 (let ((first (copy-sequence (pop prospects))))
+                   (put-text-property 0 (length first)
+                                      'face 'icomplete-first-match first)
+                   (push first prospects)))
+               (concat determ
+                       "{"
+                       (mapconcat 'identity prospects icomplete-separator)
+                       (concat (and limit (concat icomplete-separator 
ellipsis))
+                               "}")))
+           ;; Restore the base-size info, since 
completion-all-sorted-completions
            ;; is cached.
-           (if last (setcdr last base-size))
-           (concat determ
-                   "{"
-                   (mapconcat 'identity prospects icomplete-separator)
-                   (concat (and limit (concat icomplete-separator ellipsis))
-                           "}"))))))))
+           (if last (setcdr last base-size))))))))
 
 ;;; Iswitchb compatibility
 



reply via email to

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