Last active
December 27, 2015 22:29
-
-
Save coldnew/7398845 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar emacs-english-font "Monaco" | |
"The font name of English.") | |
(defvar emacs-cjk-font "Hiragino Sans GB W3" | |
"The font name for CJK.") | |
(defvar emacs-font-size-pair '(15 . 18) | |
"Default font size pair for (english . chinese)") | |
(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) | |
(defvar emacs-font-size-pair-list | |
'(( 5 . 6) (10 . 12) | |
(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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you.