[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/icomplete-vertical-mode-improvements f3cb6c2 2/3: Fix an edge ca
From: |
Jo�o T�vora |
Subject: |
scratch/icomplete-vertical-mode-improvements f3cb6c2 2/3: Fix an edge case bug in icomplete.el where base-size wasn't restored |
Date: |
Wed, 26 May 2021 07:40:59 -0400 (EDT) |
branch: scratch/icomplete-vertical-mode-improvements
commit f3cb6c288e2b0466afaca71f43b43fad047615b6
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 6107b8f..2cd42ea 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -841,17 +841,18 @@ matches exist."
(if icomplete-vertical-mode
(icomplete--render-vertical comps md)
(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
@@ -902,54 +903,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