gpt4 book ai didi

emacs - 如果 emacs 处于事件状态,则搜索区域

转载 作者:行者123 更新时间:2023-12-04 05:26:56 25 4
gpt4 key购买 nike

有没有办法告诉 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)

最佳答案

好问题。

在 Emacs 中似乎没有这种可能性。你可以自己实现

(defun isearch-yank-region ()
(interactive)
(isearch-yank-internal (lambda () (mark))))


(define-key isearch-mode-map "\C-r" 'isearch-yank-region)

现在选择一个区域,调用增量搜索 C-s并猛拉该区域 C-r .然后你可以继续增量搜索 C-s .

关于emacs - 如果 emacs 处于事件状态,则搜索区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13095405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com