From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Eli Zaretskii" Newsgroups: gmane.emacs.bidi,gmane.emacs.devel Subject: Re: merge emacs-bidi into the main tree Date: Tue, 12 Aug 2003 08:59:52 +0200 Sender: emacs-bidi-bounces+gnu-emacs-bidi=m.gmane.org@gnu.org Message-ID: <9743-Tue12Aug2003085951+0300-eliz@elta.co.il> References: <87lluax3ch.fsf@emacswiki.org> <7458-Sun03Aug2003224354+0300-eliz@elta.co.il> <87smoi9p64.fsf@emacswiki.org> <87he4x5v7x.fsf_-_@emacswiki.org> <86brv0wfyn.fsf@gerd.free-bsd.org> <6480-Fri08Aug2003180204+0300-eliz@elta.co.il> <8665l886vu.fsf@gerd.free-bsd.org> <200308120149.KAA23819@etlken.m17n.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1060668331 16178 80.91.224.253 (12 Aug 2003 06:05:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 12 Aug 2003 06:05:31 +0000 (UTC) Cc: gerd.moellmann@t-online.de, alex@emacswiki.org, emacs-bidi@gnu.org, developer@arabeyes.org, emacs-devel@gnu.org Original-X-From: emacs-bidi-bounces+gnu-emacs-bidi=m.gmane.org@gnu.org Tue Aug 12 08:05:29 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19mSHg-0007sm-00 for ; Tue, 12 Aug 2003 08:05:29 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19mSHC-0003xp-Fh for gnu-emacs-bidi@m.gmane.org; Tue, 12 Aug 2003 02:04:58 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19mSGs-0003ws-JJ for emacs-bidi@gnu.org; Tue, 12 Aug 2003 02:04:38 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19mSGM-0003iK-IV for emacs-bidi@gnu.org; Tue, 12 Aug 2003 02:04:37 -0400 Original-Received: from [192.114.186.23] (helo=aragorn.inter.net.il) by monty-python.gnu.org with esmtp (Exim 4.20) id 19mSGL-0003hU-Ue; Tue, 12 Aug 2003 02:04:06 -0400 Original-Received: from zaretski (pns03-209-21.inter.net.il [80.230.209.21]) by aragorn.inter.net.il (Mirapoint Messaging Server MOS 3.3.5-GR) with ESMTP id BFB88381; Tue, 12 Aug 2003 09:03:49 +0300 (IDT) Original-To: handa@m17n.org X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 1.8.9 In-reply-to: <200308120149.KAA23819@etlken.m17n.org> (message from Kenichi Handa on Tue, 12 Aug 2003 10:49:26 +0900 (JST)) X-BeenThere: emacs-bidi@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Discussion of Emacs support for multi-directional text. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-bidi-bounces+gnu-emacs-bidi=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.bidi:144 gmane.emacs.devel:15897 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:15897 > Date: Tue, 12 Aug 2003 10:49:26 +0900 (JST) > From: Kenichi Handa > > In brief, what I did in emacs-bidi are: > > (1) change xdisp.c to call get_next_display_element_visually > and set_iterator_to_next_visually instead of > get_next_display_element and set_iterator_to_next. > > (2) make a new file bidi.c that implements > get_next_display_element_visually and > set_iterator_to_next_visually. > > (3) make a new file bidi.el that implements simple > bidi-reordering function that is called from > get_next_display_element_visually to create a cache in > (struct it). > > (4) change xterm.c to display glyphs flushing to right when > orientation-reversed is non-nil. > > My current plan is to replace (2) and (3) with Eli's code. It's not gonna be that simple ;-) The code I wrote is designed to be plugged into the part of the display engine that walks the buffer and, for each character it encounters, generates a `struct glyph' element of the glyph matrix. Currently, ignoring overlays, text properties, etc., this buffer scan is linear, from left to right, and going to the next buffer position is simple: IT_BYTEPOS (*it) += it->len; IT_CHARPOS (*it) += 1; (this is from xdisp.c:set_iterator_to_next). That is, we simply increment the buffer's character position by one. (If the next display element comes from something other than the buffer, the code in set_iterator_to_next does similar things with the object that is the source of characters.) The code I wrote replaces the buffer position increment with a call to a function. Thus, the above two lines should roughly be replaced with this: bidi_get_next_char_visually (it->bidi_it); [IT_BYTEPOS (*it) and IT_CHARPOS (*it) get set to the right values inside that call.] What bidi_get_next_char_visually does is to find the next character in the buffer in the visual order; that could involve quickly scanning across a run of characters until we find the one we want to display. For example, i fthe buffer's contents are abcdABCDefg then after processing `d', the code will scan until `D', then go back to `C', `B', and `A', in that order, then jump to `e', and finally proceed to `f' and `g'. (To save future work, some crucial information about the characters over which we scan is cached inside the bidi_it struct, to facilitate processing later when we need to go back to those characters and generate the glyph matrix elements from them. So, in the above example, going back from 'D' to 'A' boils down to delivering information already cached during the forward scan.) So a linear scan becomes non-linear, but the details of that are completely concealed from set_iterator_to_next; as far as it is concerned, it just magically jumped over a few characters and landed on the next character to be displayed. The glyph matrices are layed in the visual order. In other words, the structure and logic of the code in xdisp.c remains largely unchanged, the only changes being where we find the position of the next display element. Or so I hope, anyway... (There still needs to be more code in the terminal-specific parts of Emacs, that displays the glyphs either starting at the left or the right margin of the screen/window, depending on the current paragraph's base direction; the latter gets decided by subroutines of bidi_get_next_char_visually and is stored in the bidi_it structure. I believe this code, at least for the X terminals, already largely exists in m17n.org's emacs-bidi.)