all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ruby-mode : ruby-mode-set-encoding
@ 2009-03-03 13:46 Paul R
  2009-03-03 13:55 ` Leo
  0 siblings, 1 reply; 14+ messages in thread
From: Paul R @ 2009-03-03 13:46 UTC (permalink / raw
  To: emacs-devel

Hello list,

ruby mode is now part of emacs.

There is this particular function :

  (defun ruby-mode-set-encoding ()
    "Insert a magic comment header with the proper encoding if necessary."
    ...

and AFAIK only ruby mode use this type of thing. It is added to saving
functions hooks :

  (add-hook
   (cond ((boundp 'before-save-hook)
          (make-local-variable 'before-save-hook)
          'before-save-hook)
         ((boundp 'write-contents-functions) 'write-contents-functions)
         ((boundp 'write-contents-hooks) 'write-contents-hooks))
   'ruby-mode-set-encoding)

I am not sure what the usecase is for this function but it writes
useless cookies in the headers of my ruby files whenever they contain
something else that ascii chars. Reading the code, it seems that the
definition of "necessary" is not very clear.

Does anybody know why this is necessary please ? If it is really
required, I would suggest to add a customizable variable to disable this
magic behaviour.

thanks,

-- 
  Paul




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-03 13:46 ruby-mode : ruby-mode-set-encoding Paul R
@ 2009-03-03 13:55 ` Leo
  2009-03-03 16:30   ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Leo @ 2009-03-03 13:55 UTC (permalink / raw
  To: emacs-devel

On 2009-03-03 13:46 +0000, Paul R wrote:
>   (defun ruby-mode-set-encoding ()
>     "Insert a magic comment header with the proper encoding if necessary."
>     ...
>
> and AFAIK only ruby mode use this type of thing. It is added to saving
> functions hooks :
>
>   (add-hook
>    (cond ((boundp 'before-save-hook)
>           (make-local-variable 'before-save-hook)
>           'before-save-hook)
>          ((boundp 'write-contents-functions) 'write-contents-functions)
>          ((boundp 'write-contents-hooks) 'write-contents-hooks))
>    'ruby-mode-set-encoding)

I agree. I think this is just too intrusive. Fortunately, I don't use
ruby.

-- 
.:  Leo  :.  [ sdl.web AT gmail.com ]  .: I use Emacs :.





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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-03 13:55 ` Leo
@ 2009-03-03 16:30   ` Stefan Monnier
  2009-03-04  0:23     ` Nobuyoshi Nakada
  0 siblings, 1 reply; 14+ messages in thread
From: Stefan Monnier @ 2009-03-03 16:30 UTC (permalink / raw
  To: nobu, Leo; +Cc: emacs-devel

>> (defun ruby-mode-set-encoding ()
>> "Insert a magic comment header with the proper encoding if necessary."
>> ...
>> 
>> and AFAIK only ruby mode use this type of thing. It is added to saving
>> functions hooks :
>> 
>> (add-hook
>> (cond ((boundp 'before-save-hook)
>> (make-local-variable 'before-save-hook)
>> 'before-save-hook)
>> ((boundp 'write-contents-functions) 'write-contents-functions)
>> ((boundp 'write-contents-hooks) 'write-contents-hooks))
>> 'ruby-mode-set-encoding)

> I agree. I think this is just too intrusive. Fortunately, I don't use ruby.

I don't know if it's too intrusive, but it seems unrelated to Ruby.
Nobuyoshi Nakada, looking at the history of ruby-mode.el at
http://svn.ruby-lang.org/repos/ruby/trunk/misc, it appears the change is
due to you, could you explain what this is intended to do?
If it's not specific to Ruby, then maybe it should be moved elsewhere.


        Stefan




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-03 16:30   ` Stefan Monnier
@ 2009-03-04  0:23     ` Nobuyoshi Nakada
  2009-03-04  1:14       ` Stefan Monnier
  2009-03-04  8:25       ` Paul R
  0 siblings, 2 replies; 14+ messages in thread
From: Nobuyoshi Nakada @ 2009-03-04  0:23 UTC (permalink / raw
  To: Stefan Monnier; +Cc: emacs-devel, nobu, Leo

Hi,

At Tue, 03 Mar 2009 11:30:51 -0500,
Stefan Monnier wrote:
> I don't know if it's too intrusive, but it seems unrelated to Ruby.
> Nobuyoshi Nakada, looking at the history of ruby-mode.el at
> http://svn.ruby-lang.org/repos/ruby/trunk/misc, it appears the change is
> due to you, could you explain what this is intended to do?
> If it's not specific to Ruby, then maybe it should be moved elsewhere.

It's mandatory for Ruby 1.9 or later.  Ruby 1.9 needs that
"magic comment" to know in what encoding a script is written.
Otherwise, the script is assumed as written with ASCII 7bit
characters only, and non-ASCII character causes an exception if
exists.

Could you elaborate the problem?

-- 
Nobu Nakada




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04  0:23     ` Nobuyoshi Nakada
@ 2009-03-04  1:14       ` Stefan Monnier
  2009-03-04  2:05         ` Stephen J. Turnbull
  2009-03-04  8:25       ` Paul R
  1 sibling, 1 reply; 14+ messages in thread
From: Stefan Monnier @ 2009-03-04  1:14 UTC (permalink / raw
  To: Nobuyoshi Nakada; +Cc: Leo, emacs-devel

>> I don't know if it's too intrusive, but it seems unrelated to Ruby.
>> Nobuyoshi Nakada, looking at the history of ruby-mode.el at
>> http://svn.ruby-lang.org/repos/ruby/trunk/misc, it appears the change is
>> due to you, could you explain what this is intended to do?
>> If it's not specific to Ruby, then maybe it should be moved elsewhere.

> It's mandatory for Ruby 1.9 or later.  Ruby 1.9 needs that
> "magic comment" to know in what encoding a script is written.
> Otherwise, the script is assumed as written with ASCII 7bit
> characters only, and non-ASCII character causes an exception if
> exists.

> Could you elaborate the problem?

So you're saying that Ruby uses the same "-*- coding: <foo> -*-" as used
by Emacs?  That makes sense, then, thank you,


        Stefan






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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04  1:14       ` Stefan Monnier
@ 2009-03-04  2:05         ` Stephen J. Turnbull
  2009-03-04  4:07           ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen J. Turnbull @ 2009-03-04  2:05 UTC (permalink / raw
  To: Stefan Monnier; +Cc: emacs-devel, Nobuyoshi Nakada, Leo

Stefan Monnier writes:

 > So you're saying that Ruby uses the same "-*- coding: <foo> -*-" as used
 > by Emacs?  That makes sense, then, thank you,

As does Python, and it is mandatory in Python for non-ASCII IIRC.  See
PEP 263 for details.  AFAIK Python modes don't try to enforce it
(yet), but they might in the future, for the same reasons that
ruby-mode does.

This should be considered equivalent to an encoding declaration in an
XML fragment.





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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04  2:05         ` Stephen J. Turnbull
@ 2009-03-04  4:07           ` Stefan Monnier
  2009-03-04  6:10             ` Stephen J. Turnbull
  0 siblings, 1 reply; 14+ messages in thread
From: Stefan Monnier @ 2009-03-04  4:07 UTC (permalink / raw
  To: Stephen J. Turnbull; +Cc: emacs-devel, Nobuyoshi Nakada, Leo

>> So you're saying that Ruby uses the same "-*- coding: <foo> -*-" as used
>> by Emacs?  That makes sense, then, thank you,

> As does Python, and it is mandatory in Python for non-ASCII IIRC.  See
> PEP 263 for details.  AFAIK Python modes don't try to enforce it
> (yet), but they might in the future, for the same reasons that
> ruby-mode does.

Interesting.  Why don't they just force the use of some arbitrarily
chosen variant of Unicode?


        Stefan




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04  4:07           ` Stefan Monnier
@ 2009-03-04  6:10             ` Stephen J. Turnbull
  2009-03-04 14:10               ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen J. Turnbull @ 2009-03-04  6:10 UTC (permalink / raw
  To: Stefan Monnier; +Cc: Leo, Nobuyoshi Nakada, emacs-devel

Stefan Monnier writes:

 > Interesting.  Why don't they just force the use of some arbitrarily
 > chosen variant of Unicode?

To avoid "arbitrarily" breaking software systems and development
environments that target other character sets.

Specifically, you can automatically add an all-ASCII comment
containing a coding cookie to every Python source file without
breaking anything anywhere.  You cannot simply run all files through
recode, as that will break strings that display on legacy terminals or
have been interned in databases.




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04  0:23     ` Nobuyoshi Nakada
  2009-03-04  1:14       ` Stefan Monnier
@ 2009-03-04  8:25       ` Paul R
  2009-03-04 14:13         ` Stefan Monnier
  2009-03-04 14:56         ` Nobuyoshi Nakada
  1 sibling, 2 replies; 14+ messages in thread
From: Paul R @ 2009-03-04  8:25 UTC (permalink / raw
  To: Nobuyoshi Nakada; +Cc: emacs-devel

Hello Nobuyoshi,

Nobuyoshi> It's mandatory for Ruby 1.9 or later. Ruby 1.9 needs that
Nobuyoshi> "magic comment" to know in what encoding a script is written.
Nobuyoshi> Otherwise, the script is assumed as written with ASCII 7bit
Nobuyoshi> characters only, and non-ASCII character causes an exception
Nobuyoshi> if exists.

Fine, I did not relate it to 1.9 (that was recently released) because
I have seen this behaviour for monthes. I think the reason is that I was
using the svn version of ruby-mode.el. After reading the doc, it is
clear and I see indeed why now ruby wants to know file encoding before
parsing it.

Nobuyoshi> Could you elaborate the problem?

The problem simply was that I did not expect this behaviour, and did not
understand the motivation behind it.

Somebody mentionned some similarities with python. Should emacs provide
a standard mechanism to insert this tag for script language modes that
need it ?

Thanks,

-- 
  Paul




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04  6:10             ` Stephen J. Turnbull
@ 2009-03-04 14:10               ` Stefan Monnier
  2009-03-04 15:07                 ` Stephen J. Turnbull
  0 siblings, 1 reply; 14+ messages in thread
From: Stefan Monnier @ 2009-03-04 14:10 UTC (permalink / raw
  To: Stephen J. Turnbull; +Cc: Leo, Nobuyoshi Nakada, emacs-devel

>> Interesting.  Why don't they just force the use of some arbitrarily
>> chosen variant of Unicode?
> To avoid "arbitrarily" breaking software systems and development
> environments that target other character sets.

Sorry, I meant "didn't" instead of "don't": these are recent programming
languages, and since Java was able to do it why couldn't Python do it?

> You cannot simply run all files through recode, as that will break
> strings that display on legacy terminals or have been interned
> in databases.

Nice theoretical problem, but I think that Java proves it to be
a non-issue in practice.  Anyway, it's too late now,


        Stefan




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04  8:25       ` Paul R
@ 2009-03-04 14:13         ` Stefan Monnier
  2009-03-04 14:56         ` Nobuyoshi Nakada
  1 sibling, 0 replies; 14+ messages in thread
From: Stefan Monnier @ 2009-03-04 14:13 UTC (permalink / raw
  To: Paul R; +Cc: Nobuyoshi Nakada, emacs-devel

> Somebody mentionned some similarities with python.  Should emacs
> provide a standard mechanism to insert this tag for script language
> modes that need it ?

Don't know about "emacs", but yes, Emacs could provide some help here,
mostly in the form of a function that returns a "good" coding-system
name to put in the tag.


        Stefan




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04  8:25       ` Paul R
  2009-03-04 14:13         ` Stefan Monnier
@ 2009-03-04 14:56         ` Nobuyoshi Nakada
  1 sibling, 0 replies; 14+ messages in thread
From: Nobuyoshi Nakada @ 2009-03-04 14:56 UTC (permalink / raw
  To: Paul R; +Cc: Nobuyoshi Nakada, emacs-devel

Hi,

At Wed, 04 Mar 2009 09:25:24 +0100,
Paul R wrote:
> Somebody mentionned some similarities with python. Should emacs provide
> a standard mechanism to insert this tag for script language modes that
> need it ?

It would be nice, however:

1. Ruby also recognizes Vim style magic comment, such as
   "encoding=utf-8", not only Emacs style.

2. we need ruby-encoding-map because of the difference between
   Ruby's encoding names list and Emacses one.  For instance,
   ruby-mode.el uses CP932 instead of Shift_JIS, since pure
   Shift_JIS is hardly used actually.

-- 
Nobu Nakada




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04 14:10               ` Stefan Monnier
@ 2009-03-04 15:07                 ` Stephen J. Turnbull
  2009-03-04 16:40                   ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen J. Turnbull @ 2009-03-04 15:07 UTC (permalink / raw
  To: Stefan Monnier; +Cc: emacs-devel, Leo, Nobuyoshi Nakada

Stefan Monnier writes:

 > > To avoid "arbitrarily" breaking software systems and development
 > > environments that target other character sets.
 > 
 > Sorry, I meant "didn't" instead of "don't": these are recent programming
 > languages, and since Java was able to do it why couldn't Python do it?

You're showing your age, Stefan, to call these "recent" programming
languages!  And I think your memory may be going, because IIRC Java
did nothing of the kind.  Java supported only Unicode from the get-go
IIRC.  So in that respect Java had no backward compatibility problem.
Python started earlier, when "8-bit clean" code was considered a major
advance and it wasn't clear that Unicode was going to beat ISO 2022.

 > Nice theoretical problem, but I think that Java proves it to be
 > a non-issue in practice.  Anyway, it's too late now,

Actually, the theoretical people (including me) were all in favor of
the One True Encoding approach.  It was the practical people (ie,
people who earn their living programming in Python) who shot it down.




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

* Re: ruby-mode : ruby-mode-set-encoding
  2009-03-04 15:07                 ` Stephen J. Turnbull
@ 2009-03-04 16:40                   ` Stefan Monnier
  0 siblings, 0 replies; 14+ messages in thread
From: Stefan Monnier @ 2009-03-04 16:40 UTC (permalink / raw
  To: Stephen J. Turnbull; +Cc: emacs-devel, Leo, Nobuyoshi Nakada

>> > To avoid "arbitrarily" breaking software systems and development
>> > environments that target other character sets.
>> Sorry, I meant "didn't" instead of "don't": these are recent programming
>> languages, and since Java was able to do it why couldn't Python do it?

> You're showing your age, Stefan, to call these "recent" programming
> languages!  And I think your memory may be going, because IIRC Java
> did nothing of the kind.

My memory isn't completely gone, it seems, since what I meant was indeed:

> Java supported only Unicode from the get-go IIRC.

But indeed, it is on the way out because I thought Java predated Python,
whereas it's the other way around.  This explains that.
OTOH Ruby came out pretty much at the same time as Java, so they clearly
could have done the same as Java, tho its Japanese connection might
explain that Unicode didn't seem like such a great idea to them at
the time.


        Stefan




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

end of thread, other threads:[~2009-03-04 16:40 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-03 13:46 ruby-mode : ruby-mode-set-encoding Paul R
2009-03-03 13:55 ` Leo
2009-03-03 16:30   ` Stefan Monnier
2009-03-04  0:23     ` Nobuyoshi Nakada
2009-03-04  1:14       ` Stefan Monnier
2009-03-04  2:05         ` Stephen J. Turnbull
2009-03-04  4:07           ` Stefan Monnier
2009-03-04  6:10             ` Stephen J. Turnbull
2009-03-04 14:10               ` Stefan Monnier
2009-03-04 15:07                 ` Stephen J. Turnbull
2009-03-04 16:40                   ` Stefan Monnier
2009-03-04  8:25       ` Paul R
2009-03-04 14:13         ` Stefan Monnier
2009-03-04 14:56         ` Nobuyoshi Nakada

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.