Skip to content

Add an event listener to create an API to tell whether a view is cloned or not #127

@evandrocoan

Description

@evandrocoan

The View.is_primary() only tells if the view is the "primary". If the view is the "primary", it does not tell whether it has multiple views into the underlying buffer.

Some years ago, I wrote this code into my fork of BufferScroll:
https://github.com/evandrocoan/BufferScroll/blob/master/BufferScroll.py#L105-L117

And today, I need to write the same code for my new package:
https://github.com/evandrocoan/SkipCloseForClonedViews/blob/master/skip_close_for_cloned_views.py#L5-L70

Which implements this feature asked on Core:

  1. Skip save (ask) when closing a cloned view sublimehq/sublime_text#2903 Skip save (ask) when closing a cloned view

Nowadays, I am worried about performance, and I am running this is_cloned_view() very often. Then, for my new Package, I wrote a optimized version which caches whether a given buffer has several views into the same buffer.

How such peculiar API is_cloned(view) which requires to extend the sublime_plugin.EventListener be distributed and shared between several packages? Could it be added to sublime_lib?

Something very similar was already requested to be added into Sublime Text Core:

  1. "View.clones()" addition sublimehq/sublime_text#11 "View.clones()" addition

Using that API, it would only require me to call len( view.clones() ) > 1 to know where some view is cloned, i.e., has clones, i.e., has several views into the same buffer. Then, optimally when integrating my implementation into sublime_lib, my original implementation could be extended to support this feature of returning all clones instead of only saying some view has clones or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions