From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#28936: move_it_in_display_line_to returns MOVE_POS_MATCH_OR_ZV before ZV Date: Sat, 21 Oct 2017 20:02:58 -0700 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1508641456 8261 195.159.176.226 (22 Oct 2017 03:04:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 22 Oct 2017 03:04:16 +0000 (UTC) To: 28936@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 22 05:04:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e66YX-0000bt-JT for geb-bug-gnu-emacs@m.gmane.org; Sun, 22 Oct 2017 05:04:06 +0200 Original-Received: from localhost ([::1]:59901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e66Yd-00076O-BO for geb-bug-gnu-emacs@m.gmane.org; Sat, 21 Oct 2017 23:04:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e66YX-00076H-J0 for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 23:04:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e66YU-0002Gx-EU for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 23:04:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46142) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e66YU-0002GM-As for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 23:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e66YU-0004Ys-29 for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 23:04:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 22 Oct 2017 03:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 28936 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: Emacs Bug Reports Original-Received: via spool by submit@debbugs.gnu.org id=B.150864140917491 (code B ref -1); Sun, 22 Oct 2017 03:04:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Oct 2017 03:03:29 +0000 Original-Received: from localhost ([127.0.0.1]:54823 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e66Xw-0004Y2-Vd for submit@debbugs.gnu.org; Sat, 21 Oct 2017 23:03:29 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33328) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e66Xv-0004Xp-1R for submit@debbugs.gnu.org; Sat, 21 Oct 2017 23:03:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e66Xo-00085U-N6 for submit@debbugs.gnu.org; Sat, 21 Oct 2017 23:03:21 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:47024) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e66Xo-00084o-Jj for submit@debbugs.gnu.org; Sat, 21 Oct 2017 23:03:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e66Xn-00074l-7I for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 23:03:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e66Xk-0007iZ-13 for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 23:03:19 -0400 Original-Received: from gateway24.websitewelcome.com ([192.185.51.56]:18220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e66Xj-0006i9-Nz for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 23:03:15 -0400 Original-Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway24.websitewelcome.com (Postfix) with ESMTP id A12ECED62 for ; Sat, 21 Oct 2017 22:02:59 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id 66XTe3LqtHEIm66XTeBG9N; Sat, 21 Oct 2017 22:02:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:To:From:Message-ID:Date: Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=z1Rv8gypq4ZiVytmOr+otfMivbRWM/le7GV9c3MxMEw=; b=hiB3SbuJEgmnr9Fb8DXESQ00E4 L4zwuOdyXgzFHwn9McD+v4TFynC21HcxegDVtRwR7KOVNCtDKoWeksc5TFM+v39lZhy1X6BsTIWzl 1RxSCrEOCXHIxZlQm9dGZdHpDrGO3EUWkUIPaO8c5M97klh5pGZGOArUEL7COAOSd+R/LY0aD5tT0 cH+fZsIlq4t0Bt4W7M0VGS1ZIio8AB1Uw7Am0fHcImUFTVGbDZvXWQJoCfjRB1RN2iesJFCs2xXOP 5lpsS3HKVsmBQAYlzot5xZoMXOz15VjisHKen+/fjlI8jBWcfSdRqdNlKBGU9RYefr7nq3uIphvnB tW5rXk2A==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:53047 helo=server.private) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.87) (envelope-from ) id 1e66XT-002MZC-0w for bug-gnu-emacs@gnu.org; Sat, 21 Oct 2017 22:02:59 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Exim-ID: 1e66XT-002MZC-0w X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.private) [45.48.239.195]:53047 X-Source-Auth: lawlist X-Email-Count: 1 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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: 208.118.235.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:138835 Archived-At: A couple of observations: 1. `move_it_in_display_line' could use an additional comment at the outset to let readers know that it is not compatible with moving to X in a horizontal scrolling and/or truncate lines situation. The existing commentary that it was intended for external use was insufficient to deter me, and it required a learning curve on my part to better understand its limited potential use. 2. When IT is on the last line in the buffer containing a few or more characters, `move_it_in_display_line_to' stops short of the target X and erroneously returns MOVE_POS_MATCH_OR_ZV when used as follows. I have display-line-numbers set to a non-nil value in the event that makes a difference. There is nothing special in terms of text-properties or overlays present in the buffer. int target_x = [Some arbitrary X that is a few characters before ZV.]; move_it_in_display_line_to (it, ZV, target_x, MOVE_TO_POS | MOVE_TO_X); The workaround is to compare the result of MOVE_POS_MATCH_OR_ZV with IT_CHARPOS to ensure that we are really at a ZV situation. Here is a working draft of what I am using for my crosshairs (#17684). int move_it_in_display_line_to_x (struct it *it, int target_x) { struct it saved_it; void *saved_data = bidi_shelve_cache (); enum move_it_result rc = MOVE_X_REACHED; int new_x, prev_x; /* Advance straight to `it->first_visible_x` if IT is prior thereto. */ if (it->current_x < it->first_visible_x) move_it_in_display_line_to (it, ZV, it->first_visible_x, MOVE_TO_POS | MOVE_TO_X); while (it->current_x + it->pixel_width <= target_x) { SAVE_IT (saved_it, *it, saved_data); new_x = it->current_x + it->pixel_width; if (new_x == it->current_x) new_x++; rc = move_it_in_display_line_to (it, ZV, new_x, MOVE_TO_POS | MOVE_TO_X); if (ITERATOR_AT_END_OF_LINE_P (it) || FETCH_BYTE (IT_BYTEPOS (it)) == '\n' /* There is a bug in `move_it_in_display_line_to' such that it returns MOVE_POS_MATCH_OR_ZV before reaching ZV when the latter is at the end of the line: abcdefg[EOB]. The workaround is to add an extra check using IT_CHARPOS and comparing it to ZV. */ || (rc == MOVE_POS_MATCH_OR_ZV && IT_CHARPOS (*it) == ZV)) break; } /* When word-wrap is on, TO_X may lie past the end of a wrapped line. Then it->current is the character on the next line, so backtrack to the space before the wrap point. */ if (it->line_wrap == WORD_WRAP && rc == MOVE_LINE_CONTINUED) { prev_x = max (it->current_x - 1, 0); RESTORE_IT (it, &saved_it, saved_data); move_it_in_display_line_to (it, -1, prev_x, MOVE_TO_X); } bidi_unshelve_cache (saved_data, true); return rc; } Thanks, Keith