* Re: [elpa] externals/hyperbole c501027 2/2: Fix set-buffer byte-compiler warnings; remove outdated references
[not found] ` <20210510035709.E742920DFD@vcs0.savannah.gnu.org>
@ 2021-05-10 13:59 ` Stefan Monnier
2021-05-11 0:18 ` Robert Weiner
2021-05-11 15:15 ` Jean Louis
0 siblings, 2 replies; 4+ messages in thread
From: Stefan Monnier @ 2021-05-10 13:59 UTC (permalink / raw)
To: emacs-devel; +Cc: Bob Weiner
> (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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/hyperbole c501027 2/2: Fix set-buffer byte-compiler warnings; remove outdated references
2021-05-10 13:59 ` [elpa] externals/hyperbole c501027 2/2: Fix set-buffer byte-compiler warnings; remove outdated references Stefan Monnier
@ 2021-05-11 0:18 ` Robert Weiner
2021-05-11 1:25 ` Stefan Monnier
2021-05-11 15:15 ` Jean Louis
1 sibling, 1 reply; 4+ messages in thread
From: Robert Weiner @ 2021-05-11 0:18 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 3888 bytes --]
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 <monnier@iro.umontreal.ca>
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
>
>
[-- Attachment #2: Type: text/html, Size: 4963 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/hyperbole c501027 2/2: Fix set-buffer byte-compiler warnings; remove outdated references
2021-05-11 0:18 ` Robert Weiner
@ 2021-05-11 1:25 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2021-05-11 1:25 UTC (permalink / raw)
To: Robert Weiner; +Cc: rswgnu, emacs-devel
> 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
That seems to point at a very unusual arrangement which you might want
(in the longer term) to reconsider, e.g. by moving the `save-excursion`
to the "deep within" place that actually moves the point in the "outer
buffer".
In the mean time, adding a comment explaining what's going on
(e.g. giving an example scenario where point would be moved unexpectedly
in the outer buffer)would go a long way.
Similarly for the
(save-excursion
(with-current-buffer (find-file-noselect (expand-file-name hbmap:filename hbmap:dir-user))
(save-excursion
in `gbut:ebut-program` because without an explanatory comment, this looks
like the kind of code you get when the author just "added
`save-excursion`s a bit at random until point stopped moving" ;-)
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [elpa] externals/hyperbole c501027 2/2: Fix set-buffer byte-compiler warnings; remove outdated references
2021-05-10 13:59 ` [elpa] externals/hyperbole c501027 2/2: Fix set-buffer byte-compiler warnings; remove outdated references Stefan Monnier
2021-05-11 0:18 ` Robert Weiner
@ 2021-05-11 15:15 ` Jean Louis
1 sibling, 0 replies; 4+ messages in thread
From: Jean Louis @ 2021-05-11 15:15 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Bob Weiner, emacs-devel
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-05-10 17:01]:
> 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 `...`.
Thank you, I totally understood this one, though I am unrelated...
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-11 15:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20210510035708.29543.25002@vcs0.savannah.gnu.org>
[not found] ` <20210510035709.E742920DFD@vcs0.savannah.gnu.org>
2021-05-10 13:59 ` [elpa] externals/hyperbole c501027 2/2: Fix set-buffer byte-compiler warnings; remove outdated references Stefan Monnier
2021-05-11 0:18 ` Robert Weiner
2021-05-11 1:25 ` Stefan Monnier
2021-05-11 15:15 ` Jean Louis
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).