Why less -F option does not work with -S option

3

1

While trying to improve output from hg diff, I noticed that less’s -F option does not work with its -S option. Why is that happening and how can I achieve the desired effect?

Here is an extract from man:

   -F or --quit-if-one-screen
      Causes less to automatically exit if the entire file can be dis-
      played on the first screen.

   -S or --chop-long-lines
      Causes  lines  longer than the screen width to be chopped rather
      than folded.  That is, the portion of a long line that does  not
      fit  in  the  screen width is not shown.  The default is to fold
      long lines; that is, display the remainder on the next line.

Tested on less 444 and less 436.

Explanation

I was mistaken in thinking that -S will cut excess bytes. Content goes to the right of the screen.

To achieve what I wanted I could just use (...) | cut -b -80 | less -FSX.

seler

Posted 2012-05-11T10:01:48.007

Reputation: 303

Do you really want to -S? If lines are longer than your output, the remainder will just be discarded, and you will lose information in your diff. Also, since I am passing by: I hope you use the color extension to get colorized diffs. – Daniel Andersson – 2012-05-11T10:06:57.970

@Daniel: I feel that spanning long lines through multipe lines is a little bit messy. When using less if change does not show up in first 80 columns I can always temporarily expand my term window. :) – seler – 2012-05-11T10:27:27.927

Without the color extension it gets very messy, but with it I have no issues. But we are all different human beings :-) . – Daniel Andersson – 2012-05-11T11:20:25.740

@Daniel, I've never said that I do not use color extension. This question is about less, not hg. – seler – 2012-05-11T13:26:12.293

Answers

1

Works for me; less -FS exits immediately if the input can be printed on one screen without folding lines, and acts normally if scrolling (either to the right or down) is needed.

jpalecek

Posted 2012-05-11T10:01:48.007

Reputation: 453

Using less -FX fixes the problem wherein less displays no output at all if it fits on a single screen. But it creates another problem in that, if the output does not fit on a single screen, then after exiting less, all of the content that was displayed remains in the terminal buffer. The -X causes the termcap deinitialization string to not be sent to the terminal. What seems to be needed is a way to use -X conditionally with -F. – blujay – 2015-08-20T20:28:33.783

I've got less 444. Which version are you using? – seler – 2012-05-11T10:57:31.730

@seler: less 443, but I've upgraded to 444 and it behaves the same. – jpalecek – 2012-05-12T11:03:08.807

I've been testing on Debian and Xubuntu under gnome terminal. What's your system and terminal? – seler – 2012-05-14T06:25:21.810

Are you sure that in your testing file you've got lines longer than your terminals width? – seler – 2012-05-14T07:04:38.003

@seler: Yes, sure. I generate the input with echo, like this echo xxxxxxxxxxxxxxxxx | less -SF -, where I enter enough xs that they wrap over and fill the whole line. The system is Debian sid, terminal is konsole. I tried it in the console, too, and saw slight difference in the behavior: in console, less prints the file when it would fit on one screen, under konsole, it doesn't (just exits). That is, however, dependent just on the -F parameter (doesn't depend on -S). – jpalecek – 2012-05-14T22:41:32.983

try with -X option – seler – 2012-05-15T06:16:12.497

Heres a screencast showing how it behaves: http://tinypic.com/r/2s3k1/6

– seler – 2012-05-15T07:06:48.143

@seler: That's about what I see as well; when you overflowed the screen to the right, less didn't exit immediately. What do you not like about it? – jpalecek – 2012-05-15T08:22:48.787

I want it to behave as expected. Seems you've misunderstood me. :( Please edit your answer. – seler – 2012-05-15T08:44:45.183

@seler: What is "expected"? When you read the manpage Causes less to automatically exit if the entire file can be displayed on the first screen., it pretty much describes what it does; in your last invocation, the data did not fit on a page. – jpalecek – 2012-05-15T08:51:24.430

Ok. You're right. I'm wrong. Sorry. :) – seler – 2012-05-15T08:59:23.777