Results 1 to 10 of 15

Thread: Custom Code Highlighting for gedit - and your system

Threaded View

  1. #1
    Join Date
    Mar 2008
    Beans
    31

    Custom Code Highlighting for gedit - and your system

    This is a technique to define a custom language definition for your system for use in gedit and possibly other ide's that inherit the system definition for the language

    by creating a new language definition xml file in:
    /usr/share/gtksourceview-2.0/language-specs/

    or editing the existing files to fit your needs.
    i.e. grouping functions into seperate categories to be colored differently than each other for better recognition while your programming.

    you then create a xml file for the style in:
    /usr/share/gtksourceview-2.0/styles/

    and then select that style xml file in gedit.

    previous versions of gedit had an interface for customizing the colors and future versions are expected to as well but currently editing the xml files is the only way to achieve these results.

    to find out if you have the interface in your version of gedit. go to
    edit>preferences
    if you see a tab called 'highlighting syntax' you have the interface. if not you don't and should follow what I've laid out below.

    the language xml file
    my suggustion is to copy an existing language file and then rename it. I copied php.lang because it's the language I'm most familiar with

    I renamed it fc_comdoc.lang and made a syntax for making my checklists pretty colors. and readable at a glance.

    major sections in the document and how they work


    a quick overview:
    - language root tag,
    --- id attribute is used for identifying which context tags to load
    --- _name is what's displayed in the menu for syntax highlighting
    --- _section is the section it is grouped under in the syntax highlighting menu

    - styles tag
    --- style tag defines the style
    ------ id attribute is what is referenced by the context tag
    ------ map-to attribute is used to redirect it to a different style

    - definitions tag is where the actual regular expression patterns are defined
    --- id attribute is used by the last context tag which has the same id as the language in order to load the pattern
    --- style-ref tag references an above style by it's id
    --- some other attributes related to processing the pattern such as end-at-line-end

    - the last context tag which has the same id as the language contains and include tag whose children are also context tags and these link to all the context tags defined above.

    again in detail:

    root tag is <language [attributes]>
    attributes of this tag:
    - _section is the section it will be under view>highlight syntax>'section_name' gedit menu
    - _name attribute is what will show up in the "view>highlight syntax>section_name>'language name'

    the first child of the language tag is <metadata>
    relevant child tags
    - <property name="mimetypes">text/x-php; etc...</property> this relates to the filetype defined in the name of a mime.types file. i don't think defining this is mandatory
    - <property name="glob">*.php;*.phtml</property> this controls what file types are automatically selected to highlight under this language as defined by thier file extension

    the next node is <styles> containing a series child of tags that look like
    <style id="style_id_name_here" _name="style_name" map-to="type:style_id">
    - id : this is the id tag referenced by the style-ref attribute of the definition>context tags (see below)
    - the _name tag I have no idea what this does. presumably gives it a name...
    - the map-to tag redirects the style to another style. this tag is optional. the purpose is to be able to change one style in the style xml file which will change multiple styles, all that have a map-to attribute with a value pointing to them.

    the next tag is <definitions> which has several <context> child tags
    the context tags define the actual patters gedit will search for highlighting
    <context [attributes]>
    the context attributes are as follows
    - id this is the id that will be referenced below in the last context tag whos id matches the id of the language (more on this below)
    - style-ref this references the id of one of the styles defined above in the <styles> tag(s)
    - some other properties pertaining to treatment of the regular expression such as end-at-line-end and extend-parent

    the child tags for the <context> tag include <start> , <end>, <include> and a few others. these are the tags that define the regular expression for pattern matching which i wont go into in detail.

    the most important thing and the thing your most likely to overlook is this:
    the last context tag must have the same id as the id of the language
    and must reference all of the context tags above as new context tags with the attribute ref="id of above context tag"

    only context tags referenced here will be loaded.



    the style xml file
    in:
    /usr/share/gtksourceview-2.0/styles/

    this file is much simpler on the condition that your aware of the namespace syntax.

    the first tag is <style [options]>
    the id and name attributes are used for reference in the preferences tab

    the <color> tags
    these define colors that can be referenced throughout this xml document

    the <style> tags
    these are the styles, the actual colors and font formatting that will be applied to the pattern matches.
    attributes:
    - name - this is how the style links to the tags in the languages. the namespace formatting is as follows name="language:style" where language is the name of the language and style is the id of the style tag in the language xml file.
    e.g. name="php:function" will refer to the style tag whose id=function in the php language document.

    that's it custom highlighting in gedit.

    also the language files are probably used else where in the system as their not in the gedit folder so they make effect highlighting in other programs too which is good, or bad depending on what you want.

    post any questions you have. or point out anything in this that is vaugue or confusing.

    I'm sooooo excited to be able to customize the highlighting of languages and even make my own. I've created a new language txtcd for text comand document and txtap for text action plan and have been so happy with how much easier it is to keep track of my tasks when I can alter the colors to prioritize my list by adding a few charactors at the begining of the line for the task such as.
    ->
    +>
    !+>
    or
    =

    enjoy

    and seriously post your questions (or criticisms). don't be shy.
    Last edited by firecrow8; March 27th, 2008 at 07:15 AM. Reason: forgot something
    an OS that does what I want it to do.... Wooo Hoooo

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •