pymander / vfish

Emacs vterm plugin for Fish shell
6 stars 0 forks source link

[feature] add blocking find-file that can be used as EDITOR #1

Open bo-tato opened 1 year ago

bo-tato commented 1 year ago

thanks for this nice vterm/fish integration. I wanted to also have it open in an emacs buffer to edit when I use fish commands like M-v to edit the current line, or funced to edit a function. Just setting vf as EDITOR doesn't work with M-v for example as when the command returns it thinks you're done editing, and the command returns instantly as it's just telling emacs to open a new buffer, so I wanted a version that will block until the buffer is closed. What I did was make a script:

#!/usr/bin/env fish
vf $argv
inotifywait -e close_write (realpath "$argv")

and then set EDITOR to that, it needs to be a script rather than just a fish function as M-v will work with EDITOR as function but funced requires it to be a actual file. I'm new with both emacs and fish so I'm not really sure best way to implement this. My solution works but is hacky in that it doesn't handle the case of closing the buffer without modifying the file. Also it introduces a dependency on inotify-tools.

pymander commented 1 year ago

I really like this idea! Thank you. Let me give it some thought to see if I can come up with a solution that doesn't require inotify-tools.

bo-tato commented 1 year ago

I had one idea that doesn't require inotify-tools but it's an even worse hack than before and insecure as it'd let stuff that can output in the terminal signal processes, something like:

sleep infinity &
trap "kill $last_pid" SIGUSR1
vterm_cmd find-file-signal-on-close $fish_pid ":" (realpath "$argv")
wait sleep

then have find-file-signal-on-close set a kill-buffer-hook to send SIGUSR1 to pid

I also realized that emacsclient does block for the buffer to close, so I think the proper solution is just to run emacs in server mode and set EDITOR to emacsclient. So I think we can close this issue as it's solved by emacsclient and don't know if it can be done cleanly from just vfish