[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/icomplete-vertical-mode-improvements 94368e2 06/10: Adjust scrol
From: |
João Távora |
Subject: |
scratch/icomplete-vertical-mode-improvements 94368e2 06/10: Adjust scrolling behaviour of icomplete-vertical-mode |
Date: |
Fri, 28 May 2021 06:10:06 -0400 (EDT) |
branch: scratch/icomplete-vertical-mode-improvements
commit 94368e211f9a28dfc7fd466578b9fdf77423e3a1
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Adjust scrolling behaviour of icomplete-vertical-mode
* lisp/icomplete.el (icomplete--last-selected): Document
(icomplete-forward-completions)
(icomplete-backward-completions): Set icomplete--last-selected
here.
(icomplete--render-vertical): Adjust and document.
---
lisp/icomplete.el | 43 ++++++++++++++++++++++++++++---------------
1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 4c651e2..8357d8f 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -228,7 +228,7 @@ the default otherwise."
(defvar icomplete--comp-predecessors nil
"Completions to list before the selected one.")
(defvar icomplete--last-selected nil
- "Last completion selected.")
+ "Last completion explicitly selected.")
(defun icomplete-forward-completions ()
"Step forward completions by one entry.
@@ -243,9 +243,10 @@ Second entry becomes the first and can be selected with
(cond (icomplete-rotate
(setcdr (last comps) (cons (pop comps) (cdr last))))
(t
- (push (pop comps) icomplete--comp-predecessors)))
- (completion--cache-all-sorted-completions beg end comps))
- (setq icomplete--last-selected nil)))
+ (push (pop comps) icomplete--comp-predecessors)
+ (setq icomplete--last-selected
+ (cons (car comps) (buffer-modified-tick)))))
+ (completion--cache-all-sorted-completions beg end comps))))
(defun icomplete-backward-completions ()
"Step backward completions by one entry.
@@ -262,9 +263,10 @@ Last entry becomes the first and can be selected with
(push (car (cdr last-but-one)) comps)
(setcdr last-but-one (cdr (cdr last-but-one))))
(icomplete--comp-predecessors
- (push (pop icomplete--comp-predecessors) comps)))
- (completion--cache-all-sorted-completions beg end comps)
- (setq icomplete--last-selected nil)))
+ (push (pop icomplete--comp-predecessors) comps)
+ (setq icomplete--last-selected
+ (cons (car comps) (buffer-modified-tick)))))
+ (completion--cache-all-sorted-completions beg end comps)))
;;; Helpers for `fido-mode' (or `ido-mode' emulation)
;;;
@@ -695,9 +697,18 @@ See `icomplete-mode' and `minibuffer-setup-hook'."
(put-text-property 0 1 'cursor t text)
(overlay-put icomplete-overlay 'after-string text))))))))
-(defun icomplete--render-vertical (comps)
- ;; First attempt to keep selection stable. Do this only if the
- ;; selection didn't change but the candidates did.
+(cl-defun icomplete--render-vertical (comps md)
+ ;; This is loopapalooza
+ ;;
+ ;; First, attempt to keep selection stable. Do this only if
+ ;; rotation is off and there is a selection.
+ ;;
+ ;; Most importantly, also only do this if the buffer changed,
+ ;; meaning there are new candidates within which we want to search
+ ;; for our manually selected one. That's because if we were to
+ ;; needlessly search for our selection in unchanged candidates, we'd
+ ;; obviously always find it in the first position, lose the illusion
+ ;; of a dropdown scroll.
(when (and icomplete--last-selected
(not (eq (cdr icomplete--last-selected) (buffer-modified-tick)))
(null icomplete-rotate))
@@ -713,7 +724,11 @@ See `icomplete-mode' and `minibuffer-setup-hook'."
(icomplete--field-end)
comps)
and return nil
- do (push comp preds)))
+ do (push comp preds)
+ finally (setq icomplete--last-selected nil)))
+ ;; The ugliest loop, collect the completions before and after the
+ ;; selected one, considering scrolling positions.
+ ;;
(cl-loop
with preds = (and (null icomplete-rotate) icomplete--comp-predecessors)
with succs = (cdr comps)
@@ -740,10 +755,8 @@ See `icomplete-mode' and `minibuffer-setup-hook'."
#'identity
(nconc before
(list
- (setq icomplete--last-selected
- (cons (propertize (car comps) 'face
- 'icomplete-selected-match)
- (buffer-modified-tick)))))
+ (propertize (car comps) 'face
+ 'icomplete-selected-match)))
after)
icomplete-separator)))))
- branch scratch/icomplete-vertical-mode-improvements created (now 0337e73), João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements d3b85d0 04/10: * lisp/icomplete.el (icomplete--render-vertical): Simplify slightly., João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 136f71b 02/10: Distinguish fido-mode from icomplete-mode verticality, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 82f8a3d 03/10: Fix an edge case bug in icomplete.el where base-size wasn't restored, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 776633a 01/10: Improve icomplete-vertical-mode, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements f751980 05/10: Don't break icomplete-vertical-mode scrolling when moving non-destructively, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 24ddc91 07/10: Rename icomplete-rotate to icomplete-scroll, for clarity, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 94368e2 06/10: Adjust scrolling behaviour of icomplete-vertical-mode,
João Távora <=
- scratch/icomplete-vertical-mode-improvements f7b22c0 08/10: Simplify icomplete-vertical-mode scrolling implementation, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 0337e73 10/10: Add annotation capability to icomplete-vertical-mode, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 37f0362 09/10: Update NEWS, João Távora, 2021/05/28