Commit e70181b8 authored by Akinori MUSHA's avatar Akinori MUSHA Committed by Dmitry Gutov
Browse files

* 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.
parent a5d38e34
2013-10-14 Akinori MUSHA <knu@iDaemons.org>
* 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 <rgm@gnu.org> 2013-10-13 Glenn Morris <rgm@gnu.org>
* progmodes/sh-script.el (sh-mark-line, sh-learn-buffer-indent): * progmodes/sh-script.el (sh-mark-line, sh-learn-buffer-indent):
...@@ -54,7 +66,7 @@ ...@@ -54,7 +66,7 @@
2013-10-12 Stefan Monnier <monnier@iro.umontreal.ca> 2013-10-12 Stefan Monnier <monnier@iro.umontreal.ca>
* progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for paren-free * 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--args-separator-p): New function.
(ruby-smie--forward-token, ruby-smie--backward-token): Use it to (ruby-smie--forward-token, ruby-smie--backward-token): Use it to
recognize paren-free method calls. recognize paren-free method calls.
......
...@@ -217,8 +217,15 @@ Also ignores spaces after parenthesis when 'space." ...@@ -217,8 +217,15 @@ Also ignores spaces after parenthesis when 'space."
"Default deep indent style." "Default deep indent style."
:options '(t nil space) :group 'ruby) :options '(t nil space) :group 'ruby)
(defcustom ruby-encoding-map '((shift_jis . cp932) (shift-jis . cp932)) (defcustom ruby-encoding-map
"Alist to map encoding name from Emacs to Ruby." '((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) :group 'ruby)
(defcustom ruby-insert-encoding-magic-comment t (defcustom ruby-insert-encoding-magic-comment t
...@@ -538,26 +545,28 @@ Also ignores spaces after parenthesis when 'space." ...@@ -538,26 +545,28 @@ Also ignores spaces after parenthesis when 'space."
(setq coding-system (setq coding-system
(if coding-system (if coding-system
(symbol-name (symbol-name
(or (and ruby-use-encoding-map (if ruby-use-encoding-map
(cdr (assq coding-system ruby-encoding-map))) (let ((elt (assq coding-system ruby-encoding-map)))
coding-system)) (if elt (cdr elt) coding-system))
coding-system))
"ascii-8bit")) "ascii-8bit"))
(if (looking-at "^#!") (beginning-of-line 2)) (when coding-system
(cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)") (if (looking-at "^#!") (beginning-of-line 2))
(unless (string= (match-string 2) coding-system) (cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)")
(goto-char (match-beginning 2)) (unless (string= (match-string 2) coding-system)
(delete-region (point) (match-end 2)) (goto-char (match-beginning 2))
(and (looking-at "-\*-") (delete-region (point) (match-end 2))
(let ((n (skip-chars-backward " "))) (and (looking-at "-\*-")
(cond ((= n 0) (insert " ") (backward-char)) (let ((n (skip-chars-backward " ")))
((= n -1) (insert " ")) (cond ((= n 0) (insert " ") (backward-char))
((forward-char))))) ((= n -1) (insert " "))
(insert coding-system))) ((forward-char)))))
((looking-at "\\s *#.*coding\\s *[:=]")) (insert coding-system)))
(t (when ruby-insert-encoding-magic-comment ((looking-at "\\s *#.*coding\\s *[:=]"))
(insert "# -*- coding: " coding-system " -*-\n")))) (t (when ruby-insert-encoding-magic-comment
(when (buffer-modified-p) (insert "# -*- coding: " coding-system " -*-\n"))))
(basic-save-buffer-1)))))) (when (buffer-modified-p)
(basic-save-buffer-1)))))))
(defun ruby-current-indentation () (defun ruby-current-indentation ()
"Return the indentation level of current line." "Return the indentation level of current line."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment