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

Output the contents of the buffer, when connected to a pipe #4

Open
iqbalansari opened this Issue Apr 26, 2017 · 5 comments

Comments

3 participants
@iqbalansari
Contributor

iqbalansari commented Apr 26, 2017

Just a thought perhaps eless can output the current buffer, when its output is pipe, this way it can part of a larger pipeline.

The use case I am thinking of is using eless, as an interactive replacement for likes of sed or awk allowing user to transform the text before it goes to next thing in the pipeline.

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Apr 26, 2017

That thought did cross my mind, but as you see in the code, I quit the script if one tries to do that. I have never needed to edit something interactively inbetween a pipe.

Also this would be a feature-creep from the emacs view-mode and less-like functionality. I am on the fence about whether we should add this functionality.

@alphapapa

This comment has been minimized.

Contributor

alphapapa commented Apr 26, 2017

It's a really neat idea.

@iqbalansari

This comment has been minimized.

Contributor

iqbalansari commented Apr 29, 2017

@kaushalmodi As much as I would to have this feature, I certainly appreciate your concerns regarding feature-creep.

Though if you think of it Emacs is ultimately a tool to manipulate text, so it makes sense to allow users to use it transform contents in a pipeline. I personally have been in situations in past where the input was too complex for my awk/sed foo and I had to copy the text to a file, edit the file using Emacs (to make it easier for other tools to parse) and then use the transformed file as input for rest of the pipeline, I would have found eless handy in such cases, just my two cents, but then as I said I totally okay with you not adding it.

One last thing though could you update eless to behave like standard less when it's output is connected to the pipe? On my system less just passes whatever input it gets directly to the output pipe. So the following command

echo "Line 1\nLine 2" | less | xargs -I text echo text

outputs

Line 1
Line 2

Thanks

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Apr 29, 2017

I personally have been in situations in past where the input was too complex for my awk/sed foo and I had to copy the text to a file, edit the file using Emacs (to make it easier for other tools to parse) and then use the transformed file as input for rest of the pipeline

I would have just used emacs to do the whole thing, and even end up writing an elisp snippet for the just-in-case event that I might need to repeat that :)

But yes, that use case does make sense. Let me find some time next week to look into this. It's probably as simple as doing (message (buffer-substring-no-properties (point-min) (point-max))) at the very end (kill-emacs-hook?) if it's detected that output is going to a pipe. The message form can be executed using a bash script var in the embedded elisp just as I am doing with the ansi stuff.

I would have found eless handy in such cases, just my two cents, but then as I said I totally okay with you not adding it.

While I look into this, feel free to provide a PR. If the solution is as simple as it think it is, then there's no harm implementing it.

One last thing though could you update eless to behave like standard less when it's output is connected to the pipe? On my system less just passes whatever input it gets directly to the output pipe. So the following command

echo "Line 1\nLine 2" | less | xargs -I text echo text
outputs

I am not at a computer at the moment. What does that do? Does it open up less in-between, or does less pass things forward and not show up at all? (Update: My google-fu is failing me. I don't find any useful application of this except for probably adding just line numbers. For that too, people suggested using nl instead of less.)

If it is the latter then emacs would need to be launched in batch mode. That would be even bigger deviation from the goal of this project.

@iqbalansari

This comment has been minimized.

Contributor

iqbalansari commented Apr 29, 2017

I am not at a computer at the moment. What does that do? Does it open up less in-between, or does less pass things forward and not show up at all?

Nothing useful at all actually, I was just trying to show less's default behavior when its output is connected to a pipe (just putting whatever it gets on stdin to stdout, as opposed to erring out like eless currently does).

I just thought it would be better if eless mimics less's behavior here.

I would have just used emacs to do the whole thing, and even end up writing an elisp snippet for the just-in-case event that I might need to repeat that :)

It was complicated 😄, I was fetching page extracting links from it, fetching each of those links and then in turn scrapping them for some more links and finally downloading them, quick and dirty web scrapping, I did end up writing a shell function to do this but it has a lot cuts and seds and awks in it.

While I look into this, feel free to provide a PR. If the solution is as simple as it think it is, then there's no harm implementing it.

Sure I will definitely try to implement this, thanks again for looking into this 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment