* 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
* bug#54218: [PATCH] Magic number regexp shouldn't match beyond end-of-line.
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
1 sibling, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2022-03-02 8:23 UTC (permalink / raw)
To: Andrew L. Moore; +Cc: 54218
On Mär 01 2022, Andrew L. Moore wrote:
> 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]*\\)$")
In Emacs regexps, `.' doesn't match newlines.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#54218: [PATCH] Magic number regexp shouldn't match beyond end-of-line.
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
1 sibling, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-03 14:42 UTC (permalink / raw)
To: Andrew L. Moore; +Cc: 54218
"Andrew L. Moore" <slewsys@gmail.com> writes:
> Repeat magic number search to work around match-data loss
> when `save-window-excursion' is called.
I think it would perhaps make more sense to just save the match data
instead of repeating the match, so I've now done so in Emacs 29
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#54218: [PATCH] Magic number regexp shouldn't match beyond end-of-line.
2022-03-03 14:42 ` Lars Ingebrigtsen
@ 2022-03-03 19:57 ` Andrew L. Moore
2022-03-04 15:37 ` Lars Ingebrigtsen
0 siblings, 1 reply; 5+ messages in thread
From: Andrew L. Moore @ 2022-03-03 19:57 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 54218
On 3/3/22 09:42, Lars Ingebrigtsen wrote:
> "Andrew L. Moore" <slewsys@gmail.com> writes:
>
>> Repeat magic number search to work around match-data loss
>> when `save-window-excursion' is called.
>
> I think it would perhaps make more sense to just save the match data
> instead of repeating the match, so I've now done so in Emacs 29
Yes, this resolves the issues that I was seeing.
For the record, I'm not able to reproduce the data loss with
vanilla Emacs by calling `executable-set-magic' manually. It
occurs (for me) when `executable-set-magic' is called automatically
from a minor mode. In any case, your patch fixes my minor mode
and does no harm.
The other issue that I attributed to the regexp matching beyond
EOL was caused by `replace-match' being called by incorrect or
uninitialized match data. Your patch resolves this as well.
Thank you!
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#54218: [PATCH] Magic number regexp shouldn't match beyond end-of-line.
2022-03-03 19:57 ` Andrew L. Moore
@ 2022-03-04 15:37 ` Lars Ingebrigtsen
0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-04 15:37 UTC (permalink / raw)
To: Andrew L. Moore; +Cc: 54218
"Andrew L. Moore" <slewsys@gmail.com> writes:
> The other issue that I attributed to the regexp matching beyond
> EOL was caused by `replace-match' being called by incorrect or
> uninitialized match data. Your patch resolves this as well.
Thanks for checking.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [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 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.