Skip to content

Latest commit

 

History

History
316 lines (218 loc) · 9.4 KB

README_EN.org

File metadata and controls

316 lines (218 loc) · 9.4 KB

Emacs Rime

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

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

Emacs in Rime, support multiple schemas.

Installation & How to use

Check Intallation.

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" "<left>" "<right>" "<up>" "<down>" "<prior>" "<next>" "<delete>"))

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-in-code-string-p

    In the code string(not comment string).

  • rime-predicate-evil-mode-p

    In the non-editing state of evil-mode.

  • rime-predicate-ace-window-p

    If the ace-window-mode is activated.

  • rime-predicate-hydra-p

    If a hydra keymap is activated.

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

  • rime-predicate-tex-math-or-command-p

    When inside a (La)TeX math environment or entering a (La)TeX command.

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

How to integrate this with evil-escape?

The following code may have performance issue

Add the following code snippet in your configuration files, then you can use evil-escape to return to normal state when having nothing in editing(no preedit overlay).

 (defun rime-evil-escape-advice (orig-fun key)
   "advice for `rime-input-method' to make it work together with `evil-escape'.
	Mainly modified from `evil-escape-pre-command-hook'"
   (if rime--preedit-overlay
	;; if `rime--preedit-overlay' is non-nil, then we are editing something, do not abort
	(apply orig-fun (list key))
     (when (featurep 'evil-escape)
	(let* (
	       (fkey (elt evil-escape-key-sequence 0))
	       (skey (elt evil-escape-key-sequence 1))
	       (evt (read-event nil nil evil-escape-delay))
	       )
	  (cond
	   ((and (characterp evt)
		 (or (and (char-equal key fkey) (char-equal evt skey))
		     (and evil-escape-unordered-key-sequence
			  (char-equal key skey) (char-equal evt fkey))))
	    (evil-repeat-stop)
	    (evil-normal-state))
	   ((null evt) (apply orig-fun (list key)))
	   (t
	    (apply orig-fun (list key))
	    (if (numberp evt)
		(apply orig-fun (list evt))
	      (setq unread-command-events (append unread-command-events (list evt))))))))))

 (advice-add 'rime-input-method :around #'rime-evil-escape-advice)

Thanks for all the contributors