有没有办法告诉 isearch 搜索活动区域(如果有)?否则定期提示输入字符串。
编辑:27.10.12
我最终使用了这些功能:
(defun er/isearch-word-at-point ()
(interactive)
(call-interactively 'isearch-forward-regexp))
(defun er/isearch-yank-word-hook ()
(when (equal this-command 'er/isearch-word-at-point)
(let ((string (concat "\\<"
(buffer-substring-no-properties
(progn (skip-syntax-backward "w_") (point))
(progn (skip-syntax-forward "w_") (point)))
"\\>")))
(if (and isearch-case-fold-search
(eq 'not-yanks search-upper-case))
(setq string (downcase string)))
(setq isearch-string string
isearch-message
(concat isearch-message
(mapconcat 'isearch-text-char-description
string ""))
isearch-yank-flag t)
(isearch-search-and-update))))
(defun er/isearch-yank-region ()
(interactive)
(isearch-yank-internal (lambda () (mark))))
(define-key isearch-mode-map (kbd "C-r") 'er/isearch-yank-region)
(define-key isearch-mode-map (kbd "C-t") 'er/isearch-word-at-point)
第一个是我在网上某处找到的一个函数,将光标下的单词标记为搜索词(类似于 vim 中的 * 和 # )并直接跳转到下一个出现,第二个是 @Oleg Pavliv 的答案。
编辑#2
实际上,为什么不将它们结合起来以获得超甜味呢?好的!
(defun er/isearch-word-or-region-at-point ()
(interactive)
(if (region-active-p)
(isearch-yank-internal (lambda () (mark)))
(call-interactively 'isearch-forward-regexp)))
(defun er/isearch-yank-word-hook ()
(when (equal this-command 'er/isearch-word-or-region-at-point)
(let ((string (concat "\\<"
(buffer-substring-no-properties
(progn (skip-syntax-backward "w_") (point))
(progn (skip-syntax-forward "w_") (point)))
"\\>")))
(if (and isearch-case-fold-search
(eq 'not-yanks search-upper-case))
(setq string (downcase string)))
(setq isearch-string string
isearch-message
(concat isearch-message
(mapconcat 'isearch-text-char-description
string ""))
isearch-yank-flag t)
(isearch-search-and-update))))
(add-hook 'isearch-mode-hook 'er/isearch-yank-word-hook)
(define-key isearch-mode-map (kbd "C-r") 'er/isearch-word-or-region-at-point)