gedit 中每個檔案類型的首選項

gedit 中每個檔案類型的首選項

我正在嘗試使用 gedit 來完成兩項不同的任務:開發 Python 軟體和編寫 Latex 文件。兩者都基於純文字文件,但它們有很大不同:例如,Python 程式碼需要對齊才能看到程式碼的結構(循環、函數等)。因此,等寬字體是件好事。對於編寫Latex文檔,我主要需要可讀性。最好使用用於列印的字體來實現這一點,並且絕對不是等寬字體。

有沒有辦法告訴 gedit 使用每個檔案類型的首選項?例如 Garamond 代表 *.tex,Monospace 代表 *.py? (但這個問題不僅限於字體,也不限於 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

建立一個小腳本來根據檔案副檔名更改它,然後就完成了;)

相關內容