-
-
Notifications
You must be signed in to change notification settings - Fork 564
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
🪲 Not possible to correctly use as Editor for Git commands #678
Comments
My understanding is this how git works. It launches a process and waits for it to exit.
Can you define what "weird things" are happening?
Again this is my expectation that this is how git works.
Correct because the Notepad Next process is still running.
Interesting idea. Sounds like there would have to be some interprocess communication going on for git to wait on process That being said it sounds quite intricate and hard to implement cross platform this way. With Notepad++ you can pass in the correct command line parameters to launch it in a stand alone isolated way. See this doc This way wouldn't be super easy with Notepad Next but would probably be a better way to implement it. |
All that being said if there was some way to signal git rather than the extra interprocess communication I'd be willing to consider that but currently that's outside my realm of expertise :) |
Correct.
Never mind it, probably unimportant and not directly related to NotepadNext. Git deletes the rebase to-do file as soon as it processes it so this could be an anomaly of conflict between Git deleting it and NotepadNext reading it. I tried it with VS Code and the file just turned up blank.
Yes, this is how most editors tackle this scenario. The CLI binary slave also doubles as a convenient way to launch the editor from Terminal without have to create a custom alias for the
In my experience, it looks like a CLI slave binary is only needed on macOS to launch an application (
That is the odd one of the bunch, as the others simply have a CLI binary slave with a It doesn't look like NotepadNext has any capability of opening a second window in another process. Even if I use It looks like CotEditor is the closest to the ideal solution.
I think for now I'll use CotEditor for giving text-file based input for Git commands, though I won't be using it as my default text editor.
The only way to signal Git is to kill the process that Git launched as its editor. |
I have to add that it's a shame that I can't use NotepadNext for this purpose because it launches really fast from "not running" when invoked in Terminal using If you can fix this somehow (perhaps make a little CLI binary slave for waiting on a tab), add support for Dark Mode, and optionally introduce a way to add syntax highlighting for Git's user input files, it will be perfect. |
True, but the implementation is likely much easier than other alternatives.
I'm willing to consider a pull request if you have any tangible solutions. I have a couple shots in the dark I can try but doubt they would result in a valid solution. The other difficulty is that this application intentionally tries to run in a "single instance" mode. A cross-platform solution will likely be difficult to create from scratch. I also only use Window's so I wouldn't be able to test on other operating systems. |
Not sure if it's possible to run a second instance of a Is a CLI binary really more difficult? Maybe Qt has some way for a CLI binary to link with the running application and signal back and forth?
Absolutely clueless when it comes to C++ and Qt, etc. Sorry.
I can help with some testing on macOS. |
Building a cli binary is not, but doing the communication between the processes is the challenge. I'm not saying it's impossible, I've just not had any experience doing this or know the best way to go about implementing it. |
I don't have deep knowledge of C++ but from what I know and what I just looked up on Stack Overflow, you should be able to do this:
All OS will have process ID and Linux is also UNIX based so SIGTERM or SIGINT will work. Windows might need some specialized way to kill process, I'm not sure. I know that any binary in Linux and any Windows exe file can be invoked with arguments, but for macOS does Anyway that's it. That's the whole idea based on this: https://stackoverflow.com/a/69789890 (check out the link in the answer). |
This is one potential way. But I'm not confused on what the process is. What I dont know is how to implement it. For example a few questions I have (I know you don't have the answers either, but you have no technical details in your proposal):
But how does it do this? QSharedMemory (which has issues with newer versions of Qt)? QLocalSocket? Some other way?
Does Qt have a cross platform way to do this? If the implementation is OS specific that leads to more possible issues to make sure it is tested cross platform.
Git also needs to know if the file was saved or not. So it needs a specific return value. Again, I understand the process just not the technical details or best way to implement it. The other thing that makes this difficult is the SingleApplication library that ensures only 1 Notepad Next process can exist, which means a secondary instance will kill itself off currently. |
Don't know any of those Qt specific stuff, but I imagine that the CLI binary is a very simple binary which invokes this shell command: open -a Notepadnext --args --invoker-pid 12345 /path/to/file If I do
In Windows it should be similar to doing So I just imagine that Notepadnext just has to do one more thing:
The
Not sure about Qt, but I imagine the commands described in this page are cross-platform. Aren't they?
No need. This is a misunderstanding. Neither the CLI binary process nor the NotepadNext process need to directly communicate with Git in any way. It's actually indirect. Git only waits for the invoked editor process to terminate. Once the process terminates, Git takes the file and continues doing its thing. It doesn't care whether the user chose to save the file or not save it. If the user discarded their changes, Git simply reads the file as it was last saved. (In fact, the user can close the file without making any changes at all, and that's also a perfectly valid response.) This implementation is actually use-case-agnostic. You provide the feature without knowing how it is used and who is using it. In fact, Git is only one example use-case. Another is that I could simply invoke |
In addition to the above comment:
I should clarify that while the CLI binary stub doesn't need to tell Git about whether the file was saved or not, it should still exit with a "non-zero" error code (usually just
When the CLI binary process exits with a non-zero error code, Git will also halt its processing and give an error to the user that the editor could not be launched. |
Additional comment:
So it should be: open -a Notepadnext --args --invoker-pid 12345 /path/to/file Whatever comes after Windows doesn't need this |
Do any of those comments make any sense? I'm no expert in any of these, but I'm only speaking from my experience as a software engineer. |
The problem is I don't either. Overall it makes sense but I don't know how to best do this with Qt. And the single instance library makes this more difficult. So I won't be able to implement this myself. Hopefully someone else will be able to |
Operating System and Version
macOS Sonoma 14.7.1 (23H222)
Distribution
brew
Description
I have tried configuring NotepadNext as the Editor for Git commands:
This doesn't work because:
open
command returns immediately, thus Git cannot wait for user input.This kind of works:
But the problem is:
Is there another way? (The way TextMate does this kind of thing is, it has its own CLI binary which I can configure as the editor:
/usr/local/bin/mate -w
and it signals to Git that I'm done when I close the tab.)PS: An alternative way to configure editor is to edit your
.zshrc
or.bashrc
file to add this:But the problems described above will persist.
Steps to Reproduce
commit
andrebase
typically do this.)Additional Details
No response
The text was updated successfully, but these errors were encountered: