bug#81489: 32.0.50; w32--terminal-is-conhost is nil in gui emacs.

Eli Zaretskii <[email protected]> Thu, 30 Jul 2026 10:15:46 +0300
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> From: TAKAHASHI Yoshio <[email protected]>
> Cc: [email protected]
> Date: Thu, 30 Jul 2026 15:40:02 +0900
> 
> TAKAHASHI Yoshio <[email protected]> writes:
> 
> >> I wonder why this doesn't work for you during startup.  Perhaps you
> >> could look at the relevant codes and try figuring this out?  There's
> >> probably something I'm missing here, but what?
> >
> > These call flows are in loadup.el, and not in individual emacs startup???
> 
> This is my minunderstanding, sorry.

Yes, this happens in startup.el, not loadup.el, so it happens every
time Emacs is started.

> I did "print debug" ;-)
> I add "!!!!!" line in function u-c-c-w-table.
> 
> (defun use-cjk-char-width-table (locale-name)
>   (print (format "use-cjk-char-width-table %s" locale-name)) ; !!!!!
>   (print (format "cjk-ambiguous-chars-are-wide %s" cjk-ambiguous-chars-are-wide)) ; !!!!!
>   (print (format "window-system %s" (window-system))) ; !!!!!
>   (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))
>     (print (format "slot %s" slot)) ; !!!!!
>     (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.
>                     (not (and (null (window-system))
>                               (boundp 'w32--terminal-is-conhost)
>                               (null w32--terminal-is-conhost))))))
>           (print (format "ambiguous-is-wide %s" ambiguous-is-wide)) ; !!!!!
>           (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))))
> 
> 
> emacs -Q -l ./a.el *scrach* buffer is
> --8<---------------cut here---------------start------------->8---
> 
> "use-cjk-char-width-table ja_JP"
> 
> "cjk-ambiguous-chars-are-wide t"
> 
> "window-system nil"
> 
> "slot (ja_JP nil (japanese-jisx0208 (8481 . 10366)) (cp932-2-byte (33088 . 34719)))"
> 
> "ambiguous-is-wide nil"
> 
> For information about GNU Emacs and the GNU system, type C-h C-a.
> 
> "use-cjk-char-width-table ja_JP"
> 
> "cjk-ambiguous-chars-are-wide t"
> 
> "window-system w32"
> 
> "slot (ja_JP #^[...] (japanese-jisx0208 (8481 . 10366)) (cp932-2-byte (33088 . 34719)))"
> 
> nil
> 
> 5
> 
> 5
> 
> --8<---------------cut here---------------end--------------->8---
> 
> #[...] is  delete by hand.
> 
> (nth 1 slot) is not NIL, a vector, then char table is not regenerated,
> the "ambiguous-is-wide nil" table that is generated during startup is
> continued to be used.

OK, thanks.  Please try the new patch for characters.el below, which
_replaces_ the previous one, i.e. it is relative to the current Git
repository.  You need to rebuild Emacs after you modify characters.el.

Then try again with your a.el, and I think you can drop these first 2
lines:

> (set-language-environment "English")
> (set-language-environment "Japanese")

If this still doesn't work, I'll need the debug-printouts from
use-cjk-char-width-table again, and maybe with more details, to
understand why the first call to that function doesn't set
ambiguous-is-wide to a non-nil value.  That first call is from
startup.el, i.e. when Emacs is started.

Thanks.

diff --git a/lisp/international/characters.el b/lisp/international/characters.el
index b29b0f8..c29c604 100644
--- a/lisp/international/characters.el
+++ b/lisp/international/characters.el
@@ -1716,7 +1716,8 @@ use-cjk-char-width-table
                (and cjk-ambiguous-chars-are-wide
                     ;; MS-Windows Terminal forces all ambiguous
                     ;; characters to be narrow, even in CJK locales.
-                    (not (and (boundp 'w32--terminal-is-conhost)
+                    (not (and (eq system-type 'windows-nt)
+                              (null initial-window-system)
                               (null w32--terminal-is-conhost))))))
           (map-char-table
            (lambda (range _val)