示例#1
0
 def run(self, edit, external_id, text, with_auto_postfix=True):
     rv = manager.find_repl(external_id)
     if not rv:
         return
     if with_auto_postfix:
         text += rv.repl.cmd_postfix
     SENDERS[external_id](rv.repl, text, self.view)
示例#2
0
def plugin_loaded():

    # Copied from run_existing_command to ensure functionality
    # irrespective of plugin loading order
    global SUBLIMEREPL_DIR
    global SUBLIMEREPL_USER_DIR
    SUBLIMEREPL_DIR = "Packages/SublimeREPL"
    SUBLIMEREPL_USER_DIR = os.path.join(sublime.packages_path(), "User",
                                        "SublimeREPL")

    window = sublime.active_window()
    s = window.active_view().settings()
    kind = s.get('autostart_repl')
    if not kind:
        return

    for rv in manager.find_repl(kind.lower()):
        return

    print('No {} REPL found. Opening a new instance.'.format(kind))

    if kind.lower() == 'ipython':
        window.run_command('run_existing_window_command', {
            'id': 'repl_python_ipython',
            'file': 'config/Python/Main.sublime-menu'
        })
    else:
        print('{} REPL not supported.'.format(kind))
 def run(self, edit, external_id, text):
     for rv in manager.find_repl(external_id):
         rv.append_input_text(text)
         break  # send to first repl found
     else:
         sublime.error_message(
             "Cannot find REPL for '{0}'".format(external_id))
示例#4
0
 def run(self, external_id, text, with_auto_postfix=True, file_name=None):
     rv = manager.find_repl(external_id)
     if not rv:
         return
     cmd = text
     if with_auto_postfix:
         cmd += rv.repl.cmd_postfix
     SENDERS[external_id](rv.repl, cmd, file_name)
 def run(self, external_id, text, with_auto_postfix=True, file_name=None):
     rv = manager.find_repl(external_id)
     if not rv:
         return
     cmd = text
     if with_auto_postfix:
         cmd += rv.repl.cmd_postfix
     SENDERS[external_id](rv.repl, cmd, file_name)
示例#6
0
 def run(self, edit, external_id, text, with_auto_postfix=True):
     for rv in manager.find_repl(external_id):
         if with_auto_postfix:
             text += rv.repl.cmd_postfix
         if sublime.load_settings(SETTINGS_FILE).get('show_transferred_text'):
             rv.append_input_text(text)
             rv.adjust_end()
         SENDERS[external_id](rv.repl, text, self.view)
         break
     else:
         sublime.error_message("Cannot find REPL for '{}'".format(external_id))
示例#7
0
 def run(self, edit, external_id, text, with_auto_postfix=True):
     for rv in manager.find_repl(external_id):
         if with_auto_postfix:
             text += rv.repl.cmd_postfix
         if sublime.load_settings(SETTINGS_FILE).get('show_transferred_text'):
             rv.append_input_text(text)
             rv.adjust_end()
         SENDERS[external_id](rv.repl, text, self.view)
         break
     else:
         sublime.error_message("Cannot find REPL for '{}'".format(external_id))
示例#8
0
    def run(self, edit, external_id, text, with_auto_postfix=True):
        rv = manager.find_repl(external_id)
        if not rv:
            return
        if with_auto_postfix:
            text += rv.repl.cmd_postfix

        if sublime.load_settings(SETTINGS_FILE).get('show_transferred_text'):
            rv.append_input_text(text)
            rv.adjust_end()

        SENDERS[external_id](rv.repl, text, self.view)
示例#9
0
    def selected_file(self):
        # Change working directory to path of file
        if self.view.file_name():
            fpath = os.path.dirname(self.view.file_name())
            for rv in manager.find_repl(self.repl_external_id()):
                # So far only python support
                if 'python' in rv.external_id:
                    code = "import os; os.chdir('" + fpath + "'); "
                    rv.repl.popen.stdin.write(bytes(code, 'UTF-8'))
                break

        v = self.view
        return v.substr(sublime.Region(0, v.size()))
  def run(self, edit, command, refresh_namespaces=False):
    if refresh_namespaces:
      self.view.window().run_command("refresh_namespaces_in_repl", {"clean": False})

    external_id = self.repl_external_id()
    for rv in manager.find_repl(external_id):
      command += rv.repl.cmd_postfix
      rv.append_input_text(command)
      rv.adjust_end()
      rv.repl.write(command)
      break
    else:
      sublime.error_message("Cannot find REPL for '{}'".format(external_id))
    def run(self, edit, command, refresh_namespaces=False):
        if refresh_namespaces:
            self.view.window().run_command("refresh_namespaces_in_repl",
                                           {"clean": False})

        external_id = self.repl_external_id()
        for rv in manager.find_repl(external_id):
            command += rv.repl.cmd_postfix
            rv.append_input_text(command)
            rv.adjust_end()
            rv.repl.write(command)
            break
        else:
            sublime.error_message(
                "Cannot find REPL for '{}'".format(external_id))
示例#12
0
 def run(self, edit, external_id, text):
     for rv in manager.find_repl(external_id):
         rv.append_input_text(text)
         break  # send to first repl found
     else:
         sublime.error_message("Cannot find REPL for '{0}'".format(external_id))
示例#13
0
    def run(self, clear=None, save_focus=None, split=None):
        # check depencies
        if not is_installed('SublimeREPL'):
            install('SublimeREPL')
            return

        # import is done inside of function, because this plugin
        # 	may be loaded before SublimeREPL
        # this is either for master  branch:
        try:
            from sublimerepl import manager as repl_manager
        except ImportError:  # or for release branch of SublimeREPL:
            try:
                import sublimerepl as repl_manager
            except ImportError:  # something strange...
                bug_report(
                    'Looks like SublimeREPL plugin is installed, '
                    'but cannot be loaded. Try to restart Sublime Text 2. '
                    'If it doesn\'t help, report about this issue, please.')
                return

        # if options are not set, use defaults from settings
        settings = sublime.load_settings(SETTINGS_FILE)
        if clear == None: clear = settings.get('clear')
        if save_focus == None: save_focus = settings.get('save_focus')
        if split == None: split = settings.get('split')

        # source is where we are right now
        source_group = self.window.active_group()
        source_view = self.window.active_view()
        if source_view == None:
            sublime.error_message('LoadFileToRepl: No file is selected.')
            return

        filename = source_view.file_name()
        filetype = source_view.scope_name(0).split(' ')[0].split('.')[1]
        if filetype == 'plain':
            sublime.error_message(
                'LoadFileToRepl: Plain text is not supported. '
                'Change file type, please.')
            return

        # if there is only one group, split window
        if self.window.num_groups() == 1:
            if split == 'vertically':
                self.window.run_command(
                    'set_layout', {
                        'cols': [0.0, 0.5, 1.0],
                        'rows': [0.0, 1.0],
                        'cells': [[0, 0, 1, 1], [1, 0, 2, 1]]
                    })
            elif split == 'horizontally':
                self.window.run_command(
                    'set_layout', {
                        'cols': [0.0, 1.0],
                        'rows': [0.0, 0.5, 1.0],
                        'cells': [[0, 0, 1, 1], [0, 1, 1, 2]]
                    })
            # else no any split
        next_group = (source_group + 1) % self.window.num_groups()

        # if there is no opened repl
        if repl_manager.find_repl(filetype) == None:
            # focus on another group to open repl there
            self.window.focus_group(next_group)
            # open repl according to the type of source file
            self.window.run_command(
                'run_existing_window_command', {
                    'id': 'repl_' + filetype,
                    'file': 'config/' + filetype.title() + '/Main.sublime-menu'
                })

        # reveal repl view and move to another group
        repl_view = repl_manager.find_repl(filetype)._view
        self.window.focus_view(repl_view)
        if source_group == repl_view.window().active_group():
            repl_view.window().run_command('move_to_group',
                                           {'group': next_group})

        # clear repl if needed
        if clear:
            repl_view.run_command('repl_clear')

        # focus back on source file if needed
        if save_focus:
            self.window.focus_view(source_view)

        # and finally, load file to repl!
        load_command_format = settings.get(filetype + '_load_command')
        if not load_command_format:
            bug_report('%s language is not supported by this plugin.\n' %
                       filetype.title() +
                       'If you know suitable load command for it, please, '
                       'write me to the issue tracker and I\'ll add it.')
        else:
            if sublime.platform() == 'windows':
                load_command = load_command_format % filename.replace(
                    '\\', '\\\\')
            else:
                load_command = load_command_format % filename

            source_view.run_command('save')
            self.window.run_command(
                'repl_send', {
                    'external_id': filetype,
                    'text': load_command,
                    'file_name': filename
                })

            # just to show user that everything is ok
            sublime.status_message(filetype.title() + ' REPL > ' +
                                   load_command)
	def run(self, clear=None, save_focus=None, split=None):
		# check depencies
		if not is_installed('SublimeREPL'):
			install('SublimeREPL')
			return

		# import is done inside of function, because this plugin 
		# 	may be loaded before SublimeREPL
		# this is either for master  branch:
		try: from sublimerepl import manager as repl_manager
		except ImportError: # or for release branch of SublimeREPL:
			try: import sublimerepl as repl_manager
			except ImportError: # something strange...
				bug_report(
					'Looks like SublimeREPL plugin is installed, '
					'but cannot be loaded. Try to restart Sublime Text 2. '
					'If it doesn\'t help, report about this issue, please.')
				return

		# if options are not set, use defaults from settings
		settings = sublime.load_settings(SETTINGS_FILE)
		if clear      == None: clear      = settings.get('clear')     
		if save_focus == None: save_focus = settings.get('save_focus')
		if split      == None: split      = settings.get('split')     

		# source is where we are right now
		source_group = self.window.active_group()
		source_view = self.window.active_view()
		if source_view == None:
			sublime.error_message('LoadFileToRepl: No file is selected.')
			return

		filename = source_view.file_name()
		filetype = source_view.scope_name(0).split(' ')[0].split('.')[1]
		if filetype == 'plain':
			sublime.error_message(
				'LoadFileToRepl: Plain text is not supported. '
				'Change file type, please.')
			return

		# if there is only one group, split window
		if self.window.num_groups() == 1:
			if split == 'vertically':
				self.window.run_command('set_layout', {
					'cols'  : [0.0, 0.5, 1.0],
					'rows'  : [0.0, 1.0],
					'cells' : [[0, 0, 1, 1], [1, 0, 2, 1]]
					})
			elif split == 'horizontally':
				self.window.run_command('set_layout', {
					'cols'  : [0.0, 1.0],
					'rows'  : [0.0, 0.5, 1.0],
					'cells' : [[0, 0, 1, 1], [0, 1, 1, 2]]
					})
			# else no any split
		next_group = (source_group + 1) % self.window.num_groups()

		# if there is no opened repl
		if repl_manager.find_repl(filetype) == None:
			# focus on another group to open repl there
			self.window.focus_group(next_group)
			# open repl according to the type of source file
			self.window.run_command('run_existing_window_command', {
				'id'   : 'repl_' + filetype,
				'file' : 'config/' + filetype.title() + '/Main.sublime-menu'
			})

		# reveal repl view and move to another group
		repl_view = repl_manager.find_repl(filetype)._view
		self.window.focus_view(repl_view)
		if source_group == repl_view.window().active_group():
			repl_view.window().run_command(
				'move_to_group', {'group': next_group})

		# clear repl if needed
		if clear:
			repl_view.run_command('repl_clear')

		# focus back on source file if needed
		if save_focus:
			self.window.focus_view(source_view)

		# and finally, load file to repl!
		load_command_format = settings.get(filetype + '_load_command')
		if not load_command_format:
			bug_report(
				'%s language is not supported by this plugin.\n' % 
				filetype.title() +
			    'If you know suitable load command for it, please, '
			    'write me to the issue tracker and I\'ll add it.')
		else:
			if sublime.platform() == 'windows':
				load_command = load_command_format % filename.replace('\\','\\\\')
			else:
				load_command = load_command_format % filename

			source_view.run_command('save')
			self.window.run_command('repl_send', {
				'external_id' : filetype,
				'text'        : load_command,    
				'file_name'   : filename 
				})

			# just to show user that everything is ok
			sublime.status_message(filetype.title() + ' REPL > ' + load_command)
	def run(self, clear=None, save_focus=None, split=None):
		# import is done inside of function, because this plugin 
		# 	may be loaded before SublimeREPL
		try:
			if sys.version.split('.')[0] == '2': 
				from sublimerepl 			 import manager as repl_manager
			else: 	  
				from SublimeREPL.sublimerepl import manager as repl_manager
		except ImportError: # something strange...
			bug_report(
				'Looks like SublimeREPL plugin cannot be loaded. '
				'Try to restart Sublime Text. '
				'If it doesn\'t help, report about this issue, please.')
			return

		# if options are not set, use defaults from settings
		settings = sublime.load_settings(SETTINGS_FILE)
		if clear      == None: clear      = settings.get('clear')     
		if save_focus == None: save_focus = settings.get('save_focus')
		if split      == None: split      = settings.get('split')     

		# source is where we are right now
		source_group = self.window.active_group()
		source_view = self.window.active_view()
		if source_view == None:
			sublime.error_message('LoadFileToRepl: No file is selected.')
			return

		filename = source_view.file_name()
		filetype = ".".join(source_view.scope_name(0).split(' ')[0].split('.')[1:])
		#for the case if user hasn't saved file yet
		if filetype == 'plain':
			sublime.error_message(
				'LoadFileToRepl: Plain text is not supported. '
				'Change file type, please.')
			return
		# check if such filetype is supported
		load_command_format = settings.get(filetype + '_load_command')
		if not load_command_format:
			bug_report(
				'%s language is not supported by this plugin.\n' % 
				filetype.title() +
			    'If you know suitable load command for it, please, '
			    'write it to the issue tracker and I\'ll add it.')
			return

		peek_repl = peek(repl_manager.find_repl(filetype))

		# if there is only one group and repl view is not present or is in current window, split window
		# i.e if repl view is in different window don't split
		if self.window.num_groups() == 1 and (peek_repl == None or peek_repl._view.window() == self.window):
			if split == 'vertically':
				self.window.run_command('set_layout', {
					'cols'  : [0.0, 0.5, 1.0],
					'rows'  : [0.0, 1.0],
					'cells' : [[0, 0, 1, 1], [1, 0, 2, 1]]
					})
			elif split == 'horizontally':
				self.window.run_command('set_layout', {
					'cols'  : [0.0, 1.0],
					'rows'  : [0.0, 0.5, 1.0],
					'cells' : [[0, 0, 1, 1], [0, 1, 1, 2]]
					})
			# else no any split
		next_group = (source_group + 1) % self.window.num_groups()

		# if there is no opened repl
		if peek_repl == None:
			config_title = filetype.title()
			repl_id = filetype
			if repl_id == 'js':
				repl_id = 'node'
				config_title = 'NodeJS'
			elif repl_id == 'racket':
				repl_id = 'plt_racket'
			elif repl_id == 'fsharp':
				repl_id = 'f#'
				config_title = 'F'
			# focus on another group to open repl there
			self.window.focus_group(next_group)
			# open repl according to the type of source file
			self.window.run_command('run_existing_window_command', {
				'id'   : 'repl_' + repl_id,
				'file' : 'config/' + config_title + '/Main.sublime-menu'
			})

		# reveal repl view and move to another group
		peek_repl = peek(repl_manager.find_repl(filetype))
		if peek_repl == None:
			sublime.error_message('LoadFileToRepl: Couldn\'t open the repl.')
			return

		repl_view = peek_repl._view
		self.window.focus_view(repl_view)
		if source_group == repl_view.window().active_group():
			repl_view.window().run_command(
				'move_to_group', {'group': next_group})

		# clear repl if needed
		if clear:
			repl_view.run_command('repl_clear')

		# focus back on source file if needed
		if save_focus:
			source_view.window().focus_view(source_view)

		# and finally, load file to repl!
		if load_command_format:
			if sublime.platform() == 'windows':
				load_command = load_command_format % filename.replace('\\','\\\\')
			else:
				load_command = load_command_format % filename

			source_view.run_command('save')
			self.window.run_command('repl_send', {
				'external_id' : filetype,
				'text'        : load_command
				})

			# just to show user that everything is ok
			sublime.status_message(filetype.title() + ' REPL > ' + load_command)
示例#16
0
 def run(self, external_id, text, file_name=None):
     rv = manager.find_repl(external_id)
     if not rv:
         return
     rv.append_input_text(text)
    def run(self, clear=None, save_focus=None, split=None):
        # import is done inside of function, because this plugin
        # 	may be loaded before SublimeREPL
        try:
            if sys.version.split('.')[0] == '2':
                from sublimerepl import manager as repl_manager
            else:
                from SublimeREPL.sublimerepl import manager as repl_manager
        except ImportError:  # something strange...
            bug_report('Looks like SublimeREPL plugin cannot be loaded. '
                       'Try to restart Sublime Text. '
                       'If it doesn\'t help, report about this issue, please.')
            return

        # if options are not set, use defaults from settings
        settings = sublime.load_settings(SETTINGS_FILE)
        if clear == None: clear = settings.get('clear')
        if save_focus == None: save_focus = settings.get('save_focus')
        if split == None: split = settings.get('split')

        # source is where we are right now
        source_group = self.window.active_group()
        source_view = self.window.active_view()
        if source_view == None:
            sublime.error_message('LoadFileToRepl: No file is selected.')
            return

        filename = source_view.file_name()
        filetype = ".".join(
            source_view.scope_name(0).split(' ')[0].split('.')[1:])
        #for the case if user hasn't saved file yet
        if filetype == 'plain':
            sublime.error_message(
                'LoadFileToRepl: Plain text is not supported. '
                'Change file type, please.')
            return
        # check if such filetype is supported
        load_command_format = settings.get(filetype + '_load_command')
        if not load_command_format:
            bug_report('%s language is not supported by this plugin.\n' %
                       filetype.title() +
                       'If you know suitable load command for it, please, '
                       'write it to the issue tracker and I\'ll add it.')
            return

        peek_repl = peek(repl_manager.find_repl(filetype))

        # if there is only one group and repl view is not present or is in current window, split window
        # i.e if repl view is in different window don't split
        if self.window.num_groups() == 1 and (
                peek_repl == None or peek_repl._view.window() == self.window):
            if split == 'vertically':
                self.window.run_command(
                    'set_layout', {
                        'cols': [0.0, 0.5, 1.0],
                        'rows': [0.0, 1.0],
                        'cells': [[0, 0, 1, 1], [1, 0, 2, 1]]
                    })
            elif split == 'horizontally':
                self.window.run_command(
                    'set_layout', {
                        'cols': [0.0, 1.0],
                        'rows': [0.0, 0.5, 1.0],
                        'cells': [[0, 0, 1, 1], [0, 1, 1, 2]]
                    })
            # else no any split
        next_group = (source_group + 1) % self.window.num_groups()

        # if there is no opened repl
        if peek_repl == None:
            config_title = filetype.title()
            repl_id = filetype
            if repl_id == 'js':
                repl_id = 'node'
                config_title = 'NodeJS'
            elif repl_id == 'racket':
                repl_id = 'plt_racket'
            elif repl_id == 'fsharp':
                repl_id = 'f#'
                config_title = 'F'
            # focus on another group to open repl there
            self.window.focus_group(next_group)
            # open repl according to the type of source file
            self.window.run_command(
                'run_existing_window_command', {
                    'id': 'repl_' + repl_id,
                    'file': 'config/' + config_title + '/Main.sublime-menu'
                })

        # reveal repl view and move to another group
        peek_repl = peek(repl_manager.find_repl(filetype))
        if peek_repl == None:
            sublime.error_message('LoadFileToRepl: Couldn\'t open the repl.')
            return

        repl_view = peek_repl._view
        self.window.focus_view(repl_view)
        if source_group == repl_view.window().active_group():
            repl_view.window().run_command('move_to_group',
                                           {'group': next_group})

        # clear repl if needed
        if clear:
            repl_view.run_command('repl_clear')

        # focus back on source file if needed
        if save_focus:
            source_view.window().focus_view(source_view)

        # and finally, load file to repl!
        if load_command_format:
            if sublime.platform() == 'windows':
                load_command = load_command_format % filename.replace(
                    '\\', '\\\\')
            else:
                load_command = load_command_format % filename

            source_view.run_command('save')
            self.window.run_command('repl_send', {
                'external_id': filetype,
                'text': load_command
            })

            # just to show user that everything is ok
            sublime.status_message(filetype.title() + ' REPL > ' +
                                   load_command)
 def run(self, external_id, text, file_name=None):
     rv = manager.find_repl(external_id)
     if not rv:
         return
     rv.append_input_text(text)
示例#19
0
 def run(self, edit, external_id, text):
     rv = manager.find_repl(external_id)
     if not rv:
         return
     rv.append_input_text(text)