自己写的helm source,搜索的时候没有高亮,怎么回事?

代码如下:

(defun random-candidates ()
  "Return a list of 40 random numbers from 0 to 10"
  (loop for i below 40 collect (random 100)))

(setq some-helm-source
      '((name . "HELM at the Emacs")
        (candidates . random-candidates)
        (action . (lambda (candidate)
                    (message "%s" candidate)))))

(helm :sources '(some-helm-source))

搜索的时候是可以正常过滤,但是关键字没有高亮,不方便使用。 helm自带的命令可以正常高亮

在你的 Source 中加一个

(filtered-candidate-transformer . helm-fuzzy-highlight-matches)

能得到高亮。

但是现在 Helm 不推荐你手动构造这个 Alist,而是用 helm-build-sync-source 等,比如实现你的例子:

(helm :sources
      (helm-build-sync-source "Some Random Numbers"
        :candidates (lambda () (loop for i below 40 collect (random 100)))
        :action #'message))

更多的介绍可以参考:Developing · emacs-helm/helm Wiki · GitHub ,虽然这个介绍也并不详尽,但没有更权威的了。注意有些介绍手写 Alist 来构造 Helm Source 的教程是过时的。

恩,是的。后来试了一下,并看了一下源码,setq的source它是不加修饰直接用,而用helm-build-sync-source生成的,它会往source里面添加很多功能,包括高亮。不过默认不高亮有点意外,太基本的功能了