all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: Sebastien Vauban <sva-news@mygooglest.com>
Cc: 15453@debbugs.gnu.org
Subject: bug#15453: 24.3.50; Point moved away by Flyspell
Date: Thu, 26 Sep 2019 16:00:24 +0200	[thread overview]
Message-ID: <CADwFkm=Kvp0N7p1JGDTnyC8U3begBQ3MJNJ1UheYsqP2RA7QJA@mail.gmail.com> (raw)
In-Reply-To: <8638oujy75.fsf@somewhere.org>

tags 15453 notabug
close 15453
quit

"Sebastien Vauban" <sva-news@mygooglest.com> writes:

> When the following 2 conditions are met, Flyspell moves the pointer to the
> beginning of the buffer during commands which change the buffer, such as a
> string replace... But that completely breaks the operation mode of Emacs (and
> is scary).
>
> Conditions:
>
> - Activate Flyspell in `first-change-hook' (as there is no reason to do
>   anything Flyspell-related when opening files just for reading).
>
> - Have a `LocalWords' line in the opened file.
>
> Minimal `.emacs' file:
>
> ;; default dictionary to use
> (setq ispell-dictionary "american")
>
> ;; enable on-the-fly spell checking when changing a buffer which was
> ;; unmodified
> (add-hook 'first-change-hook
>           (lambda ()
>             (save-excursion
>               ;; skip temporary buffers
>               (unless (eq (aref (buffer-name) 0) ?\s) ;; buffer starts with " "
>                 (cond ((derived-mode-p 'text-mode) ;; org-mode
>                        (flyspell-mode 1))
>                       ((derived-mode-p 'prog-mode)
>                        ;; prevent flyspell from finding mistakes in the code,
>                        ;; which is pretty cool
>                        (flyspell-prog-mode))
>                       )))))
>
>
> Minimal file to reproduce the problem:
>
> #+TITLE:     Convert documents
>
> * Usage
>
> - Type =make doc.html= to regenerate only the file =doc.html=.
>
> #  LocalWords:  PDF pdf HTML html
>
> Recipe:
>
> 1. Open the example file
> 2. Put point somewhere in the middle of the file (for example, after the
>    heading "Usage")
> 3. Type `M-%' to replace `doc' by `file'
> 4. Answer `y' to replace the first occurrence (from current point position) of
>    `doc', that is in `make doc.html'
> 5. That modifies the buffer... hence calls `flyspell-mode'
> 6. The second occurrence to replace becomes `doc' from the title "Convert
>    documents" ... *instead of* `doc' from `doc.html' (if point hadn't been
>    moved away to the beginning of the buffer).
>
> Observations:
>
> 1. Having added a `save-excursion' around the `flyspell-mode' activation (in
>    `first-change-hook') did not solve the problem...

The correct solution here is to use save-match-data.  The following
version of your minimal config works for me:

(progn
  (setq ispell-dictionary "american")
  (add-hook 'first-change-hook
            (lambda ()
              (save-excursion
                (save-match-data
                  (unless (eq (aref (buffer-name) 0) ?\s)
                    (cond ((derived-mode-p 'text-mode)
                           (flyspell-mode 1))
                          ((derived-mode-p 'prog-mode)
                           (flyspell-prog-mode)))))))))

I think this is as expected, and I'm closing this as notabug.

Best regards,
Stefan Kangas





      reply	other threads:[~2019-09-26 14:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 10:44 bug#15453: 24.3.50; Point moved away by Flyspell Sebastien Vauban
2019-09-26 14:00 ` Stefan Kangas [this message]

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='CADwFkm=Kvp0N7p1JGDTnyC8U3begBQ3MJNJ1UheYsqP2RA7QJA@mail.gmail.com' \
    --to=stefan@marxist.se \
    --cc=15453@debbugs.gnu.org \
    --cc=sva-news@mygooglest.com \
    /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.