# -*- coding: utf-8 -*-

import sublime
import sublime_plugin
import sys
from .kanaconverter import to_hiragana, to_katakana, invert_hiragana_katakana

class ConvertToHiraganaCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        sels = self.view.sel()
        for select in sels:
            s = self.view.substr(select)
            self.view.replace(edit, select, to_hiragana(s))

class ConvertToKatakanaCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        sels = self.view.sel()
        for select in sels:
            s = self.view.substr(select)
            self.view.replace(edit, select, to_katakana(s))

class InvertHiraganaAndKatakanaCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        sels = self.view.sel()
        for select in sels:
            s = self.view.substr(select)
            self.view.replace(edit, select, invert_hiragana_katakana(s))

@@ -230,38 +230,42 @@
  edit):%0A        
-sels =
+for sel in
  self.view.sel()
@@ -268,35 +268,8 @@
 el()
-%0A        for select in sels
 :%0A  
@@ -270,33 +270,36 @@
 ():%0A            
-s
+text
  = self.view.sub
@@ -297,35 +297,32 @@
 .view.substr(sel
-ect
 )%0A            se
@@ -342,27 +342,24 @@
 ce(edit, sel
-ect
 , to_hiragan
@@ -356,25 +356,28 @@
 to_hiragana(
-s
+text
 ))%0A%0Aclass Co
@@ -453,38 +453,42 @@
  edit):%0A        
-sels =
+for sel in
  self.view.sel()
@@ -491,35 +491,8 @@
 el()
-%0A        for select in sels
 :%0A  
@@ -493,33 +493,36 @@
 ():%0A            
-s
+text
  = self.view.sub
@@ -520,35 +520,32 @@
 .view.substr(sel
-ect
 )%0A            se
@@ -569,19 +569,16 @@
 dit, sel
-ect
 , to_kat
@@ -583,17 +583,20 @@
 atakana(
-s
+text
 ))%0A%0Aclas
@@ -696,14 +696,18 @@
     
-sels =
+for sel in
  sel
@@ -722,35 +722,8 @@
 el()
-%0A        for select in sels
 :%0A  
@@ -732,17 +732,20 @@
         
-s
+text
  = self.
@@ -759,19 +759,16 @@
 bstr(sel
-ect
 )%0A      
@@ -804,11 +804,8 @@
  sel
-ect
 , in
@@ -827,12 +827,15 @@
 atakana(
-s
+text
 ))%0A

Simplify command codes on kanakana.py