From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#28312: 25.2; Arabic script changes when scrolling Date: Thu, 06 Jun 2019 17:04:13 +0300 Message-ID: <834l52stcy.fsf@gnu.org> References: <83lgly29zf.fsf@gnu.org> <83h8wm24v9.fsf@gnu.org> Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="165560"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 28312@debbugs.gnu.org To: mituharu@math.s.chiba-u.ac.jp, handa@gnu.org, nick@tenpoint.co.nz Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 06 16:05:24 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYt19-000gva-7r for geb-bug-gnu-emacs@m.gmane.org; Thu, 06 Jun 2019 16:05:23 +0200 Original-Received: from localhost ([127.0.0.1]:32945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYt18-00008d-3O for geb-bug-gnu-emacs@m.gmane.org; Thu, 06 Jun 2019 10:05:22 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:49098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYt0v-0008SR-K5 for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2019 10:05:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYt0t-00016A-KT for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2019 10:05:09 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36780) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hYt0o-0000dy-8F for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2019 10:05:06 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hYt0n-0001WL-V6 for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2019 10:05:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 06 Jun 2019 14:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28312 X-GNU-PR-Package: emacs Original-Received: via spool by 28312-submit@debbugs.gnu.org id=B28312.15598298815813 (code B ref 28312); Thu, 06 Jun 2019 14:05:01 +0000 Original-Received: (at 28312) by debbugs.gnu.org; 6 Jun 2019 14:04:41 +0000 Original-Received: from localhost ([127.0.0.1]:50322 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hYt0S-0001Vb-RI for submit@debbugs.gnu.org; Thu, 06 Jun 2019 10:04:41 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34583) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hYt0N-0001VD-Nr; Thu, 06 Jun 2019 10:04:36 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:45878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYt0H-0005MR-7Y; Thu, 06 Jun 2019 10:04:29 -0400 Original-Received: from [176.228.60.248] (port=3938 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hYt0E-0006rG-Tx; Thu, 06 Jun 2019 10:04:28 -0400 In-reply-to: <83h8wm24v9.fsf@gnu.org> (message from Eli Zaretskii on Fri, 01 Sep 2017 11:35:38 +0300) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:160181 Archived-At: tags 28312 patch thanks > Date: Fri, 01 Sep 2017 11:35:38 +0300 > From: Eli Zaretskii > Cc: 28312@debbugs.gnu.org, nick@tenpoint.co.nz > > I'm guessing that somehow we don't redraw enough characters to give > the font shaper a chance to shape them correctly. CC'ing Handa-san, > in the hope that he could have some insights on this. The guess was correct, but finding why this happens and under what circumstances proved an elusive problem. I eventually found the culprit: it turned out we sometimes stop examining buffer text at arbitrary positions, and don't make sure these positions are never in the middle of a composable character sequence. I implemented a solution, the patch is below. Unfortunately, it makes redisplay slower in buffers with lots of composable characters, so I hesitate to install it. Would people please try the patch and see if Emacs is still reasonably responsive in buffers with Arabic text, especially when marking or extending the region under transient-mark-mode? If I get enough positive feedback, I will install this. TIA. diff --git a/src/composite.c b/src/composite.c index 7d7ed3f..aba47a9 100644 --- a/src/composite.c +++ b/src/composite.c @@ -1427,7 +1427,7 @@ struct position_record representing the composition, and return true. Otherwise, *GSTRING to Qnil, and return false. */ -static bool +bool find_automatic_composition (ptrdiff_t pos, ptrdiff_t limit, ptrdiff_t *start, ptrdiff_t *end, Lisp_Object *gstring, Lisp_Object string) diff --git a/src/composite.h b/src/composite.h index 8675163..b4c6a93 100644 --- a/src/composite.h +++ b/src/composite.h @@ -324,7 +324,9 @@ extern bool composition_reseat_it (struct composition_it *, ptrdiff_t, struct face *, Lisp_Object); extern int composition_update_it (struct composition_it *, ptrdiff_t, ptrdiff_t, Lisp_Object); - +extern bool find_automatic_composition (ptrdiff_t, ptrdiff_t, + ptrdiff_t *, ptrdiff_t *, + Lisp_Object *, Lisp_Object); extern ptrdiff_t composition_adjust_point (ptrdiff_t, ptrdiff_t); INLINE_HEADER_END diff --git a/src/xdisp.c b/src/xdisp.c index 5f43815..e4fb48b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3618,7 +3618,25 @@ compute_stop_pos (struct it *it) /* Set up variables for computing the stop position from text property changes. */ XSETBUFFER (object, current_buffer); - limit = make_fixnum (IT_CHARPOS (*it) + TEXT_PROP_DISTANCE_LIMIT); + /* Find the position to limit the search for properties. It + must not be in the middle of a composable sequence, because + having a stop_charpos there risks breaking the composition + into two or more separate parts, to be submitted separately + to the shaping engine, and that will produce incorrect + shaping with some scripts (e.g., Arabic). */ + pos = charpos + TEXT_PROP_DISTANCE_LIMIT; + if (!NILP (Vauto_composition_mode)) + { + ptrdiff_t cpos = charpos, posmax = min (pos, ZV); + ptrdiff_t start = posmax, end = posmax; + Lisp_Object ignored; + while (find_automatic_composition (cpos, posmax, &start, &end, + &ignored, Qnil) + && end < posmax) + cpos = end; + pos = max (end, posmax); + } + limit = make_fixnum (pos); } /* Get the interval containing IT's position. Value is a null