Skip to content

Commit

Permalink
Merge pull request #1362 from garlic0x1/completion-tweaks
Browse files Browse the repository at this point in the history
Completion tweaks
  • Loading branch information
cxxxr committed May 12, 2024
2 parents 181e01e + 472129e commit e1aa6be
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/ext/completion-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
(defparameter *limit-number-of-items* 100)

(defvar *completion-context* nil)
(defvar *completion-reverse* nil)

(defclass completion-context ()
((spec
Expand Down Expand Up @@ -264,13 +265,18 @@

(define-command completion-narrowing-down-or-next-line () ()
(or (narrowing-down *completion-context* (context-last-items *completion-context*))
(completion-next-line)))
(if *completion-reverse*
(completion-previous-line)
(completion-next-line))))

(defun limitation-items (items)
(if (and *limit-number-of-items*
(< *limit-number-of-items* (length items)))
(subseq items 0 *limit-number-of-items*)
items))
(let ((result (if (and *limit-number-of-items*
(< *limit-number-of-items* (length items)))
(subseq items 0 *limit-number-of-items*)
items)))
(if *completion-reverse*
(reverse result)
result)))

(defun compute-completion-items (context then)
(flet ((update-items-and-then (items)
Expand All @@ -297,6 +303,8 @@
(completion-mode t)
(unless (spec-async-p (context-spec context))
(narrowing-down context items))
(when *completion-reverse*
(completion-end-of-buffer))
(call-focus-action)))

(defun continue-completion (context)
Expand All @@ -310,7 +318,9 @@
(popup-menu-update (context-popup-menu *completion-context*)
items
:print-spec (make-print-spec items))
(call-focus-action)))))))
(call-focus-action))))))
(when *completion-reverse*
(ignore-errors (completion-end-of-buffer))))

(defun run-completion (completion-spec &key style)
(let* ((spec (ensure-completion-spec completion-spec))
Expand Down

0 comments on commit e1aa6be

Please sign in to comment.