Function: use-cjk-char-width-table

use-cjk-char-width-table is a byte-compiled function defined in characters.el.gz.

Signature

(use-cjk-char-width-table LOCALE-NAME)

Source Code

;; Defined in /usr/src/emacs/lisp/international/characters.el.gz
;; Internal use only.
;; Setup char-width-table appropriate for a language environment
;; corresponding to LOCALE-NAME (symbol).

(defun use-cjk-char-width-table (locale-name)
  (while (char-table-parent char-width-table)
    (setq char-width-table (char-table-parent char-width-table)))
  (let ((slot (assq locale-name cjk-char-width-table-list)))
    (or slot (error "Unknown locale for CJK language environment: %s"
		    locale-name))
    (unless (nth 1 slot)
      (let ((table (make-char-table nil)))
	(dolist (charset-info (nthcdr 2 slot))
	  (let ((charset (car charset-info)))
	    (dolist (code-range (cdr charset-info))
              (map-charset-chars (lambda (range _arg)
                                   (set-char-table-range table range 2))
				 charset nil
				 (car code-range) (cdr code-range)))))
	(optimize-char-table table)
	(set-char-table-parent table char-width-table)
        (let ((tbl (make-char-table nil))
              (ambiguous-is-wide
               (and cjk-ambiguous-chars-are-wide
                    ;; MS-Windows Terminal forces all ambiguous
                    ;; characters to be narrow, even in CJK locales,
                    ;; assuming the fonts it uses were left at their
                    ;; defaults.
                    (not (and (eq system-type 'windows-nt)
                              ;; 'window-system' might be nil when this
                              ;; code is called from startup.el, as part
                              ;; of 'set-locale-environment', so we must
                              ;; test 'initial-window-system' instead.
                              (null initial-window-system)
                              (boundp 'w32--terminal-is-conhost)
                              (null w32--terminal-is-conhost))))))
          (map-char-table
           (lambda (range _val)
             (set-char-table-range
              tbl range
              (if ambiguous-is-wide 2 1)))
           ambiguous-width-chars)
          (optimize-char-table tbl)
          (set-char-table-parent tbl table)
	  (setcar (cdr slot) tbl))))
    (setq char-width-table (nth 1 slot))))