gedit의 파일 유형별 기본 설정

gedit의 파일 유형별 기본 설정

저는 Python 소프트웨어 개발과 Latex 문서 작성이라는 두 가지 다른 작업에 gedit를 사용하려고 합니다. 둘 다 순수한 텍스트 파일을 기반으로 하지만 매우 다릅니다. 예를 들어 Python 코드는 코드 구조(루프, 함수 등)를 보려면 정렬되어야 합니다. 따라서 Monospace 글꼴이 좋습니다. Latex 문서를 작성하려면 주로 가독성이 필요합니다. 이는 인쇄에 사용되는 글꼴을 사용하는 것이 가장 좋으며 고정 폭 글꼴이 아닌 글꼴을 사용하는 것이 가장 좋습니다.

파일 유형별 기본 설정을 사용하도록 gedit에 지시하는 방법이 있습니까? 예를 들어 *.tex의 경우 Garamond, *.py의 경우 Monospace? (그러나 이 문제는 글꼴에만 국한되지 않으며 Latex 및 Python에도 적용되지 않습니다.)

답변1

좋아, 불가능할 것 같아서 지금은 나에게 맞는 gedit2용 프로토 플러그인을 만들었습니다. 그래도 누군가가 더 나은 답변을 해주길 바랍니다.

~/.gnome2/gedit/plugins/mimeprefs.py

import gedit

class MimePrefsPlugin(gedit.Plugin):
    def __init__(self):
        gedit.Plugin.__init__(self)

    def activate(self, window):
        pass

    def deactivate(self, window):
        pass

    def update_ui(self, window):
        doc = window.get_active_document()
        try:
            mt = doc.get_mime_type()
        except AttributeError:
            return
        view = window.get_active_view()
        if 'x-tex' in mt:
            view.set_font(False, 'Garamond 14')
        elif 'x-python' in mt:
            view.set_font(False, 'Monospace 12')
        else:
            view.set_font(True, 'Monospace 10')

~/.gnome2/gedit/plugins/mimeprefs.gedit-plugin

[Gedit Plugin]
Loader=python
Module=mimeprefs
IAge=2
Name=Mime-Prefs v1
Description=A plugin to set font preferences based on the mimetype of the document
Authors=-
Copyright=Public Domain
Website=None

편집: gedit3 업데이트: 플러그인 파일이 들어가서 ~/.local/share/gedit/plugins/다음과 같이 보입니다.

mimeprefs.플러그인:

[Plugin]
Loader=python
Module=mimeprefs
IAge=3
Name=Mime-Prefs
Description=A plugin to set font preferences based on the mimetype of the document
Authors=Stefan Schwarzburg
Copyright=Public Domain
Website=None
Version=1.0.0

mimeprefs.py:

from gi.repository import GObject, Gedit


class MimePrefsPlugin(GObject.Object, Gedit.WindowActivatable):
    __gtype_name__ = "MimePrefsPlugin"
    window = GObject.property(type=Gedit.Window)

    def __init__(self):
        GObject.Object.__init__(self)

    def do_activate(self):
        pass

    def do_deactivate(self):
        pass

    def do_update_state(self):
        doc = self.window.get_active_document()
        try:
            mt = doc.get_mime_type()
        except AttributeError:
            return
        view = self.window.get_active_view()
        if 'x-tex' in mt:
            view.set_font(False, 'Garamond 14')
        elif 'x-python' in mt:
            view.set_font(False, 'Monospace 12')
        else:
            view.set_font(True, 'Monospace 10')

답변2

내가 아는 한 대답은 "아니요"입니다... 하지만...

gconf-editor를 사용하면 인쇄 글꼴을 설정할 수 있습니다. /apps/gedit-2/preferences/print/fonts의 gedit 옵션에서 현재 어떤 글꼴이 선택되어 있는지에 관계없이 표시 글꼴을 선택하는 옵션도 있을 수 있습니다. 이것이 사실이라면 간단한 스크립트를 사용하여 파일 확장자에 따라 이를 변경할 수 있습니다.

--편집하다--

찾고 있는 구성 부분은 /apps/gedit-2/preferences/editor/font에 있습니다.

파일 확장자에 따라 이를 변경하는 작은 스크립트를 작성하면 완료됩니다.)

관련 정보