Advice 大法好。
从 https://github.com/abo-abo/swiper/commit/76fff20e6774f777787902030e9dcb528682078a 抄一个,face 效果不明显的话就换别的:
(defface helm-active-mode
'((t :inherit error))
"Face used by `helm-M-x' for activated modes."
:group 'helm-faces)
(define-advice helm-M-x-transformer-1
(:filter-return (candidates) highlight-enabled-mode)
(mapcar
(pcase-lambda (`(,text . ,cmd))
(let* ((sym (intern cmd))
(alias (symbol-function sym))
(key (where-is-internal (intern cmd) nil t)))
(cons
(if (or (eq sym major-mode)
(and
(memq sym minor-mode-list)
(boundp sym)
(buffer-local-value sym helm-current-buffer)))
(propertize text 'face 'helm-active-mode)
text)
cmd)))
candidates))
最好还给 helm 提个 pr,用 advice 又多迭代了一次,不环保。