From: Robert Weiner <rsw@gnu.org>
To: Noam Postavsky <npostavs@users.sourceforge.net>
Cc: 24021@debbugs.gnu.org
Subject: bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
Date: Tue, 19 Jul 2016 09:15:49 -0400 [thread overview]
Message-ID: <CA+OMD9gETavHsLaoQ2s=P=f280VhM6+CoUv2Bm+v4FjD4ETAqg@mail.gmail.com> (raw)
In-Reply-To: <87oa5ucx1a.fsf@users.sourceforge.net>
[-- Attachment #1: Type: text/plain, Size: 2894 bytes --]
Slightly revised version of the function below.
On Mon, Jul 18, 2016 at 8:05 PM, <npostavs@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)))))
[-- Attachment #2: Type: text/html, Size: 5186 bytes --]
next prev parent reply other threads:[~2016-07-19 13:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-18 16:23 bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer Robert Weiner
2016-07-19 0:05 ` npostavs
2016-07-19 2:05 ` Robert Weiner
2016-07-19 2:20 ` Noam Postavsky
2016-07-19 13:15 ` Robert Weiner [this message]
2016-07-20 1:55 ` npostavs
2021-12-01 19:49 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+OMD9gETavHsLaoQ2s=P=f280VhM6+CoUv2Bm+v4FjD4ETAqg@mail.gmail.com' \
--to=rsw@gnu.org \
--cc=24021@debbugs.gnu.org \
--cc=npostavs@users.sourceforge.net \
--cc=rswgnu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.