help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A problem (apparently) connected with window point


From: Marcin Borkowski
Subject: Re: A problem (apparently) connected with window point
Date: Sat, 03 Apr 2021 05:25:35 +0200
User-agent: mu4e 1.1.0; emacs 28.0.50

On 2021-04-02, at 14:13, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>> The problem is that `reorder-sentence-copy-word-at-point' inserts every
>> word at the beginning of the buffer.  (Try it, following the steps
>> above.)  I very much suspect that this is because of the window point:
>
> That's right.  To avoid the problem you have to understand that
> `(with-current-buffer reorder-sentence--buffer ...)` will select the
> right buffer but will place point at a location that depends on what was
> the last use of that buffer (and redisplay *is* a use of that buffer,
> which is why having the buffer displayed makes a difference).
> In your case I think you have two options:

Thanks!  I have to admit that I still don't get _why_ this is
happening.  Why would `with-current-buffer' do that -- it just uses
`set-buffer' and `save-current-buffer' under the hood, and their
docstrings don't mention anything like that.  Isn't it a bug in the
docs, then?

> 1- Take it for granted that the buffer is displayed and make
>    `reorder-sentence-copy-word-at-point` move the corresponding
>    window-point (either by selecting that window around the `insert` or
>    by explicitly using `set-window-point`) and use that window-point as
>    the insertion point (so the user can move the cursor in that window
>    in order to insert word either at the end, beginning or elsewhere in
>    the temp buffer).
>
> 2- Use your own notion of "point", e.g. by calling (goto-char <my-point>)
>    before the `insert` and updating <my-point> as you see fit.
>    In your example, I suspect using (point-max) for <my-point> might do
>    the trick.

I think both vaiants make sense - 1 is slightly better (and I guess
doable via `get-buffer-window'), 2 is slightly simpler (and should cover
99.99% of the needs anyway).

Thanks,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]