From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Weiner Newsgroups: gmane.emacs.devel Subject: Re: [elpa] externals/hyperbole c501027 2/2: Fix set-buffer byte-compiler warnings; remove outdated references Date: Mon, 10 May 2021 20:18:11 -0400 Message-ID: References: <20210510035708.29543.25002@vcs0.savannah.gnu.org> <20210510035709.E742920DFD@vcs0.savannah.gnu.org> Reply-To: rswgnu@gmail.com Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000e149cb05c202d500" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20775"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue May 11 02:19:56 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lgG7v-0005JJ-7i for ged-emacs-devel@m.gmane-mx.org; Tue, 11 May 2021 02:19:55 +0200 Original-Received: from localhost ([::1]:35472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgG7u-0001Oy-Am for ged-emacs-devel@m.gmane-mx.org; Mon, 10 May 2021 20:19:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgG6h-0000iw-Kf for emacs-devel@gnu.org; Mon, 10 May 2021 20:18:39 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:59338) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgG6h-0003ys-Cq for emacs-devel@gnu.org; Mon, 10 May 2021 20:18:39 -0400 Original-Received: from mail-lf1-f49.google.com ([209.85.167.49]:36718) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lgG6g-0001Cm-Tn for emacs-devel@gnu.org; Mon, 10 May 2021 20:18:39 -0400 Original-Received: by mail-lf1-f49.google.com with SMTP id m11so9577992lfg.3 for ; Mon, 10 May 2021 17:18:38 -0700 (PDT) X-Gm-Message-State: AOAM532CWijXzlQIKf4Q0UW73/4S3Q7vKgji0cmxbRYqEGgNVETN/Zmy OtTYkL2/+xLHp+QDH9HI5MYPRuX7uX0fOcfBHX0= X-Google-Smtp-Source: ABdhPJzQW2001SUYLCl6z8ecWwcBqIutUjm2jgwAdQKWCNS1hLAgtKcP4UmJeIg5em1ZrjaTBvsL44MXlpwG0P8vYOs= X-Received: by 2002:a05:6512:3141:: with SMTP id s1mr7784028lfi.171.1620692317586; Mon, 10 May 2021 17:18:37 -0700 (PDT) In-Reply-To: X-Gmail-Original-Message-ID: X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:269138 Archived-At: --000000000000e149cb05c202d500 Content-Type: text/plain; charset="UTF-8" Eli and I exchanged messages about this on the emacs-devel list and settled on the outer save-excursion as you first wrote below since it is indeed the original buffer whose point we want to save which may be manipulated by some subroutine deep within the with-current-buffer that changes the buffer back to the original. Thanks as always for the pointers though. -- Bob On Mon, May 10, 2021 at 10:00 AM Stefan Monnier wrote: > > (save-excursion > > - (set-buffer (if (bufferp loc) loc (find-file-noselect loc))) > > - (when (ibut:to (ibut:key but-sym)) > > - (let (buffer-read-only) > > - (if (< (point) start) > > - ;; Find beginning of button named label delimiter and > delete > > - ;; from there. > > - (progn (goto-char (- (point) (length ibut:label-start))) > > - (delete-region (point) end)) > > - ;; No label, just delete delimited ibutton text. > > - (delete-region start end)) > > - (when (looking-at "[ \t]*\r?\n") > > - (delete-region (point) (match-end 0))) > > - (run-hooks 'ibut-delete-hook)))) > > + (with-current-buffer (if (bufferp loc) loc (find-file-noselect > loc)) > > + (when (ibut:to (ibut:key but-sym)) > > + (let (buffer-read-only) > > + (if (< (point) start) > > + ;; Find beginning of button named label delimiter and > delete > > + ;; from there. > > + (progn (goto-char (- (point) (length > ibut:label-start))) > > + (delete-region (point) end)) > > + ;; No label, just delete delimited ibutton text. > > + (delete-region start end)) > > + (when (looking-at "[ \t]*\r?\n") > > + (delete-region (point) (match-end 0))) > > + (run-hooks 'ibut-delete-hook))))) > > but-sym)))) > > > > (defun ibut:get (&optional lbl-key buffer key-src) > > diff --git a/hui-window.el b/hui-window.el > > index 654c035..796770e 100644 > > --- a/hui-window.el > > +++ b/hui-window.el > > @@ -311,12 +311,12 @@ part of InfoDock and not a part of Hyperbole)." > > "Return t iff there is a non-empty active region in buffer of the > last Smart Mouse Key release." > > (when (setq hkey-value (if assist-flag assist-key-depress-prev-point > action-key-depress-prev-point)) > > (save-excursion > > - (set-buffer (marker-buffer hkey-value)) > > - ;; Store and goto any prior value of point from the region > > - ;; prior to the Smart Key depress, so we can return to it later. > > - (and (goto-char hkey-value) > > - (hmouse-save-region) > > - t)))) > > + (with-current-buffer (marker-buffer hkey-value) > > + ;; Store and goto any prior value of point from the region > > + ;; prior to the Smart Key depress, so we can return to it later. > > + (and (goto-char hkey-value) > > + (hmouse-save-region) > > + t))))) > > These two don't make much sense: `save-excursion` only saves the > position of point in the current buffer, so > > (save-excursion (with-current-buffer FOO ...)) > > is useless in one of two ways: > - FOO is already the current buffer, so `with-current-buffer` > (previously `set-buffer`) does nothing. > - FOO is a different buffer, so the buffer-position saved&restored by > `save-excursion` is in a buffer that's not affected by `...`. > > If you want to combine the two, then you should use > > (with-current-buffer FOO (save-excursion ...)) > > Tho if we presume that the `set-buffer` in the previous code did do > something useful (i.e. selected a different buffer), then there's a good > chance that the `save-excursion` has never done its intended job and can > be removed. > > > Stefan > > --000000000000e149cb05c202d500 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Eli and I exchanged messages about this on th= e emacs-devel list and settled on the outer save-excursion as you first wro= te below since it is indeed the original buffer whose point we want to save= which may be manipulated by some subroutine deep within the with-current-b= uffer that changes the buffer back to the original.=C2=A0 Thanks as always = for the pointers though.=C2=A0 -- Bob

On Mon, May 10, 2021 at 10:00 AM= Stefan Monnier <monnier@iro= .umontreal.ca> wrote:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(save-excursion
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0(set-buffer (if (bufferp loc) loc (find-fi= le-noselect loc)))
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0(when (ibut:to (ibut:key but-sym))
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let (buffer-read-only)
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (< (point) start)
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Find beginn= ing of button named label delimiter and delete
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; from there.=
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn (goto-c= har (- (point) (length ibut:label-start)))
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 (delete-region (point) end))
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; No label, just del= ete delimited ibutton text.
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-region start = end))
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when (looking-at "[ \t= ]*\r?\n")
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-region (point= ) (match-end 0)))
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(run-hooks 'ibut-delete-= hook))))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0(with-current-buffer (if (bufferp loc) loc= (find-file-noselect loc))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when (ibut:to (ibut:key but-sym))<= br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let (buffer-read-only)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (< (point) sta= rt)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Find= beginning of button named label delimiter and delete
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; from= there.
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn = (goto-char (- (point) (length ibut:label-start)))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 (delete-region (point) end))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; No label, j= ust delete delimited ibutton text.
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-region= start end))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when (looking-at &qu= ot;[ \t]*\r?\n")
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(delete-region= (point) (match-end 0)))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(run-hooks 'ibut-= delete-hook)))))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0but-sym))))
>=C2=A0
>=C2=A0 (defun=C2=A0 =C2=A0 ibut:get (&optional lbl-key buffer key-s= rc)
> diff --git a/hui-window.el b/hui-window.el
> index 654c035..796770e 100644
> --- a/hui-window.el
> +++ b/hui-window.el
> @@ -311,12 +311,12 @@ part of InfoDock and not a part of Hyperbole).&q= uot;
>=C2=A0 =C2=A0 "Return t iff there is a non-empty active region in = buffer of the last Smart Mouse Key release."
>=C2=A0 =C2=A0 (when (setq hkey-value (if assist-flag assist-key-depress= -prev-point action-key-depress-prev-point))
>=C2=A0 =C2=A0 =C2=A0 (save-excursion
> -=C2=A0 =C2=A0 =C2=A0 (set-buffer (marker-buffer hkey-value))
> -=C2=A0 =C2=A0 =C2=A0 ;; Store and goto any prior value of point from = the region
> -=C2=A0 =C2=A0 =C2=A0 ;; prior to the Smart Key depress, so we can ret= urn to it later.
> -=C2=A0 =C2=A0 =C2=A0 (and (goto-char hkey-value)
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 (hmouse-save-region)
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 t))))
> +=C2=A0 =C2=A0 =C2=A0 (with-current-buffer (marker-buffer hkey-value)<= br> > +=C2=A0 =C2=A0 =C2=A0;; Store and goto any prior value of point from t= he region
> +=C2=A0 =C2=A0 =C2=A0;; prior to the Smart Key depress, so we can retu= rn to it later.
> +=C2=A0 =C2=A0 =C2=A0(and (goto-char hkey-value)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (hmouse-save-region)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t)))))

These two don't make much sense: `save-excursion` only saves the
position of point in the current buffer, so

=C2=A0 =C2=A0 (save-excursion (with-current-buffer FOO ...))

is useless in one of two ways:
- FOO is already the current buffer, so `with-current-buffer`
=C2=A0 (previously `set-buffer`) does nothing.
- FOO is a different buffer, so the buffer-position saved&restored by =C2=A0 `save-excursion` is in a buffer that's not affected by `...`.
If you want to combine the two, then you should use

=C2=A0 =C2=A0 (with-current-buffer FOO (save-excursion ...))

Tho if we presume that the `set-buffer` in the previous code did do
something useful (i.e. selected a different buffer), then there's a goo= d
chance that the `save-excursion` has never done its intended job and can be removed.


=C2=A0 =C2=A0 =C2=A0 =C2=A0 Stefan

--000000000000e149cb05c202d500--