Commit 99f5d074 authored by Bozhidar Batsov's avatar Bozhidar Batsov
Browse files

* lisp/progmodes/ruby-mode.el (ruby-mode-set-encoding):

Fix and simplify encoding comment update logic.
parent 9caa4907
......@@ -2,6 +2,7 @@
* progmodes/ruby-mode.el (ruby-mode-set-encoding):
Add the ability to always insert an utf-8 encoding comment.
Fix and simplify coding comment update logic.
2013-11-14 Michael Albinus <michael.albinus@gmx.de>
......
......@@ -683,15 +683,11 @@ The style of the comment is controlled by `ruby-encoding-magic-comment-style'."
(let ((coding-system (ruby--detect-encoding)))
(when coding-system
(if (looking-at "^#!") (beginning-of-line 2))
(cond ((looking-at "\\s *#.*-\*-\\s *\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)\\s *\\(;\\|-\*-\\)")
(cond ((looking-at "\\s *#\\s *.*\\(en\\)?coding\\s *:\\s *\\([-a-z0-9_]*\\)")
;; update existing encoding comment if necessary
(unless (string= (match-string 2) coding-system)
(goto-char (match-beginning 2))
(delete-region (point) (match-end 2))
(and (looking-at "-\*-")
(let ((n (skip-chars-backward " ")))
(cond ((= n 0) (insert " ") (backward-char))
((= n -1) (insert " "))
((forward-char)))))
(insert coding-system)))
((looking-at "\\s *#.*coding\\s *[:=]"))
(t (when ruby-insert-encoding-magic-comment
......
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