From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#15453: 24.3.50; Point moved away by Flyspell Date: Thu, 26 Sep 2019 16:00:24 +0200 Message-ID: References: <8638oujy75.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="227080"; mail-complaints-to="usenet@blaine.gmane.org" Cc: 15453@debbugs.gnu.org To: Sebastien Vauban Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 26 16:01:32 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iDUKp-000ww6-Ml for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Sep 2019 16:01:31 +0200 Original-Received: from localhost ([::1]:36188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDUKm-00081B-7X for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Sep 2019 10:01:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57552) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iDUKR-0007zE-Jp for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 10:01:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iDUKP-000270-M6 for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 10:01:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35309) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iDUKM-00024T-W8 for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 10:01:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iDUKM-0005Tm-3L for bug-gnu-emacs@gnu.org; Thu, 26 Sep 2019 10:01:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <8638oujy75.fsf@somewhere.org> Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Sep 2019 14:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15453 X-GNU-PR-Package: emacs Original-Received: via spool by 15453-submit@debbugs.gnu.org id=B15453.156950644720157 (code B ref 15453); Thu, 26 Sep 2019 14:01:02 +0000 Original-Received: (at 15453) by debbugs.gnu.org; 26 Sep 2019 14:00:47 +0000 Original-Received: from localhost ([127.0.0.1]:44128 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iDUK6-0005Ef-IV for submit@debbugs.gnu.org; Thu, 26 Sep 2019 10:00:46 -0400 Original-Received: from mail-pl1-f175.google.com ([209.85.214.175]:44503) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iDUK4-000563-VW for 15453@debbugs.gnu.org; Thu, 26 Sep 2019 10:00:45 -0400 Original-Received: by mail-pl1-f175.google.com with SMTP id q15so1103464pll.11 for <15453@debbugs.gnu.org>; Thu, 26 Sep 2019 07:00:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=9X343jpRPO8JYXu5TLVbnoIpOfZVuEjBFVV/S9jv5EM=; b=b63Smy70+gP1ti4gIJ7f3SjJhr7MiQqNZu6Ajv1NJpor9+oT8gw0Nm4vIExx08nG8m 1Qim0oF29O878qsoPrPEgpTeB+4My27a4izl5zTr3Trrj+SkX2+aAhvDme03HOQFUQ1N /nvjM9EmlZ1tQV5fPnqxmQ3j641P8LxkevQyeWToqwppNNPNoD02yXfqBVYFHmBdHftB iSmFriUWJwARR/qI3SzO8OLLpBKNrB8ppPk7s/odi/Ie0WQvQj7hw/V0hUTAttZPczBV wcbY8nDcv8cyg9KU14URyyMSpbS7u5muqRLCcrK6A+SZ85RV3UEDZFiVj0TCtDOHQHQD CX7A== X-Gm-Message-State: APjAAAWlfWkGJlIJG1UyUN6sCYvTTVKr9BTQ814YkXIUicnXv8lLM8CP MmubctziqQ5TU1xqRWCOYv0dSRC+RyEdLGpEWM4= X-Google-Smtp-Source: APXvYqzRwNqXgee1tz3o20O3NVLTIQD2dR8u0QdIVpDiIvQSXgdYgA5/4jji0zP+UoKKhEOHwB/Hy7g2OYsR6Tks/U4= X-Received: by 2002:a17:902:326:: with SMTP id 35mr4502530pld.128.1569506435945; Thu, 26 Sep 2019 07:00:35 -0700 (PDT) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:167249 Archived-At: tags 15453 notabug close 15453 quit "Sebastien Vauban" 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