如果我选择一个文本区域,有没有办法使用isearch(或其他一些搜索命令),这将允许我只在该区域内搜索?我希望在宏中使用它来进行技术处理.
这可能是显而易见的,但我做了一个快速搜索,找不到办法.
您可以使用以下命令组合:
M-x narrow-to-region C-s SOMETEXT M-x widen
虽然,这有点麻烦,但这是一个新的命令,可以自动完成上述操作.
(defun isearch-forward-region-cleanup () "turn off variable, widen" (if isearch-forward-region (widen)) (setq isearch-forward-region nil)) (defvar isearch-forward-region nil "variable used to indicate we're in region search") (add-hook 'isearch-mode-end-hook 'isearch-forward-region-cleanup) (defun isearch-forward-region (&optional regexp-p no-recursive-edit) "Do an isearch-forward, but narrow to region first." (interactive "P\np") (narrow-to-region (point) (mark)) (goto-char (point-min)) (setq isearch-forward-region t) (isearch-mode t (not (null regexp-p)) nil (not no-recursive-edit)))
现在就做M-x isearch-forward-region RET SOMETEXT,或者将它绑定到您的首选项的键绑定,如:
(global-set-key (kbd "C-S-s") 'isearch-forward-region)
正如Trey Jackson所说,你可以使用narrow-to-region
和widen
.我将填写键盘快捷键.请注意,默认情况下它们处于禁用状态,并且emacs会在首次使用时以交互方式提示"不可删除"它们.
C-x n n C-s sometext C-x n w