Event to tie into buffer loading?


#1

I’d like to build a package to emulate Vim’s buffer behavior in Atom (opening new buffers in the currently active tab rather than a new tab). I’ve been digging through the source using the debugger today to see what happens when I load a new buffer. It looks like this behavior is theoretically be possible, but currently there’s no event that fires from the time a file is chosen until after it’s loaded in a new tab.

Are there plans to add any hooks into the buffer loading process that I can use for this? Or is this possible already and I missed something?

Thanks!
Joe


#2

see Document Custom Events


#3

I’ve gone through those lists a couple times and can’t find anything obvious that would run when the user selects a file, but before that file is loaded in a new tab. Is there any chance this might come eventually in the beta?


Influencing Atom Internals?
#4

Been looking into this further. It appears the tabs plugin subscribes to the “pane:item-added” command to open items in a new tab (see https://github.com/atom/tabs/blob/master/lib/tab-bar-view.coffee#L27-L29). I’m thinking what I want to do is stop propagation to the tab view, so that I can load the item into the existing tab instead. Unfortunately, it looks like the tabs plugin is getting loaded before mine, therefore its subscription is getting called before mine. Is there any way to control the load order so mine is called first and I can stop propagation to tabs?

Edit: Did a little more digging, looks like we have one of two options here:

  1. Can I insert myself into the subscription chain before tabs? This sounds like a bad idea, but then again so does
  2. Have tab-bar-view trigger an event before a tab is opened that allows me to cancel the tab opening, but it still updates the tab state; this is bad because it’d be better if tabs knew nothing about this behavior

I can’t think of a better option than #1 at the moment. I’m also falling asleep as I type this, so maybe I need to reapproach this with a fresh mind. Does anyone else have any ideas?


#5

I would wrap TabBarView.prototype.addTabForItem… IE, something like

var original = TabBarView.prototype.addTabForItem;
TabBarView.prototype.addTabForItem = function(){
if (iWantTo) {
  original.apply(this, _.toArray(arguments));
}

Monkey patching is your only real option :frowning:


#6

That was the conclusion I was coming to as well. Thanks for confirming!