From 13f8919cf244d4a8f73d0bd3193f6434a0ad1a22 Mon Sep 17 00:00:00 2001 From: Peng Li Date: Sun, 30 Aug 2015 15:18:55 +0800 Subject: [PATCH] emacs : change chinese font --- emacs.d/config/init-base.el | 3 +- emacs.d/config/init-font.el | 71 +++++++++++++++++++++++++++++++++++++++++++++ emacs.d/init.el | 14 +++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 emacs.d/config/init-font.el diff --git a/emacs.d/config/init-base.el b/emacs.d/config/init-base.el index 5a4d64a..00fa25b 100644 --- a/emacs.d/config/init-base.el +++ b/emacs.d/config/init-base.el @@ -6,7 +6,8 @@ (add-to-list 'default-frame-alist '(width . 120)) (add-to-list 'default-frame-alist '(height . 40)) ;(add-to-list 'default-frame-alist '(font . "Source Code Pro for Powerline-12:weight:light" )) -(add-to-list 'default-frame-alist '(font . "Source Code Pro for Powerline-12" )) +;(add-to-list 'default-frame-alist '(font . "Source Code Pro for Powerline-12" )) + (setq inhibit-startup-message t) (put 'set-goal-column 'disabled nil) diff --git a/emacs.d/config/init-font.el b/emacs.d/config/init-font.el new file mode 100644 index 0000000..17bd23b --- /dev/null +++ b/emacs.d/config/init-font.el @@ -0,0 +1,71 @@ + +;; http://coldnew.github.io/blog/2013/11/16_d2f3a.html +(defvar emacs-english-font "Source Code Pro for Powerline" + "The font name of English.") + +(defvar emacs-cjk-font "Heiti SC" + "The font name for CJK.") + + +(defvar emacs-font-size-pair '(12 . 14) + "Default font size pair for (english . chinese)") + +(defvar emacs-font-size-pair-list + '(( 5 . 6) (10 . 12) (12 . 14) + (13 . 16) (15 . 18) (17 . 20) + (19 . 22) (20 . 24) (21 . 26) + (24 . 28) (26 . 32) (28 . 34) + (30 . 36) (34 . 40) (36 . 44)) + "This list is used to store matching (englis . chinese) font-size.") + + +(defun font-exist-p (fontname) + "Test if this font is exist or not." + (if (or (not fontname) (string= fontname "")) + nil + (if (not (x-list-fonts fontname)) nil t))) + +(defun set-font (english chinese size-pair) + "Setup emacs English and Chinese font on x window-system." + + (if (font-exist-p english) + (set-frame-font (format "%s:pixelsize=%d" english (car size-pair)) t)) + + (if (font-exist-p chinese) + (dolist (charset '(kana han symbol cjk-misc bopomofo)) + (set-fontset-font (frame-parameter nil 'font) charset + (font-spec :family chinese :size (cdr size-pair)))))) + + +;; Setup font size based on emacs-font-size-pair +(set-font emacs-english-font emacs-cjk-font emacs-font-size-pair) + + +(defun emacs-step-font-size (step) + "Increase/Decrease emacs's font size." + (let ((scale-steps emacs-font-size-pair-list)) + (if (< step 0) (setq scale-steps (reverse scale-steps))) + (setq emacs-font-size-pair + (or (cadr (member emacs-font-size-pair scale-steps)) + emacs-font-size-pair)) + (when emacs-font-size-pair + (message "emacs font size set to %.1f" (car emacs-font-size-pair)) + (set-font emacs-english-font emacs-cjk-font emacs-font-size-pair)))) + + +(defun increase-emacs-font-size () + "Decrease emacs's font-size acording emacs-font-size-pair-list." + (interactive) (emacs-step-font-size 1)) + +(defun decrease-emacs-font-size () + "Increase emacs's font-size acording emacs-font-size-pair-list." + (interactive) (emacs-step-font-size -1)) + + +(global-set-key (kbd "C-=") 'increase-emacs-font-size) +(global-set-key (kbd "C--") 'decrease-emacs-font-size) + + + + +(provide 'init-font) diff --git a/emacs.d/init.el b/emacs.d/init.el index 81553d2..c281acc 100644 --- a/emacs.d/init.el +++ b/emacs.d/init.el @@ -16,6 +16,7 @@ (global-set-key "\C-r" 'isearch-backward-regexp) (require 'init-base) +(require 'init-font) (require 'my-packages) @@ -120,3 +121,16 @@ (require 'init-org) (setq help-window-select t) + + + (add-to-list 'load-path "~/.emacs.d/site-lisp/eim") + (autoload 'eim-use-package "eim" "Another emacs input method") + + (register-input-method + "eim-wb" "euc-cn" 'eim-use-package + "五笔" "汉字五笔输入法" "~/.emacs.d/site-lisp/eim/wb.txt") + (register-input-method + "eim-py" "euc-cn" 'eim-use-package + "拼音" "汉字拼音输入法" "~/.emacs.d/site-lisp/eim/py.txt") + + -- 2.11.0