* bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
@ 2016-07-18 16:23 Robert Weiner
2016-07-19 0:05 ` npostavs
0 siblings, 1 reply; 7+ messages in thread
From: Robert Weiner @ 2016-07-18 16:23 UTC (permalink / raw)
To: 24021
[-- Attachment #1: Type: text/plain, Size: 983 bytes --]
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)))))
[-- Attachment #2: Type: text/html, Size: 3286 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
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 13:15 ` Robert Weiner
0 siblings, 2 replies; 7+ messages in thread
From: npostavs @ 2016-07-19 0:05 UTC (permalink / raw)
To: Robert Weiner; +Cc: rswgnu, 24021
severity 24021 wishlist
quit
Robert Weiner <rsw@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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
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
1 sibling, 1 reply; 7+ messages in thread
From: Robert Weiner @ 2016-07-19 2:05 UTC (permalink / raw)
To: npostavs; +Cc: 24021
Thanks for the feedback. I will work on an update.
-- Bob
> On 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?).
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
2016-07-19 2:05 ` Robert Weiner
@ 2016-07-19 2:20 ` Noam Postavsky
0 siblings, 0 replies; 7+ messages in thread
From: Noam Postavsky @ 2016-07-19 2:20 UTC (permalink / raw)
To: Robert Weiner; +Cc: 24021
On Mon, Jul 18, 2016 at 10:05 PM, Robert Weiner <rswgnu@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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
2016-07-19 0:05 ` npostavs
2016-07-19 2:05 ` Robert Weiner
@ 2016-07-19 13:15 ` Robert Weiner
2016-07-20 1:55 ` npostavs
1 sibling, 1 reply; 7+ messages in thread
From: Robert Weiner @ 2016-07-19 13:15 UTC (permalink / raw)
To: Noam Postavsky; +Cc: 24021
[-- 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 --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
2016-07-19 13:15 ` Robert Weiner
@ 2016-07-20 1:55 ` npostavs
2021-12-01 19:49 ` Lars Ingebrigtsen
0 siblings, 1 reply; 7+ messages in thread
From: npostavs @ 2016-07-20 1:55 UTC (permalink / raw)
To: Robert Weiner; +Cc: rswgnu, 24021
Robert Weiner <rsw@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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24021: FEATURE ADDITION: 25.0.94: goto-marker, jumps to a marker potentially in a different buffer
2016-07-20 1:55 ` npostavs
@ 2021-12-01 19:49 ` Lars Ingebrigtsen
0 siblings, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-01 19:49 UTC (permalink / raw)
To: npostavs; +Cc: rswgnu, 24021, Robert Weiner
npostavs@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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-12-01 19:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-07-20 1:55 ` npostavs
2021-12-01 19:49 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).