Geditに新しい言語を追加する

Geditに新しい言語を追加する

Geditに新しい言語を追加する必要があります。問題はGeditの言語メニューに含まれていますが、構文は強調表示されず、Geditはファイルサフィックスでのみ言語を識別できないことです。

MIME-TYPEを記述する.langファイルとXMLファイルを作成しました。

LANG file - /usr/share/gtksourceview-3.0/language-specs/test.lang
MIME-TYPE file - /usr/share/mime/packages/test.xml

作成後にMIMEデータベースを更新しました。

sudo update-mime-database /usr/share/mime

次のこと

test.xml1)代わりにファイルを/usr/share/mime/applicationsフォルダにコピーしてみましたが、うまく/usr/share/mime/packagesいきませんでした。

/etc/mime.types2)MIMEタイプを次のように入れてみました。

text/x-test test

また、効果はありません。


テスト言語

<?xml version="1.0" encoding="UTF-8"?>
<language id="test" _name="Test" version="1.0" _section="Source">
    <metadata>
        <property name="mimetypes">text/x-test</property>
        <property name="globs">*.test</property>
        <property name="line-comment-start">//</property>
        <property name="block-comment-start">/*</property>
        <property name="block-comment-end">*/</property>
    </metadata>

    <styles>
       <style id="comment" _name="Comment" map-to="def:comment"/>
       <style id="keyword" _name="Keyword" map-to="def:keyword"/>
    </styles>

    <definitions>
        <context id="if0-comment" style-ref="comment">
          <start>\%{preproc-start}if\b\s*0\b</start>
          <end>\%{preproc-start}(endif|else|elif)\b</end>
          <include>
            <context id="if-in-if0">
              <start>\%{preproc-start}if(n?def)?\b</start>
              <end>\%{preproc-start}endif\b</end>
              <include>
                <context ref="if-in-if0"/>
                <context ref="def:in-comment"/>
              </include>
            </context>
            <context ref="def:in-comment"/>
          </include>
        </context>

        <context id="keywords" style-ref="keyword">
            <keyword>hello</keyword>
            <keyword>hi</keyword>
        </context>

        <!--Main context-->
        <context id="test">
            <include>
                <context ref="if0-comment"/>
                <context ref="keywords"/>
            </include>
        </context>

    </definitions>
</language>

テスト.xml

<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info" >
  <mime-type type="text/x-test">
    <sub-class-of type="text/plain"/>
    <comment xml:lang="en">TEST language document</comment>
    <comment xml:lang="cs">Dokument v jazyce TEST</comment>
    <glob pattern="*.test"/>
  </mime-type>
</mime-info>

ベストアンサー1

ついに私はそれを見つけた。 ~によるとGTK言語リファレンス versionタグの属性はで<language>なければなりません2.0

したがって、正しい<language>ラベルは次のようになります。

<language id="test" _name="Test" version="2.0" _section="Source">

おすすめ記事