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#22763: 25.1.50; Feature Request -- A faster method to obtain line number at position. Date: Mon, 08 Feb 2021 17:04:58 +0200 Message-ID: <83pn1alhwl.fsf@gnu.org> References: <83y4aclofm.fsf@gnu.org> <878s7z532u.fsf@gnus.org> <87y2fz3lpe.fsf@gnus.org> <87h7mn22ls.fsf@gnus.org> <83eehrn408.fsf@gnu.org> <87y2fzzqxb.fsf@gnus.org> <87tuqnzqh2.fsf@gnus.org> <83blcvn1ku.fsf@gnu.org> <87czxbznly.fsf@gnus.org> <87r1lry5hl.fsf@gnus.org> <83v9b3li0a.fsf@gnu.org> <87zh0fwofn.fsf@gnus.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13378"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 22763@debbugs.gnu.org, esq@lawlist.com, monnier@iro.umontreal.ca To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 08 22:09:18 2021 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 1l9DmY-0003L2-9v for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 08 Feb 2021 22:09:18 +0100 Original-Received: from localhost ([::1]:55542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9DmX-0004Ag-7W for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 08 Feb 2021 16:09:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9868-0001ze-EE for bug-gnu-emacs@gnu.org; Mon, 08 Feb 2021 10:05:08 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l9862-0003pD-OQ for bug-gnu-emacs@gnu.org; Mon, 08 Feb 2021 10:05:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l9862-0001Zb-Hg for bug-gnu-emacs@gnu.org; Mon, 08 Feb 2021 10:05:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 08 Feb 2021 15:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22763 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 22763-submit@debbugs.gnu.org id=B22763.16127966986033 (code B ref 22763); Mon, 08 Feb 2021 15:05:02 +0000 Original-Received: (at 22763) by debbugs.gnu.org; 8 Feb 2021 15:04:58 +0000 Original-Received: from localhost ([127.0.0.1]:51665 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l985y-0001ZF-Fv for submit@debbugs.gnu.org; Mon, 08 Feb 2021 10:04:58 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47154) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l985v-0001Z2-9r for 22763@debbugs.gnu.org; Mon, 08 Feb 2021 10:04:57 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:51511) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l985p-0003jN-F6; Mon, 08 Feb 2021 10:04:49 -0500 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4342 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l985j-0008Q8-UJ; Mon, 08 Feb 2021 10:04:45 -0500 In-Reply-To: <87zh0fwofn.fsf@gnus.org> (message from Lars Ingebrigtsen on Sun, 07 Feb 2021 22:36:12 +0100) 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" Xref: news.gmane.io gmane.emacs.bugs:199616 Archived-At: > From: Lars Ingebrigtsen > Cc: monnier@iro.umontreal.ca, 22763@debbugs.gnu.org, esq@lawlist.com > Date: Sun, 07 Feb 2021 22:36:12 +0100 > > > It exists to support the line-number display on the mode line. That > > display has its own cache, as part of the window object, so > > display_count_lines very rarely needs to count from the beginning of > > the buffer, it usually counts from the last place it stopped the > > previous time for the same window. This is why it has the signature > > that it has. > > But these are the signatures: > > ptrdiff_t > find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, > ptrdiff_t end_byte, ptrdiff_t count, ptrdiff_t *counted, > ptrdiff_t *bytepos, bool allow_quit) > > > static ptrdiff_t > display_count_lines (ptrdiff_t start_byte, > ptrdiff_t limit_byte, ptrdiff_t count, > ptrdiff_t *byte_pos_ptr) > > So they seem very similar... I was trying to explain why display_count_lines accepts arguments that may seem unnecessary at first sight if the job is to just count the lines. > Anyway, here's something that just occurred to me: It's still the plan > to have so-long-mode on by default, right? Which means that > 'buffer-line-statistics' will be called when opening a file, which means > that we know whether there are any long lines in the buffer. > > Could we use this info to switch between cached and non-cached action > for find_newline? (I.e., just set 'cache-long-scans'.) It isn't as easy as it may sound, because cache-long-scans also affects another cache, the one used by bidi.c. We need to be able to turn them on and off separately to be able to support what you suggest. > Conversely, could we use find_newline to trigger so-long-mode? Today, > so-long-mode isn't able to step into the fray when something plops a > long line into the buffer (in shell-mode, for instance). If > find_newline finds a long line, it could switch 'cache-long-scans' on, > and also (on perhaps a different threshold) notify so-long-mode? We already detect overlong lines: that's when the line number on the mode line becomes "??". We just need to use that as trigger for so-long-mode, if we want it to turn on automatically. Also, we need to consider whether the same threshold as the one we use for the mode-line display of line numbers is suitable for so-long-mode, or we need two separate thresholds.