GNU bug report logs - #24021
FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer

Previous Next

Package: emacs;

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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 24021 in the body.
You can then email your comments to 24021 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#24021; Package emacs. (Mon, 18 Jul 2016 16:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to rswgnu <at> gmail.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 18 Jul 2016 16:24:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Robert Weiner <rsw <at> gnu.org>
To: bug-gnu-emacs <at> gnu.org
Subject: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially
 in a different buffer
Date: Mon, 18 Jul 2016 12:23:02 -0400
[Message part 1 (text/plain, inline)]
Since goto-char signals an error when given a marker pointing to a buffer
other than the current one (probably to prevent programming errors) and
pop-global-mark only works on the global-mark-ring, there is a need for a
simple function that jumps to the location of an arbitrary marker.  The
following function does that and is based on pop-global-mark.  Please
consider adding it to simple.el.

Bob

(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)))))
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24021; Package emacs. (Tue, 19 Jul 2016 00:06:01 GMT) Full text and rfc822 format available.

Message #8 received at 24021 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Robert Weiner <rsw <at> gnu.org>
Cc: rswgnu <at> gmail.com, 24021 <at> debbugs.gnu.org
Subject: Re: bug#24021: FEATURE ADDITION: 25.0.94: goto-marker,
 jumps to a marker potentially in a different buffer
Date: Mon, 18 Jul 2016 20:05:21 -0400
severity 24021 wishlist
quit

Robert Weiner <rsw <at> gnu.org> writes:

> Since goto-char signals an error when given a marker pointing to a
> buffer other than the current one (probably to prevent programming
> errors) and pop-global-mark only works on the global-mark-ring, there
> is a need for a simple function that jumps to the location of an
> arbitrary marker. The following function does that and is based on
> pop-global-mark. Please consider adding it to simple.el.
>
> Bob
>
> (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?).

>   (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.

>         (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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24021; Package emacs. (Tue, 19 Jul 2016 02:06:02 GMT) Full text and rfc822 format available.

Message #11 received at 24021 <at> debbugs.gnu.org (full text, mbox):

From: Robert Weiner <rswgnu <at> gmail.com>
To: npostavs <at> users.sourceforge.net
Cc: 24021 <at> debbugs.gnu.org
Subject: Re: bug#24021: FEATURE ADDITION: 25.0.94: goto-marker,
 jumps to a marker potentially in a different buffer
Date: Mon, 18 Jul 2016 22:05:33 -0400
Thanks for the feedback.  I will work on an update.

-- Bob

> On 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?).

That interactive spec should not be in there.
> 
>>  (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 will take a look.
> 
>>        (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.

But it does need to do these things to leave the selected buffer and point where the marker points.  It only widens if the marker position is outside the restricted range.  It can be wrapped in save-restriction and save-excursion for times when it is used for temporary effect, e.g. to find the column of the marker position.

Bob



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24021; Package emacs. (Tue, 19 Jul 2016 02:21:01 GMT) Full text and rfc822 format available.

Message #14 received at 24021 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Robert Weiner <rswgnu <at> gmail.com>
Cc: 24021 <at> debbugs.gnu.org
Subject: Re: bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a
 marker potentially in a different buffer
Date: Mon, 18 Jul 2016 22:20:20 -0400
On Mon, Jul 18, 2016 at 10:05 PM, Robert Weiner <rswgnu <at> gmail.com> wrote:
>>
>> If this is just a "simple function" (not an interactive command), it
>> shouldn't widen, or call switch-to-buffer.
>
> But it does need to do these things to leave the selected buffer and point where the marker points.  It only widens if the marker position is outside the restricted range.  It can be wrapped in save-restriction and save-excursion for times when it is used for temporary effect, e.g. to find the column of the marker position.

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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24021; Package emacs. (Tue, 19 Jul 2016 13:17:02 GMT) Full text and rfc822 format available.

Message #17 received at 24021 <at> debbugs.gnu.org (full text, mbox):

From: Robert Weiner <rsw <at> gnu.org>
To: Noam Postavsky <npostavs <at> users.sourceforge.net>
Cc: 24021 <at> debbugs.gnu.org
Subject: Re: 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
[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)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24021; Package emacs. (Wed, 20 Jul 2016 01:56:02 GMT) Full text and rfc822 format available.

Message #20 received at 24021 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Robert Weiner <rsw <at> gnu.org>
Cc: rswgnu <at> gmail.com, 24021 <at> debbugs.gnu.org
Subject: Re: bug#24021: FEATURE ADDITION: 25.0.94: goto-marker,
 jumps to a marker potentially in a different buffer
Date: Tue, 19 Jul 2016 21:55:30 -0400
Robert Weiner <rsw <at> gnu.org> writes:

>
> 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.

Fair enough, I would suggest using (unless ... (error ...)) to avoid
having the error checking add nesting depth to the main code.

>>
>> 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 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.

It really just makes more sense to let the caller do (switch-to-buffer
(current-buffer)) if needed.  Or display-buffer, or pop-to-buffer.  Not
hard coding the switch-to-buffer call makes the function more flexible
and usable in more situations.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24021; Package emacs. (Wed, 01 Dec 2021 19:50:02 GMT) Full text and rfc822 format available.

Message #23 received at 24021 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: npostavs <at> users.sourceforge.net
Cc: rswgnu <at> gmail.com, 24021 <at> debbugs.gnu.org, Robert Weiner <rsw <at> gnu.org>
Subject: Re: bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a
 marker potentially in a different buffer
Date: Wed, 01 Dec 2021 20:49:46 +0100
npostavs <at> users.sourceforge.net writes:

> It really just makes more sense to let the caller do (switch-to-buffer
> (current-buffer)) if needed.  Or display-buffer, or pop-to-buffer.  Not
> hard coding the switch-to-buffer call makes the function more flexible
> and usable in more situations.

I think that because of this, I don't think that a goto-marker function
is all that useful -- there's so many ways that you can "go" to a
different buffer that it's best to do that explicitly.

So I don't think this would be a generally useful function, and I'm
therefore closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 01 Dec 2021 19:50:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 24021 <at> debbugs.gnu.org and rswgnu <at> gmail.com Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 01 Dec 2021 19:50:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 30 Dec 2021 12:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 109 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.