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

inconsistencies among go-* and replace #14

Open
epipping opened this issue Jan 7, 2014 · 0 comments
Open

inconsistencies among go-* and replace #14

epipping opened this issue Jan 7, 2014 · 0 comments

Comments

@epipping
Copy link
Contributor

epipping commented Jan 7, 2014

Consider the following "input" with line numbers.

1 xxxxxx
2 xxXXxx
3 xxxxxx_bar
4 xxxxxx-bar
5 axxxxxxb

I observe the following.

(a) smartscan-symbol-go-forward and smartscan-symbol-go-backward cut these lines (or rather, their respective contents) into equivalence classes. 1 and 2 are considered equivalent by default, the others form singletons. If I want to have line 1 and 2 considered as not identical, I can employ something like

(defadvice smartscan-symbol-go-forward (around smartscan activate)
  "Match in a case-sensitive way."
  (let ((case-fold-search nil))
    ad-do-it))

(defadvice smartscan-symbol-go-backward (around smartscan activate)
  "Match in a case-sensitive way."
  (let ((case-fold-search nil))
    ad-do-it))

Is there a simpler way?

(b) smartscan-symbol-replace when called on line 1 or 2 will also replace matches in line 3-5. Why?

Here's a fix:

(defun smartscan-symbol-replace (arg)
  "Replaces the symbol at point with another string in the entire buffer.                

With C-u the scope is limited to the current defun, as defined by                        
`narrow-to-defun'.                                                                       

This function uses `search-forward' and `replace-match' to do the                        
actual work."
  (interactive "P")
  (save-excursion
      (let* ((oldsymbol (smartscan-symbol-at-pt 'beginning))
             (newsymbol (query-replace-read-to
                         oldsymbol (format "%sSmart Scan replace"
                                           (if arg "[Defun] " "")) nil))
             (counter 0))
        (if arg (goto-char (save-excursion (beginning-of-defun) (point)))
          ;; go to the beginning of the buffer as it's assumed you want to               
          ;; apply it from there onwards. beginning                                      
          (goto-char (point-min)))
        (while (re-search-forward
                (concat "\\_<" oldsymbol "\\_>")
                (if arg (save-excursion (end-of-defun) (point)) nil) t nil)
          (replace-match newsymbol nil t) (cl-incf counter 1))
        (message "Smart Scan replaced %d matches" counter))))

(c) Setting smartscan-use-extended-syntax should affect the behaviour described in (a) and (b), no? [what exactly should it do?]. It doesn't seem to have any effect for me.

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

1 participant