Syntax highlighting

C

Chupo

I stumbled upon an old (abandoned) site:

http://users.powernet.co.uk/eton/kandr2/

and would like to know what program/method was used for syntax
highlighting. I see there is now a new page:

http://clc-wiki.net/wiki/K&R2_solutions

where GeSHi C has been used to highlight the code but I am examining
the other methods as well. For example, I sometimes use ConTEXT to save
highlighted code in .html file so I can paste the highlighted code
where I need.

I've tried to reach Richard Heathfield to ask him a question but
could't find any valid mail address.

ps
I often use to paste the *highlighted* ) articles from my newsreader
(Microplanet Gravity) into the M$ Word, is there any way to paste
highlighted C code from somewhere into a Word document?
 
S

spinoza1111

I stumbled upon an old (abandoned) site:

http://users.powernet.co.uk/eton/kandr2/

and would like to know what program/method was used for syntax
highlighting. I see there is now a new page:

http://clc-wiki.net/wiki/K&R2_solutions

where GeSHi C has been used to highlight the code but I am examining
the other methods as well. For example, I sometimes use ConTEXT to save
highlighted code in .html file so I can paste the highlighted code
where I need.

I've tried to reach Richard Heathfield to ask him a question but
could't find any valid mail address.

ps
I often use to paste the *highlighted* ) articles from my newsreader
(Microplanet Gravity) into the M$ Word, is there any way to paste
highlighted C code from somewhere into a Word document?

Word will preserve the syntax highlighting created by Microsoft C++
Express, which is free. So: download Microsoft C++ Express, paste your
code in a source window, copy it and paste it into Word.

Wordpress has a code tag but its formatting doesn't transfer to Word.

My compiler for most of Quick Basic as described in "Build Your
Own .Net Language and Compiler" (Apress 2004) does syntax coloring and
its source is available with the book.

The method used in my compiler doesn't use "syntax" strictly speaking.
This is because what is ordinarily used to highlight things APART from
the dynamic bolding and dimming of balanced parentheses available in
many GUIs (including C++ Express) is just lexical analysis where you
want keywords in green, your identifiers in black, operators in red,
and so on.

A really nifty code formatter would show levels of nesting in shades
of grey. If I recall correctly, Knuth developed such a tool.
 
K

Keith Thompson

Chupo said:
I've tried to reach Richard Heathfield to ask him a question but
could't find any valid mail address.
[...]

See the signature he appends to every message:
 
N

Nisse Engström

C

Chupo

23g2000pre.googlegroups.com> said:
Word will preserve the syntax highlighting created by Microsoft C++

I wasn't aware of that, thank you very much. It would be nice to have a
programming editor with such a feature (highlighted paste) for many
languages. However, I am not aware of any (if it even exists).
 
K

Keith Thompson

Chupo said:
I wasn't aware of that, thank you very much. It would be nice to have a
programming editor with such a feature (highlighted paste) for many
languages. However, I am not aware of any (if it even exists).

I'm not sure how you could do that.

Programming editors that automatically highlight based on the
language syntax are quite common, of course. Highlighting based
on existing highlighting information in copy-and-pasted text would
be difficult. To retain any pasted highlighting information, the
editor would have to store that information in addition to the text;
to be a programming editor, it would have to save the file in a
format acceptable to a compiler.

I suppose it could store formatting information in an auxiliary file,
but keeping that in sync with the text would be difficult, and perhaps
even impossible if you ever use anything else to edit the text. I don't
see much benefit anyway.
 
S

Seebs

Programming editors that automatically highlight based on the
language syntax are quite common, of course. Highlighting based
on existing highlighting information in copy-and-pasted text would
be difficult.

Well, it's easy outside of a programming editor; cut and paste preserving
highlighting is commonplace now.
To retain any pasted highlighting information, the
editor would have to store that information in addition to the text;
to be a programming editor, it would have to save the file in a
format acceptable to a compiler.
Yes.

I suppose it could store formatting information in an auxiliary file,
but keeping that in sync with the text would be difficult, and perhaps
even impossible if you ever use anything else to edit the text. I don't
see much benefit anyway.

It does seem pointless to preserve highlighting while pasting into a source
file. On the other hand, preserving highlighting while copying into plain
text documents might be quite useful.

-s
 
C

Chupo

Chupo said:

BTW, am I missing something in this algorithm? Because here:

http://clc-wiki.net/wiki/K&R2_solutions:Chapter_1:Exercise_13

in the very first solution I don't see any reason to use the variable
'firstletter'? Maybe I am wrong but I think everything would work
perfectly well even after removing every occurrence of it :-/

In the other hand, although I don't see it, I believe there has to be a
reason for checking that variable :-/
 
K

Keith Thompson

Seebs said:
It does seem pointless to preserve highlighting while pasting into a source
file. On the other hand, preserving highlighting while copying into plain
text documents might be quite useful.

If it preserves highlighting, then I suggest it's not dealing with
"plain text".
 
G

Gene

I stumbled upon an old (abandoned) site:

http://users.powernet.co.uk/eton/kandr2/

and would like to know what program/method was used for syntax
highlighting. I see there is now a new page:

http://clc-wiki.net/wiki/K&R2_solutions

where GeSHi C has been used to highlight the code but I am examining
the other methods as well. For example, I sometimes use ConTEXT to save
highlighted code in .html file so I can paste the highlighted code
where I need.

I've tried to reach Richard Heathfield to ask him a question but
could't find any valid mail address.

I have used this with good success:

http://www.palfrader.org/code2html/code2html.html
 
P

Peter Nilsson

Chupo said:
... I see there is now a new page:

http://clc-wiki.net/wiki/K&R2_solutions

where GeSHi C has been used to highlight the code

I find the syntax colouring makes the code virtually
unreadable.
but I am examining the other methods as well. For example,
I sometimes use ConTEXT to save highlighted code in .html
file so I can paste the highlighted code where I need.

I'm old-school. I believe that code that notionally _requires_
sytnax highlighting only does so be because it is badly
structured and formatted to begin with. If it doesn't look
good in monotone, then adding colour is just an attempt at
dressing up old ham.

I don't limit that observation to C. Indeed it derives from
publication in general. Colouring is often used to 'jazz'
up text that is otherwise dull and not worth publishing. But
whilst it may make a document superficially look better, it
often reduces readability, and makes documents look awful,
particularly on grey scale printers.
 
B

bart.c

I don't limit that observation to C. Indeed it derives from
publication in general. Colouring is often used to 'jazz'
up text that is otherwise dull and not worth publishing. But
whilst it may make a document superficially look better, it
often reduces readability, and makes documents look awful,
particularly on grey scale printers.

On a black & white printer, bold, italics and fonts are a better idea.
(Although, I can't remember how many years since I actually printed out some
code. It might have been part of a technical manual where I did make use of
text styles)
 
I

Ian Collins

I'm old-school. I believe that code that notionally _requires_
sytnax highlighting only does so be because it is badly
structured and formatted to begin with. If it doesn't look
good in monotone, then adding colour is just an attempt at
dressing up old ham.

I don't think I've ever encountered code that _requires_ syntax
highlighting (OK, excluding XML if you consider it code!). Syntax
highlighting is simply a visual aid. Code doesn't require whites pace
either, but we still use it.
 
S

spinoza1111

I don't think I've ever encountered code that _requires_ syntax
highlighting (OK, excluding XML if you consider it code!).  Syntax
highlighting is simply a visual aid.  Code doesn't require whites pace
either, but we still use it.

intintIndex1=0;for(;intIndex1<=intLimit;intIndex1++)bnarg();

Interestingly, the only point in the above where the white space is
indeed "required" is between in the first and second int.
 
N

Nick Keighley

and would like to know what program/method was used for syntax
highlighting.

so as to avoid it?
I see there is now a new page:

http://clc-wiki.net/wiki/K&R2_solutions

where GeSHi C has been used to highlight the code but I am examining
the other methods as well. For example, I sometimes use ConTEXT to save
highlighted code in .html file so I can paste the highlighted code
where I need.

ConTEXT as in the Windows based text editor? I use that, how do you
get it to save the formatting in html? If I save it as html I lose all
the formatting. Have I misunderstood what you're saying?
 
N

Nick Keighley

I find the syntax colouring makes the code virtually
unreadable.

with you there
I'm old-school. I believe that code that notionally _requires_
sytnax highlighting only does so be because it is badly
structured and formatted to begin with. If it doesn't look
good in monotone, then adding colour is just an attempt at
dressing up old ham.

the first time I encountered a syntax hilighting editor I thought I
was going to be ill. But if you are more subtle about things, it looks
ok. And it helps spot over-running comments, unterminated strings and
mispelled language words. I also choose "nasty" colours for literal
constants.

(Ah, old memory floated to the surface- the *first* time I encountered
syntax highlighting was on a monochrome monitor so that actually
looked ok. The previous paragraph is talking about the first time I
saw it on a PC)

Some **** has set up vi to syntax hilight in neon on one of the linux
systems I use. Good grief.
I don't limit that observation to C. Indeed it derives from
publication in general. Colouring is often used to 'jazz'
up text that is otherwise dull and not worth publishing. But
whilst it may make a document superficially look better, it
often reduces readability, and makes documents look awful,
particularly on grey scale printers.

my hilighted code looks ok in grey (but then it doesn't use colour
much)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top