all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom Gillespie <tgbugs@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: Re: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding
Date: Sun, 15 Aug 2021 14:35:40 -0700	[thread overview]
Message-ID: <CA+G3_PP1Wa785pyP2KGMxKVBM4yW6rGfgjmVOPNeSBv3bmSc_w@mail.gmail.com> (raw)
In-Reply-To: <CA+G3_PPNdCS8QWtemUuZ1LgwcwaLc=YLnSokcU9u9zc=OG+U7A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

Here is the backport to the emacs-27 branch. Best!
Tom

On Sun, Aug 15, 2021 at 2:23 PM Tom Gillespie <tgbugs@gmail.com> wrote:
>
> Hi,
>     This patch provides a test and a fix for an edge case when opening
> files literally that have dos crlf line endings. The patch was made
> against master, but a similar fix could be issued for a potential
> Emacs 27.3 release if one is forthcoming. Best!
> Tom

[-- Attachment #2: 0001-Backport-hack-local-variables-for-find-file-literall.patch --]
[-- Type: text/x-patch, Size: 2984 bytes --]

From 1c6a76ae9c436fe89bb9ab638696e4509a100a96 Mon Sep 17 00:00:00 2001
From: Tom Gillespie <tgbugs@gmail.com>
Date: Sun, 15 Aug 2021 14:31:43 -0700
Subject: [PATCH] Backport hack-local-variables for find-file-literally with
 dos

* lisp/files.el (hack-local-variables--find-variables): Update
hack-local-variables--find-variables to check whether a buffer has
find-file-literally set before converting ?\^m to ?\n.

* test/lisp/files-tests.el (files-tests-hack-local-literal-dos): Added
test for calling hack-local-variables on files with dos encoding opened
with find-file-literally.

This fixes a bug where hack-local-variables would fail to find a
matching suffix for local variables when files with dos line endings
were opened literally using find-file-literally.

The unless branch is conditioned on buffer-file-coding-system because
the find-file-literally local variable is set after the call to
set-buffer-major-mode in find-file-noselect-1. If find-file-literally
was set before calling set-buffer-major-mode then it could be use
directly.
---
 lisp/files.el            |  6 ++++--
 test/lisp/files-tests.el | 11 +++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 0a00b8b828..86c592e480 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3742,7 +3742,8 @@ hack-local-variables
 	      (forward-line 1)
 	      (let ((startpos (point))
 		    endpos
-		    (thisbuf (current-buffer)))
+		    (thisbuf (current-buffer))
+		    (noconv (eq buffer-file-coding-system 'no-conversion)))
 		(save-excursion
 		  (unless (let ((case-fold-search t))
 			    (re-search-forward
@@ -3758,7 +3759,8 @@ hack-local-variables
 		(with-temp-buffer
 		  (insert-buffer-substring thisbuf startpos endpos)
 		  (goto-char (point-min))
-		  (subst-char-in-region (point) (point-max) ?\^m ?\n)
+		  (unless noconv
+		    (subst-char-in-region (point) (point-max) ?\^m ?\n))
 		  (while (not (eobp))
 		    ;; Discard the prefix.
 		    (if (looking-at prefix)
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 1fc8007352..d24a4c5a23 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -150,6 +150,17 @@ files-tests-local-variables
         (dolist (subtest (cdr test))
           (should (file-test--do-local-variables-test str subtest)))))))
 
+(ert-deftest files-tests-hack-local-literal-dos ()
+  (let ((tempfile (make-temp-file "files-tests-test-hack-local-literal-dos" nil ".el")))
+    (unwind-protect
+        (progn
+          (with-temp-buffer
+            (insert ";; -*- mode: Emacs-Lisp -*-\^m\n;; Local Variables:\^m\n;; lol: t\^m\n;; End:\^m\n")
+            (write-file tempfile))
+          (with-current-buffer (find-file-literally tempfile)
+            (hack-local-variables)))
+      (delete-file tempfile))))
+
 (defvar files-test-bug-18141-file
   (expand-file-name "data/files-bug18141.el.gz" (getenv "EMACS_TEST_DIRECTORY"))
   "Test file for bug#18141.")
-- 
2.31.1


  reply	other threads:[~2021-08-15 21:35 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 [this message]
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
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+G3_PP1Wa785pyP2KGMxKVBM4yW6rGfgjmVOPNeSBv3bmSc_w@mail.gmail.com \
    --to=tgbugs@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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 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.