diff options
author | Dmitry Gutov <dgutov@yandex.ru> | 2013-10-05 20:21:22 +0300 |
---|---|---|
committer | Dmitry Gutov <dgutov@yandex.ru> | 2013-10-05 20:21:22 +0300 |
commit | aa0214dae5260f7523fc6d0aa0ca94eb5f46e09b (patch) | |
tree | 6755badc6dc91a50e4359a1ebb6c6e6e1ace6acc | |
parent | 544a2a8049b9f1660134e1868a32c9e829d3c952 (diff) | |
download | emacs-aa0214dae5260f7523fc6d0aa0ca94eb5f46e09b.tar.gz |
Revert 2013-10-05T02:26:39Z!dgutov@yandex.ru
`last-coding-system-used' is unreliable: it can be modified by other functions
in `after-save-hook'.
-rw-r--r-- | lisp/ChangeLog | 8 | ||||
-rw-r--r-- | lisp/progmodes/ruby-mode.el | 28 |
2 files changed, 18 insertions, 18 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0b617f8ed0f..e3ca8751535 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -3,14 +3,6 @@ * progmodes/octave.el (octave-send-region): Call compilation-forget-errors. -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): diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 8abf8fedefb..95206c15390 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -450,13 +450,19 @@ 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-get last-coding-system-used 'mime-charset) - (coding-system-change-eol-conversion ast-coding-system-used - nil)))) + (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)))) (setq coding-system - (symbol-name (or (and ruby-use-encoding-map - (cdr (assq coding-system ruby-encoding-map))) - coding-system))) + (if coding-system + (symbol-name + (or (and ruby-use-encoding-map + (cdr (assq coding-system ruby-encoding-map))) + 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) @@ -470,9 +476,7 @@ 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")))) - (when (buffer-modified-p) - (basic-save-buffer-1)))))) + (insert "# -*- coding: " coding-system " -*-\n")))))))) (defun ruby-current-indentation () "Return the indentation level of current line." @@ -1930,7 +1934,11 @@ The variable `ruby-indent-level' controls the amount of indentation. (set (make-local-variable 'end-of-defun-function) 'ruby-end-of-defun) - (add-hook 'after-save-hook 'ruby-mode-set-encoding nil 'local) + (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) (set (make-local-variable 'electric-indent-chars) (append '(?\{ ?\}) electric-indent-chars)) |