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

Use compilation-filter as subprocess filter #21

Merged
merged 1 commit into from
Jul 1, 2022

Conversation

BlankSpruce
Copy link
Contributor

No description provided.

justl.el Outdated
@@ -60,12 +60,23 @@
;;
;; You can also control the width of the RECIPE column in the justl
;; buffer via `justl-recipe width`. By default it has a value of 20.
;;
;; You can enable coloring of the output by adding proper hook to
;; `compilation-filter-hook`. For Emacs older than 28.1 you need to
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realize that this was only available for 28.1. I guess we would need some sort of conditional then with xterm-color fixing the actual bug too...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you consider using compilation-filter then I don't know how to approach that. On one hand I understand that you would rather preserve already existing functionality but on the other hand this package shouldn't add its own functions to compilation-filter-hook because it'll affect things outside of the package (like M-x compile). And if the package doesn't register such function itself then the user needs to discover it themselves which brings us to back to square one.

Another way would be offering customization point on the filter with the suggestion about compilation-filter. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify the point on 28.1: as in the note ansi-color provides means to colorize compilation buffers but before 28.1 there was no convenient function definition so you had to define this small function yourself. I'd say it's not a bad trade-off especially when the README and doc comment provides example how to do that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emacs has the variable emacs-version. We need to use that and switch to appropriate version of compilation-filter-hook based on that to support both the versions.

Let me know if you have more questions. Alternatively if you want me to work on top of your work, let me know and I can take that up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm aware of emacs-version but that's not the main point of my observation. The thing is I'm of the opinion that this package should never, on its own, register its own functions to compilation-filter-hook because this customization point is outside of the scope of the package. We can use compilation-filter to have unified behavior between compile and justl-exec-recipe but customization of that filter should be on the user side.

If you'd rather have this package automatically register function to colorize the output then I'd opt into either of these solutions to mimic the behaviour of compilation-filter:

  • providing customization point on process filter (named like justl-output-filter)
  • providing hook on predefined filter (named something like justl-output-filter-hook)

Since you're maintainer it's up to you to decide and I'll try to implement that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to handle both - the colors as well as proper carriage return handling ?

I just checked eshell and it seems to be doing both jobs fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed another approach. Let me know what you think about that.

I've tested it with justfile:

foo:
    #!/bin/bash
    printf "1/5\r"
    sleep 1
    printf "2/5\r"
    sleep 1
    printf "3/5\r"
    sleep 1
    printf "4/5\r"
    sleep 1
    printf "5/5\n"
    sleep 1
    printf "DONE\n"

bar:
    #!/bin/bash
    printf "\x1B[0mThis is normal text\n"
    printf "\x1B[31mThis is red text\n"
    printf "\x1B[32mThis is green text\n"
    printf "\x1B[34mThis is blue text\n"
    printf "\x1B[0mThis is normal text\n"

foo target:
image
bar target:
image

Copy link
Owner

@psibi psibi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! This looks good to me. Can you see why the tests are failing ?

I don't mind disabling it for 26.3 if we aren't able to make things work.

Also, do you mind adding a test for the carriage return ? (If you want do that as part of separate PR, it's fine and I can merge this once the CI passes green)

justl.el Outdated
@@ -90,6 +95,12 @@
:type 'integer
:group 'justl)

(defcustom justl-process-filter
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this anymore ? Since your implementation now handles both, I'm assuming it's not required anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it's nice to have customization point. For instance it's not impossible to use compilation-filter as I originally showcased and someone might have some specific hook for compilation-filter.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would want to avoid customization unless it's really required.

For instance it's not impossible to use compilation-filter as I originally showcased and someone might have some specific hook for compilation-filter.

In the context of justfiles and it's execution, do you see any reason why someone might want to provide their own hook ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the point above I don't have explicit example. I'll remove the customization point then.

README.org Outdated
@@ -69,6 +69,8 @@ W => open eshell without executing
change the /justl-executable/ variable to set any explicit path.
- You can also control the width of the RECIPE column in the justl
buffer via /justl-recipe width/. By default it has a value of 20.
- You can enable customize how output from *just* is processed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto for this too.

@BlankSpruce
Copy link
Contributor Author

Yes, I'll prepare the test and check 26.3 regression later today. I just wanted to discuss this proof of concept before doing that work.

Copy link
Owner

@psibi psibi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Nice work on the test. I'm merging this PR.

Can you do this in a follow up PR: Update the changelog and also add test for a just target involving color (the one you have shown in the comment) ? If not, I can probably add that up in the coming days.

@psibi psibi merged commit f9844fa into psibi:master Jul 1, 2022
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