ruby-additional.el: ruby-encode-unicode

* misc/ruby-additional.el (ruby-encode-unicode): convert non-ascii
  string to \\u{} form.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-04-23 02:03:24 +00:00
Родитель 506c6f52b9
Коммит 4332617032
1 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -106,6 +106,18 @@ Emacs to Ruby."
(t (when ruby-insert-encoding-magic-comment (t (when ruby-insert-encoding-magic-comment
(insert "# -*- coding: " coding-system " -*-\n")))))))) (insert "# -*- coding: " coding-system " -*-\n"))))))))
(define-key ruby-mode-map "\C-c\C-u" 'ruby-encode-unicode)
(defun ruby-encode-unicode (beg end)
"Convert non-ascii string in the given region to \\u{} form."
(interactive "r")
(goto-char beg)
(while (and (< (point) end)
(re-search-forward "\\Ca+" end t))
(let ((u (mapconcat (lambda (c) (format "%x" c)) (match-string-no-properties 0) " ")))
(delete-region (match-beginning 0) (match-end 0))
(insert "\\u{" u "}"))
))
)) ))
(provide 'ruby-additional) (provide 'ruby-additional)