From: Dmitry Gutov Date: Sun, 13 Oct 2013 21:35:31 +0000 (+0300) Subject: * lisp/progmodes/ruby-mode.el (ruby-mode): Add `ruby-mode-set-encoding' X-Git-Url: http://git.hcoop.net/bpt/emacs.git/commitdiff_plain/a9ba094b81d899218e8762a66377b2fe71274d35 * lisp/progmodes/ruby-mode.el (ruby-mode): Add `ruby-mode-set-encoding' to `after-save-hook' instead of `before-save-hook'. (ruby-mode-set-encoding): Use the value of coding system used to write the file. Call `basic-save-buffer-1' after modifying the buffer. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e3f32150ee..d7eedf1dc6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-10-13 Dmitry Gutov + + * progmodes/ruby-mode.el (ruby-mode): Add `ruby-mode-set-encoding' + to `after-save-hook' instead of `before-save-hook'. + (ruby-mode-set-encoding): Use the value of coding system used to + write the file. Call `basic-save-buffer-1' after modifying the + buffer. + 2013-10-13 Alan Mackenzie Fix indentation/fontification of Java enum with diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index dfc93a21b4..a06121ed63 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -529,7 +529,7 @@ 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 + (or save-buffer-coding-system buffer-file-coding-system))) (if coding-system (setq coding-system @@ -555,7 +555,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." @@ -2017,11 +2019,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))