From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#64696: 30.0.50; indent-to inherits preceding text properties, including 'invisible Date: Sat, 22 Jul 2023 14:22:47 +0300 Message-ID: <83wmys8a2g.fsf@gnu.org> References: <87fs5l3b3g.fsf@localhost> <83ilah79aq.fsf@gnu.org> <87jzux2zg8.fsf@localhost> <83351l74ci.fsf@gnu.org> <87a5vt2vx8.fsf@localhost> <831qh56vvz.fsf@gnu.org> <871qh52nlw.fsf@localhost> <83pm4p5er8.fsf@gnu.org> <874jm0mhgb.fsf@localhost> <831qh459sy.fsf@gnu.org> <87jzuvq785.fsf@localhost> <835y6ca1ah.fsf@gnu.org> <87zg3o8m2a.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4552"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, 64696@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 22 13:23:23 2023 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 1qNAhn-00012M-7v for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 Jul 2023 13:23:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNAhT-0003is-P7; Sat, 22 Jul 2023 07:23:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNAhS-0003ij-J3 for bug-gnu-emacs@gnu.org; Sat, 22 Jul 2023 07:23:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qNAhS-00031m-B4 for bug-gnu-emacs@gnu.org; Sat, 22 Jul 2023 07:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qNAhS-0000hQ-5z for bug-gnu-emacs@gnu.org; Sat, 22 Jul 2023 07:23: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: Sat, 22 Jul 2023 11:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64696 X-GNU-PR-Package: emacs Original-Received: via spool by 64696-submit@debbugs.gnu.org id=B64696.16900249412633 (code B ref 64696); Sat, 22 Jul 2023 11:23:02 +0000 Original-Received: (at 64696) by debbugs.gnu.org; 22 Jul 2023 11:22:21 +0000 Original-Received: from localhost ([127.0.0.1]:35567 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qNAgm-0000gP-Gs for submit@debbugs.gnu.org; Sat, 22 Jul 2023 07:22:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57636) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qNAgj-0000gC-Fr for 64696@debbugs.gnu.org; Sat, 22 Jul 2023 07:22:19 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNAgd-0002nc-Er; Sat, 22 Jul 2023 07:22:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=dzc05AH4DVVZOoczR6Lh1NChgGaJvQmkRwC/vMN/jjs=; b=d9QSIyyDVdZVjoTpHzJX bYs+5kGumKJlkQW5Kyc0cMUCpZLdRdNG9opVyJn68mIfAY1N0xtO7oIpZumjbOqO9z2w71njhVPT2 R7MK0ixQHxgHSE05VkYL8nDy6d1u2IqjZvZz1mjC8Y5og8Sw45tsXnNAudG5KCQCmEE22Jrq5rtK9 ObLfbGN+RWwDaIvdgLp2SnPQKoF1yn9H42TRBPIg6lZ3CJQY3o+ggwMOn2y+8995bRdmGW0pcrtxg gqhFjy71dHt45fBWxE8hSPlVgB8/C0yhLkJVEVVHDdZD8hoBVIXj1YtTy3CjfAtS34lNnvlUKcEzE 7hECZsh3yfahsw==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qNAgb-0003us-HS; Sat, 22 Jul 2023 07:22:10 -0400 In-Reply-To: <87zg3o8m2a.fsf@localhost> (message from Ihor Radchenko on Sat, 22 Jul 2023 07:03:41 +0000) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:265799 Archived-At: > From: Ihor Radchenko > Cc: monnier@iro.umontreal.ca, 64696@debbugs.gnu.org > Date: Sat, 22 Jul 2023 07:03:41 +0000 > > Eli Zaretskii writes: > > >> You can do M-x yant/full-test after evaluating the code below > > > > And what are the problems you see with current-column in this example? > > (Let's leave indent-to alone for now.) > > ⛔ Warning (emacs): Test #1:: Everything visible. > ⛔ Warning (emacs): Moved point after first ’word’ > ⛔ Warning (emacs): 1:: current-column = 4 > > Test #1 is expected - everything is visible, we are indeed at column 4. > > ⛔ Warning (emacs): Test #2:: ’word’ is inside folded heading (hidden using overlays). > ⛔ Warning (emacs): Moved point after first ’word’ > ⛔ Warning (emacs): 1:: current-column = 4 > > Test #2 is unexpected - we are inside invisible region, but > current-column reports as if everything were visible. current-column produces incorrect results when the newline before the current line is invisible. It always starts from the beginning of the current physical line, even if that is in invisible text. We could teach current-column about invisible newlines, see the patch below. But I'm not sure this is justified, nor whether it won't break something. The patch below also has a disadvantage that it will still behave as before for a buffer that is not displayed in any window; if we want that to be fixed as well, the changes will need to be more extensive. (Basically, we will need to write a non-display version of back_to_previous_visible_line_start.) With the patch below, Test #2 shows "current-column = 6", which is correct, since the cursor is shown after "* Test", with all the rest invisible. If we think this kind of change is a good idea (Stefan?), patches to make the below work without employing display code (which needs the window) will be welcome. diff --git a/src/indent.c b/src/indent.c index eda85f2..1357fd2 100644 --- a/src/indent.c +++ b/src/indent.c @@ -563,11 +563,35 @@ scan_for_column (ptrdiff_t *endpos, EMACS_INT *goalcol, ptrdiff_t end = endpos ? *endpos : PT; ptrdiff_t scan, scan_byte, next_boundary, prev_pos, prev_bpos; - scan = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, NULL, &scan_byte, 1); - window = Fget_buffer_window (Fcurrent_buffer (), Qnil); w = ! NILP (window) ? XWINDOW (window) : NULL; + int prevbyte = 0; + Lisp_Object prop = Qnil; + if (PT > BEGV && w) + { + prevbyte = FETCH_BYTE (PT_BYTE - 1); + prop = Fget_char_property (make_fixnum (PT - 1), Qinvisible, window); + } + if (w && !(prevbyte == '\n' && TEXT_PROP_MEANS_INVISIBLE (prop) == 0)) + { + struct it it; + struct text_pos pt; + specpdl_ref count = SPECPDL_INDEX (); + void *itdata = bidi_shelve_cache (); + SET_TEXT_POS (pt, PT, PT_BYTE); + record_unwind_protect_void (unwind_display_working_on_window); + display_working_on_window_p = true; + start_display (&it, w, pt); + reseat_at_previous_visible_line_start (&it); + scan = IT_CHARPOS (it); + scan_byte = IT_BYTEPOS (it); + bidi_unshelve_cache (itdata, 0); + unbind_to (count, Qnil); + } + else + scan = find_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, -1, NULL, &scan_byte, 1); + if (current_buffer->long_line_optimizations_p) { bool lines_truncated = false;