diff options
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 28 |
1 files changed, 18 insertions, 10 deletions
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." | |||
| 450 | (when (re-search-forward "[^\0-\177]" nil t) | 450 | (when (re-search-forward "[^\0-\177]" nil t) |
| 451 | (goto-char (point-min)) | 451 | (goto-char (point-min)) |
| 452 | (let ((coding-system | 452 | (let ((coding-system |
| 453 | (or (coding-system-get last-coding-system-used 'mime-charset) | 453 | (or coding-system-for-write |
| 454 | (coding-system-change-eol-conversion ast-coding-system-used | 454 | buffer-file-coding-system))) |
| 455 | nil)))) | 455 | (if coding-system |
| 456 | (setq coding-system | ||
| 457 | (or (coding-system-get coding-system 'mime-charset) | ||
| 458 | (coding-system-change-eol-conversion coding-system nil)))) | ||
| 456 | (setq coding-system | 459 | (setq coding-system |
| 457 | (symbol-name (or (and ruby-use-encoding-map | 460 | (if coding-system |
| 458 | (cdr (assq coding-system ruby-encoding-map))) | 461 | (symbol-name |
| 459 | coding-system))) | 462 | (or (and ruby-use-encoding-map |
| 463 | (cdr (assq coding-system ruby-encoding-map))) | ||
| 464 | coding-system)) | ||
| 465 | "ascii-8bit")) | ||
| 460 | (if (looking-at "^#!") (beginning-of-line 2)) | 466 | (if (looking-at "^#!") (beginning-of-line 2)) |
| 461 | (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)") | 467 | (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)") |
| 462 | (unless (string= (match-string 2) coding-system) | 468 | (unless (string= (match-string 2) coding-system) |
| @@ -470,9 +476,7 @@ Also ignores spaces after parenthesis when 'space." | |||
| 470 | (insert coding-system))) | 476 | (insert coding-system))) |
| 471 | ((looking-at "\\s *#.*coding\\s *[:=]")) | 477 | ((looking-at "\\s *#.*coding\\s *[:=]")) |
| 472 | (t (when ruby-insert-encoding-magic-comment | 478 | (t (when ruby-insert-encoding-magic-comment |
| 473 | (insert "# -*- coding: " coding-system " -*-\n")))) | 479 | (insert "# -*- coding: " coding-system " -*-\n")))))))) |
| 474 | (when (buffer-modified-p) | ||
| 475 | (basic-save-buffer-1)))))) | ||
| 476 | 480 | ||
| 477 | (defun ruby-current-indentation () | 481 | (defun ruby-current-indentation () |
| 478 | "Return the indentation level of current line." | 482 | "Return the indentation level of current line." |
| @@ -1930,7 +1934,11 @@ The variable `ruby-indent-level' controls the amount of indentation. | |||
| 1930 | (set (make-local-variable 'end-of-defun-function) | 1934 | (set (make-local-variable 'end-of-defun-function) |
| 1931 | 'ruby-end-of-defun) | 1935 | 'ruby-end-of-defun) |
| 1932 | 1936 | ||
| 1933 | (add-hook 'after-save-hook 'ruby-mode-set-encoding nil 'local) | 1937 | (add-hook |
| 1938 | (cond ((boundp 'before-save-hook) 'before-save-hook) | ||
| 1939 | ((boundp 'write-contents-functions) 'write-contents-functions) | ||
| 1940 | ((boundp 'write-contents-hooks) 'write-contents-hooks)) | ||
| 1941 | 'ruby-mode-set-encoding nil 'local) | ||
| 1934 | 1942 | ||
| 1935 | (set (make-local-variable 'electric-indent-chars) | 1943 | (set (make-local-variable 'electric-indent-chars) |
| 1936 | (append '(?\{ ?\}) electric-indent-chars)) | 1944 | (append '(?\{ ?\}) electric-indent-chars)) |