Skip to content

Fix tabs not preserved in raw mode#620

Merged
gwsw merged 1 commit into
gwsw:masterfrom
mohd-akram:fix-raw-tabs
May 1, 2025
Merged

Fix tabs not preserved in raw mode#620
gwsw merged 1 commit into
gwsw:masterfrom
mohd-akram:fix-raw-tabs

Conversation

@mohd-akram

Copy link
Copy Markdown
Contributor

No description provided.

@gwsw

gwsw commented Apr 30, 2025

Copy link
Copy Markdown
Owner

Can you explain the motivation for this change? Normally less does not output tabs, but can be configured to do so via the -U option. In that case, currently less configures the tty driver to expand tabs to spaces. This PR configures the driver to output raw tabs instead. I think an argument could be made for either behavior. I can also see an argument to leave the TAB bits unchanged so that the tty driver does whatever the user has configured it to do outside less.

@mohd-akram

Copy link
Copy Markdown
Contributor Author

The primary motivation is to be able to copy diffs when eg. using less as a pager for git (#152).

I think an argument could be made for either behavior.

IMO this behavior is more useful because the current behavior is a no-op for tabs in raw mode, and if one still wants expansion in raw mode, they can get it with --proc-tab. I also noticed the following comment, so it seems this was the intention:

less/screen.c

Line 373 in 26cfc73

* 4. \t is NOT expanded into spaces.

I can also see an argument to leave the TAB bits unchanged so that the tty driver does whatever the user has configured it to do outside less.

That's what my patch did initially, but then I saw:

less/screen.c

Line 631 in 26cfc73

s.sg_flags &= ~(ECHO|XTABS);

I guess that line would also need to be tweaked? I don't have a strong opinion on this part tbh, and since the user can control it, it doesn't hurt.

@gwsw

gwsw commented Apr 30, 2025

Copy link
Copy Markdown
Owner

I think the modified patch is ok. It was clearly wrong for the behavior to be different depending on whether TCGETA or TIOCGETP is supported.

However, I think the change should be made only to screen.c, not subsearch.lt nor term.c. The subsearch.lt file is not source code, it is just using an old copy of screen.c as a text file for one of the tests. And in term.c which is part of the lesstest program, the behavior should be deterministic, not dependent on how the user has set his terminal. The exact behavior (tabs expanded or not) doesn't really matter, but it does matter that the behavior is the same for every user, regardless of their tty configuration.

@mohd-akram

Copy link
Copy Markdown
Contributor Author

That makes sense. Updated the patch to only change screen.c.

@gwsw gwsw merged commit 5cab95a into gwsw:master May 1, 2025
@mohd-akram mohd-akram deleted the fix-raw-tabs branch May 1, 2025 18:35
dscho added a commit to dscho/MSYS2-packages that referenced this pull request May 20, 2025
Release notes (https://www.greenwoodsoftware.com/less/news.678.html):

Version 678 was released for beta testing on 2 May 2025, and was
released for general use on 17 May 2025.

These are the differences between [version
668](https://www.greenwoodsoftware.com/less/news.668.html) and version
678:

-   Treat -r in LESS environment variable as -R.
-   Add ESC-j and ESC-k commands ([github
    msys2#560](gwsw/less#560)).
-   Add --no-paste option ([github
    msys2#523](gwsw/less#523)).
-   Add --no-edit-warn option ([github
    msys2#513](gwsw/less#513)).
-   Add --form-feed option ([github
    msys2#496](gwsw/less#496)).
-   Add ESC-b command ([github
    msys2#615](gwsw/less#615)).
-   Make TAB complete option name in -- command ([github
    msys2#531](gwsw/less#531)).
-   Update the file size on an attempt to go past end of file.
-   Make -R able to pass through any OSC escape sequences, not just OSC
    8 ([github msys2#504](gwsw/less#504)).
-   Setting LESS_IS_MORE=0 now disables "more" compatibility even if
    invoked via a file link named "more" ([github
    msys2#500](gwsw/less#500)).
-   Pass through escape sequences in prompts even if -R is not set.
-   Add LESS_SHELL_LINES to support shell prompts which use more than
    one line ([github msys2#514](gwsw/less#514)).
-   Add LESSANSIOSCALLOW to define OSC types which may be passed
    through.
-   Add LESSANSIOSCCHARS to define non-standard OSC intro chars.
-   Add LESS_SIGUSR1 to define user signal handler ([github
    msys2#582](gwsw/less#582)).
-   Add mouse and mouse6 commands to lesskey ([github
    msys2#569](gwsw/less#569)).
-   Improve behavior of ^O^N and ^O^P commands.
-   Leave stty tabs setting unchanged ([github
    msys2#620](gwsw/less#620)).
-   Fix unexpected behavior when entering a partial command followed by
    a valid command ([github
    msys2#543](gwsw/less#543)).
-   Fix bug when coloring prompt string with SGR sequences ([github
    msys2#516](gwsw/less#516)).
-   Fix bug when searching for text near an invalid UTF-8 sequence
    ([github msys2#542](gwsw/less#542)).
-   Fix display bug when file contains ESC followed by NUL ([github
    msys2#550](gwsw/less#550)).
-   Fix bug when using +:n +:p +:x or +:d on the command line ([github
    msys2#552](gwsw/less#552)).
-   Fix bug with --no-number-headers when header is not at start of file
    ([github msys2#566](gwsw/less#566)).
-   Fix bug where lesstest fails if window is resized ([github
    msys2#570](gwsw/less#570)).
-   Fix bug using "configure --with-secure=no" ([github
    msys2#584](gwsw/less#584)).
-   Fix bug using multibyte command chars ([github
    msys2#595](gwsw/less#595)).
-   Fix auto_wrap setting on Windows ([github
    msys2#497](gwsw/less#497)).
-   Fix two bugs using ^S search modifier ([github
    msys2#605](gwsw/less#605)).
-   Fix bug searching for UTF-8 strings with the PCRE2 library ([github
    msys2#610](gwsw/less#610)).
-   Fix bug highlighting OSC 8 links when opening a new file.
-   Fix bug when & filtering is active ([github
    msys2#618](gwsw/less#618)).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
lazka pushed a commit to msys2/MSYS2-packages that referenced this pull request May 20, 2025
Release notes (https://www.greenwoodsoftware.com/less/news.678.html):

Version 678 was released for beta testing on 2 May 2025, and was
released for general use on 17 May 2025.

These are the differences between [version
668](https://www.greenwoodsoftware.com/less/news.668.html) and version
678:

-   Treat -r in LESS environment variable as -R.
-   Add ESC-j and ESC-k commands ([github
    #560](gwsw/less#560)).
-   Add --no-paste option ([github
    #523](gwsw/less#523)).
-   Add --no-edit-warn option ([github
    #513](gwsw/less#513)).
-   Add --form-feed option ([github
    #496](gwsw/less#496)).
-   Add ESC-b command ([github
    #615](gwsw/less#615)).
-   Make TAB complete option name in -- command ([github
    #531](gwsw/less#531)).
-   Update the file size on an attempt to go past end of file.
-   Make -R able to pass through any OSC escape sequences, not just OSC
    8 ([github #504](gwsw/less#504)).
-   Setting LESS_IS_MORE=0 now disables "more" compatibility even if
    invoked via a file link named "more" ([github
    #500](gwsw/less#500)).
-   Pass through escape sequences in prompts even if -R is not set.
-   Add LESS_SHELL_LINES to support shell prompts which use more than
    one line ([github #514](gwsw/less#514)).
-   Add LESSANSIOSCALLOW to define OSC types which may be passed
    through.
-   Add LESSANSIOSCCHARS to define non-standard OSC intro chars.
-   Add LESS_SIGUSR1 to define user signal handler ([github
    #582](gwsw/less#582)).
-   Add mouse and mouse6 commands to lesskey ([github
    #569](gwsw/less#569)).
-   Improve behavior of ^O^N and ^O^P commands.
-   Leave stty tabs setting unchanged ([github
    #620](gwsw/less#620)).
-   Fix unexpected behavior when entering a partial command followed by
    a valid command ([github
    #543](gwsw/less#543)).
-   Fix bug when coloring prompt string with SGR sequences ([github
    #516](gwsw/less#516)).
-   Fix bug when searching for text near an invalid UTF-8 sequence
    ([github #542](gwsw/less#542)).
-   Fix display bug when file contains ESC followed by NUL ([github
    #550](gwsw/less#550)).
-   Fix bug when using +:n +:p +:x or +:d on the command line ([github
    #552](gwsw/less#552)).
-   Fix bug with --no-number-headers when header is not at start of file
    ([github #566](gwsw/less#566)).
-   Fix bug where lesstest fails if window is resized ([github
    #570](gwsw/less#570)).
-   Fix bug using "configure --with-secure=no" ([github
    #584](gwsw/less#584)).
-   Fix bug using multibyte command chars ([github
    #595](gwsw/less#595)).
-   Fix auto_wrap setting on Windows ([github
    #497](gwsw/less#497)).
-   Fix two bugs using ^S search modifier ([github
    #605](gwsw/less#605)).
-   Fix bug searching for UTF-8 strings with the PCRE2 library ([github
    #610](gwsw/less#610)).
-   Fix bug highlighting OSC 8 links when opening a new file.
-   Fix bug when & filtering is active ([github
    #618](gwsw/less#618)).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants