]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/ruby-mode.el (ruby-mode): Add `ruby-mode-set-encoding'
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Oct 2013 02:26:39 +0000 (05:26 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Oct 2013 02:26:39 +0000 (05:26 +0300)
to `after-save-hook' instead of `before-save-hook', because then
we know exactly what encoding was used to write the file.
(ruby-mode-set-encoding): Use `last-coding-system-used' instead of
guessing.  Call `basic-save-buffer-1' after modifying the buffer.

lisp/ChangeLog
lisp/progmodes/ruby-mode.el

index 427c7394bfff26946b2933c9f69c8a5c6416a701..a31ceec74a85bf3c0fe2da3b59f5e77daeeb1f3e 100644 (file)
@@ -1,3 +1,11 @@
+2013-10-05  Dmitry Gutov  <dgutov@yandex.ru>
+
+       * progmodes/ruby-mode.el (ruby-mode): Add `ruby-mode-set-encoding'
+       to `after-save-hook' instead of `before-save-hook', because then
+       we know exactly what encoding was used to write the file.
+       (ruby-mode-set-encoding): Use `last-coding-system-used' instead of
+       guessing.  Call `basic-save-buffer-1' after modifying the buffer.
+
 2013-10-04  Xue Fuqiao  <xfq.free@gmail.com>
 
        * vc/vc-svn.el (vc-svn-find-admin-dir):
index 95206c153901f8fe9867be2162ea83a02c3f120c..8abf8fedefb6b838902c1083ddc7e14be06090bf 100644 (file)
@@ -450,19 +450,13 @@ Also ignores spaces after parenthesis when 'space."
     (when (re-search-forward "[^\0-\177]" nil t)
       (goto-char (point-min))
       (let ((coding-system
-             (or coding-system-for-write
-                 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))))
+             (or (coding-system-get last-coding-system-used 'mime-charset)
+                 (coding-system-change-eol-conversion ast-coding-system-used
+                                                      nil))))
         (setq coding-system
-              (if coding-system
-                  (symbol-name
-                   (or (and ruby-use-encoding-map
-                            (cdr (assq coding-system ruby-encoding-map)))
-                       coding-system))
-                "ascii-8bit"))
+              (symbol-name (or (and ruby-use-encoding-map
+                                    (cdr (assq coding-system ruby-encoding-map)))
+                               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)
@@ -476,7 +470,9 @@ Also ignores spaces after parenthesis when 'space."
                  (insert coding-system)))
               ((looking-at "\\s *#.*coding\\s *[:=]"))
               (t (when ruby-insert-encoding-magic-comment
-                   (insert "# -*- coding: " coding-system " -*-\n"))))))))
+                   (insert "# -*- coding: " coding-system " -*-\n"))))
+        (when (buffer-modified-p)
+          (basic-save-buffer-1))))))
 
 (defun ruby-current-indentation ()
   "Return the indentation level of current line."
@@ -1934,11 +1930,7 @@ The variable `ruby-indent-level' controls the amount of indentation.
   (set (make-local-variable 'end-of-defun-function)
        'ruby-end-of-defun)
 
-  (add-hook
-   (cond ((boundp 'before-save-hook) 'before-save-hook)
-         ((boundp 'write-contents-functions) 'write-contents-functions)
-         ((boundp 'write-contents-hooks) 'write-contents-hooks))
-   'ruby-mode-set-encoding nil 'local)
+  (add-hook 'after-save-hook 'ruby-mode-set-encoding nil 'local)
 
   (set (make-local-variable 'electric-indent-chars)
        (append '(?\{ ?\}) electric-indent-chars))