메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

Sublime plugin 생성 방법: 두 판 사이의 차이

데브카페
새 문서: == 서브라임 플러그인 만들기 == * 서브라임 플러그인 프로그램 생성 원칙 ** 클래스 이름은 반드시 Command로 끝나야 합니다. ** 올바른 예: class MyExampleCommand(sublime_plugin.TextCommand) ** 잘못된 예: class MyExample(sublime_plugin.TextCommand)
 
편집 요약 없음
1번째 줄: 1번째 줄:
== 서브라임 플러그인 만들기 ==
== 서브라임 플러그인 만드는법 ==


* 서브라임 플러그인 프로그램 생성 원칙  
* 서브라임 플러그인 프로그램 생성 원칙  
5번째 줄: 5번째 줄:
** 올바른 예: 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>
[[분류:서브라임]]

2025년 6월 16일 (월) 12:24 판

서브라임 플러그인 만드는법

  • 서브라임 플러그인 프로그램 생성 원칙
    • 클래스 이름은 반드시 Command로 끝나야 합니다.
    • 올바른 예: class MyExampleCommand(sublime_plugin.TextCommand)
    • 잘못된 예: class MyExample(sublime_plugin.TextCommand)

서브라임 플러그인 생성 절차

  1. Sublime Text 메뉴에서 Preferences > Browse Packages... 선택
    - 이렇게 하면 Sublime Text의 패키지 디렉토리가 파일 탐색기/파인더에 열립니다.
  2. 패키지 디렉토리 내에 새 폴더 생성 (예: MyPlugin)
  3. 이 폴더 안에 Python 파일 생성 (예: my_plugin.py)
  4. 플러그인 클래스 예제(위 코드를 my_plugin.py 파일에 저장)
import sublime
import sublime_plugin
class MyExampleCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.insert(edit, 0, "Hello, World!")

플러그인 등록 및 실행 방법

  1. (저장만 하면) Sublime Text는 자동으로 플러그인을 로드합니다
  2. 플러그인 실행 방법
    1. 콘솔에서 실행: view.run_command('my_example')
    2. 키 바인딩으로 실행:
      - 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

Comments