unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: [Emacs-diffs] trunk r114533: Revert 114527
       [not found] <E1VSVZF-0008Rg-4r@vcs.savannah.gnu.org>
@ 2013-10-05 18:43 ` Stefan Monnier
  2013-10-05 18:52   ` Dmitry Gutov
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2013-10-05 18:43 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

> `last-coding-system-used' is unreliable: it can be modified by other
> functions in `after-save-hook'.

Indeed.  Why not use buffer-file-coding-system?


        Stefan



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

* Re: [Emacs-diffs] trunk r114533: Revert 114527
  2013-10-05 18:43 ` [Emacs-diffs] trunk r114533: Revert 114527 Stefan Monnier
@ 2013-10-05 18:52   ` Dmitry Gutov
  2013-10-05 19:02     ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Gutov @ 2013-10-05 18:52 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 05.10.2013 21:43, Stefan Monnier wrote:
>> `last-coding-system-used' is unreliable: it can be modified by other
>> functions in `after-save-hook'.
>
> Indeed.  Why not use buffer-file-coding-system?

Because its value doesn't change (from the initial `undecided-unix') 
even after the buffer is saved with new, non-ASCII characters.

Should this be considered a bug?

So far I've decided to use `select-safe-coding-system-function', but it 
just adds to the mess:

=== modified file 'lisp/progmodes/ruby-mode.el'
--- lisp/progmodes/ruby-mode.el	2013-10-05 17:21:22 +0000
+++ lisp/progmodes/ruby-mode.el	2013-10-05 18:49:48 +0000
@@ -452,6 +452,9 @@
        (let ((coding-system
               (or coding-system-for-write
                   buffer-file-coding-system)))
+        (when (string-match-p "\\`undecided-" (symbol-name coding-system))
+          (setq coding-system (funcall select-safe-coding-system-function
+                                       (point-min) (point-max) nil 
#'identity)))
          (if coding-system
              (setq coding-system
                    (or (coding-system-get coding-system 'mime-charset)





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

* Re: [Emacs-diffs] trunk r114533: Revert 114527
  2013-10-05 18:52   ` Dmitry Gutov
@ 2013-10-05 19:02     ` Eli Zaretskii
  2013-10-05 19:16       ` Dmitry Gutov
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2013-10-05 19:02 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: monnier, emacs-devel

> Date: Sat, 05 Oct 2013 21:52:14 +0300
> From: Dmitry Gutov <dgutov@yandex.ru>
> Cc: emacs-devel@gnu.org
> 
> On 05.10.2013 21:43, Stefan Monnier wrote:
> >> `last-coding-system-used' is unreliable: it can be modified by other
> >> functions in `after-save-hook'.
> >
> > Indeed.  Why not use buffer-file-coding-system?
> 
> Because its value doesn't change (from the initial `undecided-unix') 
> even after the buffer is saved with new, non-ASCII characters.

Didn't Emacs asked you to select an encoding when you saved?  Also,
what were the non-ASCII characters, and what is your
default-buffer-file-coding-system?

> So far I've decided to use `select-safe-coding-system-function', but it 
> just adds to the mess:

Please describe the issue from the beginning, I cannot find it in the
mailing list archives.  It's hard to judge the solution without
knowing the details of the problem.



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

* Re: [Emacs-diffs] trunk r114533: Revert 114527
  2013-10-05 19:02     ` Eli Zaretskii
@ 2013-10-05 19:16       ` Dmitry Gutov
  2013-10-05 19:38         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Gutov @ 2013-10-05 19:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: monnier, emacs-devel

On 05.10.2013 22:02, Eli Zaretskii wrote:
>> Because its value doesn't change (from the initial `undecided-unix')
>> even after the buffer is saved with new, non-ASCII characters.
>
> Didn't Emacs asked you to select an encoding when you saved?

Nope, it saves the file correctly automatically.

> Also, what were the non-ASCII characters,

Some cyrillic characters, for example: фывапролд

 > and what is your
> default-buffer-file-coding-system?

utf-8-unix

>> So far I've decided to use `select-safe-coding-system-function', but it
>> just adds to the mess:
>
> Please describe the issue from the beginning, I cannot find it in the
> mailing list archives.  It's hard to judge the solution without
> knowing the details of the problem.

Sorry, at first I thought I had the solution (with 
last-coding-system-used), so I didn't start the discussion.

Scenario:

1. Open an .rb file, written in ASCII (buffer-file-coding-system will be 
undecided-unix).
2. Switch to the Russian layout (usually that happens by accident, but 
sometimes even on purpose, according to my colleagues), type some text 
in Russian, press `C-x C-s'.
3. The file is saved fine, but buffer-file-coding-system is still 
undecided-unix. And `ruby-mode-set-encoding', from before-save-hook, has 
inserted `# coding: undecided' at the beginning of the file.

If I kill the buffer, then open the file again, 
buffer-file-coding-system is now utf-8-unix. If I make a modification 
and save the buffer now, the first line is changed to the correct `# -*- 
coding: utf-8 -*-'.



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

* Re: [Emacs-diffs] trunk r114533: Revert 114527
  2013-10-05 19:16       ` Dmitry Gutov
@ 2013-10-05 19:38         ` Eli Zaretskii
  2013-10-05 20:03           ` Dmitry Gutov
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2013-10-05 19:38 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: monnier, emacs-devel

> Date: Sat, 05 Oct 2013 22:16:36 +0300
> From: Dmitry Gutov <dgutov@yandex.ru>
> CC: monnier@iro.umontreal.ca, emacs-devel@gnu.org
> 
> If I kill the buffer, then open the file again, 
> buffer-file-coding-system is now utf-8-unix. If I make a modification 
> and save the buffer now, the first line is changed to the correct `# -*- 
> coding: utf-8 -*-'.

"Changed"?  You mean, there was an existing coding: cookie in the file
before you typed the cyrillic characters?  If so, what did that
original coding cookie say?

Also, do you see the same behavior with Emacs 24.3?

I think it is OK to silently save the buffer with UTF-8, if that's
your default, but the value of buffer-file-coding-system should in
that case change to UTF-8.



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

* Re: [Emacs-diffs] trunk r114533: Revert 114527
  2013-10-05 19:38         ` Eli Zaretskii
@ 2013-10-05 20:03           ` Dmitry Gutov
  2013-10-06  2:40             ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Gutov @ 2013-10-05 20:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: monnier, emacs-devel

On 05.10.2013 22:38, Eli Zaretskii wrote:
>> Date: Sat, 05 Oct 2013 22:16:36 +0300
>> From: Dmitry Gutov <dgutov@yandex.ru>
>> CC: monnier@iro.umontreal.ca, emacs-devel@gnu.org
>>
>> If I kill the buffer, then open the file again,
>> buffer-file-coding-system is now utf-8-unix. If I make a modification
>> and save the buffer now, the first line is changed to the correct `# -*-
>> coding: utf-8 -*-'.
>
> "Changed"?  You mean, there was an existing coding: cookie in the file
> before you typed the cyrillic characters?  If so, what did that
> original coding cookie say?

No, that's a continuation of the scenario. That's what happens if I kill 
the modified buffer with the newly-added `# coding: undecided`, and then 
reopen it.

The presence of the `# coding' line is not particularly important. The 
fact that the file has some cyrillic characters in it, however, makes 
the buffer open with buffer-file-coding-system `utf-8-unix'.

> Also, do you see the same behavior with Emacs 24.3?

Yes and no. The `ruby-mode-set-encoding' bug is there, because it uses 
`before-save-hook', but `buffer-file-coding-system' does change after 
the buffer is saved, in accordance with your preference below.

So I don't need to kill and reopen the buffer. Just making another 
change and saving sets `coding:` comment to the right value (as long as 
the second change leaves at least some non-ASCII characters in the buffer).

> I think it is OK to silently save the buffer with UTF-8, if that's
> your default, but the value of buffer-file-coding-system should in
> that case change to UTF-8.

Should I file a bug, or..?



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

* Re: [Emacs-diffs] trunk r114533: Revert 114527
  2013-10-05 20:03           ` Dmitry Gutov
@ 2013-10-06  2:40             ` Eli Zaretskii
  2013-10-06  2:44               ` Dmitry Gutov
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2013-10-06  2:40 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: monnier, emacs-devel

> Date: Sat, 05 Oct 2013 23:03:14 +0300
> From: Dmitry Gutov <dgutov@yandex.ru>
> CC: monnier@iro.umontreal.ca, emacs-devel@gnu.org
> 
> The presence of the `# coding' line is not particularly important.

You are wrong, the presence of the cookie changes a lot how encoding
and decoding works.  So it is very important.

> Should I file a bug, or..?

Yes, but please include a test case starting with "emacs -Q" and a
file that initially has only ASCII characters, and no 'coding'
cookies.  Also, please keep the ruby mode out of the scenario (unless
then the problem goes away).

Thanks.



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

* Re: [Emacs-diffs] trunk r114533: Revert 114527
  2013-10-06  2:40             ` Eli Zaretskii
@ 2013-10-06  2:44               ` Dmitry Gutov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Gutov @ 2013-10-06  2:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

On 06.10.2013 05:40, Eli Zaretskii wrote:
>> Date: Sat, 05 Oct 2013 23:03:14 +0300
>> From: Dmitry Gutov <dgutov@yandex.ru>
>> CC: monnier@iro.umontreal.ca, emacs-devel@gnu.org
>>
>> The presence of the `# coding' line is not particularly important.
>
> You are wrong, the presence of the cookie changes a lot how encoding
> and decoding works.  So it is very important.

I mean, in this case. `# coding: undecided' doesn't change anything if 
the file contains actual non-ASCII characters.

>> Should I file a bug, or..?
>
> Yes, but please include a test case starting with "emacs -Q" and a
> file that initially has only ASCII characters, and no 'coding'
> cookies.  Also, please keep the ruby mode out of the scenario (unless
> then the problem goes away).

Here you go: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15535#8




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

end of thread, other threads:[~2013-10-06  2:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <E1VSVZF-0008Rg-4r@vcs.savannah.gnu.org>
2013-10-05 18:43 ` [Emacs-diffs] trunk r114533: Revert 114527 Stefan Monnier
2013-10-05 18:52   ` Dmitry Gutov
2013-10-05 19:02     ` Eli Zaretskii
2013-10-05 19:16       ` Dmitry Gutov
2013-10-05 19:38         ` Eli Zaretskii
2013-10-05 20:03           ` Dmitry Gutov
2013-10-06  2:40             ` Eli Zaretskii
2013-10-06  2:44               ` 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).