Editor for syntax coloring code fragments?
May 12, 2010 4:43 PM Subscribe
Is there a text editor for Mac OS or WinXP that can syntax color (a.k.a. fontify or syntax highlight) C and C++ code fragments for my daily journal?
I write notes to myself about what I'm doing and drop in bits of code. Sometimes it's just a classname::methodname and sometimes it's 5 or 10 lines. The code lives on a Win XP machine and the notes on Mac OS, but the volume is shared to the Win machine. I edit code on Win XP and notes on both platforms, all w/ Gnu emacs.
When I paste code from a buffer in C++ editing mode to one in Fundamental mode it retains its syntax coloring, but only for that editing session.
I want to keep this fast & fluid, so I don't want to paste code into some tool that turns it into HTML (for the text attributes) then paste that into an editor. Instead, I'd like to just do a special paste or paste then select the just-pasted-text and tell the editor it's code.
I write notes to myself about what I'm doing and drop in bits of code. Sometimes it's just a classname::methodname and sometimes it's 5 or 10 lines. The code lives on a Win XP machine and the notes on Mac OS, but the volume is shared to the Win machine. I edit code on Win XP and notes on both platforms, all w/ Gnu emacs.
When I paste code from a buffer in C++ editing mode to one in Fundamental mode it retains its syntax coloring, but only for that editing session.
I want to keep this fast & fluid, so I don't want to paste code into some tool that turns it into HTML (for the text attributes) then paste that into an editor. Instead, I'd like to just do a special paste or paste then select the just-pasted-text and tell the editor it's code.
Or you could just run emacs within Terminal on OS X.
posted by Blazecock Pileon at 4:46 PM on May 12, 2010
posted by Blazecock Pileon at 4:46 PM on May 12, 2010
There are a few options for doing multiple modes in one file in emacs.
Also why not name your file .c or manually turn on c mode if it contains c code and no other programming syntax?
posted by idiopath at 4:46 PM on May 12, 2010
Also why not name your file .c or manually turn on c mode if it contains c code and no other programming syntax?
posted by idiopath at 4:46 PM on May 12, 2010
KomodoEdit has support for multi language files. This is primarily for tempting type situations, but I bet it could be bent to your purpose.
posted by jimfl at 5:54 PM on May 12, 2010
posted by jimfl at 5:54 PM on May 12, 2010
Response by poster: Also why not name your file .c or manually turn on c mode if it contains c code and no other programming syntax?
There's text in the journal that's not code, just my notes about what I've tested, results and what I think is going on. There are other things like a call stack copied from a debugger.
The bits of C are not necessarily well structured. This works in an emacs session because the syntax coloring is done with the code in its original context & the color attributes "stick" to the text when it's pasted into another buffer but are lost if the buffer is saved to a file, closed and re-opened.
There's nothing in my text to set off the C the way there's HTML around JavaScript in the emacs multi-mode tricks I've seen so far. I could put a little mark-up around the code sections.
TextMate is huge and might do what I want, but a cursory glance (which means very cursory relative to the depth of the editor) at language grammars and scope selectors tells me it won't.
I think I may have to use a heavy-ish weight wysiwyg editor (like Microsoft Word) to open my journal and the source I want to quote so when I copy the source I can paste it with the colors intact and saveable.
posted by morganw at 6:16 PM on May 12, 2010
There's text in the journal that's not code, just my notes about what I've tested, results and what I think is going on. There are other things like a call stack copied from a debugger.
The bits of C are not necessarily well structured. This works in an emacs session because the syntax coloring is done with the code in its original context & the color attributes "stick" to the text when it's pasted into another buffer but are lost if the buffer is saved to a file, closed and re-opened.
There's nothing in my text to set off the C the way there's HTML around JavaScript in the emacs multi-mode tricks I've seen so far. I could put a little mark-up around the code sections.
TextMate is huge and might do what I want, but a cursory glance (which means very cursory relative to the depth of the editor) at language grammars and scope selectors tells me it won't.
I think I may have to use a heavy-ish weight wysiwyg editor (like Microsoft Word) to open my journal and the source I want to quote so when I copy the source I can paste it with the colors intact and saveable.
posted by morganw at 6:16 PM on May 12, 2010
Best answer: What about /* */ comment blocks around all the non code text? Though I guess that may seem odd if the file is mostly not code.
I have a notes.lisp, notes.c, notes.ml and a notes.sc file for my various ideas and experiments and snippets I would want to refer back to, and they are all more comment than code.
posted by idiopath at 6:37 PM on May 12, 2010
I have a notes.lisp, notes.c, notes.ml and a notes.sc file for my various ideas and experiments and snippets I would want to refer back to, and they are all more comment than code.
posted by idiopath at 6:37 PM on May 12, 2010
Best answer: For what it's worth, the VisualStudio code editor produces colored rich text when you copy text, so you can write your fragments in VS and when you paste it into a non-brain dead text editor, it should carry the syntax coloring along.
posted by plinth at 4:46 AM on May 13, 2010
posted by plinth at 4:46 AM on May 13, 2010
Response by poster: What about /* */ comment blocks around all the non code text?
Doh! This is so simple & would kind of work. The file is mostly non-code, so I can wrap my code with */ {some code} /* and just make sure I have /* at the beginning and */ at the end of the file.
The snippets aren't really syntactically correct, so it might get a little messy, but it might not be too hard to add a fake function definition around them.
the VisualStudio code editor produces colored rich text when you copy text
I wish emacs did this. I'll have to try it w/ VS.
org-mode has you covered.
Awesome! You held out on me, though. In another answer about org-mode, you mentioned the screencast. I'm going to watch that, get back to work, then take a break & try these ideas.
Thanks everyone!
posted by morganw at 10:50 AM on May 13, 2010
Doh! This is so simple & would kind of work. The file is mostly non-code, so I can wrap my code with */ {some code} /* and just make sure I have /* at the beginning and */ at the end of the file.
The snippets aren't really syntactically correct, so it might get a little messy, but it might not be too hard to add a fake function definition around them.
the VisualStudio code editor produces colored rich text when you copy text
I wish emacs did this. I'll have to try it w/ VS.
org-mode has you covered.
Awesome! You held out on me, though. In another answer about org-mode, you mentioned the screencast. I'm going to watch that, get back to work, then take a break & try these ideas.
Thanks everyone!
posted by morganw at 10:50 AM on May 13, 2010
This thread is closed to new comments.
posted by Blazecock Pileon at 4:45 PM on May 12, 2010