https://github.com/abo-abo/swiper/issues/919
我给swiper提了这样一个issue。
据abo-abo的回复,这样搞定的:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 让`ivy-read'支持拼音
(require 'pinyinlib)
(defun re-builder-pinyin (str)
(or (pinyin-to-utf8 str)
(ivy--regex-plus str)
(ivy--regex-ignore-order)
))
(setq ivy-re-builders-alist
'(
(t . re-builder-pinyin)
))
(defun my-pinyinlib-build-regexp-string (str)
(progn
(cond ((equal str ".*")
".*")
(t
(pinyinlib-build-regexp-string str t))))
)
(defun my-pinyin-regexp-helper (str)
(cond ((equal str " ")
".*")
((equal str "")
nil)
(t
str)))
(defun pinyin-to-utf8 (str)
(cond ((equal 0 (length str))
nil)
((equal (substring str 0 1) "!")
(mapconcat 'my-pinyinlib-build-regexp-string
(remove nil (mapcar 'my-pinyin-regexp-helper (split-string
(replace-in-string str "!" "") "")))
""))
nil))
;; ;; ;;; 这样就可以去掉`pinyin'区配
;; (defun pinyin-to-utf8 (str)
;; nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
前提是需要安装 pinyinlib
这个库。
这样的话,使用ivy-read的函数可以这样来match拼音:
!nh
就可以match到“你好”。
以"!"开头就开启区配拼音。否则还和原来的功能一样。
可以不用切换输入法啦