Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

over-zealous replacement #23

Open
r2evans opened this issue Aug 14, 2018 · 1 comment
Open

over-zealous replacement #23

r2evans opened this issue Aug 14, 2018 · 1 comment

Comments

@r2evans
Copy link

r2evans commented Aug 14, 2018

Sample source code (R-language):

sample_func <- function(...) {
  xy <- xy2(123)
  xyz
  xy
}

If I place the cursor on the xy variable, then smartscan-symbol-go-forward correctly jumps between the two instances and correctly skips the function xy2 and the variable xyz. However, if I use smartscan-symbol-replace and set it to xyWRONG, then I get:

sample_func <- function(...) {
  xyWRONG <- xyWRONG2(123)
  xyWRONGz
  xyWRONG
}

Expected output:

sample_func <- function(...) {
  xyWRONG <- xy2(123)
  xyz
  xyWRONG
}
@alhassy
Copy link

alhassy commented Dec 19, 2019

Here is a solution that is global ---it does not narrow to defun-s and so it may not be ideal for your use case. This is related to issue #10.

(defun my/symbol-replace (replacement)
  "Replace all standalone symbols in the buffer matching the one at point."
  (interactive  (list (read-from-minibuffer "Replacement for thing at point: " nil)))
  (save-excursion 
    (let ((symbol (or (thing-at-point 'symbol) (error "No symbol at point!"))))
      (beginning-of-buffer)
      ;; (query-replace-regexp symbol replacement)
      (replace-regexp (format "\\b%s\\b" (regexp-quote symbol)) replacement))))

(global-set-key (kbd "M-'") 'my/symbol-replace))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants