gedit のファイルタイプごとの設定

gedit のファイルタイプごとの設定

私は、Python ソフトウェアの開発と Latex ドキュメントの作成という 2 つの異なるタスクに gedit を使用しようとしています。どちらも純粋なテキスト ファイルに基づいていますが、非常に異なります。たとえば、Python コードは、コードの構造 (ループ、関数など) を確認できるように配置する必要があります。したがって、等幅フォントが適しています。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にあります

ファイル拡張子に応じて変更する小さなスクリプトを作成すれば完了です ;)

関連情報