nvim-ghost.nvim icon indicating copy to clipboard operation
nvim-ghost.nvim copied to clipboard

Feature Request: enable automatically switching to Neovim

Open gibfahn opened this issue 3 years ago • 4 comments

Just came across this app, works ideally on my machine without dependencies.

One nice thing that vim-ghost does is automatically switching to nvim when you hit the ghost button in your browser (https://github.com/raghur/vim-ghost#auto-switching-to-vim).

Would be nice to have the same functionality in this plugin.

gibfahn avatar Mar 21 '21 15:03 gibfahn

Which OS are you on?

I had tried it once, but I couldn't get it working reliably across all platforms. When you factor in the fact that many people run neovim inside their terminals, it becomes even harder.

I am considering to look into how raghur implemented in vim-ghost, but I don't think I will be working on this before June. I am really busy till June.

tl;dr - I will try, but not now.

subnut avatar Mar 21 '21 15:03 subnut

I'm on macOS, on which I believe raghur has you set a variable like:

let g:ghost_darwin_app = 'kitty'                    " Tell vim-ghost which terminal to open.

and then to switch to the app it runs open -a kitty. There's probably something more fancy that could be done with auto-detection of the parent process of the nvim process the plugin is running in, but that seems like a lot of work.

I don't think I will be working on this before June

No urgency on my side 😁 .

gibfahn avatar Mar 22 '21 13:03 gibfahn

Just re-discovered this issue. :laughing:

I've left neovim and ghosttext long since, but I don't want to let this plugin rot unmaintained.

After reading raghur's code, it looks like this is the function he is using -

def _raise_window(self):
    try:
        if platform.system() == "Linux" and self.linux_window_id:
            subprocess.call(["xdotool", "windowactivate",
                             self.linux_window_id])
            logger.debug("activated window: %s", self.linux_window_id)
        elif platform.system() == "Windows" and self.winapp:
            logger.debug("WINDOWS: trying to raise window")
            # dragons - this is the only thing that works.
            try:
                self.winapp.windows()[0].set_focus()
                self.winapp.windows()[0].ShowInTaskbar()
            except Exception as e:
                logger.warning("Error during _raise_window, %s", e)
        elif platform.system() == "Darwin" and self.darwin_app:
            logger.debug("Darwin: trying to raise window")
            subprocess.call(["osascript", "-e",
                             'tell application "' + self.darwin_app +
                             '" to activate'])
    except Exception as e:
        # with vim yarp etc - letting an exception escape messes
        # with other plugins. so catch everything
        logger.debug("error while activating window - %s" % e)

Looks like in macOS it uses some osascript program to raise the window. I'll have to take a look


@gibfahn Are you still using this plugin? If so, I will consider implementing this feature. Else, I shall keep it open for any future contributors as a "Good First Issue"

subnut avatar Feb 11 '22 14:02 subnut

Are you still using this plugin? If so, I will consider implementing this feature

Totally missed this, yes I'm still using the plugin. I have an easy shortcut to switch to my terminal though, so this isn't high-priority for me.

gibfahn avatar Mar 13 '23 12:03 gibfahn