因为自己很多古文相关文件都是繁体中文,请教各位,buffer切换时如何实现用拼音首字母命中繁体中文文件,谢谢!
方法签名里有啊:
(defun pinyinlib-build-regexp-string
(str &optional no-punc-p tranditional-p only-chinese-p mixed-p)
;; The first parameter `char' is the letter to be converted. The latter
;; four parameters are optional.
;; - If `no-punc-p' is `t': it will not convert English punctuations to
;; Chinese punctuations.
;; - If `traditional-p' is `t': traditional Chinese characters are used
;; instead of simplified Chinese characters.
;; - If `only-chinese-p' is `t': the resulting regular expression doesn't
;; contain the English letter `char'.
;; - If `mixed-p' is `t': the resulting regular expression will mix
;; traditional and simplified Chinese characters. This parameter will take
;; precedence over `traditional-p'.
如果你用的是 consult-buffer 切换的话,可以用 advice 定制,类似这样的:
(defun completion--regex-pinyin (str)
(orderless-regexp (pinyinlib-build-regexp-string str nil t nil t))) ;;; 改这里
(defun advice--regexp-pinyin (func &rest args)
(add-to-list 'orderless-matching-styles #'completion--regex-pinyin)
(let ((result (apply func args)))
(setq orderless-matching-styles
(delete 'completion--regex-pinyin orderless-matching-styles))
result))
(advice-add 'consult-buffer :around #'advice--regexp-pinyin)
1 个赞
谢谢回复,可以了。