GNU bug report logs -
#23675
Feature request: Emacs 25.0.94: count-lines should offer a way to ignore invisible lines, e.g. outline mode
Previous Next
Reported by: Robert Weiner <rsw <at> gnu.org>
Date: Wed, 1 Jun 2016 15:34:03 UTC
Severity: wishlist
Tags: fixed, patch
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 23675 in the body.
You can then email your comments to 23675 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Wed, 01 Jun 2016 15:34:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Robert Weiner <rsw <at> gnu.org>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 01 Jun 2016 15:34:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Often when particular lines are hidden, one wants to count only visible
lines. count-lines presently cannot do this. XEmacs has for a long-time
had count-lines take an optional 3rd parameter flag which if non-nil,
ignores invisible lines in the line count. This would be very helpful
whenever selective-display is in use.
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Sat, 04 Jun 2016 08:58:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 23675 <at> debbugs.gnu.org (full text, mbox):
> From: Robert Weiner <rsw <at> gnu.org>
> Date: Wed, 1 Jun 2016 10:23:56 -0400
>
> Often when particular lines are hidden, one wants to count only visible lines. count-lines presently cannot do
> this. XEmacs has for a long-time had count-lines take an optional 3rd parameter flag which if non-nil, ignores
> invisible lines in the line count. This would be very helpful whenever selective-display is in use.
Patches are welcome to add this.
Also, we have forward-visible-line, which might prove instrumental.
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Mon, 06 Jun 2016 23:37:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 23675 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Attached is a patch to add this feature based on 25.0.94. Please consider
applying it to Emacs. I have also included the full new version of the
function below.
---------------------
(defun count-lines (start end &optional ignore-invisible-lines-flag)
"Return number of lines between START and END.
This is usually the number of newlines between them,
but can be one more if START is not equal to END
and the greater of them is not at the start of a line.
With optional IGNORE-INVISIBLE-LINES-FLAG non-nil,
lines collapsed with selective-display are excluded
from the line count."
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(cond ((and (not ignore-invisible-lines-flag) (eq selective-display
t))
(save-match-data
(let ((done 0))
(while (re-search-forward "\n\\|\r[^\n]" nil t 40)
(setq done (+ 40 done)))
(while (re-search-forward "\n\\|\r[^\n]" nil t 1)
(setq done (+ 1 done)))
(goto-char (point-max))
(if (and (/= start end)
(not (bolp)))
(1+ done)
done))))
(ignore-invisible-lines-flag
(- (buffer-size) (forward-line (buffer-size))
(let ((invisible-count 0)
prop)
(goto-char (point-min))
(while (re-search-forward "\n\\|\r[^\n]" nil t)
(setq prop (get-char-property (1- (point)) 'invisible))
(if (if (eq buffer-invisibility-spec t)
prop
(or (memq prop buffer-invisibility-spec)
(assq prop buffer-invisibility-spec)))
(setq invisible-count (1+ invisible-count))))
invisible-count)))
(t (- (buffer-size) (forward-line (buffer-size))))))))
---------------------
On Wed, Jun 1, 2016 at 10:23 AM, Robert Weiner <rsw <at> gnu.org> wrote:
>
> Often when particular lines are hidden, one wants to count only visible
lines. count-lines presently cannot do this. XEmacs has for a long-time
had count-lines take an optional 3rd parameter flag which if non-nil,
ignores invisible lines in the line count. This would be very helpful
whenever selective-display is in use.
>
[Message part 2 (text/html, inline)]
[count-lines-diff.txt (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Tue, 07 Jun 2016 15:59:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 23675 <at> debbugs.gnu.org (full text, mbox):
> From: Robert Weiner <rsw <at> gnu.org>
> Date: Mon, 6 Jun 2016 19:35:47 -0400
> Cc: emacs-devel <emacs-devel <at> gnu.org>
>
> Attached is a patch to add this feature based on 25.0.94. Please consider applying it to Emacs. I have also
> included the full new version of the function below.
Thanks.
Any reason why you didn't use forward-visible-line, which would leave
the skipping of invisible text to that function, and make your code
simpler?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Tue, 07 Jun 2016 22:19:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 23675 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Tue, Jun 7, 2016 at 11:58 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> Any reason why you didn't use forward-visible-line, which would leave
> the skipping of invisible text to that function, and make your code
> simpler?
>
Because unlike forward-line, forward-visible-line does not indicate how
many lines it failed to move when it cannot move the requested amount (of
course it should). Therefore, I could not tell when it failed to move and
would have had to add other buffer location tests. I hope that explains it
sufficiently.
Bob
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Tue, 25 Jun 2019 13:31:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 23675 <at> debbugs.gnu.org (full text, mbox):
Some comments on the patch:
Robert Weiner <rsw <at> gnu.org> writes:
> ! (defun count-lines (start end)
> "Return number of lines between START and END.
> This is usually the number of newlines between them,
> but can be one more if START is not equal to END
> ! and the greater of them is not at the start of a line."
> (save-excursion
> (save-restriction
> (narrow-to-region start end)
> (goto-char (point-min))
> ! (if (eq selective-display t)
> ! (save-match-data
Hm... the current version of the function doesn't mention
selective-display at all, which it probably should, anyway...
> ! (defun count-lines (start end &optional ignore-invisible-lines-flag)
I think we tend to avoid -flag in arguments these days?
> ! With optional IGNORE-INVISIBLE-LINES-FLAG non-nil,
> ! lines collapsed with selective-display are excluded
> ! from the line count."
This is very confusing, because it only mentions selective-display when
this flag is non-nil, but not what the flag does otherwise.
> ! (cond ((and (not ignore-invisible-lines-flag) (eq selective-display t))
> ! (save-match-data
[...]
> ! (while (re-search-forward "\n\\|\r[^\n]" nil t)
And the selective-display bit saves match data and the
non-selective-display one doesn't.
But other than that, I think this sounds like a useful addition.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Tue, 25 Jun 2019 15:27:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 23675 <at> debbugs.gnu.org (full text, mbox):
>> ! (defun count-lines (start end)
>> "Return number of lines between START and END.
>> This is usually the number of newlines between them,
>> but can be one more if START is not equal to END
>> ! and the greater of them is not at the start of a line."
>> (save-excursion
>> (save-restriction
>> (narrow-to-region start end)
>> (goto-char (point-min))
>> ! (if (eq selective-display t)
>> ! (save-match-data
>
> Hm... the current version of the function doesn't mention
> selective-display at all,
That's because the t value of selective-display has been described as
obsolete in the manual since 2013.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Tue, 25 Jun 2019 15:30:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 23675 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> Hm... the current version of the function doesn't mention
>> selective-display at all,
>
> That's because the t value of selective-display has been described as
> obsolete in the manual since 2013.
Aha. But then the new doc string (if we apply this patch) shouldn't
either, I guess...
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Tue, 25 Jun 2019 15:34:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 23675 <at> debbugs.gnu.org (full text, mbox):
>> Any reason why you didn't use forward-visible-line, which would leave
>> the skipping of invisible text to that function, and make your code
>> simpler?
> Because unlike forward-line, forward-visible-line does not indicate how
> many lines it failed to move when it cannot move the requested amount (of
> course it should).
Then let's fix that.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Tue, 11 Aug 2020 14:54:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 23675 <at> debbugs.gnu.org (full text, mbox):
Robert Weiner <rsw <at> gnu.org> writes:
> Attached is a patch to add this feature based on 25.0.94. Please
> consider applying it to Emacs. I have also included the full new
> version of the function below.
There were some comments about implementing this based on other
functions, but that was never followed up, so I went ahead and applied
the patch to Emacs 28. Further improvements are left as an exercise for
the reader.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Tue, 11 Aug 2020 14:55:01 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 28.1, send any further explanations to
23675 <at> debbugs.gnu.org and Robert Weiner <rsw <at> gnu.org>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Tue, 11 Aug 2020 14:55:01 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 09 Sep 2020 11:24:11 GMT)
Full text and
rfc822 format available.
bug unarchived.
Request was from
"J.P." <jp <at> neverwas.me>
to
control <at> debbugs.gnu.org
.
(Fri, 04 Aug 2023 12:55:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Sat, 05 Aug 2023 00:36:02 GMT)
Full text and
rfc822 format available.
Message #43 received at 23675 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Closed in 2020 (Emacs 28).
Perhaps I'm not understanding how the `ignore-invisible-lines' parameter
for `count-lines' is supposed to work, but it doesn't seem to make the
function consider `invisible' text properties that have lists as values.
I bring this up because ERC will likely be needing a line-counting
function that's list-aware, at least in the manner shown in the attached
tests. The change to `count-lines' accompanying these tests was merely
lifted from `forward-visible-line' to make them pass, but it's quite
possibly flawed and/or incomplete. If a proper solution ever emerges to
address this, hopefully it'll come at the hands of someone better
informed than I in the ways of Emacs invisibility. In the meantime
(2023), ERC will likely be doing its own subpar rendition unless someone
takes up the challenge for 30.1 (and Compat agrees to adopt it). Thanks.
[0001-POC-Honor-invisible-text-prop-list-values-in-count-l.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Sat, 05 Aug 2023 06:33:02 GMT)
Full text and
rfc822 format available.
Message #46 received at 23675 <at> debbugs.gnu.org (full text, mbox):
> Cc: emacs-erc <at> gnu.org, rsw <at> gnu.org
> From: "J.P." <jp <at> neverwas.me>
> Date: Fri, 04 Aug 2023 17:35:27 -0700
>
> Perhaps I'm not understanding how the `ignore-invisible-lines' parameter
> for `count-lines' is supposed to work, but it doesn't seem to make the
> function consider `invisible' text properties that have lists as values.
> I bring this up because ERC will likely be needing a line-counting
> function that's list-aware, at least in the manner shown in the attached
> tests. The change to `count-lines' accompanying these tests was merely
> lifted from `forward-visible-line' to make them pass, but it's quite
> possibly flawed and/or incomplete. If a proper solution ever emerges to
> address this, hopefully it'll come at the hands of someone better
> informed than I in the ways of Emacs invisibility. In the meantime
> (2023), ERC will likely be doing its own subpar rendition unless someone
> takes up the challenge for 30.1 (and Compat agrees to adopt it). Thanks.
This is OK for master, but please don't use cl-incf in simple.el, as
there's no real need to do so there.
Stefan, any comments?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#23675
; Package
emacs
.
(Sun, 06 Aug 2023 13:04:02 GMT)
Full text and
rfc822 format available.
Message #49 received at 23675 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
>> Cc: emacs-erc <at> gnu.org, rsw <at> gnu.org
>> From: "J.P." <jp <at> neverwas.me>
>> Date: Fri, 04 Aug 2023 17:35:27 -0700
>>
>> Perhaps I'm not understanding how the `ignore-invisible-lines' parameter
>> for `count-lines' is supposed to work, but it doesn't seem to make the
>> function consider `invisible' text properties that have lists as values.
>> I bring this up because ERC will likely be needing a line-counting
>> function that's list-aware, at least in the manner shown in the attached
>> tests. The change to `count-lines' accompanying these tests was merely
>> lifted from `forward-visible-line' to make them pass, but it's quite
>> possibly flawed and/or incomplete. If a proper solution ever emerges to
>> address this, hopefully it'll come at the hands of someone better
>> informed than I in the ways of Emacs invisibility. In the meantime
>> (2023), ERC will likely be doing its own subpar rendition unless someone
>> takes up the challenge for 30.1 (and Compat agrees to adopt it). Thanks.
>
> This is OK for master, but please don't use cl-incf in simple.el, as
> there's no real need to do so there.
Actually, it's looking like `count-screen-lines' will suit ERC's needs.
Thanks anyway for taking a peek, and apologies for the noise.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 04 Sep 2023 11:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 232 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.