Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

emt.el

Introduction

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.

Features

  • Han-aware word motion via Emacs’ native word-boundary hook
  • Buffer-local emt-mode plus convenient global-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

Installation

Requirements

  • Emacs 26.1 or later, built with dynamic module support
  • An Emacs build that provides find-word-boundary-function-table for emt-mode
  • macOS, Linux, or Windows

Dynamic module

Pre-built

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>.

Build from source

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

Install package

(use-package emt
  :straight (:host github :repo "LuciusChen/emt"
                   :files ("*.el"))
  :config
  (global-emt-mode 1))

Customization

emt-use-cache

If non-nil, EMT caches segmentation results for contiguous Han runs in each buffer.

emt-lib-path

Path to the dynamic module.

Usage

Minor modes

emt-mode

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.

global-emt-mode

Enable emt-mode in most buffers.

Public API

emt-segment

(emt-segment "测试封装功能")
;; => [(0 . 2) (2 . 4) (4 . 6)]

Returns a vector of relative word bounds.

emt-split

Compatibility wrapper that returns a list of relative word bounds.

emt-bounds-at-point

Returns absolute buffer bounds of the Han word at point, or nil.

emt-bounds-at-point-or-forward

Returns absolute buffer bounds of the Han word at point, preferring the next word when point is on a word boundary.

emt-bounds-at-point-or-backward

Returns absolute buffer bounds of the Han word at point, preferring the previous word when point is on a word boundary.

emt-word-at-point-or-forward

Returns the Han word at point, or the next one when point is on a boundary.

emt-word-at-point-or-backward

Returns the Han word at point, or the previous one when point is on a boundary.

emt-forward-word / emt-backward-word

Compatibility wrappers around built-in word motion using EMT’s boundary rules. These work even if emt-mode is not enabled.

emt-kill-word / emt-backward-kill-word / emt-mark-word

Compatibility wrappers built on top of EMT-aware word motion.

emt-ensure

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.

emt-download-module

Download a pre-built module release. When installing to the default emt-lib-path, the module is loaded immediately after download.

Notes

  • emt-mode changes how Emacs finds word boundaries; it does not remap commands.
  • Commands that bypass forward-word on purpose, such as code using forward-word-strictly or independent regexp logic, are outside EMT’s scope.
  • Compatibility wrappers remain available for downstream packages and scripts.

Release Process

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:

  1. Open the Release workflow.
  2. Run it from main.
  3. Enter the next package version without a leading v, for example 0.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.

Relation To EMT

  • The original roife/emt package established the emt name 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.

Acknowledgements

  • roife/emt: the original project that established the EMT package name
  • jieba-rs: the segmentation backend used by the Rust module

About

Han word boundaries for Emacs via jieba-rs.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages