Giter Site home page Giter Site logo

emacs-rime's Introduction

Emacs Rime

https://melpa.org/packages/rime-badge.svg

中文文档(目前更加完善)

https://i.imgur.com/jHpk7BT.gif

Emacs in Rime, support multiple schemas.

Installation & How to use

Requirements

Emacs 26.1+ with dynamic modules support, gcc and make.

emacs-rime will build dynamic module automatically.

Install librime

Linux

ArchLinux/Manjaro

sudo pacman -S librime

Debian/Ubuntu

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

MacOS

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

Minimal configuration

(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")

Activate input method

To activate Rime, use command toggle-input-method which is bound to C-\ by default.

Keybindings in Rime.

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"))

Candidate menu style

Set via rime-show-candidate.

Valuedescription
nildon’t show candidate at all.
minibufferDisplay in minibuffer.
messageDisplay with message function, useful when you use minibuffer as mode-line.
popupUse popup.
posframeUse posfarme, will fallback to popup in TUI

Open Rime menu

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

The lighter

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.

Temporarily ascii mode

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

Force enable

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.

The soft cursor

Default to | , you can customize it with

(setq rime-cursor "˰")

Shortcut to open Rime configuration file

Use rime-open-configuration.

FAQ

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."))
Want a pure emacs input method without `librime`?

Maybe, you need pyim.

Thanks for all the contributors

emacs-rime's People

Contributors

chuxubank avatar cnsunyour avatar con5tella avatar doglooksgood avatar jixiuf avatar longminwang avatar shuxiao9058 avatar wsw0108 avatar z572 avatar

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.