Plaster
New
List
Login
common-lisp
default
anonymous
2024.01.11 01:16:24
(defun lisp-fuzzy-search () "Search REPL history with flex completion. Works in the SLIME REPL, or any comint-derived mode." (interactive) (unless (or (eq major-mode 'slime-repl-mode) (derived-mode-p 'comint-mode)) (user-error "Not in slime-repl-mode, or a mode derived from comint-mode.")) (pcase-let* ((history (if (eq major-mode 'slime-repl-mode) slime-repl-input-history (ring-elements comint-input-ring))) (bol (if (eq major-mode 'slime-repl-mode) #'slime-repl-previous-prompt #'comint-bol)) (`(,beg . ,end) (save-excursion (funcall bol) (cons (point) (pos-eol)))) (completion-styles '(flex basic)) (chosen-candidate (completing-read "History: " ;; Use a custom completion function to prevent sorting of the candidates. (lambda (str pred action) (let ((result (complete-with-action action history str pred))) (if (eq action 'metadata) `(metadata . ((cycle-sort-function . identity) (display-sort-function . identity))) result))) nil nil (buffer-substring-no-properties beg end)))) (delete-region beg end) (unless (eq major-mode 'slime-repl-mode) (setf comint-input-ring-index (seq-position history chosen-candidate))) (insert chosen-candidate)))
Raw
Annotate
Repaste
Edit