Home Download Buy Blog Forum Support

Selection Mode

Re: Selection Mode

Postby markus.haider on Mon Oct 22, 2012 10:56 pm

@quodlibet: Great, thanks. This is exactly what i meant
markus.haider
 
Posts: 12
Joined: Thu Feb 09, 2012 6:42 pm

Re: Selection Mode

Postby markus.haider on Sun Oct 28, 2012 9:49 pm

A further question: When I am done with my selection I have to exit the selection mode again. Is there a way so that the selection_mode would finish if any other key than e.g. a movement key is pressed?
markus.haider
 
Posts: 12
Joined: Thu Feb 09, 2012 6:42 pm

Re: Selection Mode

Postby markus.haider on Tue Nov 27, 2012 5:39 pm

bump
markus.haider
 
Posts: 12
Joined: Thu Feb 09, 2012 6:42 pm

Re: Selection Mode

Postby quodlibet on Wed Nov 28, 2012 9:22 pm

I'm almost certain this would require a plugin -- which means python -- and, not being a programmer, I can't help you further. Hopefully someone else will pitch in.
quodlibet
 
Posts: 517
Joined: Sat Jun 18, 2011 5:53 pm

Re: Selection Mode

Postby jps on Thu Nov 29, 2012 6:52 am

Take a look at the Edit/Mark menu, too, which already implements a selection mode of sorts, a la emacs
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Selection Mode

Postby MiraHedl on Sat Oct 26, 2013 11:24 pm

You probably solved it in some way, but anyway, here is hint for others.

You need custom plugin for that (Tools -> New Plugin and then save it and restart ST):

Code: Select all
import sublime, sublime_plugin

# Takes an array of commands (same as those you'd provide to a key binding) with
# an optional context (defaults to view commands) & runs each command in order.
# Valid contexts are 'text', 'window', and 'app' for running a TextCommand,
# WindowCommands, or ApplicationCommand respectively.
class RunMultipleCommand(sublime_plugin.TextCommand):
  def exec_command(self, command):
    if not 'command' in command:
      raise Exception('No command name provided.')

    args = None
    if 'args' in command:
      args = command['args']

    # default context is the view since it's easiest to get the other contexts
    # from the view
    context = self.view
    if 'context' in command:
      context_name = command['context']
      if context_name == 'window':
        context = context.window()
      elif context_name == 'app':
        context = sublime
      elif context_name == 'text':
        pass
      else:
        raise Exception('Invalid command context "'+context_name+'".')

    # skip args if not needed
    if args is None:
      context.run_command(command['command'])
    else:
      context.run_command(command['command'], args)

  def run(self, edit, commands = None):
    if commands is None:
      return # not an error
    for command in commands:
      self.exec_command(command)


Although not perfect, here's how I do it:

Code: Select all
   { "keys": ["alt+space"], "command": "toggle_setting", "args": {"setting": "selection_mode"}},

   { "keys": ["alt+l"], "command": "move", "args": {"by": "characters", "forward": true}},
   { "keys": ["alt+l"], "command": "move", "args": {"by": "characters", "forward": true, "extend" : true},
                   "context": [{"key": "setting.selection_mode", "operator": "equal", "operand": true}]},
   {
       "keys": ["alt+c"],
       "command": "run_multiple",
       "args": {
         "commands": [
           { "command": "copy" },
           { "command": "set_setting", "args": {"setting": "selection_mode", "value": false }},
            ]
       }
   },



If you have better way, don't hesitate to share it.

Regards,
dingo
MiraHedl
 
Posts: 1
Joined: Sat Oct 26, 2013 11:16 pm

Previous

Return to General Discussion

Who is online

Users browsing this forum: Exabot [Bot] and 30 guests