Function: ruby-mode-set-encoding
ruby-mode-set-encoding is a byte-compiled function defined in
ruby-mode.el.gz.
Signature
(ruby-mode-set-encoding)
Documentation
Insert a magic comment header with the proper encoding if necessary.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/ruby-mode.el.gz
(defun ruby-mode-set-encoding ()
"Insert a magic comment header with the proper encoding if necessary."
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(when (ruby--encoding-comment-required-p)
(goto-char (point-min))
(let ((coding-system (ruby--detect-encoding)))
(when coding-system
(if (looking-at "^#!") (beginning-of-line 2))
(cond ((looking-at "\\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))
(insert (symbol-name coding-system))))
((looking-at "\\s *#.*coding\\s *[:=]"))
(t (when ruby-insert-encoding-magic-comment
(ruby--insert-coding-comment coding-system))))
(when (buffer-modified-p)
(basic-save-buffer-1))))))))