LoginSignup
2
2

More than 5 years have passed since last update.

SublimeTextで突然の死

Posted at

http://qiita.com/items/b10d5659cb1f1a168758
を見て。
pythonもplugin作るのも初めてなんで不具合とかあるかもです(><)
何かあったら誰か直してください(>
<)

ソース

SuddenDeath.py
# -*- coding: utf-8 -*-

import sublime, sublime_plugin

class SuddenDeathCommand(sublime_plugin.TextCommand):
    def width_kana(self,str):
        all = len(str)              # 全文字数
        zenkaku = self.count_zen(str)    # 全角文字数
        hankaku = all - zenkaku     # 半角文字数
        return zenkaku * 2 + hankaku
    def count_zen(self,str):
        from unicodedata import east_asian_width
        n = 0
        for c in str:
            wide_chars = u"WFA"
            eaw = east_asian_width(c)
            if wide_chars.find(eaw) > -1:
                n += 1
        return n
    def run(self, edit):
        for region in self.view.sel():
            if not region.empty():
                strs=self.view.substr(region).splitlines()
                max_width=max(map(self.width_kana,strs))
                head=u"_人"+u"人"*(max_width/2)+u"人_\n"
                tail=u" ̄Y"+u"Y"*(max_width/2)+u"Y ̄\n"
                death_str=head
                for str in strs:
                    death_str+=u'> %s <\n' % (str+" "*(max_width - self.width_kana(str)))
                death_str+=tail
                self.view.replace(edit, region, death_str)

使い方

~/.config/sublime-text-2/Packages/Userに保存。
適当にキーバインドして囲みたい文字を選択して実行。

_人人人人人人_
> 突然の死 <
 ̄YYYYYY ̄

_人人人人人人人人人人_
> _人人人人人人_ <
> > 突然の死 < <
>  ̄YYYYYY ̄ <
 ̄YYYYYYYYYY ̄

_人人人人人人人人人人人人人人_
> _人人人人人人人人人人_ <
> > _人人人人人人_ < <
> > > ちょっと < < <
> > > ずれる   < < <
> > > かも     < < <
> >  ̄YYYYYY ̄ < <
>  ̄YYYYYYYYYY ̄ <
 ̄YYYYYYYYYYYYYY ̄

参考文献

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2