unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to edit "mixed" (e.g. HTML/JavaScript) files?
@ 2007-03-06 19:45 kj
  2007-03-06 21:07 ` Lennart Borgman (gmail)
       [not found] ` <mailman.552.1173217248.7795.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 13+ messages in thread
From: kj @ 2007-03-06 19:45 UTC (permalink / raw)
  To: help-gnu-emacs



It often happens that a single file must contain code corresponding
to two different syntaxes.  For example, an HTML file with embedded
JavaScript or CSS.

Is there a way to *locally* override the mode of a file and replace
it with a different mode?

If not, is there a good way to deal with such situations (other
than avoiding them altogether)?

Thanks!

kj

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-06 19:45 How to edit "mixed" (e.g. HTML/JavaScript) files? kj
@ 2007-03-06 21:07 ` Lennart Borgman (gmail)
       [not found] ` <mailman.552.1173217248.7795.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 13+ messages in thread
From: Lennart Borgman (gmail) @ 2007-03-06 21:07 UTC (permalink / raw)
  Cc: help-gnu-emacs

kj wrote:
> It often happens that a single file must contain code corresponding
> to two different syntaxes.  For example, an HTML file with embedded
> JavaScript or CSS.
> 
> Is there a way to *locally* override the mode of a file and replace
> it with a different mode?
> 
> If not, is there a good way to deal with such situations (other
> than avoiding them altogether)?
> 
> Thanks!
> 
> kj

It depends on whom you ask ;-)

You may try nxhtml-part-mode in nXhtml (you need Emacs 22 beta):

   http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html

Or you may try this

   http://www.emacswiki.org/cgi-bin/wiki/MultipleModes

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
       [not found] ` <mailman.552.1173217248.7795.help-gnu-emacs@gnu.org>
@ 2007-03-07 18:06   ` kj
  2007-03-08  9:48   ` Hadron
  1 sibling, 0 replies; 13+ messages in thread
From: kj @ 2007-03-07 18:06 UTC (permalink / raw)
  To: help-gnu-emacs

In <mailman.552.1173217248.7795.help-gnu-emacs@gnu.org> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:

>kj wrote:

>It depends on whom you ask ;-)

>You may try nxhtml-part-mode in nXhtml (you need Emacs 22 beta):

>   http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html

>Or you may try this

>   http://www.emacswiki.org/cgi-bin/wiki/MultipleModes

Thanks!

kj

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
       [not found] ` <mailman.552.1173217248.7795.help-gnu-emacs@gnu.org>
  2007-03-07 18:06   ` kj
@ 2007-03-08  9:48   ` Hadron
  2007-03-08 11:02     ` Hadron
  2007-03-08 11:49     ` David Hansen
  1 sibling, 2 replies; 13+ messages in thread
From: Hadron @ 2007-03-08  9:48 UTC (permalink / raw)
  To: help-gnu-emacs

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:

> kj wrote:
>> It often happens that a single file must contain code corresponding
>> to two different syntaxes.  For example, an HTML file with embedded
>> JavaScript or CSS.
>>
>> Is there a way to *locally* override the mode of a file and replace
>> it with a different mode?
>>
>> If not, is there a good way to deal with such situations (other
>> than avoiding them altogether)?
>>
>> Thanks!
>>
>> kj
>
> It depends on whom you ask ;-)
>
> You may try nxhtml-part-mode in nXhtml (you need Emacs 22 beta):
>
>   http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html
>
> Or you may try this
>
>   http://www.emacswiki.org/cgi-bin/wiki/MultipleModes
>
>

Has anyone recently got this multiplemodes working? The wiki reads like
a slaughter house!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-08  9:48   ` Hadron
@ 2007-03-08 11:02     ` Hadron
  2007-03-08 11:49     ` David Hansen
  1 sibling, 0 replies; 13+ messages in thread
From: Hadron @ 2007-03-08 11:02 UTC (permalink / raw)
  To: help-gnu-emacs

Hadron <hadronquark@gmail.com> writes:

> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>
>> kj wrote:
>>> It often happens that a single file must contain code corresponding
>>> to two different syntaxes.  For example, an HTML file with embedded
>>> JavaScript or CSS.
>>>
>>> Is there a way to *locally* override the mode of a file and replace
>>> it with a different mode?
>>>
>>> If not, is there a good way to deal with such situations (other
>>> than avoiding them altogether)?
>>>
>>> Thanks!
>>>
>>> kj
>>
>> It depends on whom you ask ;-)
>>
>> You may try nxhtml-part-mode in nXhtml (you need Emacs 22 beta):
>>
>>   http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html
>>
>> Or you may try this
>>
>>   http://www.emacswiki.org/cgi-bin/wiki/MultipleModes
>>
>>
>
> Has anyone recently got this multiplemodes working? The wiki reads like
> a slaughter house!

ok, I bit the bullet.

I followed the instructions here:

http://www.emacswiki.org/cgi-bin/wiki/HtmlModeDeluxe

having installed php-mode, downloaded stefans css-mode, mmm-mode and pqsml from synaptic in Ubuntu.

I created a "my-mmm.el" pasting in the code listed there to configure
the html editing.

It all worked well "enough".

The default hiliting is attrocious IMO and I had to change
mmm-default-submode-face to grey12.  The mode changes when I am in
embedded php.

Interestingly though css-mode is the major mode for css files, not mmm
mode. Any ideas why?




-- 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-08  9:48   ` Hadron
  2007-03-08 11:02     ` Hadron
@ 2007-03-08 11:49     ` David Hansen
  2007-03-08 13:27       ` Lennart Borgman (gmail)
       [not found]       ` <mailman.655.1173360456.7795.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 13+ messages in thread
From: David Hansen @ 2007-03-08 11:49 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 08 Mar 2007 10:48:27 +0100 Hadron wrote:

> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>
>> kj wrote:
>>> It often happens that a single file must contain code corresponding
>>> to two different syntaxes.  For example, an HTML file with embedded
>>> JavaScript or CSS.
>>>
>>> Is there a way to *locally* override the mode of a file and replace
>>> it with a different mode?
>>>
>>> If not, is there a good way to deal with such situations (other
>>> than avoiding them altogether)?
>>>
>>> Thanks!
>>>
>>> kj
>>
>> It depends on whom you ask ;-)
>>
>> You may try nxhtml-part-mode in nXhtml (you need Emacs 22 beta):
>>
>>   http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html
>>
>> Or you may try this
>>
>>   http://www.emacswiki.org/cgi-bin/wiki/MultipleModes
>>
>>
>
> Has anyone recently got this multiplemodes working? The wiki reads like
> a slaughter house!

Just my experience:  you won't get it to work.  Everything available
are more or less dirty hacks.

The most promising approach (IMHO) is multi-mode.el (but it's a more
general solution, you have to do some hacking yourself to get it
work for your special mode).

Don't spend to much time fiddling with the different modes.  Emacs
isn't ready yet to deal with this.

David

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-08 11:49     ` David Hansen
@ 2007-03-08 13:27       ` Lennart Borgman (gmail)
  2007-03-08 14:11         ` David Hansen
       [not found]       ` <mailman.655.1173360456.7795.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 13+ messages in thread
From: Lennart Borgman (gmail) @ 2007-03-08 13:27 UTC (permalink / raw)
  To: help-gnu-emacs

David Hansen wrote:
> On Thu, 08 Mar 2007 10:48:27 +0100 Hadron wrote:
> 
>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>
>>> kj wrote:
>>>> It often happens that a single file must contain code corresponding
>>>> to two different syntaxes.  For example, an HTML file with embedded
>>>> JavaScript or CSS.
>>>>
>>>> Is there a way to *locally* override the mode of a file and replace
>>>> it with a different mode?
>>>>
>>>> If not, is there a good way to deal with such situations (other
>>>> than avoiding them altogether)?
>>>>
>>>> Thanks!
>>>>
>>>> kj
>>> It depends on whom you ask ;-)
>>>
>>> You may try nxhtml-part-mode in nXhtml (you need Emacs 22 beta):
>>>
>>>   http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html
>>>
>>> Or you may try this
>>>
>>>   http://www.emacswiki.org/cgi-bin/wiki/MultipleModes
>>>
>>>
>> Has anyone recently got this multiplemodes working? The wiki reads like
>> a slaughter house!
> 
> Just my experience:  you won't get it to work.  Everything available
> are more or less dirty hacks.
> 
> The most promising approach (IMHO) is multi-mode.el (but it's a more
> general solution, you have to do some hacking yourself to get it
> work for your special mode).
> 
> Don't spend to much time fiddling with the different modes.  Emacs
> isn't ready yet to deal with this.
> 
> David


Did you try nXhtml above? It should work OTB. Drawbacks is that it 
requires the Emacs 22 beta. Maybe also in the beginning that it uses 
nxhtml-mode for XHTML.

nXhtml takes another approach to multiple modes. Since Emacs actually 
have no way to restrict a mode to only handle part of a buffer (not even 
in Emacs 22) it instead switches mode. See the home page for more info.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
       [not found]       ` <mailman.655.1173360456.7795.help-gnu-emacs@gnu.org>
@ 2007-03-08 13:51         ` Hadron
  0 siblings, 0 replies; 13+ messages in thread
From: Hadron @ 2007-03-08 13:51 UTC (permalink / raw)
  To: help-gnu-emacs

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:

> David Hansen wrote:
>> On Thu, 08 Mar 2007 10:48:27 +0100 Hadron wrote:
>>
>>> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>>>
>>>> kj wrote:
>>>>> It often happens that a single file must contain code corresponding
>>>>> to two different syntaxes.  For example, an HTML file with embedded
>>>>> JavaScript or CSS.
>>>>>
>>>>> Is there a way to *locally* override the mode of a file and replace
>>>>> it with a different mode?
>>>>>
>>>>> If not, is there a good way to deal with such situations (other
>>>>> than avoiding them altogether)?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> kj
>>>> It depends on whom you ask ;-)
>>>>
>>>> You may try nxhtml-part-mode in nXhtml (you need Emacs 22 beta):
>>>>
>>>>   http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html
>>>>
>>>> Or you may try this
>>>>
>>>>   http://www.emacswiki.org/cgi-bin/wiki/MultipleModes
>>>>
>>>>
>>> Has anyone recently got this multiplemodes working? The wiki reads like
>>> a slaughter house!
>>
>> Just my experience:  you won't get it to work.  Everything available
>> are more or less dirty hacks.
>>
>> The most promising approach (IMHO) is multi-mode.el (but it's a more
>> general solution, you have to do some hacking yourself to get it
>> work for your special mode).
>>
>> Don't spend to much time fiddling with the different modes.  Emacs
>> isn't ready yet to deal with this.
>>
>> David
>
>
> Did you try nXhtml above? It should work OTB. Drawbacks is that it
> requires the Emacs 22 beta. Maybe also in the beginning that it uses
> nxhtml-mode for XHTML.
>
> nXhtml takes another approach to multiple modes. Since Emacs actually
> have no way to restrict a mode to only handle part of a buffer (not
> even in Emacs 22) it instead switches mode. See the home page for more
> info.

I would strongly advise anyone trying emacs CVS if they use
debian/ubuntu - you have to really know what you are doing to get it
installed. Despite advice from ##emacs on irc, I never got it working -
the cvs version clashes with the debian install packages.

Having said that I use emacs-snapshot from synaptic and I got
htmlmodedelux working. The jury is out on whether its better than c-mode
for php and html-helper-mode, but it works.

http://www.emacswiki.org/cgi-bin/wiki/HtmlModeDeluxe

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-08 13:27       ` Lennart Borgman (gmail)
@ 2007-03-08 14:11         ` David Hansen
  2007-03-08 16:06           ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 13+ messages in thread
From: David Hansen @ 2007-03-08 14:11 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 08 Mar 2007 14:27:12 +0100 Lennart Borgman wrote:

> Did you try nXhtml above? It should work OTB. Drawbacks is that it
> requires the Emacs 22 beta. Maybe also in the beginning that it uses
> nxhtml-mode for XHTML.
>
> nXhtml takes another approach to multiple modes. Since Emacs
> actually have no way to restrict a mode to only handle part of a
> buffer (not even in Emacs 22) it instead switches mode. See the home
> page for more info.

My experiences all come from editing .jsp files.  I doubt this
approach will work here.  Java mode will be totally confused by the
html parts.

Also note that switching the mode may be OK for small files but
complete fortification of a >1k lines file takes some time that
is not acceptable during editing (but i have to admit that i haven't
tried nxhtml yet).

The multi-mode.el approach is to have multiple indirect buffers with
different major modes and it narrows to the region with `point'.
You don't have to run the major-mode command all the time and the
current major mode won't get confused by the rest of the buffer but
indentation can only work within one region.

There are a some more minor glitches (especially font-locking) but i
think it's at least a promising approach.

I hope this topic will get some more attention after the upcoming
(?) release of Emacs 22.

David

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-08 14:11         ` David Hansen
@ 2007-03-08 16:06           ` Lennart Borgman (gmail)
  2007-03-08 16:43             ` David Hansen
  0 siblings, 1 reply; 13+ messages in thread
From: Lennart Borgman (gmail) @ 2007-03-08 16:06 UTC (permalink / raw)
  To: help-gnu-emacs

David Hansen wrote:
> On Thu, 08 Mar 2007 14:27:12 +0100 Lennart Borgman wrote:
> 
>> Did you try nXhtml above? It should work OTB. Drawbacks is that it
>> requires the Emacs 22 beta. Maybe also in the beginning that it uses
>> nxhtml-mode for XHTML.
>>
>> nXhtml takes another approach to multiple modes. Since Emacs
>> actually have no way to restrict a mode to only handle part of a
>> buffer (not even in Emacs 22) it instead switches mode. See the home
>> page for more info.
> 
> My experiences all come from editing .jsp files.  I doubt this
> approach will work here.  Java mode will be totally confused by the
> html parts.

Yes, I guess that is right. I therefore have two different approaches. 
The other approach narrows the buffer and shows just the narrowed part. 
This is used for embedded css and javascript, but could be used for 
other things as well.

I have thought about instead of narrowing adding overlays to the part 
that belongs to the other mode, but I have not got down to actually 
implement it yet. Doing that could make it look like a mixing of major 
modes.


> Also note that switching the mode may be OK for small files but
> complete fortification of a >1k lines file takes some time that
> is not acceptable during editing (but i have to admit that i haven't
> tried nxhtml yet).
> 
> The multi-mode.el approach is to have multiple indirect buffers with
> different major modes and it narrows to the region with `point'.
> You don't have to run the major-mode command all the time and the
> current major mode won't get confused by the rest of the buffer but
> indentation can only work within one region.
> 
> There are a some more minor glitches (especially font-locking) but i
> think it's at least a promising approach.

I guess you mean that it is bad to switch major mode because of that it 
takes long time, or are there other reasons?

If it is the time to change that is important, what do you believe is 
that takes too much time?

When it comes to fontification the approach with indirect buffers can 
not work, unfortunately, since text properties (which are used for 
fontification) are shared between the buffers. This together with that a 
major mode wants to fontify the whole buffer makes it impossible as far 
as I can see. (There is nothing in Emacs 22 beta that can remedy this 
either.)


> I hope this topic will get some more attention after the upcoming
> (?) release of Emacs 22.

Yes, that would be good. But I think we need some experiences then about 
what can work.

As far as I can see switching major mode might not be that bad if it 
could be applied to a part of a buffer.

Maybe I should say that I just found some glitches in the handling of 
mode switching between nXhtml mode and PHP mode so I have to find out 
what that could be. So if someone wants to test then please wait a 
little while.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-08 16:06           ` Lennart Borgman (gmail)
@ 2007-03-08 16:43             ` David Hansen
  2007-03-08 17:15               ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 13+ messages in thread
From: David Hansen @ 2007-03-08 16:43 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 08 Mar 2007 17:06:53 +0100 Lennart Borgman wrote:
> I guess you mean that it is bad to switch major mode because of that
> it takes long time, or are there other reasons?
>
> If it is the time to change that is important, what do you believe
> is that takes too much time?

I guess mainly the first font-lock run.

> When it comes to fontification the approach with indirect buffers
> can not work, unfortunately, since text properties (which are used
> for fontification) are shared between the buffers.

multi-mode works (or at least tries to works) the way that
fontification happens region by region only in the relevant buffer.
In theory this should work (long time ago that i had a look at the
sources).

> This together with that a major mode wants to fontify the whole
> buffer

There's `font-lock-dont-widen' (I think one of the glitches of
multi-mode is that it doesn't set this and syntactic fontification
in one mode may screws it in the other mode).

> makes it impossible as far as I can see. (There is nothing
> in Emacs 22 beta that can remedy this either.)

Have a look at the multi-mode sources.  It's a relatively small,
clean coded and good commented package (no not by me ;).

For my taste this is a minor problem anyway as long as the text
around the part of code I'm currently editing looks OK (and if not
there's M-o M-o).

What terrible sucks is indentation if some construct spreads over
more than one region.  But at least it works reliable within one
region.  MMM mode can't even that.

I assume NXML mode won't be that happy too if you narrow it to one
region (or does it widen for it's syntax analysis?  Would probably
be even worse).

>> I hope this topic will get some more attention after the upcoming
>> (?) release of Emacs 22.
>
> Yes, that would be good. But I think we need some experiences then
> about what can work.


> As far as I can see switching major mode might not be that bad if it
> could be applied to a part of a buffer.

This always implies unnecessary refontification which IMHO is *very*
bad.

David

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-08 16:43             ` David Hansen
@ 2007-03-08 17:15               ` Lennart Borgman (gmail)
  2007-03-08 18:14                 ` David Hansen
  0 siblings, 1 reply; 13+ messages in thread
From: Lennart Borgman (gmail) @ 2007-03-08 17:15 UTC (permalink / raw)
  To: help-gnu-emacs

David Hansen wrote:
> On Thu, 08 Mar 2007 17:06:53 +0100 Lennart Borgman wrote:
>> This together with that a major mode wants to fontify the whole
>> buffer
> 
> There's `font-lock-dont-widen' (I think one of the glitches of
> multi-mode is that it doesn't set this and syntactic fontification
> in one mode may screws it in the other mode).

Ah, I see. Then perhaps this is the reason that no one has gotten it to 
work for nxml-mode and its derivates (like nxhtml-mode). Those modes 
must look at the whole buffer to be able to check against the DTD.

Maybe this can be fixed by using an extra indirect buffer for the DTD 
checking ...

> Have a look at the multi-mode sources.  It's a relatively small,
> clean coded and good commented package (no not by me ;).

I will.

> I assume NXML mode won't be that happy too if you narrow it to one
> region (or does it widen for it's syntax analysis?  Would probably
> be even worse).

Yes, see above.

>> As far as I can see switching major mode might not be that bad if it
>> could be applied to a part of a buffer.
> 
> This always implies unnecessary refontification which IMHO is *very*
> bad.

I can see your point. But I meant that if a mode where restricted to 
just a part of a buffer it would not be that bad. But there are no 
structures within Emacs to support that - or multi-mode might be a way 
to do it.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: How to edit "mixed" (e.g. HTML/JavaScript) files?
  2007-03-08 17:15               ` Lennart Borgman (gmail)
@ 2007-03-08 18:14                 ` David Hansen
  0 siblings, 0 replies; 13+ messages in thread
From: David Hansen @ 2007-03-08 18:14 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 08 Mar 2007 18:15:11 +0100 Lennart Borgman wrote:

> David Hansen wrote:
>> This always implies unnecessary refontification which IMHO is *very*
>> bad.
>
> I can see your point. But I meant that if a mode where restricted to
> just a part of a buffer it would not be that bad. But there are no
> structures within Emacs to support that - or multi-mode might be a
> way to do it.

I know it's considered to be bad style but i have edited .jsp's with
hundreds of lines of java code on top of it.  Switching the mode for
these regions just isn't acceptable for me.

David

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2007-03-08 18:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-06 19:45 How to edit "mixed" (e.g. HTML/JavaScript) files? kj
2007-03-06 21:07 ` Lennart Borgman (gmail)
     [not found] ` <mailman.552.1173217248.7795.help-gnu-emacs@gnu.org>
2007-03-07 18:06   ` kj
2007-03-08  9:48   ` Hadron
2007-03-08 11:02     ` Hadron
2007-03-08 11:49     ` David Hansen
2007-03-08 13:27       ` Lennart Borgman (gmail)
2007-03-08 14:11         ` David Hansen
2007-03-08 16:06           ` Lennart Borgman (gmail)
2007-03-08 16:43             ` David Hansen
2007-03-08 17:15               ` Lennart Borgman (gmail)
2007-03-08 18:14                 ` David Hansen
     [not found]       ` <mailman.655.1173360456.7795.help-gnu-emacs@gnu.org>
2007-03-08 13:51         ` Hadron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).