pastebin

Private paste #81654: Untitled XML/HTML paste by 61.48.45.84

;;
;; language.el
;;
;; Last modified time
;; Time-stamp: <esun 03/10/2011 1802M02S>
;;

;;方案1
;;(set-default-font "Monospace-10")
;;(set-fontset-font "fontset-default"
;;                  'han '("Microsoft YaHei" . "unicode-bmp"))


;;方案2
;; (set-face-attribute
;;   'default nil :font "Sans 11")
 
;; (dolist (charset '(kana han symbol cjk-misc bopomofo))
;;     (set-fontset-font (frame-parameter nil 'font)
;;                       charset
;;                       (font-spec :family "WenQuanYi Micro Hei Mono"
:size 16)))

;;
;; 方案3
比较复杂的版本,能自动设置字体
;;

;;判断某个字体在系统中是否安装:
(defun esun-font-existsp (font)
  (if (null (x-list-fonts font))
      nil t))

;;按顺序找到一个字体列表(
list )
中第一个已经安装可用的字体
(defvar font-list '("Microsoft Yahei"
"文泉驿等宽微米黑"
"新宋体" "宋体"))
(require 'cl) ;; find-if is in common list package
(find-if #'esun-font-existsp font-list)

;;辅助函数,用来产生带上
font size 信息的 font
描述文本
;;这里绕的地方是,如果传入的
font-size
是“:pixelsize=18”这样的话,字体名称和它
;;之间不能有空格。如果是普通的数字的话(
12或“12”),需要有个空格分隔字体名称和
;;字体大小。
(defun esun-make-font-string (font-name font-size)
  (if (and (stringp font-size) 
           (equal ":" (string (elt font-size 0))))
      (format "%s%s" font-name font-size)
    (format "%s %s" font-name font-size)))

;;自动设置字体函数
(defun esun-set-font (english-fonts
                       english-font-size
                       chinese-fonts
                       &optional chinese-font-size)
  "english-font-size could be set to \":pixelsize=18\" or a integer.
If set/leave chinese-font-size to nil, it will follow
english-font-size"
  (require 'cl)                         ; for find if
  (let ((en-font (esun-make-font-string
                  (find-if #'esun-font-existsp english-fonts)
                  english-font-size))
        (zh-font (font-spec :family (find-if #'esun-font-existsp
chinese-fonts)
                            :size chinese-font-size)))
 
    ;; Set the default English font
    ;; 
    ;; The following 2 method cannot make the font settig work in new
frames.
    ;; (set-default-font "Consolas:pixelsize=18")
    ;; (add-to-list 'default-frame-alist '(font .
"Consolas:pixelsize=18"))
    ;; We have to use set-face-attribute
    (message "Set English Font to %s" en-font)
    (set-face-attribute
     'default nil :font en-font)
 
    ;; Set Chinese font 
    ;; Do not use 'unicode charset, it will cause the english font
setting invalid
    (message "Set Chinese Font to %s" zh-font)
    (dolist (charset '(kana han symbol cjk-misc bopomofo))
      (set-fontset-font (frame-parameter nil 'font)
                        charset
                        zh-font))))

(esun-set-font
 '("Monaco" "Consolas"  "DejaVu Sans Mono" "Monospace" "Courier New")
"11"
 '("ZhunYuan" "Microsoft Yahei"
"文泉驿等宽微米黑"
"新宋体"))

;;
;; end
;;

(provide 'language)

Private
Wrap long lines

2 + 1 =