Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:
being surprised WRT behavior of copy-marker:
(setq a (copy-marker nil)) -> #<marker in no buffer>
(markerp a) -> t
a -> #<marker in no buffer>
Is taking nil by copy-marker reasonable?
Wanted to check for a valid buffer position, which doesn't seem
possible that way. While without copy-marker, the variable a would be
set to nil, now the result evaluates to #<marker in no buffer>, which
is a kind of t.
There are other ways to get a marker to no buffer, such as
(let ((a (point-marker)))
(set-marker a nil))
So if you don't control the creation of the marker, it's probably a
scenario you need to take care for either way.
Explicitly testing the marker's buffer should work:
(let ((a (copy-marker nil)))
(and (markerp a)
(buffer-live-p (marker-buffer a))))