Sublime Forum

How to loop through all the buffers of window?

#1

How to loop through all the buffers of a window?

I want to process all the views and add all the words to the auto completion. Simultaneously, I am check for each word I got, if the total time has not been passed the limit of 0.3 seconds.

Currently I can think of creating a set and adding to it, each view buffer id, so I do not process the same buffer again, if its buffer id is already on the set, when I am looping through the views after doing sublime.active_window().views().

buffers_id_set = set()
start_time     = time.time()

# The current buffer is already processed
buffers_id_set.add( active_view.buffer_id() )

for view in views:
    view_buffer_id = view.buffer_id()

    if view_buffer_id not in buffers_id_set:
        buffers_id_set.add( view_buffer_id )

        if time.time() - start_time > 0.3:
            break
0 Likes

#2

So, what’s the question?

0 Likes

#3

It on the topic’s title, but the topic it self already has a solution to it.

0 Likes