unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Gerry Agbobada <gagbobada@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Question about composite.c
Date: Tue, 21 Jan 2020 20:15:22 +0200	[thread overview]
Message-ID: <83r1zsvfph.fsf@gnu.org> (raw)
In-Reply-To: <CAHhDRB85NHEjmKKnJ=LzMBbvZZNtyJmANVbzEjJdrx5iF3v3-Q@mail.gmail.com> (message from Gerry Agbobada on Mon, 20 Jan 2020 23:17:19 +0100)

> From: Gerry Agbobada <gagbobada@gmail.com>
> Date: Mon, 20 Jan 2020 23:17:19 +0100
> 
> (defvar composition-ligature-table (make-char-table nil))
> (require 'composite)
> 
> (let ((alist
>        '(
>          (?* . ".\\(?:\\(\\*\\*\\|[*>]\\)[*>]?\\)")
>          )))
>   (dolist (char-regexp alist)
>     (set-char-table-range composition-ligature-table (car char-regexp)
>                           `([,(cdr char-regexp) 0 font-shape-gstring]))))
> 
> (set-char-table-parent composition-ligature-table composition-function-table)
> 
> (setq-local composition-function-table composition-ligature-table)

Can you tell what kind of ligatures you wanted to support that
required such a non-trivial regexp?

Also, why did you need to use a separate char-table instead of
composition-function-table?

> I think my error may come from having a composition-table where a replacement
> triggered by =prettify-symbols= occurs before the regex for
> =composition-ligature-table= happens, so there's only an empty string for
> replacement and there's an error because it doesn't pass the test.

It's not just an empty string, it's a _unibyte_ string.  How did that
happen?

More importantly, please don't use prettify-symbols-mode, which are
based on static compositions, together with automatic compositions.
Static compositions are an obsolete feature, it lacks support for some
modern Emacs features (e.g., bidirectional text), and we should remove
it from Emacs at some future point -- but not before we implement a
replacement for it using composition-function-table and related
machinery.  Mixing these two incompatible compositions is asking for
trouble.  If you turn off prettify-symbols-mode, does the problem go
away?

> diff --git a/src/composite.c b/src/composite.c
> index 53e6930b5f..1151721d61 100644
> --- a/src/composite.c
> +++ b/src/composite.c
> @@ -1735,7 +1735,7 @@ Otherwise (for terminal display), FONT-OBJECT
> must be a terminal ID, a
>    if (NILP (string))
>      {
>        if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
> -       error ("Attempt to shape unibyte text");
> +       error ("Attempt to shape unibyte text \"%s\" in non multibyte
> buffer", string);
>        validate_region (&from, &to);
>        frompos = XFIXNAT (from);
>        topos = XFIXNAT (to);
> @@ -1745,8 +1745,8 @@ Otherwise (for terminal display), FONT-OBJECT
> must be a terminal ID, a
>      {
>        CHECK_STRING (string);
>        validate_subarray (string, from, to, SCHARS (string), &frompos, &topos);
> -      if (! STRING_MULTIBYTE (string))
> -       error ("Attempt to shape unibyte text");
> +      if (strlen(string) != 0 && ! STRING_MULTIBYTE (string))
> +       error ("Attempt to shape unibyte text \"%s\"", string);
>        frombyte = string_char_to_byte (string, frompos);

This cannot be right.  We cannot meaningfully compose unibyte text,
because it is not made of characters, it is made of raw bytes, and
therefore you cannot meaningfully reference composition-function-table
by such raw bytes.  The errors are correct, and must stay that way.
You need to debug this further to understand how come you ended up in
this condition, and then fix whatever root cause caused that.

> * Question
> I guess the only question is : what's supposed to happen when =string= is an
> empty lisp string in this condition ?

There's no problem with empty strings here, as long as they are
multibyte.



  reply	other threads:[~2020-01-21 18:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-20 22:17 Question about composite.c Gerry Agbobada
2020-01-21 18:15 ` Eli Zaretskii [this message]
2020-01-21 18:57   ` Gerry Agbobada
2020-01-21 19:15     ` Eli Zaretskii
2020-01-22  8:55       ` Gerry Agbobada
2020-04-14 22:43         ` Gerry Agbobada
2020-04-15  1:10           ` Noam Postavsky
2020-04-15  7:39             ` Gerry Agbobada
2020-04-25 12:44           ` Eli Zaretskii
2020-04-25 13:06             ` Gerry Agbobada
2020-04-25 13:29               ` Gerry Agbobada
2020-04-25 13:53                 ` Gerry Agbobada
2020-04-25 15:23                   ` Eli Zaretskii
2020-04-25 15:32                     ` Gerry Agbobada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83r1zsvfph.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=gagbobada@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).