all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to use `narrow'?
@ 2005-10-18  2:09 Ilya Zakharevich
  2005-10-18  8:13 ` Gian Uberto Lauri
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Ilya Zakharevich @ 2005-10-18  2:09 UTC (permalink / raw)



My idea how *I* would use `narrow' is like this:

  Suppose I have a file which is "in multiple modes".  E.g., consider
  some "literate programming" style text, or one which contains a
  HERE-document with a program in a different language than the main
  text of the document:

    $var = <<EOV;		 # E.g., this is Perl

       // Here is some code in JavaScript
       ...

    EOV

  So I would like to narrow to the region "inside the HERE-document",
  and switch the mode to "other mode" (above, from CPerl mode to
  JavaScript mode).

However, I looked, and `font-lock' does `widen' before it starts up;
so all the effect of narrowing is gone...  Is there any *use* of
narrowing?

Thanks,
Ilya

P.S. I ask this since now CPerl has a (contributed) code to
     `narrow-to-here-doc', and I would like to document why this would
     be useful...

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

* How to use `narrow'?
  2005-10-18  2:09 How to use `narrow'? Ilya Zakharevich
@ 2005-10-18  8:13 ` Gian Uberto Lauri
       [not found] ` <mailman.11713.1129623266.20277.help-gnu-emacs@gnu.org>
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Gian Uberto Lauri @ 2005-10-18  8:13 UTC (permalink / raw)
  Cc: help-gnu-emacs

>>>>> "IZ" == Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

IZ> My idea how *I* would use `narrow' is like this:

IZ>   Suppose I have a file which is "in multiple modes".

...

IZ>   So I would like to narrow to the region "inside the
IZ> HERE-document", and switch the mode to "other mode" (above, from
IZ> CPerl mode to JavaScript mode).

...

IZ> However, I looked, and `font-lock' does `widen' before it starts
IZ> up; so all the effect of narrowing is gone...  Is there any *use*
IZ> of narrowing?

font-lock widens then narrows, afaik.

So what's narrowed stays narrowed at least for what concerns the user.

-- 
 /\            ___
/___/\__|_|\_|__|___Gian Uberto Lauri_____________________
  //--\ | | \|  |   Integralista GNUslamico  
\/		    e allevatore di bug da competizione

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

* Re: How to use `narrow'?
       [not found] ` <mailman.11713.1129623266.20277.help-gnu-emacs@gnu.org>
@ 2005-10-18  8:47   ` Ilya Zakharevich
  0 siblings, 0 replies; 9+ messages in thread
From: Ilya Zakharevich @ 2005-10-18  8:47 UTC (permalink / raw)


[A complimentary Cc of this posting was sent to
Gian Uberto Lauri
<saint@eng.it>], who wrote in article <mailman.11713.1129623266.20277.help-gnu-emacs@gnu.org>:
> IZ> My idea how *I* would use `narrow' is like this:
> IZ>   Suppose I have a file which is "in multiple modes".
...
> IZ>   So I would like to narrow to the region "inside the
> IZ> HERE-document", and switch the mode to "other mode" (above, from
> IZ> CPerl mode to JavaScript mode).
> ...
> IZ> However, I looked, and `font-lock' does `widen' before it starts
> IZ> up; so all the effect of narrowing is gone...  Is there any *use*
> IZ> of narrowing?
> 
> font-lock widens then narrows, afaik.

> So what's narrowed stays narrowed at least for what concerns the user.

Eh???  There is no narrowing in font-lock (except some for C modes).
Thus fontification is based on the whole contents of the buffer (which
is multi-mode, thus can't be parsed by Emacs).

Yours,
Ilya

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

* Re: How to use `narrow'?
  2005-10-18  2:09 How to use `narrow'? Ilya Zakharevich
  2005-10-18  8:13 ` Gian Uberto Lauri
       [not found] ` <mailman.11713.1129623266.20277.help-gnu-emacs@gnu.org>
@ 2005-10-18 12:53 ` David Hansen
  2005-10-18 19:41   ` Ilya Zakharevich
  2005-10-18 16:25 ` Anselm Helbig
  3 siblings, 1 reply; 9+ messages in thread
From: David Hansen @ 2005-10-18 12:53 UTC (permalink / raw)


On Tue, 18 Oct 2005 02:09:51 +0000 (UTC) Ilya Zakharevich wrote:

> My idea how *I* would use `narrow' is like this:
>
>   Suppose I have a file which is "in multiple modes".  E.g., consider
>   some "literate programming" style text, or one which contains a
>   HERE-document with a program in a different language than the main
>   text of the document:
>
>     $var = <<EOV;		 # E.g., this is Perl
>
>        // Here is some code in JavaScript
>        ...
>
>     EOV
>
>   So I would like to narrow to the region "inside the HERE-document",
>   and switch the mode to "other mode" (above, from CPerl mode to
>   JavaScript mode).
>
> However, I looked, and `font-lock' does `widen' before it starts up;
> so all the effect of narrowing is gone...  Is there any *use* of
> narrowing?

Is this working?

(add-hook 'java-scrip-mode-hook 
          (lambda ()
            (set
             (make-local-variable 'font-lock-dont-widen t))))

,----[ C-h v font-lock-dont-widen RET ]
| font-lock-dont-widen is a variable defined in `font-lock'.
| Its value is nil
| 
| Documentation:
| If non-nil, font-lock will work on the non-widened buffer.
| Useful for things like RMAIL and Info where the whole buffer is not
| a very meaningful entity to highlight.
`----

David

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

* Re: How to use `narrow'?
  2005-10-18  2:09 How to use `narrow'? Ilya Zakharevich
                   ` (2 preceding siblings ...)
  2005-10-18 12:53 ` David Hansen
@ 2005-10-18 16:25 ` Anselm Helbig
  3 siblings, 0 replies; 9+ messages in thread
From: Anselm Helbig @ 2005-10-18 16:25 UTC (permalink / raw)


narrow-to-region is useful e.g. when you want to apply a command that
usually continues to the end of the buffer only to a part of the text,
sth like you do a query-replace and hit `!', or like repeating a
keyboard macro many times. 

if you need multiple modes, there's mmm-mode, two-mode and another one
i don't recall right now. none of these is a really perfect solution,
though. 

regards, 

anselm

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

* Re: How to use `narrow'?
  2005-10-18 12:53 ` David Hansen
@ 2005-10-18 19:41   ` Ilya Zakharevich
  2005-10-18 22:15     ` David Hansen
  0 siblings, 1 reply; 9+ messages in thread
From: Ilya Zakharevich @ 2005-10-18 19:41 UTC (permalink / raw)


[A complimentary Cc of this posting was sent to
David Hansen 
<david.hansen@gmx.net>], who wrote in article <87ek6j17i5.fsf@robotron.ath.cx>:
> Is this working?
> 
> (add-hook 'java-scrip-mode-hook 
>           (lambda ()
>             (set
>              (make-local-variable 'font-lock-dont-widen t))))

No, it does not help.  font-lock widens unconditionally.

> ,----[ C-h v font-lock-dont-widen RET ]
> | font-lock-dont-widen is a variable defined in `font-lock'.
> | Its value is nil
> | 
> | Documentation:
> | If non-nil, font-lock will work on the non-widened buffer.
> | Useful for things like RMAIL and Info where the whole buffer is not
> | a very meaningful entity to highlight.
> `----

I would prefer a solution which works in real world, not in some
imaginary settings...  However, it is nice that somebody realized that
widening is a problem.  When will we see it, in 22.1?

Thanks,
Ilya

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

* Re: How to use `narrow'?
  2005-10-18 19:41   ` Ilya Zakharevich
@ 2005-10-18 22:15     ` David Hansen
  2005-10-19  2:11       ` Ilya Zakharevich
  0 siblings, 1 reply; 9+ messages in thread
From: David Hansen @ 2005-10-18 22:15 UTC (permalink / raw)


On Tue, 18 Oct 2005 19:41:51 +0000 (UTC) Ilya Zakharevich wrote:

> No, it does not help.  font-lock widens unconditionally.
>
>> ,----[ C-h v font-lock-dont-widen RET ]
>
> I would prefer a solution which works in real world, not in some
> imaginary settings...  However, it is nice that somebody realized that
> widening is a problem.  When will we see it, in 22.1?

I'm sorry, i forgot to mention that I'm running emacs from CVS.

David

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

* Re: How to use `narrow'?
  2005-10-18 22:15     ` David Hansen
@ 2005-10-19  2:11       ` Ilya Zakharevich
  2005-10-21  4:29         ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Ilya Zakharevich @ 2005-10-19  2:11 UTC (permalink / raw)


[A complimentary Cc of this posting was sent to
David Hansen 
<david.hansen@gmx.net>], who wrote in article <874q7e1nfz.fsf@robotron.ath.cx>:
> On Tue, 18 Oct 2005 19:41:51 +0000 (UTC) Ilya Zakharevich wrote:
> 
> > No, it does not help.  font-lock widens unconditionally.
> >
> >> ,----[ C-h v font-lock-dont-widen RET ]
> >
> > I would prefer a solution which works in real world, not in some
> > imaginary settings...  However, it is nice that somebody realized that
> > widening is a problem.  When will we see it, in 22.1?

> I'm sorry, i forgot to mention that I'm running emacs from CVS.

Well, I guessed this.  But anyway, just font-lock-dont-widen is not
enough to have robust support for narrowing.  Obviously, there are
cases when this widen() *is* useful.  And there are cases when it is
harmful.

The only way I see which may be usable is a way to mark a *particular*
narrowing operation as requiring (or not) widen() during
fontification.  E.g., one could put some text property on the narrowed
region (as far as widen() is smart enough to remove this text property
afterwards...).

Is there anything like this in CVS?

Thanks,
Ilya

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

* Re: How to use `narrow'?
  2005-10-19  2:11       ` Ilya Zakharevich
@ 2005-10-21  4:29         ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2005-10-21  4:29 UTC (permalink / raw)


>> > No, it does not help.  font-lock widens unconditionally.
>> >
>> >> ,----[ C-h v font-lock-dont-widen RET ]
>> >
>> > I would prefer a solution which works in real world, not in some
>> > imaginary settings...  However, it is nice that somebody realized that
>> > widening is a problem.

Thanks Ilya for the compliment ;-)

>> > When will we see it, in 22.1?
>> I'm sorry, i forgot to mention that I'm running emacs from CVS.
> Well, I guessed this.  But anyway, just font-lock-dont-widen is not
> enough to have robust support for narrowing.  Obviously, there are
> cases when this widen() *is* useful.  And there are cases when it is
> harmful.

> The only way I see which may be usable is a way to mark a *particular*
> narrowing operation as requiring (or not) widen() during
> fontification.  E.g., one could put some text property on the narrowed
> region (as far as widen() is smart enough to remove this text property
> afterwards...).

Indeed, you're right.

> Is there anything like this in CVS?

No.  Narrowing is fairly badly defined in Emacs.  Sometimes it's used to
pretend the rest of the buffer doesn't exist at all, and other times it's
only meant to hide the rest of the buffer from some operations (e.g. from
display) without pretending the rest doesn't exist.

So, e.g. font-lock doesn't know whether to widen or not.  Same thing for
indentation, etc... it's pretty messy.  I personally try to stay away from
narrow except as an elisp tool for things like emulating the presence of
a `limit' argument to `looking-at'.

As for your original problem.  There are several packages that try to
provide support for multi-mode operation.  The approach they take to do that
vary, but I think they all end up using changing
font-lock-fontify-region-function so they can better control what is
highlighted how.  Maybe you could simply add support for mmm-mode or
multi-mode.el or somesuch and forget about narrowing ;-)


        Stefan

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

end of thread, other threads:[~2005-10-21  4:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-18  2:09 How to use `narrow'? Ilya Zakharevich
2005-10-18  8:13 ` Gian Uberto Lauri
     [not found] ` <mailman.11713.1129623266.20277.help-gnu-emacs@gnu.org>
2005-10-18  8:47   ` Ilya Zakharevich
2005-10-18 12:53 ` David Hansen
2005-10-18 19:41   ` Ilya Zakharevich
2005-10-18 22:15     ` David Hansen
2005-10-19  2:11       ` Ilya Zakharevich
2005-10-21  4:29         ` Stefan Monnier
2005-10-18 16:25 ` Anselm Helbig

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.