From: Bozhidar Batsov Date: Thu, 14 Nov 2013 12:39:41 +0000 (+0200) Subject: * lisp/progmodes/ruby-mode.el (ruby-mode-set-encoding): X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~828 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=99f5d0744ebf302d9ba56aae78da90504cb48772;p=emacs.git * lisp/progmodes/ruby-mode.el (ruby-mode-set-encoding): Fix and simplify encoding comment update logic. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e0b700a14ba..c9d767e5b7d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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 diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 8051a759410..e5a2de931d2 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -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