다른 명령
새 문서: == 서브라임 플러그인 만들기 == * 서브라임 플러그인 프로그램 생성 원칙 ** 클래스 이름은 반드시 Command로 끝나야 합니다. ** 올바른 예: class MyExampleCommand(sublime_plugin.TextCommand) ** 잘못된 예: class MyExample(sublime_plugin.TextCommand) |
|||
(같은 사용자의 중간 판 4개는 보이지 않습니다) | |||
1번째 줄: | 1번째 줄: | ||
== 서브라임 플러그인 | == 서브라임 플러그인 만드는법 == | ||
* 서브라임 플러그인 프로그램 생성 원칙 | * 서브라임 플러그인 프로그램 생성 원칙 | ||
** 클래스 이름은 반드시 Command로 끝나야 합니다. | ** 클래스 이름은 반드시 Command로 끝나야 합니다.(~Command) | ||
** 올바른 예: class MyExampleCommand(sublime_plugin.TextCommand) | ** 올바른 예: class MyExampleCommand(sublime_plugin.TextCommand) | ||
** 잘못된 예: class MyExample(sublime_plugin.TextCommand) | ** 잘못된 예: class MyExample(sublime_plugin.TextCommand) | ||
=== 서브라임 플러그인 생성 절차 === | |||
# Sublime Text 메뉴에서 Preferences > Browse Packages... 선택 | |||
#: - 이렇게 하면 Sublime Text의 패키지 디렉토리가 파일 탐색기/파인더에 열립니다. | |||
# 패키지 디렉토리 내에 새 폴더 생성 (예: MyPlugin) | |||
# 이 폴더 안에 Python 파일 생성 (예: my_plugin.py) | |||
# 플러그인 클래스 예제(위 코드를 my_plugin.py 파일에 저장) | |||
<source lang=python> | |||
import sublime | |||
import sublime_plugin | |||
class MyExampleCommand(sublime_plugin.TextCommand): | |||
def run(self, edit): | |||
self.view.insert(edit, 0, "Hello, World!") | |||
</source> | |||
=== 플러그인 등록 및 실행 방법 === | |||
# (저장만 하면) Sublime Text는 자동으로 플러그인을 로드합니다 | |||
# 플러그인 실행 방법 | |||
## 콘솔에서 실행: view.run_command('my_example') | |||
## 키 바인딩으로 실행: | |||
##: - Preferences > Key Bindings 열기 | |||
##: - 사용자 키 바인딩 파일에 추가: | |||
<source lang=xml> | |||
{ | |||
"keys": ["ctrl+alt+shift+h"], | |||
"command": "my_example" | |||
} | |||
</source> | |||
=== 플러그인 : 자동 증가 번호 추가하기(선택한 라인) === | |||
* LineNumbersAdd.py | |||
<source lang=python> | |||
import sublime | |||
import sublime_plugin | |||
class LineNumbersAddCommand(sublime_plugin.TextCommand): | |||
def run(self, edit, suffix=""): | |||
selections = self.view.sel() | |||
totalOffset = 0 | |||
for selection in selections: | |||
lines = self.view.split_by_newlines(selection) | |||
for i, line in enumerate(lines): | |||
line_number_string = str(i+1)+suffix | |||
offset = len(line_number_string) | |||
# print offset, "just" | |||
self.view.insert(edit, line.begin() + totalOffset, line_number_string) | |||
totalOffset += offset | |||
</source> | |||
=== 플러그인 : 라인모드에서 자동 증가 번호 추가하기(선택한 라인) === | |||
* LineModeNumbersAdd.py | |||
<source lang=python> | |||
import sublime | |||
import sublime_plugin | |||
class IncrementLineEditCommand(sublime_plugin.TextConmand): | |||
def run(self, edit): | |||
selections = self.view.sel() | |||
if not selections: | |||
+7 | |||
return | |||
padding = 1 if len(selections) ‹ 10 else 2 | |||
# for index, region in enumerate (selections, start-1) | |||
for i in range(len(selections)): | |||
# self,view. replace(edit, region, str(index)) | |||
self.view.replace(edit, selections[1],str(i+1).zfill(padding)) | |||
# sublime,status_message(f"{len(selections)} affected") | |||
</source> | |||
[[분류:서브라임]] |
2025년 6월 16일 (월) 19:29 기준 최신판
서브라임 플러그인 만드는법
- 서브라임 플러그인 프로그램 생성 원칙
- 클래스 이름은 반드시 Command로 끝나야 합니다.(~Command)
- 올바른 예: class MyExampleCommand(sublime_plugin.TextCommand)
- 잘못된 예: class MyExample(sublime_plugin.TextCommand)
서브라임 플러그인 생성 절차
- Sublime Text 메뉴에서 Preferences > Browse Packages... 선택
- - 이렇게 하면 Sublime Text의 패키지 디렉토리가 파일 탐색기/파인더에 열립니다.
- 패키지 디렉토리 내에 새 폴더 생성 (예: MyPlugin)
- 이 폴더 안에 Python 파일 생성 (예: my_plugin.py)
- 플러그인 클래스 예제(위 코드를 my_plugin.py 파일에 저장)
import sublime import sublime_plugin class MyExampleCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.insert(edit, 0, "Hello, World!")
플러그인 등록 및 실행 방법
- (저장만 하면) Sublime Text는 자동으로 플러그인을 로드합니다
- 플러그인 실행 방법
- 콘솔에서 실행: view.run_command('my_example')
- 키 바인딩으로 실행:
- - Preferences > Key Bindings 열기
- - 사용자 키 바인딩 파일에 추가:
{ "keys": ["ctrl+alt+shift+h"], "command": "my_example" }
플러그인 : 자동 증가 번호 추가하기(선택한 라인)
- LineNumbersAdd.py
import sublime import sublime_plugin class LineNumbersAddCommand(sublime_plugin.TextCommand): def run(self, edit, suffix=""): selections = self.view.sel() totalOffset = 0 for selection in selections: lines = self.view.split_by_newlines(selection) for i, line in enumerate(lines): line_number_string = str(i+1)+suffix offset = len(line_number_string) # print offset, "just" self.view.insert(edit, line.begin() + totalOffset, line_number_string) totalOffset += offset
플러그인 : 라인모드에서 자동 증가 번호 추가하기(선택한 라인)
- LineModeNumbersAdd.py
import sublime import sublime_plugin class IncrementLineEditCommand(sublime_plugin.TextConmand): def run(self, edit): selections = self.view.sel() if not selections: +7 return padding = 1 if len(selections) ‹ 10 else 2 # for index, region in enumerate (selections, start-1) for i in range(len(selections)): # self,view. replace(edit, region, str(index)) self.view.replace(edit, selections[1],str(i+1).zfill(padding)) # sublime,status_message(f"{len(selections)} affected")