Home Download Buy Blog Forum Support

CamelHumping Plugin

CamelHumping Plugin

Postby Mostley on Wed Feb 10, 2010 10:26 am

nice little plugin, actually my first, to move over CamelHumps instead of words on CTRL-Left and CTRL-Right.

Code: Select all
import sublime, sublimeplugin, re

class moveCamelHump(sublimeplugin.TextCommand):
   def run(self, view, args):
      pos = view.sel()[0].begin()
      shift = int(args[0])
      if shift == 0:
         self.move(view, shift)
      
      if shift > 0:
         word = view.word(pos+1);
         word = sublime.Region(pos+1, word.end())
      else:
         word = view.word(pos-1);
         word = sublime.Region(word.begin(), pos-1)
      #testTestTestTestTest
      
      if word.size() == 0:
         self.move(view, shift)
      
      text = view.substr(word)
      m = re.finditer('[A-Z]', text)
      res = None
      if m:
         for a in m:
            res = a
            break
      if res:
         if shift > 0:
            res = res.start()
         else:
            for a in m: res = a
            res = res.start()
         shift = shift * abs((pos - word.begin()) - res)
         self.moveChars(view, shift)
      else:
         self.move(view, shift)
   
   def moveChars(self, view, shift):
      pos = view.sel()[0].begin() + shift
      view.sel().clear()
      view.sel().add(sublime.Region(pos,pos))
      
   def move(self, view, shift):
      pos = view.sel()[0].begin()
      if shift > 0:
         pos = view.word(pos+1).end()
      else:
         pos = view.word(pos-1).begin()
      view.sel().clear()
      view.sel().add(sublime.Region(pos,pos))
      
      


necessary key bindings:

Code: Select all
   <binding key="ctrl+left" command="moveCamelHump -1"/>
   <binding key="ctrl+right" command="moveCamelHump 1"/>
Mostley
 
Posts: 1
Joined: Wed Feb 10, 2010 10:22 am

Re: CamelHumping Plugin

Postby EJ12N on Wed Feb 10, 2010 4:15 pm

Nice job :D
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: CamelHumping Plugin

Postby gpfsmurf on Wed Feb 10, 2010 7:29 pm

Cool!
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: CamelHumping Plugin

Postby stormlifter on Thu Mar 04, 2010 9:50 pm

So I go to "Tools" -> "New Plugin" then paste in what you got there. Then go to "Preferences" -> "User Key Bindings" and put
Code: Select all
<bindings>
   <binding key="ctrl+left" command="moveCamelHump -1"/>
      <binding key="ctrl+right" command="moveCamelHump 1"/>
</bindings>


Or so I thought... I restarted and it's not working. The .pyc file is being generated however. But pushing control and the left or right arrow keys is doing nothing.
stormlifter
 
Posts: 1
Joined: Thu Mar 04, 2010 9:48 pm


Return to Plugin Announcements

Who is online

Users browsing this forum: Exabot [Bot], Majestic-12 [Bot] and 5 guests