I am a big fan of query-selection-in-search-engine but am frustrated that it searches in the current buffer, while I usually want to search things before having finished my initial read. Therefore, I want the searches to be opened in new buffers. I am trying to define a custom function but haven’t been successful yet.

Below is the current state of what I tried, and the last line is broken. Any ideas what I am doing wrong?

(in-package #:nyxt-user)
(in-package :nyxt)

;;search selected text in new buffer
(define-command-global query-selection-in-search-engine-new-buffer ()
  "Search selected text in a new buffer using the queried search engine."
  (let* ((selection (%copy))
         (engine (first (prompt
                         :prompt "Search engine (new buffer):"
                         :sources (make-instance 'search-engine-source)))))
    (when engine
      (make-buffer-focus :url (make-instance 'new-url-query :query selection :engine engine)))))
1 Like

I would write it like this:

(define-command query-selection-in-search-engine ()
  "Search selected text using the queried search engine."
  (let* ((selection (%copy))
         (engine (first (prompt
                         :prompt "Search engine:"
                         :sources (make-instance 'search-engine-source))))
         (new-buffer (make-buffer-focus)))
    (when engine
      (buffer-load (make-instance 'new-url-query :query selection :engine engine)
                   :buffer new-buffer))))

it seems like we should support new buffers for this command though, that does seem quite logical!

1 Like


1 Like

Awesome, thank you!

(Damn, I was so close!)