diff --git a/contrib/chinese/README.org b/contrib/chinese/README.org new file mode 100644 index 000000000..1dc80e9e4 --- /dev/null +++ b/contrib/chinese/README.org @@ -0,0 +1,70 @@ +#+TITLE: Chinese contribution layer for Spacemacs +[[file:img/China.png]] [[file:img/Chinese.png]] + + +* Table of Contents :TOC@4: + - [[#description][Description]] + - [[#install][Install]] + - [[#layer][Layer]] + - [[#configuration][Configuration]] + - [[#configure-the-default-input-method配置默认中文输入法][Configure the Default Input Method(配置默认中文输入法)]] + - [[#configure-the-chinese-pyim-input-method配置中文拼音输入法][Configure the =Chinese-pyim= Input Method(配置中文拼音输入法)]] + - [[#set-monospaced-font-size设置等宽字体)][Set monospaced font size(设置等宽字体)]] + - [[#key-bindings][Key Bindings]] + - [[#youdao-dictionrary][Youdao Dictionrary]] + - [[#find-by-pinyin-dired][Find-by-pinyin-dired]] + +* Description +This Layer adds Chinese related packages: +- [[https://github.com/tumashu/chinese-pyim][chinese-pyim]] : The best Chinese Pinyin(拼音) input method. +- [[https://github.com/andyque/chinese-wbim][chinese-wbim]]: The best Chinese Wubi(五笔) input method. +- [[https://github.com/xuchunyang/youdao-dictionary.el][youdao-dictionary]]: The Youdao(有道) Dictionary interface for Emacs. +- [[https://github.com/redguardtoo/find-by-pinyin-dired][find-by-pinyin-dired]]: Find file by first Pinyin characters of Chinese Hanzi. +- [[https://github.com/cute-jumper/ace-pinyin][ace-pinyin]]: Jump to Chinese character by pinyin with `ace-jump-mode'. + + +* Install +** Layer +To use this contribution add it to your =~/.spacemacs= + +#+BEGIN_SRC emacs-lisp + (setq-default dotspacemacs-configuration-layers '(chinese)) +#+END_SRC +** Configuration +*** Configure the Default Input Method(配置默认中文输入法) +The default Chinese input method is =Chinese-pyim=, if you are a Wubi(五笔) user, +you could set the variable `chinese-default-input-method` to 'wubi: +#+begin_src emacs-lisp + (setq-default dotspacemacs-configuration-layers '( + (chinese :variables chinese-default-input-method 'wubi))) +#+end_src +*** Configure the =Chinese-pyim= Input Method(配置中文拼音输入法) +When the first time you use =Chinese-pyim=, you should install the lexicon(词库) file. +You could call =pyim-dicts-manager= to open up the settings buffer and press =i e= to install the default lexicon. +The lexicon is about 20M, so you should be patient when downloading starts. +After the lexicon file is downloaded, just press =s= to save and =R= to restart configuration. +*** Set monospaced font size(设置等宽字体) +If you are mixing Chinese words with English words, the text is not perfectly aligned in org table. +That's because normally the Chinese font size is not equal to the English font size. +You could call =spacemacs//set-monospaced-font= with your own Chinese font name in =dotspacemacs/config= function. + +Example configuration: +#+begin_src emacs-lisp +;;Note: The Hiragino Sans GB is bundled with MacOS X. +;;If you are not using MacOS X, you should change it to another Chinese font name. +(spacemacs//set-monospaced-font "Source Code Pro" "Hiragino Sans GB" 14 16) +#+end_src + + + +* Key Bindings +Currently, there are no built-in key bindings for this layer. You could define your own preference. + +Here are a few suggested key bindings: + +** Youdao Dictionrary +Bind ~ o y~ to =youdao-dictionary-search-at-point+=. + +** Find-by-pinyin-dired +Bind ~ o d~ to =find-by-pinyin-dired= + diff --git a/contrib/chinese/config.el b/contrib/chinese/config.el new file mode 100644 index 000000000..1e9c389f7 --- /dev/null +++ b/contrib/chinese/config.el @@ -0,0 +1,29 @@ +;;; config.el --- Colors Layer configuration File for Spacemacs +;; +;; Copyright (c) 2012-2014 Sylvain Benner +;; Copyright (c) 2014-2015 Sylvain Benner & Contributors +;; +;; Author: Sylvain Benner +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +;; Variables + +(defvar chinese-default-input-method 'pinyin + "The default chiense input method. Can be `wubi` or `pinyin`.") + +;; Set the monospaced font size when mixed Chinese and English words +(defun spacemacs//set-monospaced-font (english chinese english-size chinese-size) + (set-face-attribute 'default nil :font + (format "%s:pixelsize=%d" english english-size)) + (dolist (charset '(kana han symbol cjk-misc bopomofo)) + (set-fontset-font (frame-parameter nil 'font) charset + (font-spec :family chinese :size chinese-size)))) + +;; If the Hiragino Sans GB font is not found in your system, you could call this +;; method in dotspacemacs/config function with a different Chinese font name. +(if (system-is-mac) + (spacemacs//set-monospaced-font "Source Code Pro" "Hiragino Sans GB" 14 16)) diff --git a/contrib/chinese/img/China.png b/contrib/chinese/img/China.png new file mode 100644 index 000000000..a2c4ea269 Binary files /dev/null and b/contrib/chinese/img/China.png differ diff --git a/contrib/chinese/img/Chinese.png b/contrib/chinese/img/Chinese.png new file mode 100644 index 000000000..5ac390c29 Binary files /dev/null and b/contrib/chinese/img/Chinese.png differ diff --git a/contrib/chinese/packages.el b/contrib/chinese/packages.el new file mode 100644 index 000000000..ca61be55a --- /dev/null +++ b/contrib/chinese/packages.el @@ -0,0 +1,80 @@ +;;; packages.el --- chinese Layer packages File for Spacemacs +;; +;; Copyright (c) 2012-2014 Sylvain Benner +;; Copyright (c) 2014-2015 Sylvain Benner & Contributors +;; +;; Author: Sylvain Benner +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + +;; List of all packages to install and/or initialize. Built-in packages +;; which require an initialization must be listed explicitly in the list. +(setq chinese-packages + '( + youdao-dictionary + chinese-pyim + find-by-pinyin-dired + ace-pinyin + chinese-wbim + )) + +(defun chinese/init-chinese-wbim () + "Initialize chinese-wubi" + (use-package chinese-wbim + :if (eq 'wubi chinese-default-input-method) + :init + (progn + (autoload 'chinese-wbim-use-package "chinese-wubi" "Another emacs input method") + ;; Tooptip is not good enough, so disable it here. + (setq chinese-wbim-use-tooltip nil) + + (register-input-method + "chinese-wubi" "euc-cn" 'chinese-wbim-use-package + "五笔" "汉字五笔输入法" "wb.txt") + (require 'chinese-wbim-extra) + (global-set-key ";" 'chinese-wbim-insert-ascii) + (setq default-input-method 'chinese-wubi) + ))) + +(defun chinese/init-youdao-dictionary () + (use-package youdao-dictionary + :config + (progn + ;; Enable Cache + (setq url-automatic-caching t) + + ;; Set file path for saving search history + (setq youdao-dictionary-search-history-file (concat spacemacs-cache-directory ".youdao")) + + ;; Enable Chinese word segmentation support + (setq youdao-dictionary-use-chinese-word-segmentation t) + ))) + +(defun chinese/init-chinese-pyim () + (use-package chinese-pyim + :if (eq 'pinyin chinese-default-input-method) + :init + (progn + (setq pyim-use-tooltip t) + (setq pyim-dicts-directory spacemacs-cache-directory) + (setq pyim-personal-file (concat spacemacs-cache-directory "pyim-personal.txt")) + (setq default-input-method "chinese-pyim") + (evilify pyim-dicts-manager-mode pyim-dicts-manager-mode-map) + ))) + + +(defun chinese/init-find-by-pinyin-dired () + (use-package find-by-pinyin-dired + :defer t + )) + +(defun chinese/init-ace-pinyin () + (use-package ace-pinyin + :defer t + :init + (progn + (ace-pinyin-global-mode t) + (spacemacs|hide-lighter ace-pinyin-mode))))