From d5d4453125e965a5f992712ea735238b27a8d571 Mon Sep 17 00:00:00 2001 From: andyque Date: Sat, 27 Jun 2015 23:12:43 +0800 Subject: [PATCH] Add Chinese layer to spacemacs. --- contrib/chinese/README.org | 70 ++++++++++++++++++++++++++++ contrib/chinese/config.el | 29 ++++++++++++ contrib/chinese/img/China.png | Bin 0 -> 1529 bytes contrib/chinese/img/Chinese.png | Bin 0 -> 4877 bytes contrib/chinese/packages.el | 80 ++++++++++++++++++++++++++++++++ 5 files changed, 179 insertions(+) create mode 100644 contrib/chinese/README.org create mode 100644 contrib/chinese/config.el create mode 100644 contrib/chinese/img/China.png create mode 100644 contrib/chinese/img/Chinese.png create mode 100644 contrib/chinese/packages.el 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 0000000000000000000000000000000000000000..a2c4ea26996ffeab2a12a5b5ea1874796dfc7e45 GIT binary patch literal 1529 zcmVp5ZxIN|L6e!-2nX21Nz1V^sWf;oeAoB z4CGY~-!2gEl?v{X3g9;n=W7k~stEnl1OC_n?1T&9KM(e_2j^!E=3ouuP7dsc3+QhR z`p5<1Mi26(3FTZ4>wXOR!3FJ%3-Fr>cc5|>000FrNkllYp4!oN1ru9=UYAJH6mRkVhpQ`aB`)kz)&{ws}a12;keQxk&&x~E>5vj(;M6(tN!k*W)#M1BFxTJw3ULFWMYcNf2&&Zs235CK#+1X*E7>Ak;f#ccs`+%F#GctPlic@9Y_%qv8s?fign{` zJMvJ^VWR03S)|VCuC717|Lko<#$mo2*{bLE!Kl^zYI7bY_O`A*ZEjxg1w~B)BS=xB zH?)R9k$Pu1`6Bq_>t{l&?=OJmc0HKI`DD&pbqq>_&4Y^|+$UQ7KUEm1G-VSTlsFBA zY1OhpQT;>c8WJ;LPS5=~8HWjL>?fm6EvFvI-i*^w;Ze_V<4A5pKB9KWC|%2OV$o&F z{~QuCQ_jy^3(>D*CHX|@nfXIRh;=fl~uQ+o{MCi@A8L`dD$-Ai;!4!5#21c;h|s43H2dVqj{sKkYS19>K`?~Ra5G@ zx_uPdzA;XOH@hH}&|Bq%w`<>O{Ds@869m6GCUkUr-kJa6D@VXNccAU2vE2v{nS}p{%@WUJEsm$mz1r-VyN(4*@rG0rb@y+ zosZNpZEYX2-j0iLQ~HG))fHYGix#OvcsFb2B^~9f!f;9Z}uk$8G4vWoeXbaLgambAJ7PWduK;5nV>OcG%d~ji$UR0(779GRdQp^VtaD z>sqg=<q8++uCP(Pd)5ak z(u5Ajn0GUBD^K08T9_7Ml9SPB&$LPiZz3i+J3!2Mn8bw45R(Gk@qmY<+QFEwbheF4 zT0Ou2(?=O|dcnBTU>PfmoxrMr3Bz<`V}i8F$UQwKjCwJ`k9R8`Auk|o=6+K6TSyuD{2#Zf zQLlb{>)@eKO#lD@00000000000000000000000000000000000000000000000000 f000000N~PpPdYjY0_!KX00000NkvXXu0mjfETrZA literal 0 HcmV?d00001 diff --git a/contrib/chinese/img/Chinese.png b/contrib/chinese/img/Chinese.png new file mode 100644 index 0000000000000000000000000000000000000000..5ac390c29c267c835e9c785c67f72d7f94260b0a GIT binary patch literal 4877 zcmV+o6Y}hdP)004{#0{{R3%zsi+0001rP)t-s|Ns90 z000^q8Wh|{b-QC^8!^6wV z%Oxcxn3$Nnyu3$8M>se*)6>)L?(SY*UbVHgii(O~UtipK~#90?ObWMqPi08 z1W1@=24#?W6950-dlhg*RP^+{eb-yPKlD0%j>Jk*!>&q&U%x(qy461V{J)OC%M0UA z3-Jm@j!+pTe_D*^P!9-;LNEVmIj&F>!1nroN5YsWe@>nUsIaH@F5H~|Ux^r_=ub*C zhl?hnu57rQx7ZFxKKDw!u8$Yo+z~A4_0xAQx0PRQJ#n}mEH0n3)q(elh6;A|7>L`qLPvq zFP3=1<_J?IcQaKxM0al2dcMseiNK$E!eQI1JM)9EXZ53m)xw_)r?DxFi!l}Bw~LtM zFc8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yUH^)ZVeFRY5S ze%fK(^$VAR8`v?4^1OIuBfS0UENgE+d0Pa~O)o0KDKTVk`}hoykStw{gk+vxCY?o2 zF|a!jFK698Q2-gC?k5MG4qB}HMX1q}B+>Ql_M24p7X9b+JztBpXt|MHS7NY1_({cRHGXX00000NkvXXu0mjfHV +;; 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))))