mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
506c6f52b9
commit
4332617032
1 changed files with 12 additions and 0 deletions
|
@ -106,6 +106,18 @@ Emacs to Ruby."
|
|||
(t (when ruby-insert-encoding-magic-comment
|
||||
(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)
|
||||
|
|
Loading…
Reference in a new issue