(defun goto-marker (marker)
"Make MARKER's buffer and position current."
(interactive)
(cond ((not (markerp marker))
(error "Invalid marker: %s" marker))
((not (marker-buffer marker))
(error "Invalid marker buffer: %s" marker))
(t (let* ((buffer (marker-buffer marker))
(position (marker-position marker)))
(set-buffer buffer)
(or (and (>= position (point-min))
(<= position (point-max)))
(if widen-automatically
(widen)
(error "Marker position is outside accessible part of buffer: %s" marker)))
(goto-char position)
(switch-to-buffer buffer)))))