tags:

views:

71

answers:

3

Hey guys,

is it possible to search for the text that currently is present in the clipboard when hitting C-s, probably with some sort of hook that is triggered when hitting C-s and then inserts the clipboard into the minibuffer?

kind regards, mefiX

A: 

You can either use defadvice to alter the behaviour of the command isearch-forward, that is bound by default to C-s, or define another function that maybe wraps isearch-forward and bind it to C-s in place of isearch-forward.

Bozhidar Batsov
+6  A: 

Isearch provides a set of standard keys to change the behaviour of the search process. Typing C-s M-y invokes isearch-yank-kill that pulls string from kill ring (i.e., clipboard) into search string.

Török Gábor
A: 

You could yank the text after starting isearch:

(defun my-isearch-yank-clipboard ()
  (interactive)
  (isearch-yank-string (or (x-get-selection 'PRIMARY)
                           (x-get-selection 'CLIPBOARD)
                           "")))

(define-key isearch-mode-map (kbd "M-s c") 'my-isearch-yank-clipboard)

Start isearch then "M-s c"

scottfrazer
@scottfrazer: Built-in `(isearch-yank-x-selection)` does exactly the same.
Török Gábor