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

Emacs: neil.el should work with compound commands #247

Merged
merged 7 commits into from
Dec 9, 2024

Conversation

agzam
Copy link
Contributor

@agzam agzam commented Dec 7, 2024

@agzam agzam force-pushed the neil-executable-path-compound-command branch from 98fa7a2 to cfc9cc4 Compare December 7, 2024 20:49
@agzam agzam force-pushed the neil-executable-path-compound-command branch from cfc9cc4 to 0227ef3 Compare December 7, 2024 20:53
@agzam agzam force-pushed the neil-executable-path-compound-command branch from cd22f91 to 983488a Compare December 7, 2024 21:23
@agzam agzam force-pushed the neil-executable-path-compound-command branch from 983488a to cb36308 Compare December 7, 2024 21:30
@agzam agzam marked this pull request as ready for review December 7, 2024 21:32
I forgot that it could be not only 'clj' but 'clojure' as well
@agzam agzam force-pushed the neil-executable-path-compound-command branch from 97c5c90 to b0be3e5 Compare December 7, 2024 21:52
CHANGELOG.md Show resolved Hide resolved
@borkdude
Copy link
Contributor

borkdude commented Dec 7, 2024

Could you maybe explain the fix? Why is there a specific regex about clj/clojure?
Does another command like bb -Sdeps '...' -m babashka.neil not work?
In lsp-mode you can define lsp-clojure-custom-server-command to be a list of strings, would something similar not work here?

https://github.com/emacs-lsp/lsp-mode/blob/c3be413f8545a26ad0334e1dd2b7e65c448d9f22/clients/lsp-clojure.el#L41

@agzam
Copy link
Contributor Author

agzam commented Dec 7, 2024

Hmm... good point. So, basically, I'm trying to resolve the executable path, i.e. if it's set to "clj -M:neil", it should become something like "/usr/bin/clj -M:neil". But (executable-find "clj -M:neil") => nil - it is not smart enough. So I need to resolve only the first part and then stitch the cmd-line string together.

I suppose I can make it work for any generic command - trying to resolve the first part of it.

@agzam agzam force-pushed the neil-executable-path-compound-command branch from 595c865 to c328615 Compare December 7, 2024 22:33
@a13
Copy link
Contributor

a13 commented Dec 8, 2024

@agzam Just in case, shell-command-to-string works even if I use a command name without the full path, it has to be in $PATH though (as well as with executable-find case), so the solution looks a bit overcomplicated to me.

@agzam
Copy link
Contributor Author

agzam commented Dec 8, 2024

the solution looks a bit overcomplicated to me.

executable-find pattern is quite common for this kind of cases, shell-commands may fail if:

  • The executable isn't in the current PATH
  • The PATH env in Emacs differs from your shell's PATH

executable-find helps with:

  • minimizing ambiguity, resolving to the actual binary file, avoiding shell-level abstractions like aliases, functions, or built-ins, symlinked executables, systems with multiple Python/Node/etc. versions
  • you get the same binary regardless of PATH order or shell configuration

when you run (shell-command-to-string "foo"), where "foo" can't be found, the error message may differ on different systems with different shells - accurately detecting exact cause and reporting about the failure to the user requires more work.

I don't think it's an overcomplication worth simplifying.

@a13
Copy link
Contributor

a13 commented Dec 8, 2024

The executable isn't in the current PATH

in this case, most likely it isn't in exec-path either

The PATH env in Emacs differs from your shell's PATH

exec-path-from-shell helps with that a bit

minimizing ambiguity, resolving to the actual binary file, avoiding shell-level abstractions like aliases, functions, or built-ins, symlinked executables, systems with multiple Python/Node/etc. versions

Ok, but if we want to avoid the ambiguity and other shell-related problems, shell-command isn't the best solution either, why not call-process for example?

you get the same binary regardless of PATH order or shell configuration

or you don't get it at all :)

An alternative solution would be to use two defcustoms - one for the command itself and another for (optional) args. Like some other Emacs packages do.

@agzam
Copy link
Contributor Author

agzam commented Dec 8, 2024

Like I said: "I don't think it's an overcomplication worth simplifying.". If you disagree, please make another PR, we can even hold off merging this one until then. If it makes simpler, you can even do it in a nested PR.

You do know how the saying goes: "Talk is cheap, send patches". I already spent a good chunk of my Saturday to fix a problem you pulled out of thin air, if the proposed solution is still not bringing any joy, please do improve it, I have no emotional attachment to this code, nor do I have any privilege to dictate how it should be structured.

In short - I probably had good reasons to put that check in place, because things were failing for me otherwise. I don't remember the details anymore, but if you can prove that piece is really not needed - the best way to prove that is with code. Otherwise we may get bogged down debating for a long time about various ways things may or may not fail.

@borkdude borkdude merged commit 935190c into babashka:main Dec 9, 2024
4 checks passed
@borkdude
Copy link
Contributor

borkdude commented Dec 9, 2024

Thanks a lot @agzam for your time and contributions!

I think I should have asked first why @a13 wasn't using babashka to run neil which makes the most sense and then we probably wouldn't even have ended up here, but it's good to have this fixed anyway.

@agzam agzam deleted the neil-executable-path-compound-command branch December 9, 2024 15:03
@agzam
Copy link
Contributor Author

agzam commented Dec 9, 2024

@a13 upon revisiting my own comment, I just realized how awfully angry it may sound for the reader on the other side. I'm sorry, never was my intent. I just want to emphasize, there's no reluctance from me for any change - if you feel anything can be improved, of course, I will happily review any proposals, I just don't like mincing words when something can be better expressed with code. The last thing I would ever want is to make anyone feel discouraged. Cheers.

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.

3 participants