Skip to content

Commit

Permalink
Merge pull request #1555 from naryl/main
Browse files Browse the repository at this point in the history
List listener history filtering by prefix
  • Loading branch information
cxxxr authored Oct 2, 2024
2 parents 3f2f0ad + 789a55a commit 334fd12
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/ext/listener-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
:listener-return
:listener-previous-input
:listener-next-input
:listener-previous-startswith-input
:listener-next-startswith-input
:listener-previous-matching-input
:listener-clear-buffer
:listener-clear-input)
Expand Down Expand Up @@ -168,6 +170,47 @@
(when win
(replace-textarea buffer str))))

(define-command listener-previous-startswith-input () ()
(block nil
(let* ((buffer (current-buffer))
(point (buffer-point buffer))
(charpos (point-charpos point))
(prefix (points-to-string (input-start-point buffer) point)))
(backup-edit-string (current-buffer))
(flet ((commit (str)
(replace-textarea buffer str)
(setf (point-charpos point) charpos)
(return)))
(loop
(multiple-value-bind (str win)
(lem/common/history:previous-history (current-listener-history))
(if win
(when (eql 0 (search prefix str :test #'string=))
(commit str))
(return))))))))

(define-command listener-next-startswith-input () ()
(block nil
(let* ((buffer (current-buffer))
(point (buffer-point buffer))
(charpos (point-charpos point))
(prefix (points-to-string (input-start-point buffer) point)))
(backup-edit-string (current-buffer))
(flet ((commit (str)
(replace-textarea buffer str)
(setf (point-charpos point) charpos)
(return))
(rollback ()
(restore-edit-string buffer)
(return)))
(loop
(multiple-value-bind (str win)
(lem/common/history:next-history (current-listener-history))
(if win
(when (eql 0 (search prefix str :test #'string=))
(commit str))
(rollback))))))))

(define-command listener-previous-input () ()
(backup-edit-string (current-buffer))
(multiple-value-bind (str win)
Expand Down

0 comments on commit 334fd12

Please sign in to comment.