unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
@ 2013-11-01 12:59 Bozhidar Batsov
  2013-11-01 17:46 ` Stefan Monnier
  2013-11-02  0:00 ` Dmitry Gutov
  0 siblings, 2 replies; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-01 12:59 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 336 bytes --]

Hi guys,  

Since Ruby 1.8 reached end of life in the summer and most projects these days use Ruby 2.0 (which assumes source files use utf8 by default) having `ruby-insert-encoding-magic-comment’ doesn’t make much sense. Most people just disable it anyways, so why not have it disabled by default?  

--  
Cheers,
Bozhidar


[-- Attachment #1.2: Type: text/html, Size: 598 bytes --]

[-- Attachment #2: 0001-lisp-progmodes-ruby-mode.el-Set.patch --]
[-- Type: application/octet-stream, Size: 883 bytes --]

From 9e0bcf177292d0c62f7ad6730700a8eee21e80b1 Mon Sep 17 00:00:00 2001
From: Bozhidar Batsov <bozhidar@batsov.com>
Date: Fri, 1 Nov 2013 14:51:28 +0200
Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set  
 `ruby-insert-encoding-magic-comment' to nil by default.

---
 lisp/progmodes/ruby-mode.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 1a49f70..2f68dfd 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -260,7 +260,7 @@ explicitly declared in magic comment."
   :type '(repeat (cons (symbol :tag "From") (symbol :tag "To")))
   :group 'ruby)
 
-(defcustom ruby-insert-encoding-magic-comment t
+(defcustom ruby-insert-encoding-magic-comment nil
   "Insert a magic Emacs 'coding' comment upon save if this is non-nil."
   :type 'boolean :group 'ruby)
 
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-01 12:59 Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default Bozhidar Batsov
@ 2013-11-01 17:46 ` Stefan Monnier
  2013-11-01 18:51   ` Bozhidar Batsov
  2013-11-02  0:00 ` Dmitry Gutov
  1 sibling, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2013-11-01 17:46 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: emacs-devel

> Since Ruby 1.8 reached end of life in the summer and most projects these
> days use Ruby 2.0 (which assumes source files use utf8 by default) having
> ruby-insert-encoding-magic-comment’ doesn’t make much sense.  Most people
> just disable it anyways, so why not have it disabled by default?  

IIUC, Ruby-2.0 doesn't require source code to be utf-8, so the
magic-comment is not obsolete.  IOW, what needs to be done is to make
Emacs prefer utf-8 for ruby files (it's probably the case already), and
to make ruby-mode-set-encoding only insert the magic comment if it is
different from utf-8.


        Stefan "not a Ruby user"


PS: The `ruby' package in Debian stable is still at 1.9.1.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-01 17:46 ` Stefan Monnier
@ 2013-11-01 18:51   ` Bozhidar Batsov
  0 siblings, 0 replies; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-01 18:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

I cannot imagine why would anyone want to use any encoding other than utf-8
for their code. As for Ruby 1.9 - I think it makes sense to simply set the
magic comment to utf-8 if a file contains non-ascii characters. Keep in
mind that I'm not suggesting to remove the functionality, but simply to
disable it by default, since it's not something that most Ruby hackers
today would want to use.


On 1 November 2013 19:46, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> > Since Ruby 1.8 reached end of life in the summer and most projects these
> > days use Ruby 2.0 (which assumes source files use utf8 by default) having
> > ruby-insert-encoding-magic-comment’ doesn’t make much sense.  Most people
> > just disable it anyways, so why not have it disabled by default?
>
> IIUC, Ruby-2.0 doesn't require source code to be utf-8, so the
> magic-comment is not obsolete.  IOW, what needs to be done is to make
> Emacs prefer utf-8 for ruby files (it's probably the case already), and
> to make ruby-mode-set-encoding only insert the magic comment if it is
> different from utf-8.
>
>
>         Stefan "not a Ruby user"
>
>
> PS: The `ruby' package in Debian stable is still at 1.9.1.
>

[-- Attachment #2: Type: text/html, Size: 1643 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-01 12:59 Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default Bozhidar Batsov
  2013-11-01 17:46 ` Stefan Monnier
@ 2013-11-02  0:00 ` Dmitry Gutov
  2013-11-02 10:38   ` Bozhidar Batsov
  1 sibling, 1 reply; 17+ messages in thread
From: Dmitry Gutov @ 2013-11-02  0:00 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: emacs-devel

Bozhidar Batsov <bozhidar@batsov.com> writes:

> Since Ruby 1.8 reached end of life in the summer and most projects these days use Ruby 2.0 (which
> assumes source files use utf8 by default) having `ruby-insert-encoding-magic-comment’ doesn’t make
> much sense. Most people just disable it anyways, so why not have it disabled by default?

AFAICT, even in 2.0 it's still important for Japanese users who may use
an encoding other than UTF-8.

Disabling the addition of magic comment when UTF-8 is used should be
done via adding '(utf-8 . nil) to `ruby-encoding-map', and even that I
can't support personally since our team, at work, is still on 1.9.3.

Also see http://lists.gnu.org/archive/html/emacs-devel/2013-10/msg00236.html



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-02  0:00 ` Dmitry Gutov
@ 2013-11-02 10:38   ` Bozhidar Batsov
  2013-11-02 20:15     ` Dmitry Gutov
  0 siblings, 1 reply; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-02 10:38 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

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

On 2 November 2013 02:00, Dmitry Gutov <dgutov@yandex.ru> wrote:

> Bozhidar Batsov <bozhidar@batsov.com> writes:
>
> > Since Ruby 1.8 reached end of life in the summer and most projects these
> days use Ruby 2.0 (which
> > assumes source files use utf8 by default) having
> `ruby-insert-encoding-magic-comment’ doesn’t make
> > much sense. Most people just disable it anyways, so why not have it
> disabled by default?
>
> AFAICT, even in 2.0 it's still important for Japanese users who may use
> an encoding other than UTF-8.
>
> Disabling the addition of magic comment when UTF-8 is used should be
> done via adding '(utf-8 . nil) to `ruby-encoding-map', and even that I
> can't support personally since our team, at work, is still on 1.9.3.
>
> Also see
> http://lists.gnu.org/archive/html/emacs-devel/2013-10/msg00236.html


Disabling this by default is not directly related to improving it. While I
think your suggestions for running this in an after-save-hook are sound, I
feel that the majority of Ruby programmers out there no longer need this,
so it doesn't make sense to have it on by default just to make people
search how to disable it (unless it stops messing with files that are
already using utf-8, which as you note is problematic for users of Ruby
1.9).

P.S. I also think we should insert the comment in Ruby style (e.g. "#
encoding: utf-8") instead of the current Emacs style encoding comment (or
make this customizable).

[-- Attachment #2: Type: text/html, Size: 2057 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-02 10:38   ` Bozhidar Batsov
@ 2013-11-02 20:15     ` Dmitry Gutov
  2013-11-03  7:35       ` Bozhidar Batsov
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Gutov @ 2013-11-02 20:15 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: emacs-devel

On 02.11.2013 14:38, Bozhidar Batsov wrote:
>     Also see
>     http://lists.gnu.org/archive/html/emacs-devel/2013-10/msg00236.html
>
>
> Disabling this by default is not directly related to improving it. While
> I think your suggestions for running this in an after-save-hook are
> sound, I feel that the majority of Ruby programmers out there no longer
> need this, so it doesn't make sense to have it on by default just to
> make people search how to disable it (unless it stops messing with files
> that are already using utf-8, which as you note is problematic for users
> of Ruby 1.9).

I don't understand what you mean with the sentence in parentheses.

Ruby 1.9 still requires "coding: utf-8" cookies in unicode files that 
have non-ascii characters. There was a problem with inserting it 
("coding: unknown" was often inserted instead), but that has been fixed.

> P.S. I also think we should insert the comment in Ruby style (e.g. "#
> encoding: utf-8") instead of the current Emacs style encoding comment
> (or make this customizable).

Maybe. I'm not sure what would be the benefit, but it sounds fine to me.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-02 20:15     ` Dmitry Gutov
@ 2013-11-03  7:35       ` Bozhidar Batsov
  2013-11-03  9:22         ` Dmitry Gutov
  0 siblings, 1 reply; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-03  7:35 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

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

On 2 November 2013 22:15, Dmitry Gutov <dgutov@yandex.ru> wrote:

> On 02.11.2013 14:38, Bozhidar Batsov wrote:
>
>>     Also see
>>     http://lists.gnu.org/archive/html/emacs-devel/2013-10/msg00236.html
>>
>>
>> Disabling this by default is not directly related to improving it. While
>> I think your suggestions for running this in an after-save-hook are
>> sound, I feel that the majority of Ruby programmers out there no longer
>> need this, so it doesn't make sense to have it on by default just to
>> make people search how to disable it (unless it stops messing with files
>> that are already using utf-8, which as you note is problematic for users
>> of Ruby 1.9).
>>
>
> I don't understand what you mean with the sentence in parentheses.
>

Sorry about the lack of clarity - I meant that if you have a Ruby 2.0 only
project you likely don't want the insertion of utf-8 coding comments.


>
> Ruby 1.9 still requires "coding: utf-8" cookies in unicode files that have
> non-ascii characters. There was a problem with inserting it ("coding:
> unknown" was often inserted instead), but that has been fixed.


Yeah, I'm aware of that. In my open source projects I still keep 1.9
compatibility and generally include those cookies in every file. Since I
want them included unconditionally (AFAIK many other Ruby programmers do
this as well for the sake of consistency) the magic-comment functionality
in ruby-mode is quite useless to me even for Ruby 1.9. If we add the option
to include the magic comment unconditionally that might increase the
usefulness of the setting for some people.


>
>
>  P.S. I also think we should insert the comment in Ruby style (e.g. "#
>> encoding: utf-8") instead of the current Emacs style encoding comment
>> (or make this customizable).
>>
>
> Maybe. I'm not sure what would be the benefit, but it sounds fine to me.
>

[-- Attachment #2: Type: text/html, Size: 2943 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-03  7:35       ` Bozhidar Batsov
@ 2013-11-03  9:22         ` Dmitry Gutov
  2013-11-04 13:40           ` Bozhidar Batsov
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Gutov @ 2013-11-03  9:22 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: emacs-devel

Bozhidar Batsov <bozhidar@batsov.com> writes:

> Sorry about the lack of clarity - I meant that if you have a Ruby 2.0 only project you likely don't
> want the insertion of utf-8 coding comments.
>
> ...
>
> Yeah, I'm aware of that. In my open source projects I still keep 1.9 compatibility and generally
> include those cookies in every file. Since I want them included unconditionally (AFAIK many other
> Ruby programmers do this as well for the sake of consistency) the magic-comment functionality in
> ruby-mode is quite useless to me even for Ruby 1.9.

Now I get it, thanks for the explanation.

> If we add the option to include the magic
> comment unconditionally that might increase the usefulness of the
> setting for some people.

Sure, as long as it's not on by default. For example, add a new possible
value of `ruby-insert-encoding-magic-comment': `always'. Or `always-utf8'.

In this case, `ruby-mode-set-encoding' might short-circuit the whole
encoding detection logic and just always write `coding: utf-8'.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-03  9:22         ` Dmitry Gutov
@ 2013-11-04 13:40           ` Bozhidar Batsov
  2013-11-06 17:10             ` Bozhidar Batsov
  0 siblings, 1 reply; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-04 13:40 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

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

OK. I'll implement the discussed customizations.


On 3 November 2013 11:22, Dmitry Gutov <dgutov@yandex.ru> wrote:

> Bozhidar Batsov <bozhidar@batsov.com> writes:
>
> > Sorry about the lack of clarity - I meant that if you have a Ruby 2.0
> only project you likely don't
> > want the insertion of utf-8 coding comments.
> >
> > ...
> >
> > Yeah, I'm aware of that. In my open source projects I still keep 1.9
> compatibility and generally
> > include those cookies in every file. Since I want them included
> unconditionally (AFAIK many other
> > Ruby programmers do this as well for the sake of consistency) the
> magic-comment functionality in
> > ruby-mode is quite useless to me even for Ruby 1.9.
>
> Now I get it, thanks for the explanation.
>
> > If we add the option to include the magic
> > comment unconditionally that might increase the usefulness of the
> > setting for some people.
>
> Sure, as long as it's not on by default. For example, add a new possible
> value of `ruby-insert-encoding-magic-comment': `always'. Or `always-utf8'.
>
> In this case, `ruby-mode-set-encoding' might short-circuit the whole
> encoding detection logic and just always write `coding: utf-8'.
>

[-- Attachment #2: Type: text/html, Size: 1737 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-04 13:40           ` Bozhidar Batsov
@ 2013-11-06 17:10             ` Bozhidar Batsov
  2013-11-06 21:45               ` Dmitry Gutov
  0 siblings, 1 reply; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-06 17:10 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 1470 bytes --]

Here's a patch for making the comment format customizable. How does it look
to you?


I'll send later another patch with the always-utf8 customization we
discussed.


On 4 November 2013 15:40, Bozhidar Batsov <bozhidar@batsov.com> wrote:

> OK. I'll implement the discussed customizations.
>
>
> On 3 November 2013 11:22, Dmitry Gutov <dgutov@yandex.ru> wrote:
>
>> Bozhidar Batsov <bozhidar@batsov.com> writes:
>>
>> > Sorry about the lack of clarity - I meant that if you have a Ruby 2.0
>> only project you likely don't
>> > want the insertion of utf-8 coding comments.
>> >
>> > ...
>> >
>> > Yeah, I'm aware of that. In my open source projects I still keep 1.9
>> compatibility and generally
>> > include those cookies in every file. Since I want them included
>> unconditionally (AFAIK many other
>> > Ruby programmers do this as well for the sake of consistency) the
>> magic-comment functionality in
>> > ruby-mode is quite useless to me even for Ruby 1.9.
>>
>> Now I get it, thanks for the explanation.
>>
>> > If we add the option to include the magic
>> > comment unconditionally that might increase the usefulness of the
>> > setting for some people.
>>
>> Sure, as long as it's not on by default. For example, add a new possible
>> value of `ruby-insert-encoding-magic-comment': `always'. Or `always-utf8'.
>>
>> In this case, `ruby-mode-set-encoding' might short-circuit the whole
>> encoding detection logic and just always write `coding: utf-8'.
>>
>
>

[-- Attachment #1.2: Type: text/html, Size: 2327 bytes --]

[-- Attachment #2: 0001-lisp-progmodes-ruby-mode.el-ruby-mode-set-encoding.patch --]
[-- Type: application/octet-stream, Size: 1641 bytes --]

From 3202624bb533968cc1bdd7b4a8c8669a9fc4f967 Mon Sep 17 00:00:00 2001
From: Bozhidar Batsov <bozhidar@batsov.com>
Date: Wed, 6 Nov 2013 19:04:34 +0200
Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-mode-set-encoding):  
 Make encoding comment format customizable via
 `ruby-encoding-magic-comment-template'.

---
 lisp/progmodes/ruby-mode.el | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 253a600..01989f5 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -261,6 +261,10 @@ explicitly declared in magic comment."
   "Insert a magic Emacs 'coding' comment upon save if this is non-nil."
   :type 'boolean :group 'ruby)
 
+(defcustom ruby-encoding-magic-comment-template " -*- coding: %s -*-"
+  "An encoding comment template in which the actual encoding will be inserted."
+  :type 'string :group 'ruby)
+
 (defcustom ruby-use-encoding-map t
   "Use `ruby-encoding-map' to set encoding magic comment if this is non-nil."
   :type 'boolean :group 'ruby)
@@ -621,7 +625,10 @@ explicitly declared in magic comment."
                    (insert coding-system)))
                 ((looking-at "\\s *#.*coding\\s *[:=]"))
                 (t (when ruby-insert-encoding-magic-comment
-                     (insert "# -*- coding: " coding-system " -*-\n"))))
+                     (insert
+                      "#"
+                      (format ruby-encoding-magic-comment-template coding-system)
+                      "\n"))))
           (when (buffer-modified-p)
             (basic-save-buffer-1)))))))
 
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-06 17:10             ` Bozhidar Batsov
@ 2013-11-06 21:45               ` Dmitry Gutov
  2013-11-07 10:23                 ` Bozhidar Batsov
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Gutov @ 2013-11-06 21:45 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: emacs-devel

On 06.11.2013 19:10, Bozhidar Batsov wrote:
> Here's a patch for making the comment format customizable. How does it
> look to you?

There might be a problem with weird template formats a user would be 
technically allowed to choose: if the template doesn't match either of 
the regexps used in `ruby-mode-set-encoding', the coding comment will be 
added at the first line of the buffer, even if it already contains (the 
non-standard) one. Not sure if that's a real problem, but maybe we 
should relax the regexps and/or reject all non-matching templates.

Other than that, looks fine to me. Possible improvements, if you like:

1. Move "#" also inside the template. It'll make the code a bit simpler 
and get rid of the implicit requirement that the template starts with a 
space.

2. Add predefined values to the customize widget? (:type (choice ...)) 
Allow the user to choose between Emacs-style and Ruby-style.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-06 21:45               ` Dmitry Gutov
@ 2013-11-07 10:23                 ` Bozhidar Batsov
  2013-11-07 11:06                   ` Dmitry Gutov
  0 siblings, 1 reply; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-07 10:23 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

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

On 6 November 2013 23:45, Dmitry Gutov <dgutov@yandex.ru> wrote:

> On 06.11.2013 19:10, Bozhidar Batsov wrote:
>
>> Here's a patch for making the comment format customizable. How does it
>> look to you?
>>
>
> There might be a problem with weird template formats a user would be
> technically allowed to choose: if the template doesn't match either of the
> regexps used in `ruby-mode-set-encoding', the coding comment will be added
> at the first line of the buffer, even if it already contains (the
> non-standard) one. Not sure if that's a real problem, but maybe we should
> relax the regexps and/or reject all non-matching templates.
>

Yeah, I though of this, but decided we can assume that few people would run
into this and they'll probably understand their mistake pretty soon.


>
> Other than that, looks fine to me. Possible improvements, if you like:
>
> 1. Move "#" also inside the template. It'll make the code a bit simpler
> and get rid of the implicit requirement that the template starts with a
> space.
>

Actually the template should not necessary start with a space, that why I
did not put the `#` in it. A comment like #coding:utf-8 is perfectly valid
(albeit it looks kind of ugly). But yeah, might be easier for people of the
`#` was in the template itself.


>
> 2. Add predefined values to the customize widget? (:type (choice ...))
> Allow the user to choose between Emacs-style and Ruby-style.
>

Makes sense.

Btw, Dimitry - please add some info the ruby-mode.el about running the
tests. I tried evaluating and running them manually, but this crashed my
Emacs (the tests hogged my CPU completely and I had to kill Emacs). Maybe
there is something wrong with them right now, or perhaps they should
invoked in some manner I'm not aware of.

[-- Attachment #2: Type: text/html, Size: 2601 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-07 10:23                 ` Bozhidar Batsov
@ 2013-11-07 11:06                   ` Dmitry Gutov
  2013-11-13 14:36                     ` Bozhidar Batsov
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Gutov @ 2013-11-07 11:06 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: emacs-devel

On 07.11.2013 12:23, Bozhidar Batsov wrote:
> Btw, Dimitry - please add some info the ruby-mode.el about running the
> tests. I tried evaluating and running them manually, but this crashed my
> Emacs (the tests hogged my CPU completely and I had to kill Emacs).
> Maybe there is something wrong with them right now, or perhaps they
> should invoked in some manner I'm not aware of.

I'm not aware of any problems running the tests, looks like a bug. 
Weren't you able to stop the freezing with C-g, at least?

I just open ruby-mode-tests.el, M-x eval-buffer, M-x ert RET.
They run fine.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-07 11:06                   ` Dmitry Gutov
@ 2013-11-13 14:36                     ` Bozhidar Batsov
  2013-11-13 19:19                       ` Dmitry Gutov
  0 siblings, 1 reply; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-13 14:36 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 909 bytes --]

I've attached here a second patch that adds support for always inserting a
utf-8 encoding comment. I've also simplified a bit the code of
`ruby-mode-set-encoding' (by breaking it into several functions) as it was
quite convoluted.


On 7 November 2013 13:06, Dmitry Gutov <dgutov@yandex.ru> wrote:

> On 07.11.2013 12:23, Bozhidar Batsov wrote:
>
>> Btw, Dimitry - please add some info the ruby-mode.el about running the
>> tests. I tried evaluating and running them manually, but this crashed my
>> Emacs (the tests hogged my CPU completely and I had to kill Emacs).
>> Maybe there is something wrong with them right now, or perhaps they
>> should invoked in some manner I'm not aware of.
>>
>
> I'm not aware of any problems running the tests, looks like a bug. Weren't
> you able to stop the freezing with C-g, at least?
>
> I just open ruby-mode-tests.el, M-x eval-buffer, M-x ert RET.
> They run fine.
>

[-- Attachment #1.2: Type: text/html, Size: 1395 bytes --]

[-- Attachment #2: 0001-lisp-progmodes-ruby-mode.el-ruby-mode-set-encoding.patch --]
[-- Type: application/octet-stream, Size: 4700 bytes --]

From 1768305926bf60084a42ffeca913be32f6ee288e Mon Sep 17 00:00:00 2001
From: Bozhidar Batsov <bozhidar@batsov.com>
Date: Wed, 13 Nov 2013 16:31:59 +0200
Subject: [PATCH] * lisp/progmodes/ruby-mode.el (ruby-mode-set-encoding):

Add support for always inserting an utf-8 encoding comment.
---
 lisp/progmodes/ruby-mode.el | 68 ++++++++++++++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 26 deletions(-)

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 87454cd..1e8faf0 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -256,7 +256,12 @@ explicitly declared in magic comment."
   :group 'ruby)
 
 (defcustom ruby-insert-encoding-magic-comment t
-  "Insert a magic Emacs 'coding' comment upon save if this is non-nil."
+  "Insert a magic Emacs 'coding' comment upon save if this is non-nil.
+The encoding will be auto-detected.  The format of the encoding comment
+is customizable via `ruby-encoding-magic-comment-style'.
+
+When set to `always-utf8' an utf-8 comment will always be added, even if it's not
+required."
   :type 'boolean :group 'ruby)
 
 (defcustom ruby-encoding-magic-comment-style 'ruby
@@ -633,28 +638,47 @@ explicitly declared in magic comment."
   (setq-local paragraph-separate paragraph-start)
   (setq-local paragraph-ignore-fill-prefix t))
 
+(defun ruby--insert-coding-comment (encoding)
+  (let ((encoding-magic-comment-template
+         (pcase ruby-encoding-magic-comment-style
+           (`ruby "# coding: %s")
+           (`emacs "# -*- coding: %s -*-")
+           (`custom
+            ruby-custom-encoding-magic-comment-template))))
+    (insert
+     (format encoding-magic-comment-template encoding)
+     "\n")))
+
+(defun ruby--detect-encoding ()
+  (if (eq ruby-insert-encoding-magic-comment 'always-utf8)
+      "utf-8"
+    (let ((coding-system
+           (or save-buffer-coding-system
+               buffer-file-coding-system)))
+      (if coding-system
+          (setq coding-system
+                (or (coding-system-get coding-system 'mime-charset)
+                    (coding-system-change-eol-conversion coding-system nil))))
+      (if coding-system
+          (symbol-name
+           (if ruby-use-encoding-map
+               (let ((elt (assq coding-system ruby-encoding-map)))
+                 (if elt (cdr elt) coding-system))
+             coding-system))
+        "ascii-8bit"))))
+
+(defun ruby--encoding-comment-required-p ()
+  (or (re-search-forward "[^\0-\177]" nil t)
+      (eq ruby-insert-encoding-magic-comment 'always-utf8)))
+
 (defun ruby-mode-set-encoding ()
   "Insert a magic comment header with the proper encoding if necessary."
   (save-excursion
     (widen)
     (goto-char (point-min))
-    (when (re-search-forward "[^\0-\177]" nil t)
+    (when (ruby--encoding-comment-required-p)
       (goto-char (point-min))
-      (let ((coding-system
-             (or save-buffer-coding-system
-                 buffer-file-coding-system)))
-        (if coding-system
-            (setq coding-system
-                  (or (coding-system-get coding-system 'mime-charset)
-                      (coding-system-change-eol-conversion coding-system nil))))
-        (setq coding-system
-              (if coding-system
-                  (symbol-name
-                   (if ruby-use-encoding-map
-                       (let ((elt (assq coding-system ruby-encoding-map)))
-                         (if elt (cdr elt) coding-system))
-                     coding-system))
-                "ascii-8bit"))
+      (let ((coding-system (ruby--detect-encoding)))
         (when coding-system
           (if (looking-at "^#!") (beginning-of-line 2))
           (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)")
@@ -669,15 +693,7 @@ explicitly declared in magic comment."
                    (insert coding-system)))
                 ((looking-at "\\s *#.*coding\\s *[:=]"))
                 (t (when ruby-insert-encoding-magic-comment
-                     (let ((encoding-magic-comment-template
-                            (pcase ruby-encoding-magic-comment-style
-                              (`ruby "# coding: %s")
-                              (`emacs "# -*- coding: %s -*-")
-                              (`custom
-                               ruby-custom-encoding-magic-comment-template))))
-                       (insert
-                        (format encoding-magic-comment-template coding-system)
-                        "\n")))))
+                     (ruby--insert-coding-comment coding-system))))
           (when (buffer-modified-p)
             (basic-save-buffer-1)))))))
 
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-13 14:36                     ` Bozhidar Batsov
@ 2013-11-13 19:19                       ` Dmitry Gutov
  2013-11-14  9:53                         ` Bozhidar Batsov
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Gutov @ 2013-11-13 19:19 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: emacs-devel

On 13.11.2013 16:36, Bozhidar Batsov wrote:
> I've attached here a second patch that adds support for always inserting
> a utf-8 encoding comment. I've also simplified a bit the code of
> `ruby-mode-set-encoding' (by breaking it into several functions) as it
> was quite convoluted.

Looks good to me, with a couple of notes.

1. ruby-insert-encoding-magic-comment docstring width exceeds the 
default value of emacs-lisp-docstring-fill-column. Maybe you'd like to 
refill it.

2. I'd swap the `or' clauses in ruby--encoding-comment-required-p. The 
second one, though rare, should be much faster.

That aside, have you managed to run the test suite?

> On 7 November 2013 13:06, Dmitry Gutov <dgutov@yandex.ru
> <mailto:dgutov@yandex.ru>> wrote:
>
>     On 07.11.2013 12:23, Bozhidar Batsov wrote:
>
>         Btw, Dimitry - please add some info the ruby-mode.el about
>         running the
>         tests. I tried evaluating and running them manually, but this
>         crashed my
>         Emacs (the tests hogged my CPU completely and I had to kill Emacs).
>         Maybe there is something wrong with them right now, or perhaps they
>         should invoked in some manner I'm not aware of.
>
>
>     I'm not aware of any problems running the tests, looks like a bug.
>     Weren't you able to stop the freezing with C-g, at least?
>
>     I just open ruby-mode-tests.el, M-x eval-buffer, M-x ert RET.
>     They run fine.
>
>




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-13 19:19                       ` Dmitry Gutov
@ 2013-11-14  9:53                         ` Bozhidar Batsov
  2013-11-14 13:23                           ` Dmitry Gutov
  0 siblings, 1 reply; 17+ messages in thread
From: Bozhidar Batsov @ 2013-11-14  9:53 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

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

On 13 November 2013 21:19, Dmitry Gutov <dgutov@yandex.ru> wrote:

> On 13.11.2013 16:36, Bozhidar Batsov wrote:
>
>> I've attached here a second patch that adds support for always inserting
>> a utf-8 encoding comment. I've also simplified a bit the code of
>> `ruby-mode-set-encoding' (by breaking it into several functions) as it
>> was quite convoluted.
>>
>
> Looks good to me, with a couple of notes.
>
> 1. ruby-insert-encoding-magic-comment docstring width exceeds the default
> value of emacs-lisp-docstring-fill-column. Maybe you'd like to refill it.
>

Sure.


>
> 2. I'd swap the `or' clauses in ruby--encoding-comment-required-p. The
> second one, though rare, should be much faster.
>

Good point.


>
> That aside, have you managed to run the test suite?
>

Yeah, the tests started working after I updated my Emacs. I guess I had
installed a bad build. One test is failing, though:

f ruby-interpolation-inside-percent-literal-with-paren
    (ert-test-failed
     ((should
       (eq face
           (get-text-property pos 'face)))
      :form
      (eq font-lock-string-face nil)
      :value nil))


Btw, there also seems to be some bug in the output of ert - the "f" was
printed in the same colour as the passing tests. Pretty sure it shouldn't
be this way. Maybe I should report this.


>
>  On 7 November 2013 13:06, Dmitry Gutov <dgutov@yandex.ru
>> <mailto:dgutov@yandex.ru>> wrote:
>>
>>     On 07.11.2013 12:23, Bozhidar Batsov wrote:
>>
>>         Btw, Dimitry - please add some info the ruby-mode.el about
>>         running the
>>         tests. I tried evaluating and running them manually, but this
>>         crashed my
>>         Emacs (the tests hogged my CPU completely and I had to kill
>> Emacs).
>>         Maybe there is something wrong with them right now, or perhaps
>> they
>>         should invoked in some manner I'm not aware of.
>>
>>
>>     I'm not aware of any problems running the tests, looks like a bug.
>>     Weren't you able to stop the freezing with C-g, at least?
>>
>>     I just open ruby-mode-tests.el, M-x eval-buffer, M-x ert RET.
>>     They run fine.
>>
>>
>>
>

[-- Attachment #2: Type: text/html, Size: 4016 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default.
  2013-11-14  9:53                         ` Bozhidar Batsov
@ 2013-11-14 13:23                           ` Dmitry Gutov
  0 siblings, 0 replies; 17+ messages in thread
From: Dmitry Gutov @ 2013-11-14 13:23 UTC (permalink / raw)
  To: Bozhidar Batsov; +Cc: emacs-devel

On 14.11.2013 11:53, Bozhidar Batsov wrote:
> One test is failing, though:
>
> f ruby-interpolation-inside-percent-literal-with-paren
> ...
>
> Btw, there also seems to be some bug in the output of ert - the "f" was
> printed in the same colour as the passing tests. Pretty sure it
> shouldn't be this way.

It should: if you look at the test definition, you can notice the 
arguments `:expected-result :failed`.

It describes a feature that I find rather hard to implement, but worth 
remembering: arbitrary nesting of code inside interpolation blocks.



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2013-11-14 13:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-01 12:59 Subject: [PATCH] * lisp/progmodes/ruby-mode.el: Set `ruby-insert-encoding-magic-comment' to nil by default Bozhidar Batsov
2013-11-01 17:46 ` Stefan Monnier
2013-11-01 18:51   ` Bozhidar Batsov
2013-11-02  0:00 ` Dmitry Gutov
2013-11-02 10:38   ` Bozhidar Batsov
2013-11-02 20:15     ` Dmitry Gutov
2013-11-03  7:35       ` Bozhidar Batsov
2013-11-03  9:22         ` Dmitry Gutov
2013-11-04 13:40           ` Bozhidar Batsov
2013-11-06 17:10             ` Bozhidar Batsov
2013-11-06 21:45               ` Dmitry Gutov
2013-11-07 10:23                 ` Bozhidar Batsov
2013-11-07 11:06                   ` Dmitry Gutov
2013-11-13 14:36                     ` Bozhidar Batsov
2013-11-13 19:19                       ` Dmitry Gutov
2013-11-14  9:53                         ` Bozhidar Batsov
2013-11-14 13:23                           ` Dmitry Gutov

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).