gedit中的每个文件类型首选项

我正在尝试将gedit用于两个不同的任务:开发Python软件和编写Latex文档。 两者都基于纯文本文件,但它们非常不同:例如,需要对齐Python代码才能看到代码的结构(循环,函数,……)。 因此Monospace字体是一件好事。 对于编写Latex文档,我主要需要可读性。 使用打印时使用的字体最好不要使用等宽字体。

有没有办法告诉gedit使用每个文件类型的首选项? 例如,Garamond用于* .tex,Monospace用于* .py? (但这个问题不仅限于字体,也不限于Latex和Python)。

好吧,因为它似乎不可能,我为gedit2组装了一个proto-plugin,目前适用于我。 我仍然希望有人有更好的答案……

〜/ .gnome2 / gedit中/插件/ 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中/插件/ mimeprefs.gedit-插件

 [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:

 [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') 

据我所知,答案是“不”……但……

gconf-editor允许你设置一个打印字体,不管是gedit在/ apps / gedit-2 / preferences / print / fonts选项上当前选择的字体,也许还有一个选项来选择显示字体。 如果这是真的,简单的脚本可以根据文件的扩展名为您更改。

– 编辑 –

您正在寻找的配置部件位于/ apps / gedit-2 / preferences / editor / font

根据文件扩展名制作一个小脚本来改变它,你就完成了;)