From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Robert Weiner Newsgroups: gmane.emacs.bugs 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 Message-ID: References: <87oa5ucx1a.fsf@users.sourceforge.net> Reply-To: rswgnu@gmail.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113bfd0ceb4b750537fce393 X-Trace: ger.gmane.org 1468934729 5959 80.91.229.3 (19 Jul 2016 13:25:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Jul 2016 13:25:29 +0000 (UTC) Cc: 24021@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 19 15:25:19 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bPV1M-0002kR-37 for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Jul 2016 15:25:12 +0200 Original-Received: from localhost ([::1]:55933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPV1L-0005yH-8r for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Jul 2016 09:25:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPUtW-0004PJ-Vb for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2016 09:17:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPUtS-0000jP-De for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2016 09:17:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPUtS-0000jL-AV for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2016 09:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bPUtS-0006xC-3W for bug-gnu-emacs@gnu.org; Tue, 19 Jul 2016 09:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Robert Weiner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Jul 2016 13:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24021 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24021-submit@debbugs.gnu.org id=B24021.146893420126699 (code B ref 24021); Tue, 19 Jul 2016 13:17:02 +0000 Original-Received: (at 24021) by debbugs.gnu.org; 19 Jul 2016 13:16:41 +0000 Original-Received: from localhost ([127.0.0.1]:56611 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPUt2-0006wU-D4 for submit@debbugs.gnu.org; Tue, 19 Jul 2016 09:16:41 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58186) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPUsv-0006w8-PM for 24021@debbugs.gnu.org; Tue, 19 Jul 2016 09:16:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPUsn-0000eH-5h for 24021@debbugs.gnu.org; Tue, 19 Jul 2016 09:16:24 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPUsn-0000e4-28 for 24021@debbugs.gnu.org; Tue, 19 Jul 2016 09:16:21 -0400 Original-Received: from mail-oi0-f54.google.com ([209.85.218.54]:36099) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1bPUsl-0002mS-EQ for 24021@debbugs.gnu.org; Tue, 19 Jul 2016 09:16:19 -0400 Original-Received: by mail-oi0-f54.google.com with SMTP id w18so24522462oiw.3 for <24021@debbugs.gnu.org>; Tue, 19 Jul 2016 06:16:19 -0700 (PDT) X-Gm-Message-State: ALyK8tKtcGCR39eYeMKkRhKx+xVqTgNvKCxRHf9PFamjN3aV6O/KMZv4nJoaN5c+d9sgOf+zjA5j6cpwgP83dA== X-Received: by 10.157.10.16 with SMTP id 16mr24388958otg.131.1468934178685; Tue, 19 Jul 2016 06:16:18 -0700 (PDT) Original-Received: by 10.202.199.143 with HTTP; Tue, 19 Jul 2016 06:15:49 -0700 (PDT) In-Reply-To: <87oa5ucx1a.fsf@users.sourceforge.net> X-Gmail-Original-Message-ID: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:121257 Archived-At: --001a113bfd0ceb4b750537fce393 Content-Type: text/plain; charset=UTF-8 Slightly revised version of the function below. On Mon, Jul 18, 2016 at 8:05 PM, 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))))) --001a113bfd0ceb4b750537fce393 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Slightly revised versi= on of the function below.

On Mon, Jul 18, 2016 at 8:05 PM, <npostavs@users.sourceforge.net= > wrote:
>
>
> > (defun goto-marker (marker)> > =C2=A0 "Make MARKER's buffer and position current."= ;
> > =C2=A0 (interactive)
>
> The interactive spec do= esn't match the parameter list.=C2=A0 I'm not sure if
> it ma= kes sense for this to be interactive (how would the user enter a
> ma= rker?).


The interactive spec has been removed.
=C2=A0
>=
>
> > =C2=A0 (cond ((not (markerp marker))
> > =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(error "Invalid marker: %s" marker= ))
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((not (marker-buffer marker))> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(error "Invalid marker b= uffer: %s" marker))
>
> I think these checks are redundant= , you'll get the same errors when you
> call marker-buffer and se= t-buffer, below.

I like these checks as they make the specific error= very clear. =C2=A0set-buffer will trigger a type error when given a nil bu= ffer but neither marker-buffer nor marker-position signal an error when giv= en a marker that doesn't point anywhere, so the checks prior to calling= those functions are relevant.

>
> > =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (t (let* ((buffer (marker-buffer marker))
> > =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (position (marker-p= osition marker)))
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(set-buffer buffer)
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(or (and (>=3D position (point-min))
> > =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (<= =3D position (point-max)))
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(if widen-automatically
> > =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(widen)> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(error "Marker position is outside accessible part of buffer: %s= " marker)))
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(goto-char position)
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(switch-to-buffer buffer)))))
>
> If this is just a &= quot;simple function" (not an interactive command), it
> shouldn= 't widen, or call switch-to-buffer.
>
> =C2=A0
>
&= gt; save-excursion or save-current-buffer don't counteract
>
&= gt; switch-to-buffer, because it affects the UI selected buffer. You might<= br>>
> be right about the widen part, not sure.


You are= right that save-excursion and save-restriction won't counteract the ef= fects of this function, so its purpose must be to put the selected window&#= 39;s point at the location of the marker.=C2=A0 Possibly, a macro called wi= th-marker-location could be useful when one needs to temporarily set buffer= and point from a marker and evaluate some forms
=C2=A0
but not affec= t the display.

Here is the slightly revised function. =C2=A0-- Bob

(defun hypb:goto-marker (marker)
=C2=A0 "Make MARKER's buffer and= position current.
If = MARKER is invalid signal an error."
=C2=A0 (cond ((not (markerp marker))
(error "Invalid marker: %s" marker))
= ((not (marker-buffer marker))
(er= ror "Invalid marker buffer: %s" marker))
(t (let* ((buffer (marker-buffer marker))
=C2=A0(position (marker-position marker)))
=C2=A0 =C2=A0 (set-buffer buffer)
=C2=A0 = =C2=A0 (unless (and (>=3D position (point-min))
= =C2=A0(<=3D position (point-max)))
=C2=A0 =C2=A0 =C2=A0 (if widen-automatically
=C2=A0 (widen)
(error "Marker posit= ion is outside accessible part of buffer: %s" marker)))
=C2=A0 =C2=A0 (goto-char position)
=C2=A0 =C2=A0 (switch-to-buffer buffer)))))

--001a113bfd0ceb4b750537fce393--