Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sh mode for region only ?

42 views
Skip to first unread message

Alexandre Oberlin

unread,
May 9, 2012, 9:25:54 AM5/9/12
to
Hi all,

Is there a possibility to benefit of sh (or whatever) syntax
highlighting on a region only?

This could be useful when editing a list of instructions containing codes.

Alexandre


XeCycle

unread,
May 9, 2012, 9:40:16 AM5/9/12
to help-gn...@gnu.org
C-x n n

Or a more complex C-x 4 c.

--
Carl Lei (XeCycle)
Department of Physics, Shanghai Jiao Tong University
OpenPGP public key: 7795E591
Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

Richard Riley

unread,
May 9, 2012, 10:04:29 AM5/9/12
to help-gn...@gnu.org
XeCycle <XeC...@Gmail.com> writes:
> C-x n n
>
> Or a more complex C-x 4 c.

How does that address the question? Is there some way to then have it
auto mode to the correct syntax hiliting in the narrowed region?


Doug Lewan

unread,
May 9, 2012, 10:19:35 AM5/9/12
to help-gn...@gnu.org
At my last job I had to work with HTML that was heavily laden with JavaScript, so something similar was very useful for me.
I wrote a post-command-hook to see if the point had moved into a region of JavaScript and, if it had, then change to JavaScript mode.

If your regions of shell code have reasonably consistent delimiters, then doing the same thing should not be too difficult.

,Doug

Richard Riley

unread,
May 9, 2012, 10:19:21 AM5/9/12
to help-gn...@gnu.org

Doug Lewan <do...@shubertticketing.com> writes:

> At my last job I had to work with HTML that was heavily laden with JavaScript, so something similar was very useful for me.
> I wrote a post-command-hook to see if the point had moved into a region of JavaScript and, if it had, then change to JavaScript mode.
>
> If your regions of shell code have reasonably consistent delimiters, then doing the same thing should not be too difficult.
>
> ,Doug

nxhtml might be good for you too.

>
>> -----Original Message-----
>> From: help-gnu-emacs-bounces+dougl=shuberttic...@gnu.org
>> [mailto:help-gnu-emacs-bounces+dougl=shuberttic...@gnu.org] On
>> Behalf Of Alexandre Oberlin
>> Sent: Wednesday, 2012 May 09 09:26
>> To: help-gn...@gnu.org
>> Subject: sh mode for region only ?
>>

XeCycle

unread,
May 9, 2012, 10:32:38 AM5/9/12
to help-gn...@gnu.org
Richard Riley <ril...@gmail.com> writes:

> XeCycle <XeC...@Gmail.com> writes:
>
>> Alexandre Oberlin <ple...@nospam.com> writes:
>>
>> C-x n n
>>
>> Or a more complex C-x 4 c.
>
> How does that address the question? Is there some way to then have it
> auto mode to the correct syntax hiliting in the narrowed region?

Of course you can do something to narrow functions, but running
them manually is not very hard.

Doug Lewan

unread,
May 9, 2012, 10:56:49 AM5/9/12
to help-gn...@gnu.org
Well, dang!

Gotta love emacs. If you need something, someone else has almost certainly thought of it and probably already built it.

,Doug

Alexandre Oberlin

unread,
May 9, 2012, 10:55:55 AM5/9/12
to
Thanks for your suggestion.

I tried to check if one of those solutions would work at least while
editing but none does. Actually in the narrowed region or cloned buffer
the syntax highlighting seems to take into account the unseen text to
set the highlighting. I need to copy the sh region to a new file to get
the correct syntax highlighting.

Alexandre

Alexandre Oberlin

unread,
May 9, 2012, 11:05:30 AM5/9/12
to
Thanks Doug for your answer.

Actually changing the mode of the buffer (be it narrowed, cloned or not)
does not consistently help, because even if it is not seen, the non code
text impacts on the code highlighting.

Even with standalone code blocks or delimiters, I can't see how to get
this to work without commenting out the non code sections.

Alexandre

Alexandre Oberlin

unread,
May 9, 2012, 11:19:59 AM5/9/12
to
On 05/09/2012 04:19 PM, Richard Riley wrote:
> nxhtml might be good for you too.

The concept should be generalized...

Alexandre

Alexandre Oberlin

unread,
May 9, 2012, 11:40:09 AM5/9/12
to
I noticed another problem when switching even temporarily to sh mode:
the Enriched mode formatting goes away and does not come back.

Alexandre

Andreas Röhler

unread,
May 9, 2012, 12:11:16 PM5/9/12
to help-gn...@gnu.org
[ ... ]

maybe try this:

https://github.com/purcell/mmm-mode


Pascal J. Bourguignon

unread,
May 9, 2012, 12:37:59 PM5/9/12
to
There are mmm-mode and mumamo-mode (plus perhaps a few others)

http://emacswiki.org/emacs/MultipleModes

--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Barry Margolin

unread,
May 9, 2012, 12:42:14 PM5/9/12
to
In article <eWvqr.501$9Q6...@newsfe18.iad>,
There's something called mmm-mode, for multiple major modes. I use it
with PHP embedded in HTML.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Alexandre Oberlin

unread,
May 9, 2012, 5:01:33 PM5/9/12
to
With 3 advises I must try it.
Sounds great.

Thanks a lot,

Alexandre

XeCycle

unread,
May 9, 2012, 11:44:06 PM5/9/12
to help-gn...@gnu.org
Alexandre Oberlin <ple...@nospam.com> writes:

> Thanks for your suggestion.
>
> I tried to check if one of those solutions would work at least
> while editing but none does. Actually in the narrowed region or
> cloned buffer the syntax highlighting seems to take into account
> the unseen text to set the highlighting. I need to copy the sh
> region to a new file to get the correct syntax highlighting.

Apart from multiple modes, you can try working with Org mode,
which gives a nice way of embedding source code in documents.

rusi

unread,
May 12, 2012, 11:26:14 PM5/12/12
to
On May 10, 8:44 am, XeCycle <XeCy...@Gmail.com> wrote:
> Alexandre Oberlin <ple...@nospam.com> writes:
> > Thanks for your suggestion.
>
> > I tried to check if one of those solutions would work at least
> > while editing but none does. Actually in the narrowed region or
> > cloned buffer the syntax highlighting seems to take into account
> > the unseen text to set the highlighting. I need to copy the sh
> > region to a new file to get the correct syntax highlighting.
>
> Apart from multiple modes, you can try working with Org mode,
> which gives a nice way of embedding source code in documents.

Yes orgmode, specifically babel, is probably the most stable and
sophisticated solution
http://orgmode.org/worg/org-contrib/babel/intro.html

More lightweight is eepitch http://angg.twu.net/eev-current/eepitch.el.html
If you dont mind hackish and not heavily documented

rusi

unread,
May 13, 2012, 1:19:19 AM5/13/12
to
On May 13, 8:26 am, rusi <rustompm...@gmail.com> wrote:
<snipped>
> More lightweight is eepitchhttp://angg.twu.net/eev-current/eepitch.el.html
> If you dont mind hackish and not heavily documented

Sorry jumped in without thinking.
OP asked about syntax highlighting.

eepitch does not do this at all (as far as I know).
And orgmode uses indirect buffers for that. One may or may not like
this as much as a (working) multiple mode.

Alexandre Oberlin

unread,
May 14, 2012, 4:33:09 PM5/14/12
to
org mode indeed seems to offer a realm of possibilities I still have to
explore:
http://emacs-fu.blogspot.it/2009/05/writing-and-blogging-with-org-mode.html

Cheers,

Alexandre
0 new messages