Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement :only command

  • Loading branch information...
commit 3252956e3b99eaf020e790461b4f7f0cda056e86 1 parent b3a4934
@guillermooo guillermooo authored
Showing with 28 additions and 0 deletions.
  1. +7 −0 ex_command_parser.py
  2. +19 −0 ex_commands.py
  3. +2 −0  ex_error.py
View
7 ex_command_parser.py
@@ -346,6 +346,13 @@
invocations=(),
error_on=()
),
+ ('only', 'on'): ex_cmd_data(
+ command='ex_only',
+ invocations=(re.compile(r'^$',),
+ ),
+ error_on=(ex_error.ERR_TRAILING_CHARS,
+ ex_error.ERR_NO_RANGE_ALLOWED,)
+ ),
(':', ':'): ex_cmd_data(
command='ex_goto',
invocations=(),
View
19 ex_commands.py
@@ -413,6 +413,25 @@ def run(self, edit, range='.', forced=False, address=''):
self.view.sel().add(sublime.Region(cursor_dest, cursor_dest))
+class ExOnly(sublime_plugin.TextCommand):
+ """ Command: :only
+ """
+ def run(self, edit, forced=False):
+ if not forced:
+ if is_any_buffer_dirty(self.view.window()):
+ ex_error.display_error(ex_error.ERR_OTHER_BUFFER_HAS_CHANGES)
+ return
+
+ w = self.view.window()
+ current_id = self.view.id()
+ for v in w.views():
+ if v.id() != current_id:
+ if forced and v.is_dirty():
+ v.set_scratch(True)
+ w.focus_view(v)
+ w.run_command('close')
+
+
class ExDoubleAmpersand(sublime_plugin.TextCommand):
""" Command :&&
"""
View
2  ex_error.py
@@ -14,6 +14,7 @@
ERR_NO_RANGE_ALLOWED = 481 # Command can't take a range.
ERR_UNSAVED_CHANGES = 37 # The buffer has been modified but not saved.
ERR_ADDRESS_REQUIRED = 14 # Command needs an address.
+ERR_OTHER_BUFFER_HAS_CHANGES = 445 # :only, for example, may trigger this
ERR_MESSAGES = {
@@ -25,6 +26,7 @@
ERR_NO_RANGE_ALLOWED: 'No range allowed.',
ERR_UNSAVED_CHANGES: 'There are unsaved changes.',
ERR_ADDRESS_REQUIRED: 'Invalid address.',
+ ERR_OTHER_BUFFER_HAS_CHANGES: "Other buffer contains changes."
}
Please sign in to comment.
Something went wrong with that request. Please try again.