Gary Fixler wrote: > I like to work in Vim as often as Gedit, but haven't come across any > highlighting files for EMC's NGC code in the wiki, nor through Google > searches. There IS a way in Gedit, and we have that in the wiki, which is > cool: > > http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Highlighting_In_Gedit > It's mentioned in the Improvements here: > http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?EMC2_Development > > I've tried several times in the past to figure out Vim's syntax > highlighting, but it's been complicated enough to warrant giving up > immediately each time :) Tonight, however, something got into me, and I > pushed through pages and pages of documentation, and hours of testing my > from-scratch file as I went, comparing everything against the 'bible': > > http://linuxcnc.org/docs/html/gcode_main.html > > The syntax file I made (links/install how-to near the end of this email) is > understandably remedial, given the single night of R&D, but it already > properly¹ highlights a rather extensive set of the files I tested. I > endeavored to break up each highlighting type in sensible, pre-defined ways, > such that the power user with lots of the standard sub-types defined for > their Vim sessions could benefit from something passably² familiar. In fact, > there are no custom highlight types - all are linked to types that already > exist in Vim. > > Here's what I got to highlight before giving up: > * conditionals (if, else, endif) > * repeats (do, while, endwhile, break, continue) > * functions (sub, endsub, call, return) > * comments > * special comments (log stuff, print, msg, debug) > * identifiers (e.g. vars: #1, #<foo>, #<also_works>) > * operators (+, -, *, /, %, and all the EQ, and ACOS things) > * constants (ints, and floats) > * all g-codes³ > * all m-codes³ > * any o-code style number > * old-fashioned n# line numbers > * TODO, FIXME, XXX > * axes (x, y, z, a, b, c, u, v, w) > * feed rates > * "special" characters (i, j, k, e, d, l, p, r, s) > * tool selects, w/ h offset tool indices > > Cool extras: > * everything is case-insensitive, as w/ NGC/EMC2 (g1, and G1 are the same) > * line breaks in comments break their highlighting to indicate the error > * special comments allow whitespace around keyword (e.g. ( MSG , etc...) > * identifiers inside special comments have their own highlight type > * n# labels, and o-codes only match if first non whitespace block on line > * TODO stuff all works from within comments, of course (where else?) > * axes highlight only if preceded by whitespace, and followed by digit, or [ > * feed rates follow axes' rules, but can also be first characters on line > * special chars follow the rules of axes > > Caveats: > * "-" is a tough one, in that it means 'minus,' and also 'negative' > * it currently never highlights with the constant (always an operator) > * I've at various points had it working in various ways > * this has much to do with the order in which highlights are defined > * it would appear to have a non-trivial, multi-workaround solution > * any change to order, or method breaks other highlighting - sigh... > * I got a bit lazy by the time I got to special chars/tool select stuff > * there are likely some oddities in this stuff > * I rarely/never use any of that stuff; it was low-priority for me > * probably plenty more :) > > There could be all manner of fancy extras, like catching lots of other > errors, and flagging them as such, but it gets rather complicated rather > quickly. I wanted to post this ASAP in case it helps any Vim users, and in > case any pros in here wanted to enhance it with things like more robust > error-checking, tighter adherence to the spec, or new ways to break up the > concepts (e.g. highlighting an entire X[#<something>] block as a single type > (not my preference, but perhaps someone would prefer that), or properly > checking item locations in lines, or getting negative constants working, > without breaking all else. There are a lot of parts of the g-code spec that > I've never touched (e.g. I've never used an M-code), so I've probably missed > whole swaths of highlightables. > > So... interested in using it? Here's how: > 1) make yourself a ~/.vim/ directory > 2) make a syntax directory in there > 3) save ngc.vim into ~/.vim/syntax/ > http://www.garyfixler.com/emc/vim/syntax/ngc.vim > 4) save filetype.vim into ~/.vim/ (or merge with your existing one, if any): > http://www.garyfixler.com/emc/vim/filetype.vim > 5) open, or restart vim > 6) open any files with *.ngc extensions, and it should auto-highlight them > > You can also force highlighting with: > > :set syntax=ngc > > There are ways to have Vim check a few lines in the file to determine type, > but that's more involved, and an exercise for a later date. You can > duplicate the au! line in filetype.vim to add your own extension(s), or just > modify the one that's already there (*.ngc). > > I copied and pasted many gcode examples³, and even noticed an error > immediately, thanks to the syntax colors: > > http://linuxcnc.org/docs/html/gcode_main.html#r9_4_3 > > The second comment in the code in section 9.4.3: Jon Elson's Example is > missing its closing ")," and thus it didn't colorize :) > > Here's a slightly nonsensical example screencap with syntax off: > http://www.garyfixler.com/emc/vim/syntoff.png > And here it is with the syntax turned on: > http://www.garyfixler.com/emc/vim/synton.png > > I happen to have a lot of my subtypes as the same core type colors, so > there's actually more separation of highlight types than you're seeing, but > already I think it's a bit easier to visually parse. Just for fun, here's > the 3-monitor setup I was on while researching, and editing the syntax file > (left 2 panes show lots more highlighting): > > http://www.garyfixler.com/emc/vim/editing.png >
I don't use vim and can't test, but this sounds like a great effort. Thanks! > Anyway, feedback/corrections much appreciated, and if anyone gets it > working, or makes some nice modifications, I'd love to hear about it. I > don't think I have wiki powers, but if someone would like to add it, that > would also be nice. Thanks! > Everyone has wiki access, although you must log in to prevent automated wiki spam. The password and the process are described here: http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?BasicSteps Regards, John Kasunich ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Emc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/emc-users
