sublime text 给选中项插入编号

 1 #coding=utf-8

 2 import datetime, getpass

 3 import sublime, sublime_plugin

 4 import re

 5 

 6 # 插数字

 7 class InsertNumberCommand(sublime_plugin.TextCommand):

 8     def run(self, edit):

 9         self.view.window().show_input_panel("input start_num and diff_num:", "start_num:1, diff_num:1", lambda text: self.accumulate(text, edit), None, None)

10     def accumulate(self, text, edit):

11         text =  re.sub(r"[^\d\+-]*([\+-]?\d+)[,\s\t]+[^\d\+-]*([\+-]?\d+)", r"\1 \2", text)

12         numbers = text.split(" ")

13         start_num   = int(numbers[0])

14         diff_num    = int(numbers[1])

15         for region in self.view.sel():

16             #(row,col) = self.view.rowcol(region.begin())

17             self.view.insert(edit, region.end(), "%d" %start_num)

18             start_num += diff_num

 

 

 

 

 1 #coding=utf-8

 2 import datetime, getpass

 3 import sublime, sublime_plugin

 4 

 5 # 求和

 6 class SumCommand(sublime_plugin.TextCommand):

 7     def run(self, edit):

 8         sum_all = 0

 9         for region in self.view.sel():

10             add = 0

11             str_region = self.view.substr(region)

12             try:

13                 add = int(str_region)

14             except ValueError:

15                 sublime.error_message(u"含有非数字的字符串")

16                 return

17             sum_all = sum_all + add

18 

19         sublime.message_dialog(str(sum_all))

20 

21 class SelectWordCommand(sublime_plugin.TextCommand):

22     def run(self, edit):

23         for region in self.view.sel():

24             reg = self.view.word(region)

25             self.view.sel().add(reg)

 

 

写配置文件时,可以根据数据的规律,编写适当的函数。根据 count 计算对应的数据。

 sublime text 给选中项插入编号sublime text 给选中项插入编号

 

 

  

http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/extensibility/plugins.html

你可能感兴趣的:(Sublime Text)