From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.bugs Subject: bug#57693: 29.0.50; Is there a more reliable version of `char-displayable-p'? Date: Mon, 12 Sep 2022 13:46:50 +0800 Message-ID: <875yhtw3ed.fsf@localhost> References: <87v8pw1xyo.fsf@localhost> <83a678d5w6.fsf@gnu.org> <878rmr25tk.fsf@localhost> <83czc3bvbg.fsf@gnu.org> <87y1urybt6.fsf@localhost> <837d2bbr2s.fsf@gnu.org> <87edwjy77h.fsf@localhost> <831qsjboy0.fsf@gnu.org> <87v8puw945.fsf@localhost> <838rmq9rfr.fsf@gnu.org> <837d2a9qcu.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25106"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 57693@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 12 07:47:26 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oXcI1-0006Jx-2x for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Sep 2022 07:47:25 +0200 Original-Received: from localhost ([::1]:34096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXcHu-0007V6-4C for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Sep 2022 01:47:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXcHf-0007Uu-3W for bug-gnu-emacs@gnu.org; Mon, 12 Sep 2022 01:47:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXcHe-0001bZ-Q7 for bug-gnu-emacs@gnu.org; Mon, 12 Sep 2022 01:47:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oXcHe-0004Id-CB for bug-gnu-emacs@gnu.org; Mon, 12 Sep 2022 01:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Sep 2022 05:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57693 X-GNU-PR-Package: emacs Original-Received: via spool by 57693-submit@debbugs.gnu.org id=B57693.166296156716463 (code B ref 57693); Mon, 12 Sep 2022 05:47:02 +0000 Original-Received: (at 57693) by debbugs.gnu.org; 12 Sep 2022 05:46:07 +0000 Original-Received: from localhost ([127.0.0.1]:43869 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXcGk-0004HS-Sb for submit@debbugs.gnu.org; Mon, 12 Sep 2022 01:46:07 -0400 Original-Received: from mail-pg1-f172.google.com ([209.85.215.172]:38849) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXcGg-0004Gg-VC for 57693@debbugs.gnu.org; Mon, 12 Sep 2022 01:46:05 -0400 Original-Received: by mail-pg1-f172.google.com with SMTP id t70so7272592pgc.5 for <57693@debbugs.gnu.org>; Sun, 11 Sep 2022 22:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date; bh=lyrcnoOXyjLsqaFuUuKAqBaipfYa3jSAaoqrh56mF4Y=; b=WjShw++u24+o+3DcdcWd3nYy9XptRbbsl1Pohj779j1ub4QI01eBzuxeGxFCHNZjMi hxXlZpmAKH7fgwk9ZZ2LFhv+kyZNf3k+OUw4TGa4fe6prwKkGOOY12qdFuFYQE8jCm+6 yTktPpNsmRLh9ntVCK3oKiAtBs/2H+LRwqxoag9vIj1UynWcYR63pLsrgFQsGXgqRu0g E1FEHDk0zEtsLYcDceOZQqW4DJyHJ7jdltSQ0Ek5Y6L5emBBVKcrBZKU5tcNJm8SNnRB QCQ6d8lyoL1rDrCWHXragOdWhyarxgP0qr6kLIzc1RMGeAxSEi7mQFTNwMWk6jqus5+8 7ggw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date; bh=lyrcnoOXyjLsqaFuUuKAqBaipfYa3jSAaoqrh56mF4Y=; b=r2Nj2VMUynuIsakonkqzjOCP+Rn+KT4H83/4P2T//t2Ipv/Cx9mEzbB0NncWZrBx/+ 51LvEoMKxZqHqPTFhlBK+Bd54bwtuH0YMK2tjiVs6p3lbW0hg7UOtebSZa5AievADE+N k1wd4U7q4dTOdvBS8dyhDr/YDsywmy+jQtaU9n3po/u/PLe0aoJ52CDrTmvo6pIOybPe No9BM/J1D1Px75VSO5dL01JwCnFO4GfOJJZYOybLFvtRz/f4Zid1roym9G6EhcNlxO3T J+H8EyQmgYJCJq/qOEB34mAc+P17tttptT49bwAKVLcWm/ZhxpKC9z3jeyrwCYuJHeWS FFKA== X-Gm-Message-State: ACgBeo2sJNeIaYtp0WC2+kvx69lKdE4ysArvm6cUzUaEmxuu1Qe5hIZ5 zdqT+Bjal3votz9THJMICYMtGVIl86Y= X-Google-Smtp-Source: AA6agR5ugVhzeNt5+ELNLUQByKOev6QBKD3aAo9YH739UpD8qDKeYY66NL6w4JV0EfQ9xzfgCmvVmg== X-Received: by 2002:a65:6e83:0:b0:42a:868b:dc89 with SMTP id bm3-20020a656e83000000b0042a868bdc89mr22180004pgb.554.1662961556777; Sun, 11 Sep 2022 22:45:56 -0700 (PDT) Original-Received: from localhost ([2409:8a70:2bc:c850:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id jm15-20020a17090304cf00b00177ff4019d9sm4853603plb.274.2022.09.11.22.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Sep 2022 22:45:56 -0700 (PDT) In-Reply-To: <837d2a9qcu.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:242209 Archived-At: Eli Zaretskii writes: > Here's what I suggest for GUI frames: > > (defun insert-char-safely (ch repl) > "Insert character CH, if it can be displayed; otherwise insert REPL." > (insert ch) > (unless (font-at (1- (point))) > (delete-char -1) > (insert repl))) Thanks! > Do you need this to work for TTY frames as well? If so, it could be a > problem, since most terminal emulators don't provide a way of > inquiring whether a certain character can be displayed. > char-displayable-p currently just checks on most terminals that the > terminal-coding-system can _encode_ the character, which isn't enough > if the terminal encoding is UTF-8. The original code I was referring to unconditionally used a "safe" fallback on terminals. If there is no technical possibility to determine whether a character can be displayed, so be it. I am thinking about something like below (to insert string, not a char), (defun org-insert-displayable (&rest strings) "Insert the first displayable string from STRINGS. If none of the STRINGS can be displayed, display the last string. In terminal, always insert the last string." (if (not (display-graphic-p)) (insert (car (last strings))) (catch :displayable (dolist (string strings) (insert string) (save-excursion (catch :undisplayable (dotimes (i (length string)) (unless (font-at (- (point) i 1)) (throw :undisplayable t))) ;; All chars can be displayed. Keep the inserted string. (throw :displayable t))) ;; Some char cannot be displayed. Clear the insertion and move ahead to ;; the next candidate. (delete-char (- (length string)))) ;; None displayable. (insert (car (last strings)))))) -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92