求助:consult-ripgrep命令报错,没有错误信息。有什么方法可以看到报错的信息吗?

问题如题。想问下大家有没有碰到过这种情况。怎么处理的

具体效果截图如下:

错误详情应该是在隐藏buffer里,试试 C-x b space列出隐藏buffer查看详情

正常应该message buffer里面有错误信息的,不过这个完全没有报错信息。最神奇的是用–debug-init参数启动,也没有报错信息。有其他方法可以看到报错位置么

_*consult-async-log* Troubleshooting consult commands `consult-ripgrip` and `consult-find` · Issue #247 · minad/consult · GitHub

这个issue的报错倒是类似,不过用(setq consult-project-root-function nil) 也没用。

_*consult-async-log* 这个buffer用list-buffers也看不到。

上面 @bing 告诉你了可以用 C-x b SPC 查看隐藏 buffer。 结合 @Voleking 提供的信息我觉得你不难找到这个 buffer。

(switch-to-buffer " *consult-async*")

没有别的意思,我也不是管理员,只是建议你仔细阅读一下别人的评论或者解答 :grimacing:

确实是不知道要空格看隐藏buffer,以为是下划线的buffer名,就回车执行命令看buffer列表了。没仔细看,不好意思了。感谢三位解答 @bing @Voleking @alexluigit

我给的链接也有说明🔗

查看了 consult-async,看到rg的执行命令,发现最后一个位置的搜索路径,总是为“.",导致搜索不到。之前在window/linux下都是正常搜索的,没出现这种情况。当前是在mac上使用的是emacs-mac才出现的该问题。这个路径是怎么设置传入的

执行consult-ripgrep出现如图所示,说明在.emacs.d下搜索,但命令却是如下:

“rg” “–null” “–line-buffered” “–color=never” “–max-columns=1000” “–path-separator” “/” “–smart-case” “–no-heading” “–with-filename” “–line-number” “–search-zip” “-P” “-e” “a” “.”

没有指定路径的情况下默认paths是"."

(builder (funcall make-builder paths))
(defun consult--grep (prompt make-builder dir initial)
  "Run asynchronous grep.

MAKE-BUILDER is the function that returns the command line
builder function.  DIR is a directory or a list of file or
directories.  PROMPT is the prompt string.  INITIAL is initial
input."
  (pcase-let* ((`(,prompt ,paths ,dir) (consult--directory-prompt prompt dir))
               (default-directory dir)
               (builder (funcall make-builder paths)))
    (consult--read
     (consult--async-command builder
       (consult--grep-format builder)
       :file-handler t) ;; allow tramp
     :prompt prompt
     :lookup #'consult--lookup-member
     :state (consult--grep-state)
     :initial (consult--async-split-initial initial)
     :add-history (consult--async-split-thingatpt 'symbol)
     :require-match t
     :category 'consult-grep
     :group #'consult--prefix-group
     :history '(:input consult--grep-history)
     :sort nil)))

下面是我修改的只搜索当前文件。

(defun my/consult--grep-file (prompt make-builder dir initial)
  (let ((builder (funcall make-builder nil)))
    (consult--read
     (consult--async-command builder
       (consult--grep-format builder)
       :file-handler t) ;; allow tramp
     :prompt prompt
     :lookup #'consult--lookup-member
     :state (consult--grep-state)
     :initial (consult--async-split-initial initial)
     :add-history (consult--async-split-thingatpt 'symbol)
     :require-match t
     :category 'consult-grep
     :group #'consult--prefix-group
     :history '(:input consult--grep-history)
     :sort nil)))

paths默认就是".",估计搜索路径使用的就是default-directory (即判断处理后的dir)

经过一早上的研究,各种源码测试,还一度怀疑大佬,不可能吧。原来是自己的问题,编码问题。以前的环境需要设置语言环境,mac上不需要。注释掉即可,终于解决了

还是得多从自己身上找原因 :sweat_smile:

1 个赞

我最近升级 emacs-mac 29.1 也遇到了这个问题,查到是编码问题,我注释掉下面的代码就好了:

;; (set-language-environment 'chinese-gbk)
;; (prefer-coding-system 'utf-8-auto)
2 个赞