unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#54218: [PATCH] Magic number regexp shouldn't match beyond end-of-line.
@ 2022-03-02  4:52 Andrew L. Moore
  2022-03-02  8:23 ` Andreas Schwab
  2022-03-03 14:42 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew L. Moore @ 2022-03-02  4:52 UTC (permalink / raw)
  To: 54218; +Cc: Andrew L. Moore

Repeat magic number search to work around match-data loss
when `save-window-excursion' is called.
---
  lisp/progmodes/executable.el | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el
index d7c093444e..9116bdea9d 100644
--- a/lisp/progmodes/executable.el
+++ b/lisp/progmodes/executable.el
@@ -232,7 +232,8 @@ executable-set-magic
        (save-excursion
         (goto-char (point-min))
         (add-hook 'after-save-hook 'executable-chmod nil t)
-       (if (looking-at "#![ \t]*\\(.*\\)$")
+        ;; Regexp shouldn't match beyond end-of-line.
+       (if (looking-at "#![ \t]*\\([^\n]*\\)$")
             (and (goto-char (match-beginning 1))
                  ;; If the line ends in a space,
                  ;; don't offer to change it.
@@ -247,8 +248,13 @@ executable-set-magic
                                       "Replace magic number by `#!%s'? "
                                       argument))))
                      (progn
-                      (replace-match argument t t nil 1)
-                      (message "Magic number changed to `#!%s'" 
argument))))
+                       ;; Repeat search to work around match-data loss
+                       ;; from call to `save-window-excursion' above.
+                       (goto-char (point-min))
+                       (if (looking-at "^#![ \t]*\\([^\n]*\\)$")
+                           (progn
+                            (replace-match argument t t nil 1)
+                            (message "Magic number changed to `#!%s'" 
argument))))))
           (insert "#!" argument ?\n)
           (message "Magic number changed to `#!%s'" argument))))
      interpreter)
-- 





^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-04 15:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-02  4:52 bug#54218: [PATCH] Magic number regexp shouldn't match beyond end-of-line Andrew L. Moore
2022-03-02  8:23 ` Andreas Schwab
2022-03-03 14:42 ` Lars Ingebrigtsen
2022-03-03 19:57   ` Andrew L. Moore
2022-03-04 15:37     ` Lars Ingebrigtsen

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).