Git Product home page Git Product logo

chinese-wbim's Introduction

本项目说明

Deprecated!! 推荐使用 pyim, pyim 目前支持拼音和五笔输入,并且 pyim 可以跟 librime 配合一起输入,这样我们就可以在 Emacs 里面非常方便地使用五笔拼音输入法了。配置参考 https://emacs-china.org/t/mac-emacs-rime/10063/26

本项目 fork 至https://github.com/wenbinye/emacs-eim 因为作者很久都不更新了,所以 fork 过来维护。本项目的目的不是为了取代 Emacs-eim, 而是专注于改善 Emacs 中的五笔输入法。

后续开发计划 [25%]

  • [X] 添加 MELPA 支持
  • [ ] 重构代码,移除拼音输入法
  • [ ] 添加 popup 支持
  • [ ] 添加拼音五笔混合输入支持

特点

五笔

  1. 临时拼音输入汉字。用 z 开头可以输入汉字的拼音并查看其五笔字码。
  2. 反查五笔。用 M-x chinese-wbim-describe-char 可以查看光标处汉字的五笔字码。
  3. 加入自造词。M-x chinese-wbim-table-add-word,默认是光标前的两个汉字。用 C-a 和 C-e 调整。
  4. 可以保存选择的历史。

安装

如果有 make 命令,可以用 make 和 make install 命令安装。可以修改 PREFIX 使文件安装到指定位置。windows 下可以直接设置 ELISPDIR。 如果没有 make 命令,可以直接复制 EL 和 EXTRAFILES 到 load-path 里的目 录里,推荐是在 site-lisp/chinese-wbim 目录中。

在 .emacs 加入这几行就行了。五笔输入法要修改 chinese-wbim-wb-history-file 和 chinese-wbim-wb-user-file 的位置。chinese-wbim-wb-history-file 要修改成能保存的文件名即 可。chinese-wbim-wb-user-file 可以不修改,如果不改则使用默认的 mywb.txt。如果修 改则可以自己指定一个文件。文件格式参考 mywb.txt。

(autoload 'chinese-wbim-use-package "chinese-wbim" "Another emacs input method")
;; Tooltip 暂时还不好用
(setq chinese-wbim-use-tooltip nil)

(register-input-method
 "chinese-wbim" "euc-cn" 'chinese-wbim-use-package
 "五笔" "汉字五笔输入法" "wb.txt")

;; 用 ; 暂时输入英文
(require 'chinese-wbim-extra)
(global-set-key ";" 'chinese-wbim-insert-ascii)

;设置默认输入法
(setq default-input-method 'chinese-wbim)

注意,如果所有文件都在 load-path 里的某个目录中,就能找到(如果没有同名 文件的话),否则,请在文件或者配置中使用文件全名。

常用的按键:

按键功能
C-n向下翻页
C-p向上翻页
C-c取消输入
SPC确定输入
RET字母上屏

按键绑定可以用 C-h I(M-x describe-input-method) 查看。

其余无关文件

  • charpy.st 用 Storable 模块保存的汉字拼音列表
  • pychr.txt 原始的汉字拼音列表
  • pyword2tbl.pl 用于把词组文件转换成可用的词库的 perl 程序
  • sanguo.txt 一个测试文件
  • mergepy.pl 可以更新词库的程序。

详细说明一下 mergepy.pl 的用法。如果我发布一个新版本的拼音词库,要使用 这个词库又不想丢失自己词库里新造的词和词频信息,这时就可以用这个程序。 在命令行中用这样的命令:

$ perl mergepy.pl 自己的词库文件 新词库文件 -o py-new.txt

然后把自己的词库文件备份或者删除,把 py-new.txt 改名成 py.txt 就行了。

增加汉字

五笔输入法

对于五笔输入法,可以选择导入 chinese-wbim-wb-gbk,只要在 .emacs 里加上:

(setq chinese-wbim-wb-use-gbk t)

另一个选择是在 chinese-wbim-wb-user-file 里加上需要的汉字。这样基本上是够用的。 一般的输入 gbk 汉字是没有问题,因为 wb.txt 中已经加入了 fcitx 中所有的 gbk 汉字,只是如果需要造词时,不导入 gbk 汉字是无法自动造词的。

如何定制一个输入法

初级定制方法:

例如,要设置按键,可以这样:

(defun my-chinese-wbim-wb-activate-function ()
  (add-hook 'chinese-wbim-active-hook 
        (lambda ()
          (let ((map (chinese-wbim-mode-map)))
            (define-key map "-" 'chinese-wbim-previous-page)
            (define-key map "=" 'chinese-wbim-next-page)))))

然后要这样 register-input-method:

(register-input-method
 "chinese-wbim-wb" "euc-cn" 'chinese-wbim-use-package
 "五笔" "汉字五笔输入法" "wb.txt"
 'my-chinese-wbim-wb-activate-function)

或者这样:

(add-hook 'chinese-wbim-wb-load-hook
          (lambda ()
            (let ((map (chinese-wbim-mode-map)))
              (define-key map "-" 'chinese-wbim-previous-page)
              (define-key map "=" 'chinese-wbim-next-page))))

这样不需要再写一个函数。 拼音输入法是类似的。

对于五笔输入法,如果不想记录上次输入位置,设置 chinese-wbim-wb-history-file 为 nil。

高级定制方法:

  • chinese-wbim-use-package 可以接受两个参数,一个是 word-file,给出一个词库,一个

是 active-function,这个 active-function 是在每次切换时都要调用的。如果 想只在第一次启动输入法时调用一些命令,最好定义一个变量,在启动之后设置 为 t,或者加入到 chinese-wbim-load-hook 中。在调用这个命令时,chinese-wbim-current-package 可能还没有定义(第一次启动),这样,如果要修改或者使用 chinese-wbim-current-package 中的变量,就要用 chinese-wbim-load-hook 或者 chinese-wbim-active-hook 或者 chinese-wbim-active-function。chinese-wbim-load-hook 只在第一次启动输入法时调 用,chinese-wbim-active-function 和 chinese-wbim-active-hook 每次都要调用。一般来说,如果 要修改按键绑定,就加入到 chinese-wbim-load-hook 中。如果要修改 chinese-wbim-page-length 这样的局部变量,使用 chinese-wbim-active-function 或者 chinese-wbim-active-hook。 chinese-wbim-active-function 是为有专门的 lib 的输入法设计的,这样不用在 register-input-method 中加入一个 active-function。而 chinese-wbim-active-hook 是为用户定制设计的,这样不用专门写到一个文件中。设置 chinese-wbim-active-function 使用 chinese-wbim-set-active-function 函数。

  • chinese-wbim-stop-function:

这个函数是用于决定是否停止转换。比如五笔中可以设置当 chinese-wbim-current-key 大于 4 时就停止。默认是 nil,也就是说可以无限的输入。

  • chinese-wbim-translate-function:

当输入的字符是第一个字符(chinese-wbim-current-key 为空)时,如果不在 chinese-wbim-first-char 中,或者不是第一个字符,但是不在 chinese-wbim-total-char 中,会 停止转换。这时,会调用这个函数来处理最后一个输入字符。通常用这个函数来 输入标点。

  • chinese-wbim-add-completion-function:

通过这个函数来为当前的词条添加更多的选项。当往后翻页超出直接查找到的词 条时,会调用这个函数,如果添加结束,返回 t,还需要再添加返回 nil。 我写的五笔输入法用这个函数时是直接一次性加完。如果要每次添加几个的话, 一种办法就是在 chinese-wbim-current-choice 中加入一个新元素,记录这次搜索到哪个 位置。下次从这个位置继续,直到结束,比较麻烦。而且,一次加完的速度也很 快,就用简单的办法好了。

  • chinese-wbim-format-function:

chinese-wbim-current-choice 中的第一个元素是通常是一个字符串列表。但是也可以含 有 list。这时需要给出一个显示的函数。比如我在五笔输入法中搜索出可能的 单字或者输入拼音时显示五笔字根。 这个函数要接受四个参数,分别是当前输入的字符串 chinese-wbim-current-key, 当前页数,所有页数,这一页的选项。

  • chinese-wbim-handle-function:

这个函数是决定输入法行为的核心函数。通常要完成的任务是:

  1. 决定是否要继续转换。
  2. 设置 chinese-wbim-current-choice, chinese-wbim-current-pos, chinese-wbim-current-str, chinese-wbim-guidance-str, 最后调用 chinese-wbim-show 显示结果。通常如果 chinese-wbim-current-choice 的 CAR 不为空的话,就调用 chinese-wbim-format-page 显示。 如果为空,则设置相应的 chinese-wbim-current-str 和 chinese-wbim-guidance-str,调用 chinese-wbim-show 显示。

参考 chinese-wbim-wb 和 chinese-wbim-py 的写法。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.