Emacs in Rime, support multiple schemas.
Emacs 26.1+ with dynamic modules support, gcc
and make
.
emacs-rime will build dynamic module automatically.
sudo pacman -S librime
Check the version of librime-dev
in repositiory, if it’s older than 1.5.3, you need compile it from source.
sudo apt install git build-essential cmake libboost-all-dev libgoogle-glog-dev libleveldb-dev libmarisa-dev libopencc-dev libyaml-cpp-dev libgtest-dev
git clone https://github.com/rime/librime.git ~/.emacs.d/librime
cd ~/.emacs.d/librime
make
sudo make install
You can download the release.
wget https://github.com/rime/librime/releases/download/1.5.3/rime-1.5.3-osx.zip
unzip rime-1.5.3-osx.zip -d ~/.emacs.d/librime
rm -rf rime-1.5.3-osx.zip
(use-package rime
:custom
(default-input-method "rime"))
Use Straight
(use-package rime
:straight (rime :type git
:host github
:repo "DogLooksGood/emacs-rime"
:files ("*.el" "Makefile" "lib.c"))
:custom
(default-input-method "rime"))
Use Quelpa
(use-package rime
:quelpa (rime :fetcher github
:repo "DogLooksGood/emacs-rime"
:files ("*.el" "Makefile" "lib.c"))
:custom
(default-input-method "rime"))
NOTE: If you are on MacOS or don’t have librime in standard path,
you MUST specify rime-librime-root
.
Put following in the :custom
section.
(Assuming you unzip librime to ~/.emacs.d/librime)
(rime-librime-root "~/.emacs.d/librime/dist")
To activate Rime, use command toggle-input-method
which is bound to C-\
by default.
With following configuration, you can send a serials of keybindings to Rime. Since you may want them to help you with cursor navigation, candidate pagination and selection.
Currently the keybinding with Control(C-), Meta(M-) and Shift(S-) is supported.
;; defaults
(setq rime-translate-keybindings
'("C-f" "C-b" "C-n" "C-p" "C-g"))
Set via rime-show-candidate
.
Value | description |
---|---|
nil | don’t show candidate at all. |
minibuffer | Display in minibuffer. |
message | Display with message function, useful when you use minibuffer as mode-line. |
popup | Use popup. |
posframe | Use posfarme, will fallback to popup in TUI |
Assuming you use C-~
for the menu.
switcher:
caption: 〔方案選單〕
hotkeys:
- Control+grave
You can bind this key to rime-mode-map
with command rime-send-keybinding
.
(use-package
...
:bind
(:map rime-mode-map
("C-`" . 'rime-send-keybinding))
...
)
You can get a lighter via (rime-lighter)
, which returns you a colored ㄓ
.
Put it in modeline or anywhere you want.
You can customize with rime-title
, rime-indicator-face
and rime-indicator-dim-face
.
If you want specific a list of rules to automatically enable ascii mode, you can customize rime-disable-predicates
.
Following is a example to use ascii mode in evil-normal-state
or when cursor is after alphabet character or when cursor is in code.
(setq rime-disable-predicates
'(rime-predicate-evil-mode-p
rime-predicate-after-alphabet-char-p
rime-predicate-prog-in-code-p))
Built-in Predicate Functions
rime-predicate-after-alphabet-char-p
After an alphabet character (must beginning with letter [a-zA-Z]).
rime-predicate-after-ascii-char-p
After any alphabet character.
rime-predicate-prog-in-code-p
On
prog-mode
andconf-mode
, not in comments and quotes.rime-predicate-evil-mode-p
In the non-editing state of
evil-mode
.rime-predicate-current-input-punctuation-p
When entering punctuation.
rime-predicate-punctuation-after-space-cc-p
When entering punctuation after a Chinese character appended with whitespaces.
rime-predicate-punctuation-after-ascii-p
When entering punctuation after an ascii character.
rime-predicate-punctuation-line-begin-p
When entering punctuation at the beginning of the line.
rime-predicate-space-after-ascii-p
After an ascii character appended with whitespaces.
rime-predicate-space-after-cc-p
After a Chinese character appended with whitespaces.
rime-predicate-current-uppercase-letter-p
When entering a uppercase letter.
If one of rime-disable-predicates
returns t, you can still force enable the input method with rime-force-enable
.
The effect will only last for one input behavior.
You probably want to give this command a keybinding.
Default to |
, you can customize it with
(setq rime-cursor "˰")
Use rime-open-configuration
.
How to get Emacs with dynamic module support?
- **Linux**
Emacs included in major linux distributions has dynamic module support enabled by default.
- **MacOS**
emacs-plus
enables dynamic modules support by default. homebrew installation:
brew tap d12frosted/emacs-plus
brew install emacs-plus
When installing emacs-mac
, you need to add --with-modules
option. homebrew installation:
brew tap railwaycat/emacsmacport
brew install emacs-mac --with-modules
- **Compile Emacs 26 manually**
Use --with-modules
option.
Can’t find rime_api.h when compile
You MUST specify rime-librime-root
in this case.
Check Installation for how to set.
Can’t find emacs-module.h when compile
If you build Emacs by yourself and does not install to standard location,
you MUST specify rime-emacs-module-header-root
.
Put following in the :custom
section.
(Assuming you install Emacs to ~/emacs)
(rime-emacs-module-header-root "~/emacs/include")
How to show dynamic ~rime-lighter~ logo in ~doom-modeline~ ?
We need to redefine segment of input-method
, to change it’s face properties.
And then, we also need to modify the properties of rime-indicator-face
and
rime-indicator-dim-face
, to be same as the color style of doome-modeline
.
(after! doom-modeline
(set-face-attribute 'rime-indicator-face nil
:foreground 'unspecified
:inherit 'doom-modeline-buffer-major-mode)
(set-face-attribute 'rime-indicator-dim-face nil
:foreground 'unspecified
:inherit 'doom-modeline-buffer-minor-mode)
(doom-modeline-def-segment input-method
"Define the current input method properties."
(propertize (cond (current-input-method
(concat (doom-modeline-spc)
current-input-method-title
(doom-modeline-spc)))
((and (bound-and-true-p evil-local-mode)
(bound-and-true-p evil-input-method))
(concat
(doom-modeline-spc)
(nth 3 (assoc default-input-method input-method-alist))
(doom-modeline-spc)))
(t ""))
'face (if (doom-modeline--active)
(or (get-text-property 0 'face (rime-lighter))
'doom-modeline-buffer-major-mode)
'mode-line-inactive)
'help-echo (concat
"Current input method: "
current-input-method
"\n\
mouse-2: Disable input method\n\
mouse-3: Describe current input method")
'mouse-face 'mode-line-highlight
'local-map mode-line-input-method-map)))
The last item of the candidate box is not displayed?
Few users occasionally have a issue that the last candidate word is not displayed. It can be determined that this is related to `posframe`, but the reason has not been found. A temporary solution is to append a full-width whitespace to the end of the candidate list.
(defun +rime--posframe-display-content-a (args)
"Append a full-width whitespace to the input string.
This can temporarily solve the problem of `posframe` occasionally
\"eating\" words."
(cl-destructuring-bind (content) args
(let ((newresult (if (string-blank-p content)
content
(concat content " "))))
(list newresult))))
(if (fboundp 'rime--posframe-display-content)
(advice-add 'rime--posframe-display-content
:filter-args
#'+rime--posframe-display-content-a)
(error "Function `rime--posframe-display-content' is not available."))