Automatic narrowing in Emacs?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatic narrowing in Emacs?

David Sumbler
This may be slightly off-topic, but it concerns a problem I have
encountered in Emacs when editing Lilypond files and at no other time.

I always use Emacs for creating and editing my Lilypond files.  Some of
these get quite large.  When editing a very long file (typically over
2,000 lines) I have discovered occasionally that I have apparently
inadvertently deleted a chunk at the beginning of the file.

I got in a terrible mess a couple of times trying to restore this
missing chunk from earlier versions of the file, only to find
afterwards that the relevant portion was never missing at all: it was
simply not shown in the window.

I now realise that in these cases the buffer has been "narrowed".  This
is a useful feature of Emacs that I wasn't even aware of previously,
and no doubt I shall start to use it intentionally in future.

But I find that a large buffer gets narrowed automatically when I am
editing, even though I have not given a command for this.  Even if I
then issue a 'widen' command (Ctrl-x n w) the buffer gets narrowed
again after short while.

I can find no reference in the Emacs Manual to this automatic
behaviour, so I thought perhaps it was a feature of the Lilypond Emacs
mode.  But having looked at the files in my
/usr/local/lilypond/usr/share/emacs/site-lisp/
directory, I cannot find anything relevant there either.

Can anyone explain why this odd behaviour is occurring?

David


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic narrowing in Emacs?

Andrew Bernard
Hi David,

Never heard of this being automatic. Have you got a lot of customisations in your emacs? What version are you running (not that I think that makes any difference) and on what platform?

Weird. hard to imagine how you would have both set a mark and typed C-x n n inadvertently.

I always found lilypond mode a bit strange. I don't use it. Can't think of any examples at the moment, but I understand it's a bit half baked, isn't that so?

Andrew


On Wed, 2 Jan 2019 at 23:13, David Sumbler <[hidden email]> wrote:
This may be slightly off-topic, but it concerns a problem I have
encountered in Emacs when editing Lilypond files and at no other time.

I always use Emacs for creating and editing my Lilypond files.  Some of
these get quite large.  When editing a very long file (typically over
2,000 lines) I have discovered occasionally that I have apparently
inadvertently deleted a chunk at the beginning of the file.

I got in a terrible mess a couple of times trying to restore this
missing chunk from earlier versions of the file, only to find
afterwards that the relevant portion was never missing at all: it was
simply not shown in the window.

I now realise that in these cases the buffer has been "narrowed".  This
is a useful feature of Emacs that I wasn't even aware of previously,
and no doubt I shall start to use it intentionally in future.

But I find that a large buffer gets narrowed automatically when I am
editing, even though I have not given a command for this.  Even if I
then issue a 'widen' command (Ctrl-x n w) the buffer gets narrowed
again after short while.

I can find no reference in the Emacs Manual to this automatic
behaviour, so I thought perhaps it was a feature of the Lilypond Emacs
mode.  But having looked at the files in my
/usr/local/lilypond/usr/share/emacs/site-lisp/
directory, I cannot find anything relevant there either.

Can anyone explain why this odd behaviour is occurring?

David


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic narrowing in Emacs?

David Kastrup
In reply to this post by David Sumbler
David Sumbler <[hidden email]> writes:

> I now realise that in these cases the buffer has been "narrowed".
> This is a useful feature of Emacs that I wasn't even aware of
> previously, and no doubt I shall start to use it intentionally in
> future.
>
> But I find that a large buffer gets narrowed automatically when I am
> editing, even though I have not given a command for this.  Even if I
> then issue a 'widen' command (Ctrl-x n w) the buffer gets narrowed
> again after short while.

The key sequences for narrowing are _disabled_ by default as narrowing
is confusing.  If you haven't enabled them, this should not be an issue.

Looking at LilyPond-mode, I see a few occurences of narrowing:

$ git grep narrow
lilypond-indent.el:      (narrow-to-region
lilypond-mode.el:      (narrow-to-region start end)
lilypond-song.el:          (narrow-to-region (or (mark) (point)) (point)))

Those are likely for purely programmatic reasons.  If you are plagued
here, you may want to review the respective Elisp passages to see if the
narrow-to-region sequences are reliably reversed (by being encapsulated
in constructs that are guaranteed to restore the state of narrowing even
when exited in error cases).

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic narrowing in Emacs?

Andrew Bernard
Hi All,

I now remember it was exactly this issue some time ago that caused me to stop using lilypond-mode. The narrowing does not get undone properly. My emacs-lisp coding is not up to fixing it.

Is there anyone that could have a go at it?


Andrew



_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Automatic narrowing in Emacs?

David Sumbler
In reply to this post by David Kastrup
-----Original Message-----
From: David Kastrup <[hidden email]>
To: David Sumbler <[hidden email]>
CC: [hidden email]
Subject: Re: Automatic narrowing in Emacs?
Date: Wed, 02 Jan 2019 15:14:29 +0100

David Sumbler <[hidden email]> writes:

> I now realise that in these cases the buffer has been "narrowed".
> This is a useful feature of Emacs that I wasn't even aware of
> previously, and no doubt I shall start to use it intentionally in
> future.
>
> But I find that a large buffer gets narrowed automatically when I am
> editing, even though I have not given a command for this.  Even if I
> then issue a 'widen' command (Ctrl-x n w) the buffer gets narrowed
> again after short while.

The key sequences for narrowing are _disabled_ by default as narrowing
is confusing.  If you haven't enabled them, this should not be an
issue.

Looking at LilyPond-mode, I see a few occurences of narrowing:

$ git grep narrow
lilypond-indent.el:      (narrow-to-region
lilypond-mode.el:      (narrow-to-region start end)
lilypond-song.el:          (narrow-to-region (or (mark) (point))
(point)))

Those are likely for purely programmatic reasons.  If you are plagued
here, you may want to review the respective Elisp passages to see if
the narrow-to-region sequences are reliably reversed (by being encapsulated in constructs that are guaranteed to restore the state of narrowing even when exited in error cases).

-----Original Message-----
From: Andrew Bernard <[hidden email]>
To: lilypond-user Mailinglist <[hidden email]>
Subject: Re: Automatic narrowing in Emacs?
Date: Wed, 2 Jan 2019 23:33:47 +1100

Hi David,

Never heard of this being automatic. Have you got a lot of
customisations in your emacs? What version are you running (not that I
think that makes any difference) and on what platform?

Weird. hard to imagine how you would have both set a mark and typed C-x
n n inadvertently.

I always found lilypond mode a bit strange. I don't use it. Can't think
of any examples at the moment, but I understand it's a bit half baked,
isn't that so?

----------------------------------

To answer Andrew first, I am running Emacs 25.2.2 in Ubuntu 18.04.  My
own customisations of Emacs are fairly normal and trivial (screen and
font colour etc.).

And David is quite right: if I type C-x n n I get told that narrowing
is disabled, and would have to choose to enable it.  I am pretty sure
that I am cannot be typing C-x n n SPC or C-x n n ! by accident.

In other words, my buffer is being narrowed even when the narrowing
commands themselves are disabled.  Pretty mysterious, eh?

I had already looked at those 3 mentions of narrowing in the Lilypond-
mode files.  From what I could see they wouldn't cause narrowing by
accident, although I am not capable of analysing the code to the extent
that David suggests in his final sentence.

As for Lilypond-mode being half-baked, I don't find that, although
there are a few anomalies, e.g. indenting after manual beams and
sometimes after slurs is a bit buggy.  (I don't think the characters
'()[]' should affect the indenting at all in pure Lilypond code, but
occasionally they do.)  And I add 'q' to the list of allowable note-
names in lilypond-words.el so that repeated chords don't stand out like
lighthouses in the text!

David


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user