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

Feat+run cmd on match #399

Merged
merged 2 commits into from Apr 13, 2021
Merged

Conversation

nojhan
Copy link
Contributor

@nojhan nojhan commented Mar 4, 2021

Adds the necessary features to add a regexp/command plugin.
My use-case is to be able to open a file at a specific line in my IDE, just by clicking on an error message.

For instance, for opening a python script indicated in a python error, within vim, use the following configuration with the RunCmdOnMatch plugin implemented in this PR:

  • regexp = \B(/\S+?\.py)\S{2}\sline\s(\d+)
  • command = gvim --servername IDE --remote +{1} {0}

This adds three interconnected features:

  • a plugin which can run any command when clicking on a link inserted on texts matching a regexp,
  • a way to hide plugins in the preference/plugins window (by prefixing their name with an underscore),
  • a way to bypass the URL handler (xdg-open), when the URLhandler plugin returns a terminator:// URL.

The overall architecture is not really elegant, but it is the smallest footprint I found for implementing a match/command plugin.

It needs a URLhandler metaclass and will instantiate on-the-fly one plugin per configured match/command pair (hence the necessity to hide them, as the user is not supposed to interact with them anyway).
As those hidden plugins are responsible for "opening" the URL they match, a way to bypass the URL handler was needed. Returning None already had a semantic, so I opted for a fake protocol in the URI.

The GUI code is almost a copy/paste of the custom commands plugin, so it would be better to have the plugin window's entry point (instead of the contextual menu) and keep a single code base.

I'm not sure where to edit a user documentation.

Easier debugging: some Python exception error messages are difficult to
interpret without the exception type (e.g. KeyError).
- Plugins starting with underscore will not be displayed by the
  preference/plugins window.
- This allow to add URLhandlers plugins on-the-fly.
- Add the RunCmdOnMatch plugin, which creates URLhandlers plugins
  based on a regexp/command pair.
- If an URLhandler plugin returns a prepared URL starting with "terminator://",
  then terminator will not try to open it with the URL handler (like xdg-open).
@mattrose
Copy link
Member

Sorry for letting this drop for so long. I actually love this feature and I think the code changes are mostly good.

I checked it out and tried to use the example you put in the description, but I can't seem to figure out how to click on the text so that it brings up the command. It should underline the line and that should let me click on it, but it doesn't seem to do that. Is there something I'm missing?

@nojhan
Copy link
Contributor Author

nojhan commented Apr 13, 2021

The full test procedure would goes:
Add the \B(/\S+?\.py)\S{2}\sline\s(\d+) regexp, linking to your favorite editor, gvim +{1} {0}.

Run a script that display the info to catch, here a Python script displaying THE ABSOLUTE PATH.

echo "print('What the F)" >  test.py
python3 $(pwd)/test.py

Note that if you just do ./test.py, then the path information is contextual and it's not going to work (or else we would need to pass the current directory from the shell to the URL manager). In that case, the observed behaviour would be to open an empty file.

Then, you have to pass the mouse over the path segment to see it underlined, and [Ctrl-] click to open it.

Example (the mouse is over the link):
screen

@mattrose
Copy link
Member

Huh. that's what I thought I did, but I'll try again.

Tried again. Worked. It may have been my gvim command. Merging. Thanks so much for this, and sorry it took me so long to get around to looking at it.

@mattrose mattrose merged commit 5455ac2 into gnome-terminator:master Apr 13, 2021
@nojhan
Copy link
Contributor Author

nojhan commented Apr 14, 2021 via email

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.

None yet

2 participants