tumashu / pyim

一个 emacs 中文输入法,支持全拼,双拼,五笔,仓颉和Rime,pyim 是 GNU elpa 包。
888 stars 93 forks source link

[FR] Display how to type each candidate in default scheme, when assistant scheme is enabled #471

Closed RuijieYu closed 1 year ago

RuijieYu commented 1 year ago

For example, when I have this setup:

(setopt pyim-default-scheme 'wubi
        pyim-assistant-scheme 'pinyin)

And when I enable assistant scheme via TAB, I want to be able to see how to type a candidate in wubi when I use pinyin to type it.

This feature, if implemented, should be locked behind an opt-in defcustom, because it takes space to display this information, and the user might need to adjust the number of displayed candidates accordingly, especially when the candidates are displayed in minibuffer.

This proposed feature is in the same vein as the assistant scheme itself, for people who are still unfamiliar with the default scheme and need additional help using the assistant scheme.

RuijieYu commented 1 year ago

Actually, this might already be the case, but only for the currently selected candidate. I see this between the input key and the list of candidates. Am I understanding it correctly?

If so, maybe this issue can be closed, thanks.

tumashu commented 1 year ago

yes, this feature is controled by the below code

(cl-defgeneric pyim-page-preview-create (scheme &optional separator)
  "这个函数用于创建在 page 中显示的预览字符串。

这个预览是在 page 中显示,而 `pyim-preview--refresh' 对应的预览
是在 buffer 光标处显示,两者要做区别。")

(cl-defmethod pyim-page-preview-create ((_scheme pyim-scheme-quanpin) &optional separator)
  (let* ((separator (or separator " "))
         (translated (string-join (mapcar (lambda (w)
                                            (concat (nth 0 w) (nth 1 w)))
                                          (pyim-process-get-first-imobj))
                                  separator)))
    (concat
     ;; | 显示光标位置的字符
     (pyim-process-with-entered-buffer
       (if (equal 1 (point))
           (concat "|" translated)
         (concat (replace-regexp-in-string (concat separator "'") "'" translated)
                 " |" (buffer-substring-no-properties (point) (point-max)))))
     ;; 使用辅助输入法时,在 page 中提示默认输入法的 code, 这个功能对形码用户挺
     ;; 有用。
     (pyim-page--code-hint-of-default-scheme))))

(defun pyim-page--code-hint-of-default-scheme ()
  "获取当前词条在默认输入法下的 code 提示."
  (when (pyim-scheme-assistant-enable-p)
    (let* ((word (nth (pyim-process-word-position)
                      (pyim-process-get-candidates)))
           (codes (sort (pyim-cstring-to-codes
                         word (pyim-scheme-get pyim-default-scheme))
                        (lambda (a b)
                          (< (length a) (length b)))))
           (hint (string-join codes " ")))
      (if (> (length hint) 0)
          (format " [%s]" hint)
        " "))))
RuijieYu commented 1 year ago

Thanks. Closing, since the requested feature is already in place.