Close all *other* panes


#1

In Emacs, when you have multiple panes split and you decide, “Now I want this pane to be full screen” you press C-x 0 which closes all other panes that is not the one you’re in focus on.

With Atom I have to switch over to the one of the other panes, hit Cmd-W until all its tabs close and when all are closed I get my desired pane back in full screen.

Any remedies other than switching back to Emacs :slight_smile: …which I don’t want to do.


#2

I don’t use Emacs, but I tried to understand what you explained and I hope this helps.

Add this to your keymap.cson file:

'body':
  'f6': 'custom:close-panes'

And this to your init.coffee:

atom.workspaceView.command 'custom:close-panes', ->
  panes = atom.workspace.getPanes()
  activePane = atom.workspace.getActivePane()
  for pane in panes
    pane.destroy() if activePane isnt pane

#3

Yay! Works like a charm! You rock!

Now, would it be possible to bind this to some keyboard command that is more similar to the other pane splitting commands. For example, can I make this Cmd-k 0?


#4

Use cmd-k 0 instead of f6

'body':
  'cmd-k 0': 'custom:close-panes'

#5

That works like a charm too. Now I just need to get it into my muscle memory.


#6

I’m looking for this functionality, but with the ability to restore the previously closed tabs and panes.

The idea is I have several files open, and I want to focus on a single file (correct some mistakes), after I can switch back to the view I started.
Kind of like a fullscreen functionality with the current file only.

So I’m looking to a restore functionality. Is it possible (the above code calls .destroy()), so I doubt it.


#7

Opening the files that were closed would be easy, just record which ones and open them on restore. Restoring the exact pane configuration might be harder, but I suspect still doable.


#8

Look at smart-tab-sort as an example. It controls the order of tabs.

It might be nice to be able to save the entire state of the panes/tabs with names so you can load them at any time.


#9

Don’t work with 0.155.0. Had to add Item:

atom.workspaceView.command 'custom:close-panes', ->
  panes = atom.workspace.getPaneItems()
  activePane = atom.workspace.getActivePaneItem()
  for pane in panes
    pane.destroy() if activePane isnt pane

#10

v0.155.0 is pretty old at this point, over three months old. You should probably update to the latest version.

Additionally, for the latest version, you should change it to:

atom.commands.add 'atom-workspace',
  'custom:close-panes': ->
    panes = atom.workspace.getPaneItems()
    activePane = atom.workspace.getActivePaneItem()
    for pane in panes
      pane.destroy() if activePane isnt pane

#11

Wow, thank you very much, I didn’t know that. Looks like Windows version stopped notifying about updates.
And thanks for the updated code.


#12

Thanks for the update.
However, it’s causing this issue at the moment: https://github.com/atom/atom/issues/6587


#13

If you use the command I updated above in a normal way, i.e. calling it from an editor with no special views open, it works. You are correct that it doesn’t have any error checking in it. I doubt though that the issue you linked is actually related. “undefined is not a function” is the most generic of error messages.


#14

Do pane.destroy?() if activePane isnt pane in case of a SettingsView. I’m not sure how to close that pane.


#15

Adding a custom script isn’t necessary anymore. Now the solution is built in. For example, to make ‘cmd-shift-w’ the shortcut to close all other tabs, add the following to ~/.atom/keymap.cson:

'atom-text-editor':
  'cmd-shift-w' : 'pane:close-other-items'