map-extents and narrowed buffer

Hrvoje Niksic <[email protected]>
Newsgroups gmane.emacs.xemacs.design
Message-ID <[email protected]>
I've just noticed that (map-extents FUNCTION nil nil nil) maps over
the extents in the whole buffer, not only the narrowed portion.

I wouldn't argue that it's a bug, but it certainly surprised me.  I
expected it to respect narrowing, just like pretty much anything else
in Emacs does.  As it stands, code that wants to correctly respect
narrowing has to explicitly specify (map-extents FUNCTION nil
(point-min) (point-max)), which looks a bit strange to me.

The documentation is not of much help, but the current wording seems
to support the current behavior:

    FUNCTION is called with the arguments (extent, MAPARG).  The
    arguments OBJECT, FROM, TO, MAPARG, and FLAGS are all optional and
    default to the current buffer, the beginning of OBJECT, the end of
    OBJECT, nil, and nil, respectively.

The "offending" code is in get_buffer_range_char:

  min_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
    BUF_BEG (b) : BUF_BEGV (b);
[...]
  if (NILP (from) && (flags & GB_ALLOW_NIL))
    *from_out = min_allowed;

In other words:

1. If "allow past accessible is in effect", BUF_BEG is the smallest
   allowed position.

2. If FROM is nil, set FROM to the minimum allowed position.

In other words, "allow specifying positions past the restriction" is
conflated with "make the *default* (nil) positions ignore the
restriction", which is not quite the same.

I wonder if things would break if we changed `nil' to mean
BUG_BEGV/BUF_ZV rather than BUF_BEG and BUF_Z, even in the
GB_ALLOW_PAST_ACCESSIBLE case?  As far as I can tell, not many
functions specify GB_ALLOW_PAST_ACCESSIBLE and GB_ALLOW_NIL at the
same time -- in fact, map-extents and map-extent-children are the only
ones!

I think map-extents should at least document the exact meaning of
`nil' FROM and TO.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.