Skip to content

Commit

Permalink
Use filter-exact-matches in much more places.
Browse files Browse the repository at this point in the history
This way, sources disappear when having no matches, or narrow down to the useful
suggestions really fast. This is particularly important when dealing with lots
of noisy data, like URLs, colors, lots of text entries.

The default preprocessor, delete-inexact-matches, is insufficient, as it matches
all the suggestion against any substring of input, which almost always passes
most elements through.
  • Loading branch information
aartaka committed Mar 21, 2023
1 parent 7e8483f commit a0c232c
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion source/buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,7 @@ proceeding."
(define-class buffer-source (prompter:source)
((prompter:name "Buffer list")
(prompter:constructor (buffer-initial-suggestions :current-is-last-p nil))
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:enable-marks-p t)
(prompter:actions-on-return (list (lambda-unmapped-command set-current-buffer)
(lambda-mapped-command buffer-delete)
Expand Down Expand Up @@ -1486,7 +1487,7 @@ URL-DESIGNATOR is then transformed by BUFFER's `buffer-load-hook'."
(declare (ignorable source))
(history-initial-suggestions)))
(prompter:enable-marks-p t)
(prompter:filter-preprocessor nil) ; Don't remove non-exact results.
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:actions-on-return #'buffer-load*))
(:export-class-name-p t)
(:metaclass user-class))
Expand Down
6 changes: 4 additions & 2 deletions source/command-commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
:global-p (global-p source)
:mode-symbols (mapcar #'sera:class-name-of (sera:filter #'enabled-p (modes (buffer source))))))))
(prompter:active-attributes-keys '("Name" "Bindings" "Docstring")
:accessor nil))
:accessor nil)
(prompter:filter-preprocessor #'prompter:filter-exact-matches))
(:export-class-name-p t)
(:documentation "Prompter source to execute commands.
Global commands are listed if `global-p' is non-nil.
Expand All @@ -54,7 +55,8 @@ from a key binding.")
(prompter:constructor
(lambda (source)
(declare (ignore source))
(list (predict-next-command *browser*)))))
(list (predict-next-command *browser*))))
(prompter:filter-preprocessor #'prompter:filter-exact-matches))
(:export-class-name-p t)
(:documentation "Prompter source to predict commands.")
(:metaclass user-class))
Expand Down
6 changes: 4 additions & 2 deletions source/describe.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ See `sym:package-functions' for an example."
:type (maybe (list-of package))
:documentation "Include internal symbols from the given packages.")
(prompter:name (alex:required-argument 'prompter:name))
(prompter:constructor (alex:required-argument 'prompter:constructor)))
(prompter:constructor (alex:required-argument 'prompter:constructor))
(prompter:filter-preprocessor #'prompter:filter-exact-matches))
(:export-class-name-p nil) ; Internal class.
(:export-accessor-names-p t))

Expand Down Expand Up @@ -149,7 +150,8 @@ See `sym:package-functions' for an example."

(define-class package-source (prompter:source)
((prompter:name "Packages")
(prompter:constructor (mapcar (compose #'intern #'package-name) (list-all-packages)))))
(prompter:constructor (mapcar (compose #'intern #'package-name) (list-all-packages)))
(prompter:filter-preprocessor #'prompter:filter-exact-matches)))

(define-internal-page-command-global describe-any (&key input)
(buffer (format nil "*Describe-~a*" input) 'nyxt/help-mode:help-mode)
Expand Down
1 change: 1 addition & 0 deletions source/history.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ lot."
((prompter:name "Disowned History")
(buffer :accessor buffer :initarg :buffer)
(prompter:enable-marks-p t)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:constructor
(lambda (source)
(let* ((history (buffer-history (buffer source)))
Expand Down
1 change: 1 addition & 0 deletions source/mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ For production code, see `find-submode' instead."
((prompter:name "Modes")
(prompter:enable-marks-p t)
(prompter:constructor (sort (all-mode-symbols) #'string< :key #'symbol-name))
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:suggestion-maker 'make-mode-suggestion))
(:export-class-name-p t)
(:metaclass user-class))
Expand Down
1 change: 1 addition & 0 deletions source/mode/annotate.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ make-instance."
(define-class annotation-source (prompter:source)
((prompter:name "Annotations")
(prompter:constructor (files:content (annotations-file (current-buffer))))
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:enable-marks-p t)))

(define-class annotation-tag-source (prompter:source)
Expand Down
2 changes: 2 additions & 0 deletions source/mode/document.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ It does not assume being online."))
(define-class ring-source (prompter:source)
((prompter:name "Clipboard ring")
(ring :initarg :ring :accessor ring :initform nil)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:constructor
(lambda (source)
(containers:container->list (ring source))))
Expand Down Expand Up @@ -441,6 +442,7 @@ ID is a buffer `id'."
(define-class heading-source (prompter:source)
((prompter:name "Headings")
(buffer :accessor buffer :initarg :buffer)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:actions-on-current-suggestion-enabled-p t)
(prompter:actions-on-current-suggestion
(lambda-command scroll-page-to-heading* (heading)
Expand Down
3 changes: 2 additions & 1 deletion source/mode/file-manager.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ When the user is unspecified, take the current one."
(define-class program-source (prompter:source)
((prompter:name "Programs")
(prompter:constructor (executables))
(prompter:enable-marks-p t))
(prompter:enable-marks-p t)
(prompter:filter-preprocessor #'prompter:filter-exact-matches))
(:export-class-name-p t)
(:export-accessor-names-p t)
(:documentation "Prompt source for user-accessible programs.")
Expand Down
3 changes: 2 additions & 1 deletion source/mode/hint.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ FUNCTION is the action to perform on the selected elements."
(nyxt/dom:toggle-details-element details))

(define-class options-source (prompter:source)
((prompter:name "Options"))
((prompter:name "Options")
(prompter:filter-preprocessor #'prompter:filter-exact-matches))
(:export-class-name-p t)
(:documentation "Prompt source for select tag options."))

Expand Down
6 changes: 6 additions & 0 deletions source/mode/history.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ This saves the history to disk when BODY exits."
(define-class history-backwards-source (prompter:source)
((prompter:name "Parent URLs")
(buffer :initarg :buffer :accessor buffer :initform nil)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:constructor
(lambda (source)
(with-history (history (buffer source))
Expand Down Expand Up @@ -173,6 +174,7 @@ This saves the history to disk when BODY exits."
(define-class direct-history-forwards-source (prompter:source)
((prompter:name "First child of all forward-branches")
(buffer nil :type (maybe buffer))
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:constructor
(lambda (source)
(with-history (history (buffer source))
Expand Down Expand Up @@ -208,6 +210,7 @@ Otherwise go forward to the only child."
(define-class history-forwards-source (prompter:source)
((prompter:name "All children URLs of the current forward-branch")
(buffer :initarg :buffer :accessor buffer :initform nil)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:constructor
(lambda (source)
(with-history (history (buffer source))
Expand All @@ -232,6 +235,7 @@ Otherwise go forward to the only child."
(define-class all-history-forwards-source (prompter:source)
((prompter:name "Child URLs")
(buffer :initarg :buffer :accessor buffer :initform nil)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:constructor
(lambda (source)
(with-history (history (buffer source))
Expand All @@ -255,6 +259,7 @@ Otherwise go forward to the only child."
(define-class history-all-owner-nodes-source (prompter:source)
((prompter:name "All history URLs")
(buffer :initarg :buffer :accessor buffer :initform nil)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:constructor
(lambda (source)
(with-history (history (buffer source))
Expand All @@ -279,6 +284,7 @@ Otherwise go forward to the only child."
(define-class history-all-source (prompter:source)
((prompter:name "All history URLs")
(buffer :initarg :buffer :accessor buffer :initform nil)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:constructor
(lambda (source)
(with-history (history (buffer source))
Expand Down
1 change: 1 addition & 0 deletions source/panel.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(define-class panel-buffer-source (prompter:source)
((prompter:name "Panel buffers")
(window :accessor window :initarg :window)
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:enable-marks-p t)
(prompter:constructor (lambda (source)
(panel-buffers (window source))))))
Expand Down
3 changes: 2 additions & 1 deletion source/recent-buffers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
(mapc #'reopen-dead-buffer buffer-list)
(set-current-buffer (or (first (prompter:marks (current-source)))
(current-suggestion-value (current-prompt-buffer)))))
(lambda-mapped-command reopen-dead-buffer)))))
(lambda-mapped-command reopen-dead-buffer)))
(prompter:filter-preprocessor #'prompter:filter-exact-matches)))

(define-command reopen-buffer ()
"Reopen queried deleted buffer(s)."
Expand Down
3 changes: 2 additions & 1 deletion source/renderer/gtk.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,8 @@ the `active-buffer'."
(define-class color-source (prompter:source)
((prompter:name "Color")
(prompter:constructor *css-colors*)
(prompter:filter-preprocessor
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:filter-postprocessor
(lambda (suggestions source input)
(let ((input-color input))
(cons (make-instance 'prompter:suggestion
Expand Down
4 changes: 3 additions & 1 deletion source/search-engine.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ Example (Tor-proxied completion function for Wikipedia):

(define-class search-engine-source (prompter:source)
((prompter:name "Search Engines")
(prompter:constructor (all-search-engines))))
(prompter:constructor (all-search-engines))
(prompter:filter-preprocessor #'prompter:filter-exact-matches)))

(define-class search-engine-url-source (prompter:source)
((prompter:name "Search Engines")
(prompter:constructor (delete nil (mapcar #'fallback-url (all-search-engines))))
(prompter:filter-preprocessor #'prompter:filter-exact-matches)
(prompter:enable-marks-p t)))

(define-command query-selection-in-search-engine (&key (query-in-new-buffer-p t))
Expand Down

0 comments on commit a0c232c

Please sign in to comment.