all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: A problem (apparently) connected with window point
Date: Sat, 03 Apr 2021 05:25:35 +0200	[thread overview]
Message-ID: <87r1js82xc.fsf@mbork.pl> (raw)
In-Reply-To: <jwvft0828rh.fsf-monnier+emacs@gnu.org>


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	other threads:[~2021-04-03  3:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02  4:15 A problem (apparently) connected with window point Marcin Borkowski
2021-04-02  5:54 ` Eli Zaretskii
2021-04-02 12:13 ` Stefan Monnier
2021-04-03  3:25   ` Marcin Borkowski [this message]
2021-04-03 15:22     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1js82xc.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.