请教一下consult中文处理等几个问题?

最近想尝试从ivy向vertico、consult的迁移,还是有点不太习惯;遇到几个问题请教一下大家: 1、consult-grep无法查找中文,不知道是不是应该增加什么设置才好?counsel-grep查找中文没有问题; 2、consult-locate在windows中,可以向counsel-locate一样使用everything吗?counsel-locate配合everything真是方便; 3、consult可以定制按照一定顺序排列可选项吗?

刚开始用还不熟悉,多谢大家指点。

1 2 都是你去对比两个源码就行了,比如说 counsel-grep-commandgrep -E -n -e %s filename 可以搜中文,你去对比 consult-grep-args 有啥不一样的地方,然后看咋改。 counsel-locate-cmd-es 也就一个函数,然后如果没有就看看咋改。(可能是改 consult-locate-args 我没用过,不确定)

(defun counsel-locate-cmd-es (input)
  "Return a `es' shell command based on INPUT."
  (defvar w32-ansi-code-page)
  (counsel-require-program "es.exe")
  (let ((raw-string (format "es.exe -i -p -r %s"
                            (counsel--elisp-to-pcre
                             (ivy--regex input t)))))
    ;; W32 doesn't use Unicode by default, so we encode search command
    ;; to local codepage to support searching file names containing
    ;; non-ASCII characters.
    (if (and (eq system-type 'windows-nt)
             (boundp 'w32-ansi-code-page))
        (encode-coding-string raw-string
                              (intern (format "cp%d" w32-ansi-code-page)))
      raw-string)))

@zilongshanren 的配置,consult-locate 就可以用 everything 来搜索, 并且能显示中文。

不过不支持空格来分词,只能搜索一个单词。请教下,怎么设置才能像在 GUI 的 everything 中那样分词进行搜索。

1 个赞

貌似目前只能通过单个单词搜索之后,在搜索结果后面加上#再用orderless的规则去弄。

比如 搜索 #emacs#keyword1 keyword2 来过滤,此时可以添加空格

2 个赞

这样也很棒。 Windows 下虽然 everything 很快,但在 Emacs 中刷新还是明显能感觉到延迟的。 单个单词出来结果后,通过 orderless 进一步过滤时,速度速度贼快 :+1:,瞬时更新。

似乎不能搜索中文吧?

可以的,不过我现在也不用 everything 了。如果不行,可能是编码问题。

(use-package pinyinlib
  :after orderless
  :config
  (defun completion--regex-pinyin (str)
    (orderless-regexp (pinyinlib-build-regexp-string str)))
  (add-to-list 'orderless-matching-styles 'completion--regex-pinyin))

刚踩完的坑,得设置windows系统编码方式为UTF-8,然后这几行里面最好再加一行对grep的