セレクションで範囲限定する置換

 昨日のコメントの所で教えてもらったのでセレクションを使うやつを見て、ふと思ったのはxyzzyって良くあるエディタみたいなセレクションで範囲限定して置換とかってないなぁと。使い始めた頃にそこで詰まっていたような気もした。ので、適当にセレクションがある場合はセレクション内で置換するのを適当に書いてみた。

(defun replace-string-overwrite (pattern replacement &optional noerror)
  "selectionがある場合はselectionの範囲で置換"
  (interactive "*sReplace string: \nswith: "
	:default0 ed::*last-search-string* :history0 'search
	:default1 ed::*last-replace-string* :history1 'search)
  (when (pre-selection-p)
	(narrow-to-region (selection-mark) (selection-point))
	(stop-selection))
  (replace-string pattern replacement noerror)
  (widen)
  (setq *this-command* 'replace-string))

(global-set-key #\M-r 'replace-string-overwrite)

でも、ここで詰まったので、逆にリージョンの扱いを覚えたとかあるから役に立つのか微妙だけど。isearchってセレクション反応しないので色々普通のWindowsエディタっぽい挙動にもできそう。
isearchはセレクション反応させるのは少し見た感じだと面倒そう。isearchを書き換えた方がすっきり出来そうだけど、isearch自体の出来が非常にいいので変に変えると他にも不都合が出そうだから辞めてみた。