I want isearch-forward-symbol-at-point
to also save to the kill-ring
. How can I accomplish that please?
1 Answer
Try this.
(defun my-isearch-forward-symbol-at-point ()
"`isearch-forward-symbol-at-point', but copy symbol name to `kill-ring'."
(interactive)
(isearch-forward-symbol nil 1)
(let* ((bounds (find-tag-default-bounds))
(string (and bounds (buffer-substring-no-properties
(car bounds) (cdr bounds)))))
(cond
(string
(kill-new string)
(when (< (car bounds) (point))(goto-char (car bounds)))
(isearch-yank-string string))
(t
(setq isearch-error "No symbol at point")
(isearch-push-state)
(isearch-update)))))
(define-key isearch-mode-map "." 'my-isearch-forward-symbol-at-point)
(define-key search-map "." 'my-isearch-forward-symbol-at-point)
All I did was copy the definition of isearch-forward-symbol-at-point
and insert a call to kill-new
.
-
thanks but how is this to be invoked? after hitting C-s and then . isearch just searches for . occurences. I would rather have the copying as a side effect of hitting M-w .– CD86Jan 10 at 8:33
-
Sorry, I pasted the wrong code I forgot the
(kill-new string)
, which puts thestring
into thekill-ring
. Please try the updated code.– DrewJan 10 at 16:42 -
thank you, but how can I automatically invoke this when pressing M-s . isearch-forward-symbol-at-point ? I dont want to have to press C-s .– CD86Jan 10 at 20:10
-
I added the binding to
search-map
as well. You can also add it toquery-replace-map
...– DrewJan 10 at 21:27