EMT provides Han word boundaries for Emacs backed by jieba-rs.
It keeps the emt package name and a compatibility surface so existing configs
and downstream packages can migrate without a hard rename.
The package now integrates with Emacs’ find-word-boundary-function-table
instead of remapping only a handful of commands. In emt-mode, built-in word
motion commands such as forward-word, kill-word, mark-word, and
transpose-words become segmentation aware for Chinese text.
EMT focuses on Han text. It does not attempt to segment Japanese kana or Korean Hangul.
- Han-aware word motion via Emacs’ native word-boundary hook
- Buffer-local
emt-modeplus convenientglobal-emt-mode - Compatibility wrappers for callers that want EMT behavior without enabling the minor mode
- Per-buffer segmentation cache invalidated by
buffer-chars-modified-tick - Cross-platform dynamic module via Rust and jieba-rs
- Emacs 26.1 or later, built with dynamic module support
- An Emacs build that provides
find-word-boundary-function-tableforemt-mode - macOS, Linux, or Windows
If you call M-x emt-ensure and the module cannot be found, EMT offers to
download the pre-built binary release. The module is placed at emt-lib-path,
which defaults to ~/.emacs.d/modules/libemt_module.<suffix>.
Requires the Rust toolchain.
cd module
cargo build --release
cp target/release/libemt_module.dylib ~/.emacs.d/modules/libemt_module.dylib # macOS
# cp target/release/libemt_module.so ~/.emacs.d/modules/libemt_module.so # Linux(use-package emt
:straight (:host github :repo "LuciusChen/emt"
:files ("*.el"))
:config
(global-emt-mode 1))If non-nil, EMT caches segmentation results for contiguous Han runs in each buffer.
Path to the dynamic module.
Buffer-local mode that installs EMT’s word-boundary handlers for Han text while
preserving the buffer’s existing find-word-boundary-function-table entries for
other characters.
Enable emt-mode in most buffers.
(emt-segment "测试封装功能")
;; => [(0 . 2) (2 . 4) (4 . 6)]Returns a vector of relative word bounds.
Compatibility wrapper that returns a list of relative word bounds.
Returns absolute buffer bounds of the Han word at point, or nil.
Returns absolute buffer bounds of the Han word at point, preferring the next word when point is on a word boundary.
Returns absolute buffer bounds of the Han word at point, preferring the previous word when point is on a word boundary.
Returns the Han word at point, or the next one when point is on a boundary.
Returns the Han word at point, or the previous one when point is on a boundary.
Compatibility wrappers around built-in word motion using EMT’s boundary rules.
These work even if emt-mode is not enabled.
Compatibility wrappers built on top of EMT-aware word motion.
Load the dynamic module and verify the required entry points exist. When called interactively and the module is missing, EMT offers to download a pre-built release.
Download a pre-built module release. When installing to the default
emt-lib-path, the module is loaded immediately after download.
emt-modechanges how Emacs finds word boundaries; it does not remap commands.- Commands that bypass
forward-wordon purpose, such as code usingforward-word-strictlyor independent regexp logic, are outside EMT’s scope. - Compatibility wrappers remain available for downstream packages and scripts.
Dependabot watches jieba-rs in module/Cargo.toml and opens update pull
requests. After merging a dependency update, publish a new EMT release from
GitHub Actions:
- Open the
Releaseworkflow. - Run it from
main. - Enter the next package version without a leading
v, for example0.1.1.
The workflow updates the Elisp and Rust package versions, runs the module build
and ERT suite, commits the version bump, tags vX.Y.Z, builds release artifacts
for the supported platforms, and creates the GitHub release.
- The original roife/emt package established the
emtname and the idea of editor-side Chinese word segmentation. - This repository uses a different implementation: Rust module, jieba-rs backend, Emacs word-boundary integration, and buffer-local caching.
- The package keeps compatible entry points where practical so existing users and downstream packages do not need a flag day rename.