I am using following solution (How do I add a keybinding to use during an interactive isearch, `C-s ...`) to move over symbols in the buffer, which iterates over the matching symbols:
(define-key isearch-mode-map (kbd "C-w")
'isearch-forward-symbol-at-point)
Is it possible to apply same manner into replace-all where instead of text it replaces the symbols (where the isearch-forward-symbol-at-point
iterates over):
My query replace function, which replace all the matching query instead of only the symbols:
(defun query-replace-region-or-from-top ()
(interactive)
(let ((case-fold-search nil))
(progn
(let ((orig-point (point)))
(if (use-region-p)
(call-interactively 'query-replace)
(save-excursion
(goto-char (point-min))
(call-interactively 'query-replace)))
(message "Back to old point.")
(goto-char orig-point)))))
(global-set-key "\C-x\C-r" 'query-replace-region-or-from-top)
Example_1:
gas_costs = 100
_cost = 10
log(f"==> cost={_cost}")
Replace-all _cost
into cost
=> changes into:
gascosts = 100
cost = 10
log(f"==> cost={cost}")
wanted:
gas_cost = 100 # should remain unchanged
cost = 100
log(f"==> cost={cost}")
Example_2:
alper = 100
alper99 = 99
Replace-all alper
into sad
=> changes into:
sad = 100
sad99 = 99
wanted:
sad = 100
alper99 = 99
I just want to replace patterns as exactly same with isearch
finds. Because first I always search patterns using isearch
and than replace them. But if there are diffierent matched patterns in replace-all
, I get end up replacing differect results than isearch
finds.