Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first_line_not_read is 0 for new buffer with a message #2029

Open
trygveaa opened this issue Oct 8, 2023 · 2 comments
Open

first_line_not_read is 0 for new buffer with a message #2029

trygveaa opened this issue Oct 8, 2023 · 2 comments
Assignees
Labels
bug Unexpected problem or unintended behavior

Comments

@trygveaa
Copy link
Contributor

trygveaa commented Oct 8, 2023

Bug summary

If you create a new buffer and print a line to it, without switching to it, first_line_not_read is 0. Shouldn't it be 1 since you haven't read the line?

Steps to reproduce

1. Run weechat -t -r '/buffer add 2; /command -buffer core.2 * /print 1'
2. Load hdata.py and see that first_line_not_read for the buffer is 0

Current behavior

first_line_not_read is 0 for a new unread buffer with only one line.

Expected behavior

It's 1.

Suggested solutions

Set first_line_not_read to 1 when the first line is printed in a buffer.


  • WeeChat version: 4.0.5
  • OS, distribution and version: Arch Linux
  • Terminal: kitty
  • Terminal multiplexer (screen/tmux/…/none): none
@trygveaa trygveaa added the bug Unexpected problem or unintended behavior label Oct 8, 2023
@trygveaa
Copy link
Contributor Author

trygveaa commented Oct 8, 2023

This is more apparent if you enable weechat.look.read_marker_always_show. Then the read marker will be below the first line when you switch to the buffer, even though you've never read the line.

@flashcode flashcode self-assigned this Oct 9, 2023
@trygveaa
Copy link
Contributor Author

trygveaa commented Oct 9, 2023

We discussed changing first_line_not_read on IRC. After some back and forth regarding having one or two variables to track the read state, we realized that in order to support the weechat.look.read_marker_always_show with the behavior it has today we need two variables. That behavior is that when you switch to a buffer and a new line is printed, the marker should remain after the same like when the option is on and not be shown when the option is off.

@flashcode proposed replacing the first_line_not_read variable with a unread_lines variable. I think it should behave this way:

  1. Buffer is created (not displayed): last_read_line=NULL, unread_lines=0
  2. Line is printed: last_read_line=NULL, unread_lines=1
  3. Buffer is switched to: last_read_line=NULL, unread_lines=1
  4. Line is printed: last_read_line=NULL, unread_lines=1
  5. Buffer is switched from: last_read_line=line1, unread_lines=0
  6. Buffer is switched to: last_read_line=line1, unread_lines=0
  7. Line is printed: last_read_line=line1, unread_lines=0
  8. Buffer is switched from: last_read_line=line2, unread_lines=0

So unread_lines is set to 1 when a line is printed in a buffer that isn't displayed, kept unchanged when a line is printed to the buffer that is displayed and set to 0 when you switch away from a buffer. last_read_line remains at the same value when you switch to a buffer (so not set to NULL like it is today when read_marker_always_show is off) and is updated to the last line when you switch away from a buffer.

When you run /buffer set unread, last_read_line is updated to the new last read line (depending on the command arguments) and unread_lines is set to 1.

When read_marker_always_show is on the read marker is shown after last_read_line (or as the first line if it's NULL) and unread_lines can be ignored. When read_marker_always_show is off the read marker is only shown when unread_lines is 1, but otherwise it behaves the same.

@flashcode flashcode added this to the 4.2.0 milestone Oct 10, 2023
@flashcode flashcode removed this from the 4.2.0 milestone Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants