emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114654: * progmodes/ruby-mode.el (ruby-encoding-map


From: Dmitry Gutov
Subject: [Emacs-diffs] trunk r114654: * progmodes/ruby-mode.el (ruby-encoding-map): Add a mapping from
Date: Mon, 14 Oct 2013 00:23:36 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114654
revision-id: address@hidden
parent: address@hidden
author: Akinori MUSHA  <address@hidden>
committer: Dmitry Gutov <address@hidden>
branch nick: trunk
timestamp: Mon 2013-10-14 03:23:29 +0300
message:
  * progmodes/ruby-mode.el (ruby-encoding-map): Add a mapping from
  `japanese-cp932' to `cp932' to fix the problem where saving a
  source file written in Shift_JIS twice would end up having
  `coding: japanese-cp932' which Ruby could not recognize.
  (ruby-mode-set-encoding): Add support for encodings mapped to nil
  in `ruby-encoding-map'.
  (ruby-encoding-map): Map `us-ascii' to nil by default, meaning it
  doesn't need to be explicitly declared in magic comment.
  (ruby-encoding-map): Add type declaration for better customize UI.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/ruby-mode.el    
rubymode.el-20091113204419-o5vbwnq5f7feedwu-8804
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-10-13 23:21:56 +0000
+++ b/lisp/ChangeLog    2013-10-14 00:23:29 +0000
@@ -1,3 +1,15 @@
+2013-10-14  Akinori MUSHA  <address@hidden>
+
+       * progmodes/ruby-mode.el (ruby-encoding-map): Add a mapping from
+       `japanese-cp932' to `cp932' to fix the problem where saving a
+       source file written in Shift_JIS twice would end up having
+       `coding: japanese-cp932' which Ruby could not recognize.
+       (ruby-mode-set-encoding): Add support for encodings mapped to nil
+       in `ruby-encoding-map'.
+       (ruby-encoding-map): Map `us-ascii' to nil by default, meaning it
+       doesn't need to be explicitly declared in magic comment.
+       (ruby-encoding-map): Add type declaration for better customize UI.
+
 2013-10-13  Glenn Morris  <address@hidden>
 
        * progmodes/sh-script.el (sh-mark-line, sh-learn-buffer-indent):
@@ -54,7 +66,7 @@
 2013-10-12  Stefan Monnier  <address@hidden>
 
        * progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for paren-free
-       method calls (bug#bug#15594).
+       method calls (bug#15594).
        (ruby-smie--args-separator-p): New function.
        (ruby-smie--forward-token, ruby-smie--backward-token): Use it to
        recognize paren-free method calls.

=== modified file 'lisp/progmodes/ruby-mode.el'
--- a/lisp/progmodes/ruby-mode.el       2013-10-13 21:35:31 +0000
+++ b/lisp/progmodes/ruby-mode.el       2013-10-14 00:23:29 +0000
@@ -217,8 +217,15 @@
   "Default deep indent style."
   :options '(t nil space) :group 'ruby)
 
-(defcustom ruby-encoding-map '((shift_jis . cp932) (shift-jis . cp932))
-  "Alist to map encoding name from Emacs to Ruby."
+(defcustom ruby-encoding-map
+  '((us-ascii       . nil)       ;; Do not put coding: us-ascii
+    (shift-jis      . cp932)     ;; Emacs charset name of Shift_JIS
+    (shift_jis      . cp932)     ;; MIME charset name of Shift_JIS
+    (japanese-cp932 . cp932))    ;; Emacs charset name of CP932
+  "Alist to map encoding name from Emacs to Ruby.
+Associating an encoding name with nil means it needs not be
+explicitly declared in magic comment."
+  :type '(repeat (cons (symbol :tag "From") (symbol :tag "To")))
   :group 'ruby)
 
 (defcustom ruby-insert-encoding-magic-comment t
@@ -538,26 +545,28 @@
         (setq coding-system
               (if coding-system
                   (symbol-name
-                   (or (and ruby-use-encoding-map
-                            (cdr (assq coding-system ruby-encoding-map)))
-                       coding-system))
+                   (if ruby-use-encoding-map
+                       (let ((elt (assq coding-system ruby-encoding-map)))
+                         (if elt (cdr elt) coding-system))
+                     coding-system))
                 "ascii-8bit"))
-        (if (looking-at "^#!") (beginning-of-line 2))
-        (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s 
*\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)")
-               (unless (string= (match-string 2) coding-system)
-                 (goto-char (match-beginning 2))
-                 (delete-region (point) (match-end 2))
-                 (and (looking-at "-\*-")
-                      (let ((n (skip-chars-backward " ")))
-                        (cond ((= n 0) (insert "  ") (backward-char))
-                              ((= n -1) (insert " "))
-                              ((forward-char)))))
-                 (insert coding-system)))
-              ((looking-at "\\s *#.*coding\\s *[:=]"))
-              (t (when ruby-insert-encoding-magic-comment
-                   (insert "# -*- coding: " coding-system " -*-\n"))))
-        (when (buffer-modified-p)
-          (basic-save-buffer-1))))))
+        (when coding-system
+          (if (looking-at "^#!") (beginning-of-line 2))
+          (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s 
*\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)")
+                 (unless (string= (match-string 2) coding-system)
+                   (goto-char (match-beginning 2))
+                   (delete-region (point) (match-end 2))
+                   (and (looking-at "-\*-")
+                        (let ((n (skip-chars-backward " ")))
+                          (cond ((= n 0) (insert "  ") (backward-char))
+                                ((= n -1) (insert " "))
+                                ((forward-char)))))
+                   (insert coding-system)))
+                ((looking-at "\\s *#.*coding\\s *[:=]"))
+                (t (when ruby-insert-encoding-magic-comment
+                     (insert "# -*- coding: " coding-system " -*-\n"))))
+          (when (buffer-modified-p)
+            (basic-save-buffer-1)))))))
 
 (defun ruby-current-indentation ()
   "Return the indentation level of current line."


reply via email to

[Prev in Thread] Current Thread [Next in Thread]