[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Fix hack-local-variables for find-file-literally with dos en
From: |
Lars Ingebrigtsen |
Subject: |
Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding |
Date: |
Mon, 16 Aug 2021 14:01:08 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
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
- [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Tom Gillespie, 2021/08/15
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Tom Gillespie, 2021/08/15
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Lars Ingebrigtsen, 2021/08/15
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding,
Lars Ingebrigtsen <=
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Lars Ingebrigtsen, 2021/08/16
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Eli Zaretskii, 2021/08/16
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Lars Ingebrigtsen, 2021/08/16
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Eli Zaretskii, 2021/08/16
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Tom Gillespie, 2021/08/16
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Stefan Monnier, 2021/08/16
- Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding, Eli Zaretskii, 2021/08/16