Sublime Forum

OpenUri - Opening URIs (mostly URLs) in your file

#1

Package: https://packagecontrol.io/packages/OpenUri


image

OpenUri is a customizable plugin that allows you to open URIs (mostly for URLs) in your file via a web browser directly by clicking on the phantom, popup or key/mouse bindings.

Here are featured customizable settings:

  • You are able to add new schemes and path-matching regexes by yourself.
    https://github.com/jfcherng/Sublime-OpenUri/blob/f9a23fa/OpenUri.sublime-settings#L78-L110
    Schemes and path-matching regexes will be optimized into one single regex for finding URIs.

  • There are 3 ways to emphasize URIs’ location. You can use the one which fits you the best, or disable them all and only use a key/mouse binding to open URIs.

    • If show_open_button is configured to be always: Phantom will be added next to a URI (both image and color can be customized)
      image
    • If show_open_button is configured to be hover: Popup will be used when a URI is hovered (text, image and color can be customized)
      image
    • emphasize URL regions (can be solid background, underline, bordered)
      image

Plugins for a similar purpose but less customizable:

4 Likes

#2

This package is great. One question, though. Can you somehow make it open the URI in Sublime Text instead of opening it in the browser? That would be marvelous.

0 Likes

#3

Didn’t aware that Python can open a URI without the help of a web browser. (searched via keyword python open uri on Google)

file:// should be able to be directly open in ST but not implemented though.

0 Likes

#4

That’s beyond my comprehension of Python, but I wasn’t referring to that. If, instead of hitting that button OpenUri displays, I select the complete URI, and copy it into the Open File dialog, the contents of that “file” will be displayed in Sublime Text. Or at least that happens on Windows. Now, I’m aware that has very little to do with ST, Windows will download it to some sort of cache file and will open that instead of the URI itself, still it behaves as if it had opened that URI.
My question is, is it possible to somehow mimic that whole procedure instead of doing it manually?

0 Likes

#5

That can be done theoretically but I doubt that should be the default behavior. Say I click on the text https://google.com and it downloads the HTML source code of it and opens it in ST. I will feel “what the hell?” in my mind.

0 Likes

#6

Well, that wording wasn’t very clever on my part, was it? :grinning: I didn’t mean to open the contents in ST instead of the browser by default. It’s pretty clear that most people want this to use the browser.

What I meant was if it was possible (generally) to do “a” instead of “b”?

I’ve unsuccessfully tried to mutilate your code (my apologies :fearful:) to do that, and I’m fairly convinced that self.view.window().open_file(uri) instead of webbrowser.get(browser).open(uri, autoraise=True) in open_uri_with_browser won’t do a decent job.

0 Likes

#7

So, is this what you want? Or there is another scheme that I wan’t aware of to be opened in ST?
I can image that file:// is better to be opened with ST rather than a web browser.

Could you provide an exact sample rather than a concept? I.e., what’s the exact URI you are trying to open with ST?

0 Likes

#8

Mostly (currently) it’s a bunch of xml files located under a https address. Otherwise, literally anything. For example, take that comment in functions.py referencing https://docs.python.org/3.3/library/webbrowser.html#webbrowser.get
I open that in ST using the Open File dialog (see in https://streamable.com/s9xy1)

0 Likes

#9

With the video, you want to open a URL in ST so you can view the source code directly in ST, right?

Oh, it looks like view.window().open_file('https://google.com') just not work.

0 Likes

#10

Yes, that’s what I’ve tried to use instead of webbrowser.get(browser).open(uri, autoraise=True) in open_uri_with_browser

0 Likes