Next: Q5.1.11, Previous: Q5.1.9, Up: Miscellaneous
map-extents
won’t traverse all of my extents!I tried to use map-extents
to do an operation on all the extents
in a region. However, it seems to quit after processing a random number
of extents. Is it buggy?
No. The documentation of map-extents
states that it will iterate
across the extents as long as function returns nil
.
Unexperienced programmers often forget to return nil
explicitly,
which results in buggy code. For instance, the following code is
supposed to delete all the extents in a buffer, and issue as many
‘fubar!’ messages.
(map-extents (lambda (ext ignore) (delete-extent ext) (message "fubar!")))
Instead, it will delete only the first extent, and stop right there –
because message
will return a non-nil value. The correct code
is:
(map-extents (lambda (ext ignore) (delete-extent ext) (message "fubar!") nil))