Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm writing a Python CGI script, let's say e.g.

print "Content-Type: text/html"
print                          
print "<html><head><title>Cool Page</title></head><body><h1>Hello World</h1>
output_awesome_information()
print "</body></html>"

I'm writing it in an editor with Python syntax highlighting. But since a lot of this script is actually written in HTML, I want both HTML and Python syntax highlighting, where HTML syntax highlighting is activated only in all strings.

Is there an editor that supports this?

share|improve this question
I actually would like to add a "CGI"-tag, but it doesn't exist and I don't have enough reputation to create it. Can someone create it? – Turion Jul 27 '11 at 10:32
cgi is not a good tag for this. – user1249 Jul 27 '11 at 10:42
cgi-script-editing???? – Turion Jul 27 '11 at 10:54
I would also be interested in comments whether other people experienced this sort of problem already. – Turion Jul 27 '11 at 10:58
1  
I suspect that this is one of the reasons plain CGI scripts have gotten out of style - they basically require you to mix languages. Sure you can use a template engine, but then you're already halfway to a web framework anyway. – Michael Borgwardt Jul 27 '11 at 11:01
show 1 more comment

4 Answers

up vote 1 down vote accepted

You can do this with emacs using MuMaMo (Mulitple Major Modes) -- there's an overview here:

http://www.emacswiki.org/emacs/MuMaMo

Basically, this lets you work in different parts of the same file using different emacs modes (and thus getting different rules for syntax coloring, indentation, and more).

Importantly, this also includes presets which automatically set modes by part for a number of HTML-embedding systems, including django, eruby, php, and more.

share|improve this answer

This will not probably fully answer your question, but I sense a chance that, depending on your style of editing, it may prove useful.

A little trick: Use Geany and switching to PHP everytime you want to edit/review HTML code.

  • Geany with your snippet as Python here, and
  • Geany with your snippet as PHP there (well, it's not really PHP--no <?php ?>)

This could work also in some other editors, of course. :)

(Sorry, I can't post images directly...)

share|improve this answer
Then I could also change between HTML and Python, which is even nicer in Geany. – Turion Jul 27 '11 at 12:36

I use TextPad and you can download pre-configured sytanx files. You can also custom color your own syntax if you like.

share|improve this answer
That's the case for any decent editor. – Turion Jul 27 '11 at 13:09
But still, I will consider doing that for Geany. – Turion Aug 12 '11 at 12:03

What you are looking for is an editor smart enough to handle context dependent language switching, and those are rare. Emacs or vim might.

I would strongly recommend that you consider splitting this into separate single language entities which can be loaded directly by the PHP engine. Does it support caching includes? If yes, then that is what you should be looking for.

share|improve this answer
It's a Pythin CGI script, no PHP engine in sight. – Michael Borgwardt Jul 27 '11 at 10:49
Apparently I cannot read :( Question is then if the Python interpreter is persisted or invoked per request. – user1249 Jul 27 '11 at 10:55
Invoked per request. But loading the large HTML parts from files or a database would not be a problem since I have 1 request per minute at most. – Turion Jul 27 '11 at 11:04
Then split it so you have a single language per file. Makes things easier. – user1249 Jul 27 '11 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.