all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Peter Oliver <p.d.oliver@mavit.org.uk>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 48043@debbugs.gnu.org
Subject: bug#48043: UTF-8 magic comment is unwelcome with recent Ruby versions
Date: Tue, 27 Apr 2021 16:29:17 +0100 (BST)	[thread overview]
Message-ID: <bd862ce7-4b31-57ac-d267-acccb911efb9@froglet.home.mavit.org.uk> (raw)
In-Reply-To: <5a8e33ff-2ca9-7125-2fac-1874a9f69900@yandex.ru>

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

On Tue, 27 Apr 2021, Dmitry Gutov wrote:

> On 26.04.2021 21:28, Peter Oliver wrote:
>
>>  Two patches are attached to address this:
>>
>>  - The first patch adds a new choice to ruby-insert-encoding-magic-comment,
>>  unless-utf8, which causes the magic comment not to be inserted if the
>>  encoding is UTF-8.
>>
>>  - The second patch, perhaps more controversially, makes this the default.
>
> Both changes make sense to me.
>
> However, I've looked at the existing code and found a prior change which 
> intended for this to be more customizable already, yet had a minor bug.
>
> Please try out the following patch:

That works for me, and I think is more straightforward than my approach.  Thanks.

Attached is an additional patch which adapts the tests added in my patch for your patch.

-- 
Peter Oliver

[-- Attachment #2: Type: text/plain, Size: 2500 bytes --]

From 675c08cee899444f33113b806d6709b569c44790 Mon Sep 17 00:00:00 2001
From: Peter Oliver <git@mavit.org.uk>
Date: Tue, 27 Apr 2021 16:24:58 +0100
Subject: [PATCH] Test ruby-mode-set-encoding with a few different encodings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Follows on from Dmitry Gutov’s patch in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48043#8.
---
 test/lisp/progmodes/ruby-mode-tests.el | 30 ++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/test/lisp/progmodes/ruby-mode-tests.el b/test/lisp/progmodes/ruby-mode-tests.el
index 42a011c8bc..fec7d86a95 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -32,6 +32,12 @@ ruby-with-temp-buffer
      (ruby-mode)
      ,@body))
 
+(defmacro ruby-with-temp-file (contents &rest body)
+  `(ruby-with-temp-buffer ,contents
+     (set-visited-file-name "ruby-mode-tests")
+     ,@body
+     (delete-file buffer-file-name)))
+
 (defun ruby-should-indent (content column)
   "Assert indentation COLUMN on the last line of CONTENT."
   (ruby-with-temp-buffer content
@@ -844,6 +850,30 @@ ruby--insert-coding-comment-custom-style
       (ruby--insert-coding-comment "utf-8")
       (should (string= "# encoding: utf-8\n\n" (buffer-string))))))
 
+(ert-deftest ruby--set-encoding-when-ascii ()
+  (ruby-with-temp-file "ascii"
+    (let ((ruby-encoding-magic-comment-style 'ruby)
+          (ruby-insert-encoding-magic-comment t))
+      (setq save-buffer-coding-system 'us-ascii)
+      (ruby-mode-set-encoding)
+      (should (string= "ascii" (buffer-string))))))
+
+(ert-deftest ruby--set-encoding-when-utf8 ()
+  (ruby-with-temp-file "💎"
+    (let ((ruby-encoding-magic-comment-style 'ruby)
+          (ruby-insert-encoding-magic-comment t))
+      (setq save-buffer-coding-system 'utf-8)
+      (ruby-mode-set-encoding)
+      (should (string= "💎" (buffer-string))))))
+
+(ert-deftest ruby--set-encoding-when-latin-15 ()
+  (ruby-with-temp-file "Ⓡ"
+    (let ((ruby-encoding-magic-comment-style 'ruby)
+          (ruby-insert-encoding-magic-comment t))
+      (setq save-buffer-coding-system 'iso-8859-15)
+      (ruby-mode-set-encoding)
+      (should (string= "# coding: iso-8859-15\nⓇ" (buffer-string))))))
+
 (ert-deftest ruby--indent/converted-from-manual-test ()
   :tags '(:expensive-test)
   ;; Converted from manual test.
-- 
2.26.3


  reply	other threads:[~2021-04-27 15:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26 18:28 bug#48043: UTF-8 magic comment is unwelcome with recent Ruby versions Peter Oliver
2021-04-26 21:04 ` Dmitry Gutov
2021-04-27 15:29   ` Peter Oliver [this message]
2021-04-28  2:23     ` Dmitry Gutov
2021-04-28 11:59       ` Peter Oliver
2021-04-28 12:28         ` 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=bd862ce7-4b31-57ac-d267-acccb911efb9@froglet.home.mavit.org.uk \
    --to=p.d.oliver@mavit.org.uk \
    --cc=48043@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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.