smart-scan icon indicating copy to clipboard operation
smart-scan copied to clipboard

inconsistencies among `go-*` and `replace`

Open epipping opened this issue 12 years ago • 0 comments

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.

epipping avatar Jan 07 '14 22:01 epipping