如何整合 isearch 模式中发生的任何事情

发布于 2024-11-04 20:50:06 字数 999 浏览 1 评论 0原文

我非常喜欢 anything.el 。一切 UI 都很棒。

我也经常使用 isearch,它提供了键绑定 Ms o 以使用 isearch 输入字符串调用 occurr 。但本机发生模式还不够强大。

occurr-mode中,您无法再次过滤结果。跳跃功能也是基本的。

我发现 anything-occur 比 < code>occurr,你可以过滤结果,以任何方式跳转一个位置。

但有一个问题,如何集成anything-occurr?我的最后一次尝试是:

(defun occur-in-isearch ()
  (interactive)
  (let ((case-fold-search isearch-case-fold-search))
    (occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))

我用 anything-occurr 替换 occurr,但没有用。 anything-occurr 是一个不带参数的 defun。我无法将 isearch 字符串传递给 anything-occurr

我如何集成anything-occurr?或者是否有更好的方法在isearch-mode 中使用anything-occurr

I like anything.el a lot. The anything UI is wonderful.

I also use isearch very often, and it provides the keybinding M-s o to invoke occur using the isearch input string. But native occur mode is not powerful enough.

In occur-mode you cannot filter result again. And jumping function is basic too.

I find anything-occur is more powerful than occur, you can filter result, jump a position in anything style.

But there is a problem , How to integrate anything-occur? My last attempt is:

(defun occur-in-isearch ()
  (interactive)
  (let ((case-fold-search isearch-case-fold-search))
    (occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))

I replace occur with anything-occur, but it is no use. anything-occur is a defun which takes no parameters. I cannot pass the isearch string to anything-occur.

How might I integrate anything-occur? Or is there a better way to use anything-occur within isearch-mode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤城病女 2024-11-11 20:50:06

我不是任何东西的用户,但是这段代码可以完成你想要的 99% 的事情。唯一需要注意的是,当您键入 backspace 时,初始输入字符串不会正确更新。我不知道为什么会这样。其他一切似乎都按预期工作。

(eval-after-load "isearch"
  '(define-key isearch-mode-map (kbd "M-s o") 'isearch-anything-occur))

(defun isearch-anything-occur (regexp &optional nlines)
  "isearch anything occur"
  (interactive
   ;; from isearch-occur
   (list
    (cond
     (isearch-word (concat "\\b" (replace-regexp-in-string
                                  "\\W+" "\\W+"
                                  (replace-regexp-in-string
                                   "^\\W+\\|\\W+$" "" isearch-string)
                                  nil t)
                           "\\b"))
     (isearch-regexp isearch-string)
     (t (regexp-quote isearch-string)))
    (if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
  ;; from occur-anything
  (let ((anything-compile-source-functions
         ;; rule out anything-match-plugin because the input is one regexp.
         (delq 'anything-compile-source--match-plugin
               (copy-sequence anything-compile-source-functions))))
    (anything :sources 'anything-c-source-occur
              :input regexp
              :buffer "*Anything Occur*")))

I'm not a user of anything, but this code does 99% of what you want. The only caveat is that the initial input string doesn't get properly updated when you type backspace. I don't know why that is. Everything else works seems to work as expected.

(eval-after-load "isearch"
  '(define-key isearch-mode-map (kbd "M-s o") 'isearch-anything-occur))

(defun isearch-anything-occur (regexp &optional nlines)
  "isearch anything occur"
  (interactive
   ;; from isearch-occur
   (list
    (cond
     (isearch-word (concat "\\b" (replace-regexp-in-string
                                  "\\W+" "\\W+"
                                  (replace-regexp-in-string
                                   "^\\W+\\|\\W+$" "" isearch-string)
                                  nil t)
                           "\\b"))
     (isearch-regexp isearch-string)
     (t (regexp-quote isearch-string)))
    (if current-prefix-arg (prefix-numeric-value current-prefix-arg))))
  ;; from occur-anything
  (let ((anything-compile-source-functions
         ;; rule out anything-match-plugin because the input is one regexp.
         (delq 'anything-compile-source--match-plugin
               (copy-sequence anything-compile-source-functions))))
    (anything :sources 'anything-c-source-occur
              :input regexp
              :buffer "*Anything Occur*")))
泪眸﹌ 2024-11-11 20:50:06

非常相似——

Icicles中,在Isearch期间点击S-TAB。按 RET 接受相同的搜索模式,或先对其进行编辑,然后按 RET

这将打开 Icicles 搜索,并将所有匹配项作为搜索上下文。要使用进一步的模式缩小/过滤这些上下文,只需输入更多文本即可。

要逐步过滤多个模式,请在模式之间点击 M-SPC。使用 C-down (等)在匹配项之间循环,或完成其中任何一个,或在 *Completions< 中的任何一个上单击 C-mouse-2 /代码>。

http://www.emacswiki.org/emacs/Icicles_-_Isearch_Enhancements#IciclesSearchFromIsearch

Very similar --

In Icicles, during Isearch hit S-TAB. Hit RET to accept the same search pattern, or edit it first and then hit RET.

That opens Icicles search with all matches as the search contexts. To narrow/filter those contexts with a further pattern, just type more text.

To filter progressively with multiple patterns, hit M-SPC between patterns. Cycle among the matches using C-down (etc.) or complete to any of them or click C-mouse-2 on any of them in *Completions.

http://www.emacswiki.org/emacs/Icicles_-_Isearch_Enhancements#IciclesSearchFromIsearch

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文