/usr/share/nano/js.nanorc configuration: syntax highlighting

I have a question regarding syntax highlighting with JavaScript using nano. I have tweaked the js.nanorc file to my liking using the colors I prefer:
## New updated taken from [url]http://wiki.linuxhelp.net/index.php/Nano_Syntax_Highlighting[/url]
syntax "JavaScript" "\.(js)$"
## Default
color brightgreen "^.+$"
## Decimal, cotal and hexadecimal numbers
color brightyellow "\<[-+]?([1-9][0-9]*|0[0-7]*|0x[0-9a-fA-F]+)([uU][lL]?|[lL][uU]?)?\>"
## Floating point number with at least one digit before decimal point
color brightyellow "\<[-+]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([EePp][+-]?[0-9]+)?[fFlL]?"
color brightyellow "\<[-+]?([0-9]+[EePp][+-]?[0-9]+)[fFlL]?"
## Keywords
color brightcyan "\<(break|case|catch|continue|default|delete|do|else|finally)\>"
color brightcyan "\<(for|function|if|in|instanceof|new|null|return|switch)\>"
color brightcyan "\<(switch|this|throw|try|typeof|undefined|var|void|while|with)\>"
## Type specifiers
color brightmagenta "\<(Array|Boolean|Date|Enumerator|Error|Function|Math)\>"
color brightmagenta "\<(Number|Object|RegExp|String)\>"
color brightmagenta "\<(true|false)\>"
## String
color brightblue "L?\"(\\"|[^"])*\""
color brightblue "L?'(\'|[^'])*'"
## Escapes
color red "\\[0-7][0-7]?[0-7]?|\\x[0-9a-fA-F]+|\\[bfnrt'"\?\\]"
## Comments
color brightwhite start="/\*" end="\*/"
color brightwhite "//.*$"
However, I would also like the rendering to be a little different. For example:
var code = function(nano) {
console.log("I would like these parenthesis to be a different color than the keywords");
The parenthesis and keywords(var, function, for, while....etc) are the same color, how can I adjust the rendering so that the parenthesis or brackets will be a different color?
Last edited by rg_arc (2012-04-04 13:40:31)

doug piston wrote:I deal with alot of .mk files and would love to see it there.
You mean GNU makefiles?
I'm afraid they might be out of scope for this generic config-file syntax.
Logically they're not system config files, and technically they're a pretty specialized and complex format (different "types" of rules, rules spanning multiple lines, rules containing arbitrary Bash code, etc.).
This is how an .mk file currently looks with this highlighting syntax:
$ nano -Y conf /usr/lib/httpd/build/rules.mk
And apart from highlighting variables of the form $$abc or $(abc), I'm not sure how much can be improved here without breaking the highlighting for more conventional config files.
It would probably be better to create a specialized highlighting syntax just for .mk files.
EDIT: I sat down and did just that, here's the result: nano syntax highlighting: GNU makefiles, and here is how the above makefile snipped looks with it:
Last edited by sas (2012-02-01 15:18:52)

Similar Messages

  • Nano syntax highlighting: catch-all syntax for configuration files

    After years of using nano, I only recently learned that it supports syntax coloring... (Why would they turn that off by default? ) Well, I thought I'll make up for it by making extra good use of it from now on...
    Unfortunately it didn't ship a highlighting syntax for the the kind of files that I use nano the most for: system configuration files.
    So I wrote my own, and after tweaking a bit here and there whenever I encountered a config file for which the highlighting wasn't satisfactory at first, I think the result is now good enough (screenshots below) that it's worth sharing with my fellow Arch users:
    Code & Instructions:
    Here is the syntax definition:
    # config file highlighting
    syntax "conf" "(\.(conf|config|cfg|cnf|rc|lst|list|defs|ini|desktop|mime|types|preset|cache|seat|service|htaccess)$|(^|/)(\w*crontab|mirrorlist|group|hosts|passwd|rpc|netconfig|shadow|fstab|inittab|inputrc|protocols|sudoers)$|conf.d/|.config/)"
    # default text
    color magenta "^.*$"
    # special values
    icolor brightblue "(^|\s|=)(default|true|false|on|off|yes|no)(\s|$)"
    # keys
    icolor cyan "^\s*(set\s+)?[A-Z0-9_\/\.\%\@+-]+\s*([:]|\>)"
    # commands
    color blue "^\s*set\s+\<"
    # punctuation
    color blue "[.]"
    # numbers
    color red "(^|\s|[[/:|<>(){}=,]|\])[-+]?[0-9](\.?[0-9])*%?($|\>)"
    # keys
    icolor cyan "^\s*(\$if )?([A-Z0-9_\/\.\%\@+-]|\s)+="
    # punctuation
    color blue "/"
    color brightwhite "(\]|[()<>[{},;:=])"
    color brightwhite "(^|\[|\{|\:)\s*-(\s|$)"
    # section headings
    icolor brightyellow "^\s*(\[([A-Z0-9_\.-]|\s)+\])+\s*$"
    color brightcyan "^\s*((Sub)?Section\s*(=|\>)|End(Sub)?Section\s*$)"
    color brightcyan "^\s*\$(end)?if(\s|$)"
    # URLs
    icolor green "\b(([A-Z]+://|www[.])[A-Z0-9/:#?&$=_\.\-]+)(\b|$| )"
    # XML-like tags
    icolor brightcyan "</?\w+((\s*\w+\s*=)?\s*("[^"]*"|'[^']*'|!?[A-Z0-9_:/]))*(\s*/)?>"
    # strings
    color yellow "\"(\\.|[^"])*\"" "'(\\.|[^'])*'"
    # comments
    color white "#.*$"
    color blue "^\s*##.*$"
    color white "^;.*$"
    color white start="<!--" end="-->"
    To install, save the above above code snippet as a file called conf.nanorc in the folder /usr/share/nano/ (or /usr/local/share/nano/ or similar if you feel strongly about the /usr <--> /usr/local separation), and then add the following to the end of the file /etc/nanorc:
    ## Configuration files (catch-all syntax)
    include "/usr/share/nano/conf.nanorc"
    Hints:
    The colors I chose look good (imo) with the terminal background and color settings that I use, but might not look good, or even readable, with yours, so simply change the color names in the code snippet to whatever you prefer - valid color names are:
    If you use a console with white background, you'll have to change at least the white color I chose for comments and punctuation.
    The first code line in the snippet includes a regular expression that defines for which file names this syntax highlighting should be used. Whenever you encounter a config file that is not matched by this, but you would still like to open it with syntax highlighting, you can manually select this syntax with nano's -Y switch, like so:
    nano -Y conf myConfigFile
    Technical Note:
    It's implemented as a single catch-all syntax, since nano chooses which syntax to apply based on the filename, and in the case of config files usually not much can be learned about the content format from the file name extension (.conf can by anything from flat key/value tuples to XML, .ini can be the official INI format or something else, etc...).
    This means that some compromises have been made, so with this highlighting syntax probably no config file looks 100% as good as a highlighting syntax that would be specifically optimized for one kind of config format, but all in all the vast majority of config files should look pretty good.
    Screenshots:
    /etc/rc.conf,  /etc/hosts:
    /etc/pacman.conf,  /etc/group:
    xorg.conf,  some .desktop file:
    httpd.conf (Apache config),  php.ini:
    More screenshots:
    /etc/fonts/fonts.conf (uses XML)
    /etc/inittab
    /etc/fstab
    /etc/inputrc
    /etc/mime.types
    /etc/protocols
    /etc/xinetd.conf
    See Also:
    nano syntax highlighting: GNU makefiles
    Update [2012-01-28]: Made some more improvements to the syntax definition (see post)
    Last edited by sas (2012-02-01 15:26:43)

    doug piston wrote:I deal with alot of .mk files and would love to see it there.
    You mean GNU makefiles?
    I'm afraid they might be out of scope for this generic config-file syntax.
    Logically they're not system config files, and technically they're a pretty specialized and complex format (different "types" of rules, rules spanning multiple lines, rules containing arbitrary Bash code, etc.).
    This is how an .mk file currently looks with this highlighting syntax:
    $ nano -Y conf /usr/lib/httpd/build/rules.mk
    And apart from highlighting variables of the form $$abc or $(abc), I'm not sure how much can be improved here without breaking the highlighting for more conventional config files.
    It would probably be better to create a specialized highlighting syntax just for .mk files.
    EDIT: I sat down and did just that, here's the result: nano syntax highlighting: GNU makefiles, and here is how the above makefile snipped looks with it:
    Last edited by sas (2012-02-01 15:18:52)

  • JSP Syntax Highlighting

    Does anyone know how to configure Syntax highlighting for JSP's in JDeveloper v3.2?
    Thanks
    Mark

    You need a plugin which supports JSP.
    MyEclipse does (along with a lot of other stuff)
    Lomboz also provides a jsp editor
    You can find a whole lot of eclipse plugins at
    http://www.eclipseplugincentral.com/
    http://eclipse-plugins.2y.net/eclipse/index.jsp
    Cheers,
    evnafets

  • Pacman.conf file syntax highlighting for nano

    Hi, here is pacman.conf file syntax highlighting for nano. It may be useful for those who edit their pacman.conf regularly.
    Just put this lines in the end of your /etc/nanorc or ~/.nanorc file:
    # syntax highlithing in pacman.conf
    syntax "pacman.conf" "pacman\.conf$"
    color brightwhite start="\[" end="\]"
    color brightyellow ".*="
    color brightred "=.*"
    color white "="
    color brightblue "\[|\]"
    color brightcyan start="/|http|ftp" end=".*"
    color green "#.*"
    In this thread you can find rc.conf file syntax highlighting.

    thank you! i always accidentally open up nano, find out text is practically unreadable with its default colours, close it and then wait the horrific 4 seconds it takes for emacs to spring to life.

  • Rc.conf file syntax highlighting for nano

    Hey, here is rc.conf file syntax highlighting for nano. It may be useful for those who edit their rc.conf regularly.
    # syntax highlithing in rc.conf
    syntax "rc.conf" "rc\.conf$"
    color brightwhite ""(\\.|[^\"])*""
    color brightwhite "\((\\.|[^\"])*\)"
    color brightred "![^> ]+"
    color brightcyan "@[^> ]+"
    color brightyellow ".*="
    color white "="
    color brightblue ""|\(|\)"
    color green "#.*"
    Put this lines into /etc/nanorc or ~/.nanorc

    thank you! i always accidentally open up nano, find out text is practically unreadable with its default colours, close it and then wait the horrific 4 seconds it takes for emacs to spring to life.

  • Enable syntax highlighting with configuration file in emacs

    When editing configuration files such as .procmailrc, .fetchmailrc, Emacs won't automatically highlight syntax for me.
    I can enable syntax highlighting in Vim by appending "syntax on"  to the .vimrc.
    I tried adding "global-font-lock-mode t" in the .emacs file, but it didn't solve my problem.
    What is the solution?

    igndenok wrote:
    Some of my config file have this (using conf-unix-mode)
    # this is .somerc
    # -*- conf-unix -*-
    Or using this in your .emacs
    (add-to-list 'auto-mode-alist '("\\.*rc$" . conf-unix-mode))
    I followed your advice, and it does have some syntax highlighting, but less than Vim does.
    For example, Vim will highlight all the names of colors in the .muttrc file, but Emacs doesn't.
    I guess Emacs is not as strong as Vim when it comes to editing configuration files.
    Last edited by yu3k (2011-09-14 10:06:47)

  • Syntax Highlighting in nano?

    After seeing nano running on a Linux machine while editing a python file I realised that it was different from my mac version which lacked the beautful syntax highlighting. Anyway to get syntax highlighting? and update the nano version? -Cheers

    How to use syntax highlighting with the GNU nano text editor

  • [SOLVED] VIM: different syntax highlighting for new vs existing file

    I've had this minor nagging issue for a while that I've been trying to figure out, but I just don't know where to look.
    It is most obvious with LaTeX files (*.tex).  When I create a new file with "vim file.tex" it is recognized as a latex file and I get syntax highlighting, but it seems odd, or off.  When I close then reopen the same file, it gets "propper" syntax highlighting.
    I gather that this must be because of the two different mechanisms for matching the syntax type: filename versus content.  When the file is new, vim only uses the extension.  Once there is a latex comand (e.g., "\documentclass{article}") it recognizes it as something else and the highlighting style is different.
    It turns out just by actually elaborating exactly what the problem was, I was able to find the solution.  I looked for how vim recognizes the files, and found two relevant lines in /usr/share/vim/vim73/filetype.vim on lines 2093 and 2094.  Apparently the .tex filetype is not the same as .latex and others.  I changed it so it was, and I got the desired behavior.
    I thought about just not posting this - but it may be useful for others.

    You're right about it being overridden.  This change should be able to be placed in ~/.vimrc though.
    Well  that was foolish - I should have read the comments right below in that file.  It says exactly how to set it in vimrc.  I've now added the following to my ~/.vimrc and this is completely solved without modifying the /usr/... file.
    let g:tex_flavor = "tex"
    Last edited by Trilby (2013-03-29 16:11:26)

  • Archlinux policy WRT /usr/share/vim/vim72 vs. /usr/share/vim/vimfiles

    Hi all,
    with the recent vim upgrade I have notified a couple of package maintainers that they would have to move some vim support files that are in their packages (e.g. syntax highlighting) out of /usr/share/vim/syntax and similar into subdirectories. However, I'm afraid I might have suggested something wrong there: My suggestion was that they be put in /usr/share/vim/vimfiles/syntax and so on, but Pierre has already updated his cmake package (bugreport) and moved it into /usr/share/vim/vim72/syntax etc.
    Since I've also seen similar discussions at least in the latexsuite package (now removed since the packages have been renamed), and so I wonder what is the difference resp. the Archlinux policy with regard to those two directories: /usr/share/vim/vim72 vs. /usr/share/vim/vimfiles. (Personally, I thought that the vim72 subdirectory is for the distribution of vim itself, whereas distribution-specific stuff would go to the vimfiles subdirectory. - That's where the latex-suite package's files are now, too.)
    Anyone with more sound reasoning or an insight into some quasi-"official" view on the question?
    TIA,
    Andreas

    Actually the bug report asked to move from /usr/share/vim to /usr/share/vim/vimfiles
    So I am confused..
    Edit : ok I see now : http://repos.archlinux.org/viewvc.cgi/c … 3&r2=52345
    Pierre moved from /usr/share/vim to /usr/share/vim/vim72 instead.
    Last edited by shining (2009-10-08 11:13:01)

  • Syntax Highlighting for MATRIXx MathScript and TPL

    There have been some questions about text editors for MATRIXx, so I wanted to let everyone know about an application note that we just posted. It describes how to configure a syntax highlighter for use with MathScript and Template Programming Language (TPL). There is also an example of how Crimson Editor can be configured. I choose Crimson Editor because it was free, but the same thing can be done in other syntax highlighters. Using a syntax highlighter makes MATRIXx code a lot easier to read.
    http://zone.ni.com/devzone/conceptd.nsf/webmain/C43375149CB01C3186256E530081EAA5
    While I am at it, I am going to point out some other resources. The application note is located on Developer Zone section of our website, where
    you can find other MATRIXx examples and tutorials:
    http://zone.ni.com/devzone/devzone.nsf/webcategories/A92DB8BA2DE149F486256CBC00655A0C?opendocument
    If you have code or examples that you want to share with other users you can submit the example to the Example Code Library:
    http://www.ni.com/devzone/dev_exchange/ex_search.htm
    Suggestions and feedback can be submitted from Product Feedback section of Contact NI:
    http://sine.ni.com/apps/we/nicc.call_me?p_action=country&p_lang_id=US
    And of course the main MATRIXx page is:
    http://www.ni.com/matrixx
    Carl L
    National Instruments

    I found another editor with syntax highlighting capabilities for MATRIXx. The editor is VIM which is based on the Unix VI editor, and is available on both Solaris and Windows.
    www.vim.org
    Carl L
    National Instruments
    www.ni.com/matrixx

  • Editor for ASP with syntax highlighting? (I use Bluefish)

    Is there a decent, simple (or not-so-simple) editor for ASP code?  Or, is there a way to get Bluefish to highlight ASP correctly?
    Don't suggest VIM.  I love it, but I haven't learned the intricacies of it yet. 
    And, yes, I apologize for writing ASP... 

    Hi,
    this is a short introduction, might help at start:
    Starts with some generell settings, please note that I just add these
    settings to the files in /usr/share/scite, most of the stuff can also be set in
    files in your ~. Refer to scite docs for filenames onn that.
    SciTEGlobal.properties: general settings which are mostly scattered over
    the file. Find the lines and tweak them.
    # I like my Scite with tabs and a statusbar, displaying line and column
    tabbar.visible=1
    tabbar.hide.one=1
    tabbar.multiline=1
    statusbar.visible=1
    #comment out this line to have it displayed under the textfield not besides
    #split.vertical=1
    #display line numbers (create enough space for 4 digits)
    line.margin.visible=1
    line.margin.width=4
    # ask b4 automatically reload an altered file on disk
    are.you.sure.on.reload=1
    # show name and number of my tab in titlebar
    title.full.path=1
    title.show.buffers=1
    # save the buffer state in a file
    and reload on startup
    save.recent=1
    save.session=1
    load.on.activate=1
    # allows 25 tabs
    buffers=25
    # I plain hate tabs and using 8 spaces is waste of place
    # converts tab hits to spaces
    tabsize=2
    indent.size=2
    use.tabs=0
    # some sane fontsettings: - the ! activates pango -> AA fonts
    # sets them all to similar sizes and monospace font
    # after the if PLAT_GTK these must be tabs in intendation!
    if PLAT_GTK
    font.base=font:!bitstream vera sans mono,size:9
    font.small=font:!bitstream vera sans mono,size:8
    font.comment=font:!bitstream vera sans mono,italics,size:9
    font.code.comment.box=$(font.comment)
    font.code.comment.line=$(font.comment)
    font.code.comment.doc=$(font.comment)
    font.text=font:!bitstream vera sans mono,size:9
    font.text.comment=font:!bitstream vera sans mono,size:8
    font.embedded.base=font:!bitstream vera sans mono,size:9
    font.embedded.comment=font:!bitstream vera sans mono,size:9
    font.monospace=font:!bitstream vera sans mono,size:9
    font.vbs=font:!bitstream vera sans mono,italics,size:9
    # uuh, netscape - long time not seen, replce with firefox
    if PLAT_GTK
    command.print.*=a2ps "$(FileNameExt)"
    command.scite.help=mozilla-firefox "file://$(SciteDefaultHome)/SciTEDoc.html"
    # add a vertical line at column 80
    edge.column=80
    edge.mode=1
    edge.colour=#E0E0E0
    go on to html.properties file; to get the advantages you need the php.api
    and the phpfunctions.properties from http://scintilla.sourceforge.net/SciTEExtras.html
    there you also find api files for ASP
    #replace netscape with mozilla-firefox again
    if PLAT_GTK
    command.go.$(file.patterns.web)=mozilla-firefox "file:///$(FilePath)"
    # load the .api file which I downloaded from the web; it contains, per line,
    # a short explaination of each command
    # $file.patterns.php is defined for *.php and friends by file extensions
    api.$(file.patterns.php)=$(SciteDefaultHome)/php.api
    # the calltips for the hypertext lexer shall not be case sensitive
    calltip.hypertext.ignorecase=1
    # define how the calltipps should be parsed, the following is the same as
    # the standard anyway, but might be overwritten by some people in SciTEGlobal
    calltip.hypertext.parameters.start=(
    calltip.hypertext.parameters.end=)
    calltip.hypertext.parameters.separators=,
    # some calltips have an additionally explaination after the final ")"
    # -this makes display them in a second line
    calltip.hypertext.end.definition=)
    # autocopleter stuff
    # defines which type of characters let the autocompletion pop up
    autocomplete.hypertext.start.characters=_$(chars.alpha)
    # also the autocompletion should not be case sensitive since, grrr php and html
    autocomplete.html.ignorecase=1
    # extend the "Extras" menu with some commands
    # Tidy Checking
    command.name.1.$(file.patterns.web)=HTML Tidy Validate
    command.1.$(file.patterns.web)=tidy -quiet -errors $(FilePath)
    error.select.line=1
    # Tidy Cleanup and indent
    command.name.2.$(file.patterns.web)=HTML Tidy Cleanup
    command.2.$(file.patterns.web)=tidy -i -wrap 80 -m $(FilePath)
    # the executed command alternates the file, so it should be saved b4 and must be
    # re-read -> activate are.you.sure.on.reload=1 , makes things easier to handle
    # !!!! THERE IS NO UNDO ON THIS COMMAND !!!!
    command.save.before.1.$(file.patterns.web)=1
    command.is.filter.2.$(file.patterns.web)=1
    # activate a lint checker for php files
    command.name.1.$(file.patterns.php)=Check PHP syntax
    command.1.$(file.patterns.php)=php -l $(FilePath)
    the tidy doesn't work onClick, but it shows you the errors in line and column
    some pictures to show stuff:
    the gray edge at column 80 and the php-lint checker in action:
    autocomplete code:
    the calltip, NOTE: it is wrapped after the ) which was our setting:
    calltip.hypertext.end.definition=)
    and the delimiter , let highlight the the correct argument:
    whoever want's jump in and wikify that, go ahead, leave me a note where
    I shall help.
    -neri

  • Vim, Perl and syntax highlight

    Hello all,
    Suppose you have a little snippet of Perl code like such:
    sub foo # some comment with keywords for die and or not
    print "In sub foo!\n";
    The comment in the sub line is not treated (i.e. highlighted) as a comment. Rather, it is highlighted as regular source code. Seems like a bug, but before reporting it to the maintainer, I wanted to see if anyone else shared the same issue.
    To clarify: this refers only to highlight in vim, running the code works as expected. And I took care to see if this could be the results of my settings: the problem seems in fact, to be with the perl.vim file (in my system: /usr/share/vim/vim73/syntax/perl.vim).
    So, can anyone reproduce this behaviour?

    frabjous wrote:Yes, same for me. (I don't write perl, so I don't have anything special installed for it other than the default /usr/share/vim73/syntax/perl.vim.)
    Hum, ok. I'll report it to the maintainer then.

  • [SOLVED] Associate extensions to syntax highlights pluma/gedit

    Hi,
    I am trying to make pluma/gedit use the SQL syntax highlight by default, when I open or create a file
    with extension .hql (hive).
    I think I added correctly the mime for hql file, but it still doesn't work.
    Can you help me with this issue?
    (also if there is an hive syntax highlighter for pluma it is even better, but for the moment I would be happy just to highlight it as an Sql file).
    Thanks a lot in advance for the help,
    Cheers,
    Luca
    Last edited by lucacerone (2014-12-10 11:50:17)

    Hi,
    go to:
    /usr/share/gtksourceview-3.0/language-specs
    edit sql.lang:
    sudo gedit sql.lang
    go to line 27 and change
    <property name="globs">*.sql</property>
    to
    <property name="globs">*.sql;*.hql</property>
    and restart gedit. Worked for me (Ubuntu 14.04 LTS)
    Cheers

  • [self-SOLVED]vim + lilypond syntax highlighting

    I'm trying to get vim to use syntax highlighting in lilypond files. Apparently lilypond comes with the necessary files, but I have not been able to make vim find them (?). I am not very experienced with vi(m), so there might be something wrong with my setup.
    I have, of course, both vim and lilypond installed. The files for lilypond syntax highlighting are in subdirectories of /usr/share/lilypond/2.12.3/vim/. Vim syntax highlighting works for other files, such as C++, HTML, etc., so no problem there. My ~/.vimrc file contains
    set runtimepath+=/usr/share/lilypond/2.12.3/vim/
    as per instruction given in http://lilypond.org/doc/v2.12/Documenta … m/Vim-mode (and the path is correctly modified). But when I open a lilypond file (with the correct .ly suffix) all I get is black and white. What's the problem?
    [EDIT: Oh heck, nevermind! Apparently I was getting too tired to read instructions properly. Was missing the ~/.vim/filetype.vim file described in the above link.]
    Last edited by lotuskip (2010-04-12 18:33:42)

    You're right about it being overridden.  This change should be able to be placed in ~/.vimrc though.
    Well  that was foolish - I should have read the comments right below in that file.  It says exactly how to set it in vimrc.  I've now added the following to my ~/.vimrc and this is completely solved without modifying the /usr/... file.
    let g:tex_flavor = "tex"
    Last edited by Trilby (2013-03-29 16:11:26)

  • Different Styles in PlainView - Syntax Highlighting?

    Hi,
    I've managed to extend PlainView and looking at old JEdit code I have the syntax highlighting working for the most part. However, at certain times while typing the cursor starts to get way ahead of the text it's typing. And as I backspace on the line the cursor eventually gets closer to the character the closer it gets to the start of the line.
    I'm overridding the "drawUnselectedText()" method in PlainView to do the coloring.
    Here's the code, you can see the call to SyntaxUtilities.paintSyntaxLine() which is JEdit's class to do the drawing.
             * Renders the given range in the model as normal unselected text. This
             * is implemented to paint colors based upon the token-to-color
             * translations. To reduce the number of calls to the Graphics object,
             * text is batched up until a color change is detected or the entire
             * requested range has been reached.
             * @param g
             *            the graphics context
             * @param x
             *            the starting X coordinate
             * @param y
             *            the starting Y coordinate
             * @param p0
             *            the beginning position in the model
             * @param p1
             *            the ending position in the model
             * @returns the location of the end of the range
             * @exception BadLocationException
             *                if the range is invalid
            protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException {
                System.out.println("p0: " + p0 + " p1: " + p1 + " x: " + x + " y: " + y);
                // Get the start of the element
                int lineIndex = doc.getDefaultRootElement().getElementIndex(p0);
                // Get the element for the line
                Element elem = doc.getDefaultRootElement().getElement(lineIndex);
                System.out.println("lineIndex: " + lineIndex + " elemStartIDX: " + elem.getStartOffset() + " elemEndIDX: " + elem.getEndOffset());
                // Get the line text
                doc.getText(p0, p1 - p0, currentLineText);
                // If highlighting, mark the tokens
                if (marker != null) {
                    Token t = marker.markTokens(currentLineText, lineIndex);
                    x = SyntaxUtilities.paintSyntaxLine(currentLineText, t, styles, this, g, x, y, p0, p1);
                    System.out.println("Painted line at: " + x);
                } else {
                    // No highlighting requested, draw normal text
                    Font defaultFont = g.getFont();
                    Color defaultColor = styles[0].getColor(); // Default color of text
                    g.setFont(defaultFont);
                    g.setColor(defaultColor);
                    x = Utilities.drawTabbedText(currentLineText, x, y, g, this, p0);
                // Set the last line processed
                lastLine  = lineIndex;
                return x;
    Here is the code from the paintSyntaxLine() method:
         * Paints the specified line onto the graphics context. Note that this
         * method munges the offset and count values of the segment.
         * @param line
         *            The line segment
         * @param tokens
         *            The token list for the line
         * @param styles
         *            The syntax style list
         * @param expander
         *            The tab expander used to determine tab stops. May be null
         * @param gfx
         *            The graphics context
         * @param x
         *            The x co-ordinate
         * @param y
         *            The y co-ordinate
         * @return The x co-ordinate, plus the width of the painted string
        public static int paintSyntaxLine(Segment line, Token tokens, SyntaxStyle[] styles, TabExpander expander, Graphics gfx, int x, int y, int p0, int p1) {
            Font defaultFont = gfx.getFont();
            Color defaultColor = Color.black;
            FontMetrics fm = gfx.getFontMetrics(defaultFont);
            int offset = 0;
            while (tokens != null && tokens.id != Token.END) {
                int length = tokens.length;
                if (tokens.id == Token.NULL) {
                    if (!defaultColor.equals(gfx.getColor()))
                        gfx.setColor(defaultColor);
                    if (!defaultFont.equals(gfx.getFont()))
                        gfx.setFont(defaultFont);
                } else {
                    styles[tokens.id].setGraphicsFlags(gfx, defaultFont);
    //                fm = gfx.getFontMetrics();//[tokens.id].getStyledFont(defaultFont);
    //                FontMetrics dfm = Toolkit.getDefaultToolkit().getFontMetrics(defaultFont);
    //                System.out.println("Font Info: CharWidth[" + fm.charWidth(line.array[p1])+"], Max Advance[" + fm.getMaxAdvance()+"]");
    //                System.out.println("Default Font Info: CharWidth[" + dfm.charWidth(line.array[p1])+"], DMax Advance[" + dfm.getMaxAdvance()+"]");
    ////                x = fm.charsWidth(line.array, p0, length);
                line.count = length;
                x = Utilities.drawTabbedText(line, x, y, gfx, expander, p0);
                line.offset += length;
                offset += length;
                tokens = tokens.next;
            return x;
    I'm not sure what the problem is..i thought it might be an issue with the View and drawing multiple font styles. Since plain view only deals with a single font color and size. I tried using LabelView but that seems to need a StyledDocument and I had problems when I tried to use DefaultStyledDocument for my syntaxdocument. I was getting strange offset issues when using the Segment class.
    Here's what I posted: http://forum.java.sun.com/thread.jspa?threadID=780801
    I am using PlainDocument because that seemed to be what everyone was using for a syntax editor..since the structure of the document in a Plain Document is less complex.
    I orginally started out using the setCharacterAttributes() method on the DefaultStyledDocument and letting the views draw the text. That all seemed to work except for the "segment offset" issue. And I wasn't sure where the best spot to get the document to redraw subsequent lines in the case of changing a multiline comment, etc.
    So, everything I read about others attempts for syntax highlighters seems to use either StyledEditorKit with a fixed language set with custom parsing and using the setCharacterAttributes method. Or they use the plaindocument approach with a custom view..(which no one seems to share the source) or the project just simply uses the JEditTextArea directly (which we can't do in our product).
    We don't need multiple fonts per-line.. The document will always use one font face (Arial, Helvetica, etc) but may use different styles per word (bold, italic, etc).
    I thought I'd need to use FontMetrics to get the size of the font and such. But there didn't seem to be a difference in measurements based on the style of the font. (i.,e A bold font has the same charWidth('m') size as a regular style.
    At least that's what my test program showed..
    The other thing I noticed is that when the document is successfully colored and I use the mouse to select a region of text, the style of the text reverts back to normal. I'm sure that's because I only override the drawUnselectedText() method.
    Any ideas? Is there anyone who has successfully done this?
    Thanks,
    - Tim

    I just tried using a proportional font in my editor, and now I'm seeing your runaway-caret problem. Specifically, the caret remains in sync with the text as long as no bold characters are encountered, but it gets noticeably farther out of whack with each bold character it passes. I suspect that, when you measured the charWidth, your FontMetrics object wasn't really based on a bold font, because bold versions of proportional fonts are larger. And of course, the model/view conversion methods assume that the same style of the same font is used throughout the document. I've never had to deal with that problem, since I've always used monospaced fonts by preference, and bold versions of monospaced fonts really are the same size as the non-bold versions. I suggest you do the same, because getting this to work with proportional fonts look like a major hassle.

Maybe you are looking for

  • Scrolling credits are unreadable when played in full screen

    yet they look fine when I am typing in the info on the small screen. How can I fix this so the credit font quality is good when showing the movie in full screen? thanks, Charlene

  • How do i read from/write to FieldPoint modules in LabView 8.5?

    Is there a new way to read from/write to FieldPoint modules in LabView 8.5?  I made a .vi in LabView 8.0 using the FieldPoint icon under 'Measurement I/O' on the Functions Palette (to read from and write to different modules), but now, after transfer

  • ESS Family members/dependents iview

    Hello All, I am having an issue with the family members and dependents iview in ESS. Right now when I click on the iview it displays a line of buttons each saying new spouse, new child, new first emergency contact etc and when I click on any of these

  • Compiler cannot see my classes

    I know this doesn't belong here, but my problem is here: http://forum.java.sun.com/thread.jspa?threadID=664447&tstart=0 And I figure, if I can reinstall it, but with all of the default settings, it should work. So how do I go about that?

  • How do I return error code from a DLL?

    I have a C++ DLL that can throw an exception.  In the C function interface between LabView and the C++ class, I catch exceptions so they don't go up to LabView.  But I want to get the error to the calling VI.  Is there a way to get an error code into