I use emacs for viewing and editing code and other text files. I wanted to know if there is a way to search forward or backward for text which is marked in the current buffer. S
I am using the following which does not have the problem of having to type more then one successive C-s to find later occurences:
(defun search-selection (beg end)
"search for selected text"
(interactive "r")
(kill-ring-save beg end)
(isearch-mode t nil nil nil)
(isearch-yank-pop)
)
(define-key global-map (kbd "") 'search-selection)
The disadvantage of the previous code is that the selected text is copied to the stretch. The following code does not have this problem:
(defun search-selection (beg end)
"search for selected text"
(interactive "r")
(let (
(selection (buffer-substring-no-properties beg end))
)
(deactivate-mark)
(isearch-mode t nil nil nil)
(isearch-yank-string selection)
)
)
(define-key global-map (kbd "") 'search-selection)