From: Lars Ingebrigtsen <larsi@gnus.org>
To: Tom Gillespie <tgbugs@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding
Date: Mon, 16 Aug 2021 14:01:08 +0200 [thread overview]
Message-ID: <87bl5xfvjv.fsf@gnus.org> (raw)
In-Reply-To: <CA+G3_PORBJ9RcBmNBpix-d2b_B-FRVgohmawyOjMfDFmxN7VQw@mail.gmail.com> (Tom Gillespie's message of "Sun, 15 Aug 2021 15:21:19 -0700")
Tom Gillespie <tgbugs@gmail.com> writes:
> No, when we read a file literally we don't want to normalize anything.
> The issue is that 'when noconv' is set (i.e. we are in find-file-literally)
> then we don't want to convert ?\^m because the value of suffix
> contains ?\^m. Does this make sense? I tried other approaches
> including modifying the suffix but this one was by far the cleanest.
Ah, I see what you mean now. The code in
`hack-local-variables--find-variables' is clear enough in what it does,
but it's rather obscure in what it intends to do.
The issue is that if you've loaded a DOS file literally, and then you
want to run the local variables anyway, then you have a file like this:
;; -*- mode: Emacs-Lisp -*-^M
;; Local Variables:^M
;; lol: t^M
;; End:^M
Then we have this:
(when (let ((case-fold-search t))
(search-forward "Local Variables:" nil t))
(skip-chars-forward " \t")
;; suffix is what comes after "local variables:" in its line.
;; prefix is what comes before "local variables:" in its line.
(let ((suffix
(concat
(regexp-quote (buffer-substring (point)
(line-end-position)))
"$"))
So... it notes all characters that are after "local variables:", which
in this case is ^M.
Then later it does
(with-temp-buffer
(insert-buffer-substring thisbuf startpos endpos)
(goto-char (point-min))
(subst-char-in-region (point) (point-max) ?\^m ?\n)
(while (not (eobp))
;; Discard the prefix.
(if (looking-at prefix)
(delete-region (point) (match-end 0))
(error "Local variables entry is missing the prefix"))
and this fails.
I think the intention here is to be able to say:
;; Local Variables:my-identifier
;; lol: t
;; End:my-identifier
although that's not something I can remember seeing in the wild.
So I think your revised patch is correct -- the `subst-char-in-region'
thing is just plain wrong and should be removed.
Does anybody else have any insights into this corner of the
hack-local-variables code?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
next prev parent reply other threads:[~2021-08-16 12:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-15 21:23 [PATCH] Fix hack-local-variables for find-file-literally with dos encoding Tom Gillespie
2021-08-15 21:35 ` Tom Gillespie
2021-08-15 21:52 ` Lars Ingebrigtsen
2021-08-15 22:14 ` Lars Ingebrigtsen
2021-08-15 22:31 ` Tom Gillespie
2021-08-15 22:21 ` Tom Gillespie
2021-08-15 22:39 ` Tom Gillespie
2021-08-15 23:09 ` Tom Gillespie
2021-08-16 11:32 ` Eli Zaretskii
2021-08-16 12:01 ` Lars Ingebrigtsen [this message]
2021-08-16 12:06 ` Lars Ingebrigtsen
2021-08-16 12:29 ` Eli Zaretskii
2021-08-16 12:53 ` Lars Ingebrigtsen
2021-08-16 13:22 ` Eli Zaretskii
2021-08-16 17:44 ` Tom Gillespie
2021-08-16 17:49 ` Stefan Monnier
2021-08-16 18:09 ` Eli Zaretskii
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bl5xfvjv.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=emacs-devel@gnu.org \
--cc=tgbugs@gmail.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 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).