GNU bug report logs -
#24021
FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
Previous Next
Reported by: rswgnu <at> gmail.com
Date: Mon, 18 Jul 2016 16:24:02 UTC
Severity: wishlist
Tags: wontfix
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Slightly revised version of the function below.
On Mon, Jul 18, 2016 at 8:05 PM, <npostavs <at> users.sourceforge.net> wrote:
>
>
> > (defun goto-marker (marker)
> > "Make MARKER's buffer and position current."
> > (interactive)
>
> The interactive spec doesn't match the parameter list. I'm not sure if
> it makes sense for this to be interactive (how would the user enter a
> marker?).
The interactive spec has been removed.
>
>
> > (cond ((not (markerp marker))
> > (error "Invalid marker: %s" marker))
> > ((not (marker-buffer marker))
> > (error "Invalid marker buffer: %s" marker))
>
> I think these checks are redundant, you'll get the same errors when you
> call marker-buffer and set-buffer, below.
I like these checks as they make the specific error very clear. set-buffer
will trigger a type error when given a nil buffer but neither marker-buffer
nor marker-position signal an error when given a marker that doesn't point
anywhere, so the checks prior to calling those functions are relevant.
>
> > (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)))))
>
> If this is just a "simple function" (not an interactive command), it
> shouldn't widen, or call switch-to-buffer.
>
>
>
> save-excursion or save-current-buffer don't counteract
>
> switch-to-buffer, because it affects the UI selected buffer. You might
>
> be right about the widen part, not sure.
You are right that save-excursion and save-restriction won't counteract the
effects of this function, so its purpose must be to put the selected
window's point at the location of the marker. Possibly, a macro called
with-marker-location could be useful when one needs to temporarily set
buffer and point from a marker and evaluate some forms
but not affect the display.
Here is the slightly revised function. -- Bob
(defun hypb:goto-marker (marker)
"Make MARKER's buffer and position current.
If MARKER is invalid signal an error."
(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)
(unless (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)))))
[Message part 2 (text/html, inline)]
This bug report was last modified 3 years and 167 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.